incrementaltp: respect physics overrides
[waspsaliva.git] / src / mapgen / mapgen.h
blob1487731e20bb46ef19de89c3efecfbd4bd3d9b3a
1 /*
2 Minetest
3 Copyright (C) 2010-2020 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2015-2020 paramat
5 Copyright (C) 2013-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
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.
22 #pragma once
24 #include "noise.h"
25 #include "nodedef.h"
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 // Obsolete. Moved into mgv6 flags
34 #define MG_CAVES 0x02
35 #define MG_DUNGEONS 0x04
36 #define MG_FLAT 0x08 // Obsolete. Moved into mgv6 flags
37 #define MG_LIGHT 0x10
38 #define MG_DECORATIONS 0x20
39 #define MG_BIOMES 0x40
40 #define MG_ORES 0x80
42 typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include
44 class Settings;
45 class MMVManip;
46 class NodeDefManager;
48 extern FlagDesc flagdesc_mapgen[];
49 extern FlagDesc flagdesc_gennotify[];
51 class Biome;
52 class BiomeGen;
53 struct BiomeParams;
54 class BiomeManager;
55 class EmergeParams;
56 class EmergeManager;
57 class MapBlock;
58 class VoxelManipulator;
59 struct BlockMakeData;
60 class VoxelArea;
61 class Map;
63 enum MapgenObject {
64 MGOBJ_VMANIP,
65 MGOBJ_HEIGHTMAP,
66 MGOBJ_BIOMEMAP,
67 MGOBJ_HEATMAP,
68 MGOBJ_HUMIDMAP,
69 MGOBJ_GENNOTIFY
72 enum GenNotifyType {
73 GENNOTIFY_DUNGEON,
74 GENNOTIFY_TEMPLE,
75 GENNOTIFY_CAVE_BEGIN,
76 GENNOTIFY_CAVE_END,
77 GENNOTIFY_LARGECAVE_BEGIN,
78 GENNOTIFY_LARGECAVE_END,
79 GENNOTIFY_DECORATION,
80 NUM_GENNOTIFY_TYPES
83 struct GenNotifyEvent {
84 GenNotifyType type;
85 v3s16 pos;
86 u32 id;
89 class GenerateNotifier {
90 public:
91 // Use only for temporary Mapgen objects with no map generation!
92 GenerateNotifier() = default;
93 GenerateNotifier(u32 notify_on, const std::set<u32> *notify_on_deco_ids);
95 bool addEvent(GenNotifyType type, v3s16 pos, u32 id=0);
96 void getEvents(std::map<std::string, std::vector<v3s16> > &event_map);
97 void clearEvents();
99 private:
100 u32 m_notify_on = 0;
101 const std::set<u32> *m_notify_on_deco_ids = nullptr;
102 std::list<GenNotifyEvent> m_notify_events;
105 // Order must match the order of 'static MapgenDesc g_reg_mapgens[]' in mapgen.cpp
106 enum MapgenType {
107 MAPGEN_V7,
108 MAPGEN_VALLEYS,
109 MAPGEN_CARPATHIAN,
110 MAPGEN_V5,
111 MAPGEN_FLAT,
112 MAPGEN_FRACTAL,
113 MAPGEN_SINGLENODE,
114 MAPGEN_V6,
115 MAPGEN_INVALID,
118 struct MapgenParams {
119 MapgenParams() = default;
120 virtual ~MapgenParams();
122 MapgenType mgtype = MAPGEN_DEFAULT;
123 s16 chunksize = 5;
124 u64 seed = 0;
125 s16 water_level = 1;
126 s16 mapgen_limit = MAX_MAP_GENERATION_LIMIT;
127 // Flags set in readParams
128 u32 flags = 0;
129 u32 spflags = 0;
131 BiomeParams *bparams = nullptr;
133 s16 mapgen_edge_min = -MAX_MAP_GENERATION_LIMIT;
134 s16 mapgen_edge_max = MAX_MAP_GENERATION_LIMIT;
136 virtual void readParams(const Settings *settings);
137 virtual void writeParams(Settings *settings) const;
138 // Default settings for g_settings such as flags
139 virtual void setDefaultSettings(Settings *settings) {};
141 s32 getSpawnRangeMax();
143 private:
144 void calcMapgenEdges();
145 bool m_mapgen_edges_calculated = false;
150 Generic interface for map generators. All mapgens must inherit this class.
151 If a feature exposed by a public member pointer is not supported by a
152 certain mapgen, it must be set to NULL.
154 Apart from makeChunk, getGroundLevelAtPoint, and getSpawnLevelAtPoint, all
155 methods can be used by constructing a Mapgen base class and setting the
156 appropriate public members (e.g. vm, ndef, and so on).
158 class Mapgen {
159 public:
160 s32 seed = 0;
161 int water_level = 0;
162 int mapgen_limit = 0;
163 u32 flags = 0;
164 bool generating = false;
165 int id = -1;
167 MMVManip *vm = nullptr;
168 const NodeDefManager *ndef = nullptr;
170 u32 blockseed;
171 s16 *heightmap = nullptr;
172 biome_t *biomemap = nullptr;
173 v3s16 csize;
175 BiomeGen *biomegen = nullptr;
176 GenerateNotifier gennotify;
178 Mapgen() = default;
179 Mapgen(int mapgenid, MapgenParams *params, EmergeParams *emerge);
180 virtual ~Mapgen() = default;
181 DISABLE_CLASS_COPY(Mapgen);
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 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
188 s16 findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax);
189 void updateHeightmap(v3s16 nmin, v3s16 nmax);
190 void getSurfaces(v2s16 p2d, s16 ymin, s16 ymax,
191 std::vector<s16> &floors, std::vector<s16> &ceilings);
193 void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
195 void setLighting(u8 light, v3s16 nmin, v3s16 nmax);
196 void lightSpread(VoxelArea &a, std::queue<std::pair<v3s16, u8>> &queue,
197 const v3s16 &p, u8 light);
198 void calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax,
199 bool propagate_shadow = true);
200 void propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow);
201 void spreadLight(const v3s16 &nmin, const v3s16 &nmax);
203 virtual void makeChunk(BlockMakeData *data) {}
204 virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
206 // getSpawnLevelAtPoint() is a function within each mapgen that returns a
207 // suitable y co-ordinate for player spawn ('suitable' usually meaning
208 // within 16 nodes of water_level). If a suitable spawn level cannot be
209 // found at the specified (X, Z) 'MAX_MAP_GENERATION_LIMIT' is returned to
210 // signify this and to cause Server::findSpawnPos() to try another (X, Z).
211 virtual int getSpawnLevelAtPoint(v2s16 p) { return 0; }
213 // Mapgen management functions
214 static MapgenType getMapgenType(const std::string &mgname);
215 static const char *getMapgenName(MapgenType mgtype);
216 static Mapgen *createMapgen(MapgenType mgtype, MapgenParams *params,
217 EmergeParams *emerge);
218 static MapgenParams *createMapgenParams(MapgenType mgtype);
219 static void getMapgenNames(std::vector<const char *> *mgnames, bool include_hidden);
220 static void setDefaultSettings(Settings *settings);
222 private:
223 // isLiquidHorizontallyFlowable() is a helper function for updateLiquid()
224 // that checks whether there are floodable nodes without liquid beneath
225 // the node at index vi.
226 inline bool isLiquidHorizontallyFlowable(u32 vi, v3s16 em);
230 MapgenBasic is a Mapgen implementation that handles basic functionality
231 the majority of conventional mapgens will probably want to use, but isn't
232 generic enough to be included as part of the base Mapgen class (such as
233 generating biome terrain over terrain node skeletons, generating caves,
234 dungeons, etc.)
236 Inherit MapgenBasic instead of Mapgen to add this basic functionality to
237 your mapgen without having to reimplement it. Feel free to override any of
238 these methods if you desire different or more advanced behavior.
240 Note that you must still create your own generateTerrain implementation when
241 inheriting MapgenBasic.
243 class MapgenBasic : public Mapgen {
244 public:
245 MapgenBasic(int mapgenid, MapgenParams *params, EmergeParams *emerge);
246 virtual ~MapgenBasic();
248 virtual void generateBiomes();
249 virtual void dustTopNodes();
250 virtual void generateCavesNoiseIntersection(s16 max_stone_y);
251 virtual void generateCavesRandomWalk(s16 max_stone_y, s16 large_cave_ymax);
252 virtual bool generateCavernsNoise(s16 max_stone_y);
253 virtual void generateDungeons(s16 max_stone_y);
255 protected:
256 EmergeParams *m_emerge;
257 BiomeManager *m_bmgr;
259 Noise *noise_filler_depth;
261 v3s16 node_min;
262 v3s16 node_max;
263 v3s16 full_node_min;
264 v3s16 full_node_max;
266 content_t c_stone;
267 content_t c_water_source;
268 content_t c_river_water_source;
269 content_t c_lava_source;
270 content_t c_cobble;
272 int ystride;
273 int zstride;
274 int zstride_1d;
275 int zstride_1u1d;
277 u32 spflags;
279 NoiseParams np_cave1;
280 NoiseParams np_cave2;
281 NoiseParams np_cavern;
282 NoiseParams np_dungeons;
283 float cave_width;
284 float cavern_limit;
285 float cavern_taper;
286 float cavern_threshold;
287 int small_cave_num_min;
288 int small_cave_num_max;
289 int large_cave_num_min;
290 int large_cave_num_max;
291 float large_cave_flooded;
292 s16 large_cave_depth;
293 s16 dungeon_ymin;
294 s16 dungeon_ymax;