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