diff options
Diffstat (limited to 'src/world.cpp')
-rw-r--r-- | src/world.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/world.cpp b/src/world.cpp index ad055c0..07d5638 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -68,10 +68,11 @@ void world_t::generate(sector_t *sector, sector_index_t index) sector->empty = false; } -bool world_t::find_path(v2f_t src, v2f_t dst, rectf_t size, +bool world_t::find_path(v2f_t src, v2f_t dst, rectf_t size, entity_t *ignore, std::list<v2f_t> *path) { path_finder_t finder; + rectf_t bounds; finder.setup_nodes(src, dst); @@ -85,9 +86,32 @@ bool world_t::find_path(v2f_t src, v2f_t dst, rectf_t size, get_tile(index)->type <= 3); } + bounds = rectf_t(src, dst).norm(); + + for (entity_t *ent : get_entities(bounds)) + if (ent != ignore) + finder.eliminate_nodes(ent->bounds); + if (!finder.find()) return false; + debug.clear(); + + for (size_t y = 0; y < finder.height; y++) + for (size_t x = 0; x < finder.width; x++) { + path_node_t *node = finder.nodes + y * finder.width + x; + std::stringstream ss; + + ss << finder.base + tile_index_t(x, y) << "\n"; + if (node->accessible) + ss << node->dist; + else + ss << "inaccessible"; + + debug.push_back((debug_t){finder.base + tile_index_t(x, y), ss.str()}); + } + + finder.export_path(path); return true; } @@ -146,7 +170,7 @@ std::list<entity_t*> world_t::get_entities(rectf_t rect) if (ent->cookie == cookie) continue; - if (!rect.intersects(ent->bounds)) + if (!(rect && ent->bounds)) continue; ent->cookie = cookie; @@ -169,7 +193,7 @@ std::list<entity_t*> world_t::get_render_entities(rectf_t rect) if (ent->cookie == cookie) continue; - if (!rect.intersects(ent->render_bounds)) + if (!(rect && ent->render_bounds)) continue; ent->cookie = cookie; @@ -200,7 +224,7 @@ void entity_t::link(world_t *world) float xlip, ylip; size_t xsecs, ysecs; - total_bounds = bounds + render_bounds; + total_bounds = bounds | render_bounds; fx = floor(total_bounds[0][0]); fy = floor(total_bounds[0][1]); |