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