aboutsummaryrefslogtreecommitdiffstats
path: root/2
diff options
context:
space:
mode:
Diffstat (limited to '2')
-rw-r--r--264
1 files changed, 64 insertions, 0 deletions
diff --git a/2 b/2
new file mode 100644
index 0000000..cc0ebef
--- /dev/null
+++ b/2
@@ -0,0 +1,64 @@
+#include "world/tectonicphase.h"
+#include "boxii/input.h"
+
+TectonicPhase::TectonicPhase(std::shared_ptr<GenerationPhase> prev, std::shared_ptr<WorldMap> map) :
+ GenerationPhase(prev, map)
+{
+ std::uniform_real_distribution<float> xDist(0.f, 1.f);
+ std::uniform_real_distribution<float> yDist(0.f, 1.f);
+
+ for(int i = 0; i < TECTONIC_PLATES; i++){
+ m_plates[i].x = xDist(map->getRandom()) * map->getWidth();
+ m_plates[i].y = yDist(map->getRandom()) * map->getHeight();
+ m_plates[i].continental = rand() % 2;
+
+ printf("Plate %i : %i %i (%i)\n\r", i, m_plates[i].x, m_plates[i].y, m_plates[i].continental);
+ Boxii::Input::getch(true);
+ }
+
+ rasterize(map);
+}
+
+static float
+dist(float x1, float x2, float y1, float y2)
+{
+ return sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)));
+}
+
+void
+TectonicPhase::rasterize(std::shared_ptr<WorldMap> map)
+{
+ int w = map->getWidth();
+ int h = map->getHeight();
+
+ for(int y = 0; y < h; y++)
+ for(int x = 0; x < w; x++)
+ {
+ Plate *closest = nullptr;
+ float cdist = INT_MAX;
+
+ //Iterate through plates
+ for(int i = 0; i < TECTONIC_PLATES; i++){
+ Plate *plate = &m_plates[i];
+
+ float d = dist(x, y, plate->x, plate->y);
+
+ if(d < cdist){
+ closest = plate;
+ cdist = d;
+ }
+ }
+
+ if(closest == nullptr) {
+ printf("Skipping tile with no clear closest?\n");
+ Boxii::Input::getch(true);
+ continue;
+ }
+
+ if(closest->continental) {
+ map->setProperties(x, y, 1024, 0, 0);
+ }else{
+ map->setProperties(x, y, 0, 0, 0);
+ }
+ }
+}