3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
26 #include "util/string.h"
27 #include "util/container.h"
29 #define MAPGEN_DEFAULT MAPGEN_V7
30 #define MAPGEN_DEFAULT_NAME "v7"
32 /////////////////// Mapgen flags
33 #define MG_TREES 0x01 // Deprecated. Moved into mgv6 flags
35 #define MG_DUNGEONS 0x04
36 #define MG_FLAT 0x08 // Deprecated. Moved into mgv6 flags
38 #define MG_DECORATIONS 0x20
40 typedef u8 biome_t; // copy from mg_biome.h to avoid an unnecessary include
44 class INodeDefManager;
46 extern FlagDesc flagdesc_mapgen[];
47 extern FlagDesc flagdesc_gennotify[];
55 class VoxelManipulator;
74 GENNOTIFY_LARGECAVE_BEGIN,
75 GENNOTIFY_LARGECAVE_END,
80 // TODO(hmmmm/paramat): make stone type selection dynamic
87 struct GenNotifyEvent {
93 class GenerateNotifier {
96 GenerateNotifier(u32 notify_on, std::set<u32> *notify_on_deco_ids);
98 void setNotifyOn(u32 notify_on);
99 void setNotifyOnDecoIds(std::set<u32> *notify_on_deco_ids);
101 bool addEvent(GenNotifyType type, v3s16 pos, u32 id=0);
102 void getEvents(std::map<std::string, std::vector<v3s16> > &event_map,
103 bool peek_events=false);
107 std::set<u32> *m_notify_on_deco_ids;
108 std::list<GenNotifyEvent> m_notify_events;
122 struct MapgenParams {
130 BiomeParams *bparams;
133 mgtype(MAPGEN_DEFAULT),
137 mapgen_limit(MAX_MAP_GENERATION_LIMIT),
138 flags(MG_CAVES | MG_LIGHT | MG_DECORATIONS),
143 virtual ~MapgenParams();
145 virtual void readParams(const Settings *settings);
146 virtual void writeParams(Settings *settings) const;
151 Generic interface for map generators. All mapgens must inherit this class.
152 If a feature exposed by a public member pointer is not supported by a
153 certain mapgen, it must be set to NULL.
155 Apart from makeChunk, getGroundLevelAtPoint, and getSpawnLevelAtPoint, all
156 methods can be used by constructing a Mapgen base class and setting the
157 appropriate public members (e.g. vm, ndef, and so on).
169 INodeDefManager *ndef;
177 GenerateNotifier gennotify;
180 Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge);
183 virtual MapgenType getType() const { return MAPGEN_INVALID; }
185 static u32 getBlockSeed(v3s16 p, s32 seed);
186 static u32 getBlockSeed2(v3s16 p, s32 seed);
187 s16 findGroundLevelFull(v2s16 p2d);
188 s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
189 s16 findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax);
190 void updateHeightmap(v3s16 nmin, v3s16 nmax);
191 void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
193 void setLighting(u8 light, v3s16 nmin, v3s16 nmax);
194 void lightSpread(VoxelArea &a, v3s16 p, u8 light);
195 void calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax,
196 bool propagate_shadow = true);
197 void propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow);
198 void spreadLight(v3s16 nmin, v3s16 nmax);
200 virtual void makeChunk(BlockMakeData *data) {}
201 virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
203 // getSpawnLevelAtPoint() is a function within each mapgen that returns a
204 // suitable y co-ordinate for player spawn ('suitable' usually meaning
205 // within 16 nodes of water_level). If a suitable spawn level cannot be
206 // found at the specified (X, Z) 'MAX_MAP_GENERATION_LIMIT' is returned to
207 // signify this and to cause Server::findSpawnPos() to try another (X, Z).
208 virtual int getSpawnLevelAtPoint(v2s16 p) { return 0; }
210 // Mapgen management functions
211 static MapgenType getMapgenType(const std::string &mgname);
212 static const char *getMapgenName(MapgenType mgtype);
213 static Mapgen *createMapgen(MapgenType mgtype, int mgid,
214 MapgenParams *params, EmergeManager *emerge);
215 static MapgenParams *createMapgenParams(MapgenType mgtype);
216 static void getMapgenNames(std::vector<const char *> *mgnames, bool include_hidden);
219 // isLiquidHorizontallyFlowable() is a helper function for updateLiquid()
220 // that checks whether there are floodable nodes without liquid beneath
221 // the node at index vi.
222 inline bool isLiquidHorizontallyFlowable(u32 vi, v3s16 em);
223 DISABLE_CLASS_COPY(Mapgen);
227 MapgenBasic is a Mapgen implementation that handles basic functionality
228 the majority of conventional mapgens will probably want to use, but isn't
229 generic enough to be included as part of the base Mapgen class (such as
230 generating biome terrain over terrain node skeletons, generating caves,
233 Inherit MapgenBasic instead of Mapgen to add this basic functionality to
234 your mapgen without having to reimplement it. Feel free to override any of
235 these methods if you desire different or more advanced behavior.
237 Note that you must still create your own generateTerrain implementation when
238 inheriting MapgenBasic.
240 class MapgenBasic : public Mapgen {
242 MapgenBasic(int mapgenid, MapgenParams *params, EmergeManager *emerge);
243 virtual ~MapgenBasic();
245 virtual void generateCaves(s16 max_stone_y, s16 large_cave_depth);
246 virtual void generateDungeons(s16 max_stone_y, MgStoneType stone_type);
247 virtual MgStoneType generateBiomes();
248 virtual void dustTopNodes();
251 EmergeManager *m_emerge;
252 BiomeManager *m_bmgr;
254 Noise *noise_filler_depth;
261 // Content required for generateBiomes
263 content_t c_water_source;
264 content_t c_river_water_source;
265 content_t c_desert_stone;
266 content_t c_sandstone;
268 // Content required for generateDungeons
270 content_t c_stair_cobble;
271 content_t c_mossycobble;
272 content_t c_stair_desert_stone;
273 content_t c_sandstonebrick;
274 content_t c_stair_sandstone_block;
283 NoiseParams np_cave1;
284 NoiseParams np_cave2;