Mapgen: Make 3D noise tunnels' width settable
[oweals/minetest.git] / src / mapgen_valleys.h
1 /*
2 Minetest Valleys C
3 Copyright (C) 2010-2015 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4 Copyright (C) 2010-2015 paramat, Matt Gregory
5 Copyright (C) 2016 Duane Robertson <duane@duanerobertson.com>
6
7 Based on Valleys Mapgen by Gael de Sailly
8  (https://forum.minetest.net/viewtopic.php?f=9&t=11430)
9 and mapgen_v7 by kwolekr and paramat.
10
11 Licensing changed by permission of Gael de Sailly.
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU Lesser General Public License as published by
15 the Free Software Foundation; either version 2.1 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 GNU Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public License along
24 with this program; if not, write to the Free Software Foundation, Inc.,
25 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 */
27
28 #ifndef MAPGEN_VALLEYS_HEADER
29 #define MAPGEN_VALLEYS_HEADER
30
31 #include "mapgen.h"
32
33 ////////////// Mapgen Valleys flags
34 #define MGVALLEYS_ALT_CHILL    0x01
35 #define MGVALLEYS_HUMID_RIVERS 0x02
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
43 // Global profiler
44 //class Profiler;
45 //extern Profiler *mapgen_profiler;
46
47
48 struct MapgenValleysParams : public MapgenSpecificParams {
49         u32 spflags;
50         s16 large_cave_depth;
51         s16 massive_cave_depth;
52         u16 altitude_chill;
53         u16 lava_features;
54         u16 river_depth;
55         u16 river_size;
56         u16 water_features;
57         float cave_width;
58         NoiseParams np_cave1;
59         NoiseParams np_cave2;
60         NoiseParams np_filler_depth;
61         NoiseParams np_inter_valley_fill;
62         NoiseParams np_inter_valley_slope;
63         NoiseParams np_rivers;
64         NoiseParams np_massive_caves;
65         NoiseParams np_terrain_height;
66         NoiseParams np_valley_depth;
67         NoiseParams np_valley_profile;
68
69         MapgenValleysParams();
70         ~MapgenValleysParams() {}
71
72         void readParams(const Settings *settings);
73         void writeParams(Settings *settings) const;
74 };
75
76 struct TerrainNoise {
77         s16 x;
78         s16 z;
79         float terrain_height;
80         float *rivers;
81         float *valley;
82         float valley_profile;
83         float *slope;
84         float inter_valley_fill;
85 };
86
87 class MapgenValleys : public Mapgen {
88 public:
89
90         MapgenValleys(int mapgenid, MapgenParams *params, EmergeManager *emerge);
91         ~MapgenValleys();
92
93         virtual void makeChunk(BlockMakeData *data);
94         int getSpawnLevelAtPoint(v2s16 p);
95
96         s16 large_cave_depth;
97
98 private:
99         EmergeManager *m_emerge;
100         BiomeManager *bmgr;
101
102         int ystride;
103         int zstride;
104         int zstride_1d;
105
106         float map_gen_limit;
107
108         bool humid_rivers;
109         bool use_altitude_chill;
110         float humidity_adjust;
111         s16 cave_water_max_height;
112         s16 lava_max_height;
113
114         v3s16 node_min;
115         v3s16 node_max;
116         v3s16 full_node_min;
117         v3s16 full_node_max;
118
119         u32 spflags;
120         float altitude_chill;
121         s16 lava_features_lim;
122         s16 massive_cave_depth;
123         float river_depth_bed;
124         float river_size_factor;
125         float *tcave_cache;
126         s16 water_features_lim;
127         float cave_width;
128         Noise *noise_filler_depth;
129         Noise *noise_cave1;
130         Noise *noise_cave2;
131         Noise *noise_inter_valley_fill;
132         Noise *noise_inter_valley_slope;
133         Noise *noise_rivers;
134         Noise *noise_massive_caves;
135         Noise *noise_terrain_height;
136         Noise *noise_valley_depth;
137         Noise *noise_valley_profile;
138
139         Noise *noise_heat;
140         Noise *noise_heat_blend;
141         Noise *noise_humidity;
142         Noise *noise_humidity_blend;
143
144         content_t c_cobble;
145         content_t c_desert_stone;
146         content_t c_dirt;
147         content_t c_ice;
148         content_t c_lava_source;
149         content_t c_mossycobble;
150         content_t c_river_water_source;
151         content_t c_sand;
152         content_t c_sandstone;
153         content_t c_sandstonebrick;
154         content_t c_stair_cobble;
155         content_t c_stair_sandstonebrick;
156         content_t c_stone;
157         content_t c_water_source;
158
159         float terrainLevelAtPoint(s16 x, s16 z);
160
161         void calculateNoise();
162
163         virtual int generateTerrain();
164         float terrainLevelFromNoise(TerrainNoise *tn);
165         float adjustedTerrainLevelFromNoise(TerrainNoise *tn);
166
167         float humidityByTerrain(float humidity_base, float mount, float rivers, float valley);
168
169         MgStoneType generateBiomes(float *heat_map, float *humidity_map);
170         void dustTopNodes();
171
172         void generateCaves(s16 max_stone_y);
173 };
174
175 struct MapgenFactoryValleys : public MapgenFactory {
176         Mapgen *createMapgen(int mgid, MapgenParams *params, EmergeManager *emerge)
177         {
178                 return new MapgenValleys(mgid, params, emerge);
179         };
180
181         MapgenSpecificParams *createMapgenParams()
182         {
183                 return new MapgenValleysParams();
184         };
185 };
186
187 #endif