Skip to content

Commit

Permalink
Cavegen: Prevent caves from occuring above ground level, and superflu…
Browse files Browse the repository at this point in the history
…ous mixing of lava and water in caves
  • Loading branch information
kwolekr committed Jul 2, 2013
1 parent 8161ab5 commit fe4ce03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/cavegen.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/cavegen.h
Expand Up @@ -75,6 +75,8 @@ class CaveV7 {
ManualMapVoxelManipulator *vm;
INodeDefManager *ndef;

NoiseParams *np_caveliquids;

s16 min_tunnel_diameter;
s16 max_tunnel_diameter;
u16 tunnel_routepoints;
Expand Down

0 comments on commit fe4ce03

Please sign in to comment.