aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2013-07-01 21:10:59 -0400
committerkwolekr <kwolekr@minetest.net>2013-07-01 21:20:03 -0400
commitfe4ce03d529f70346b2e2c4872223ebdcd37fffa (patch)
tree9622bd00b4d607fdf36b71a04ac94f97525354db /src
parent8161ab573fd6f8a45b3986278ce7fc1596140526 (diff)
downloadminetest-fe4ce03d529f70346b2e2c4872223ebdcd37fffa.tar.gz
minetest-fe4ce03d529f70346b2e2c4872223ebdcd37fffa.tar.bz2
minetest-fe4ce03d529f70346b2e2c4872223ebdcd37fffa.zip
Cavegen: Prevent caves from occuring above ground level, and superfluous mixing of lava and water in caves
Diffstat (limited to 'src')
-rw-r--r--src/cavegen.cpp21
-rw-r--r--src/cavegen.h2
2 files changed, 21 insertions, 2 deletions
diff --git a/src/cavegen.cpp b/src/cavegen.cpp
index 8e6798586..01149084b 100644
--- a/src/cavegen.cpp
+++ b/src/cavegen.cpp
@@ -24,6 +24,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapgen_v7.h"
#include "cavegen.h"
+NoiseParams nparams_caveliquids =
+ {0, 1, v3f(150.0, 150.0, 150.0), 776, 3, 0.6};
+
+
+///////////////////////////////////////////////////////////////////////////////
+
CaveV6::CaveV6(MapgenV6 *mg, PseudoRandom *ps, PseudoRandom *ps2, bool is_large_cave) {
this->mg = mg;
@@ -269,6 +275,7 @@ CaveV7::CaveV7(MapgenV7 *mg, PseudoRandom *ps, bool is_large_cave) {
this->ps = ps;
this->c_water_source = mg->c_water_source;
this->c_lava_source = mg->c_lava_source;
+ this->np_caveliquids = &nparams_caveliquids;
dswitchint = ps->range(1, 14);
flooded = ps->range(1, 2) == 2;
@@ -303,7 +310,7 @@ void CaveV7::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height) {
// Allow a bit more
//(this should be more than the maximum radius of the tunnel)
s16 insure = 10;
- s16 more = MAP_BLOCKSIZE - max_tunnel_diameter / 2 - insure;
+ s16 more = MYMAX(MAP_BLOCKSIZE - max_tunnel_diameter / 2 - insure, 1);
ar += v3s16(1,0,1) * more * 2;
of -= v3s16(1,0,1) * more;
@@ -462,11 +469,14 @@ void CaveV7::carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine) {
MapNode airnode(CONTENT_AIR);
MapNode waternode(c_water_source);
MapNode lavanode(c_lava_source);
- MapNode liquidnode = ps->range(0, 4) ? lavanode : waternode;
v3s16 startp(orp.X, orp.Y, orp.Z);
startp += of;
+ float nval = NoisePerlin3D(np_caveliquids, startp.X,
+ startp.Y, startp.Z, mg->seed);
+ MapNode liquidnode = nval < 0.40 ? lavanode : waternode;
+
v3f fp = orp + vec * f;
fp.X += 0.1 * ps->range(-10, 10);
fp.Z += 0.1 * ps->range(-10, 10);
@@ -502,6 +512,13 @@ void CaveV7::carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine) {
v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
p += of;
+
+ if (!is_ravine && mg->heightmap) {
+ 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])
+ continue;
+ }
if (vm->m_area.contains(p) == false)
continue;
diff --git a/src/cavegen.h b/src/cavegen.h
index 7822816d6..a908c61d8 100644
--- a/src/cavegen.h
+++ b/src/cavegen.h
@@ -75,6 +75,8 @@ public:
ManualMapVoxelManipulator *vm;
INodeDefManager *ndef;
+ NoiseParams *np_caveliquids;
+
s16 min_tunnel_diameter;
s16 max_tunnel_diameter;
u16 tunnel_routepoints;