Skip to content

Commit bc9bb63

Browse files
authoredJul 18, 2018
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.
1 parent ade7a1c commit bc9bb63

File tree

3 files changed

+57
-53
lines changed

3 files changed

+57
-53
lines changed
 

‎builtin/settingtypes.txt

+10-8
Original file line numberDiff line numberDiff line change
@@ -1760,14 +1760,16 @@ mgfractal_np_cave2 (Cave2 noise) noise_params_3d 0, 12, (67, 67, 67), 10325, 3,
17601760
[*Mapgen Valleys]
17611761

17621762
# Map generation attributes specific to Mapgen Valleys.
1763-
# 'altitude_chill' makes higher elevations colder, which may cause biome issues.
1764-
# 'humid_rivers' modifies the humidity around rivers and in areas where water would tend to pool,
1765-
# it may interfere with delicately adjusted biomes.
1766-
# Flags that are not enabled are not modified from the default.
1767-
# Flags starting with 'no' are used to explicitly disable them.
1768-
mgvalleys_spflags (Mapgen Valleys specific flags) flags altitude_chill,humid_rivers altitude_chill,noaltitude_chill,humid_rivers,nohumid_rivers
1769-
1770-
# The altitude at which temperature drops by 20.
1763+
# 'altitude_chill': Reduces heat with altitude.
1764+
# 'humid_rivers': Increases humidity around rivers and where water pools.
1765+
# 'vary_river_depth': If enabled, low humidity and high heat causes rivers
1766+
# to become shallower and occasionally dry.
1767+
# 'altitude_dry': Reduces humidity with altitude.
1768+
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
1769+
1770+
# The vertical distance over which heat drops by 20 if 'altitude_chill' is
1771+
# enabled. Also the vertical distance over which humidity drops by 10 if
1772+
# 'altitude_dry' is enabled.
17711773
mgvalleys_altitude_chill (Altitude chill) int 90
17721774

17731775
# Depth below which you'll find large caves.

‎src/mapgen/mapgen_valleys.cpp

+32-34
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
4444
#include <cmath>
4545

4646

