Cavegen: Remove CavesV6 dependency on Mapgen
[oweals/minetest.git] / src / cavegen.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 CAVEGEN_HEADER
21 #define CAVEGEN_HEADER
22
23 #define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1
24 #define DEFAULT_LAVA_DEPTH (-256)
25
26 class GenerateNotifier;
27
28 class CavesRandomWalk {
29 public:
30         Mapgen *mg;
31         MMVManip *vm;
32         INodeDefManager *ndef;
33         s16 *heightmap;
34
35         // variables
36         int lava_depth;
37         NoiseParams *np_caveliquids;
38
39         s16 min_tunnel_diameter;
40         s16 max_tunnel_diameter;
41         u16 tunnel_routepoints;
42         int dswitchint;
43         int part_max_length_rs;
44
45         bool large_cave_is_flat;
46         bool flooded;
47
48         s16 max_stone_y;
49         v3s16 node_min;
50         v3s16 node_max;
51
52         v3f orp;  // starting point, relative to caved space
53         v3s16 of; // absolute coordinates of caved space
54         v3s16 ar; // allowed route area
55         s16 rs;   // tunnel radius size
56         v3f main_direction;
57
58         s16 route_y_min;
59         s16 route_y_max;
60
61         PseudoRandom *ps;
62
63         content_t c_water_source;
64         content_t c_lava_source;
65         content_t c_ice;
66
67         int water_level;
68         u16 ystride;
69
70         CavesRandomWalk(Mapgen *mg, PseudoRandom *ps);
71         void makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height);
72         void makeTunnel(bool dirswitch);
73         void carveRoute(v3f vec, float f, bool randomize_xz);
74 };
75
76 /*
77         CavesV6 is the original version of caves used with Mapgen V6.
78
79         Though it uses the same fundamental algorithm as CavesRandomWalk, it is made
80         separate to preserve the exact sequence of PseudoRandom calls - any change
81         to this ordering results in the output being radically different.
82         Because caves in Mapgen V6 are responsible for a large portion of the basic
83         terrain shape, modifying this will break our contract of reverse
84         compatibility for a 'stable' mapgen such as V6.
85
86         tl;dr,
87         *** DO NOT TOUCH THIS CLASS UNLESS YOU KNOW WHAT YOU ARE DOING ***
88 */
89 class CavesV6 {
90 public:
91         MMVManip *vm;
92         INodeDefManager *ndef;
93         GenerateNotifier *gennotify;
94         PseudoRandom *ps;
95         PseudoRandom *ps2;
96
97         s16 *heightmap;
98         content_t c_water_source;
99         content_t c_lava_source;
100         int water_level;
101
102         u16 ystride;
103
104         s16 min_tunnel_diameter;
105         s16 max_tunnel_diameter;
106         u16 tunnel_routepoints;
107         int dswitchint;
108         int part_max_length_rs;
109
110         bool large_cave;
111         bool large_cave_is_flat;
112
113         v3s16 node_min;
114         v3s16 node_max;
115
116         v3f orp;  // starting point, relative to caved space
117         v3s16 of; // absolute coordinates of caved space
118         v3s16 ar; // allowed route area
119         s16 rs;   // tunnel radius size
120         v3f main_direction;
121
122         s16 route_y_min;
123         s16 route_y_max;
124
125         // ndef is a mandatory parameter.
126         // If gennotify is NULL, generation events are not logged.
127         CavesV6(INodeDefManager *ndef,
128                 GenerateNotifier *gennotify = NULL,
129                 int water_level = 1,
130                 content_t water_source = CONTENT_IGNORE,
131                 content_t lava_source = CONTENT_IGNORE);
132
133         // vm, ps, and ps2 are mandatory parameters.
134         // If heightmap is NULL, the surface level at all points is assumed to
135         // be water_level.
136         void makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax,
137                 PseudoRandom *ps, PseudoRandom *ps2,
138                 bool is_large_cave, int max_stone_height, s16 *heightmap = NULL);
139
140 private:
141         void makeTunnel(bool dirswitch);
142         void carveRoute(v3f vec, float f, bool randomize_xz, bool tunnel_above_ground);
143 };
144
145 #endif