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