Add minetest.clear_registered_decorations() and clear_registered_ores()
[oweals/minetest.git] / src / mapgen.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #ifndef MAPGEN_HEADER
21 #define MAPGEN_HEADER
22
23 #include "noise.h"
24 #include "nodedef.h"
25 #include "mapnode.h"
26 #include "util/string.h"
27 #include "util/container.h"
28
29 #define DEFAULT_MAPGEN "v6"
30
31 /////////////////// Mapgen flags
32 #define MG_TREES         0x01
33 #define MG_CAVES         0x02
34 #define MG_DUNGEONS      0x04
35 #define MG_FLAT          0x08
36 #define MG_LIGHT         0x10
37
38 class Settings;
39 class ManualMapVoxelManipulator;
40 class INodeDefManager;
41
42 extern FlagDesc flagdesc_mapgen[];
43 extern FlagDesc flagdesc_gennotify[];
44
45 class Biome;
46 class EmergeManager;
47 class MapBlock;
48 class ManualMapVoxelManipulator;
49 class VoxelManipulator;
50 struct BlockMakeData;
51 class VoxelArea;
52 class Map;
53
54 enum MapgenObject {
55         MGOBJ_VMANIP,
56         MGOBJ_HEIGHTMAP,
57         MGOBJ_BIOMEMAP,
58         MGOBJ_HEATMAP,
59         MGOBJ_HUMIDMAP,
60         MGOBJ_GENNOTIFY
61 };
62
63 enum GenNotifyType {
64         GENNOTIFY_DUNGEON,
65         GENNOTIFY_TEMPLE,
66         GENNOTIFY_CAVE_BEGIN,
67         GENNOTIFY_CAVE_END,
68         GENNOTIFY_LARGECAVE_BEGIN,
69         GENNOTIFY_LARGECAVE_END,
70         GENNOTIFY_DECORATION,
71         NUM_GENNOTIFY_TYPES
72 };
73
74 struct GenNotifyEvent {
75         GenNotifyType type;
76         v3s16 pos;
77         u32 id;
78 };
79
80 class GenerateNotifier {
81 public:
82         GenerateNotifier();
83         GenerateNotifier(u32 notify_on, std::set<u32> *notify_on_deco_ids);
84
85         void setNotifyOn(u32 notify_on);
86         void setNotifyOnDecoIds(std::set<u32> *notify_on_deco_ids);
87
88         bool addEvent(GenNotifyType type, v3s16 pos, u32 id=0);
89         void getEvents(std::map<std::string, std::vector<v3s16> > &event_map,
90                 bool peek_events=false);
91
92 private:
93         u32 m_notify_on;
94         std::set<u32> *m_notify_on_deco_ids;
95         std::list<GenNotifyEvent> m_notify_events;
96 };
97
98 struct MapgenSpecificParams {
99         virtual void readParams(Settings *settings) = 0;
100         virtual void writeParams(Settings *settings) = 0;
101         virtual ~MapgenSpecificParams() {}
102 };
103
104 struct MapgenParams {
105         std::string mg_name;
106         s16 chunksize;
107         u64 seed;
108         s16 water_level;
109         u32 flags;
110
111         NoiseParams np_biome_heat;
112         NoiseParams np_biome_humidity;
113
114         MapgenSpecificParams *sparams;
115
116         MapgenParams()
117         {
118                 mg_name     = DEFAULT_MAPGEN;
119                 seed        = 0;
120                 water_level = 1;
121                 chunksize   = 5;
122                 flags       = MG_TREES | MG_CAVES | MG_LIGHT;
123                 sparams     = NULL;
124                 np_biome_heat     = NoiseParams(50, 50, v3f(500.0, 500.0, 500.0), 5349, 3, 0.5, 2.0);
125                 np_biome_humidity = NoiseParams(50, 50, v3f(500.0, 500.0, 500.0), 842, 3, 0.5, 2.0);
126         }
127 };
128
129 class Mapgen {
130 public:
131         int seed;
132         int water_level;
133         u32 flags;
134         bool generating;
135         int id;
136         ManualMapVoxelManipulator *vm;
137         INodeDefManager *ndef;
138
139         s16 *heightmap;
140         u8 *biomemap;
141         v3s16 csize;
142
143         GenerateNotifier gennotify;
144
145         Mapgen();
146         Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge);
147         virtual ~Mapgen();
148
149         s16 findGroundLevelFull(v2s16 p2d);
150         s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
151         void updateHeightmap(v3s16 nmin, v3s16 nmax);
152         void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
153         void setLighting(v3s16 nmin, v3s16 nmax, u8 light);
154         void lightSpread(VoxelArea &a, v3s16 p, u8 light);
155         void calcLighting(v3s16 nmin, v3s16 nmax);
156         void calcLightingOld(v3s16 nmin, v3s16 nmax);
157
158         virtual void makeChunk(BlockMakeData *data) {}
159         virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
160 };
161
162 struct MapgenFactory {
163         virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
164                 EmergeManager *emerge) = 0;
165         virtual MapgenSpecificParams *createMapgenParams() = 0;
166         virtual ~MapgenFactory() {}
167 };
168
169 class GenElement {
170 public:
171         virtual ~GenElement() {}
172         u32 id;
173         std::string name;
174 };
175
176 class GenElementManager {
177 public:
178         static const char *ELEMENT_TITLE;
179         static const size_t ELEMENT_LIMIT = -1;
180
181         GenElementManager(IGameDef *gamedef);
182         virtual ~GenElementManager();
183
184         virtual GenElement *create(int type) = 0;
185
186         virtual u32 add(GenElement *elem);
187         virtual GenElement *get(u32 id);
188         virtual GenElement *update(u32 id, GenElement *elem);
189         virtual GenElement *remove(u32 id);
190         virtual void clear();
191
192         virtual GenElement *getByName(const std::string &name);
193
194 protected:
195         NodeResolver *m_resolver;
196         std::vector<GenElement *> m_elements;
197 };
198
199 #endif