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 DEFAULT_MAPGEN "v6"
31 /////////////////// Mapgen flags
34 #define MG_DUNGEONS 0x04
40 class INodeDefManager;
42 extern FlagDesc flagdesc_mapgen[];
43 extern FlagDesc flagdesc_gennotify[];
48 class VoxelManipulator;
67 GENNOTIFY_LARGECAVE_BEGIN,
68 GENNOTIFY_LARGECAVE_END,
73 struct GenNotifyEvent {
79 class GenerateNotifier {
82 GenerateNotifier(u32 notify_on, std::set<u32> *notify_on_deco_ids);
84 void setNotifyOn(u32 notify_on);
85 void setNotifyOnDecoIds(std::set<u32> *notify_on_deco_ids);
87 bool addEvent(GenNotifyType type, v3s16 pos, u32 id=0);
88 void getEvents(std::map<std::string, std::vector<v3s16> > &event_map,
89 bool peek_events=false);
93 std::set<u32> *m_notify_on_deco_ids;
94 std::list<GenNotifyEvent> m_notify_events;
97 struct MapgenSpecificParams {
98 virtual void readParams(const Settings *settings) = 0;
99 virtual void writeParams(Settings *settings) const = 0;
100 virtual ~MapgenSpecificParams() {}
103 struct MapgenParams {
110 NoiseParams np_biome_heat;
111 NoiseParams np_biome_humidity;
113 MapgenSpecificParams *sparams;
116 mg_name(DEFAULT_MAPGEN),
120 flags(MG_TREES | MG_CAVES | MG_LIGHT),
121 np_biome_heat(NoiseParams(50, 50, v3f(500.0, 500.0, 500.0), 5349, 3, 0.5, 2.0)),
122 np_biome_humidity(NoiseParams(50, 50, v3f(500.0, 500.0, 500.0), 842, 3, 0.5, 2.0)),
126 void load(const Settings &settings);
127 void save(Settings &settings) const;
139 INodeDefManager *ndef;
146 GenerateNotifier gennotify;
149 Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge);
152 static u32 getBlockSeed(v3s16 p, int seed);
153 static u32 getBlockSeed2(v3s16 p, int seed);
154 s16 findGroundLevelFull(v2s16 p2d);
155 s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
156 void updateHeightmap(v3s16 nmin, v3s16 nmax);
157 void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
159 void setLighting(u8 light, v3s16 nmin, v3s16 nmax);
160 void lightSpread(VoxelArea &a, v3s16 p, u8 light);
162 void calcLighting(v3s16 nmin, v3s16 nmax);
163 void calcLighting(v3s16 nmin, v3s16 nmax,
164 v3s16 full_nmin, v3s16 full_nmax);
166 void propagateSunlight(v3s16 nmin, v3s16 nmax);
167 void spreadLight(v3s16 nmin, v3s16 nmax);
169 void calcLightingOld(v3s16 nmin, v3s16 nmax);
171 virtual void makeChunk(BlockMakeData *data) {}
172 virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
175 struct MapgenFactory {
176 virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
177 EmergeManager *emerge) = 0;
178 virtual MapgenSpecificParams *createMapgenParams() = 0;
179 virtual ~MapgenFactory() {}
182 typedef std::map<std::string, std::string> StringMap;
183 typedef u32 ObjDefHandle;
185 #define OBJDEF_INVALID_INDEX ((u32)(-1))
186 #define OBJDEF_INVALID_HANDLE 0
187 #define OBJDEF_HANDLE_SALT 0x00585e6fu
188 #define OBJDEF_MAX_ITEMS (1 << 18)
189 #define OBJDEF_UID_MASK ((1 << 7) - 1)
209 class ObjDefManager {
211 ObjDefManager(IGameDef *gamedef, ObjDefType type);
212 virtual ~ObjDefManager();
214 virtual const char *getObjectTitle() const = 0;
216 virtual void clear();
217 virtual ObjDef *getByName(const std::string &name) const;
219 //// Add new/get/set object definitions by handle
220 virtual ObjDefHandle add(ObjDef *obj);
221 virtual ObjDef *get(ObjDefHandle handle) const;
222 virtual ObjDef *set(ObjDefHandle handle, ObjDef *obj);
224 //// Raw variants that work on indexes
225 virtual u32 addRaw(ObjDef *obj);
227 // It is generally assumed that getRaw() will always return a valid object
228 // This won't be true if people do odd things such as call setRaw() with NULL
229 virtual ObjDef *getRaw(u32 index) const;
230 virtual ObjDef *setRaw(u32 index, ObjDef *obj);
232 size_t getNumObjects() const { return m_objects.size(); }
233 ObjDefType getType() const { return m_objtype; }
234 INodeDefManager *getNodeDef() const { return m_ndef; }
236 u32 validateHandle(ObjDefHandle handle) const;
237 static ObjDefHandle createHandle(u32 index, ObjDefType type, u32 uid);
238 static bool decodeHandle(ObjDefHandle handle, u32 *index,
239 ObjDefType *type, u32 *uid);
242 INodeDefManager *m_ndef;
243 std::vector<ObjDef *> m_objects;
244 ObjDefType m_objtype;