7b1e3102062593e4774b6293eb05bfa8a7e59ffb
[oweals/minetest.git] / src / mapgen_v6.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 MAPGENV6_HEADER
21 #define MAPGENV6_HEADER
22
23 #include "mapgen.h"
24
25 #define AVERAGE_MUD_AMOUNT 4
26 #define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1
27
28 enum BiomeType
29 {
30         BT_NORMAL,
31         BT_DESERT
32 };
33
34 extern NoiseParams nparams_v6_def_terrain_base;
35 extern NoiseParams nparams_v6_def_terrain_higher;
36 extern NoiseParams nparams_v6_def_steepness;
37 extern NoiseParams nparams_v6_def_height_select;
38 extern NoiseParams nparams_v6_def_trees;
39 extern NoiseParams nparams_v6_def_mud;
40 extern NoiseParams nparams_v6_def_beach;
41 extern NoiseParams nparams_v6_def_biome;
42 extern NoiseParams nparams_v6_def_cave;
43
44 struct MapgenV6Params : public MapgenParams {
45         float freq_desert;
46         float freq_beach;
47         NoiseParams *np_terrain_base;
48         NoiseParams *np_terrain_higher;
49         NoiseParams *np_steepness;
50         NoiseParams *np_height_select;
51         NoiseParams *np_trees;
52         NoiseParams *np_mud;
53         NoiseParams *np_beach;
54         NoiseParams *np_biome;
55         NoiseParams *np_cave;
56
57         MapgenV6Params() {
58                 freq_desert       = 0.45;
59                 freq_beach        = 0.15;
60                 np_terrain_base   = &nparams_v6_def_terrain_base;
61                 np_terrain_higher = &nparams_v6_def_terrain_higher;
62                 np_steepness      = &nparams_v6_def_steepness;
63                 np_height_select  = &nparams_v6_def_height_select;
64                 np_trees          = &nparams_v6_def_trees;
65                 np_mud            = &nparams_v6_def_mud;
66                 np_beach          = &nparams_v6_def_beach;
67                 np_biome          = &nparams_v6_def_biome;
68                 np_cave           = &nparams_v6_def_cave;
69         }
70         
71         bool readParams(Settings *settings);
72         void writeParams(Settings *settings);
73 };
74
75 class MapgenV6 : public Mapgen {
76 public:
77         int ystride;
78         v3s16 csize;
79         u32 flags;
80
81         u32 blockseed;
82         v3s16 node_min;
83         v3s16 node_max;
84         v3s16 full_node_min;
85         v3s16 full_node_max;
86         v3s16 central_area_size;
87         int volume_nodes;
88
89         Noise *noise_terrain_base;
90         Noise *noise_terrain_higher;
91         Noise *noise_steepness;
92         Noise *noise_height_select;
93         Noise *noise_trees;
94         Noise *noise_mud;
95         Noise *noise_beach;
96         Noise *noise_biome;
97         NoiseParams *np_cave;
98         float freq_desert;
99         float freq_beach;
100         
101         content_t c_stone;
102         content_t c_dirt;
103         content_t c_dirt_with_grass;
104         content_t c_sand;
105         content_t c_water_source;
106         content_t c_lava_source;
107         content_t c_gravel;
108         content_t c_cobble;
109         content_t c_desert_sand;
110         content_t c_desert_stone;
111
112         MapgenV6(int mapgenid, MapgenV6Params *params);
113         ~MapgenV6();
114         
115         void makeChunk(BlockMakeData *data);
116         int getGroundLevelAtPoint(v2s16 p);
117
118         float baseTerrainLevel(float terrain_base, float terrain_higher,
119                                                    float steepness, float height_select);
120         float baseTerrainLevelFromNoise(v2s16 p);
121         float baseTerrainLevelFromMap(v2s16 p);
122         float baseTerrainLevelFromMap(int index);
123
124         s16 find_ground_level(v2s16 p2d);
125         s16 find_stone_level(v2s16 p2d);
126         bool block_is_underground(u64 seed, v3s16 blockpos);
127         s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
128         
129         float getTreeAmount(v2s16 p);
130         float getTreeAmount(int index);
131         float getMudAmount(v2s16 p);
132         float getMudAmount(int index);
133         bool getHaveBeach(v2s16 p);
134         bool getHaveBeach(int index);
135         BiomeType getBiome(v2s16 p);
136         BiomeType getBiome(int index, v2s16 p);
137         
138         u32 get_blockseed(u64 seed, v3s16 p);
139         
140         
141         void calculateNoise();
142         int generateGround();
143         void addMud();
144         void flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos);
145         void addDirtGravelBlobs();
146         void growGrass();
147         void placeTrees();
148         void generateCaves(int max_stone_y);
149 };
150
151 struct MapgenFactoryV6 : public MapgenFactory {
152         Mapgen *createMapgen(int mgid, MapgenParams *params, EmergeManager *emerge) {
153                 return new MapgenV6(mgid, (MapgenV6Params *)params);
154         };
155         
156         MapgenParams *createMapgenParams() {
157                 return new MapgenV6Params();
158         };
159 };
160
161 #endif