3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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 #include "util/numeric.h"
23 #include "mapgen_v5.h"
24 #include "mapgen_v6.h"
25 #include "mapgen_v7.h"
28 NoiseParams nparams_caveliquids(0, 1, v3f(150.0, 150.0, 150.0), 776, 3, 0.6, 2.0);
31 ///////////////////////////////////////// Caves V5
34 CaveV5::CaveV5(Mapgen *mg, PseudoRandom *ps)
38 this->ndef = mg->ndef;
39 this->water_level = mg->water_level;
41 c_water_source = ndef->getId("mapgen_water_source");
42 c_lava_source = ndef->getId("mapgen_lava_source");
43 c_ice = ndef->getId("mapgen_ice");
44 this->np_caveliquids = &nparams_caveliquids;
45 this->ystride = mg->csize.X;
47 if (c_ice == CONTENT_IGNORE)
50 dswitchint = ps->range(1, 14);
51 flooded = ps->range(1, 2) == 2;
53 part_max_length_rs = ps->range(2, 4);
54 tunnel_routepoints = ps->range(5, ps->range(15, 30));
55 min_tunnel_diameter = 5;
56 max_tunnel_diameter = ps->range(7, ps->range(8, 24));
58 large_cave_is_flat = (ps->range(0, 1) == 0);
62 void CaveV5::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height)
66 main_direction = v3f(0, 0, 0);
68 // Allowed route area size in nodes
69 ar = node_max - node_min + v3s16(1, 1, 1);
70 // Area starting point in nodes
74 //(this should be more than the maximum radius of the tunnel)
76 s16 more = MYMAX(MAP_BLOCKSIZE - max_tunnel_diameter / 2 - insure, 1);
77 ar += v3s16(1,0,1) * more * 2;
78 of -= v3s16(1,0,1) * more;
81 // Allow half a diameter + 7 over stone surface
82 route_y_max = -of.Y + max_stone_y + max_tunnel_diameter / 2 + 7;
84 // Limit maximum to area
85 route_y_max = rangelim(route_y_max, 0, ar.Y - 1);
88 if (node_min.Y < water_level && node_max.Y > water_level) {
89 min = water_level - max_tunnel_diameter/3 - of.Y;
90 route_y_max = water_level + max_tunnel_diameter/3 - of.Y;
92 route_y_min = ps->range(min, min + max_tunnel_diameter);
93 route_y_min = rangelim(route_y_min, 0, route_y_max);
95 s16 route_start_y_min = route_y_min;
96 s16 route_start_y_max = route_y_max;
98 route_start_y_min = rangelim(route_start_y_min, 0, ar.Y - 1);
99 route_start_y_max = rangelim(route_start_y_max, route_start_y_min, ar.Y - 1);
101 // Randomize starting position
103 (float)(ps->next() % ar.X) + 0.5,
104 (float)(ps->range(route_start_y_min, route_start_y_max)) + 0.5,
105 (float)(ps->next() % ar.Z) + 0.5
108 // Add generation notify begin event
109 v3s16 abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
110 GenNotifyType notifytype = GENNOTIFY_LARGECAVE_BEGIN;
111 mg->gennotify.addEvent(notifytype, abs_pos);
113 // Generate some tunnel starting from orp
114 for (u16 j = 0; j < tunnel_routepoints; j++)
115 makeTunnel(j % dswitchint == 0);
117 // Add generation notify end event
118 abs_pos = v3s16(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
119 notifytype = GENNOTIFY_LARGECAVE_END;
120 mg->gennotify.addEvent(notifytype, abs_pos);
124 void CaveV5::makeTunnel(bool dirswitch)
127 s16 min_d = min_tunnel_diameter;
128 s16 max_d = max_tunnel_diameter;
129 rs = ps->range(min_d, max_d);
130 s16 rs_part_max_length_rs = rs * part_max_length_rs;
134 rs_part_max_length_rs,
135 rs_part_max_length_rs / 2,
136 rs_part_max_length_rs
140 // Jump downward sometimes
142 (float)(ps->next() % maxlen.X) - (float)maxlen.X / 2,
143 (float)(ps->next() % maxlen.Y) - (float)maxlen.Y / 2,
144 (float)(ps->next() % maxlen.Z) - (float)maxlen.Z / 2
147 // Do not make caves that are above ground.
148 // It is only necessary to check the startpoint and endpoint.
149 v3s16 orpi(orp.X, orp.Y, orp.Z);
150 v3s16 veci(vec.X, vec.Y, vec.Z);
153 p = orpi + veci + of + rs / 2;
154 if (p.Z >= node_min.Z && p.Z <= node_max.Z &&
155 p.X >= node_min.X && p.X <= node_max.X) {
156 u32 index = (p.Z - node_min.Z) * ystride + (p.X - node_min.X);
157 s16 h = mg->heightmap[index];
160 } else if (p.Y > water_level) {
161 return; // If it's not in our heightmap, use a simple heuristic
164 p = orpi + of + rs / 2;
165 if (p.Z >= node_min.Z && p.Z <= node_max.Z &&
166 p.X >= node_min.X && p.X <= node_max.X) {
167 u32 index = (p.Z - node_min.Z) * ystride + (p.X - node_min.X);
168 s16 h = mg->heightmap[index];
171 } else if (p.Y > water_level) {
175 vec += main_direction;
180 else if (rp.X >= ar.X)
183 if (rp.Y < route_y_min)
185 else if (rp.Y >= route_y_max)
186 rp.Y = route_y_max - 1;
190 else if (rp.Z >= ar.Z)
195 float veclen = vec.getLength();
199 // Every second section is rough
200 bool randomize_xz = (ps->range(1, 2) == 1);
203 for (float f = 0; f < 1.0; f += 1.0 / veclen)
204 carveRoute(vec, f, randomize_xz);
210 void CaveV5::carveRoute(v3f vec, float f, bool randomize_xz)
212 MapNode airnode(CONTENT_AIR);
213 MapNode waternode(c_water_source);
214 MapNode lavanode(c_lava_source);
216 v3s16 startp(orp.X, orp.Y, orp.Z);
219 float nval = NoisePerlin3D(np_caveliquids, startp.X,
220 startp.Y, startp.Z, mg->seed);
221 MapNode liquidnode = (nval < 0.40 && node_max.Y < MGV5_LAVA_DEPTH) ?
222 lavanode : waternode;
224 v3f fp = orp + vec * f;
225 fp.X += 0.1 * ps->range(-10, 10);
226 fp.Z += 0.1 * ps->range(-10, 10);
227 v3s16 cp(fp.X, fp.Y, fp.Z);
232 d0 += ps->range(-1, 1);
233 d1 += ps->range(-1, 1);
236 for (s16 z0 = d0; z0 <= d1; z0++) {
237 s16 si = rs / 2 - MYMAX(0, abs(z0) - rs / 7 - 1);
238 for (s16 x0 = -si - ps->range(0,1); x0 <= si - 1 + ps->range(0,1); x0++) {
239 s16 maxabsxz = MYMAX(abs(x0), abs(z0));
241 s16 si2 = rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
243 for (s16 y0 = -si2; y0 <= si2; y0++) {
244 if (large_cave_is_flat) {
245 // Make large caves not so tall
246 if (rs > 7 && abs(y0) >= rs / 3)
250 v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
253 if (vm->m_area.contains(p) == false)
256 u32 i = vm->m_area.index(p);
257 content_t c = vm->m_data[i].getContent();
258 if (!ndef->get(c).is_ground_content)
261 int full_ymin = node_min.Y - MAP_BLOCKSIZE;
262 int full_ymax = node_max.Y + MAP_BLOCKSIZE;
264 if (flooded && full_ymin < water_level &&
265 full_ymax > water_level)
266 vm->m_data[i] = (p.Y <= water_level) ?
268 else if (flooded && full_ymax < water_level)
269 vm->m_data[i] = (p.Y < startp.Y - 4) ?
270 liquidnode : airnode;
272 vm->m_data[i] = airnode;
279 ///////////////////////////////////////// Caves V6
282 CaveV6::CaveV6(MapgenV6 *mg, PseudoRandom *ps, PseudoRandom *ps2, bool is_large_cave)
286 this->ndef = mg->ndef;
287 this->water_level = mg->water_level;
288 this->large_cave = is_large_cave;
291 this->c_water_source = mg->c_water_source;
292 this->c_lava_source = mg->c_lava_source;
294 min_tunnel_diameter = 2;
295 max_tunnel_diameter = ps->range(2, 6);
296 dswitchint = ps->range(1, 14);
300 part_max_length_rs = ps->range(2,4);
301 tunnel_routepoints = ps->range(5, ps->range(15,30));
302 min_tunnel_diameter = 5;
303 max_tunnel_diameter = ps->range(7, ps->range(8,24));
305 part_max_length_rs = ps->range(2,9);
306 tunnel_routepoints = ps->range(10, ps->range(15,30));
309 large_cave_is_flat = (ps->range(0,1) == 0);
313 void CaveV6::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height)
317 max_stone_y = max_stone_height;
318 main_direction = v3f(0, 0, 0);
320 // Allowed route area size in nodes
321 ar = node_max - node_min + v3s16(1, 1, 1);
322 // Area starting point in nodes
326 //(this should be more than the maximum radius of the tunnel)
327 const s16 max_spread_amount = MAP_BLOCKSIZE;
329 s16 more = MYMAX(max_spread_amount - max_tunnel_diameter / 2 - insure, 1);
330 ar += v3s16(1,0,1) * more * 2;
331 of -= v3s16(1,0,1) * more;
334 // Allow half a diameter + 7 over stone surface
335 route_y_max = -of.Y + max_stone_y + max_tunnel_diameter / 2 + 7;
337 // Limit maximum to area
338 route_y_max = rangelim(route_y_max, 0, ar.Y - 1);
342 if (node_min.Y < water_level && node_max.Y > water_level) {
343 min = water_level - max_tunnel_diameter/3 - of.Y;
344 route_y_max = water_level + max_tunnel_diameter/3 - of.Y;
346 route_y_min = ps->range(min, min + max_tunnel_diameter);
347 route_y_min = rangelim(route_y_min, 0, route_y_max);
350 s16 route_start_y_min = route_y_min;
351 s16 route_start_y_max = route_y_max;
353 route_start_y_min = rangelim(route_start_y_min, 0, ar.Y-1);
354 route_start_y_max = rangelim(route_start_y_max, route_start_y_min, ar.Y-1);
356 // Randomize starting position
358 (float)(ps->next() % ar.X) + 0.5,
359 (float)(ps->range(route_start_y_min, route_start_y_max)) + 0.5,
360 (float)(ps->next() % ar.Z) + 0.5
363 // Add generation notify begin event
364 v3s16 abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
365 GenNotifyType notifytype = large_cave ?
366 GENNOTIFY_LARGECAVE_BEGIN : GENNOTIFY_CAVE_BEGIN;
367 mg->gennotify.addEvent(notifytype, abs_pos);
369 // Generate some tunnel starting from orp
370 for (u16 j = 0; j < tunnel_routepoints; j++)
371 makeTunnel(j % dswitchint == 0);
373 // Add generation notify end event
374 abs_pos = v3s16(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
375 notifytype = large_cave ?
376 GENNOTIFY_LARGECAVE_END : GENNOTIFY_CAVE_END;
377 mg->gennotify.addEvent(notifytype, abs_pos);
381 void CaveV6::makeTunnel(bool dirswitch)
383 if (dirswitch && !large_cave) {
384 main_direction = v3f(
385 ((float)(ps->next() % 20) - (float)10) / 10,
386 ((float)(ps->next() % 20) - (float)10) / 30,
387 ((float)(ps->next() % 20) - (float)10) / 10
389 main_direction *= (float)ps->range(0, 10) / 10;
393 s16 min_d = min_tunnel_diameter;
394 s16 max_d = max_tunnel_diameter;
395 rs = ps->range(min_d, max_d);
396 s16 rs_part_max_length_rs = rs * part_max_length_rs;
401 rs_part_max_length_rs,
402 rs_part_max_length_rs / 2,
403 rs_part_max_length_rs
407 rs_part_max_length_rs,
408 ps->range(1, rs_part_max_length_rs),
409 rs_part_max_length_rs
414 (float)(ps->next() % maxlen.X) - (float)maxlen.X / 2,
415 (float)(ps->next() % maxlen.Y) - (float)maxlen.Y / 2,
416 (float)(ps->next() % maxlen.Z) - (float)maxlen.Z / 2
419 // Jump downward sometimes
420 if (!large_cave && ps->range(0, 12) == 0) {
422 (float)(ps->next() % maxlen.X) - (float)maxlen.X / 2,
423 (float)(ps->next() % (maxlen.Y * 2)) - (float)maxlen.Y,
424 (float)(ps->next() % maxlen.Z) - (float)maxlen.Z / 2
428 // Do not make caves that are entirely above ground, to fix
429 // shadow bugs caused by overgenerated large caves.
430 // It is only necessary to check the startpoint and endpoint.
431 v3s16 orpi(orp.X, orp.Y, orp.Z);
432 v3s16 veci(vec.X, vec.Y, vec.Z);
436 v3s16 p1 = orpi + veci + of + rs / 2;
437 if (p1.Z >= node_min.Z && p1.Z <= node_max.Z &&
438 p1.X >= node_min.X && p1.X <= node_max.X) {
439 u32 index1 = (p1.Z - node_min.Z) * mg->ystride +
441 h1 = mg->heightmap[index1];
443 h1 = water_level; // If not in heightmap
446 v3s16 p2 = orpi + of + rs / 2;
447 if (p2.Z >= node_min.Z && p2.Z <= node_max.Z &&
448 p2.X >= node_min.X && p2.X <= node_max.X) {
449 u32 index2 = (p2.Z - node_min.Z) * mg->ystride +
451 h2 = mg->heightmap[index2];
456 // If startpoint and endpoint are above ground,
457 // disable placing of nodes in carveRoute while
458 // still running all pseudorandom calls to ensure
459 // caves consistent with existing worlds.
460 bool tunnel_above_ground = p1.Y > h1 && p2.Y > h2;
462 vec += main_direction;
467 else if (rp.X >= ar.X)
470 if (rp.Y < route_y_min)
472 else if (rp.Y >= route_y_max)
473 rp.Y = route_y_max - 1;
477 else if (rp.Z >= ar.Z)
482 float veclen = vec.getLength();
483 // As odd as it sounds, veclen is *exactly* 0.0 sometimes, causing a FPE
487 // Every second section is rough
488 bool randomize_xz = (ps2->range(1, 2) == 1);
491 for (float f = 0; f < 1.0; f += 1.0 / veclen)
492 carveRoute(vec, f, randomize_xz, tunnel_above_ground);
498 void CaveV6::carveRoute(v3f vec, float f, bool randomize_xz, bool tunnel_above_ground)
500 MapNode airnode(CONTENT_AIR);
501 MapNode waternode(c_water_source);
502 MapNode lavanode(c_lava_source);
504 v3s16 startp(orp.X, orp.Y, orp.Z);
507 v3f fp = orp + vec * f;
508 fp.X += 0.1 * ps->range(-10, 10);
509 fp.Z += 0.1 * ps->range(-10, 10);
510 v3s16 cp(fp.X, fp.Y, fp.Z);
515 d0 += ps->range(-1, 1);
516 d1 += ps->range(-1, 1);
519 for (s16 z0 = d0; z0 <= d1; z0++) {
520 s16 si = rs / 2 - MYMAX(0, abs(z0) - rs / 7 - 1);
521 for (s16 x0 = -si - ps->range(0,1); x0 <= si - 1 + ps->range(0,1); x0++) {
522 if (tunnel_above_ground)
525 s16 maxabsxz = MYMAX(abs(x0), abs(z0));
526 s16 si2 = rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
527 for (s16 y0 = -si2; y0 <= si2; y0++) {
528 if (large_cave_is_flat) {
529 // Make large caves not so tall
530 if (rs > 7 && abs(y0) >= rs / 3)
534 v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
537 if (vm->m_area.contains(p) == false)
540 u32 i = vm->m_area.index(p);
541 content_t c = vm->m_data[i].getContent();
542 if (!ndef->get(c).is_ground_content)
546 int full_ymin = node_min.Y - MAP_BLOCKSIZE;
547 int full_ymax = node_max.Y + MAP_BLOCKSIZE;
549 if (flooded && full_ymin < water_level &&
550 full_ymax > water_level) {
551 vm->m_data[i] = (p.Y <= water_level) ?
553 } else if (flooded && full_ymax < water_level) {
554 vm->m_data[i] = (p.Y < startp.Y - 2) ?
557 vm->m_data[i] = airnode;
560 if (c == CONTENT_IGNORE || c == CONTENT_AIR)
563 vm->m_data[i] = airnode;
564 vm->m_flags[i] |= VMANIP_FLAG_CAVE;
572 ///////////////////////////////////////// Caves V7
575 CaveV7::CaveV7(MapgenV7 *mg, PseudoRandom *ps)
579 this->ndef = mg->ndef;
580 this->water_level = mg->water_level;
582 this->c_water_source = mg->c_water_source;
583 this->c_lava_source = mg->c_lava_source;
584 this->c_ice = mg->c_ice;
585 this->np_caveliquids = &nparams_caveliquids;
587 dswitchint = ps->range(1, 14);
588 flooded = ps->range(1, 2) == 2;
590 part_max_length_rs = ps->range(2, 4);
591 tunnel_routepoints = ps->range(5, ps->range(15, 30));
592 min_tunnel_diameter = 5;
593 max_tunnel_diameter = ps->range(7, ps->range(8, 24));
595 large_cave_is_flat = (ps->range(0, 1) == 0);
599 void CaveV7::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height)
603 max_stone_y = max_stone_height;
604 main_direction = v3f(0, 0, 0);
606 // Allowed route area size in nodes
607 ar = node_max - node_min + v3s16(1, 1, 1);
608 // Area starting point in nodes
612 //(this should be more than the maximum radius of the tunnel)
614 s16 more = MYMAX(MAP_BLOCKSIZE - max_tunnel_diameter / 2 - insure, 1);
615 ar += v3s16(1,0,1) * more * 2;
616 of -= v3s16(1,0,1) * more;
619 // Allow half a diameter + 7 over stone surface
620 route_y_max = -of.Y + max_stone_y + max_tunnel_diameter / 2 + 7;
622 // Limit maximum to area
623 route_y_max = rangelim(route_y_max, 0, ar.Y - 1);
626 if (node_min.Y < water_level && node_max.Y > water_level) {
627 min = water_level - max_tunnel_diameter/3 - of.Y;
628 route_y_max = water_level + max_tunnel_diameter/3 - of.Y;
630 route_y_min = ps->range(min, min + max_tunnel_diameter);
631 route_y_min = rangelim(route_y_min, 0, route_y_max);
633 s16 route_start_y_min = route_y_min;
634 s16 route_start_y_max = route_y_max;
636 route_start_y_min = rangelim(route_start_y_min, 0, ar.Y - 1);
637 route_start_y_max = rangelim(route_start_y_max, route_start_y_min, ar.Y - 1);
639 // Randomize starting position
641 (float)(ps->next() % ar.X) + 0.5,
642 (float)(ps->range(route_start_y_min, route_start_y_max)) + 0.5,
643 (float)(ps->next() % ar.Z) + 0.5
646 // Add generation notify begin event
647 v3s16 abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
648 GenNotifyType notifytype = GENNOTIFY_LARGECAVE_BEGIN;
649 mg->gennotify.addEvent(notifytype, abs_pos);
651 // Generate some tunnel starting from orp
652 for (u16 j = 0; j < tunnel_routepoints; j++)
653 makeTunnel(j % dswitchint == 0);
655 // Add generation notify end event
656 abs_pos = v3s16(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
657 notifytype = GENNOTIFY_LARGECAVE_END;
658 mg->gennotify.addEvent(notifytype, abs_pos);
662 void CaveV7::makeTunnel(bool dirswitch)
665 s16 min_d = min_tunnel_diameter;
666 s16 max_d = max_tunnel_diameter;
667 rs = ps->range(min_d, max_d);
668 s16 rs_part_max_length_rs = rs * part_max_length_rs;
672 rs_part_max_length_rs,
673 rs_part_max_length_rs / 2,
674 rs_part_max_length_rs
678 // Jump downward sometimes
680 (float)(ps->next() % maxlen.X) - (float)maxlen.X / 2,
681 (float)(ps->next() % maxlen.Y) - (float)maxlen.Y / 2,
682 (float)(ps->next() % maxlen.Z) - (float)maxlen.Z / 2
685 // Do not make caves that are above ground.
686 // It is only necessary to check the startpoint and endpoint.
687 v3s16 orpi(orp.X, orp.Y, orp.Z);
688 v3s16 veci(vec.X, vec.Y, vec.Z);
691 p = orpi + veci + of + rs / 2;
692 if (p.Z >= node_min.Z && p.Z <= node_max.Z &&
693 p.X >= node_min.X && p.X <= node_max.X) {
694 u32 index = (p.Z - node_min.Z) * mg->ystride + (p.X - node_min.X);
695 s16 h = mg->ridge_heightmap[index];
698 } else if (p.Y > water_level) {
699 return; // If it's not in our heightmap, use a simple heuristic
702 p = orpi + of + rs / 2;
703 if (p.Z >= node_min.Z && p.Z <= node_max.Z &&
704 p.X >= node_min.X && p.X <= node_max.X) {
705 u32 index = (p.Z - node_min.Z) * mg->ystride + (p.X - node_min.X);
706 s16 h = mg->ridge_heightmap[index];
709 } else if (p.Y > water_level) {
713 vec += main_direction;
718 else if (rp.X >= ar.X)
721 if (rp.Y < route_y_min)
723 else if (rp.Y >= route_y_max)
724 rp.Y = route_y_max - 1;
728 else if (rp.Z >= ar.Z)
733 float veclen = vec.getLength();
737 // Every second section is rough
738 bool randomize_xz = (ps->range(1, 2) == 1);
741 for (float f = 0; f < 1.0; f += 1.0 / veclen)
742 carveRoute(vec, f, randomize_xz);
748 void CaveV7::carveRoute(v3f vec, float f, bool randomize_xz)
750 MapNode airnode(CONTENT_AIR);
751 MapNode waternode(c_water_source);
752 MapNode lavanode(c_lava_source);
754 v3s16 startp(orp.X, orp.Y, orp.Z);
757 float nval = NoisePerlin3D(np_caveliquids, startp.X,
758 startp.Y, startp.Z, mg->seed);
759 MapNode liquidnode = (nval < 0.40 && node_max.Y < MGV7_LAVA_DEPTH) ?
760 lavanode : waternode;
762 v3f fp = orp + vec * f;
763 fp.X += 0.1 * ps->range(-10, 10);
764 fp.Z += 0.1 * ps->range(-10, 10);
765 v3s16 cp(fp.X, fp.Y, fp.Z);
770 d0 += ps->range(-1, 1);
771 d1 += ps->range(-1, 1);
774 for (s16 z0 = d0; z0 <= d1; z0++) {
775 s16 si = rs / 2 - MYMAX(0, abs(z0) - rs / 7 - 1);
776 for (s16 x0 = -si - ps->range(0,1); x0 <= si - 1 + ps->range(0,1); x0++) {
777 s16 maxabsxz = MYMAX(abs(x0), abs(z0));
779 s16 si2 = rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
781 for (s16 y0 = -si2; y0 <= si2; y0++) {
782 if (large_cave_is_flat) {
783 // Make large caves not so tall
784 if (rs > 7 && abs(y0) >= rs / 3)
788 v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
791 if (vm->m_area.contains(p) == false)
794 u32 i = vm->m_area.index(p);
795 content_t c = vm->m_data[i].getContent();
796 if (!ndef->get(c).is_ground_content)
799 int full_ymin = node_min.Y - MAP_BLOCKSIZE;
800 int full_ymax = node_max.Y + MAP_BLOCKSIZE;
802 if (flooded && full_ymin < water_level &&
803 full_ymax > water_level)
804 vm->m_data[i] = (p.Y <= water_level) ?
806 else if (flooded && full_ymax < water_level)
807 vm->m_data[i] = (p.Y < startp.Y - 4) ?
808 liquidnode : airnode;
810 vm->m_data[i] = airnode;