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
29 class BiomeDefManager;
32 //struct BlockMakeData;
34 class ManualMapVoxelManipulator;
35 class VoxelManipulator;
36 class INodeDefManager;
46 struct BlockMakeData {
48 ManualMapVoxelManipulator *vmanip;
52 v3s16 blockpos_requested;
53 UniqueQueue<v3s16> transforming_liquid;
54 INodeDefManager *nodedef;
61 /////////////////// Mapgen flags
64 #define MG_DUNGEONS 0x04
65 #define MGV6_FORESTS 0x08
66 #define MGV6_BIOME_BLEND 0x10
68 #define AVERAGE_MUD_AMOUNT 4
70 /////////////////// Mapgen V6 perlin noise default values
71 NoiseParams nparams_v6_def_terrain_base =
72 {-AVERAGE_MUD_AMOUNT, 20.0, v3f(250.0, 250.0, 250.0), 82341, 5, 0.6};
73 NoiseParams nparams_v6_def_terrain_higher =
74 {20.0, 16.0, v3f(500.0, 500.0, 500.0), 85309, 5, 0.6};
75 NoiseParams nparams_v6_def_steepness =
76 {0.85, 0.5, v3f(125.0, 125.0, 125.0), -932, 5, 0.7};
77 NoiseParams nparams_v6_def_height_select =
78 {0.5, 1.0, v3f(250.0, 250.0, 250.0), 4213, 5, 0.69};
79 NoiseParams nparams_v6_def_trees =
80 {0.0, 1.0, v3f(125.0, 125.0, 125.0), 2, 4, 0.66};
81 NoiseParams nparams_v6_def_mud =
82 {AVERAGE_MUD_AMOUNT, 2.0, v3f(200.0, 200.0, 200.0), 91013, 3, 0.55};
83 NoiseParams nparams_v6_def_beach =
84 {0.0, 1.0, v3f(250.0, 250.0, 250.0), 59420, 3, 0.50};
85 NoiseParams nparams_v6_def_biome =
86 {0.0, 1.0, v3f(250.0, 250.0, 250.0), 9130, 3, 0.50};
87 NoiseParams nparams_v6_def_cave =
88 {6.0, 6.0, v3f(250.0, 250.0, 250.0), 34329, 3, 0.50};
90 /////////////////// Mapgen V7 perlin noise default values
91 NoiseParams nparams_v7_def_terrain =
92 {10.0, 12.0, v3f(350., 350., 350.), 82341, 5, 0.6}; //terrain
93 NoiseParams nparams_v7_def_bgroup =
94 {0.5, 1/(2*1.6), v3f(350., 350., 350.), 5923, 2, 0.60}; //0 to 1
95 NoiseParams nparams_v7_def_heat =
96 {25.0, 50.0, v3f(500., 500., 500.), 35293, 1, 0.00}; //-25 to 75
97 NoiseParams nparams_v7_def_humidity =
98 {50, 100/(2*1.6), v3f(750., 750., 750.), 12094, 2, 0.60}; //0 to 100
100 struct MapgenParams {
110 flags = MG_TREES | MG_CAVES | MGV6_BIOME_BLEND;
115 struct MapgenV6Params : public MapgenParams {
118 NoiseParams *np_terrain_base;
119 NoiseParams *np_terrain_higher;
120 NoiseParams *np_steepness;
121 NoiseParams *np_height_select;
122 NoiseParams *np_trees;
124 NoiseParams *np_beach;
125 NoiseParams *np_biome;
126 NoiseParams *np_cave;
131 np_terrain_base = &nparams_v6_def_terrain_base;
132 np_terrain_higher = &nparams_v6_def_terrain_higher;
133 np_steepness = &nparams_v6_def_steepness;
134 np_height_select = &nparams_v6_def_height_select;
135 np_trees = &nparams_v6_def_trees;
136 np_mud = &nparams_v6_def_mud;
137 np_beach = &nparams_v6_def_beach;
138 np_biome = &nparams_v6_def_biome;
139 np_cave = &nparams_v6_def_cave;
143 struct MapgenV7Params : public MapgenParams {
144 NoiseParams *np_terrain;
145 NoiseParams *np_bgroup;
146 NoiseParams *np_heat;
147 NoiseParams *np_humidity;
150 np_terrain = &nparams_v7_def_terrain;
151 np_bgroup = &nparams_v7_def_bgroup;
152 np_heat = &nparams_v7_def_heat;
153 np_humidity = &nparams_v7_def_humidity;
165 virtual void makeChunk(BlockMakeData *data) {};
167 //Legacy functions for Farmesh (pending removal)
168 static bool get_have_beach(u64 seed, v2s16 p2d);
169 static double tree_amount_2d(u64 seed, v2s16 p);
170 static s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
174 class MapgenV6 : public Mapgen {
176 //ManualMapVoxelManipulator &vmanip;
184 Noise *noise_terrain_base;
185 Noise *noise_terrain_higher;
186 Noise *noise_steepness;
187 Noise *noise_height_select;
194 float *map_terrain_base;
195 float *map_terrain_higher;
196 float *map_steepness;
197 float *map_height_select;
208 MapgenV6(int mapgenid, MapgenV6Params *params);
211 void makeChunk(BlockMakeData *data);
214 static s16 find_ground_level(VoxelManipulator &vmanip, v2s16 p2d, INodeDefManager *ndef);
215 static s16 find_stone_level(VoxelManipulator &vmanip, v2s16 p2d, INodeDefManager *ndef);
216 void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, bool is_apple_tree, INodeDefManager *ndef);
217 double tree_amount_2d(u64 seed, v2s16 p);
218 bool block_is_underground(u64 seed, v3s16 blockpos);
219 double base_rock_level_2d(u64 seed, v2s16 p);
220 s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
221 double get_mud_add_amount(u64 seed, v2s16 p);
222 bool get_have_beach(u64 seed, v2s16 p2d);
223 BiomeType get_biome(u64 seed, v2s16 p2d);
224 u32 get_blockseed(u64 seed, v3s16 p);
228 class MapgenV7 : public Mapgen {
231 ManualMapVoxelManipulator *vmanip;
232 INodeDefManager *ndef;
233 BiomeDefManager *biomedef;
240 Noise *noise_terrain;
243 Noise *noise_humidity;
258 NoiseParams *np_terrain;
259 NoiseParams *np_bgroup;
260 NoiseParams *np_heat;
261 NoiseParams *np_humidity;*/
263 //should these be broken off into a "commonly used nodes" class?
268 MapgenV7(BiomeDefManager *biomedef, int mapgenid, MapgenV7Params *params);
271 void makeChunk(BlockMakeData *data);
272 void updateLiquid(v3s16 node_min, v3s16 node_max);
273 void updateLighting(v3s16 node_min, v3s16 node_max);
275 //Legacy functions for Farmesh (pending removal)
276 // static bool get_have_beach(u64 seed, v2s16 p2d);
277 // static double tree_amount_2d(u64 seed, v2s16 p);
278 // static s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
281 class EmergeManager {
285 MapgenParams *params;
287 //mapgen objects here
291 BiomeDefManager *biomedef;
293 EmergeManager(IGameDef *gamedef, int mg_version=6);
297 void setMapgenParams();
298 void addBlockToQueue();
300 //mapgen helper methods
301 Biome *getBiomeAtPoint(v3s16 p);
302 int getGroundLevelAtPoint(v2s16 p);
303 bool isBlockUnderground(v3s16 blockpos);
304 u32 getBlockSeed(v3s16 p);
311 // Finds precise ground level at any position
312 s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
314 // Find out if block is completely underground
315 bool block_is_underground(u64 seed, v3s16 blockpos);
317 // Get a pseudorandom seed for a position on the map
318 u32 get_blockseed(u64 seed, v3s16 p);
320 // Main map generation routine
321 void make_block(BlockMakeData *data);
324 //These are used by FarMesh
325 bool get_have_beach(u64 seed, v2s16 p2d);
326 double tree_amount_2d(u64 seed, v2s16 p);
331 ManualMapVoxelManipulator *vmanip; // Destructor deletes
335 v3s16 blockpos_requested;
336 UniqueQueue<v3s16> transforming_liquid;
337 INodeDefManager *nodedef;
343 }; // namespace mapgen