Skip to content

Commit

Permalink
Mapgen: Combine dungeon generation code
Browse files Browse the repository at this point in the history
  • Loading branch information
kwolekr committed May 28, 2016
1 parent 0810901 commit fd0efb2
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 324 deletions.
73 changes: 72 additions & 1 deletion src/mapgen.cpp
Expand Up @@ -40,6 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "filesys.h"
#include "log.h"
#include "cavegen.h"
#include "dungeongen.h"

FlagDesc flagdesc_mapgen[] = {
{"trees", MG_TREES},
Expand Down Expand Up @@ -414,13 +415,30 @@ MapgenBasic::MapgenBasic(int mapgenid, MapgenParams *params, EmergeManager *emer
c_sandstone = ndef->getId("mapgen_sandstone");
c_river_water_source = ndef->getId("mapgen_river_water_source");

//// Fall back to more basic content if not defined
// Fall back to more basic content if not defined
if (c_desert_stone == CONTENT_IGNORE)
c_desert_stone = c_stone;
if (c_sandstone == CONTENT_IGNORE)
c_sandstone = c_stone;
if (c_river_water_source == CONTENT_IGNORE)
c_river_water_source = c_water_source;

//// Content used for dungeon generation
c_cobble = ndef->getId("mapgen_cobble");
c_stair_cobble = ndef->getId("mapgen_stair_cobble");
c_mossycobble = ndef->getId("mapgen_mossycobble");
c_sandstonebrick = ndef->getId("mapgen_sandstonebrick");
c_stair_sandstonebrick = ndef->getId("mapgen_stair_sandstonebrick");

// Fall back to more basic content if not defined
if (c_mossycobble == CONTENT_IGNORE)
c_mossycobble = c_cobble;
if (c_stair_cobble == CONTENT_IGNORE)
c_stair_cobble = c_cobble;
if (c_sandstonebrick == CONTENT_IGNORE)
c_sandstonebrick = c_sandstone;
if (c_stair_sandstonebrick == CONTENT_IGNORE)
c_stair_sandstonebrick = c_sandstone;
}


Expand Down Expand Up @@ -614,6 +632,59 @@ void MapgenBasic::generateCaves(s16 max_stone_y, s16 large_cave_depth)
}


void MapgenBasic::generateDungeons(s16 max_stone_y, MgStoneType stone_type)
{
if (max_stone_y < node_min.Y)
return;

DungeonParams dp;

dp.np_rarity = nparams_dungeon_rarity;
dp.np_density = nparams_dungeon_density;
dp.np_wetness = nparams_dungeon_wetness;
dp.c_water = c_water_source;
switch (stone_type) {
default:
case MGSTONE_STONE:
dp.c_cobble = c_cobble;
dp.c_moss = c_mossycobble;
dp.c_stair = c_stair_cobble;

dp.diagonal_dirs = false;
dp.mossratio = 3.0;
dp.holesize = v3s16(1, 2, 1);
dp.roomsize = v3s16(0, 0, 0);
dp.notifytype = GENNOTIFY_DUNGEON;
break;
case MGSTONE_DESERT_STONE:
dp.c_cobble = c_desert_stone;
dp.c_moss = c_desert_stone;
dp.c_stair = c_desert_stone;

dp.diagonal_dirs = true;
dp.mossratio = 0.0;
dp.holesize = v3s16(2, 3, 2);
dp.roomsize = v3s16(2, 5, 2);
dp.notifytype = GENNOTIFY_TEMPLE;
break;
case MGSTONE_SANDSTONE:
dp.c_cobble = c_sandstonebrick;
dp.c_moss = c_sandstonebrick;
dp.c_stair = c_sandstonebrick;

dp.diagonal_dirs = false;
dp.mossratio = 0.0;
dp.holesize = v3s16(2, 2, 2);
dp.roomsize = v3s16(2, 0, 2);
dp.notifytype = GENNOTIFY_DUNGEON;
break;
}

DungeonGen dgen(this, &dp);
dgen.generate(blockseed, full_node_min, full_node_max);
}


