]> git.localhorst.tv Git - blobs.git/blobdiff - src/world/world.cpp
slightly better planet
[blobs.git] / src / world / world.cpp
index fb57c7c09bde150172b0304ceabd580624728e90..a3494b3024f700ca7d78f24e0e5426ed3a7ac515 100644 (file)
@@ -389,17 +389,24 @@ void GenerateEarthlike(const TileSet &tiles, Planet &p) noexcept {
        rand::SimplexNoise elevation_gen(0);
 
        const int ice = tiles["ice"].id;
-       const int grass = tiles["grass"].id;
+       const int ocean = tiles["ocean"].id;
        const int water = tiles["water"].id;
        const int sand = tiles["sand"].id;
-       const int rock = tiles["rock"].id;
+       const int grass = tiles["grass"].id;
+       const int tundra = tiles["tundra"].id;
+       const int desert = tiles["desert"].id;
+       const int mntn = tiles["mountain"].id;
 
+       constexpr double ocean_thresh = -0.2;
        constexpr double water_thresh = 0.0;
        constexpr double beach_thresh = 0.1;
        constexpr double mountain_thresh = 0.5;
 
        const glm::dvec3 axis(glm::dvec4(0.0, 1.0, 0.0, 0.0) * glm::eulerAngleXY(p.SurfaceTilt().x, p.SurfaceTilt().y));
-       const double cap_thresh = std::cos(p.AxialTilt().x);
+       const double cap_thresh = std::abs(std::cos(p.AxialTilt().x));
+       const double equ_thresh = 2.0 * (1.0 - cap_thresh);
+       const double fzone_start = equ_thresh - (equ_thresh - cap_thresh) / 3.0;
+       const double fzone_end = cap_thresh + (equ_thresh - cap_thresh) / 3.0;
 
        for (int surface = 0; surface <= 5; ++surface) {
                for (int y = 0; y < p.SideLength(); ++y) {
@@ -419,14 +426,25 @@ void GenerateEarthlike(const TileSet &tiles, Planet &p) noexcept {
                                        2,   // amplitude
                                        2    // growth
                                );
-                               if (elevation < water_thresh) {
+                               if (elevation < ocean_thresh) {
+                                       p.TileAt(surface, x, y).type = ocean;
+                               } else if (elevation < water_thresh) {
                                        p.TileAt(surface, x, y).type = water;
                                } else if (elevation < beach_thresh) {
                                        p.TileAt(surface, x, y).type = sand;
                                } else if (elevation < mountain_thresh) {
-                                       p.TileAt(surface, x, y).type = grass;
+                                       // TODO: perturb climate rings a little
+                                       if (near_axis < equ_thresh) {
+                                               p.TileAt(surface, x, y).type = desert;
+                                       } else if (near_axis < fzone_start) {
+                                               p.TileAt(surface, x, y).type = grass;
+                                       } else if (near_axis < fzone_end) {
+                                               p.TileAt(surface, x, y).type = tundra;
+                                       } else {
+                                               p.TileAt(surface, x, y).type = grass;
+                                       }
                                } else {
-                                       p.TileAt(surface, x, y).type = rock;
+                                       p.TileAt(surface, x, y).type = mntn;
                                }
                        }
                }