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 dswitchint = ps->range(1, 14);
48 flooded = ps->range(1, 2) == 2;
50 part_max_length_rs = ps->range(2, 4);
51 tunnel_routepoints = ps->range(5, ps->range(15, 30));
52 min_tunnel_diameter = 5;
53 max_tunnel_diameter = ps->range(7, ps->range(8, 24));
55 large_cave_is_flat = (ps->range(0, 1) == 0);
59 void CaveV5::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height)
63 main_direction = v3f(0, 0, 0);
65 // Allowed route area size in nodes
66 ar = node_max - node_min + v3s16(1, 1, 1);
67 // Area starting point in nodes
71 //(this should be more than the maximum radius of the tunnel)
73 s16 more = MYMAX(MAP_BLOCKSIZE - max_tunnel_diameter / 2 - insure, 1);
74 ar += v3s16(1,0,1) * more * 2;
75 of -= v3s16(1,0,1) * more;
78 // Allow half a diameter + 7 over stone surface
79 route_y_max = -of.Y + max_stone_y + max_tunnel_diameter / 2 + 7;
81 // Limit maximum to area
82 route_y_max = rangelim(route_y_max, 0, ar.Y - 1);
85 if (node_min.Y < water_level && node_max.Y > water_level) {
86 min = water_level - max_tunnel_diameter/3 - of.Y;
87 route_y_max = water_level + max_tunnel_diameter/3 - of.Y;
89 route_y_min = ps->range(min, min + max_tunnel_diameter);
90 route_y_min = rangelim(route_y_min, 0, route_y_max);
92 s16 route_start_y_min = route_y_min;
93 s16 route_start_y_max = route_y_max;
95 route_start_y_min = rangelim(route_start_y_min, 0, ar.Y - 1);
96 route_start_y_max = rangelim(route_start_y_max, route_start_y_min, ar.Y - 1);
98 // Randomize starting position
100 (float)(ps->next() % ar.X) + 0.5,
101 (float)(ps->range(route_start_y_min, route_start_y_max)) + 0.5,
102 (float)(ps->next() % ar.Z) + 0.5
105 // Add generation notify begin event
106 v3s16 abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
107 GenNotifyType notifytype = GENNOTIFY_LARGECAVE_BEGIN;
108 mg->gennotify.addEvent(notifytype, abs_pos);
110 // Generate some tunnel starting from orp
111 for (u16 j = 0; j < tunnel_routepoints; j++)
112 makeTunnel(j % dswitchint == 0);
114 // Add generation notify end event
115 abs_pos = v3s16(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
116 notifytype = GENNOTIFY_LARGECAVE_END;
117 mg->gennotify.addEvent(notifytype, abs_pos);
121 void CaveV5::makeTunnel(bool dirswitch)
124 s16 min_d = min_tunnel_diameter;
125 s16 max_d = max_tunnel_diameter;
126 rs = ps->range(min_d, max_d);
127 s16 rs_part_max_length_rs = rs * part_max_length_rs;
131 rs_part_max_length_rs,
132 rs_part_max_length_rs / 2,
133 rs_part_max_length_rs
137 // Jump downward sometimes
139 (float)(ps->next() % maxlen.X) - (float)maxlen.X / 2,
140 (float)(ps->next() % maxlen.Y) - (float)maxlen.Y / 2,
141 (float)(ps->next() % maxlen.Z) - (float)maxlen.Z / 2
144 // Do not make caves that are above ground.
145 // It is only necessary to check the startpoint and endpoint.
146 v3s16 orpi(orp.X, orp.Y, orp.Z);
147 v3s16 veci(vec.X, vec.Y, vec.Z);
150 p = orpi + veci + of + rs / 2;
151 if (p.Z >= node_min.Z && p.Z <= node_max.Z &&
152 p.X >= node_min.X && p.X <= node_max.X) {
153 u32 index = (p.Z - node_min.Z) * ystride + (p.X - node_min.X);
154 s16 h = mg->heightmap[index];
157 } else if (p.Y > water_level) {
158 return; // If it's not in our heightmap, use a simple heuristic
161 p = orpi + of + rs / 2;
162 if (p.Z >= node_min.Z && p.Z <= node_max.Z &&
163 p.X >= node_min.X && p.X <= node_max.X) {
164 u32 index = (p.Z - node_min.Z) * ystride + (p.X - node_min.X);
165 s16 h = mg->heightmap[index];
168 } else if (p.Y > water_level) {
172 vec += main_direction;
177 else if (rp.X >= ar.X)
180 if (rp.Y < route_y_min)
182 else if (rp.Y >= route_y_max)
183 rp.Y = route_y_max - 1;
187 else if (rp.Z >= ar.Z)
192 float veclen = vec.getLength();
196 // Every second section is rough
197 bool randomize_xz = (ps->range(1, 2) == 1);
200 for (float f = 0; f < 1.0; f += 1.0 / veclen)
201 carveRoute(vec, f, randomize_xz);
207 void CaveV5::carveRoute(v3f vec, float f, bool randomize_xz)
209 MapNode airnode(CONTENT_AIR);
210 MapNode waternode(c_water_source);
211 MapNode lavanode(c_lava_source);
213 v3s16 startp(orp.X, orp.Y, orp.Z);
216 float nval = NoisePerlin3D(np_caveliquids, startp.X,
217 startp.Y, startp.Z, mg->seed);
218 MapNode liquidnode = (nval < 0.40 && node_max.Y < MGV5_LAVA_DEPTH) ?
219 lavanode : waternode;
221 v3f fp = orp + vec * f;
222 fp.X += 0.1 * ps->range(-10, 10);
223 fp.Z += 0.1 * ps->range(-10, 10);
224 v3s16 cp(fp.X, fp.Y, fp.Z);
229 d0 += ps->range(-1, 1);
230 d1 += ps->range(-1, 1);
233 for (s16 z0 = d0; z0 <= d1; z0++) {
234 s16 si = rs / 2 - MYMAX(0, abs(z0) - rs / 7 - 1);
235 for (s16 x0 = -si - ps->range(0,1); x0 <= si - 1 + ps->range(0,1); x0++) {
236 s16 maxabsxz = MYMAX(abs(x0), abs(z0));
238 s16 si2 = rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
240 for (s16 y0 = -si2; y0 <= si2; y0++) {
241 if (large_cave_is_flat) {
242 // Make large caves not so tall
243 if (rs > 7 && abs(y0) >= rs / 3)
247 v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
250 if (vm->m_area.contains(p) == false)
253 u32 i = vm->m_area.index(p);
254 content_t c = vm->m_data[i].getContent();
255 if (!ndef->get(c).is_ground_content)
258 int full_ymin = node_min.Y - MAP_BLOCKSIZE;
259 int full_ymax = node_max.Y + MAP_BLOCKSIZE;
261 if (flooded && full_ymin < water_level &&
262 full_ymax > water_level)
263 vm->m_data[i] = (p.Y <= water_level) ?
265 else if (flooded && full_ymax < water_level)
266 vm->m_data[i] = (p.Y < startp.Y - 4) ?
267 liquidnode : airnode;
269 vm->m_data[i] = airnode;
276 ///////////////////////////////////////// Caves V6
279 CaveV6::CaveV6(MapgenV6 *mg, PseudoRandom *ps, PseudoRandom *ps2, bool is_large_cave)
283 this->ndef = mg->ndef;
284 this->water_level = mg->water_level;
285 this->large_cave = is_large_cave;
288 this->c_water_source = mg->c_water_source;
289 this->c_lava_source = mg->c_lava_source;
291 min_tunnel_diameter = 2;
292 max_tunnel_diameter = ps->range(2, 6);
293 dswitchint = ps->range(1, 14);
297 part_max_length_rs = ps->range(2,4);
298 tunnel_routepoints = ps->range(5, ps->range(15,30));
299 min_tunnel_diameter = 5;
300 max_tunnel_diameter = ps->range(7, ps->range(8,24));
302 part_max_length_rs = ps->range(2,9);
303 tunnel_routepoints = ps->range(10, ps->range(15,30));
306 large_cave_is_flat = (ps->range(0,1) == 0);
310 void CaveV6::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height)
314 max_stone_y = max_stone_height;
315 main_direction = v3f(0, 0, 0);
317 // Allowed route area size in nodes
318 ar = node_max - node_min + v3s16(1, 1, 1);
319 // Area starting point in nodes
323 //(this should be more than the maximum radius of the tunnel)
324 const s16 max_spread_amount = MAP_BLOCKSIZE;
326 s16 more = MYMAX(max_spread_amount - max_tunnel_diameter / 2 - insure, 1);
327 ar += v3s16(1,0,1) * more * 2;
328 of -= v3s16(1,0,1) * more;
331 // Allow half a diameter + 7 over stone surface
332 route_y_max = -of.Y + max_stone_y + max_tunnel_diameter / 2 + 7;
334 // Limit maximum to area
335 route_y_max = rangelim(route_y_max, 0, ar.Y - 1);
339 if (node_min.Y < water_level && node_max.Y > water_level) {
340 min = water_level - max_tunnel_diameter/3 - of.Y;
341 route_y_max = water_level + max_tunnel_diameter/3 - of.Y;
343 route_y_min = ps->range(min, min + max_tunnel_diameter);
344 route_y_min = rangelim(route_y_min, 0, route_y_max);
347 s16 route_start_y_min = route_y_min;
348 s16 route_start_y_max = route_y_max;
350 route_start_y_min = rangelim(route_start_y_min, 0, ar.Y-1);
351 route_start_y_max = rangelim(route_start_y_max, route_start_y_min, ar.Y-1);
353 // Randomize starting position
355 (float)(ps->next() % ar.X) + 0.5,
356 (float)(ps->range(route_start_y_min, route_start_y_max)) + 0.5,
357 (float)(ps->next() % ar.Z) + 0.5
360 // Add generation notify begin event
361 v3s16 abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
362 GenNotifyType notifytype = large_cave ?
363 GENNOTIFY_LARGECAVE_BEGIN : GENNOTIFY_CAVE_BEGIN;
364 mg->gennotify.addEvent(notifytype, abs_pos);
366 // Generate some tunnel starting from orp
367 for (u16 j = 0; j < tunnel_routepoints; j++)
368 makeTunnel(j % dswitchint == 0);
370 // Add generation notify end event
371 abs_pos = v3s16(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
372 notifytype = large_cave ?
373 GENNOTIFY_LARGECAVE_END : GENNOTIFY_CAVE_END;
374 mg->gennotify.addEvent(notifytype, abs_pos);
378 void CaveV6::makeTunnel(bool dirswitch)
380 if (dirswitch && !large_cave) {
381 main_direction = v3f(
382 ((float)(ps->next() % 20) - (float)10) / 10,
383 ((float)(ps->next() % 20) - (float)10) / 30,
384 ((float)(ps->next() % 20) - (float)10) / 10
386 main_direction *= (float)ps->range(0, 10) / 10;
390 s16 min_d = min_tunnel_diameter;
391 s16 max_d = max_tunnel_diameter;
392 rs = ps->range(min_d, max_d);
393 s16 rs_part_max_length_rs = rs * part_max_length_rs;
398 rs_part_max_length_rs,
399 rs_part_max_length_rs / 2,
400 rs_part_max_length_rs
404 rs_part_max_length_rs,
405 ps->range(1, rs_part_max_length_rs),
406 rs_part_max_length_rs
411 (float)(ps->next() % maxlen.X) - (float)maxlen.X / 2,
412 (float)(ps->next() % maxlen.Y) - (float)maxlen.Y / 2,
413 (float)(ps->next() % maxlen.Z) - (float)maxlen.Z / 2
416 // Jump downward sometimes
417 if (!large_cave && ps->range(0, 12) == 0) {
419 (float)(ps->next() % maxlen.X) - (float)maxlen.X / 2,
420 (float)(ps->next() % (maxlen.Y * 2)) - (float)maxlen.Y,
421 (float)(ps->next() % maxlen.Z) - (float)maxlen.Z / 2
425 // Do not make caves that are entirely above ground, to fix
426 // shadow bugs caused by overgenerated large caves.
427 // It is only necessary to check the startpoint and endpoint.
428 v3s16 orpi(orp.X, orp.Y, orp.Z);
429 v3s16 veci(vec.X, vec.Y, vec.Z);
433 v3s16 p1 = orpi + veci + of + rs / 2;
434 if (p1.Z >= node_min.Z && p1.Z <= node_max.Z &&
435 p1.X >= node_min.X && p1.X <= node_max.X) {
436 u32 index1 = (p1.Z - node_min.Z) * mg->ystride +
438 h1 = mg->heightmap[index1];
440 h1 = water_level; // If not in heightmap
443 v3s16 p2 = orpi + of + rs / 2;
444 if (p2.Z >= node_min.Z && p2.Z <= node_max.Z &&
445 p2.X >= node_min.X && p2.X <= node_max.X) {
446 u32 index2 = (p2.Z - node_min.Z) * mg->ystride +
448 h2 = mg->heightmap[index2];
453 // If startpoint and endpoint are above ground,
454 // disable placing of nodes in carveRoute while
455 // still running all pseudorandom calls to ensure
456 // caves consistent with existing worlds.
457 bool tunnel_above_ground = p1.Y > h1 && p2.Y > h2;
459 vec += main_direction;
464 else if (rp.X >= ar.X)
467 if (rp.Y < route_y_min)
469 else if (rp.Y >= route_y_max)
470 rp.Y = route_y_max - 1;
474 else if (rp.Z >= ar.Z)
479 float veclen = vec.getLength();
480 // As odd as it sounds, veclen is *exactly* 0.0 sometimes, causing a FPE
484 // Every second section is rough
485 bool randomize_xz = (ps2->range(1, 2) == 1);
488 for (float f = 0; f < 1.0; f += 1.0 / veclen)
489 carveRoute(vec, f, randomize_xz, tunnel_above_ground);
495 void CaveV6::carveRoute(v3f vec, float f, bool randomize_xz, bool tunnel_above_ground)
497 MapNode airnode(CONTENT_AIR);
498 MapNode waternode(c_water_source);
499 MapNode lavanode(c_lava_source);
501 v3s16 startp(orp.X, orp.Y, orp.Z);
504 v3f fp = orp + vec * f;
505 fp.X += 0.1 * ps->range(-10, 10);
506 fp.Z += 0.1 * ps->range(-10, 10);
507 v3s16 cp(fp.X, fp.Y, fp.Z);
512 d0 += ps->range(-1, 1);
513 d1 += ps->range(-1, 1);
516 for (s16 z0 = d0; z0 <= d1; z0++) {
517 s16 si = rs / 2 - MYMAX(0, abs(z0) - rs / 7 - 1);
518 for (s16 x0 = -si - ps->range(0,1); x0 <= si - 1 + ps->range(0,1); x0++) {
519 if (tunnel_above_ground)
522 s16 maxabsxz = MYMAX(abs(x0), abs(z0));
523 s16 si2 = rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
524 for (s16 y0 = -si2; y0 <= si2; y0++) {
525 if (large_cave_is_flat) {
526 // Make large caves not so tall
527 if (rs > 7 && abs(y0) >= rs / 3)
531 v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
534 if (vm->m_area.contains(p) == false)
537 u32 i = vm->m_area.index(p);
538 content_t c = vm->m_data[i].getContent();
539 if (!ndef->get(c).is_ground_content)
543 int full_ymin = node_min.Y - MAP_BLOCKSIZE;
544 int full_ymax = node_max.Y + MAP_BLOCKSIZE;
546 if (flooded && full_ymin < water_level &&
547 full_ymax > water_level) {
548 vm->m_data[i] = (p.Y <= water_level) ?
550 } else if (flooded && full_ymax < water_level) {
551 vm->m_data[i] = (p.Y < startp.Y - 2) ?
554 vm->m_data[i] = airnode;
557 if (c == CONTENT_IGNORE || c == CONTENT_AIR)
560 vm->m_data[i] = airnode;
561 vm->m_flags[i] |= VMANIP_FLAG_CAVE;
569 ///////////////////////////////////////// Caves V7
572 CaveV7::CaveV7(MapgenV7 *mg, PseudoRandom *ps)
576 this->ndef = mg->ndef;
577 this->water_level = mg->water_level;
579 this->c_water_source = mg->c_water_source;
580 this->c_lava_source = mg->c_lava_source;
581 this->c_ice = mg->c_ice;
582 this->np_caveliquids = &nparams_caveliquids;
584 dswitchint = ps->range(1, 14);
585 flooded = ps->range(1, 2) == 2;
587 part_max_length_rs = ps->range(2, 4);
588 tunnel_routepoints = ps->range(5, ps->range(15, 30));
589 min_tunnel_diameter = 5;
590 max_tunnel_diameter = ps->range(7, ps->range(8, 24));
592 large_cave_is_flat = (ps->range(0, 1) == 0);
596 void CaveV7::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height)
600 max_stone_y = max_stone_height;
601 main_direction = v3f(0, 0, 0);
603 // Allowed route area size in nodes
604 ar = node_max - node_min + v3s16(1, 1, 1);
605 // Area starting point in nodes
609 //(this should be more than the maximum radius of the tunnel)
611 s16 more = MYMAX(MAP_BLOCKSIZE - max_tunnel_diameter / 2 - insure, 1);
612 ar += v3s16(1,0,1) * more * 2;
613 of -= v3s16(1,0,1) * more;
616 // Allow half a diameter + 7 over stone surface
617 route_y_max = -of.Y + max_stone_y + max_tunnel_diameter / 2 + 7;
619 // Limit maximum to area
620 route_y_max = rangelim(route_y_max, 0, ar.Y - 1);
623 if (node_min.Y < water_level && node_max.Y > water_level) {
624 min = water_level - max_tunnel_diameter/3 - of.Y;
625 route_y_max = water_level + max_tunnel_diameter/3 - of.Y;
627 route_y_min = ps->range(min, min + max_tunnel_diameter);
628 route_y_min = rangelim(route_y_min, 0, route_y_max);
630 s16 route_start_y_min = route_y_min;
631 s16 route_start_y_max = route_y_max;
633 route_start_y_min = rangelim(route_start_y_min, 0, ar.Y - 1);
634 route_start_y_max = rangelim(route_start_y_max, route_start_y_min, ar.Y - 1);
636 // Randomize starting position
638 (float)(ps->next() % ar.X) + 0.5,
639 (float)(ps->range(route_start_y_min, route_start_y_max)) + 0.5,
640 (float)(ps->next() % ar.Z) + 0.5
643 // Add generation notify begin event
644 v3s16 abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
645 GenNotifyType notifytype = GENNOTIFY_LARGECAVE_BEGIN;
646 mg->gennotify.addEvent(notifytype, abs_pos);
648 // Generate some tunnel starting from orp
649 for (u16 j = 0; j < tunnel_routepoints; j++)
650 makeTunnel(j % dswitchint == 0);
652 // Add generation notify end event
653 abs_pos = v3s16(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
654 notifytype = GENNOTIFY_LARGECAVE_END;
655 mg->gennotify.addEvent(notifytype, abs_pos);
659 void CaveV7::makeTunnel(bool dirswitch)
662 s16 min_d = min_tunnel_diameter;
663 s16 max_d = max_tunnel_diameter;
664 rs = ps->range(min_d, max_d);
665 s16 rs_part_max_length_rs = rs * part_max_length_rs;
669 rs_part_max_length_rs,
670 rs_part_max_length_rs / 2,
671 rs_part_max_length_rs
675 // Jump downward sometimes
677 (float)(ps->next() % maxlen.X) - (float)maxlen.X / 2,
678 (float)(ps->next() % maxlen.Y) - (float)maxlen.Y / 2,
679 (float)(ps->next() % maxlen.Z) - (float)maxlen.Z / 2
682 // Do not make caves that are above ground.
683 // It is only necessary to check the startpoint and endpoint.
684 v3s16 orpi(orp.X, orp.Y, orp.Z);
685 v3s16 veci(vec.X, vec.Y, vec.Z);
688 p = orpi + veci + of + rs / 2;
689 if (p.Z >= node_min.Z && p.Z <= node_max.Z &&
690 p.X >= node_min.X && p.X <= node_max.X) {
691 u32 index = (p.Z - node_min.Z) * mg->ystride + (p.X - node_min.X);
692 s16 h = mg->ridge_heightmap[index];
695 } else if (p.Y > water_level) {
696 return; // If it's not in our heightmap, use a simple heuristic
699 p = orpi + of + rs / 2;
700 if (p.Z >= node_min.Z && p.Z <= node_max.Z &&
701 p.X >= node_min.X && p.X <= node_max.X) {
702 u32 index = (p.Z - node_min.Z) * mg->ystride + (p.X - node_min.X);
703 s16 h = mg->ridge_heightmap[index];
706 } else if (p.Y > water_level) {
710 vec += main_direction;
715 else if (rp.X >= ar.X)
718 if (rp.Y < route_y_min)
720 else if (rp.Y >= route_y_max)
721 rp.Y = route_y_max - 1;
725 else if (rp.Z >= ar.Z)
730 float veclen = vec.getLength();
734 // Every second section is rough
735 bool randomize_xz = (ps->range(1, 2) == 1);
738 for (float f = 0; f < 1.0; f += 1.0 / veclen)
739 carveRoute(vec, f, randomize_xz);
745 void CaveV7::carveRoute(v3f vec, float f, bool randomize_xz)
747 MapNode airnode(CONTENT_AIR);
748 MapNode waternode(c_water_source);
749 MapNode lavanode(c_lava_source);
751 v3s16 startp(orp.X, orp.Y, orp.Z);
754 float nval = NoisePerlin3D(np_caveliquids, startp.X,
755 startp.Y, startp.Z, mg->seed);
756 MapNode liquidnode = (nval < 0.40 && node_max.Y < MGV7_LAVA_DEPTH) ?
757 lavanode : waternode;
759 v3f fp = orp + vec * f;
760 fp.X += 0.1 * ps->range(-10, 10);
761 fp.Z += 0.1 * ps->range(-10, 10);
762 v3s16 cp(fp.X, fp.Y, fp.Z);
767 d0 += ps->range(-1, 1);
768 d1 += ps->range(-1, 1);
771 for (s16 z0 = d0; z0 <= d1; z0++) {
772 s16 si = rs / 2 - MYMAX(0, abs(z0) - rs / 7 - 1);
773 for (s16 x0 = -si - ps->range(0,1); x0 <= si - 1 + ps->range(0,1); x0++) {
774 s16 maxabsxz = MYMAX(abs(x0), abs(z0));
776 s16 si2 = rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
778 for (s16 y0 = -si2; y0 <= si2; y0++) {
779 if (large_cave_is_flat) {
780 // Make large caves not so tall
781 if (rs > 7 && abs(y0) >= rs / 3)
785 v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
788 if (vm->m_area.contains(p) == false)
791 u32 i = vm->m_area.index(p);
792 content_t c = vm->m_data[i].getContent();
793 if (!ndef->get(c).is_ground_content)
796 int full_ymin = node_min.Y - MAP_BLOCKSIZE;
797 int full_ymax = node_max.Y + MAP_BLOCKSIZE;
799 if (flooded && full_ymin < water_level &&
800 full_ymax > water_level)
801 vm->m_data[i] = (p.Y <= water_level) ?
803 else if (flooded && full_ymax < water_level)
804 vm->m_data[i] = (p.Y < startp.Y - 4) ?
805 liquidnode : airnode;
807 vm->m_data[i] = airnode;