///////////////////////////////////////// Caves V5
-CaveV5::CaveV5(MapgenV5 *mg, PseudoRandom *ps) {
+CaveV5::CaveV5(Mapgen *mg, PseudoRandom *ps)
+{
this->mg = mg;
this->vm = mg->vm;
this->ndef = mg->ndef;
this->water_level = mg->water_level;
this->ps = ps;
- this->c_water_source = mg->c_water_source;
- this->c_lava_source = mg->c_lava_source;
- this->c_ice = mg->c_ice;
+ c_water_source = ndef->getId("mapgen_water_source");
+ c_lava_source = ndef->getId("mapgen_lava_source");
+ c_ice = ndef->getId("mapgen_ice");
this->np_caveliquids = &nparams_caveliquids;
+ this->ystride = mg->csize.X;
+
+ if (c_ice == CONTENT_IGNORE)
+ c_ice = CONTENT_AIR;
dswitchint = ps->range(1, 14);
flooded = ps->range(1, 2) == 2;
}
-void CaveV5::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height) {
+void CaveV5::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height)
+{
node_min = nmin;
node_max = nmax;
main_direction = v3f(0, 0, 0);
}
-void CaveV5::makeTunnel(bool dirswitch) {
-
+void CaveV5::makeTunnel(bool dirswitch)
+{
// Randomize size
s16 min_d = min_tunnel_diameter;
s16 max_d = max_tunnel_diameter;
(float)(ps->next() % maxlen.Z) - (float)maxlen.Z / 2
);
- // Do not make large caves that are above ground.
+ // Do not make caves that are above ground.
// It is only necessary to check the startpoint and endpoint.
v3s16 orpi(orp.X, orp.Y, orp.Z);
v3s16 veci(vec.X, vec.Y, vec.Z);
p = orpi + veci + of + rs / 2;
if (p.Z >= node_min.Z && p.Z <= node_max.Z &&
p.X >= node_min.X && p.X <= node_max.X) {
- u32 index = (p.Z - node_min.Z) * mg->ystride + (p.X - node_min.X);
+ u32 index = (p.Z - node_min.Z) * ystride + (p.X - node_min.X);
s16 h = mg->heightmap[index];
if (h < p.Y)
return;
p = orpi + of + rs / 2;
if (p.Z >= node_min.Z && p.Z <= node_max.Z &&
p.X >= node_min.X && p.X <= node_max.X) {
- u32 index = (p.Z - node_min.Z) * mg->ystride + (p.X - node_min.X);
+ u32 index = (p.Z - node_min.Z) * ystride + (p.X - node_min.X);
s16 h = mg->heightmap[index];
if (h < p.Y)
return;
// Every second section is rough
bool randomize_xz = (ps->range(1, 2) == 1);
- // Make a ravine every once in a while if it's long enough
- //float xylen = vec.X * vec.X + vec.Z * vec.Z;
- //disable ravines for now
- bool is_ravine = false; //(xylen > 500.0) && !large_cave && (ps->range(1, 8) == 1);
-
// Carve routes
for (float f = 0; f < 1.0; f += 1.0 / veclen)
- carveRoute(vec, f, randomize_xz, is_ravine);
+ carveRoute(vec, f, randomize_xz);
orp = rp;
}
-void CaveV5::carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine) {
+void CaveV5::carveRoute(v3f vec, float f, bool randomize_xz)
+{
MapNode airnode(CONTENT_AIR);
MapNode waternode(c_water_source);
MapNode lavanode(c_lava_source);
float nval = NoisePerlin3D(np_caveliquids, startp.X,
startp.Y, startp.Z, mg->seed);
- MapNode liquidnode = nval < 0.40 ? lavanode : waternode;
+ MapNode liquidnode = (nval < 0.40 && node_max.Y < MGV5_LAVA_DEPTH) ?
+ lavanode : waternode;
v3f fp = orp + vec * f;
fp.X += 0.1 * ps->range(-10, 10);
d1 += ps->range(-1, 1);
}
- bool should_make_cave_hole = ps->range(1, 10) == 1;
-
for (s16 z0 = d0; z0 <= d1; z0++) {
s16 si = rs / 2 - MYMAX(0, abs(z0) - rs / 7 - 1);
for (s16 x0 = -si - ps->range(0,1); x0 <= si - 1 + ps->range(0,1); x0++) {
s16 maxabsxz = MYMAX(abs(x0), abs(z0));
- s16 si2 = is_ravine ? MYMIN(ps->range(25, 26), ar.Y) :
- rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
+ s16 si2 = rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
for (s16 y0 = -si2; y0 <= si2; y0++) {
if (large_cave_is_flat) {
v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
p += of;
- if (!is_ravine && mg->heightmap && should_make_cave_hole &&
- p.X <= node_max.X && p.Z <= node_max.Z) {
- int maplen = node_max.X - node_min.X + 1;
- int idx = (p.Z - node_min.Z) * maplen +
- (p.X - node_min.X);
- if (p.Y >= mg->heightmap[idx] - 2)
- continue;
- }
-
if (vm->m_area.contains(p) == false)
continue;
///////////////////////////////////////// Caves V6
-CaveV6::CaveV6(MapgenV6 *mg, PseudoRandom *ps, PseudoRandom *ps2, bool is_large_cave) {
+CaveV6::CaveV6(MapgenV6 *mg, PseudoRandom *ps, PseudoRandom *ps2, bool is_large_cave)
+{
this->mg = mg;
this->vm = mg->vm;
this->ndef = mg->ndef;
}
-void CaveV6::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height) {
+void CaveV6::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height)
+{
node_min = nmin;
node_max = nmax;
max_stone_y = max_stone_height;
}
-void CaveV6::makeTunnel(bool dirswitch) {
+void CaveV6::makeTunnel(bool dirswitch)
+{
if (dirswitch && !large_cave) {
main_direction = v3f(
((float)(ps->next() % 20) - (float)10) / 10,
);
}
- // Do not make large caves that are entirely above ground.
+ // Do not make caves that are entirely above ground, to fix
+ // shadow bugs caused by overgenerated large caves.
// It is only necessary to check the startpoint and endpoint.
- if (large_cave) {
- v3s16 orpi(orp.X, orp.Y, orp.Z);
- v3s16 veci(vec.X, vec.Y, vec.Z);
- s16 h1;
- s16 h2;
-
- v3s16 p1 = orpi + veci + of + rs / 2;
- if (p1.Z >= node_min.Z && p1.Z <= node_max.Z &&
- p1.X >= node_min.X && p1.X <= node_max.X) {
- u32 index1 = (p1.Z - node_min.Z) * mg->ystride +
- (p1.X - node_min.X);
- h1 = mg->heightmap[index1];
- } else {
- h1 = water_level; // If not in heightmap
- }
-
- v3s16 p2 = orpi + of + rs / 2;
- if (p2.Z >= node_min.Z && p2.Z <= node_max.Z &&
- p2.X >= node_min.X && p2.X <= node_max.X) {
- u32 index2 = (p2.Z - node_min.Z) * mg->ystride +
- (p2.X - node_min.X);
- h2 = mg->heightmap[index2];
- } else {
- h2 = water_level;
- }
+ v3s16 orpi(orp.X, orp.Y, orp.Z);
+ v3s16 veci(vec.X, vec.Y, vec.Z);
+ s16 h1;
+ s16 h2;
+
+ v3s16 p1 = orpi + veci + of + rs / 2;
+ if (p1.Z >= node_min.Z && p1.Z <= node_max.Z &&
+ p1.X >= node_min.X && p1.X <= node_max.X) {
+ u32 index1 = (p1.Z - node_min.Z) * mg->ystride +
+ (p1.X - node_min.X);
+ h1 = mg->heightmap[index1];
+ } else {
+ h1 = water_level; // If not in heightmap
+ }
- if (p1.Y > h1 && p2.Y > h2) // If startpoint and endpoint are above ground
- return;
+ v3s16 p2 = orpi + of + rs / 2;
+ if (p2.Z >= node_min.Z && p2.Z <= node_max.Z &&
+ p2.X >= node_min.X && p2.X <= node_max.X) {
+ u32 index2 = (p2.Z - node_min.Z) * mg->ystride +
+ (p2.X - node_min.X);
+ h2 = mg->heightmap[index2];
+ } else {
+ h2 = water_level;
}
+ // If startpoint and endpoint are above ground,
+ // disable placing of nodes in carveRoute while
+ // still running all pseudorandom calls to ensure
+ // caves consistent with existing worlds.
+ bool tunnel_above_ground = p1.Y > h1 && p2.Y > h2;
+
vec += main_direction;
v3f rp = orp + vec;
// Carve routes
for (float f = 0; f < 1.0; f += 1.0 / veclen)
- carveRoute(vec, f, randomize_xz);
+ carveRoute(vec, f, randomize_xz, tunnel_above_ground);
orp = rp;
}
-void CaveV6::carveRoute(v3f vec, float f, bool randomize_xz) {
+void CaveV6::carveRoute(v3f vec, float f, bool randomize_xz, bool tunnel_above_ground)
+{
MapNode airnode(CONTENT_AIR);
MapNode waternode(c_water_source);
MapNode lavanode(c_lava_source);
for (s16 z0 = d0; z0 <= d1; z0++) {
s16 si = rs / 2 - MYMAX(0, abs(z0) - rs / 7 - 1);
for (s16 x0 = -si - ps->range(0,1); x0 <= si - 1 + ps->range(0,1); x0++) {
+ if (tunnel_above_ground)
+ continue;
+
s16 maxabsxz = MYMAX(abs(x0), abs(z0));
s16 si2 = rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
for (s16 y0 = -si2; y0 <= si2; y0++) {
///////////////////////////////////////// Caves V7
-CaveV7::CaveV7(MapgenV7 *mg, PseudoRandom *ps) {
+CaveV7::CaveV7(MapgenV7 *mg, PseudoRandom *ps)
+{
this->mg = mg;
this->vm = mg->vm;
this->ndef = mg->ndef;
}
-void CaveV7::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height) {
+void CaveV7::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height)
+{
node_min = nmin;
node_max = nmax;
max_stone_y = max_stone_height;
}
-void CaveV7::makeTunnel(bool dirswitch) {
-
+void CaveV7::makeTunnel(bool dirswitch)
+{
// Randomize size
s16 min_d = min_tunnel_diameter;
s16 max_d = max_tunnel_diameter;
(float)(ps->next() % maxlen.Z) - (float)maxlen.Z / 2
);
- // Do not make large caves that are above ground.
+ // Do not make caves that are above ground.
// It is only necessary to check the startpoint and endpoint.
v3s16 orpi(orp.X, orp.Y, orp.Z);
v3s16 veci(vec.X, vec.Y, vec.Z);
// Every second section is rough
bool randomize_xz = (ps->range(1, 2) == 1);
- // Make a ravine every once in a while if it's long enough
- //float xylen = vec.X * vec.X + vec.Z * vec.Z;
- //disable ravines for now
- bool is_ravine = false; //(xylen > 500.0) && !large_cave && (ps->range(1, 8) == 1);
-
// Carve routes
for (float f = 0; f < 1.0; f += 1.0 / veclen)
- carveRoute(vec, f, randomize_xz, is_ravine);
+ carveRoute(vec, f, randomize_xz);
orp = rp;
}
-void CaveV7::carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine) {
+void CaveV7::carveRoute(v3f vec, float f, bool randomize_xz)
+{
MapNode airnode(CONTENT_AIR);
MapNode waternode(c_water_source);
MapNode lavanode(c_lava_source);
d1 += ps->range(-1, 1);
}
- bool should_make_cave_hole = ps->range(1, 10) == 1;
-
for (s16 z0 = d0; z0 <= d1; z0++) {
s16 si = rs / 2 - MYMAX(0, abs(z0) - rs / 7 - 1);
for (s16 x0 = -si - ps->range(0,1); x0 <= si - 1 + ps->range(0,1); x0++) {
s16 maxabsxz = MYMAX(abs(x0), abs(z0));
- s16 si2 = is_ravine ? MYMIN(ps->range(25, 26), ar.Y) :
- rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
+ s16 si2 = rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
for (s16 y0 = -si2; y0 <= si2; y0++) {
if (large_cave_is_flat) {
v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
p += of;
- if (!is_ravine && mg->heightmap && should_make_cave_hole &&
- p.X <= node_max.X && p.Z <= node_max.Z) {
- int maplen = node_max.X - node_min.X + 1;
- int idx = (p.Z - node_min.Z) * maplen +
- (p.X - node_min.X);
- if (p.Y >= mg->heightmap[idx] - 2)
- continue;
- }
-
if (vm->m_area.contains(p) == false)
continue;
}
}
}
-