summaryrefslogtreecommitdiffhomepage
path: root/src/path-search.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-09-25 06:11:52 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-09-25 06:11:52 +0200
commit18d1db7d8be97fd9aea67c352e78b376d7145f4b (patch)
treeb28d9b272bf1a0e5bf971c4e162e8ef2bf44b037 /src/path-search.cpp
parent627dc90720e083b2e458ab7efb4dcca739b7a19a (diff)
a
Diffstat (limited to 'src/path-search.cpp')
-rw-r--r--src/path-search.cpp50
1 files changed, 46 insertions, 4 deletions
diff --git a/src/path-search.cpp b/src/path-search.cpp
index cf7d41d5..47ce6f61 100644
--- a/src/path-search.cpp
+++ b/src/path-search.cpp
@@ -176,10 +176,52 @@ auto path_search::make_neighbor_tile_bbox(Vector2i coord, Vector2ub own_size, ro
return { Vector2(min + shift), Vector2(max + shift) };
}
-Optional<path_search_result>
-path_search::operator()(world& w, object_id own_id,
- global_coords from, Vector2b from_offset, Vector2ub size,
- global_coords to, Vector2b to_offset)
+auto path_search::get_walkable_neighbor_tiles(world& w, global_coords coord, Vector2ub size, object_id own_id) -> neighbors
+{
+ auto ch = chunk_coords_{ coord.chunk(), coord.z() };
+ auto pos = Vector2i(coord.local());
+
+ if (auto [min, max] = make_neighbor_tile_bbox(pos, size, rotation_COUNT);
+ !is_passable(w, ch, min, max, own_id))
+ return {};
+
+ neighbors ns;
+
+ using enum rotation;
+ constexpr struct {
+ Vector2i off;
+ rotation r = {};
+ } nbs[] = {
+ { { 0, -1 }, N },
+ { { 1, 0 }, E },
+ { { 0, 1 }, S },
+ { { -1, 0 }, W },
+ };
+
+ for (auto [off, dir] : nbs)
+ {
+ auto [min, max] = make_neighbor_tile_bbox(pos, size, dir);
+ if (is_passable(w, ch, min, max, own_id))
+ ns.neighbors[ns.size++] = coord + off;
+ }
+
+ return ns;
+}
+
+auto path_search::bbox_union(bbox bb, Vector2i coord, Vector2b offset, Vector2ub size) -> bbox
+{
+ auto center = coord * iTILE_SIZE2 + Vector2i(offset);
+ auto min = center - Vector2i(size / 2u);
+ auto max = center + Vector2i(size);
+ return {
+ .min = Math::min(bb.min, Vector2(min)),
+ .max = Math::max(bb.max, Vector2(max)),
+ };
+}
+
+Optional<path_search_result> path_search::operator()(world& w, object_id own_id,
+ global_coords from, Vector2b from_offset, Vector2ub size,
+ global_coords to, Vector2b to_offset)
{
if (from.z() != to.z()) [[unlikely]]
return {};