Mgvalleys: Make river depth variation and humidity drop optional (#7532)

Add 2 new mapgen flags to make river depth variation and humidity drop
with altitude independently optional, instead of both being enabled by
the 'humid rivers' flag.

Simplify and clarify related code by removing a low priority
optimisation regarding 't_heat'.
Remove unnecessary optimisation bools and use spflags directly instead.
Improve and fix documentation in settingtypes.txt.
A few minor code cleanups.
This commit is contained in:
Paramat 2018-07-18 03:34:05 +01:00 committed by GitHub
parent ade7a1cbcf
commit bc9bb63aed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 58 deletions

@ -1760,14 +1760,16 @@ mgfractal_np_cave2 (Cave2 noise) noise_params_3d 0, 12, (67, 67, 67), 10325, 3,
[*Mapgen Valleys] [*Mapgen Valleys]
# Map generation attributes specific to Mapgen Valleys. # Map generation attributes specific to Mapgen Valleys.
# 'altitude_chill' makes higher elevations colder, which may cause biome issues. # 'altitude_chill': Reduces heat with altitude.
# 'humid_rivers' modifies the humidity around rivers and in areas where water would tend to pool, # 'humid_rivers': Increases humidity around rivers and where water pools.
# it may interfere with delicately adjusted biomes. # 'vary_river_depth': If enabled, low humidity and high heat causes rivers
# Flags that are not enabled are not modified from the default. # to become shallower and occasionally dry.
# Flags starting with 'no' are used to explicitly disable them. # 'altitude_dry': Reduces humidity with altitude.
mgvalleys_spflags (Mapgen Valleys specific flags) flags altitude_chill,humid_rivers altitude_chill,noaltitude_chill,humid_rivers,nohumid_rivers mgvalleys_spflags (Mapgen Valleys specific flags) flags altitude_chill,humid_rivers,vary_river_depth,altitude_dry altitude_chill,noaltitude_chill,humid_rivers,nohumid_rivers,vary_river_depth,novary_river_depth,altitude_dry,noaltitude_dry
# The altitude at which temperature drops by 20. # The vertical distance over which heat drops by 20 if 'altitude_chill' is
# enabled. Also the vertical distance over which humidity drops by 10 if
# 'altitude_dry' is enabled.
mgvalleys_altitude_chill (Altitude chill) int 90 mgvalleys_altitude_chill (Altitude chill) int 90
# Depth below which you'll find large caves. # Depth below which you'll find large caves.

@ -44,10 +44,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <cmath> #include <cmath>
static FlagDesc flagdesc_mapgen_valleys[] = { FlagDesc flagdesc_mapgen_valleys[] = {
{"altitude_chill", MGVALLEYS_ALT_CHILL}, {"altitude_chill", MGVALLEYS_ALT_CHILL},
{"humid_rivers", MGVALLEYS_HUMID_RIVERS}, {"humid_rivers", MGVALLEYS_HUMID_RIVERS},
{NULL, 0} {"vary_river_depth", MGVALLEYS_VARY_RIVER_DEPTH},
{"altitude_dry", MGVALLEYS_ALT_DRY},
{NULL, 0}
}; };
@ -94,8 +96,6 @@ MapgenValleys::MapgenValleys(int mapgenid, MapgenValleysParams *params,
MapgenBasic::np_cave2 = params->np_cave2; MapgenBasic::np_cave2 = params->np_cave2;
MapgenBasic::np_cavern = params->np_cavern; MapgenBasic::np_cavern = params->np_cavern;
humid_rivers = (spflags & MGVALLEYS_HUMID_RIVERS);
use_altitude_chill = (spflags & MGVALLEYS_ALT_CHILL);
humidity_adjust = bp->np_humidity.offset - 50.0f; humidity_adjust = bp->np_humidity.offset - 50.0f;
} }
@ -298,10 +298,10 @@ void MapgenValleys::calculateNoise()
float heat_offset = 0.0f; float heat_offset = 0.0f;
float humidity_scale = 1.0f; float humidity_scale = 1.0f;
// Altitude chill tends to reduce the average heat. // Altitude chill tends to reduce the average heat.
if (use_altitude_chill) if (spflags & MGVALLEYS_ALT_CHILL)
heat_offset = 5.0f; heat_offset = 5.0f;
// River humidity tends to increase the humidity range. // River humidity tends to increase the humidity range.
if (humid_rivers) if (spflags & MGVALLEYS_HUMID_RIVERS)
humidity_scale = 0.8f; humidity_scale = 0.8f;
for (s32 index = 0; index < csize.X * csize.Z; index++) { for (s32 index = 0; index < csize.X * csize.Z; index++) {
@ -477,17 +477,16 @@ int MapgenValleys::generateTerrain()
if (surface_y > surface_max_y) if (surface_y > surface_max_y)
surface_max_y = std::ceil(surface_y); surface_max_y = std::ceil(surface_y);
if (humid_rivers) { // Optionally vary river depth according to heat and humidity
// Derive heat from (base) altitude. This will be most correct if (spflags & MGVALLEYS_VARY_RIVER_DEPTH) {
// at rivers, since other surface heights may vary below. float heat = ((spflags & MGVALLEYS_ALT_CHILL) &&
if (use_altitude_chill && (surface_y > 0.0f || river_y > 0.0f)) (surface_y > 0.0f || river_y > 0.0f)) ?
t_heat -= alt_to_heat * t_heat - alt_to_heat *
std::fmax(surface_y, river_y) / altitude_chill; std::fmax(surface_y, river_y) / altitude_chill :
t_heat;
// If humidity is low or heat is high, lower the water table
float delta = m_bgen->humidmap[index_2d] - 50.0f; float delta = m_bgen->humidmap[index_2d] - 50.0f;
if (delta < 0.0f) { if (delta < 0.0f) {
float t_evap = (t_heat - 32.0f) / evaporation; float t_evap = (heat - 32.0f) / evaporation;
river_y += delta * std::fmax(t_evap, 0.08f); river_y += delta * std::fmax(t_evap, 0.08f);
} }
} }
@ -534,33 +533,32 @@ int MapgenValleys::generateTerrain()
} }
} }
if (humid_rivers) { // Optionally increase humidity around rivers
// Use base ground (water table) in a riverbed, to avoid an if (spflags & MGVALLEYS_HUMID_RIVERS) {
// unnatural rise in humidity.
float t_alt = std::fmax(noise_rivers->result[index_2d],
(float)heightmap[index_2d]);
float humid = m_bgen->humidmap[index_2d];
float water_depth = (t_alt - river_y) / humidity_dropoff;
humid *= 1.0f + std::pow(0.5f, std::fmax(water_depth, 1.0f));
// Reduce humidity with altitude (ignoring riverbeds)
if (t_alt > 0.0f)
humid -= alt_to_humid * t_alt / altitude_chill;
m_bgen->humidmap[index_2d] = humid;
}
// Assign the heat adjusted by any changed altitudes.
// The altitude will change about half the time.
if (use_altitude_chill) {
// Ground height ignoring riverbeds // Ground height ignoring riverbeds
float t_alt = std::fmax(noise_rivers->result[index_2d], float t_alt = std::fmax(noise_rivers->result[index_2d],
(float)heightmap[index_2d]); (float)heightmap[index_2d]);
float water_depth = (t_alt - river_y) / humidity_dropoff;
m_bgen->humidmap[index_2d] *=
1.0f + std::pow(0.5f, std::fmax(water_depth, 1.0f));
}
if (humid_rivers && heightmap[index_2d] == (s16)myround(surface_y)) // Optionally decrease humidity with altitude
// The altitude hasn't changed. Use the first result if (spflags & MGVALLEYS_ALT_DRY) {
m_bgen->heatmap[index_2d] = t_heat; // Ground height ignoring riverbeds
else if (t_alt > 0.0f) float t_alt = std::fmax(noise_rivers->result[index_2d],
(float)heightmap[index_2d]);
if (t_alt > 0.0f)
m_bgen->humidmap[index_2d] -=
alt_to_humid * t_alt / altitude_chill;
}
// Optionally decrease heat with altitude
if (spflags & MGVALLEYS_ALT_CHILL) {
// Ground height ignoring riverbeds
float t_alt = std::fmax(noise_rivers->result[index_2d],
(float)heightmap[index_2d]);
if (t_alt > 0.0f)
m_bgen->heatmap[index_2d] -= m_bgen->heatmap[index_2d] -=
alt_to_heat * t_alt / altitude_chill; alt_to_heat * t_alt / altitude_chill;
} }