////
//// GenerateNotifier
////
Expand Down
11 changes: 10 additions & 1 deletion src/mapgen.h
Expand Up @@ -219,9 +219,10 @@ class MapgenBasic : public Mapgen {
MapgenBasic(int mapgenid, MapgenParams *params, EmergeManager *emerge);
virtual ~MapgenBasic();

virtual void generateCaves(s16 max_stone_y, s16 large_cave_depth);
virtual void generateDungeons(s16 max_stone_y, MgStoneType stone_type);
virtual MgStoneType generateBiomes();
virtual void dustTopNodes();
virtual void generateCaves(s16 max_stone_y, s16 large_cave_depth);

protected:
EmergeManager *m_emerge;
Expand All @@ -234,12 +235,20 @@ class MapgenBasic : public Mapgen {
v3s16 full_node_min;
v3s16 full_node_max;

// Content required for generateBiomes
content_t c_stone;
content_t c_water_source;
content_t c_river_water_source;
content_t c_desert_stone;
content_t c_sandstone;

// Content required for generateDungeons
content_t c_cobble;
content_t c_stair_cobble;
content_t c_mossycobble;
content_t c_sandstonebrick;
content_t c_stair_sandstonebrick;

int ystride;
int zstride;
int zstride_1d;
Expand Down
61 changes: 2 additions & 59 deletions src/mapgen_flat.cpp
Expand Up @@ -69,23 +69,6 @@ MapgenFlat::MapgenFlat(int mapgenid, MapgenParams *params, EmergeManager *emerge

MapgenBasic::np_cave1 = sp->np_cave1;
MapgenBasic::np_cave2 = sp->np_cave2;

// Content used for dungeon generation
c_cobble = ndef->getId("mapgen_cobble");
c_stair_cobble = ndef->getId("mapgen_stair_cobble");
c_mossycobble = ndef->getId("mapgen_mossycobble");
c_sandstonebrick = ndef->getId("mapgen_sandstonebrick");
c_stair_sandstonebrick = ndef->getId("mapgen_stair_sandstonebrick");

// Fall back to more basic content if not defined
if (c_mossycobble == CONTENT_IGNORE)
c_mossycobble = c_cobble;
if (c_stair_cobble == CONTENT_IGNORE)
c_stair_cobble = c_cobble;
if (c_sandstonebrick == CONTENT_IGNORE)
c_sandstonebrick = c_sandstone;
if (c_stair_sandstonebrick == CONTENT_IGNORE)
c_stair_sandstonebrick = c_sandstone;
}


Expand Down Expand Up @@ -215,48 +198,8 @@ void MapgenFlat::makeChunk(BlockMakeData *data)
if (flags & MG_CAVES)
generateCaves(stone_surface_max_y, large_cave_depth);

if ((flags & MG_DUNGEONS) && (stone_surface_max_y >= node_min.Y)) {
DungeonParams dp;

dp.np_rarity = nparams_dungeon_rarity;
dp.np_density = nparams_dungeon_density;
dp.np_wetness = nparams_dungeon_wetness;
dp.c_water = c_water_source;
if (stone_type == MGSTONE_STONE) {
dp.c_cobble = c_cobble;
dp.c_moss = c_mossycobble;
dp.c_stair = c_stair_cobble;

dp.diagonal_dirs = false;
dp.mossratio = 3.0;
dp.holesize = v3s16(1, 2, 1);
dp.roomsize = v3s16(0, 0, 0);
dp.notifytype = GENNOTIFY_DUNGEON;
} else if (stone_type == MGSTONE_DESERT_STONE) {
dp.c_cobble = c_desert_stone;
dp.c_moss = c_desert_stone;
dp.c_stair = c_desert_stone;

dp.diagonal_dirs = true;
dp.mossratio = 0.0;
dp.holesize = v3s16(2, 3, 2);
dp.roomsize = v3s16(2, 5, 2);
dp.notifytype = GENNOTIFY_TEMPLE;
} else if (stone_type == MGSTONE_SANDSTONE) {
dp.c_cobble = c_sandstonebrick;
dp.c_moss = c_sandstonebrick;
dp.c_stair = c_sandstonebrick;

dp.diagonal_dirs = false;
dp.mossratio = 0.0;
dp.holesize = v3s16(2, 2, 2);
dp.roomsize = v3s16(2, 0, 2);
dp.notifytype = GENNOTIFY_DUNGEON;
}

DungeonGen dgen(this, &dp);
dgen.generate(blockseed, full_node_min, full_node_max);
}
if (flags & MG_DUNGEONS)
generateDungeons(stone_surface_max_y, stone_type);

// Generate the registered decorations
if (flags & MG_DECORATIONS)
Expand Down
6 changes: 0 additions & 6 deletions src/mapgen_flat.h
Expand Up @@ -70,12 +70,6 @@ class MapgenFlat : public MapgenBasic {
float hill_threshold;
float hill_steepness;
Noise *noise_terrain;

content_t c_cobble;
content_t c_stair_cobble;
content_t c_mossycobble;
content_t c_sandstonebrick;
content_t c_stair_sandstonebrick;
};

struct MapgenFactoryFlat : public MapgenFactory {
Expand Down
61 changes: 2 additions & 59 deletions src/mapgen_fractal.cpp
Expand Up @@ -73,23 +73,6 @@ MapgenFractal::MapgenFractal(int mapgenid, MapgenParams *params, EmergeManager *

this->formula = fractal / 2 + fractal % 2;
this->julia = fractal % 2 == 0;

// Content used for dungeon generation
c_cobble = ndef->getId("mapgen_cobble");
c_stair_cobble = ndef->getId("mapgen_stair_cobble");
c_mossycobble = ndef->getId("mapgen_mossycobble");
c_sandstonebrick = ndef->getId("mapgen_sandstonebrick");
c_stair_sandstonebrick = ndef->getId("mapgen_stair_sandstonebrick");

// Fall back to more basic content if not defined
if (c_mossycobble == CONTENT_IGNORE)
c_mossycobble = c_cobble;
if (c_stair_cobble == CONTENT_IGNORE)
c_stair_cobble = c_cobble;
if (c_sandstonebrick == CONTENT_IGNORE)
c_sandstonebrick = c_sandstone;
if (c_stair_sandstonebrick == CONTENT_IGNORE)
c_stair_sandstonebrick = c_sandstone;
}


Expand Down Expand Up @@ -231,48 +214,8 @@ void MapgenFractal::makeChunk(BlockMakeData *data)
if (flags & MG_CAVES)
generateCaves(stone_surface_max_y, MGFRACTAL_LARGE_CAVE_DEPTH);

if ((flags & MG_DUNGEONS) && (stone_surface_max_y >= node_min.Y)) {
DungeonParams dp;

dp.np_rarity = nparams_dungeon_rarity;
dp.np_density = nparams_dungeon_density;
dp.np_wetness = nparams_dungeon_wetness;
dp.c_water = c_water_source;
if (stone_type == MGSTONE_STONE) {
dp.c_cobble = c_cobble;
dp.c_moss = c_mossycobble;
dp.c_stair = c_stair_cobble;

dp.diagonal_dirs = false;
dp.mossratio = 3.0;
dp.holesize = v3s16(1, 2, 1);
dp.roomsize = v3s16(0, 0, 0);
dp.notifytype = GENNOTIFY_DUNGEON;
} else if (stone_type == MGSTONE_DESERT_STONE) {
dp.c_cobble = c_desert_stone;
dp.c_moss = c_desert_stone;
dp.c_stair = c_desert_stone;

dp.diagonal_dirs = true;
dp.mossratio = 0.0;
dp.holesize = v3s16(2, 3, 2);
dp.roomsize = v3s16(2, 5, 2);
dp.notifytype = GENNOTIFY_TEMPLE;
} else if (stone_type == MGSTONE_SANDSTONE) {
dp.c_cobble = c_sandstonebrick;
dp.c_moss = c_sandstonebrick;
dp.c_stair = c_sandstonebrick;

dp.diagonal_dirs = false;
dp.mossratio = 0.0;
dp.holesize = v3s16(2, 2, 2);
dp.roomsize = v3s16(2, 0, 2);
dp.notifytype = GENNOTIFY_DUNGEON;
}

DungeonGen dgen(this, &dp);
dgen.generate(blockseed, full_node_min, full_node_max);
}
if (flags & MG_DUNGEONS)
generateDungeons(stone_surface_max_y, stone_type);

// Generate the registered decorations
if (flags & MG_DECORATIONS)
Expand Down
6 changes: 0 additions & 6 deletions src/mapgen_fractal.h
Expand Up @@ -81,12 +81,6 @@ class MapgenFractal : public MapgenBasic {
float julia_z;
float julia_w;
Noise *noise_seabed;

content_t c_cobble;
content_t c_stair_cobble;
content_t c_mossycobble;
content_t c_sandstonebrick;
content_t c_stair_sandstonebrick;
};

struct MapgenFactoryFractal : public MapgenFactory {
Expand Down
61 changes: 2 additions & 59 deletions src/mapgen_v5.cpp
Expand Up @@ -64,23 +64,6 @@ MapgenV5::MapgenV5(int mapgenid, MapgenParams *params, EmergeManager *emerge)

MapgenBasic::np_cave1 = sp->np_cave1;
MapgenBasic::np_cave2 = sp->np_cave2;

// Content used for dungeon generation
c_cobble = ndef->getId("mapgen_cobble");
c_stair_cobble = ndef->getId("mapgen_stair_cobble");
c_mossycobble = ndef->getId("mapgen_mossycobble");
c_sandstonebrick = ndef->getId("mapgen_sandstonebrick");
c_stair_sandstonebrick = ndef->getId("mapgen_stair_sandstonebrick");

// Fall back to more basic content if not defined
if (c_mossycobble == CONTENT_IGNORE)
c_mossycobble = c_cobble;
if (c_stair_cobble == CONTENT_IGNORE)
c_stair_cobble = c_cobble;
if (c_sandstonebrick == CONTENT_IGNORE)
c_sandstonebrick = c_sandstone;
if (c_stair_sandstonebrick == CONTENT_IGNORE)
c_stair_sandstonebrick = c_sandstone;
}


Expand Down Expand Up @@ -215,48 +198,8 @@ void MapgenV5::makeChunk(BlockMakeData *data)
generateCaves(stone_surface_max_y, MGV5_LARGE_CAVE_DEPTH);

// Generate dungeons and desert temples
if ((flags & MG_DUNGEONS) && (stone_surface_max_y >= node_min.Y)) {
DungeonParams dp;

dp.np_rarity = nparams_dungeon_rarity;
dp.np_density = nparams_dungeon_density;
dp.np_wetness = nparams_dungeon_wetness;
dp.c_water = c_water_source;
if (stone_type == MGSTONE_STONE) {
dp.c_cobble = c_cobble;
dp.c_moss = c_mossycobble;
dp.c_stair = c_stair_cobble;

dp.diagonal_dirs = false;
dp.mossratio = 3.0;
dp.holesize = v3s16(1, 2, 1);
dp.roomsize = v3s16(0, 0, 0);
dp.notifytype = GENNOTIFY_DUNGEON;
} else if (stone_type == MGSTONE_DESERT_STONE) {
dp.c_cobble = c_desert_stone;
dp.c_moss = c_desert_stone;
dp.c_stair = c_desert_stone;

dp.diagonal_dirs = true;
dp.mossratio = 0.0;
dp.holesize = v3s16(2, 3, 2);
dp.roomsize = v3s16(2, 5, 2);
dp.notifytype = GENNOTIFY_TEMPLE;
} else if (stone_type == MGSTONE_SANDSTONE) {
dp.c_cobble = c_sandstonebrick;
dp.c_moss = c_sandstonebrick;
dp.c_stair = c_sandstonebrick;

dp.diagonal_dirs = false;
dp.mossratio = 0.0;
dp.holesize = v3s16(2, 2, 2);
dp.roomsize = v3s16(2, 0, 2);
dp.notifytype = GENNOTIFY_DUNGEON;
}

DungeonGen dgen(this, &dp);
dgen.generate(blockseed, full_node_min, full_node_max);
}
if (flags & MG_DUNGEONS)
generateDungeons(stone_surface_max_y, stone_type);

// Generate the registered decorations
if (flags & MG_DECORATIONS)
Expand Down
6 changes: 0 additions & 6 deletions src/mapgen_v5.h
Expand Up @@ -61,12 +61,6 @@ class MapgenV5 : public MapgenBasic {
Noise *noise_factor;
Noise *noise_height;
Noise *noise_ground;

content_t c_cobble;
content_t c_stair_cobble;
content_t c_mossycobble;
content_t c_sandstonebrick;
content_t c_stair_sandstonebrick;
};


Expand Down

0 comments on commit fd0efb2

Please sign in to comment.