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