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