]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mapgen.h
Add propper client initialization
[dragonfireclient.git] / src / mapgen.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 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_bloated.h"
24 #include "util/container.h" // UniqueQueue
25 #include "gamedef.h"
26 #include "nodedef.h"
27 #include "mapnode.h"
28 #include "noise.h"
29 #include "settings.h"
30
31 /////////////////// Mapgen flags
32 #define MG_TREES         0x01
33 #define MG_CAVES         0x02
34 #define MG_DUNGEONS      0x04
35 #define MGV6_JUNGLES     0x08
36 #define MGV6_BIOME_BLEND 0x10
37 #define MG_FLAT          0x20
38 #define MG_NOLIGHT       0x40
39 #define MGV7_MOUNTAINS   0x80
40 #define MGV7_RIDGES      0x100
41 #define MGV6_NOMUDFLOW   0x200
42
43 /////////////////// Ore generation flags
44 // Use absolute value of height to determine ore placement
45 #define OREFLAG_ABSHEIGHT 0x01
46 // Use 3d noise to get density of ore placement, instead of just the position
47 #define OREFLAG_DENSITY   0x02 // not yet implemented
48 // For claylike ore types, place ore if the number of surrounding
49 // nodes isn't the specified node
50 #define OREFLAG_NODEISNT  0x04 // not yet implemented
51
52 /////////////////// Decoration flags
53 #define DECO_PLACE_CENTER_X 1
54 #define DECO_PLACE_CENTER_Y 2
55 #define DECO_PLACE_CENTER_Z 4
56
57 #define ORE_RANGE_ACTUAL 1
58 #define ORE_RANGE_MIRROR 2
59
60 #define NUM_GEN_NOTIFY 6
61
62
63 extern FlagDesc flagdesc_mapgen[];
64 extern FlagDesc flagdesc_ore[];
65 extern FlagDesc flagdesc_deco_schematic[];
66 extern FlagDesc flagdesc_gennotify[];
67
68 class BiomeDefManager;
69 class Biome;
70 class EmergeManager;
71 class MapBlock;
72 class ManualMapVoxelManipulator;
73 class VoxelManipulator;
74 struct BlockMakeData;
75 class VoxelArea;
76 class Map;
77
78
79 enum MapgenObject {
80         MGOBJ_VMANIP,
81         MGOBJ_HEIGHTMAP,
82         MGOBJ_BIOMEMAP,
83         MGOBJ_HEATMAP,
84         MGOBJ_HUMIDMAP,
85         MGOBJ_GENNOTIFY
86 };
87
88 enum GenNotify {
89         GENNOTIFY_DUNGEON,
90         GENNOTIFY_TEMPLE,
91         GENNOTIFY_CAVE_BEGIN,
92         GENNOTIFY_CAVE_END,
93         GENNOTIFY_LARGECAVE_BEGIN,
94         GENNOTIFY_LARGECAVE_END
95 };
96
97 enum OreType {
98         ORE_SCATTER,
99         ORE_SHEET,
100         ORE_CLAYLIKE
101 };
102
103
104 struct MapgenParams {
105         std::string mg_name;
106         int chunksize;
107         u64 seed;
108         int water_level;
109         u32 flags;
110
111         MapgenParams() {
112                 mg_name     = "v6";
113                 seed        = 0;
114                 water_level = 1;
115                 chunksize   = 5;
116                 flags       = MG_TREES | MG_CAVES | MGV6_BIOME_BLEND;
117         }
118
119         virtual bool readParams(Settings *settings) { return true; }
120         virtual void writeParams(Settings *settings) {}
121         virtual ~MapgenParams() {}
122 };
123
124 class Mapgen {
125 public:
126         int seed;
127         int water_level;
128         bool generating;
129         int id;
130         ManualMapVoxelManipulator *vm;
131         INodeDefManager *ndef;
132
133         s16 *heightmap;
134         u8 *biomemap;
135         v3s16 csize;
136
137         u32 gennotify;
138         std::vector<v3s16> *gen_notifications[NUM_GEN_NOTIFY];
139
140         Mapgen();
141         virtual ~Mapgen();
142
143         s16 findGroundLevelFull(v2s16 p2d);
144         s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
145         void updateHeightmap(v3s16 nmin, v3s16 nmax);
146         void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
147         void setLighting(v3s16 nmin, v3s16 nmax, u8 light);
148         void lightSpread(VoxelArea &a, v3s16 p, u8 light);
149         void calcLighting(v3s16 nmin, v3s16 nmax);
150         void calcLightingOld(v3s16 nmin, v3s16 nmax);
151
152         virtual void makeChunk(BlockMakeData *data) {}
153         virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
154 };
155
156 struct MapgenFactory {
157         virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
158                                                                  EmergeManager *emerge) = 0;
159         virtual MapgenParams *createMapgenParams() = 0;
160         virtual ~MapgenFactory() {}
161 };
162
163 class Ore {
164 public:
165         std::string ore_name;
166         std::vector<std::string> wherein_names;
167         content_t ore;
168         std::vector<content_t> wherein;  // the node to be replaced
169         u32 clust_scarcity; // ore cluster has a 1-in-clust_scarcity chance of appearing at a node
170         s16 clust_num_ores; // how many ore nodes are in a chunk
171         s16 clust_size;     // how large (in nodes) a chunk of ore is
172         s16 height_min;
173         s16 height_max;
174         u8 ore_param2;          // to set node-specific attributes
175         u32 flags;          // attributes for this ore
176         float nthresh;      // threshhold for noise at which an ore is placed
177         NoiseParams *np;    // noise for distribution of clusters (NULL for uniform scattering)
178         Noise *noise;
179
180         Ore() {
181                 ore     = CONTENT_IGNORE;
182                 np      = NULL;
183                 noise   = NULL;
184         }
185
186         virtual ~Ore();
187
188         void resolveNodeNames(INodeDefManager *ndef);
189         void placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
190         virtual void generate(ManualMapVoxelManipulator *vm, int seed,
191                                                 u32 blockseed, v3s16 nmin, v3s16 nmax) = 0;
192 };
193
194 class OreScatter : public Ore {
195         ~OreScatter() {}
196         virtual void generate(ManualMapVoxelManipulator *vm, int seed,
197                                                 u32 blockseed, v3s16 nmin, v3s16 nmax);
198 };
199
200 class OreSheet : public Ore {
201         ~OreSheet() {}
202         virtual void generate(ManualMapVoxelManipulator *vm, int seed,
203                                                 u32 blockseed, v3s16 nmin, v3s16 nmax);
204 };
205
206 Ore *createOre(OreType type);
207
208
209 enum DecorationType {
210         DECO_SIMPLE,
211         DECO_SCHEMATIC,
212         DECO_LSYSTEM
213 };
214
215 #if 0
216 struct CutoffData {
217         VoxelArea a;
218         Decoration *deco;
219         //v3s16 p;
220         //v3s16 size;
221         //s16 height;
222
223         CutoffData(s16 x, s16 y, s16 z, s16 h) {
224                 p = v3s16(x, y, z);
225                 height = h;
226         }
227 };
228 #endif
229
230 class Decoration {
231 public:
232         INodeDefManager *ndef;
233
234         int mapseed;
235         std::string place_on_name;
236         content_t c_place_on;
237         s16 sidelen;
238         float fill_ratio;
239         NoiseParams *np;
240
241         std::set<u8> biomes;
242         //std::list<CutoffData> cutoffs;
243         //JMutex cutoff_mutex;
244
245         Decoration();
246         virtual ~Decoration();
247
248         virtual void resolveNodeNames(INodeDefManager *ndef);
249         void placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
250         void placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
251
252         virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) = 0;
253         virtual int getHeight() = 0;
254         virtual std::string getName() = 0;
255 };
256
257 class DecoSimple : public Decoration {
258 public:
259         std::string deco_name;
260         std::string spawnby_name;
261         content_t c_deco;
262         content_t c_spawnby;
263         s16 deco_height;
264         s16 deco_height_max;
265         s16 nspawnby;
266
267         std::vector<std::string> decolist_names;
268         std::vector<content_t> c_decolist;
269
270         ~DecoSimple() {}
271
272         void resolveNodeNames(INodeDefManager *ndef);
273         virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
274         virtual int getHeight();
275         virtual std::string getName();
276 };
277
278 #define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM'
279 #define MTSCHEM_FILE_VER_HIGHEST_READ  3
280 #define MTSCHEM_FILE_VER_HIGHEST_WRITE 3
281
282 #define MTSCHEM_PROB_NEVER  0x00
283 #define MTSCHEM_PROB_ALWAYS 0xFF
284
285 class DecoSchematic : public Decoration {
286 public:
287         std::string filename;
288
289         std::vector<std::string> *node_names;
290         std::vector<content_t> c_nodes;
291         std::map<std::string, std::string> replacements;
292
293         u32 flags;
294         Rotation rotation;
295         v3s16 size;
296         MapNode *schematic;
297         u8 *slice_probs;
298
299         DecoSchematic();
300         ~DecoSchematic();
301
302         void resolveNodeNames(INodeDefManager *ndef);
303         virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
304         virtual int getHeight();
305         virtual std::string getName();
306
307         void blitToVManip(v3s16 p, ManualMapVoxelManipulator *vm,
308                                         Rotation rot, bool force_placement);
309
310         bool loadSchematicFile();
311         void saveSchematicFile(INodeDefManager *ndef);
312
313         bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
314         void placeStructure(Map *map, v3s16 p);
315         void applyProbabilities(v3s16 p0,
316                 std::vector<std::pair<v3s16, u8> > *plist,
317                 std::vector<std::pair<s16, u8> > *splist);
318 };
319
320 void build_nnlist_and_update_ids(MapNode *nodes, u32 nodecount,
321                                         std::vector<content_t> *usednodes);
322
323 /*
324 class DecoLSystem : public Decoration {
325 public:
326         virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
327 };
328 */
329
330 Decoration *createDecoration(DecorationType type);
331
332 #endif
333