Mgvalleys: Make river depth variation and humidity drop optional (#7532)
[oweals/minetest.git] / src / mapgen / mapgen_valleys.h
1 /*
2 Minetest
3 Copyright (C) 2016-2018 Duane Robertson <duane@duanerobertson.com>
4 Copyright (C) 2016-2018 paramat
5
6 Based on Valleys Mapgen by Gael de Sailly
7 (https://forum.minetest.net/viewtopic.php?f=9&t=11430)
8 and mapgen_v7 by kwolekr and paramat.
9
10 Licensing changed by permission of Gael de Sailly.
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU Lesser General Public License as published by
14 the Free Software Foundation; either version 2.1 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 GNU Lesser General Public License for more details.
21
22 You should have received a copy of the GNU Lesser General Public License along
23 with this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 */
26
27 #pragma once
28
29 #include "mapgen.h"
30
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
36
37 // Feed only one variable into these
38 #define MYSQUARE(x) (x) * (x)
39 #define MYCUBE(x) (x) * (x) * (x)
40
41 class BiomeManager;
42 class BiomeGenOriginal;
43
44 extern FlagDesc flagdesc_mapgen_valleys[];
45
46
47 struct MapgenValleysParams : public MapgenParams {
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;
53
54         float cave_width = 0.09f;
55         s16 large_cave_depth = -33;
56         s16 lava_depth = 1;
57         s16 cavern_limit = -256;
58         s16 cavern_taper = 192;
59         float cavern_threshold = 0.6f;
60         s16 dungeon_ymin = -31000;
61         s16 dungeon_ymax = 63;
62
63         NoiseParams np_filler_depth;
64         NoiseParams np_inter_valley_fill;
65         NoiseParams np_inter_valley_slope;
66         NoiseParams np_rivers;
67         NoiseParams np_terrain_height;
68         NoiseParams np_valley_depth;
69         NoiseParams np_valley_profile;
70
71         NoiseParams np_cave1;
72         NoiseParams np_cave2;
73         NoiseParams np_cavern;
74
75         MapgenValleysParams();
76         ~MapgenValleysParams() = default;
77
78         void readParams(const Settings *settings);
79         void writeParams(Settings *settings) const;
80 };
81
82 struct TerrainNoise {
83         s16 x;
84         s16 z;
85         float terrain_height;
86         float *rivers;
87         float *valley;
88         float valley_profile;
89         float *slope;
90         float inter_valley_fill;
91 };
92
93 class MapgenValleys : public MapgenBasic {
94 public:
95
96         MapgenValleys(int mapgenid, MapgenValleysParams *params,
97                 EmergeManager *emerge);
98         ~MapgenValleys();
99
100         virtual MapgenType getType() const { return MAPGEN_VALLEYS; }
101
102         virtual void makeChunk(BlockMakeData *data);
103         int getSpawnLevelAtPoint(v2s16 p);
104
105 private:
106         BiomeGenOriginal *m_bgen;
107
108         float altitude_chill;
109         float humidity_adjust;
110         float river_depth_bed;
111         float river_size_factor;
112
113         s16 large_cave_depth;
114         s16 dungeon_ymin;
115         s16 dungeon_ymax;
116
117         Noise *noise_inter_valley_fill;
118         Noise *noise_inter_valley_slope;
119         Noise *noise_rivers;
120         Noise *noise_terrain_height;
121         Noise *noise_valley_depth;
122         Noise *noise_valley_profile;
123
124         float terrainLevelAtPoint(s16 x, s16 z);
125         void calculateNoise();
126         virtual int generateTerrain();
127         float terrainLevelFromNoise(TerrainNoise *tn);
128         float adjustedTerrainLevelFromNoise(TerrainNoise *tn);
129 };