summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/entity.cpp11
-rw-r--r--src/entity.hpp2
2 files changed, 7 insertions, 6 deletions
diff --git a/src/entity.cpp b/src/entity.cpp
index 8aa3752f..8774e3b0 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -181,10 +181,10 @@ bool entity::can_move_to(Vector2i delta)
return can_move_to(delta, coord, offset, bbox_offset, bbox_size);
}
-bool entity::move_to(size_t& i, Vector2i delta, rotation new_r)
+size_t entity::move_to(size_t& i, Vector2i delta, rotation new_r)
{
if (!can_rotate(new_r))
- return false;
+ return i;
auto& es = c->_entities;
fm_debug_assert(i < es.size());
@@ -195,7 +195,7 @@ bool entity::move_to(size_t& i, Vector2i delta, rotation new_r)
const auto [coord_, offset_] = normalize_coords(coord, offset, delta);
if (coord_ == coord && offset_ == offset)
- return false;
+ return i;
if (!is_dynamic())
c->mark_scenery_modified();
@@ -214,7 +214,6 @@ bool entity::move_to(size_t& i, Vector2i delta, rotation new_r)
const_cast<rotation&>(r) = new_r;
//for (auto i = 0uz; const auto& x : es) fm_debug("%zu %s %f", i++, x->atlas->name().data(), x->ordinal());
//fm_debug("insert (%hd;%hd|%hhd;%hhd) %td -> %zu | %f", coord_.chunk().x, coord_.chunk().y, coord_.local().x, coord_.local().y, pos1, es.size(), e.ordinal());
- return false;
}
else
{
@@ -230,9 +229,11 @@ bool entity::move_to(size_t& i, Vector2i delta, rotation new_r)
set_bbox_(offset_, bb_offset, bb_size, pass);
const_cast<rotation&>(r) = new_r;
const_cast<struct chunk*&>(c) = &c2;
+ i = (size_t)std::distance(es.cbegin(), it);
es.insert(it, std::move(e_));
- return true;
}
+
+ return i;
}
void entity::set_bbox_(Vector2b offset_, Vector2b bbox_offset_, Vector2ub bbox_size_, pass_mode pass_)
diff --git a/src/entity.hpp b/src/entity.hpp
index 8d56617c..c6ceabaf 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -75,7 +75,7 @@ struct entity
bool is_dynamic() const;
bool can_rotate(rotation new_r);
bool can_move_to(Vector2i delta);
- bool move_to(size_t& i, Vector2i delta, rotation new_r);
+ size_t move_to(size_t& i, Vector2i delta, rotation new_r);
protected:
entity(object_id id, struct chunk& c, const entity_proto& proto);