Skip to content
Permalink
Browse files

Settings: Add get_flags API for mapgen flags (mg_flags, mgv6_spflags,…

… ...) (#9284)

Unified flags handling in C++ and Lua Settings API
     -> Reading only, for now. Writing can be implemented later, if needed.
API function to read the currently active flags
     -> was impossible from Lua

Co-authored-by: Wuzzy <wuzzy2@mail.ru>
  • Loading branch information
SmallJoker and Wuzzy2 committed Jan 25, 2020
1 parent 9cb3219 commit cde2a7f6f24f638421238ead4e61b155322fefc8
@@ -6069,6 +6069,10 @@ It can be created via `Settings(filename)`.
* `default` is the value returned if `key` is not found.
* Returns `nil` if `key` is not found and `default` not specified.
* `get_np_group(key)`: returns a NoiseParams table
* `get_flags(key)`:
* Returns `{flag = true/false, ...}` according to the set flags.
* Is currently limited to mapgen flags `mg_flags` and mapgen-specific
flags like `mgv5_spflags`.
* `set(key, value)`
* Setting names can't contain whitespace or any of `="{}#`.
* Setting values can't contain the sequence `\n"""`.
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "config.h"
#include "constants.h"
#include "porting.h"
#include "mapgen/mapgen.h" // Mapgen::setDefaultSettings
#include "util/string.h"

void set_default_settings(Settings *settings)
@@ -426,10 +427,10 @@ void set_default_settings(Settings *settings)
settings->setDefault("water_level", "1");
settings->setDefault("mapgen_limit", "31000");
settings->setDefault("chunksize", "5");
settings->setDefault("mg_flags", "caves,dungeons,light,decorations,biomes");
settings->setDefault("fixed_map_seed", "");
settings->setDefault("max_block_generate_distance", "8");
settings->setDefault("enable_mapgen_debug_info", "false");
Mapgen::setDefaultSettings(settings);

// Server list announcing
settings->setDefault("server_announce", "false");
@@ -215,6 +215,17 @@ void Mapgen::getMapgenNames(std::vector<const char *> *mgnames, bool include_hid
}
}

void Mapgen::setDefaultSettings(Settings *settings)
{
settings->setDefault("mg_flags", flagdesc_mapgen,
MG_CAVES | MG_DUNGEONS | MG_LIGHT | MG_DECORATIONS | MG_BIOMES);

for (int i = 0; i < (int)MAPGEN_INVALID; ++i) {
MapgenParams *params = createMapgenParams((MapgenType)i);
params->setDefaultSettings(settings);
delete params;
}
}

