diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-23 14:36:41 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-23 14:36:41 +0200 |
commit | 64028952ceb17f97ded08f1ab7ec0b06c41e2b87 (patch) | |
tree | f792377f93ff30a41a0c559c67aa874a022d4763 /PathfindingContext.cpp | |
parent | e522f2a36ee00a3e0890adb2c34bfc8431711265 (diff) |
add pathfinding start/end selection
Diffstat (limited to 'PathfindingContext.cpp')
-rw-r--r-- | PathfindingContext.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/PathfindingContext.cpp b/PathfindingContext.cpp new file mode 100644 index 0000000..a1d31f6 --- /dev/null +++ b/PathfindingContext.cpp @@ -0,0 +1,34 @@ +#include "PathfindingContext.h" +#include "Museum.h" +#include "NullTileBehavior.h" + +using namespace std; + +PathfindingContext::PathfindingContext(Museum & m) : museum(m) {} + +void PathfindingContext::set_start(const pair<int, int> & point) { + if (!this->valid_point(point)) return; + this->start_point = point; +} + +void PathfindingContext::set_end(const pair<int, int> & point) { + if (!this->valid_point(point)) return; + this->end_point = point; +} + +bool PathfindingContext::valid_point(const std::pair<int, int> & point) { + // check if out of bounds + Canvas & canvas = this->museum.canvas; + if (point.first < 0) return false; + if (point.second < 0) return false; + if (point.first >= canvas.data.columns) return false; + if (point.second >= canvas.data.rows) return false; + + // check if square is empty (has null behavior) + Tile & tile = canvas.get_tile(point.first, point.second); + TileBehavior * behavior = tile.behavior.get(); + if (dynamic_cast<NullTileBehavior *>(behavior) != nullptr) return false; + + return true; +} + |