Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Dungeons: Settable density noise, move number calculation to mapgens (#…
…8473)

Add user-settable noise parameters for dungeon density to each mapgen,
except V6 which hardcodes this noise parameter.

Move the calculation of number of dungeons generated in a mapchunk out
of dungeongen.cpp and into mapgen code, to allow mapgens to generate
any desired number of dungeons in a mapchunk, instead of being forced
to have number of dungeons determined by a density noise.

This is more flexible and allows mapgens to use dungeon generation to
create custom structures, such as occasional mega-dungeons.
  • Loading branch information
paramat committed Jun 1, 2019
1 parent a1459a9 commit 7379aa7
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 100 deletions.
18 changes: 18 additions & 0 deletions builtin/settingtypes.txt
Expand Up @@ -1417,6 +1417,9 @@ mgv5_np_cavern (Cavern noise) noise_params_3d 0, 1, (384, 128, 384), 723, 5, 0.6
# 3D noise defining terrain.
mgv5_np_ground (Ground noise) noise_params_3d 0, 40, (80, 80, 80), 983240, 4, 0.55, 2.0, eased

# 3D noise that determines number of dungeons per mapchunk.
mgv5_np_dungeons (Dungeon noise) noise_params_3d 0.9, 0.5, (500, 500, 500), 0, 2, 0.8, 2.0

[*Mapgen V6]

# Map generation attributes specific to Mapgen v6.
Expand Down Expand Up @@ -1569,6 +1572,9 @@ mgv7_np_cave1 (Cave1 noise) noise_params_3d 0, 12, (61, 61, 61), 52534, 3, 0.5,
# Second of two 3D noises that together define tunnels.
mgv7_np_cave2 (Cave2 noise) noise_params_3d 0, 12, (67, 67, 67), 10325, 3, 0.5, 2.0

# 3D noise that determines number of dungeons per mapchunk.
mgv7_np_dungeons (Dungeon noise) noise_params_3d 0.9, 0.5, (500, 500, 500), 0, 2, 0.8, 2.0

[*Mapgen Carpathian]

# Map generation attributes specific to Mapgen Carpathian.
Expand Down Expand Up @@ -1648,6 +1654,9 @@ mgcarpathian_np_cave2 (Cave2 noise) noise_params_3d 0, 12, (67, 67, 67), 10325,
# 3D noise defining giant caverns.
mgcarpathian_np_cavern (Cavern noise) noise_params_3d 0, 1, (384, 128, 384), 723, 5, 0.63, 2.0

# 3D noise that determines number of dungeons per mapchunk.
mgcarpathian_np_dungeons (Dungeon noise) noise_params_3d 0.9, 0.5, (500, 500, 500), 0, 2, 0.8, 2.0

[*Mapgen Flat]

# Map generation attributes specific to Mapgen flat.
Expand Down Expand Up @@ -1702,6 +1711,9 @@ mgflat_np_cave1 (Cave1 noise) noise_params_3d 0, 12, (61, 61, 61), 52534, 3, 0.5
# Second of two 3D noises that together define tunnels.
mgflat_np_cave2 (Cave2 noise) noise_params_3d 0, 12, (67, 67, 67), 10325, 3, 0.5, 2.0

# 3D noise that determines number of dungeons per mapchunk.
mgflat_np_dungeons (Dungeon noise) noise_params_3d 0.9, 0.5, (500, 500, 500), 0, 2, 0.8, 2.0

[*Mapgen Fractal]

# Controls width of tunnels, a smaller value creates wider tunnels.
Expand Down Expand Up @@ -1811,6 +1823,9 @@ mgfractal_np_cave1 (Cave1 noise) noise_params_3d 0, 12, (61, 61, 61), 52534, 3,
# Second of two 3D noises that together define tunnels.
mgfractal_np_cave2 (Cave2 noise) noise_params_3d 0, 12, (67, 67, 67), 10325, 3, 0.5, 2.0

# 3D noise that determines number of dungeons per mapchunk.
mgfractal_np_dungeons (Dungeon noise) noise_params_3d 0.9, 0.5, (500, 500, 500), 0, 2, 0.8, 2.0

[*Mapgen Valleys]

