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