summaryrefslogtreecommitdiffhomepage
path: root/src/entity.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-16 09:07:00 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-17 23:23:11 +0100
commita1df7c84a5c49adb3b8e8cd3796fd53a02684dd5 (patch)
tree0e29449992a851fdb4c16628db8f1ea81c078308 /src/entity.cpp
parentfd9298ef43136fa89dab034096690a08027ebf44 (diff)
a
Diffstat (limited to 'src/entity.cpp')
-rw-r--r--src/entity.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/entity.cpp b/src/entity.cpp
index 09d4dfe2..e7d2398b 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -43,20 +43,35 @@ entity::~entity() noexcept
w.do_kill_entity(id);
}
+Vector2b entity::ordinal_offset_for_type(entity_type type, Vector2b offset)
+{
+ switch (type)
+ {
+ case entity_type::scenery:
+ return offset;
+ default:
+ fm_warn_once("unknown entity type '%zu'", std::size_t(type));
+ [[fallthrough]];
+ case entity_type::character:
+ return {};
+ }
+}
+
std::int32_t entity_proto::ordinal(local_coords local) const
{
- return entity::ordinal(local, offset);
+ return entity::ordinal(local, offset, type);
}
std::int32_t entity::ordinal() const
{
- return ordinal(coord.local(), offset);
+ return ordinal(coord.local(), offset, type);
}
-std::int32_t entity::ordinal(local_coords xy, Vector2b offset)
+std::int32_t entity::ordinal(local_coords xy, Vector2b offset, entity_type type)
{
+ offset = ordinal_offset_for_type(type, offset);
constexpr auto x_size = (std::int32_t)TILE_MAX_DIM * (std::int32_t)iTILE_SIZE[0];
- auto vec = Vector2i(xy) * Vector2i(iTILE_SIZE2) + Vector2i(offset);
+ auto vec = Vector2i(xy) * Vector2i(iTILE_SIZE2);
return vec[1] * x_size + vec[0];
}
@@ -157,7 +172,7 @@ void entity::move(It it, Vector2i delta)
chunk::bbox bb0, bb1;
bool b0 = c._bbox_for_scenery(e, bb0),
b1 = c._bbox_for_scenery(e, coord_.local(), offset_, bb1);
- const auto ord = e.ordinal(coord_.local(), offset_);
+ const auto ord = e.ordinal(coord_.local(), offset_, e.type);
if (coord_.chunk() == coord.chunk())
{