aboutsummaryrefslogtreecommitdiff
path: root/SetNeighborTileBehavior.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-18 15:48:14 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-18 15:48:14 +0200
commitd8289105193707daede1a5b59137f18e20f20aeb (patch)
tree939908b9c4c6f7aaef8aa61ee2e04be3e85610b6 /SetNeighborTileBehavior.cpp
parent76e61d68bbf568ec0d7fc4632e52d4de5496b003 (diff)
(2/2) rename
Diffstat (limited to 'SetNeighborTileBehavior.cpp')
-rw-r--r--SetNeighborTileBehavior.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/SetNeighborTileBehavior.cpp b/SetNeighborTileBehavior.cpp
new file mode 100644
index 0000000..d934d4b
--- /dev/null
+++ b/SetNeighborTileBehavior.cpp
@@ -0,0 +1,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);
+}
+