47-
static FlagDesc flagdesc_mapgen_valleys[] = {
48-
{"altitude_chill", MGVALLEYS_ALT_CHILL},
49-
{"humid_rivers", MGVALLEYS_HUMID_RIVERS},
50-
{NULL, 0}
47+
FlagDesc flagdesc_mapgen_valleys[] = {
48+
{"altitude_chill", MGVALLEYS_ALT_CHILL},
49+
{"humid_rivers", MGVALLEYS_HUMID_RIVERS},
50+
{"vary_river_depth", MGVALLEYS_VARY_RIVER_DEPTH},
51+
{"altitude_dry", MGVALLEYS_ALT_DRY},
52+
{NULL, 0}
5153
};
5254

5355

@@ -94,8 +96,6 @@ MapgenValleys::MapgenValleys(int mapgenid, MapgenValleysParams *params,
9496
MapgenBasic::np_cave2 = params->np_cave2;
9597
MapgenBasic::np_cavern = params->np_cavern;
9698

97-
humid_rivers = (spflags & MGVALLEYS_HUMID_RIVERS);
98-
use_altitude_chill = (spflags & MGVALLEYS_ALT_CHILL);
9999
humidity_adjust = bp->np_humidity.offset - 50.0f;
100100
}
101101

@@ -298,10 +298,10 @@ void MapgenValleys::calculateNoise()
298298
float heat_offset = 0.0f;
299299
float humidity_scale = 1.0f;
300300
// Altitude chill tends to reduce the average heat.
301-
if (use_altitude_chill)
301+
if (spflags & MGVALLEYS_ALT_CHILL)
302302
heat_offset = 5.0f;
303303
// River humidity tends to increase the humidity range.
304-
if (humid_rivers)
304+
if (spflags & MGVALLEYS_HUMID_RIVERS)
305305
humidity_scale = 0.8f;
306306

307307
for (s32 index = 0; index < csize.X * csize.Z; index++) {
@@ -477,17 +477,16 @@ int MapgenValleys::generateTerrain()
477477
if (surface_y > surface_max_y)
478478
surface_max_y = std::ceil(surface_y);
479479

480-
if (humid_rivers) {
481-
// Derive heat from (base) altitude. This will be most correct
482-
// at rivers, since other surface heights may vary below.
483-
if (use_altitude_chill && (surface_y > 0.0f || river_y > 0.0f))
484-
t_heat -= alt_to_heat *
485-
std::fmax(surface_y, river_y) / altitude_chill;
486-
487-
// If humidity is low or heat is high, lower the water table
480+
// Optionally vary river depth according to heat and humidity
481+
if (spflags & MGVALLEYS_VARY_RIVER_DEPTH) {
482+
float heat = ((spflags & MGVALLEYS_ALT_CHILL) &&
483+
(surface_y > 0.0f || river_y > 0.0f)) ?
484+
t_heat - alt_to_heat *
485+
std::fmax(surface_y, river_y) / altitude_chill :
486+
t_heat;
488487
float delta = m_bgen->humidmap[index_2d] - 50.0f;
489488
if (delta < 0.0f) {
490-
float t_evap = (t_heat - 32.0f) / evaporation;
489+
float t_evap = (heat - 32.0f) / evaporation;
491490
river_y += delta * std::fmax(t_evap, 0.08f);
492491
}
493492
}
@@ -534,33 +533,32 @@ int MapgenValleys::generateTerrain()
534533
}
535534
}
536535

537-
if (humid_rivers) {
538-
// Use base ground (water table) in a riverbed, to avoid an
539-
// unnatural rise in humidity.
536+
// Optionally increase humidity around rivers
537+
if (spflags & MGVALLEYS_HUMID_RIVERS) {
538+
// Ground height ignoring riverbeds
540539
float t_alt = std::fmax(noise_rivers->result[index_2d],
541540
(float)heightmap[index_2d]);
542-
float humid = m_bgen->humidmap[index_2d];
543541
float water_depth = (t_alt - river_y) / humidity_dropoff;
544-
humid *= 1.0f + std::pow(0.5f, std::fmax(water_depth, 1.0f));
542+
m_bgen->humidmap[index_2d] *=
543+
1.0f + std::pow(0.5f, std::fmax(water_depth, 1.0f));
544+
}
545545

546-
// Reduce humidity with altitude (ignoring riverbeds)
546+
// Optionally decrease humidity with altitude
547+
if (spflags & MGVALLEYS_ALT_DRY) {
548+
// Ground height ignoring riverbeds
549+
float t_alt = std::fmax(noise_rivers->result[index_2d],
550+
(float)heightmap[index_2d]);
547551
if (t_alt > 0.0f)
548-
humid -= alt_to_humid * t_alt / altitude_chill;
549-
550-
m_bgen->humidmap[index_2d] = humid;
552+
m_bgen->humidmap[index_2d] -=
553+
alt_to_humid * t_alt / altitude_chill;
551554
}
552555

553-
// Assign the heat adjusted by any changed altitudes.
554-
// The altitude will change about half the time.
555-
if (use_altitude_chill) {
556+
// Optionally decrease heat with altitude
557+
if (spflags & MGVALLEYS_ALT_CHILL) {
556558
// Ground height ignoring riverbeds
557559
float t_alt = std::fmax(noise_rivers->result[index_2d],
558560
(float)heightmap[index_2d]);
559-
560-
if (humid_rivers && heightmap[index_2d] == (s16)myround(surface_y))
561-
// The altitude hasn't changed. Use the first result
562-
m_bgen->heatmap[index_2d] = t_heat;
563-
else if (t_alt > 0.0f)
561+
if (t_alt > 0.0f)
564562
m_bgen->heatmap[index_2d] -=
565563
alt_to_heat * t_alt / altitude_chill;
566564
}

‎src/mapgen/mapgen_valleys.h

+15-11
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2828

2929
#include "mapgen.h"
3030

31-
////////////// Mapgen Valleys flags
32-
#define MGVALLEYS_ALT_CHILL 0x01
33-
#define MGVALLEYS_HUMID_RIVERS 0x02
31+
/////////////////// Mapgen Valleys flags
32+
#define MGVALLEYS_ALT_CHILL 0x01
33+
#define MGVALLEYS_HUMID_RIVERS 0x02
34+
#define MGVALLEYS_VARY_RIVER_DEPTH 0x04
35+
#define MGVALLEYS_ALT_DRY 0x08
3436

3537
// Feed only one variable into these
3638
#define MYSQUARE(x) (x) * (x)
@@ -39,12 +41,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3941
class BiomeManager;
4042
class BiomeGenOriginal;
4143

44+
extern FlagDesc flagdesc_mapgen_valleys[];
45+
4246

4347
struct MapgenValleysParams : public MapgenParams {
44-
u32 spflags = MGVALLEYS_HUMID_RIVERS | MGVALLEYS_ALT_CHILL;
45-
u16 altitude_chill = 90; // The altitude at which temperature drops by 20C
46-
u16 river_depth = 4; // How deep to carve river channels
47-
u16 river_size = 5; // How wide to make rivers
48+
u32 spflags = MGVALLEYS_ALT_CHILL | MGVALLEYS_HUMID_RIVERS |
49+
MGVALLEYS_VARY_RIVER_DEPTH | MGVALLEYS_ALT_DRY;
50+
u16 altitude_chill = 90;
51+
u16 river_depth = 4;
52+
u16 river_size = 5;
4853

4954
float cave_width = 0.09f;
5055
s16 large_cave_depth = -33;
@@ -53,7 +58,7 @@ struct MapgenValleysParams : public MapgenParams {
5358
s16 cavern_taper = 192;
5459
float cavern_threshold = 0.6f;
5560
s16 dungeon_ymin = -31000;
56-
s16 dungeon_ymax = 63; // No higher than surface mapchunks
61+
s16 dungeon_ymax = 63;
5762

5863
NoiseParams np_filler_depth;
5964
NoiseParams np_inter_valley_fill;
@@ -88,7 +93,8 @@ struct TerrainNoise {
8893
class MapgenValleys : public MapgenBasic {
8994
public:
9095

91-
MapgenValleys(int mapgenid, MapgenValleysParams *params, EmergeManager *emerge);
96+
MapgenValleys(int mapgenid, MapgenValleysParams *params,
97+
EmergeManager *emerge);
9298
~MapgenValleys();
9399

94100
virtual MapgenType getType() const { return MAPGEN_VALLEYS; }
@@ -100,8 +106,6 @@ class MapgenValleys : public MapgenBasic {
100106
BiomeGenOriginal *m_bgen;
101107

102108
float altitude_chill;
103-
bool humid_rivers;
104-
bool use_altitude_chill;
105109
float humidity_adjust;
106110
float river_depth_bed;
107111
float river_size_factor;

0 commit comments

Comments
 (0)
Please sign in to comment.