# Map generation attributes specific to Mapgen Valleys.
Expand Down Expand Up @@ -1888,6 +1903,9 @@ mgvalleys_np_valley_profile (Valley profile) noise_params_2d 0.6, 0.5, (512, 512
# Slope and fill work together to modify the heights.
mgvalleys_np_inter_valley_slope (Valley slope) noise_params_2d 0.5, 0.5, (128, 128, 128), 746, 1, 1.0, 2.0, eased

# 3D noise that determines number of dungeons per mapchunk.
mgvalleys_np_dungeons (Dungeon noise) noise_params_3d 0.9, 0.5, (500, 500, 500), 0, 2, 0.8, 2.0

[*Advanced]

# Size of mapchunks generated by mapgen, stated in mapblocks (16 nodes).
Expand Down
19 changes: 8 additions & 11 deletions src/mapgen/dungeongen.cpp
Expand Up @@ -31,9 +31,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,

//#define DGEN_USE_TORCHES

NoiseParams nparams_dungeon_density(0.9, 0.5, v3f(500.0, 500.0, 500.0), 0, 2, 0.8, 2.0);
NoiseParams nparams_dungeon_alt_wall(-0.4, 1.0, v3f(40.0, 40.0, 40.0), 32474, 6, 1.1, 2.0);


///////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -73,22 +70,22 @@ DungeonGen::DungeonGen(const NodeDefManager *ndef,
dp.rooms_max = 16;
dp.notifytype = GENNOTIFY_DUNGEON;

dp.np_density = nparams_dungeon_density;
dp.np_alt_wall = nparams_dungeon_alt_wall;
dp.np_alt_wall =
NoiseParams(-0.4, 1.0, v3f(40.0, 40.0, 40.0), 32474, 6, 1.1, 2.0);
}
}


void DungeonGen::generate(MMVManip *vm, u32 bseed, v3s16 nmin, v3s16 nmax)
void DungeonGen::generate(MMVManip *vm, u32 bseed, v3s16 nmin, v3s16 nmax,
u16 num_dungeons)
{
if (num_dungeons == 0)
return;

assert(vm);

//TimeTaker t("gen dungeons");

float nval_density = NoisePerlin3D(&dp.np_density, nmin.X, nmin.Y, nmin.Z, dp.seed);
if (nval_density < 1.0f)
return;

static const bool preserve_ignore = !g_settings->getBool("projecting_dungeons");

this->vm = vm;
Expand Down Expand Up @@ -122,7 +119,7 @@ void DungeonGen::generate(MMVManip *vm, u32 bseed, v3s16 nmin, v3s16 nmax)
}

// Add them
for (u32 i = 0; i < std::floor(nval_density); i++)
for (u32 i = 0; i < num_dungeons; i++)
makeDungeon(v3s16(1, 1, 1) * MAP_BLOCKSIZE);

// Optionally convert some structure to alternative structure
Expand Down
3 changes: 1 addition & 2 deletions src/mapgen/dungeongen.h
Expand Up @@ -58,7 +58,6 @@ struct DungeonParams {
u16 rooms_max;
GenNotifyType notifytype;

NoiseParams np_density;
NoiseParams np_alt_wall;
};

Expand All @@ -83,7 +82,7 @@ class DungeonGen {
GenerateNotifier *gennotify, DungeonParams *dparams);

void generate(MMVManip *vm, u32 bseed,
v3s16 full_node_min, v3s16 full_node_max);
v3s16 full_node_min, v3s16 full_node_max, u16 num_dungeons);

void makeDungeon(v3s16 start_padding);
void makeRoom(v3s16 roomsize, v3s16 roomplace);
Expand Down
12 changes: 9 additions & 3 deletions src/mapgen/mapgen.cpp
Expand Up @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <cmath>
#include "mapgen.h"
#include "voxel.h"
#include "noise.h"
Expand Down Expand Up @@ -889,6 +890,11 @@ void MapgenBasic::generateDungeons(s16 max_stone_y)
if (max_stone_y < node_min.Y)
return;

u16 num_dungeons = std::fmax(std::floor(
NoisePerlin3D(&np_dungeons, node_min.X, node_min.Y, node_min.Z, seed)), 0.0f);
if (num_dungeons == 0)
return;

