diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-24 18:32:55 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-24 18:32:55 +0200 |
commit | faa82f0a6004026c94a6415baf5e138b48dc1629 (patch) | |
tree | ead573bf9ec72a74569b79724c732c17dd9d0fb3 /PathfindingContext.cpp | |
parent | afc66d3013b7d47c6c22d6a99809bc3e7d1ff0dc (diff) |
implement weird dijkstra
Diffstat (limited to 'PathfindingContext.cpp')
-rw-r--r-- | PathfindingContext.cpp | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/PathfindingContext.cpp b/PathfindingContext.cpp index bcc9f37..df2f65b 100644 --- a/PathfindingContext.cpp +++ b/PathfindingContext.cpp @@ -10,7 +10,7 @@ using namespace std; PathfindingContext::PathfindingContext(Museum & m) : museum(m) { - // this->solvers.push_back(unique_ptr<Pathfinder>(new DijkstraPathfinder(m))); + this->solvers.push_back(unique_ptr<Pathfinder>(new DijkstraPathfinder(m))); this->solvers.push_back(unique_ptr<Pathfinder>(new BreadthFirstPathfinder(m))); } @@ -23,38 +23,38 @@ Pathfinder & PathfindingContext::get_solver() { } void PathfindingContext::set_start(const XY & point) { - if (!this->valid_point(point)) return; + if (this->empty_point(point)) return; this->start_point = point; this->update(); } void PathfindingContext::set_end(const XY & point) { - if (!this->valid_point(point)) return; + if (this->empty_point(point)) return; this->end_point = point; this->update(); } -bool PathfindingContext::valid_point(const XY & point) { +bool PathfindingContext::empty_point(const XY & point) { try { // check if square is empty (has null behavior) Tile & tile = this->museum.canvas.get_tile(point); TileBehavior * behavior = tile.behavior.get(); - if (dynamic_cast<NullTileBehavior *>(behavior) != nullptr) return false; + if (dynamic_cast<NullTileBehavior *>(behavior) != nullptr) return true; } catch (...) { // get_tile throws an exception if the point is outside the canvas bounds - return false; + return true; } - return true; + return false; } void PathfindingContext::update() { bool valid = true; - if (!this->valid_point(this->start_point)) { + if (this->empty_point(this->start_point)) { this->start_point = { -1, -1 }; valid = false; } - if (!this->valid_point(this->end_point)) { + if (this->empty_point(this->end_point)) { this->end_point = { -1, -1 }; valid = false; } @@ -65,3 +65,14 @@ void PathfindingContext::update() { solver.find_between(this->start_point, this->end_point); } +void PathfindingContext::register_weight(const string & type, unsigned int weight) { + this->weight_map[type] = weight; +} + +unsigned int PathfindingContext::get_weight(const string & type) { + if (this->weight_map.contains(type)) + return this->weight_map[type]; + + return 0; +} + |