Cavegen: Prevent caves from occuring above ground level, and superfluous mixing of...
authorkwolekr <kwolekr@minetest.net>
Tue, 2 Jul 2013 01:10:59 +0000 (21:10 -0400)
committerkwolekr <kwolekr@minetest.net>
Tue, 2 Jul 2013 01:20:03 +0000 (21:20 -0400)
src/cavegen.cpp
src/cavegen.h

index 8e6798586b38edc802502b55f5b79a0ed1a46fbd..01149084b0690625a6a1def9456e0930a0f59c14 100644 (file)
@@ -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;
index 7822816d6abc9a828c0291ac29358d521860bd49..a908c61d83105ee9e28f981056d738fa865880b5 100644 (file)
@@ -75,6 +75,8 @@ public:
        ManualMapVoxelManipulator *vm;
        INodeDefManager *ndef;
 
+       NoiseParams *np_caveliquids;
+
        s16 min_tunnel_diameter;
        s16 max_tunnel_diameter;
        u16 tunnel_routepoints;