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