Skip to content

Commit 4046f3e

Browse files
committedJul 19, 2015
Cavegen: Mgv6: No small caves entirely above ground
Mgv5/mgv7: Remove 'should make cave hole' feature Remove ravine code
1 parent e47f390 commit 4046f3e

File tree

2 files changed

+36
-72
lines changed

2 files changed

+36
-72
lines changed
 

‎src/cavegen.cpp

+34-70
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void CaveV5::makeTunnel(bool dirswitch) {
138138
(float)(ps->next() % maxlen.Z) - (float)maxlen.Z / 2
139139
);
140140

141-
// Do not make large caves that are above ground.
141+
// Do not make caves that are above ground.
142142
// It is only necessary to check the startpoint and endpoint.
143143
v3s16 orpi(orp.X, orp.Y, orp.Z);
144144
v3s16 veci(vec.X, vec.Y, vec.Z);
@@ -193,20 +193,15 @@ void CaveV5::makeTunnel(bool dirswitch) {
193193
// Every second section is rough
194194
bool randomize_xz = (ps->range(1, 2) == 1);
195195

196-
// Make a ravine every once in a while if it's long enough
197-
//float xylen = vec.X * vec.X + vec.Z * vec.Z;
198-
//disable ravines for now
199-
bool is_ravine = false; //(xylen > 500.0) && !large_cave && (ps->range(1, 8) == 1);
200-
201196
// Carve routes
202197
for (float f = 0; f < 1.0; f += 1.0 / veclen)
203-
carveRoute(vec, f, randomize_xz, is_ravine);
198+
carveRoute(vec, f, randomize_xz);
204199

205200
orp = rp;
206201
}
207202

208203

