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