diff options
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; +} + |