3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
23 #include "irrlichttypes_extrabloated.h"
24 #include "util/container.h" // UniqueQueue
30 /////////////////// Mapgen flags
33 #define MG_DUNGEONS 0x04
34 #define MGV6_FORESTS 0x08
35 #define MGV6_BIOME_BLEND 0x10
37 #define AVERAGE_MUD_AMOUNT 4
39 class BiomeDefManager;
42 //struct BlockMakeData;
44 class ManualMapVoxelManipulator;
45 class VoxelManipulator;
46 class INodeDefManager;
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;
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;
70 struct BlockMakeData {
72 ManualMapVoxelManipulator *vmanip;
76 v3s16 blockpos_requested;
77 UniqueQueue<v3s16> transforming_liquid;
78 INodeDefManager *nodedef;
97 flags = MG_TREES | MG_CAVES | MGV6_BIOME_BLEND;
100 static MapgenParams *createMapgenParams(int mgver);
101 static MapgenParams *getParamsFromSettings(Settings *settings);
105 struct MapgenV6Params : public MapgenParams {
108 NoiseParams *np_terrain_base;
109 NoiseParams *np_terrain_higher;
110 NoiseParams *np_steepness;
111 NoiseParams *np_height_select;
112 NoiseParams *np_trees;
114 NoiseParams *np_beach;
115 NoiseParams *np_biome;
116 NoiseParams *np_cave;
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;
133 struct MapgenV7Params : public MapgenParams {
134 NoiseParams *np_terrain;
135 NoiseParams *np_bgroup;
136 NoiseParams *np_heat;
137 NoiseParams *np_humidity;
140 np_terrain = &nparams_v7_def_terrain;
141 np_bgroup = &nparams_v7_def_bgroup;
142 np_heat = &nparams_v7_def_heat;
143 np_humidity = &nparams_v7_def_humidity;
155 virtual void makeChunk(BlockMakeData *data) {};
156 virtual int getGroundLevelAtPoint(v2s16 p) = 0;
158 //Legacy functions for Farmesh (pending removal)
159 static bool get_have_beach(u64 seed, v2s16 p2d);
160 static double tree_amount_2d(u64 seed, v2s16 p);
161 static s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
165 class MapgenV6 : public Mapgen {
167 //ManualMapVoxelManipulator &vmanip;
175 Noise *noise_terrain_base;
176 Noise *noise_terrain_higher;
177 Noise *noise_steepness;
178 Noise *noise_height_select;
184 float *map_terrain_base;
185 float *map_terrain_higher;
186 float *map_steepness;
187 float *map_height_select;
193 NoiseParams *np_cave;
199 MapgenV6(int mapgenid, MapgenV6Params *params);
202 void makeChunk(BlockMakeData *data);
203 int getGroundLevelAtPoint(v2s16 p);
205 double baseRockLevelFromNoise(v2s16 p);
206 static s16 find_ground_level(VoxelManipulator &vmanip, v2s16 p2d, INodeDefManager *ndef);
207 static s16 find_stone_level(VoxelManipulator &vmanip, v2s16 p2d, INodeDefManager *ndef);
208 void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, bool is_apple_tree, INodeDefManager *ndef);
209 double tree_amount_2d(u64 seed, v2s16 p);
210 bool block_is_underground(u64 seed, v3s16 blockpos);
211 double base_rock_level_2d(u64 seed, v2s16 p);
212 s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
213 double get_mud_add_amount(u64 seed, v2s16 p);
214 bool get_have_beach(u64 seed, v2s16 p2d);
215 BiomeType get_biome(u64 seed, v2s16 p2d);
216 u32 get_blockseed(u64 seed, v3s16 p);
220 class MapgenV7 : public Mapgen {
223 ManualMapVoxelManipulator *vmanip;
224 INodeDefManager *ndef;
225 BiomeDefManager *biomedef;
232 Noise *noise_terrain;
235 Noise *noise_humidity;
249 //should these be broken off into a "commonly used nodes" class?
254 MapgenV7(BiomeDefManager *biomedef, int mapgenid, MapgenV7Params *params);
257 void makeChunk(BlockMakeData *data);
258 int getGroundLevelAtPoint(v2s16 p);
260 Biome *getBiomeAtPoint(v3s16 p);
261 void updateLiquid(v3s16 node_min, v3s16 node_max);
262 void updateLighting(v3s16 node_min, v3s16 node_max);
264 //Legacy functions for Farmesh (pending removal)
265 // static bool get_have_beach(u64 seed, v2s16 p2d);
266 // static double tree_amount_2d(u64 seed, v2s16 p);
267 // static s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
270 class EmergeManager {
273 MapgenParams *params;
275 //mapgen objects here
279 BiomeDefManager *biomedef;
281 EmergeManager(IGameDef *gamedef, BiomeDefManager *bdef, MapgenParams *mgparams);
285 void addBlockToQueue();
287 //mapgen helper methods
288 Biome *getBiomeAtPoint(v3s16 p);
289 int getGroundLevelAtPoint(v2s16 p);
290 bool isBlockUnderground(v3s16 blockpos);
291 u32 getBlockSeed(v3s16 p);