Skip to content

Commit

Permalink
Mgvalleys / cavegen: Place riverbed nodes under river water
Browse files Browse the repository at this point in the history
When a CavesNoiseIntersection tunnel intersects a river place biome
'riverbed' nodes in tunnel entrance instead of biome 'top' nodes.
  • Loading branch information
paramat committed Jul 21, 2016
1 parent 97c7631 commit 2ba8ad1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
13 changes: 11 additions & 2 deletions src/cavegen.cpp
Expand Up @@ -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 +
Expand All @@ -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]);
Expand All @@ -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;
Expand Down
16 changes: 9 additions & 7 deletions src/mapgen_valleys.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 2ba8ad1

Please sign in to comment.