]> git.lizzy.rs Git - minetest.git/blob - src/mapgen.h
b6efe8200a0eff324d8434d25ee8eadd4886f208
[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 #define DECO_SCHEM_CIDS_UPDATED 8
54
55 #define ORE_RANGE_ACTUAL 1
56 #define ORE_RANGE_MIRROR 2
57
58 #define NUM_GEN_NOTIFY 6
59
60
61 extern FlagDesc flagdesc_mapgen[];
62 extern FlagDesc flagdesc_ore[];
63 extern FlagDesc flagdesc_deco_schematic[];
64 extern FlagDesc flagdesc_gennotify[];
65
66 class BiomeDefManager;
67 class Biome;
68 class EmergeManager;
69 class MapBlock;
70 class ManualMapVoxelManipulator;
71 class VoxelManipulator;
72 struct BlockMakeData;
73 class VoxelArea;
74 class Map;
75
76
77 enum MapgenObject {
78         MGOBJ_VMANIP,
79         MGOBJ_HEIGHTMAP,
80         MGOBJ_BIOMEMAP,
81         MGOBJ_HEATMAP,
82         MGOBJ_HUMIDMAP,
83         MGOBJ_GENNOTIFY
84 };
85
86 enum GenNotify {
87         GENNOTIFY_DUNGEON,
88         GENNOTIFY_TEMPLE,
89         GENNOTIFY_CAVE_BEGIN,
90         GENNOTIFY_CAVE_END,
91         GENNOTIFY_LARGECAVE_BEGIN,
92         GENNOTIFY_LARGECAVE_END
93 };
94
95 enum OreType {
96         ORE_SCATTER,
97         ORE_SHEET,
98         ORE_CLAYLIKE
99 };
100
101
102 struct MapgenSpecificParams {
103         virtual void readParams(Settings *settings) = 0;
104         virtual void writeParams(Settings *settings) = 0;
105         virtual ~MapgenSpecificParams() {}
106 };
107
108 struct MapgenParams {
109         std::string mg_name;
110         s16 chunksize;
111         u64 seed;
112         s16 water_level;
113         u32 flags;
114
115         MapgenSpecificParams *sparams;
116
117         MapgenParams() {
118                 mg_name     = DEFAULT_MAPGEN;
119                 seed        = 0;
120                 water_level = 1;
121                 chunksize   = 5;
122                 flags       = MG_TREES | MG_CAVES | MG_LIGHT;
123                 sparams     = NULL;
124         }
125 };
126
127 class Mapgen {
128 public:
129         int seed;
130         int water_level;
131         bool generating;
132         int id;
133         ManualMapVoxelManipulator *vm;
134         INodeDefManager *ndef;
135
136         s16 *heightmap;
137         u8 *biomemap;
138         v3s16 csize;
139
140         u32 gennotify;
141         std::vector<v3s16> *gen_notifications[NUM_GEN_NOTIFY];
142
143         Mapgen();
144         virtual ~Mapgen();
145
146         s16 findGroundLevelFull(v2s16 p2d);
147         s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
148         void updateHeightmap(v3s16 nmin, v3s16 nmax);
149         void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
150         void setLighting(v3s16 nmin, v3s16 nmax, u8 light);
151         void lightSpread(VoxelArea &a, v3s16 p, u8 light);
152         void calcLighting(v3s16 nmin, v3s16 nmax);
153         void calcLightingOld(v3s16 nmin, v3s16 nmax);
154
155         virtual void makeChunk(BlockMakeData *data) {}
156         virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
157 };
158
159 struct MapgenFactory {
160         virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
161                                                                  EmergeManager *emerge) = 0;
162         virtual MapgenSpecificParams *createMapgenParams() = 0;
163         virtual ~MapgenFactory() {}
164 };
165
166 class Ore {
167 public:
168         content_t c_ore;                  // the node to place
169         std::vector<content_t> c_wherein; // the nodes to be placed in
170         u32 clust_scarcity; // ore cluster has a 1-in-clust_scarcity chance of appearing at a node
171         s16 clust_num_ores; // how many ore nodes are in a chunk
172         s16 clust_size;     // how large (in nodes) a chunk of ore is
173         s16 height_min;
174         s16 height_max;
175         u8 ore_param2;          // to set node-specific attributes
176         u32 flags;          // attributes for this ore
177         float nthresh;      // threshhold for noise at which an ore is placed
178         NoiseParams *np;    // noise for distribution of clusters (NULL for uniform scattering)
179         Noise *noise;
180
181         Ore() {
182                 c_ore   = CONTENT_IGNORE;
183                 np      = NULL;
184                 noise   = NULL;
185         }
186
187         virtual ~Ore();
188
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::vector<content_t> c_place_on;
236         s16 sidelen;
237         float fill_ratio;
238         NoiseParams *np;
239
240         std::set<u8> biomes;
241         //std::list<CutoffData> cutoffs;
242         //JMutex cutoff_mutex;
243
244         Decoration();
245         virtual ~Decoration();
246
247         void placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
248         void placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
249
250         virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) = 0;
251         virtual int getHeight() = 0;
252         virtual std::string getName() = 0;
253 };
254
255 class DecoSimple : public Decoration {
256 public:
257         std::vector<content_t> c_decos;
258         std::vector<content_t> c_spawnby;
259         s16 deco_height;
260         s16 deco_height_max;
261         s16 nspawnby;
262
263         ~DecoSimple() {}
264
265         bool canPlaceDecoration(ManualMapVoxelManipulator *vm, v3s16 p);
266         virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
267         virtual int getHeight();
268         virtual std::string getName();
269 };
270
271 #define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM'
272 #define MTSCHEM_FILE_VER_HIGHEST_READ  3
273 #define MTSCHEM_FILE_VER_HIGHEST_WRITE 3
274
275 #define MTSCHEM_PROB_NEVER  0x00
276 #define MTSCHEM_PROB_ALWAYS 0xFF
277
278 class DecoSchematic : public Decoration {
279 public:
280         std::string filename;
281
282         std::vector<content_t> c_nodes;
283
284         u32 flags;
285         Rotation rotation;
286         v3s16 size;
287         MapNode *schematic;
288         u8 *slice_probs;
289
290         DecoSchematic();
291         ~DecoSchematic();
292
293         void updateContentIds();
294         virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
295         virtual int getHeight();
296         virtual std::string getName();
297
298         void blitToVManip(v3s16 p, ManualMapVoxelManipulator *vm,
299                                         Rotation rot, bool force_placement);
300
301         bool loadSchematicFile(NodeResolver *resolver,
302                 std::map<std::string, std::string> &replace_names);
303         void saveSchematicFile(INodeDefManager *ndef);
304
305         bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
306         void placeStructure(Map *map, v3s16 p, bool force_placement);
307         void applyProbabilities(v3s16 p0,
308                 std::vector<std::pair<v3s16, u8> > *plist,
309                 std::vector<std::pair<s16, u8> > *splist);
310 };
311
312 void build_nnlist_and_update_ids(MapNode *nodes, u32 nodecount,
313                                         std::vector<content_t> *usednodes);
314
315 /*
316 class DecoLSystem : public Decoration {
317 public:
318         virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
319 };
320 */
321
322 Decoration *createDecoration(DecorationType type);
323
324 #endif
325