Mgvalleys: Code cleanup
[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
35 // Feed only one variable into these
36 #define MYSQUARE(x) (x) * (x)
37 #define MYCUBE(x) (x) * (x) * (x)
38
39 class BiomeManager;
40 class BiomeGenOriginal;
41
42
43 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
49         float cave_width = 0.09f;
50         s16 large_cave_depth = -33;
51         s16 lava_depth = 1;
52         s16 cavern_limit = -256;
53         s16 cavern_taper = 192;
54         float cavern_threshold = 0.6f;
55         s16 dungeon_ymin = -31000;
56         s16 dungeon_ymax = 63; // No higher than surface mapchunks
57
58         NoiseParams np_filler_depth;
59         NoiseParams np_inter_valley_fill;
60         NoiseParams np_inter_valley_slope;
61         NoiseParams np_rivers;
62         NoiseParams np_terrain_height;
63         NoiseParams np_valley_depth;
64         NoiseParams np_valley_profile;
65
66         NoiseParams np_cave1;
67         NoiseParams np_cave2;
68         NoiseParams np_cavern;
69
70         MapgenValleysParams();
71         ~MapgenValleysParams() = default;
72
73         void readParams(const Settings *settings);
74         void writeParams(Settings *settings) const;
75 };
76
77 struct TerrainNoise {
78         s16 x;
79         s16 z;
80         float terrain_height;
81         float *rivers;
82         float *valley;
83         float valley_profile;
84         float *slope;
85         float inter_valley_fill;
86 };
87
88 class MapgenValleys : public MapgenBasic {
89 public:
90
91         MapgenValleys(int mapgenid, MapgenValleysParams *params, EmergeManager *emerge);
92         ~MapgenValleys();
93
94         virtual MapgenType getType() const { return MAPGEN_VALLEYS; }
95
96         virtual void makeChunk(BlockMakeData *data);
97         int getSpawnLevelAtPoint(v2s16 p);
98
99 private:
100         BiomeGenOriginal *m_bgen;
101
102         float altitude_chill;
103         bool humid_rivers;
104         bool use_altitude_chill;
105         float humidity_adjust;
106         float river_depth_bed;
107         float river_size_factor;
108
109         s16 large_cave_depth;
110         s16 dungeon_ymin;
111         s16 dungeon_ymax;
112
113         Noise *noise_inter_valley_fill;
114         Noise *noise_inter_valley_slope;
115         Noise *noise_rivers;
116         Noise *noise_terrain_height;
117         Noise *noise_valley_depth;
118         Noise *noise_valley_profile;
119
120         float terrainLevelAtPoint(s16 x, s16 z);
121         void calculateNoise();
122         virtual int generateTerrain();
123         float terrainLevelFromNoise(TerrainNoise *tn);
124         float adjustedTerrainLevelFromNoise(TerrainNoise *tn);
125 };