Cavegen: Move V5-style caves to CavesNoiseIntersection
[oweals/minetest.git] / src / mapgen_valleys.h
1 /*
2 Minetest Valleys C
3 Copyright (C) 2010-2015 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4 Copyright (C) 2010-2015 paramat, Matt Gregory
5 Copyright (C) 2016 Duane Robertson <duane@duanerobertson.com>
6
7 Based on Valleys Mapgen by Gael de Sailly
8  (https://forum.minetest.net/viewtopic.php?f=9&t=11430)
9 and mapgen_v7 by kwolekr and paramat.
10
11 Licensing changed by permission of Gael de Sailly.
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU Lesser General Public License as published by
15 the Free Software Foundation; either version 2.1 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 GNU Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public License along
24 with this program; if not, write to the Free Software Foundation, Inc.,
25 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 */
27
28 #ifndef MAPGEN_VALLEYS_HEADER
29 #define MAPGEN_VALLEYS_HEADER
30
31 #include "mapgen.h"
32
33 ////////////// Mapgen Valleys flags
34 #define MGVALLEYS_ALT_CHILL    0x01
35 #define MGVALLEYS_HUMID_RIVERS 0x02
36
37 // Feed only one variable into these.
38 #define MYSQUARE(x) (x) * (x)
39 #define MYCUBE(x) (x) * (x) * (x)
40
41 class BiomeManager;
42 class BiomeGenOriginal;
43
44 // Global profiler
45 //class Profiler;
46 //extern Profiler *mapgen_profiler;
47
48
49 struct MapgenValleysParams : public MapgenSpecificParams {
50         u32 spflags;
51         s16 large_cave_depth;
52         s16 massive_cave_depth;
53         u16 altitude_chill;
54         u16 lava_features;
55         u16 river_depth;
56         u16 river_size;
57         u16 water_features;
58         float cave_width;
59         NoiseParams np_cave1;
60         NoiseParams np_cave2;
61         NoiseParams np_filler_depth;
62         NoiseParams np_inter_valley_fill;
63         NoiseParams np_inter_valley_slope;
64         NoiseParams np_rivers;
65         NoiseParams np_massive_caves;
66         NoiseParams np_terrain_height;
67         NoiseParams np_valley_depth;
68         NoiseParams np_valley_profile;
69
70         MapgenValleysParams();
71         ~MapgenValleysParams() {}
72
73         void readParams(const Settings *settings);
74         void writeParams(Settings *settings) const;
75 };
76
77 struct TerrainNoise {
78         s16 x;
79         s16 z;
80         float terrain_height;
81         float *rivers;
82         float *valley;
83         float valley_profile;
84         float *slope;
85         float inter_valley_fill;
86 };
87
88 class MapgenValleys : public MapgenBasic {
89 public:
90
91         MapgenValleys(int mapgenid, MapgenParams *params, EmergeManager *emerge);
92         ~MapgenValleys();
93
94         virtual void makeChunk(BlockMakeData *data);
95         int getSpawnLevelAtPoint(v2s16 p);
96
97         s16 large_cave_depth;
98
99 private:
100         BiomeGenOriginal *m_bgen;
101
102         int zstride;
103         int zstride_1d;
104
105         float map_gen_limit;
106
107         bool humid_rivers;
108         bool use_altitude_chill;
109         float humidity_adjust;
110         s16 cave_water_max_height;
111         s16 lava_max_height;
112
113         u32 spflags;
114         float altitude_chill;
115         s16 lava_features_lim;
116         s16 massive_cave_depth;
117         float river_depth_bed;
118         float river_size_factor;
119         float *tcave_cache;
120         s16 water_features_lim;
121         Noise *noise_inter_valley_fill;
122         Noise *noise_inter_valley_slope;
123         Noise *noise_rivers;
124         Noise *noise_cave1;
125         Noise *noise_cave2;
126         Noise *noise_massive_caves;
127         Noise *noise_terrain_height;
128         Noise *noise_valley_depth;
129         Noise *noise_valley_profile;
130
131         content_t c_cobble;
132         content_t c_dirt;
133         content_t c_lava_source;
134         content_t c_mossycobble;
135         content_t c_sand;
136         content_t c_sandstonebrick;
137         content_t c_stair_cobble;
138         content_t c_stair_sandstonebrick;
139
140         float terrainLevelAtPoint(s16 x, s16 z);
141
142         void calculateNoise();
143
144         virtual int generateTerrain();
145         float terrainLevelFromNoise(TerrainNoise *tn);
146         float adjustedTerrainLevelFromNoise(TerrainNoise *tn);
147
148         virtual void generateCaves(s16 max_stone_y, s16 large_cave_depth);
149 };
150
151 struct MapgenFactoryValleys : public MapgenFactory {
152         Mapgen *createMapgen(int mgid, MapgenParams *params, EmergeManager *emerge)
153         {
154                 return new MapgenValleys(mgid, params, emerge);
155         };
156
157         MapgenSpecificParams *createMapgenParams()
158         {
159                 return new MapgenValleysParams();
160         };
161 };
162
163 #endif