@ -28,9 +28,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapgen.h" #include "mapgen.h"
////////////// Mapgen Valleys flags /////////////////// Mapgen Valleys flags
#define MGVALLEYS_ALT_CHILL 0x01 #define MGVALLEYS_ALT_CHILL 0x01
#define MGVALLEYS_HUMID_RIVERS 0x02 #define MGVALLEYS_HUMID_RIVERS 0x02
#define MGVALLEYS_VARY_RIVER_DEPTH 0x04
#define MGVALLEYS_ALT_DRY 0x08
// Feed only one variable into these // Feed only one variable into these
#define MYSQUARE(x) (x) * (x) #define MYSQUARE(x) (x) * (x)
@ -39,12 +41,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class BiomeManager; class BiomeManager;
class BiomeGenOriginal; class BiomeGenOriginal;
extern FlagDesc flagdesc_mapgen_valleys[];
struct MapgenValleysParams : public MapgenParams { struct MapgenValleysParams : public MapgenParams {
u32 spflags = MGVALLEYS_HUMID_RIVERS | MGVALLEYS_ALT_CHILL; u32 spflags = MGVALLEYS_ALT_CHILL | MGVALLEYS_HUMID_RIVERS |
u16 altitude_chill = 90; // The altitude at which temperature drops by 20C MGVALLEYS_VARY_RIVER_DEPTH | MGVALLEYS_ALT_DRY;
u16 river_depth = 4; // How deep to carve river channels u16 altitude_chill = 90;
u16 river_size = 5; // How wide to make rivers u16 river_depth = 4;
u16 river_size = 5;
float cave_width = 0.09f; float cave_width = 0.09f;
s16 large_cave_depth = -33; s16 large_cave_depth = -33;
@ -53,7 +58,7 @@ struct MapgenValleysParams : public MapgenParams {
s16 cavern_taper = 192; s16 cavern_taper = 192;
float cavern_threshold = 0.6f; float cavern_threshold = 0.6f;
s16 dungeon_ymin = -31000; s16 dungeon_ymin = -31000;
s16 dungeon_ymax = 63; // No higher than surface mapchunks s16 dungeon_ymax = 63;
NoiseParams np_filler_depth; NoiseParams np_filler_depth;
NoiseParams np_inter_valley_fill; NoiseParams np_inter_valley_fill;
@ -88,7 +93,8 @@ struct TerrainNoise {
class MapgenValleys : public MapgenBasic { class MapgenValleys : public MapgenBasic {
public: public:
MapgenValleys(int mapgenid, MapgenValleysParams *params, EmergeManager *emerge); MapgenValleys(int mapgenid, MapgenValleysParams *params,
EmergeManager *emerge);
~MapgenValleys(); ~MapgenValleys();
virtual MapgenType getType() const { return MAPGEN_VALLEYS; } virtual MapgenType getType() const { return MAPGEN_VALLEYS; }
@ -100,8 +106,6 @@ private:
BiomeGenOriginal *m_bgen; BiomeGenOriginal *m_bgen;
float altitude_chill; float altitude_chill;
bool humid_rivers;
bool use_altitude_chill;
float humidity_adjust; float humidity_adjust;
float river_depth_bed; float river_depth_bed;
float river_size_factor; float river_size_factor;