209-
void CaveV5::carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine) {
204+
void CaveV5::carveRoute(v3f vec, float f, bool randomize_xz) {
210205
MapNode airnode(CONTENT_AIR);
211206
MapNode waternode(c_water_source);
212207
MapNode lavanode(c_lava_source);
@@ -230,15 +225,12 @@ void CaveV5::carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine) {
230225
d1 += ps->range(-1, 1);
231226
}
232227

233-
bool should_make_cave_hole = ps->range(1, 10) == 1;
234-
235228
for (s16 z0 = d0; z0 <= d1; z0++) {
236229
s16 si = rs / 2 - MYMAX(0, abs(z0) - rs / 7 - 1);
237230
for (s16 x0 = -si - ps->range(0,1); x0 <= si - 1 + ps->range(0,1); x0++) {
238231
s16 maxabsxz = MYMAX(abs(x0), abs(z0));
239232

240-
s16 si2 = is_ravine ? MYMIN(ps->range(25, 26), ar.Y) :
241-
rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
233+
s16 si2 = rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
242234

243235
for (s16 y0 = -si2; y0 <= si2; y0++) {
244236
if (large_cave_is_flat) {
@@ -250,15 +242,6 @@ void CaveV5::carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine) {
250242
v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
251243
p += of;
252244

253-
if (!is_ravine && mg->heightmap && should_make_cave_hole &&
254-
p.X <= node_max.X && p.Z <= node_max.Z) {
255-
int maplen = node_max.X - node_min.X + 1;
256-
int idx = (p.Z - node_min.Z) * maplen +
257-
(p.X - node_min.X);
258-
if (p.Y >= mg->heightmap[idx] - 2)
259-
continue;
260-
}
261-
262245
if (vm->m_area.contains(p) == false)
263246
continue;
264247

@@ -431,38 +414,36 @@ void CaveV6::makeTunnel(bool dirswitch) {
431414
);
432415
}
433416

434-
// Do not make large caves that are entirely above ground.
417+
// Do not make caves that are entirely above ground.
435418
// It is only necessary to check the startpoint and endpoint.
436-
if (large_cave) {
437-
v3s16 orpi(orp.X, orp.Y, orp.Z);
438-
v3s16 veci(vec.X, vec.Y, vec.Z);
439-
s16 h1;
440-
s16 h2;
441-
442-
v3s16 p1 = orpi + veci + of + rs / 2;
443-
if (p1.Z >= node_min.Z && p1.Z <= node_max.Z &&
444-
p1.X >= node_min.X && p1.X <= node_max.X) {
445-
u32 index1 = (p1.Z - node_min.Z) * mg->ystride +
446-
(p1.X - node_min.X);
447-
h1 = mg->heightmap[index1];
448-
} else {
449-
h1 = water_level; // If not in heightmap
450-
}
451-
452-
v3s16 p2 = orpi + of + rs / 2;
453-
if (p2.Z >= node_min.Z && p2.Z <= node_max.Z &&
454-
p2.X >= node_min.X && p2.X <= node_max.X) {
455-
u32 index2 = (p2.Z - node_min.Z) * mg->ystride +
456-
(p2.X - node_min.X);
457-
h2 = mg->heightmap[index2];
458-
} else {
459-
h2 = water_level;
460-
}
419+
v3s16 orpi(orp.X, orp.Y, orp.Z);
420+
v3s16 veci(vec.X, vec.Y, vec.Z);
421+
s16 h1;
422+
s16 h2;
423+
424+
v3s16 p1 = orpi + veci + of + rs / 2;
425+
if (p1.Z >= node_min.Z && p1.Z <= node_max.Z &&
426+
p1.X >= node_min.X && p1.X <= node_max.X) {
427+
u32 index1 = (p1.Z - node_min.Z) * mg->ystride +
428+
(p1.X - node_min.X);
429+
h1 = mg->heightmap[index1];
430+
} else {
431+
h1 = water_level; // If not in heightmap
432+
}
461433

462-
if (p1.Y > h1 && p2.Y > h2) // If startpoint and endpoint are above ground
463-
return;
434+
v3s16 p2 = orpi + of + rs / 2;
435+
if (p2.Z >= node_min.Z && p2.Z <= node_max.Z &&
436+
p2.X >= node_min.X && p2.X <= node_max.X) {
437+
u32 index2 = (p2.Z - node_min.Z) * mg->ystride +
438+
(p2.X - node_min.X);
439+
h2 = mg->heightmap[index2];
440+
} else {
441+
h2 = water_level;
464442
}
465443

444+
if (p1.Y > h1 && p2.Y > h2) // If startpoint and endpoint are above ground
445+
return;
446+
466447
vec += main_direction;
467448

468449
v3f rp = orp + vec;
@@ -680,7 +661,7 @@ void CaveV7::makeTunnel(bool dirswitch) {
680661
(float)(ps->next() % maxlen.Z) - (float)maxlen.Z / 2
681662
);
682663

683-
// Do not make large caves that are above ground.
664+
// Do not make caves that are above ground.
684665
// It is only necessary to check the startpoint and endpoint.
685666
v3s16 orpi(orp.X, orp.Y, orp.Z);
686667
v3s16 veci(vec.X, vec.Y, vec.Z);
@@ -735,20 +716,15 @@ void CaveV7::makeTunnel(bool dirswitch) {
735716
// Every second section is rough
736717
bool randomize_xz = (ps->range(1, 2) == 1);
737718

738-
// Make a ravine every once in a while if it's long enough
739-
//float xylen = vec.X * vec.X + vec.Z * vec.Z;
740-
//disable ravines for now
741-
bool is_ravine = false; //(xylen > 500.0) && !large_cave && (ps->range(1, 8) == 1);
742-
743719
// Carve routes
744720
for (float f = 0; f < 1.0; f += 1.0 / veclen)
745-
carveRoute(vec, f, randomize_xz, is_ravine);
721+
carveRoute(vec, f, randomize_xz);
746722

747723
orp = rp;
748724
}
749725

750726

751-
void CaveV7::carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine) {
727+
void CaveV7::carveRoute(v3f vec, float f, bool randomize_xz) {
752728
MapNode airnode(CONTENT_AIR);
753729
MapNode waternode(c_water_source);
754730
MapNode lavanode(c_lava_source);
@@ -773,15 +749,12 @@ void CaveV7::carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine) {
773749
d1 += ps->range(-1, 1);
774750
}
775751

776-
bool should_make_cave_hole = ps->range(1, 10) == 1;
777-
778752
for (s16 z0 = d0; z0 <= d1; z0++) {
779753
s16 si = rs / 2 - MYMAX(0, abs(z0) - rs / 7 - 1);
780754
for (s16 x0 = -si - ps->range(0,1); x0 <= si - 1 + ps->range(0,1); x0++) {
781755
s16 maxabsxz = MYMAX(abs(x0), abs(z0));
782756

783-
s16 si2 = is_ravine ? MYMIN(ps->range(25, 26), ar.Y) :
784-
rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
757+
s16 si2 = rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
785758

786759
for (s16 y0 = -si2; y0 <= si2; y0++) {
787760
if (large_cave_is_flat) {
@@ -793,15 +766,6 @@ void CaveV7::carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine) {
793766
v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
794767
p += of;
795768

796-
if (!is_ravine && mg->heightmap && should_make_cave_hole &&
797-
p.X <= node_max.X && p.Z <= node_max.Z) {
798-
int maplen = node_max.X - node_min.X + 1;
799-
int idx = (p.Z - node_min.Z) * maplen +
800-
(p.X - node_min.X);
801-
if (p.Y >= mg->heightmap[idx] - 2)
802-
continue;
803-
}
804-
805769
if (vm->m_area.contains(p) == false)
806770
continue;
807771

‎src/cavegen.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class CaveV5 {
6969
CaveV5(MapgenV5 *mg, PseudoRandom *ps);
7070
void makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height);
7171
void makeTunnel(bool dirswitch);
72-
void carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine);
72+
void carveRoute(v3f vec, float f, bool randomize_xz);
7373
};
7474

7575
class CaveV6 {
@@ -158,7 +158,7 @@ class CaveV7 {
158158
CaveV7(MapgenV7 *mg, PseudoRandom *ps);
159159
void makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height);
160160
void makeTunnel(bool dirswitch);
161-
void carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine);
161+
void carveRoute(v3f vec, float f, bool randomize_xz);
162162
};
163163

164164
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.