]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mapgen.h
Workaround failing Travis clang build.
[dragonfireclient.git] / src / mapgen.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 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_extrabloated.h"
24 #include "util/container.h" // UniqueQueue
25 #include "gamedef.h"
26 #include "mapnode.h"
27 #include "noise.h"
28 #include "settings.h"
29
30 /////////////////// Mapgen flags
31 #define MG_TREES         0x01
32 #define MG_CAVES         0x02
33 #define MG_DUNGEONS      0x04
34 #define MGV6_FORESTS     0x08
35 #define MGV6_BIOME_BLEND 0x10
36
37 #define AVERAGE_MUD_AMOUNT 4
38
39 class BiomeDefManager;
40 class Biome;
41
42 //struct BlockMakeData;
43 class MapBlock;
44 class ManualMapVoxelManipulator;
45 class VoxelManipulator;
46 class INodeDefManager;
47
48 extern NoiseParams nparams_v6_def_terrain_base;
49 extern NoiseParams nparams_v6_def_terrain_higher;
50 extern NoiseParams nparams_v6_def_steepness;
51 extern NoiseParams nparams_v6_def_height_select;
52 extern NoiseParams nparams_v6_def_trees;
53 extern NoiseParams nparams_v6_def_mud;
54 extern NoiseParams nparams_v6_def_beach;
55 extern NoiseParams nparams_v6_def_biome;
56 extern NoiseParams nparams_v6_def_cave;
57
58 extern NoiseParams nparams_v7_def_terrain;
59 extern NoiseParams nparams_v7_def_bgroup;
60 extern NoiseParams nparams_v7_def_heat;
61 extern NoiseParams nparams_v7_def_humidity;
62
63 enum BiomeType
64 {
65         BT_NORMAL,
66         BT_DESERT
67 };
68
69
70 struct BlockMakeData {
71         bool no_op;
72         ManualMapVoxelManipulator *vmanip;
73         u64 seed;
74         v3s16 blockpos_min;
75         v3s16 blockpos_max;
76         v3s16 blockpos_requested;
77         UniqueQueue<v3s16> transforming_liquid;
78         INodeDefManager *nodedef;
79
80         BlockMakeData();
81         ~BlockMakeData();
82 };
83
84
85 struct MapgenParams {
86         std::string mg_name;
87         int chunksize;
88         u64 seed;
89         int water_level;
90         u32 flags;
91
92         MapgenParams() {
93                 mg_name     = "v6";
94                 seed        = 0;
95                 water_level = 1;
96                 chunksize   = 5;
97                 flags       = MG_TREES | MG_CAVES | MGV6_BIOME_BLEND;
98         }
99
100         static MapgenParams *createMapgenParams(std::string &mgname);
101         static MapgenParams *getParamsFromSettings(Settings *settings);
102
103 };
104
105 struct MapgenV6Params : public MapgenParams {
106         float freq_desert;
107         float freq_beach;
108         NoiseParams *np_terrain_base;
109         NoiseParams *np_terrain_higher;
110         NoiseParams *np_steepness;
111         NoiseParams *np_height_select;
112         NoiseParams *np_trees;
113         NoiseParams *np_mud;
114         NoiseParams *np_beach;
115         NoiseParams *np_biome;
116         NoiseParams *np_cave;
117
118         MapgenV6Params() {
119                 freq_desert       = 0.45;
120                 freq_beach        = 0.15;
121                 np_terrain_base   = &nparams_v6_def_terrain_base;
122                 np_terrain_higher = &nparams_v6_def_terrain_higher;
123                 np_steepness      = &nparams_v6_def_steepness;
124                 np_height_select  = &nparams_v6_def_height_select;
125                 np_trees          = &nparams_v6_def_trees;
126                 np_mud            = &nparams_v6_def_mud;
127                 np_beach          = &nparams_v6_def_beach;
128                 np_biome          = &nparams_v6_def_biome;
129                 np_cave           = &nparams_v6_def_cave;
130         }
131 };
132
133
134 class Mapgen {
135 public:
136         int seed;
137         int water_level;
138         bool generating;
139         int id;
140
141         virtual void makeChunk(BlockMakeData *data) {};
142         virtual int getGroundLevelAtPoint(v2s16 p) = 0;
143
144         //Legacy functions for Farmesh (pending removal)
145         static bool get_have_beach(u64 seed, v2s16 p2d);
146         static double tree_amount_2d(u64 seed, v2s16 p);
147         static s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
148 };
149
150
151 class MapgenV6 : public Mapgen {
152 public:
153         //ManualMapVoxelManipulator &vmanip;
154
155         int ystride;
156         v3s16 csize;
157
158         v3s16 node_min;
159         v3s16 node_max;
160
161         Noise *noise_terrain_base;
162         Noise *noise_terrain_higher;
163         Noise *noise_steepness;
164         Noise *noise_height_select;
165         Noise *noise_trees;
166         Noise *noise_mud;
167         Noise *noise_beach;
168         Noise *noise_biome;
169
170         float *map_terrain_base;
171         float *map_terrain_higher;
172         float *map_steepness;
173         float *map_height_select;
174         float *map_trees;
175         float *map_mud;
176         float *map_beach;
177         float *map_biome;
178
179         NoiseParams *np_cave;
180
181         u32 flags;
182         float freq_desert;
183         float freq_beach;
184
185         MapgenV6(int mapgenid, MapgenV6Params *params);
186         ~MapgenV6();
187
188         void makeChunk(BlockMakeData *data);
189         int getGroundLevelAtPoint(v2s16 p);
190
191         double baseRockLevelFromNoise(v2s16 p);
192         static s16 find_ground_level(VoxelManipulator &vmanip, v2s16 p2d, INodeDefManager *ndef);
193         static s16 find_stone_level(VoxelManipulator &vmanip, v2s16 p2d, INodeDefManager *ndef);
194         void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, bool is_apple_tree, INodeDefManager *ndef);
195         double tree_amount_2d(u64 seed, v2s16 p);
196         bool block_is_underground(u64 seed, v3s16 blockpos);
197         double base_rock_level_2d(u64 seed, v2s16 p);
198         s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
199         double get_mud_add_amount(u64 seed, v2s16 p);
200         bool get_have_beach(u64 seed, v2s16 p2d);
201         BiomeType get_biome(u64 seed, v2s16 p2d);
202         u32 get_blockseed(u64 seed, v3s16 p);
203 };
204
205
206 class EmergeManager {
207 public:
208         //settings
209         MapgenParams *params;
210
211         //mapgen objects here
212         Mapgen *mapgen;
213
214         //biome manager
215         BiomeDefManager *biomedef;
216
217         EmergeManager(IGameDef *gamedef, BiomeDefManager *bdef, MapgenParams *mgparams);
218         ~EmergeManager();
219
220         Mapgen *getMapgen();
221         void addBlockToQueue();
222
223         //mapgen helper methods
224         Biome *getBiomeAtPoint(v3s16 p);
225         int getGroundLevelAtPoint(v2s16 p);
226         bool isBlockUnderground(v3s16 blockpos);
227         u32 getBlockSeed(v3s16 p);
228 };
229
230 #endif
231