// Get biome at mapchunk midpoint
v3s16 chunk_mid = node_min + (node_max - node_min) / v3s16(2, 2, 2);
Biome *biome = (Biome *)biomegen->getBiomeAtPoint(chunk_mid);
Expand All @@ -902,8 +908,8 @@ void MapgenBasic::generateDungeons(s16 max_stone_y)
dp.rooms_min = 2;
dp.rooms_max = 16;

dp.np_density = nparams_dungeon_density;
dp.np_alt_wall = nparams_dungeon_alt_wall;
dp.np_alt_wall =
NoiseParams(-0.4, 1.0, v3f(40.0, 40.0, 40.0), 32474, 6, 1.1, 2.0);

// Biome-defined dungeon nodes
if (biome->c_dungeon != CONTENT_IGNORE) {
Expand Down Expand Up @@ -980,7 +986,7 @@ void MapgenBasic::generateDungeons(s16 max_stone_y)
}

DungeonGen dgen(ndef, &gennotify, &dp);
dgen.generate(vm, blockseed, full_node_min, full_node_max);
dgen.generate(vm, blockseed, full_node_min, full_node_max, num_dungeons);
}


Expand Down
1 change: 1 addition & 0 deletions src/mapgen/mapgen.h
Expand Up @@ -283,6 +283,7 @@ class MapgenBasic : public Mapgen {
NoiseParams np_cave1;
NoiseParams np_cave2;
NoiseParams np_cavern;
NoiseParams np_dungeons;
float cave_width;
float cavern_limit;
float cavern_taper;
Expand Down
34 changes: 19 additions & 15 deletions src/mapgen/mapgen_carpathian.cpp
Expand Up @@ -88,6 +88,7 @@ MapgenCarpathian::MapgenCarpathian(MapgenCarpathianParams *params, EmergeManager
MapgenBasic::np_cave1 = params->np_cave1;
MapgenBasic::np_cave2 = params->np_cave2;
MapgenBasic::np_cavern = params->np_cavern;
MapgenBasic::np_dungeons = params->np_dungeons;
}


Expand All @@ -109,21 +110,22 @@ MapgenCarpathian::~MapgenCarpathian()


MapgenCarpathianParams::MapgenCarpathianParams():
np_filler_depth (0, 1, v3f(128, 128, 128), 261, 3, 0.7, 2.0),
np_height1 (0, 5, v3f(251, 251, 251), 9613, 5, 0.5, 2.0),
np_height2 (0, 5, v3f(383, 383, 383), 1949, 5, 0.5, 2.0),
np_height3 (0, 5, v3f(509, 509, 509), 3211, 5, 0.5, 2.0),
np_height4 (0, 5, v3f(631, 631, 631), 1583, 5, 0.5, 2.0),
np_hills_terrain (1, 1, v3f(1301, 1301, 1301), 1692, 5, 0.5, 2.0),
np_ridge_terrain (1, 1, v3f(1889, 1889, 1889), 3568, 5, 0.5, 2.0),
np_step_terrain (1, 1, v3f(1889, 1889, 1889), 4157, 5, 0.5, 2.0),
np_hills (0, 3, v3f(257, 257, 257), 6604, 6, 0.5, 2.0),
np_ridge_mnt (0, 12, v3f(743, 743, 743), 5520, 6, 0.7, 2.0),
np_step_mnt (0, 8, v3f(509, 509, 509), 2590, 6, 0.6, 2.0),
np_mnt_var (0, 1, v3f(499, 499, 499), 2490, 5, 0.55, 2.0),
np_cave1 (0, 12, v3f(61, 61, 61), 52534, 3, 0.5, 2.0),
np_cave2 (0, 12, v3f(67, 67, 67), 10325, 3, 0.5, 2.0),
np_cavern (0, 1, v3f(384, 128, 384), 723, 5, 0.63, 2.0)
np_filler_depth (0, 1, v3f(128, 128, 128), 261, 3, 0.7, 2.0),
np_height1 (0, 5, v3f(251, 251, 251), 9613, 5, 0.5, 2.0),
np_height2 (0, 5, v3f(383, 383, 383), 1949, 5, 0.5, 2.0),
np_height3 (0, 5, v3f(509, 509, 509), 3211, 5, 0.5, 2.0),
np_height4 (0, 5, v3f(631, 631, 631), 1583, 5, 0.5, 2.0),
np_hills_terrain (1, 1, v3f(1301, 1301, 1301), 1692, 5, 0.5, 2.0),
np_ridge_terrain (1, 1, v3f(1889, 1889, 1889), 3568, 5, 0.5, 2.0),
np_step_terrain (1, 1, v3f(1889, 1889, 1889), 4157, 5, 0.5, 2.0),
np_hills (0, 3, v3f(257, 257, 257), 6604, 6, 0.5, 2.0),
np_ridge_mnt (0, 12, v3f(743, 743, 743), 5520, 6, 0.7, 2.0),
np_step_mnt (0, 8, v3f(509, 509, 509), 2590, 6, 0.6, 2.0),
np_mnt_var (0, 1, v3f(499, 499, 499), 2490, 5, 0.55, 2.0),
np_cave1 (0, 12, v3f(61, 61, 61), 52534, 3, 0.5, 2.0),
np_cave2 (0, 12, v3f(67, 67, 67), 10325, 3, 0.5, 2.0),
np_cavern (0, 1, v3f(384, 128, 384), 723, 5, 0.63, 2.0),
np_dungeons (0.9, 0.5, v3f(500, 500, 500), 0, 2, 0.8, 2.0)
{
}

Expand Down Expand Up @@ -156,6 +158,7 @@ void MapgenCarpathianParams::readParams(const Settings *settings)
settings->getNoiseParams("mgcarpathian_np_cave1", np_cave1);
settings->getNoiseParams("mgcarpathian_np_cave2", np_cave2);
settings->getNoiseParams("mgcarpathian_np_cavern", np_cavern);
settings->getNoiseParams("mgcarpathian_np_dungeons", np_dungeons);
}


