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