aboutsummaryrefslogtreecommitdiff
path: root/BlueTileBehavior.cpp
blob: d934d4b0ac22ce45d9ef34aa4bb31f369f601d45 (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
35
36
37
38
39
40
41
42
43
44
#include <memory>

#include "SetNeighborTileBehavior.h"
#include "CreateArtistTileBehavior.h"
#include "Artist.h"
#include "Tile.h"

using namespace std;

SetNeighborTileBehavior SetNeighborTileBehavior::instance { SetNeighborTileBehavior::type };

void SetNeighborTileBehavior::step(Artist * artist) {
	this->interactions++;
	if (dx != 0 || dy != 0) return;
	if (artist == nullptr) return;

	if (artist->data.vx == 0) dx = 1;
	if (artist->data.vy == 0) dy = 1;
}

static void update_neighbor(Tile & here, int dx, int dy) {
	if (dx == 0 && dy == 0) return;
	Tile * neighbor = here.get_neighbor(dx, dy);
	if (neighbor == &here) return;
	if (neighbor == nullptr) return;

	neighbor->set_type(SetNeighborTileBehavior::type);
}

void SetNeighborTileBehavior::update(Tile & tile) {
	if (this->interactions < 1) return;

	update_neighbor(tile, this->dx, this->dy);
	update_neighbor(tile, -this->dx, -this->dy);

	tile.set_type(CreateArtistTileBehavior::type);
}

unique_ptr<TileBehavior> SetNeighborTileBehavior::clone(Museum & museum) {
	auto instance = new SetNeighborTileBehavior();
	instance->museum = &museum;
	return unique_ptr<TileBehavior>(instance);
}