3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
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.
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.
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.
20 #ifndef CAVEGEN_HEADER
21 #define CAVEGEN_HEADER
23 #define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1
24 #define DEFAULT_LAVA_DEPTH (-256)
26 class GenerateNotifier;
29 CavesRandomWalk is an implementation of a cave-digging algorithm that
30 operates on the principle of a "random walk" to approximate the stochiastic
31 activity of cavern development.
33 In summary, this algorithm works by carving a randomly sized tunnel in a
34 random direction a random amount of times, randomly varying in width.
35 All randomness here is uniformly distributed; alternative distributions have
36 not yet been implemented.
38 This algorithm is very fast, executing in less than 1ms on average for an
39 80x80x80 chunk of map on a modern processor.
41 class CavesRandomWalk {
44 INodeDefManager *ndef;
45 GenerateNotifier *gennotify;
48 // configurable parameters
52 NoiseParams *np_caveliquids;
54 // intermediate state variables
57 s16 min_tunnel_diameter;
58 s16 max_tunnel_diameter;
59 u16 tunnel_routepoints;
60 int part_max_length_rs;
63 bool large_cave_is_flat;
70 v3f orp; // starting point, relative to caved space
71 v3s16 of; // absolute coordinates of caved space
72 v3s16 ar; // allowed route area
73 s16 rs; // tunnel radius size
81 content_t c_water_source;
82 content_t c_lava_source;
84 // ndef is a mandatory parameter.
85 // If gennotify is NULL, generation events are not logged.
86 CavesRandomWalk(INodeDefManager *ndef,
87 GenerateNotifier *gennotify = NULL,
90 content_t water_source = CONTENT_IGNORE,
91 content_t lava_source = CONTENT_IGNORE);
93 // vm and ps are mandatory parameters.
94 // If heightmap is NULL, the surface level at all points is assumed to
96 void makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, PseudoRandom *ps,
97 bool is_large_cave, int max_stone_height, s16 *heightmap);
100 void makeTunnel(bool dirswitch);
101 void carveRoute(v3f vec, float f, bool randomize_xz);
103 inline bool isPosAboveSurface(v3s16 p);
107 CavesV6 is the original version of caves used with Mapgen V6.
109 Though it uses the same fundamental algorithm as CavesRandomWalk, it is made
110 separate to preserve the exact sequence of PseudoRandom calls - any change
111 to this ordering results in the output being radically different.
112 Because caves in Mapgen V6 are responsible for a large portion of the basic
113 terrain shape, modifying this will break our contract of reverse
114 compatibility for a 'stable' mapgen such as V6.
117 *** DO NOT TOUCH THIS CLASS UNLESS YOU KNOW WHAT YOU ARE DOING ***
122 INodeDefManager *ndef;
123 GenerateNotifier *gennotify;
127 // configurable parameters
129 content_t c_water_source;
130 content_t c_lava_source;
133 // intermediate state variables
136 s16 min_tunnel_diameter;
137 s16 max_tunnel_diameter;
138 u16 tunnel_routepoints;
139 int part_max_length_rs;
142 bool large_cave_is_flat;
147 v3f orp; // starting point, relative to caved space
148 v3s16 of; // absolute coordinates of caved space
149 v3s16 ar; // allowed route area
150 s16 rs; // tunnel radius size
156 // ndef is a mandatory parameter.
157 // If gennotify is NULL, generation events are not logged.
158 CavesV6(INodeDefManager *ndef,
159 GenerateNotifier *gennotify = NULL,
161 content_t water_source = CONTENT_IGNORE,
162 content_t lava_source = CONTENT_IGNORE);
164 // vm, ps, and ps2 are mandatory parameters.
165 // If heightmap is NULL, the surface level at all points is assumed to
167 void makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax,
168 PseudoRandom *ps, PseudoRandom *ps2,
169 bool is_large_cave, int max_stone_height, s16 *heightmap = NULL);
172 void makeTunnel(bool dirswitch);
173 void carveRoute(v3f vec, float f, bool randomize_xz, bool tunnel_above_ground);
175 inline s16 getSurfaceFromHeightmap(v3s16 p);