#include "PathfindingContext.h" #include "XY.h" #include "Museum.h" #include "NullTileBehavior.h" using namespace std; PathfindingContext::PathfindingContext(Museum & m) : museum(m) {} void PathfindingContext::set_start(const XY & point) { if (!this->valid_point(point)) return; this->start_point = point; } void PathfindingContext::set_end(const XY & point) { if (!this->valid_point(point)) return; this->end_point = point; } bool PathfindingContext::valid_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(behavior) != nullptr) return false; } catch (...) { // get_tile throws an exception if the point is outside the canvas bounds return false; } return true; }