aboutsummaryrefslogtreecommitdiff
path: root/PathfindingContext.cpp
blob: cfebb44a5995a7f1c5983b651a05d2cbf5605985 (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
#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<NullTileBehavior *>(behavior) != nullptr) return false;
	} catch (...) {
		// get_tile throws an exception if the point is outside the canvas bounds
		return false;
	}

	return true;
}