aboutsummaryrefslogtreecommitdiff
path: root/BreadthFirstPathfinder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'BreadthFirstPathfinder.cpp')
-rw-r--r--BreadthFirstPathfinder.cpp26
1 files changed, 8 insertions, 18 deletions
diff --git a/BreadthFirstPathfinder.cpp b/BreadthFirstPathfinder.cpp
index ef4492a..c204387 100644
--- a/BreadthFirstPathfinder.cpp
+++ b/BreadthFirstPathfinder.cpp
@@ -1,6 +1,5 @@
#include "BreadthFirstPathfinder.h"
#include "Museum.h"
-#include "NullTileBehavior.h"
using namespace std;
@@ -26,6 +25,7 @@ void BreadthFirstPathfinder::find_between(const XY & start, const XY & end) {
vector<BreadthFirstPathfinder::Path> BreadthFirstPathfinder::find_step(const vector<Path> & to_visit) {
vector<Path> next_step = {};
+ PathfindingContext & ctx = this->museum.pathfinding;
for (Path trail : to_visit) {
const XY & here = trail.front();
@@ -34,30 +34,20 @@ vector<BreadthFirstPathfinder::Path> BreadthFirstPathfinder::find_step(const vec
return {};
}
- Tile & tile = this->museum.canvas.get_tile(here);
- const XY offsets[] = {
+ vector<XY> offsets = {
{ 0, 1 },
{ 1, 0 },
{ 0, -1 },
{ -1, 0 },
};
- for (size_t i = 0; i < 4; i++) {
- const XY offset = offsets[i];
- Tile * neighbor = tile.get_neighbor(offset);
-
- // if neighbor doesn't exist (out of bounds)
- if (neighbor == nullptr) continue;
-
- // if neighbor is a blank tile
- TileBehavior * behavior = neighbor->behavior.get();
- if (dynamic_cast<NullTileBehavior *>(behavior) != nullptr) continue;;
-
- // if neighbor is already visited
- if (this->is_visited(here + offset)) continue;
- this->set_visited(here + offset);
+ for (const XY & offset : offsets) {
+ const XY neighbor = here + offset;
+ if (ctx.empty_point(neighbor)) continue;
+ if (this->is_visited(neighbor)) continue;
+ this->set_visited(neighbor);
Path trail_copy = trail;
- trail_copy.push_front(here + offset);
+ trail_copy.push_front(neighbor);
next_step.push_back(trail_copy);
}
}