#include "PathfindingContext.h" #include "Museum.h" #include "NullTileBehavior.h" using namespace std; PathfindingContext::PathfindingContext(Museum & m) : museum(m) {} void PathfindingContext::set_start(const pair & point) { if (!this->valid_point(point)) return; this->start_point = point; } void PathfindingContext::set_end(const pair & point) { if (!this->valid_point(point)) return; this->end_point = point; } bool PathfindingContext::valid_point(const std::pair & 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(behavior) != nullptr) return false; return true; }