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;
138 mgtype(MAPGEN_DEFAULT),
142 mapgen_limit(MAX_MAP_GENERATION_LIMIT),
143 flags(MG_CAVES | MG_LIGHT | MG_DECORATIONS),
146 mapgen_edge_min(-MAX_MAP_GENERATION_LIMIT),
147 mapgen_edge_max(MAX_MAP_GENERATION_LIMIT),
148 m_sao_limit_min(-MAX_MAP_GENERATION_LIMIT * BS),
149 m_sao_limit_max(MAX_MAP_GENERATION_LIMIT * BS),
150 m_mapgen_edges_calculated(false)
154 virtual ~MapgenParams();
156 virtual void readParams(const Settings *settings);
157 virtual void writeParams(Settings *settings) const;
159 bool saoPosOverLimit(const v3f &p);
160 s32 getSpawnRangeMax();
163 void calcMapgenEdges();
165 float m_sao_limit_min;
166 float m_sao_limit_max;
167 bool m_mapgen_edges_calculated;
172 Generic interface for map generators. All mapgens must inherit this class.
173 If a feature exposed by a public member pointer is not supported by a
174 certain mapgen, it must be set to NULL.
176 Apart from makeChunk, getGroundLevelAtPoint, and getSpawnLevelAtPoint, all
177 methods can be used by constructing a Mapgen base class and setting the
178 appropriate public members (e.g. vm, ndef, and so on).
190 INodeDefManager *ndef;
198 GenerateNotifier gennotify;
201 Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge);
203 DISABLE_CLASS_COPY(Mapgen);
205 virtual MapgenType getType() const { return MAPGEN_INVALID; }
207 static u32 getBlockSeed(v3s16 p, s32 seed);
208 static u32 getBlockSeed2(v3s16 p, s32 seed);
209 s16 findGroundLevelFull(v2s16 p2d);
210 s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
211 s16 findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax);
212 void updateHeightmap(v3s16 nmin, v3s16 nmax);
213 void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
215 void setLighting(u8 light, v3s16 nmin, v3s16 nmax);
216 void lightSpread(VoxelArea &a, v3s16 p, u8 light);
217 void calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax,
218 bool propagate_shadow = true);
219 void propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow);
220 void spreadLight(v3s16 nmin, v3s16 nmax);
222 virtual void makeChunk(BlockMakeData *data) {}
223 virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
225 // getSpawnLevelAtPoint() is a function within each mapgen that returns a
226 // suitable y co-ordinate for player spawn ('suitable' usually meaning
227 // within 16 nodes of water_level). If a suitable spawn level cannot be
228 // found at the specified (X, Z) 'MAX_MAP_GENERATION_LIMIT' is returned to
229 // signify this and to cause Server::findSpawnPos() to try another (X, Z).
230 virtual int getSpawnLevelAtPoint(v2s16 p) { return 0; }
232 // Mapgen management functions
233 static MapgenType getMapgenType(const std::string &mgname);
234 static const char *getMapgenName(MapgenType mgtype);
235 static Mapgen *createMapgen(MapgenType mgtype, int mgid,
236 MapgenParams *params, EmergeManager *emerge);
237 static MapgenParams *createMapgenParams(MapgenType mgtype);
238 static void getMapgenNames(std::vector<const char *> *mgnames, bool include_hidden);
241 // isLiquidHorizontallyFlowable() is a helper function for updateLiquid()
242 // that checks whether there are floodable nodes without liquid beneath
243 // the node at index vi.
244 inline bool isLiquidHorizontallyFlowable(u32 vi, v3s16 em);
248 MapgenBasic is a Mapgen implementation that handles basic functionality
249 the majority of conventional mapgens will probably want to use, but isn't
250 generic enough to be included as part of the base Mapgen class (such as
251 generating biome terrain over terrain node skeletons, generating caves,
254 Inherit MapgenBasic instead of Mapgen to add this basic functionality to
255 your mapgen without having to reimplement it. Feel free to override any of
256 these methods if you desire different or more advanced behavior.
258 Note that you must still create your own generateTerrain implementation when
259 inheriting MapgenBasic.
261 class MapgenBasic : public Mapgen {
263 MapgenBasic(int mapgenid, MapgenParams *params, EmergeManager *emerge);
264 virtual ~MapgenBasic();
266 virtual void generateCaves(s16 max_stone_y, s16 large_cave_depth);
267 virtual bool generateCaverns(s16 max_stone_y);
268 virtual void generateDungeons(s16 max_stone_y, MgStoneType stone_type);
269 virtual MgStoneType generateBiomes();
270 virtual void dustTopNodes();
273 EmergeManager *m_emerge;
274 BiomeManager *m_bmgr;
276 Noise *noise_filler_depth;
283 // Content required for generateBiomes
285 content_t c_desert_stone;
286 content_t c_sandstone;
287 content_t c_water_source;
288 content_t c_river_water_source;
289 content_t c_lava_source;
291 // Content required for generateDungeons
293 content_t c_stair_cobble;
294 content_t c_mossycobble;
295 content_t c_stair_desert_stone;
296 content_t c_sandstonebrick;
297 content_t c_stair_sandstone_block;
306 NoiseParams np_cave1;
307 NoiseParams np_cave2;
308 NoiseParams np_cavern;
312 float cavern_threshold;