mgv7: Implement getGroundLevelAtPoint(), fix layer of topnodes at chunk Y boundaries...
[oweals/minetest.git] / src / mapgen_v7.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
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_V7_HEADER
21 #define MAPGEN_V7_HEADER
22
23 #include "mapgen.h"
24
25 extern NoiseParams nparams_v7_def_terrain_base;
26 extern NoiseParams nparams_v7_def_terrain_alt;
27 extern NoiseParams nparams_v7_def_terrain_mod;
28 extern NoiseParams nparams_v7_def_terrain_persist;
29 extern NoiseParams nparams_v7_def_height_select;
30 extern NoiseParams nparams_v7_def_ridge;
31
32 struct MapgenV7Params : public MapgenParams {
33         NoiseParams *np_terrain_base;
34         NoiseParams *np_terrain_alt;
35         NoiseParams *np_terrain_mod;
36         NoiseParams *np_terrain_persist;
37         NoiseParams *np_height_select;
38         NoiseParams *np_ridge;
39         
40         MapgenV7Params() {
41                 np_terrain_base    = &nparams_v7_def_terrain_base;
42                 np_terrain_alt     = &nparams_v7_def_terrain_alt;
43                 np_terrain_mod     = &nparams_v7_def_terrain_mod;
44                 np_terrain_persist = &nparams_v7_def_terrain_persist;
45                 np_height_select   = &nparams_v7_def_height_select;
46                 np_ridge           = &nparams_v7_def_ridge;
47         }
48         
49         bool readParams(Settings *settings);
50         void writeParams(Settings *settings);
51 };
52
53 class MapgenV7 : public Mapgen {
54 public:
55         EmergeManager *emerge;
56         BiomeDefManager *bmgr;
57
58         int ystride;
59         v3s16 csize;
60         u32 flags;
61
62         u32 blockseed;
63         v3s16 node_min;
64         v3s16 node_max;
65         v3s16 full_node_min;
66         v3s16 full_node_max;
67         
68         s16 *heightmap;
69         s16 *ridge_heightmap;
70         u8 *biomemap;
71         
72         Noise *noise_terrain_base;
73         Noise *noise_terrain_alt;
74         Noise *noise_terrain_mod;
75         Noise *noise_terrain_persist;
76         Noise *noise_height_select;
77         
78         Noise *noise_ridge;
79         
80         Noise *noise_heat;
81         Noise *noise_humidity;
82         
83         content_t c_stone;
84         content_t c_dirt;
85         content_t c_dirt_with_grass;
86         content_t c_sand;
87         content_t c_water_source;
88         content_t c_lava_source;
89         content_t c_gravel;
90         content_t c_cobble;
91         content_t c_desert_sand;
92         content_t c_desert_stone;
93
94         MapgenV7(int mapgenid, MapgenV7Params *params, EmergeManager *emerge);
95         ~MapgenV7();
96         
97         void makeChunk(BlockMakeData *data);
98         int getGroundLevelAtPoint(v2s16 p);
99         Biome *getBiomeAtPoint(v3s16 p);
100
101         float baseTerrainLevelAtPoint(int x, int z);
102         float baseTerrainLevelFromMap(int index);
103         void calculateNoise();
104         int calcHeightMap();
105         
106         void generateTerrain();
107         void carveRidges();
108         //void carveRivers(); //experimental
109         
110         void testBiomes();
111         void addTopNodes();
112         
113         void generateCaves(int max_stone_y);
114 };
115
116 struct MapgenFactoryV7 : public MapgenFactory {
117         Mapgen *createMapgen(int mgid, MapgenParams *params, EmergeManager *emerge) {
118                 return new MapgenV7(mgid, (MapgenV7Params *)params, emerge);
119         };
120         
121         MapgenParams *createMapgenParams() {
122                 return new MapgenV7Params();
123         };
124 };
125
126 #endif