Mgvalleys: Don't let cavegen place biome nodes everywhere

Fix use of 'air_above' bool so that biome
nodes are only placed in tunnel floors
Minor code improvements
'Continue' when massive cave air is placed
master
paramat 2016-04-09 00:24:36 +01:00
parent 73d4538d94
commit fe349d401d
1 changed files with 36 additions and 41 deletions

View File

@ -921,14 +921,13 @@ void MapgenValleys::generateCaves(s16 max_stone_y)
} }
u32 index_2d = 0; u32 index_2d = 0;
u32 index_3d = 0;
for (s16 z = node_min.Z; z <= node_max.Z; z++) for (s16 z = node_min.Z; z <= node_max.Z; z++)
for (s16 x = node_min.X; x <= node_max.X; x++, index_2d++) { for (s16 x = node_min.X; x <= node_max.X; x++, index_2d++) {
Biome *biome = (Biome *)bmgr->getRaw(biomemap[index_2d]); Biome *biome = (Biome *)bmgr->getRaw(biomemap[index_2d]);
bool air_above = false; bool tunnel_air_above = false;
bool underground = false; bool underground = false;
u32 index_data = vm->m_area.index(x, node_max.Y, z); u32 index_data = vm->m_area.index(x, node_max.Y, z);
index_3d = (z - node_min.Z) * zstride_1d + csize.Y * ystride + (x - node_min.X); u32 index_3d = (z - node_min.Z) * zstride_1d + csize.Y * ystride + (x - node_min.X);
// Dig caves on down loop to check for air above. // Dig caves on down loop to check for air above.
// Don't excavate the overgenerated stone at node_max.Y + 1, // Don't excavate the overgenerated stone at node_max.Y + 1,
@ -942,12 +941,10 @@ void MapgenValleys::generateCaves(s16 max_stone_y)
float terrain = noise_terrain_height->result[index_2d]; float terrain = noise_terrain_height->result[index_2d];
// Saves some time. // Saves some time.
if (y > terrain + 10) { if (y > terrain + 10)
air_above = true;
continue; continue;
} else if (y < terrain - 40) { else if (y < terrain - 40)
underground = true; underground = true;
}
// Dig massive caves. // Dig massive caves.
if (node_max.Y <= massive_cave_depth if (node_max.Y <= massive_cave_depth
@ -955,6 +952,7 @@ void MapgenValleys::generateCaves(s16 max_stone_y)
> tcave_cache[y - node_min.Y + 1]) { > tcave_cache[y - node_min.Y + 1]) {
vm->m_data[index_data] = n_air; vm->m_data[index_data] = n_air;
made_a_big_one = true; made_a_big_one = true;
continue;
} }
content_t c = vm->m_data[index_data].getContent(); content_t c = vm->m_data[index_data].getContent();
@ -963,54 +961,51 @@ void MapgenValleys::generateCaves(s16 max_stone_y)
// River water is not set as ground content // River water is not set as ground content
// in the default game. This can produce strange results // in the default game. This can produce strange results
// when a cave undercuts a river. However, that's not for // when a tunnel undercuts a river. However, that's not for
// the mapgen to correct. Fix it in lua. // the mapgen to correct. Fix it in lua.
if (c == CONTENT_AIR) { if (d1 * d2 > 0.3f && ndef->get(c).is_ground_content) {
air_above = true; // in a tunnel
} else if (d1 * d2 > 0.3f && ndef->get(c).is_ground_content) {
// in a cave
vm->m_data[index_data] = n_air; vm->m_data[index_data] = n_air;
air_above = true; tunnel_air_above = true;
} else if (air_above && (c == biome->c_filler || c == biome->c_stone)) { } else if (c == biome->c_filler || c == biome->c_stone) {
// at the cave floor if (tunnel_air_above) {
s16 sr = ps.range(0,39); // at the tunnel floor
u32 j = index_data; s16 sr = ps.range(0, 39);
vm->m_area.add_y(em, j, 1); u32 j = index_data;
vm->m_area.add_y(em, j, 1);
if (sr > terrain - y) { if (sr > terrain - y) {
// Put dirt in caves near the surface. // Put dirt in tunnels near the surface.
if (underground) if (underground)
vm->m_data[index_data] = MapNode(biome->c_filler); vm->m_data[index_data] = MapNode(biome->c_filler);
else else
vm->m_data[index_data] = MapNode(biome->c_top); vm->m_data[index_data] = MapNode(biome->c_top);
} else if (sr < 3 && underground) { } else if (sr < 3 && underground) {
sr = abs(ps.next()); sr = abs(ps.next());
if (lava_features_lim > 0 && y <= lava_max_height if (lava_features_lim > 0 && y <= lava_max_height
&& c == biome->c_stone && sr < lava_chance) && c == biome->c_stone && sr < lava_chance)
vm->m_data[j] = n_lava; vm->m_data[j] = n_lava;
sr -= lava_chance; sr -= lava_chance;
// If sr < 0 then we should have already placed lava -- // If sr < 0 then we should have already placed lava --
// don't immediately dump water on it. // don't immediately dump water on it.
if (water_features_lim > 0 && y <= cave_water_max_height if (water_features_lim > 0 && y <= cave_water_max_height
&& sr >= 0 && sr < water_chance) && sr >= 0 && sr < water_chance)
vm->m_data[j] = n_water; vm->m_data[j] = n_water;
}
} }
air_above = false; tunnel_air_above = false;
underground = true;
} else if (c == biome->c_filler || c == biome->c_stone) {
air_above = false;
underground = true; underground = true;
} else { } else {
air_above = false; tunnel_air_above = false;
} }
} }
} }
if (node_max.Y <= large_cave_depth && (!made_a_big_one)) { if (node_max.Y <= large_cave_depth && !made_a_big_one) {
u32 bruises_count = ps.range(0, 2); u32 bruises_count = ps.range(0, 2);
for (u32 i = 0; i < bruises_count; i++) { for (u32 i = 0; i < bruises_count; i++) {
CaveV5 cave(this, &ps); CaveV5 cave(this, &ps);