]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mapgen.h
Fix getCraftRecipe returing wrong reciep due to way to unspecific output matching
[dragonfireclient.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 MMVManip;
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 VoxelManipulator;
49 struct BlockMakeData;
50 class VoxelArea;
51 class Map;
52
53 enum MapgenObject {
54         MGOBJ_VMANIP,
55         MGOBJ_HEIGHTMAP,
56         MGOBJ_BIOMEMAP,
57         MGOBJ_HEATMAP,
58         MGOBJ_HUMIDMAP,
59         MGOBJ_GENNOTIFY
60 };
61
62 enum GenNotifyType {
63         GENNOTIFY_DUNGEON,
64         GENNOTIFY_TEMPLE,
65         GENNOTIFY_CAVE_BEGIN,
66         GENNOTIFY_CAVE_END,
67         GENNOTIFY_LARGECAVE_BEGIN,
68         GENNOTIFY_LARGECAVE_END,
69         GENNOTIFY_DECORATION,
70         NUM_GENNOTIFY_TYPES
71 };
72
73 struct GenNotifyEvent {
74         GenNotifyType type;
75         v3s16 pos;
76         u32 id;
77 };
78
79 class GenerateNotifier {
80 public:
81         GenerateNotifier();
82         GenerateNotifier(u32 notify_on, std::set<u32> *notify_on_deco_ids);
83
84         void setNotifyOn(u32 notify_on);
85         void setNotifyOnDecoIds(std::set<u32> *notify_on_deco_ids);
86
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);
90
91 private:
92         u32 m_notify_on;
93         std::set<u32> *m_notify_on_deco_ids;
94         std::list<GenNotifyEvent> m_notify_events;
95 };
96
97 struct MapgenSpecificParams {
98         virtual void readParams(Settings *settings) = 0;
99         virtual void writeParams(Settings *settings) = 0;
100         virtual ~MapgenSpecificParams() {}
101 };
102
103 struct MapgenParams {
104         std::string mg_name;
105         s16 chunksize;
106         u64 seed;
107         s16 water_level;
108         u32 flags;
109
110         NoiseParams np_biome_heat;
111         NoiseParams np_biome_humidity;
112
113         MapgenSpecificParams *sparams;
114
115         MapgenParams()
116         {
117                 mg_name     = DEFAULT_MAPGEN;
118                 seed        = 0;
119                 water_level = 1;
120                 chunksize   = 5;
121                 flags       = MG_TREES | MG_CAVES | MG_LIGHT;
122                 sparams     = NULL;
123                 np_biome_heat     = NoiseParams(50, 50, v3f(500.0, 500.0, 500.0), 5349, 3, 0.5, 2.0);
124                 np_biome_humidity = NoiseParams(50, 50, v3f(500.0, 500.0, 500.0), 842, 3, 0.5, 2.0);
125         }
126 };
127
128 class Mapgen {
129 public:
130         int seed;
131         int water_level;
132         u32 flags;
133         bool generating;
134         int id;
135
136         MMVManip *vm;
137         INodeDefManager *ndef;
138
139         u32 blockseed;
140         s16 *heightmap;
141         u8 *biomemap;
142         v3s16 csize;
143
144         GenerateNotifier gennotify;
145
146         Mapgen();
147         Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge);
148         virtual ~Mapgen();
149
150         static u32 getBlockSeed(v3s16 p, int seed);
151         static u32 getBlockSeed2(v3s16 p, int seed);
152         s16 findGroundLevelFull(v2s16 p2d);
153         s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
154         void updateHeightmap(v3s16 nmin, v3s16 nmax);
155         void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
156
157         void setLighting(u8 light, v3s16 nmin, v3s16 nmax);
158         void lightSpread(VoxelArea &a, v3s16 p, u8 light);
159
160         void calcLighting(v3s16 nmin, v3s16 nmax);
161         void calcLighting(v3s16 nmin, v3s16 nmax,
162                 v3s16 full_nmin, v3s16 full_nmax);
163
164         void propagateSunlight(v3s16 nmin, v3s16 nmax);
165         void spreadLight(v3s16 nmin, v3s16 nmax);
166
167         void calcLightingOld(v3s16 nmin, v3s16 nmax);
168
169         virtual void makeChunk(BlockMakeData *data) {}
170         virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
171 };
172
173 struct MapgenFactory {
174         virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
175                 EmergeManager *emerge) = 0;
176         virtual MapgenSpecificParams *createMapgenParams() = 0;
177         virtual ~MapgenFactory() {}
178 };
179
180 class GenElement {
181 public:
182         virtual ~GenElement() {}
183         u32 id;
184         std::string name;
185 };
186
187 class GenElementManager {
188 public:
189         static const char *ELEMENT_TITLE;
190         static const size_t ELEMENT_LIMIT = -1;
191
192         GenElementManager(IGameDef *gamedef);
193         virtual ~GenElementManager();
194
195         virtual GenElement *create(int type) = 0;
196
197         virtual u32 add(GenElement *elem);
198         virtual GenElement *get(u32 id);
199         virtual GenElement *update(u32 id, GenElement *elem);
200         virtual GenElement *remove(u32 id);
201         virtual void clear();
202
203         virtual GenElement *getByName(const std::string &name);
204
205 protected:
206         INodeDefManager *m_ndef;
207         std::vector<GenElement *> m_elements;
208 };
209
210 #endif