diff options
-rw-r--r-- | src/common.hpp | 1 | ||||
-rw-r--r-- | src/path_finder.cpp | 2 | ||||
-rw-r--r-- | src/world.cpp | 21 |
3 files changed, 19 insertions, 5 deletions
diff --git a/src/common.hpp b/src/common.hpp index df14f6f..81d79e3 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -152,6 +152,7 @@ namespace world { public: v2f_t src, dst, tile_center; + rectf_t bounds; cflags_t cflags; path_node_t *nodes; size_t width, height; diff --git a/src/path_finder.cpp b/src/path_finder.cpp index 15b1614..c8cd253 100644 --- a/src/path_finder.cpp +++ b/src/path_finder.cpp @@ -17,7 +17,7 @@ path_finder_t::~path_finder_t() void path_finder_t::setup_nodes(v2f_t src_, v2f_t dst_, cflags_t cflags_) { - rectf_t src_margin, dst_margin, bounds; + rectf_t src_margin, dst_margin; tile_index_t end; src = src_; diff --git a/src/world.cpp b/src/world.cpp index ef056db..3d21789 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -107,12 +107,25 @@ bool world_t::find_path(v2f_t src, v2f_t dst, cmodel_t *cmodel, entity_t *ignore finder.eliminate_nodes(combined); } - bounds = rectf_t(src, dst).norm(); + bounds = finder.bounds; + bounds[0] -= cmodel_dims / 2; + bounds[1] += cmodel_dims / 2; - for (entity_t *ent : get_entities(bounds, cmodel->cflags)) - if (ent != ignore) - finder.eliminate_nodes(ent->cmodel.bounds); + for (entity_t *ent : get_entities(bounds, cmodel->cflags)) { + v2f_t center; + v2f_t combined_dims; + rectf_t combined; + + if (ent == ignore) + continue; + center = ent->cmodel.bounds.center(); + combined_dims = ent->cmodel.bounds.dims() + cmodel_dims; + combined[0] = center - combined_dims / 2; + combined[1] = center + combined_dims / 2; + + finder.eliminate_nodes(combined); + } if (!finder.find()) return false; |