3 Copyright (C) 2010-2015 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2013-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
5 Copyright (C) 2015-2017 paramat
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "util/string.h"
29 #include "util/container.h"
31 #define MAPGEN_DEFAULT MAPGEN_V7
32 #define MAPGEN_DEFAULT_NAME "v7"
34 /////////////////// Mapgen flags
35 #define MG_TREES 0x01 // Deprecated. Moved into mgv6 flags
37 #define MG_DUNGEONS 0x04
38 #define MG_FLAT 0x08 // Deprecated. Moved into mgv6 flags
40 #define MG_DECORATIONS 0x20
42 typedef u8 biome_t; // copy from mg_biome.h to avoid an unnecessary include
46 class INodeDefManager;
48 extern FlagDesc flagdesc_mapgen[];
49 extern FlagDesc flagdesc_gennotify[];
57 class VoxelManipulator;
76 GENNOTIFY_LARGECAVE_BEGIN,
77 GENNOTIFY_LARGECAVE_END,
82 // TODO(hmmmm/paramat): make stone type selection dynamic
89 struct GenNotifyEvent {
95 class GenerateNotifier {
98 GenerateNotifier(u32 notify_on, std::set<u32> *notify_on_deco_ids);
100 void setNotifyOn(u32 notify_on);
101 void setNotifyOnDecoIds(std::set<u32> *notify_on_deco_ids);
103 bool addEvent(GenNotifyType type, v3s16 pos, u32 id=0);
104 void getEvents(std::map<std::string, std::vector<v3s16> > &event_map,
105 bool peek_events=false);
109 std::set<u32> *m_notify_on_deco_ids;
110 std::list<GenNotifyEvent> m_notify_events;
124 struct MapgenParams {
132 BiomeParams *bparams;
135 mgtype(MAPGEN_DEFAULT),
139 mapgen_limit(MAX_MAP_GENERATION_LIMIT),
140 flags(MG_CAVES | MG_LIGHT | MG_DECORATIONS),
142 m_sao_limit_min(MAX_MAP_GENERATION_LIMIT * BS),
143 m_sao_limit_max(MAX_MAP_GENERATION_LIMIT * BS),
144 m_sao_limit_calculated(false)
148 virtual ~MapgenParams();
150 virtual void readParams(const Settings *settings);
151 virtual void writeParams(Settings *settings) const;
153 bool saoPosOverLimit(const v3f &p);
155 void calcMapgenEdges();
157 float m_sao_limit_min;
158 float m_sao_limit_max;
159 bool m_sao_limit_calculated;
164 Generic interface for map generators. All mapgens must inherit this class.
165 If a feature exposed by a public member pointer is not supported by a
166 certain mapgen, it must be set to NULL.
168 Apart from makeChunk, getGroundLevelAtPoint, and getSpawnLevelAtPoint, all
169 methods can be used by constructing a Mapgen base class and setting the
170 appropriate public members (e.g. vm, ndef, and so on).
182 INodeDefManager *ndef;
190 GenerateNotifier gennotify;
193 Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge);
195 DISABLE_CLASS_COPY(Mapgen);
197 virtual MapgenType getType() const { return MAPGEN_INVALID; }
199 static u32 getBlockSeed(v3s16 p, s32 seed);
200 static u32 getBlockSeed2(v3s16 p, s32 seed);
201 s16 findGroundLevelFull(v2s16 p2d);
202 s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
203 s16 findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax);
204 void updateHeightmap(v3s16 nmin, v3s16 nmax);
205 void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
207 void setLighting(u8 light, v3s16 nmin, v3s16 nmax);
208 void lightSpread(VoxelArea &a, v3s16 p, u8 light);
209 void calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax,
210 bool propagate_shadow = true);
211 void propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow);
212 void spreadLight(v3s16 nmin, v3s16 nmax);
214 virtual void makeChunk(BlockMakeData *data) {}
215 virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
217 // getSpawnLevelAtPoint() is a function within each mapgen that returns a
218 // suitable y co-ordinate for player spawn ('suitable' usually meaning
219 // within 16 nodes of water_level). If a suitable spawn level cannot be
220 // found at the specified (X, Z) 'MAX_MAP_GENERATION_LIMIT' is returned to
221 // signify this and to cause Server::findSpawnPos() to try another (X, Z).
222 virtual int getSpawnLevelAtPoint(v2s16 p) { return 0; }
224 // Mapgen management functions
225 static MapgenType getMapgenType(const std::string &mgname);
226 static const char *getMapgenName(MapgenType mgtype);
227 static Mapgen *createMapgen(MapgenType mgtype, int mgid,
228 MapgenParams *params, EmergeManager *emerge);
229 static MapgenParams *createMapgenParams(MapgenType mgtype);
230 static void getMapgenNames(std::vector<const char *> *mgnames, bool include_hidden);
233 // isLiquidHorizontallyFlowable() is a helper function for updateLiquid()
234 // that checks whether there are floodable nodes without liquid beneath
235 // the node at index vi.
236 inline bool isLiquidHorizontallyFlowable(u32 vi, v3s16 em);
240 MapgenBasic is a Mapgen implementation that handles basic functionality
241 the majority of conventional mapgens will probably want to use, but isn't
242 generic enough to be included as part of the base Mapgen class (such as
243 generating biome terrain over terrain node skeletons, generating caves,
246 Inherit MapgenBasic instead of Mapgen to add this basic functionality to
247 your mapgen without having to reimplement it. Feel free to override any of
248 these methods if you desire different or more advanced behavior.
250 Note that you must still create your own generateTerrain implementation when
251 inheriting MapgenBasic.
253 class MapgenBasic : public Mapgen {
255 MapgenBasic(int mapgenid, MapgenParams *params, EmergeManager *emerge);
256 virtual ~MapgenBasic();
258 virtual void generateCaves(s16 max_stone_y, s16 large_cave_depth);
259 virtual bool generateCaverns(s16 max_stone_y);
260 virtual void generateDungeons(s16 max_stone_y, MgStoneType stone_type);
261 virtual MgStoneType generateBiomes();
262 virtual void dustTopNodes();
265 EmergeManager *m_emerge;
266 BiomeManager *m_bmgr;
268 Noise *noise_filler_depth;
275 // Content required for generateBiomes
277 content_t c_desert_stone;
278 content_t c_sandstone;
279 content_t c_water_source;
280 content_t c_river_water_source;
281 content_t c_lava_source;
283 // Content required for generateDungeons
285 content_t c_stair_cobble;
286 content_t c_mossycobble;
287 content_t c_stair_desert_stone;
288 content_t c_sandstonebrick;
289 content_t c_stair_sandstone_block;
298 NoiseParams np_cave1;
299 NoiseParams np_cave2;
300 NoiseParams np_cavern;
304 float cavern_threshold;