]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mapgen.h
8db01f5c115ccba1d836285d6c3434e3ddf9cec7
[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 "noise.h"
24 #include "nodedef.h"
25 #include "mapnode.h"
26 #include "util/string.h"
27 #include "util/container.h"
28
29 #define DEFAULT_MAPGEN "v6"
30
31 /////////////////// Mapgen flags
32 #define MG_TREES       0x01
33 #define MG_CAVES       0x02
34 #define MG_DUNGEONS    0x04
35 #define MG_FLAT        0x08
36 #define MG_LIGHT       0x10
37 #define MG_DECORATIONS 0x20
38
39 class Settings;
40 class MMVManip;
41 class INodeDefManager;
42
43 extern FlagDesc flagdesc_mapgen[];
44 extern FlagDesc flagdesc_gennotify[];
45
46 class Biome;
47 class BiomeGen;
48 struct BiomeParams;
49 class BiomeManager;
50 class EmergeManager;
51 class MapBlock;
52 class VoxelManipulator;
53 struct BlockMakeData;
54 class VoxelArea;
55 class Map;
56
57 enum MapgenObject {
58         MGOBJ_VMANIP,
59         MGOBJ_HEIGHTMAP,
60         MGOBJ_BIOMEMAP,
61         MGOBJ_HEATMAP,
62         MGOBJ_HUMIDMAP,
63         MGOBJ_GENNOTIFY
64 };
65
66 enum GenNotifyType {
67         GENNOTIFY_DUNGEON,
68         GENNOTIFY_TEMPLE,
69         GENNOTIFY_CAVE_BEGIN,
70         GENNOTIFY_CAVE_END,
71         GENNOTIFY_LARGECAVE_BEGIN,
72         GENNOTIFY_LARGECAVE_END,
73         GENNOTIFY_DECORATION,
74         NUM_GENNOTIFY_TYPES
75 };
76
77 // TODO(hmmmm/paramat): make stone type selection dynamic
78 enum MgStoneType {
79         MGSTONE_STONE,
80         MGSTONE_DESERT_STONE,
81         MGSTONE_SANDSTONE,
82 };
83
84 struct GenNotifyEvent {
85         GenNotifyType type;
86         v3s16 pos;
87         u32 id;
88 };
89
90 class GenerateNotifier {
91 public:
92         GenerateNotifier();
93         GenerateNotifier(u32 notify_on, std::set<u32> *notify_on_deco_ids);
94
95         void setNotifyOn(u32 notify_on);
96         void setNotifyOnDecoIds(std::set<u32> *notify_on_deco_ids);
97
98         bool addEvent(GenNotifyType type, v3s16 pos, u32 id=0);
99         void getEvents(std::map<std::string, std::vector<v3s16> > &event_map,
100                 bool peek_events=false);
101
102 private:
103         u32 m_notify_on;
104         std::set<u32> *m_notify_on_deco_ids;
105         std::list<GenNotifyEvent> m_notify_events;
106 };
107
108 struct MapgenSpecificParams {
109         virtual void readParams(const Settings *settings) = 0;
110         virtual void writeParams(Settings *settings) const = 0;
111         virtual ~MapgenSpecificParams() {}
112 };
113
114 struct MapgenParams {
115         std::string mg_name;
116         s16 chunksize;
117         u64 seed;
118         s16 water_level;
119         u32 flags;
120
121         BiomeParams *bparams;
122         MapgenSpecificParams *sparams;
123
124         MapgenParams() :
125                 mg_name(DEFAULT_MAPGEN),
126                 chunksize(5),
127                 seed(0),
128                 water_level(1),
129                 flags(MG_CAVES | MG_LIGHT | MG_DECORATIONS),
130                 bparams(NULL),
131                 sparams(NULL)
132         {
133         }
134
135         virtual ~MapgenParams();
136
137         void load(const Settings &settings);
138         void save(Settings &settings) const;
139 };
140
141
142 /*
143         Generic interface for map generators.  All mapgens must inherit this class.
144         If a feature exposed by a public member pointer is not supported by a
145         certain mapgen, it must be set to NULL.
146
147         Apart from makeChunk, getGroundLevelAtPoint, and getSpawnLevelAtPoint, all
148         methods can be used by constructing a Mapgen base class and setting the
149         appropriate public members (e.g. vm, ndef, and so on).
150 */
151 class Mapgen {
152 public:
153         int seed;
154         int water_level;
155         u32 flags;
156         bool generating;
157         int id;
158
159         MMVManip *vm;
160         INodeDefManager *ndef;
161
162         u32 blockseed;
163         s16 *heightmap;
164         u8 *biomemap;
165         v3s16 csize;
166
167         BiomeGen *biomegen;
168         GenerateNotifier gennotify;
169
170         Mapgen();
171         Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge);
172         virtual ~Mapgen();
173
174         static u32 getBlockSeed(v3s16 p, int seed);
175         static u32 getBlockSeed2(v3s16 p, int seed);
176         s16 findGroundLevelFull(v2s16 p2d);
177         s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
178         s16 findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax);
179         void updateHeightmap(v3s16 nmin, v3s16 nmax);
180         void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
181
182         void setLighting(u8 light, v3s16 nmin, v3s16 nmax);
183         void lightSpread(VoxelArea &a, v3s16 p, u8 light);
184         void calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax,
185                 bool propagate_shadow = true);
186         void propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow);
187         void spreadLight(v3s16 nmin, v3s16 nmax);
188
189         virtual void makeChunk(BlockMakeData *data) {}
190         virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
191
192         // getSpawnLevelAtPoint() is a function within each mapgen that returns a
193         // suitable y co-ordinate for player spawn ('suitable' usually meaning
194         // within 16 nodes of water_level). If a suitable spawn level cannot be
195         // found at the specified (X, Z) 'MAX_MAP_GENERATION_LIMIT' is returned to
196         // signify this and to cause Server::findSpawnPos() to try another (X, Z).
197         virtual int getSpawnLevelAtPoint(v2s16 p) { return 0; }
198
199 private:
200         DISABLE_CLASS_COPY(Mapgen);
201 };
202
203 /*
204         MapgenBasic is a Mapgen implementation that handles basic functionality
205         the majority of conventional mapgens will probably want to use, but isn't
206         generic enough to be included as part of the base Mapgen class (such as
207         generating biome terrain over terrain node skeletons, generating caves,
208         dungeons, etc.)
209
210         Inherit MapgenBasic instead of Mapgen to add this basic functionality to
211         your mapgen without having to reimplement it.  Feel free to override any of
212         these methods if you desire different or more advanced behavior.
213
214         Note that you must still create your own generateTerrain implementation when
215         inheriting MapgenBasic.
216 */
217 class MapgenBasic : public Mapgen {
218 public:
219         EmergeManager *m_emerge;
220         BiomeManager *bmgr;
221
222         Noise *noise_filler_depth;
223
224         v3s16 node_min;
225         v3s16 node_max;
226         v3s16 full_node_min;
227         v3s16 full_node_max;
228
229         content_t c_stone;
230         content_t c_water_source;
231         content_t c_river_water_source;
232         content_t c_desert_stone;
233         content_t c_sandstone;
234
235         int ystride;
236         NoiseParams np_cave1;
237         NoiseParams np_cave2;
238         float cave_width;
239
240         MapgenBasic(int mapgenid, MapgenParams *params, EmergeManager *emerge);
241
242         virtual MgStoneType generateBiomes();
243         virtual void dustTopNodes();
244         virtual void generateCaves(s16 max_stone_y, s16 large_cave_depth);
245 };
246
247 struct MapgenFactory {
248         virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
249                 EmergeManager *emerge) = 0;
250         virtual MapgenSpecificParams *createMapgenParams() = 0;
251         virtual ~MapgenFactory() {}
252 };
253
254 #endif