aboutsummaryrefslogtreecommitdiffstats
path: root/src/world/tectonicphase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/world/tectonicphase.cpp')
-rw-r--r--src/world/tectonicphase.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/world/tectonicphase.cpp b/src/world/tectonicphase.cpp
new file mode 100644
index 0000000..5e8ce96
--- /dev/null
+++ b/src/world/tectonicphase.cpp
@@ -0,0 +1,57 @@
+#include "world/tectonicphase.h"
+#include "boxii/input.h"
+
+int TectonicPhase::m_plateCount = 10;
+
+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);
+ std::uniform_int_distribution<int> cDist(0, 1);
+
+ m_plates.reserve(m_plateCount);
+
+ for(int i = 0; i < m_plateCount; i++){
+ m_plates.push_back(Plate());
+ m_plates[i].x = xDist(map->getRandom()) * map->getWidth();
+ m_plates[i].y = yDist(map->getRandom()) * map->getHeight();
+ m_plates[i].continental = cDist(map->getRandom());
+ }
+
+ rasterize(map);
+}
+
+static float
+dist(float x1, float y1, float x2, float y2)
+{
+ return ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
+}
+
+void
+TectonicPhase::rasterize(std::shared_ptr<WorldMap> map)
+{
+ for(int y = 0; y < map->getHeight(); y++){
+ for(int x = 0; x < map->getWidth(); x++){
+
+ int closest = 0;
+ float cdist = INT_MAX;
+
+ //Iterate through plates
+ for(int i = 0; i < m_plateCount; i++){
+ float d = dist(static_cast<float>(x), static_cast<float>(y), m_plates[i].x, m_plates[i].y);
+
+ if(d < cdist){
+ closest = i;
+ cdist = d;
+ }
+ }
+
+ if(m_plates[closest].continental){
+ map->setProperties(x, y, 600, 0, 0);
+ }else{
+ map->setProperties(x, y, 512, 88, 0);
+ }
+ }
+ }
+}