blob: a1d31f6fd3139d21566d93afca39f32815d9ccab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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;
}
|