Expand Down Expand Up @@ -187,6 +190,7 @@ void MapgenCarpathianParams::writeParams(Settings *settings) const
settings->setNoiseParams("mgcarpathian_np_cave1", np_cave1);
settings->setNoiseParams("mgcarpathian_np_cave2", np_cave2);
settings->setNoiseParams("mgcarpathian_np_cavern", np_cavern);
settings->setNoiseParams("mgcarpathian_np_dungeons", np_dungeons);
}


Expand Down
1 change: 1 addition & 0 deletions src/mapgen/mapgen_carpathian.h
Expand Up @@ -60,6 +60,7 @@ struct MapgenCarpathianParams : public MapgenParams
NoiseParams np_cave1;
NoiseParams np_cave2;
NoiseParams np_cavern;
NoiseParams np_dungeons;

MapgenCarpathianParams();
~MapgenCarpathianParams() = default;
Expand Down
16 changes: 10 additions & 6 deletions src/mapgen/mapgen_flat.cpp
Expand Up @@ -69,8 +69,9 @@ MapgenFlat::MapgenFlat(MapgenFlatParams *params, EmergeManager *emerge)
if ((spflags & MGFLAT_LAKES) || (spflags & MGFLAT_HILLS))
noise_terrain = new Noise(&params->np_terrain, seed, csize.X, csize.Z);
// 3D noise
MapgenBasic::np_cave1 = params->np_cave1;
MapgenBasic::np_cave2 = params->np_cave2;
MapgenBasic::np_cave1 = params->np_cave1;
MapgenBasic::np_cave2 = params->np_cave2;
MapgenBasic::np_dungeons = params->np_dungeons;
}


Expand All @@ -84,10 +85,11 @@ MapgenFlat::~MapgenFlat()