u32 Mapgen::getBlockSeed(v3s16 p, s32 seed)
{
@@ -1068,7 +1079,7 @@ void MapgenParams::writeParams(Settings *settings) const
settings->setS16("water_level", water_level);
settings->setS16("mapgen_limit", mapgen_limit);
settings->setS16("chunksize", chunksize);
settings->setFlagStr("mg_flags", flags, flagdesc_mapgen, U32_MAX);
settings->setFlagStr("mg_flags", flags, flagdesc_mapgen);

if (bparams)
bparams->writeParams(settings);
@@ -124,7 +124,9 @@ struct MapgenParams {
u64 seed = 0;
s16 water_level = 1;
s16 mapgen_limit = MAX_MAP_GENERATION_LIMIT;
u32 flags = MG_CAVES | MG_LIGHT | MG_DECORATIONS | MG_BIOMES;
// Flags set in readParams
u32 flags = 0;
u32 spflags = 0;

BiomeParams *bparams = nullptr;

@@ -133,6 +135,8 @@ struct MapgenParams {

virtual void readParams(const Settings *settings);
virtual void writeParams(Settings *settings) const;
// Default settings for g_settings such as flags
virtual void setDefaultSettings(Settings *settings) {};

s32 getSpawnRangeMax();

@@ -214,6 +218,7 @@ class Mapgen {
EmergeManager *emerge);
static MapgenParams *createMapgenParams(MapgenType mgtype);
static void getMapgenNames(std::vector<const char *> *mgnames, bool include_hidden);
static void setDefaultSettings(Settings *settings);

private:
// isLiquidHorizontallyFlowable() is a helper function for updateLiquid()
@@ -187,7 +187,7 @@ void MapgenCarpathianParams::readParams(const Settings *settings)

void MapgenCarpathianParams::writeParams(Settings *settings) const
{
settings->setFlagStr("mgcarpathian_spflags", spflags, flagdesc_mapgen_carpathian, U32_MAX);
settings->setFlagStr("mgcarpathian_spflags", spflags, flagdesc_mapgen_carpathian);

settings->setFloat("mgcarpathian_base_level", base_level);
settings->setFloat("mgcarpathian_river_width", river_width);
@@ -227,6 +227,12 @@ void MapgenCarpathianParams::writeParams(Settings *settings) const
}


void MapgenCarpathianParams::setDefaultSettings(Settings *settings)
{
settings->setDefault("mgcarpathian_spflags", flagdesc_mapgen_carpathian,
MGCARPATHIAN_CAVERNS);
}

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


@@ -37,7 +37,6 @@ struct MapgenCarpathianParams : public MapgenParams
float river_depth = 24.0f;
float valley_width = 0.25f;

u32 spflags = MGCARPATHIAN_CAVERNS;
float cave_width = 0.09f;
s16 large_cave_depth = -33;
u16 small_cave_num_min = 0;
@@ -74,6 +73,7 @@ struct MapgenCarpathianParams : public MapgenParams

void readParams(const Settings *settings);
void writeParams(Settings *settings) const;
void setDefaultSettings(Settings *settings);
};

class MapgenCarpathian : public MapgenBasic
@@ -126,7 +126,7 @@ void MapgenFlatParams::readParams(const Settings *settings)

void MapgenFlatParams::writeParams(Settings *settings) const
{
settings->setFlagStr("mgflat_spflags", spflags, flagdesc_mapgen_flat, U32_MAX);
settings->setFlagStr("mgflat_spflags", spflags, flagdesc_mapgen_flat);
settings->setS16("mgflat_ground_level", ground_level);
settings->setS16("mgflat_large_cave_depth", large_cave_depth);
settings->setU16("mgflat_small_cave_num_min", small_cave_num_min);
@@ -150,6 +150,12 @@ void MapgenFlatParams::writeParams(Settings *settings) const
}


void MapgenFlatParams::setDefaultSettings(Settings *settings)
{
settings->setDefault("mgflat_spflags", flagdesc_mapgen_flat, 0);
}


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


@@ -32,7 +32,6 @@ extern FlagDesc flagdesc_mapgen_flat[];

struct MapgenFlatParams : public MapgenParams
{
u32 spflags = 0;
s16 ground_level = 8;
s16 large_cave_depth = -33;
u16 small_cave_num_min = 0;
@@ -59,6 +58,7 @@ struct MapgenFlatParams : public MapgenParams

void readParams(const Settings *settings);
void writeParams(Settings *settings) const;
void setDefaultSettings(Settings *settings);
};

class MapgenFlat : public MapgenBasic
@@ -139,7 +139,7 @@ void MapgenFractalParams::readParams(const Settings *settings)

void MapgenFractalParams::writeParams(Settings *settings) const
{
settings->setFlagStr("mgfractal_spflags", spflags, flagdesc_mapgen_fractal, U32_MAX);
settings->setFlagStr("mgfractal_spflags", spflags, flagdesc_mapgen_fractal);
settings->setFloat("mgfractal_cave_width", cave_width);
settings->setS16("mgfractal_large_cave_depth", large_cave_depth);
settings->setU16("mgfractal_small_cave_num_min", small_cave_num_min);
@@ -167,6 +167,13 @@ void MapgenFractalParams::writeParams(Settings *settings) const
}


void MapgenFractalParams::setDefaultSettings(Settings *settings)
{
settings->setDefault("mgfractal_spflags", flagdesc_mapgen_fractal,
MGFRACTAL_TERRAIN);
}


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


@@ -35,7 +35,6 @@ extern FlagDesc flagdesc_mapgen_fractal[];

struct MapgenFractalParams : public MapgenParams
{
u32 spflags = MGFRACTAL_TERRAIN;
float cave_width = 0.09f;
s16 large_cave_depth = -33;
u16 small_cave_num_min = 0;
@@ -66,6 +65,7 @@ struct MapgenFractalParams : public MapgenParams

void readParams(const Settings *settings);
void writeParams(Settings *settings) const;
void setDefaultSettings(Settings *settings);
};


@@ -129,7 +129,7 @@ void MapgenV5Params::readParams(const Settings *settings)

void MapgenV5Params::writeParams(Settings *settings) const
{
settings->setFlagStr("mgv5_spflags", spflags, flagdesc_mapgen_v5, U32_MAX);
settings->setFlagStr("mgv5_spflags", spflags, flagdesc_mapgen_v5);
settings->setFloat("mgv5_cave_width", cave_width);
settings->setS16("mgv5_large_cave_depth", large_cave_depth);
settings->setU16("mgv5_small_cave_num_min", small_cave_num_min);
@@ -154,6 +154,15 @@ void MapgenV5Params::writeParams(Settings *settings) const
}


void MapgenV5Params::setDefaultSettings(Settings *settings)
{
settings->setDefault("mgv5_spflags", flagdesc_mapgen_v5, MGV5_CAVERNS);
}


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


int MapgenV5::getSpawnLevelAtPoint(v2s16 p)
{

@@ -31,7 +31,6 @@ extern FlagDesc flagdesc_mapgen_v5[];

struct MapgenV5Params : public MapgenParams
{
u32 spflags = MGV5_CAVERNS;
float cave_width = 0.09f;
s16 large_cave_depth = -256;
u16 small_cave_num_min = 0;
@@ -59,6 +58,7 @@ struct MapgenV5Params : public MapgenParams

void readParams(const Settings *settings);
void writeParams(Settings *settings) const;
void setDefaultSettings(Settings *settings);
};

class MapgenV5 : public MapgenBasic
@@ -190,7 +190,7 @@ void MapgenV6Params::readParams(const Settings *settings)

void MapgenV6Params::writeParams(Settings *settings) const
{
settings->setFlagStr("mgv6_spflags", spflags, flagdesc_mapgen_v6, U32_MAX);
settings->setFlagStr("mgv6_spflags", spflags, flagdesc_mapgen_v6);
settings->setFloat("mgv6_freq_desert", freq_desert);
settings->setFloat("mgv6_freq_beach", freq_beach);
settings->setS16("mgv6_dungeon_ymin", dungeon_ymin);
@@ -210,8 +210,16 @@ void MapgenV6Params::writeParams(Settings *settings) const
}


void MapgenV6Params::setDefaultSettings(Settings *settings)
{
settings->setDefault("mgv6_spflags", flagdesc_mapgen_v6, MGV6_JUNGLES |
MGV6_SNOWBIOMES | MGV6_TREES | MGV6_BIOMEBLEND | MGV6_MUDFLOW);
}


//////////////////////// Some helper functions for the map generator


// Returns Y one under area minimum if not found
s16 MapgenV6::find_stone_level(v2s16 p2d)
{
@@ -55,8 +55,6 @@ enum BiomeV6Type


struct MapgenV6Params : public MapgenParams {
u32 spflags = MGV6_JUNGLES | MGV6_SNOWBIOMES | MGV6_TREES |
MGV6_BIOMEBLEND | MGV6_MUDFLOW;
float freq_desert = 0.45f;
float freq_beach = 0.15f;
s16 dungeon_ymin = -31000;
@@ -79,6 +77,7 @@ struct MapgenV6Params : public MapgenParams {

void readParams(const Settings *settings);
void writeParams(Settings *settings) const;
void setDefaultSettings(Settings *settings);
};


@@ -183,7 +183,7 @@ void MapgenV7Params::readParams(const Settings *settings)

void MapgenV7Params::writeParams(Settings *settings) const
{
settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7, U32_MAX);
settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7);
settings->setS16("mgv7_mount_zero_level", mount_zero_level);
settings->setFloat("mgv7_cave_width", cave_width);
settings->setS16("mgv7_large_cave_depth", large_cave_depth);
@@ -214,6 +214,13 @@ void MapgenV7Params::writeParams(Settings *settings) const
}


void MapgenV7Params::setDefaultSettings(Settings *settings)
{
settings->setDefault("mgv7_spflags", flagdesc_mapgen_v7,
MGV7_MOUNTAINS | MGV7_RIDGES | MGV7_CAVERNS);
}


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


@@ -35,7 +35,6 @@ extern FlagDesc flagdesc_mapgen_v7[];


struct MapgenV7Params : public MapgenParams {
u32 spflags = MGV7_MOUNTAINS | MGV7_RIDGES | MGV7_CAVERNS;
s16 mount_zero_level = 0;

float cave_width = 0.09f;
@@ -70,6 +69,7 @@ struct MapgenV7Params : public MapgenParams {

void readParams(const Settings *settings);
void writeParams(Settings *settings) const;
void setDefaultSettings(Settings *settings);
};


@@ -162,7 +162,7 @@ void MapgenValleysParams::readParams(const Settings *settings)

void MapgenValleysParams::writeParams(Settings *settings) const
{
settings->setFlagStr("mgvalleys_spflags", spflags, flagdesc_mapgen_valleys, U32_MAX);
settings->setFlagStr("mgvalleys_spflags", spflags, flagdesc_mapgen_valleys);
settings->setU16("mgvalleys_altitude_chill", altitude_chill);
settings->setS16("mgvalleys_large_cave_depth", large_cave_depth);
settings->setU16("mgvalleys_small_cave_num_min", small_cave_num_min);
@@ -194,6 +194,17 @@ void MapgenValleysParams::writeParams(Settings *settings) const
}


void MapgenValleysParams::setDefaultSettings(Settings *settings)
{
settings->setDefault("mgvalleys_spflags", flagdesc_mapgen_valleys,
MGVALLEYS_ALT_CHILL | MGVALLEYS_HUMID_RIVERS |
MGVALLEYS_VARY_RIVER_DEPTH | MGVALLEYS_ALT_DRY);
}


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


void MapgenValleys::makeChunk(BlockMakeData *data)
{
// Pre-conditions
@@ -41,8 +41,6 @@ extern FlagDesc flagdesc_mapgen_valleys[];


struct MapgenValleysParams : public MapgenParams {
u32 spflags = MGVALLEYS_ALT_CHILL | MGVALLEYS_HUMID_RIVERS |
MGVALLEYS_VARY_RIVER_DEPTH | MGVALLEYS_ALT_DRY;
u16 altitude_chill = 90;
u16 river_depth = 4;
u16 river_size = 5;
@@ -78,6 +76,7 @@ struct MapgenValleysParams : public MapgenParams {

void readParams(const Settings *settings);
void writeParams(Settings *settings) const;
void setDefaultSettings(Settings *settings);
};


0 comments on commit cde2a7f

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