cfecb3206ac56d4fd772085fde5fde0da23a6855
[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 "nodedef.h"
24 #include "mapnode.h"
25 #include "util/string.h"
26 #include "util/container.h"
27
28 #define DEFAULT_MAPGEN "v6"
29
30 /////////////////// Mapgen flags
31 #define MG_TREES         0x01
32 #define MG_CAVES         0x02
33 #define MG_DUNGEONS      0x04
34 #define MG_FLAT          0x08
35 #define MG_LIGHT         0x10
36
37 #define NUM_GEN_NOTIFY 6
38
39 class Settings;
40 class ManualMapVoxelManipulator;
41 class INodeDefManager;
42
43 extern FlagDesc flagdesc_mapgen[];
44 extern FlagDesc flagdesc_gennotify[];
45
46 class Biome;
47 class EmergeManager;
48 class MapBlock;
49 class ManualMapVoxelManipulator;
50 class VoxelManipulator;
51 struct BlockMakeData;
52 class VoxelArea;
53 class Map;
54
55 enum MapgenObject {
56         MGOBJ_VMANIP,
57         MGOBJ_HEIGHTMAP,
58         MGOBJ_BIOMEMAP,
59         MGOBJ_HEATMAP,
60         MGOBJ_HUMIDMAP,
61         MGOBJ_GENNOTIFY
62 };
63
64 enum GenNotify {
65         GENNOTIFY_DUNGEON,
66         GENNOTIFY_TEMPLE,
67         GENNOTIFY_CAVE_BEGIN,
68         GENNOTIFY_CAVE_END,
69         GENNOTIFY_LARGECAVE_BEGIN,
70         GENNOTIFY_LARGECAVE_END
71 };
72
73 struct MapgenSpecificParams {
74         virtual void readParams(Settings *settings) = 0;
75         virtual void writeParams(Settings *settings) = 0;
76         virtual ~MapgenSpecificParams() {}
77 };
78
79 struct MapgenParams {
80         std::string mg_name;
81         s16 chunksize;
82         u64 seed;
83         s16 water_level;
84         u32 flags;
85
86         MapgenSpecificParams *sparams;
87
88         MapgenParams() {
89                 mg_name     = DEFAULT_MAPGEN;
90                 seed        = 0;
91                 water_level = 1;
92                 chunksize   = 5;
93                 flags       = MG_TREES | MG_CAVES | MG_LIGHT;
94                 sparams     = NULL;
95         }
96 };
97
98 class Mapgen {
99 public:
100         int seed;
101         int water_level;
102         bool generating;
103         int id;
104         ManualMapVoxelManipulator *vm;
105         INodeDefManager *ndef;
106
107         s16 *heightmap;
108         u8 *biomemap;
109         v3s16 csize;
110
111         u32 gennotify;
112         std::vector<v3s16> *gen_notifications[NUM_GEN_NOTIFY];
113
114         Mapgen();
115         virtual ~Mapgen();
116
117         s16 findGroundLevelFull(v2s16 p2d);
118         s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
119         void updateHeightmap(v3s16 nmin, v3s16 nmax);
120         void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
121         void setLighting(v3s16 nmin, v3s16 nmax, u8 light);
122         void lightSpread(VoxelArea &a, v3s16 p, u8 light);
123         void calcLighting(v3s16 nmin, v3s16 nmax);
124         void calcLightingOld(v3s16 nmin, v3s16 nmax);
125
126         virtual void makeChunk(BlockMakeData *data) {}
127         virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
128 };
129
130 struct MapgenFactory {
131         virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
132                 EmergeManager *emerge) = 0;
133         virtual MapgenSpecificParams *createMapgenParams() = 0;
134         virtual ~MapgenFactory() {}
135 };
136
137 class GenElement {
138 public:
139         u32 id;
140         std::string name;
141 };
142
143 class GenElementManager {
144 public:
145         static const char *ELEMENT_TITLE;
146         static const size_t ELEMENT_LIMIT = -1;
147
148         GenElementManager() {}
149         virtual ~GenElementManager();
150
151         virtual GenElement *create(int type) = 0;
152
153         virtual u32 add(GenElement *elem);
154         virtual GenElement *get(u32 id);
155         virtual GenElement *update(u32 id, GenElement *elem);
156         virtual GenElement *remove(u32 id);
157
158         virtual GenElement *getByName(const char *name);
159         virtual GenElement *getByName(std::string &name);
160
161 protected:
162         std::vector<GenElement *> m_elements;
163 };
164
165 #endif