#include #include #include "CreateArtistTileBehavior.h" #include "StepTileBehavior.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; CreateArtistTileBehavior CreateArtistTileBehavior::instance { CreateArtistTileBehavior::type }; random_device dev{}; mt19937 rng(dev()); uniform_int_distribution random_bool(0, 1); uniform_real_distribution random_float(-1, 1); void CreateArtistTileBehavior::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(tile.data.x), .y = static_cast(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(StepTileBehavior::type); } unique_ptr CreateArtistTileBehavior::clone(Museum & museum) { auto instance = new CreateArtistTileBehavior(); instance->museum = &museum; return unique_ptr(instance); }