Mgvalleys / cavegen: Place riverbed nodes under river water
authorparamat <mat.gregory@virginmedia.com>
Tue, 19 Jul 2016 23:23:08 +0000 (00:23 +0100)
committerparamat <mat.gregory@virginmedia.com>
Thu, 21 Jul 2016 04:01:18 +0000 (05:01 +0100)
When a CavesNoiseIntersection tunnel intersects a river place biome
'riverbed' nodes in tunnel entrance instead of biome 'top' nodes.

src/cavegen.cpp
src/mapgen_valleys.cpp

index dc7355fe074949135287e02c96eeeea3a3d5a8cb..bb6aa25a6ede7bf0f4acb93640056211756c4401 100644 (file)
@@ -79,6 +79,7 @@ void CavesNoiseIntersection::generateCaves(MMVManip *vm,
        for (s16 z = nmin.Z; z <= nmax.Z; z++)
        for (s16 x = nmin.X; x <= nmax.X; x++, index2d++) {
                bool column_is_open = false;  // Is column open to overground
+               bool is_under_river = false;  // Is column under river water
                bool is_tunnel = false;  // Is tunnel or tunnel floor
                u32 vi = vm->m_area.index(x, nmax.Y, z);
                u32 index3d = (z - nmin.Z) * m_zstride_1d + m_csize.Y * m_ystride +
@@ -99,6 +100,10 @@ void CavesNoiseIntersection::generateCaves(MMVManip *vm,
                                        c == biome->c_water) {
                                column_is_open = true;
                                continue;
+                       } else if (c == biome->c_river_water) {
+                               column_is_open = true;
+                               is_under_river = true;
+                               continue;
                        }
                        // Ground
                        float d1 = contour(noise_cave1->result[index3d]);
@@ -111,9 +116,13 @@ void CavesNoiseIntersection::generateCaves(MMVManip *vm,
                        } else {
                                // Not in tunnel or not ground content
                                if (is_tunnel && column_is_open &&
-                                               (c == biome->c_filler || c == biome->c_stone))
+                                               (c == biome->c_filler || c == biome->c_stone)) {
                                        // Tunnel entrance floor
-                                       vm->m_data[vi] = MapNode(biome->c_top);
+                                       if (is_under_river)
+                                               vm->m_data[vi] = MapNode(biome->c_riverbed);
+                                       else
+                                               vm->m_data[vi] = MapNode(biome->c_top);
+                               }
 
                                column_is_open = false;
                                is_tunnel = false;
index a61f1b329930ae2f0a67f279e41aeedaa7b0d3d3..456e6aa1aeabcd121b3ffe401a4ac15186b8a74d 100644 (file)
@@ -665,6 +665,7 @@ void MapgenValleys::generateCaves(s16 max_stone_y, s16 large_cave_depth)
        for (s16 x = node_min.X; x <= node_max.X; x++, index_2d++) {
                Biome *biome = (Biome *)m_bmgr->getRaw(biomemap[index_2d]);
                bool tunnel_air_above = false;
+               bool is_under_river = false;
                bool underground = false;
                u32 index_data = vm->m_area.index(x, node_max.Y, z);
                u32 index_3d = (z - node_min.Z) * zstride_1d + csize.Y * ystride + (x - node_min.X);
@@ -696,14 +697,13 @@ void MapgenValleys::generateCaves(s16 max_stone_y, s16 large_cave_depth)
                        }
 
                        content_t c = vm->m_data[index_data].getContent();
+                       // Detect river water to place riverbed nodes in tunnels
+                       if (c == biome->c_river_water)
+                               is_under_river = true;
+
                        float d1 = contour(noise_cave1->result[index_3d]);
                        float d2 = contour(noise_cave2->result[index_3d]);
 
-                       // River water is not set as ground content
-                       // in the default game. This can produce strange results
-                       // when a tunnel undercuts a river. However, that's not for
-                       // the mapgen to correct. Fix it in lua.
-
                        if (d1 * d2 > cave_width && ndef->get(c).is_ground_content) {
                                // in a tunnel
                                vm->m_data[index_data] = n_air;
@@ -716,8 +716,10 @@ void MapgenValleys::generateCaves(s16 max_stone_y, s16 large_cave_depth)
                                        vm->m_area.add_y(em, j, 1);
 
                                        if (sr > terrain - y) {
-                                               // Put dirt in tunnels near the surface.
-                                               if (underground)
+                                               // Put biome nodes in tunnels near the surface
+                                               if (is_under_river)
+                                                       vm->m_data[index_data] = MapNode(biome->c_riverbed);
+                                               else if (underground)
                                                        vm->m_data[index_data] = MapNode(biome->c_filler);
                                                else
                                                        vm->m_data[index_data] = MapNode(biome->c_top);