MapgenFlatParams::MapgenFlatParams():
np_terrain (0, 1, v3f(600, 600, 600), 7244, 5, 0.6, 2.0),
np_filler_depth (0, 1.2, v3f(150, 150, 150), 261, 3, 0.7, 2.0),
np_cave1 (0, 12, v3f(61, 61, 61), 52534, 3, 0.5, 2.0),
np_cave2 (0, 12, v3f(67, 67, 67), 10325, 3, 0.5, 2.0)
np_terrain (0, 1, v3f(600, 600, 600), 7244, 5, 0.6, 2.0),
np_filler_depth (0, 1.2, v3f(150, 150, 150), 261, 3, 0.7, 2.0),
np_cave1 (0, 12, v3f(61, 61, 61), 52534, 3, 0.5, 2.0),
np_cave2 (0, 12, v3f(67, 67, 67), 10325, 3, 0.5, 2.0),
np_dungeons (0.9, 0.5, v3f(500, 500, 500), 0, 2, 0.8, 2.0)
{
}

Expand All @@ -110,6 +112,7 @@ void MapgenFlatParams::readParams(const Settings *settings)
settings->getNoiseParams("mgflat_np_filler_depth", np_filler_depth);
settings->getNoiseParams("mgflat_np_cave1", np_cave1);
settings->getNoiseParams("mgflat_np_cave2", np_cave2);
settings->getNoiseParams("mgflat_np_dungeons", np_dungeons);
}


Expand All @@ -131,6 +134,7 @@ void MapgenFlatParams::writeParams(Settings *settings) const
settings->setNoiseParams("mgflat_np_filler_depth", np_filler_depth);
settings->setNoiseParams("mgflat_np_cave1", np_cave1);
settings->setNoiseParams("mgflat_np_cave2", np_cave2);
settings->setNoiseParams("mgflat_np_dungeons", np_dungeons);
}


Expand Down
1 change: 1 addition & 0 deletions src/mapgen/mapgen_flat.h
Expand Up @@ -48,6 +48,7 @@ struct MapgenFlatParams : public MapgenParams
NoiseParams np_filler_depth;
NoiseParams np_cave1;
NoiseParams np_cave2;
NoiseParams np_dungeons;

MapgenFlatParams();
~MapgenFlatParams() = default;
Expand Down
10 changes: 7 additions & 3 deletions src/mapgen/mapgen_fractal.cpp
Expand Up @@ -70,8 +70,9 @@ MapgenFractal::MapgenFractal(MapgenFractalParams *params, EmergeManager *emerge)
noise_seabed = new Noise(&params->np_seabed, seed, csize.X, csize.Z);
noise_filler_depth = new Noise(&params->np_filler_depth, seed, csize.X, csize.Z);

MapgenBasic::np_cave1 = params->np_cave1;
MapgenBasic::np_cave2 = params->np_cave2;
MapgenBasic::np_cave1 = params->np_cave1;
MapgenBasic::np_cave2 = params->np_cave2;
MapgenBasic::np_dungeons = params->np_dungeons;

formula = fractal / 2 + fractal % 2;
julia = fractal % 2 == 0;
Expand All @@ -89,7 +90,8 @@ MapgenFractalParams::MapgenFractalParams():
np_seabed (-14, 9, v3f(600, 600, 600), 41900, 5, 0.6, 2.0),
np_filler_depth (0, 1.2, v3f(150, 150, 150), 261, 3, 0.7, 2.0),
np_cave1 (0, 12, v3f(61, 61, 61), 52534, 3, 0.5, 2.0),
np_cave2 (0, 12, v3f(67, 67, 67), 10325, 3, 0.5, 2.0)
np_cave2 (0, 12, v3f(67, 67, 67), 10325, 3, 0.5, 2.0),
np_dungeons (0.9, 0.5, v3f(500, 500, 500), 0, 2, 0.8, 2.0)
{
}

Expand All @@ -116,6 +118,7 @@ void MapgenFractalParams::readParams(const Settings *settings)
settings->getNoiseParams("mgfractal_np_filler_depth", np_filler_depth);
settings->getNoiseParams("mgfractal_np_cave1", np_cave1);
settings->getNoiseParams("mgfractal_np_cave2", np_cave2);
settings->getNoiseParams("mgfractal_np_dungeons", np_dungeons);
}


