Skip to content
Permalink
Browse files

Mapgen: Combine dungeon generation code

  • Loading branch information...
kwolekr committed May 22, 2016
1 parent 0810901 commit fd0efb21c3d40a963a813d73a09bb80df625b247
Showing with 94 additions and 324 deletions.
  1. +72 −1 src/mapgen.cpp
  2. +10 −1 src/mapgen.h
  3. +2 −59 src/mapgen_flat.cpp
  4. +0 −6 src/mapgen_flat.h
  5. +2 −59 src/mapgen_fractal.cpp
  6. +0 −6 src/mapgen_fractal.h
  7. +2 −59 src/mapgen_v5.cpp
  8. +0 −6 src/mapgen_v5.h
  9. +2 −59 src/mapgen_v7.cpp
  10. +0 −6 src/mapgen_v7.h
  11. +4 −57 src/mapgen_valleys.cpp
  12. +0 −5 src/mapgen_valleys.h
@@ -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},
@@ -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;
}


@@ -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
////
@@ -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;
@@ -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;
@@ -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;
}


@@ -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)
@@ -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 {
@@ -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;
}


@@ -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)
@@ -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 {
@@ -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;
}


@@ -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)
@@ -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;
};


Oops, something went wrong.

0 comments on commit fd0efb2

Please sign in to comment.
You can’t perform that action at this time.