]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mapgen.h
ba1ea86c3bed4eecfa7f3e5924b9b5b3420d2336
[dragonfireclient.git] / src / mapgen.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MAPGEN_HEADER
21 #define MAPGEN_HEADER
22
23 #include "irrlichttypes_extrabloated.h"
24 #include "util/container.h" // UniqueQueue
25 #include "gamedef.h"
26 #include "mapnode.h"
27 #include "noise.h"
28 #include "settings.h"
29
30 /////////////////// Mapgen flags
31 #define MG_TREES         0x01
32 #define MG_CAVES         0x02
33 #define MG_DUNGEONS      0x04
34 #define MGV6_FORESTS     0x08
35 #define MGV6_BIOME_BLEND 0x10
36
37 #define AVERAGE_MUD_AMOUNT 4
38
39 class BiomeDefManager;
40 class Biome;
41
42 //struct BlockMakeData;
43 class MapBlock;
44 class ManualMapVoxelManipulator;
45 class VoxelManipulator;
46 class INodeDefManager;
47
48 extern NoiseParams nparams_v6_def_terrain_base;
49 extern NoiseParams nparams_v6_def_terrain_higher;
50 extern NoiseParams nparams_v6_def_steepness;
51 extern NoiseParams nparams_v6_def_height_select;
52 extern NoiseParams nparams_v6_def_trees;
53 extern NoiseParams nparams_v6_def_mud;
54 extern NoiseParams nparams_v6_def_beach;
55 extern NoiseParams nparams_v6_def_biome;
56 extern NoiseParams nparams_v6_def_cave;
57
58 extern NoiseParams nparams_v7_def_terrain;
59 extern NoiseParams nparams_v7_def_bgroup;
60 extern NoiseParams nparams_v7_def_heat;
61 extern NoiseParams nparams_v7_def_humidity;
62
63 enum BiomeType
64 {
65         BT_NORMAL,
66         BT_DESERT
67 };
68
69
70 struct BlockMakeData {
71         bool no_op;
72         ManualMapVoxelManipulator *vmanip;
73         u64 seed;
74         v3s16 blockpos_min;
75         v3s16 blockpos_max;
76         v3s16 blockpos_requested;
77         UniqueQueue<v3s16> transforming_liquid;
78         INodeDefManager *nodedef;
79
80         BlockMakeData();
81         ~BlockMakeData();
82 };
83
84
85 struct MapgenParams {
86         int mg_version;
87         int chunksize;
88         u64 seed;
89         int water_level;
90         u32 flags;
91
92         MapgenParams() {
93                 mg_version  = 6;
94                 seed        = 0;
95                 water_level = 1;
96                 chunksize   = 5;
97                 flags       = MG_TREES | MG_CAVES | MGV6_BIOME_BLEND;
98         }
99
100         static MapgenParams *createMapgenParams(int mgver);
101         static MapgenParams *getParamsFromSettings(Settings *settings);
102
103 };
104
105 struct MapgenV6Params : public MapgenParams {
106         float freq_desert;
107         float freq_beach;
108         NoiseParams *np_terrain_base;
109         NoiseParams *np_terrain_higher;
110         NoiseParams *np_steepness;
111         NoiseParams *np_height_select;
112         NoiseParams *np_trees;
113         NoiseParams *np_mud;
114         NoiseParams *np_beach;
115         NoiseParams *np_biome;
116         NoiseParams *np_cave;
117
118         MapgenV6Params() {
119                 freq_desert       = 0.45;
120                 freq_beach        = 0.15;
121                 np_terrain_base   = &nparams_v6_def_terrain_base;
122                 np_terrain_higher = &nparams_v6_def_terrain_higher;
123                 np_steepness      = &nparams_v6_def_steepness;
124                 np_height_select  = &nparams_v6_def_height_select;
125                 np_trees          = &nparams_v6_def_trees;
126                 np_mud            = &nparams_v6_def_mud;
127                 np_beach          = &nparams_v6_def_beach;
128                 np_biome          = &nparams_v6_def_biome;
129                 np_cave           = &nparams_v6_def_cave;
130         }
131 };
132
133 struct MapgenV7Params : public MapgenParams {
134         NoiseParams *np_terrain;
135         NoiseParams *np_bgroup;
136         NoiseParams *np_heat;
137         NoiseParams *np_humidity;
138
139         MapgenV7Params() {
140                 np_terrain  = &nparams_v7_def_terrain;
141                 np_bgroup   = &nparams_v7_def_bgroup;
142                 np_heat     = &nparams_v7_def_heat;
143                 np_humidity = &nparams_v7_def_humidity;
144         }
145 };
146
147
148 class Mapgen {
149 public:
150         int seed;
151         int water_level;
152         bool generating;
153         int id;
154
155         virtual void makeChunk(BlockMakeData *data) {};
156         virtual int getGroundLevelAtPoint(v2s16 p) = 0;
157
158         //Legacy functions for Farmesh (pending removal)
159         static bool get_have_beach(u64 seed, v2s16 p2d);
160         static double tree_amount_2d(u64 seed, v2s16 p);
161         static s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
162 };
163
164
165 class MapgenV6 : public Mapgen {
166 public:
167         //ManualMapVoxelManipulator &vmanip;
168
169         int ystride;
170         v3s16 csize;
171
172         v3s16 node_min;
173         v3s16 node_max;
174
175         Noise *noise_terrain_base;
176         Noise *noise_terrain_higher;
177         Noise *noise_steepness;
178         Noise *noise_height_select;
179         Noise *noise_trees;
180         Noise *noise_mud;
181         Noise *noise_beach;
182         Noise *noise_biome;
183
184         float *map_terrain_base;
185         float *map_terrain_higher;
186         float *map_steepness;
187         float *map_height_select;
188         float *map_trees;
189         float *map_mud;
190         float *map_beach;
191         float *map_biome;
192
193         NoiseParams *np_cave;
194
195         u32 flags;
196         float freq_desert;
197         float freq_beach;
198
199         MapgenV6(int mapgenid, MapgenV6Params *params);
200         ~MapgenV6();
201
202         void makeChunk(BlockMakeData *data);
203         int getGroundLevelAtPoint(v2s16 p);
204
205
206         static s16 find_ground_level(VoxelManipulator &vmanip, v2s16 p2d, INodeDefManager *ndef);
207         static s16 find_stone_level(VoxelManipulator &vmanip, v2s16 p2d, INodeDefManager *ndef);
208         void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, bool is_apple_tree, INodeDefManager *ndef);
209         double tree_amount_2d(u64 seed, v2s16 p);
210         bool block_is_underground(u64 seed, v3s16 blockpos);
211         double base_rock_level_2d(u64 seed, v2s16 p);
212         s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
213         double get_mud_add_amount(u64 seed, v2s16 p);
214         bool get_have_beach(u64 seed, v2s16 p2d);
215         BiomeType get_biome(u64 seed, v2s16 p2d);
216         u32 get_blockseed(u64 seed, v3s16 p);
217 };
218
219
220 class MapgenV7 : public Mapgen {
221 public:
222         BlockMakeData *data;
223         ManualMapVoxelManipulator *vmanip;
224         INodeDefManager *ndef;
225         BiomeDefManager *biomedef;
226
227         int ystride;
228         int zstride;
229
230         v3s16 csize;
231
232         Noise *noise_terrain;
233         Noise *noise_bgroup;
234         Noise *noise_heat;
235         Noise *noise_humidity;
236
237         v3s16 node_min;
238         v3s16 node_max;
239
240         float *map_terrain;
241         float *map_bgroup;
242         float *map_heat;
243         float *map_humidity;
244
245         bool generating;
246         int id;
247         u32 flags;
248
249         //should these be broken off into a "commonly used nodes" class?
250         MapNode n_air;
251         MapNode n_water;
252         MapNode n_lava;
253
254         MapgenV7(BiomeDefManager *biomedef, int mapgenid, MapgenV7Params *params);
255         ~MapgenV7();
256
257         void makeChunk(BlockMakeData *data);
258         int getGroundLevelAtPoint(v2s16 p);
259
260         Biome *getBiomeAtPoint(v3s16 p);
261         void updateLiquid(v3s16 node_min, v3s16 node_max);
262         void updateLighting(v3s16 node_min, v3s16 node_max);
263
264         //Legacy functions for Farmesh (pending removal)
265 //      static bool get_have_beach(u64 seed, v2s16 p2d);
266 //      static double tree_amount_2d(u64 seed, v2s16 p);
267 //      static s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
268 };
269
270 class EmergeManager {
271 public:
272         //settings
273         MapgenParams *params;
274
275         //mapgen objects here
276         Mapgen *mapgen;
277
278         //biome manager
279         BiomeDefManager *biomedef;
280
281         EmergeManager(IGameDef *gamedef, BiomeDefManager *bdef, MapgenParams *mgparams);
282         ~EmergeManager();
283
284         Mapgen *getMapgen();
285         void addBlockToQueue();
286
287         //mapgen helper methods
288         Biome *getBiomeAtPoint(v3s16 p);
289         int getGroundLevelAtPoint(v2s16 p);
290         bool isBlockUnderground(v3s16 blockpos);
291         u32 getBlockSeed(v3s16 p);
292 };
293
294 #endif
295