Expand All @@ -141,6 +144,7 @@ void MapgenFractalParams::writeParams(Settings *settings) const
settings->setNoiseParams("mgfractal_np_filler_depth", np_filler_depth);
settings->setNoiseParams("mgfractal_np_cave1", np_cave1);
settings->setNoiseParams("mgfractal_np_cave2", np_cave2);
settings->setNoiseParams("mgfractal_np_dungeons", np_dungeons);
}


Expand Down
1 change: 1 addition & 0 deletions src/mapgen/mapgen_fractal.h
Expand Up @@ -51,6 +51,7 @@ struct MapgenFractalParams : public MapgenParams
NoiseParams np_filler_depth;
NoiseParams np_cave1;
NoiseParams np_cave2;
NoiseParams np_dungeons;

MapgenFractalParams();
~MapgenFractalParams() = default;
Expand Down
24 changes: 14 additions & 10 deletions src/mapgen/mapgen_v5.cpp
Expand Up @@ -67,9 +67,10 @@ MapgenV5::MapgenV5(MapgenV5Params *params, EmergeManager *emerge)
// 1-up 1-down overgeneration
noise_ground = new Noise(&params->np_ground, seed, csize.X, csize.Y + 2, csize.Z);
// 1 down overgeneration
MapgenBasic::np_cave1 = params->np_cave1;
MapgenBasic::np_cave2 = params->np_cave2;
MapgenBasic::np_cavern = params->np_cavern;
MapgenBasic::np_cave1 = params->np_cave1;
MapgenBasic::np_cave2 = params->np_cave2;
MapgenBasic::np_cavern = params->np_cavern;
MapgenBasic::np_dungeons = params->np_dungeons;
}


Expand All @@ -83,13 +84,14 @@ MapgenV5::~MapgenV5()


MapgenV5Params::MapgenV5Params():
np_filler_depth (0, 1, v3f(150, 150, 150), 261, 4, 0.7, 2.0),
np_factor (0, 1, v3f(250, 250, 250), 920381, 3, 0.45, 2.0),
np_height (0, 10, v3f(250, 250, 250), 84174, 4, 0.5, 2.0),
np_ground (0, 40, v3f(80, 80, 80), 983240, 4, 0.55, 2.0, NOISE_FLAG_EASED),
np_cave1 (0, 12, v3f(61, 61, 61), 52534, 3, 0.5, 2.0),
np_cave2 (0, 12, v3f(67, 67, 67), 10325, 3, 0.5, 2.0),
np_cavern (0, 1, v3f(384, 128, 384), 723, 5, 0.63, 2.0)
np_filler_depth (0, 1, v3f(150, 150, 150), 261, 4, 0.7, 2.0),
np_factor (0, 1, v3f(250, 250, 250), 920381, 3, 0.45, 2.0),
np_height (0, 10, v3f(250, 250, 250), 84174, 4, 0.5, 2.0),
np_ground (0, 40, v3f(80, 80, 80), 983240, 4, 0.55, 2.0, NOISE_FLAG_EASED),
np_cave1 (0, 12, v3f(61, 61, 61), 52534, 3, 0.5, 2.0),
np_cave2 (0, 12, v3f(67, 67, 67), 10325, 3, 0.5, 2.0),
np_cavern (0, 1, v3f(384, 128, 384), 723, 5, 0.63, 2.0),
np_dungeons (0.9, 0.5, v3f(500, 500, 500), 0, 2, 0.8, 2.0)
{
}

Expand All @@ -113,6 +115,7 @@ void MapgenV5Params::readParams(const Settings *settings)
settings->getNoiseParams("mgv5_np_cave1", np_cave1);
settings->getNoiseParams("mgv5_np_cave2", np_cave2);
settings->getNoiseParams("mgv5_np_cavern", np_cavern);
settings->getNoiseParams("mgv5_np_dungeons", np_dungeons);
}


Expand All @@ -135,6 +138,7 @@ void MapgenV5Params::writeParams(Settings *settings) const
settings->setNoiseParams("mgv5_np_cave1", np_cave1);
settings->setNoiseParams("mgv5_np_cave2", np_cave2);
settings->setNoiseParams("mgv5_np_cavern", np_cavern);
settings->setNoiseParams("mgv5_np_dungeons", np_dungeons);
}


Expand Down

0 comments on commit 7379aa7

Please sign in to comment.