aboutsummaryrefslogtreecommitdiff
path: root/YellowTileBehavior.cpp
blob: 4e35733cdfffd3571c79dbf659e89181729289aa (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
45
46
#include <memory>
#include <random>

#include "YellowTileBehavior.h"
#include "GrayTileBehavior.h"
#include "Tile.h"
#include "Museum.h"

using std::uniform_int_distribution;
using std::uniform_real_distribution;
using std::random_device;
using std::mt19937;
using namespace std;

YellowTileBehavior YellowTileBehavior::instance { YellowTileBehavior::type };

random_device dev{};
mt19937 rng(dev());
uniform_int_distribution<int> random_bool(0, 1);
uniform_real_distribution<float> random_float(-1, 1);

void YellowTileBehavior::update(Tile & tile) {
	unsigned int new_artists = this->interactions - this->last_interactions;
	this->last_interactions = this->interactions;

	for (unsigned int i = 0; i < new_artists; i++) {
		if (i >= 2) break;
		ArtistData new_data = {
			.x = static_cast<float>(tile.data.x),
			.y = static_cast<float>(tile.data.y),
		};
		float velocity = random_float(rng);
		random_bool(rng) ? new_data.vx = velocity : new_data.vy = velocity;
		this->museum->people.add_artist(new_data);
	}

	if (this->interactions < 2) return;
	tile.set_type(GrayTileBehavior::type);
}

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