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.
27 #include "content_sao.h"
29 #include "voxelalgorithms.h"
31 #include "settings.h" // For g_settings
32 #include "main.h" // For g_profiler
34 #include "dungeongen.h"
38 #include "mapgen_v7.h"
41 FlagDesc flagdesc_mapgen_v7[] = {
42 {"mountains", MGV7_MOUNTAINS},
43 {"ridges", MGV7_RIDGES},
47 ///////////////////////////////////////////////////////////////////////////////
50 MapgenV7::MapgenV7(int mapgenid, MapgenParams *params, EmergeManager *emerge) {
51 this->generating = false;
53 this->emerge = emerge;
54 this->bmgr = emerge->biomedef;
56 this->seed = (int)params->seed;
57 this->water_level = params->water_level;
58 this->flags = params->flags;
59 this->gennotify = emerge->gennotify;
61 this->csize = v3s16(1, 1, 1) * params->chunksize * MAP_BLOCKSIZE;
63 //// amount of elements to skip for the next index
64 //// for noise/height/biome maps (not vmanip)
65 this->ystride = csize.X;
66 this->zstride = csize.X * csize.Y;
68 this->biomemap = new u8[csize.X * csize.Z];
69 this->heightmap = new s16[csize.X * csize.Z];
70 this->ridge_heightmap = new s16[csize.X * csize.Z];
72 MapgenV7Params *sp = (MapgenV7Params *)params->sparams;
75 noise_terrain_base = new Noise(&sp->np_terrain_base, seed, csize.X, csize.Z);
76 noise_terrain_alt = new Noise(&sp->np_terrain_alt, seed, csize.X, csize.Z);
77 noise_terrain_persist = new Noise(&sp->np_terrain_persist, seed, csize.X, csize.Z);
78 noise_height_select = new Noise(&sp->np_height_select, seed, csize.X, csize.Z);
79 noise_filler_depth = new Noise(&sp->np_filler_depth, seed, csize.X, csize.Z);
80 noise_mount_height = new Noise(&sp->np_mount_height, seed, csize.X, csize.Z);
81 noise_ridge_uwater = new Noise(&sp->np_ridge_uwater, seed, csize.X, csize.Z);
84 noise_mountain = new Noise(&sp->np_mountain, seed, csize.X, csize.Y, csize.Z);
85 noise_ridge = new Noise(&sp->np_ridge, seed, csize.X, csize.Y, csize.Z);
88 noise_heat = new Noise(bmgr->np_heat, seed, csize.X, csize.Z);
89 noise_humidity = new Noise(bmgr->np_humidity, seed, csize.X, csize.Z);
91 //// Resolve nodes to be used
92 INodeDefManager *ndef = emerge->ndef;
94 c_stone = ndef->getId("mapgen_stone");
95 c_dirt = ndef->getId("mapgen_dirt");
96 c_dirt_with_grass = ndef->getId("mapgen_dirt_with_grass");
97 c_sand = ndef->getId("mapgen_sand");
98 c_water_source = ndef->getId("mapgen_water_source");
99 c_lava_source = ndef->getId("mapgen_lava_source");
100 c_ice = ndef->getId("default:ice");
101 if (c_ice == CONTENT_IGNORE)
106 MapgenV7::~MapgenV7() {
107 delete noise_terrain_base;
108 delete noise_terrain_persist;
109 delete noise_height_select;
110 delete noise_terrain_alt;
111 delete noise_filler_depth;
112 delete noise_mount_height;
113 delete noise_ridge_uwater;
114 delete noise_mountain;
118 delete noise_humidity;
120 delete[] ridge_heightmap;
126 MapgenV7Params::MapgenV7Params() {
127 spflags = MGV7_MOUNTAINS | MGV7_RIDGES;
129 np_terrain_base = NoiseParams(4, 70, v3f(300, 300, 300), 82341, 6, 0.7);
130 np_terrain_alt = NoiseParams(4, 25, v3f(600, 600, 600), 5934, 5, 0.6);
131 np_terrain_persist = NoiseParams(0.6, 0.1, v3f(500, 500, 500), 539, 3, 0.6);
132 np_height_select = NoiseParams(-0.5, 1, v3f(250, 250, 250), 4213, 5, 0.69);
133 np_filler_depth = NoiseParams(0, 1.2, v3f(150, 150, 150), 261, 4, 0.7);
134 np_mount_height = NoiseParams(100, 30, v3f(500, 500, 500), 72449, 4, 0.6);
135 np_ridge_uwater = NoiseParams(0, 1, v3f(500, 500, 500), 85039, 4, 0.6);
136 np_mountain = NoiseParams(0, 1, v3f(250, 350, 250), 5333, 5, 0.68);
137 np_ridge = NoiseParams(0, 1, v3f(100, 100, 100), 6467, 4, 0.75);
141 void MapgenV7Params::readParams(Settings *settings) {
142 settings->getFlagStrNoEx("mgv7_spflags", spflags, flagdesc_mapgen_v7);
144 settings->getNoiseParams("mgv7_np_terrain_base", np_terrain_base);
145 settings->getNoiseParams("mgv7_np_terrain_alt", np_terrain_alt);
146 settings->getNoiseParams("mgv7_np_terrain_persist", np_terrain_persist);
147 settings->getNoiseParams("mgv7_np_height_select", np_height_select);
148 settings->getNoiseParams("mgv7_np_filler_depth", np_filler_depth);
149 settings->getNoiseParams("mgv7_np_mount_height", np_mount_height);
150 settings->getNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater);
151 settings->getNoiseParams("mgv7_np_mountain", np_mountain);
152 settings->getNoiseParams("mgv7_np_ridge", np_ridge);
156 void MapgenV7Params::writeParams(Settings *settings) {
157 settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7, (u32)-1);
159 settings->setNoiseParams("mgv7_np_terrain_base", np_terrain_base);
160 settings->setNoiseParams("mgv7_np_terrain_alt", np_terrain_alt);
161 settings->setNoiseParams("mgv7_np_terrain_persist", np_terrain_persist);
162 settings->setNoiseParams("mgv7_np_height_select", np_height_select);
163 settings->setNoiseParams("mgv7_np_filler_depth", np_filler_depth);
164 settings->setNoiseParams("mgv7_np_mount_height", np_mount_height);
165 settings->setNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater);
166 settings->setNoiseParams("mgv7_np_mountain", np_mountain);
167 settings->setNoiseParams("mgv7_np_ridge", np_ridge);
171 ///////////////////////////////////////
174 int MapgenV7::getGroundLevelAtPoint(v2s16 p) {
175 // Base terrain calculation
176 s16 y = baseTerrainLevelAtPoint(p.X, p.Y);
178 // Ridge/river terrain calculation
180 float uwatern = NoisePerlin2DNoTxfm(noise_ridge_uwater->np, p.X, p.Y, seed) * 2;
181 // actually computing the depth of the ridge is much more expensive;
182 // if inside a river, simply guess
183 if (uwatern >= -width && uwatern <= width)
184 return water_level - 10;
186 // Mountain terrain calculation
187 int iters = 128; // don't even bother iterating more than 128 times..
189 //current point would have been air
190 if (!getMountainTerrainAtPoint(p.X, y, p.Y))
200 void MapgenV7::makeChunk(BlockMakeData *data) {
201 assert(data->vmanip);
202 assert(data->nodedef);
203 assert(data->blockpos_requested.X >= data->blockpos_min.X &&
204 data->blockpos_requested.Y >= data->blockpos_min.Y &&
205 data->blockpos_requested.Z >= data->blockpos_min.Z);
206 assert(data->blockpos_requested.X <= data->blockpos_max.X &&
207 data->blockpos_requested.Y <= data->blockpos_max.Y &&
208 data->blockpos_requested.Z <= data->blockpos_max.Z);
210 this->generating = true;
211 this->vm = data->vmanip;
212 this->ndef = data->nodedef;
213 //TimeTaker t("makeChunk");
215 v3s16 blockpos_min = data->blockpos_min;
216 v3s16 blockpos_max = data->blockpos_max;
217 node_min = blockpos_min * MAP_BLOCKSIZE;
218 node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
219 full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
220 full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
222 blockseed = emerge->getBlockSeed(full_node_min); //////use getBlockSeed2()!
227 // Generate base terrain, mountains, and ridges with initial heightmaps
228 s16 stone_surface_max_y = generateTerrain();
230 updateHeightmap(node_min, node_max);
233 BiomeNoiseInput binput;
234 binput.mapsize = v2s16(csize.X, csize.Z);
235 binput.heat_map = noise_heat->result;
236 binput.humidity_map = noise_humidity->result;
237 binput.height_map = heightmap;
238 bmgr->calcBiomes(&binput, biomemap);
240 // Actually place the biome-specific nodes and what not
243 if (flags & MG_CAVES)
244 generateCaves(stone_surface_max_y);
246 if (flags & MG_DUNGEONS) {
247 DungeonGen dgen(this, NULL);
248 dgen.generate(blockseed, full_node_min, full_node_max);
251 for (size_t i = 0; i != emerge->decorations.size(); i++) {
252 Decoration *deco = emerge->decorations[i];
253 deco->placeDeco(this, blockseed + i, node_min, node_max);
256 for (size_t i = 0; i != emerge->ores.size(); i++) {
257 Ore *ore = emerge->ores[i];
258 ore->placeOre(this, blockseed + i, node_min, node_max);
261 // Sprinkle some dust on top after everything else was generated
264 //printf("makeChunk: %dms\n", t.stop());
266 updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
268 if (flags & MG_LIGHT)
269 calcLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
270 node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE);
271 //setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
272 // node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);
274 this->generating = false;
278 void MapgenV7::calculateNoise() {
279 //TimeTaker t("calculateNoise", NULL, PRECISION_MICRO);
284 noise_height_select->perlinMap2D(x, z);
285 noise_height_select->transformNoiseMap();
287 noise_terrain_persist->perlinMap2D(x, z);
288 noise_terrain_persist->transformNoiseMap();
289 float *persistmap = noise_terrain_persist->result;
290 for (int i = 0; i != csize.X * csize.Z; i++)
291 persistmap[i] = rangelim(persistmap[i], 0.4, 0.9);
293 noise_terrain_base->perlinMap2DModulated(x, z, persistmap);
294 noise_terrain_base->transformNoiseMap();
296 noise_terrain_alt->perlinMap2DModulated(x, z, persistmap);
297 noise_terrain_alt->transformNoiseMap();
299 noise_filler_depth->perlinMap2D(x, z);
301 if (spflags & MGV7_MOUNTAINS) {
302 noise_mountain->perlinMap3D(x, y, z);
303 noise_mount_height->perlinMap2D(x, z);
304 noise_mount_height->transformNoiseMap();
307 if (spflags & MGV7_RIDGES) {
308 noise_ridge->perlinMap3D(x, y, z);
309 noise_ridge_uwater->perlinMap2D(x, z);
312 noise_heat->perlinMap2D(x, z);
313 noise_humidity->perlinMap2D(x, z);
315 //printf("calculateNoise: %dus\n", t.stop());
319 Biome *MapgenV7::getBiomeAtPoint(v3s16 p) {
320 float heat = NoisePerlin2D(bmgr->np_heat, p.X, p.Z, seed);
321 float humidity = NoisePerlin2D(bmgr->np_humidity, p.X, p.Z, seed);
322 s16 groundlevel = baseTerrainLevelAtPoint(p.X, p.Z);
324 return bmgr->getBiome(heat, humidity, groundlevel);
327 //needs to be updated
328 float MapgenV7::baseTerrainLevelAtPoint(int x, int z) {
329 float hselect = NoisePerlin2D(noise_height_select->np, x, z, seed);
330 hselect = rangelim(hselect, 0.0, 1.0);
332 float persist = NoisePerlin2D(noise_terrain_persist->np, x, z, seed);
333 persist = rangelim(persist, 0.4, 0.9);
335 noise_terrain_base->np->persist = persist;
336 float height_base = NoisePerlin2D(noise_terrain_base->np, x, z, seed);
338 noise_terrain_alt->np->persist = persist;
339 float height_alt = NoisePerlin2D(noise_terrain_alt->np, x, z, seed);
341 if (height_alt > height_base)
344 return (height_base * hselect) + (height_alt * (1.0 - hselect));
348 float MapgenV7::baseTerrainLevelFromMap(int index) {
349 float hselect = rangelim(noise_height_select->result[index], 0.0, 1.0);
350 float height_base = noise_terrain_base->result[index];
351 float height_alt = noise_terrain_alt->result[index];
353 if (height_alt > height_base)
356 return (height_base * hselect) + (height_alt * (1.0 - hselect));
360 bool MapgenV7::getMountainTerrainAtPoint(int x, int y, int z) {
361 float mnt_h_n = NoisePerlin2D(noise_mount_height->np, x, z, seed);
362 float height_modifier = -((float)y / rangelim(mnt_h_n, 80.0, 150.0));
363 float mnt_n = NoisePerlin3D(noise_mountain->np, x, y, z, seed);
365 return mnt_n + height_modifier >= 0.6;
369 bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, int y) {
370 float mounthn = noise_mount_height->result[idx_xz];
371 float height_modifier = -((float)y / rangelim(mounthn, 80.0, 150.0));
372 return (noise_mountain->result[idx_xyz] + height_modifier >= 0.6);
377 void MapgenV7::carveRivers() {
378 MapNode n_air(CONTENT_AIR), n_water_source(c_water_source);
379 MapNode n_stone(c_stone);
384 for (s16 z = node_min.Z; z <= node_max.Z; z++)
385 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
386 float terrain_mod = noise_terrain_mod->result[index];
387 NoiseParams *np = noise_terrain_river->np;
388 np->persist = noise_terrain_persist->result[index];
389 float terrain_river = NoisePerlin2DNoTxfm(np, x, z, seed);
390 float height = terrain_river * (1 - abs(terrain_mod)) *
391 noise_terrain_river->np->scale;
392 height = log(height * height); //log(h^3) is pretty interesting for terrain
394 s16 y = heightmap[index];
395 if (height < 1.0 && y > river_depth &&
396 y - river_depth >= node_min.Y && y <= node_max.Y) {
398 for (s16 ry = y; ry != y - river_depth; ry--) {
399 u32 vi = vm->m_area.index(x, ry, z);
400 vm->m_data[vi] = n_air;
403 u32 vi = vm->m_area.index(x, y - river_depth, z);
404 vm->m_data[vi] = n_water_source;
411 int MapgenV7::generateTerrain() {
412 int ymax = generateBaseTerrain();
414 if (spflags & MGV7_MOUNTAINS)
415 generateMountainTerrain();
417 if (spflags & MGV7_RIDGES)
418 generateRidgeTerrain();
424 int MapgenV7::generateBaseTerrain() {
425 MapNode n_air(CONTENT_AIR);
426 MapNode n_stone(c_stone);
427 MapNode n_water(c_water_source);
429 int stone_surface_max_y = -MAP_GENERATION_LIMIT;
430 v3s16 em = vm->m_area.getExtent();
433 for (s16 z = node_min.Z; z <= node_max.Z; z++)
434 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
435 float surface_height = baseTerrainLevelFromMap(index);
436 s16 surface_y = (s16)surface_height;
438 heightmap[index] = surface_y;
439 ridge_heightmap[index] = surface_y;
441 if (surface_y > stone_surface_max_y)
442 stone_surface_max_y = surface_y;
444 u32 i = vm->m_area.index(x, node_min.Y, z);
445 for (s16 y = node_min.Y; y <= node_max.Y; y++) {
446 if (vm->m_data[i].getContent() == CONTENT_IGNORE) {
448 vm->m_data[i] = n_stone;
449 else if (y <= water_level)
450 vm->m_data[i] = n_water;
452 vm->m_data[i] = n_air;
454 vm->m_area.add_y(em, i, 1);
458 return stone_surface_max_y;
462 void MapgenV7::generateMountainTerrain() {
463 if (node_max.Y <= water_level)
466 MapNode n_stone(c_stone);
469 for (s16 z = node_min.Z; z <= node_max.Z; z++)
470 for (s16 y = node_min.Y; y <= node_max.Y; y++) {
471 u32 vi = vm->m_area.index(node_min.X, y, z);
472 for (s16 x = node_min.X; x <= node_max.X; x++) {
473 int index = (z - node_min.Z) * csize.X + (x - node_min.X);
475 if (getMountainTerrainFromMap(j, index, y))
476 vm->m_data[vi] = n_stone;
485 void MapgenV7::generateRidgeTerrain() {
486 MapNode n_water(c_water_source);
487 MapNode n_air(CONTENT_AIR);
490 for (s16 z = node_min.Z; z <= node_max.Z; z++)
491 for (s16 y = node_min.Y; y <= node_max.Y; y++) {
492 u32 vi = vm->m_area.index(node_min.X, y, z);
493 for (s16 x = node_min.X; x <= node_max.X; x++, index++, vi++) {
494 int j = (z - node_min.Z) * csize.X + (x - node_min.X);
496 if (heightmap[j] < water_level - 4)
499 float widthn = (noise_terrain_persist->result[j] - 0.6) / 0.1;
500 //widthn = rangelim(widthn, -0.05, 0.5);
502 float width = 0.3; // TODO: figure out acceptable perlin noise values
503 float uwatern = noise_ridge_uwater->result[j] * 2;
504 if (uwatern < -width || uwatern > width)
507 float height_mod = (float)(y + 17) / 2.5;
508 float width_mod = (width - fabs(uwatern));
509 float nridge = noise_ridge->result[index] * (float)y / 7.0;
512 nridge = -fabs(nridge) * 3.0 * widthn * 0.3;
514 if (nridge + width_mod * height_mod < 0.6)
517 if (y < ridge_heightmap[j])
518 ridge_heightmap[j] = y - 1;
520 vm->m_data[vi] = (y > water_level) ? n_air : n_water;
526 void MapgenV7::generateBiomes() {
527 if (node_max.Y < water_level)
530 MapNode n_air(CONTENT_AIR);
531 MapNode n_stone(c_stone);
532 MapNode n_water(c_water_source);
534 v3s16 em = vm->m_area.getExtent();
537 for (s16 z = node_min.Z; z <= node_max.Z; z++)
538 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
539 Biome *biome = bmgr->biomes[biomemap[index]];
540 s16 dfiller = biome->depth_filler + noise_filler_depth->result[index];
541 s16 y0_top = biome->depth_top;
542 s16 y0_filler = biome->depth_filler + biome->depth_top + dfiller;
545 u32 i = vm->m_area.index(x, node_max.Y, z);
547 content_t c_above = vm->m_data[i + em.X].getContent();
548 bool have_air = c_above == CONTENT_AIR;
550 for (s16 y = node_max.Y; y >= node_min.Y; y--) {
551 content_t c = vm->m_data[i].getContent();
553 // It could be the case that the elevation is equal to the chunk
554 // boundary, but the chunk above has not been generated yet
555 if (y == node_max.Y && c_above == CONTENT_IGNORE &&
556 y == heightmap[index] && c == c_stone) {
557 int j = (z - node_min.Z) * zstride +
558 (y - node_min.Y) * ystride +
560 have_air = !getMountainTerrainFromMap(j, index, y);
563 if (c == c_stone && have_air) {
564 content_t c_below = vm->m_data[i - em.X].getContent();
566 if (c_below != CONTENT_AIR) {
567 if (nplaced < y0_top) {
568 // A hack to prevent dirt_with_grass from being
569 // placed below water. TODO: fix later
570 content_t c_place = ((y < water_level) &&
571 (biome->c_top == c_dirt_with_grass)) ?
572 c_dirt : biome->c_top;
574 vm->m_data[i] = MapNode(c_place);
576 } else if (nplaced < y0_filler && nplaced >= y0_top) {
577 vm->m_data[i] = MapNode(biome->c_filler);
584 } else if (c == c_water_source) {
587 vm->m_data[i] = MapNode(biome->c_water);
588 } else if (c == CONTENT_AIR) {
593 vm->m_area.add_y(em, i, -1);
599 void MapgenV7::dustTopNodes() {
600 v3s16 em = vm->m_area.getExtent();
603 if (water_level > node_max.Y)
606 for (s16 z = node_min.Z; z <= node_max.Z; z++)
607 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
608 Biome *biome = bmgr->biomes[biomemap[index]];
610 if (biome->c_dust == CONTENT_IGNORE)
614 u32 vi = vm->m_area.index(x, y, z);
615 for (; y >= node_min.Y; y--) {
616 if (vm->m_data[vi].getContent() != CONTENT_AIR)
619 vm->m_area.add_y(em, vi, -1);
622 content_t c = vm->m_data[vi].getContent();
623 if (c == biome->c_water && biome->c_dust_water != CONTENT_IGNORE) {
627 vm->m_data[vi] = MapNode(biome->c_dust_water);
628 } else if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE) {
632 vm->m_area.add_y(em, vi, 1);
633 vm->m_data[vi] = MapNode(biome->c_dust);
640 void MapgenV7::addTopNodes() {
641 v3s16 em = vm->m_area.getExtent();
645 for (s16 z = node_min.Z; z <= node_max.Z; z++)
646 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
647 Biome *biome = bmgr->biomes[biomemap[index]];
649 //////////////////// First, add top nodes below the ridge
650 s16 y = ridge_heightmap[index];
652 // This cutoff is good enough, but not perfect.
653 // It will cut off potentially placed top nodes at chunk boundaries
656 if (y > node_max.Y) {
657 y = node_max.Y; // Let's see if we can still go downward anyway
658 u32 vi = vm->m_area.index(x, y, z);
659 content_t c = vm->m_data[vi].getContent();
660 if (ndef->get(c).walkable)
664 // N.B. It is necessary to search downward since ridge_heightmap[i]
665 // might not be the actual height, just the lowest part in the chunk
666 // where a ridge had been carved
667 u32 i = vm->m_area.index(x, y, z);
668 for (; y >= node_min.Y; y--) {
669 content_t c = vm->m_data[i].getContent();
670 if (ndef->get(c).walkable)
672 vm->m_area.add_y(em, i, -1);
675 if (y != node_min.Y - 1 && y >= water_level) {
676 ridge_heightmap[index] = y; //update ridgeheight
677 ntopnodes = biome->top_depth;
678 for (; y <= node_max.Y && ntopnodes; y++) {
680 vm->m_data[i] = MapNode(biome->c_top);
681 vm->m_area.add_y(em, i, 1);
683 // If dirt, grow grass on it.
684 if (y > water_level - 10 &&
685 vm->m_data[i].getContent() == CONTENT_AIR) {
686 vm->m_area.add_y(em, i, -1);
687 if (vm->m_data[i].getContent() == c_dirt)
688 vm->m_data[i] = MapNode(c_dirt_with_grass);
692 //////////////////// Now, add top nodes on top of the ridge
693 y = heightmap[index];
694 if (y > node_max.Y) {
695 y = node_max.Y; // Let's see if we can still go downward anyway
696 u32 vi = vm->m_area.index(x, y, z);
697 content_t c = vm->m_data[vi].getContent();
698 if (ndef->get(c).walkable)
702 i = vm->m_area.index(x, y, z);
703 for (; y >= node_min.Y; y--) {
704 content_t c = vm->m_data[i].getContent();
705 if (ndef->get(c).walkable)
707 vm->m_area.add_y(em, i, -1);
710 if (y != node_min.Y - 1) {
711 ntopnodes = biome->top_depth;
712 // Let's see if we've already added it...
713 if (y == ridge_heightmap[index] + ntopnodes - 1)
716 for (; y <= node_max.Y && ntopnodes; y++) {
718 vm->m_data[i] = MapNode(biome->c_top);
719 vm->m_area.add_y(em, i, 1);
721 // If dirt, grow grass on it.
722 if (y > water_level - 10 &&
723 vm->m_data[i].getContent() == CONTENT_AIR) {
724 vm->m_area.add_y(em, i, -1);
725 if (vm->m_data[i].getContent() == c_dirt)
726 vm->m_data[i] = MapNode(c_dirt_with_grass);
734 NoiseParams nparams_v7_def_cave(6, 6.0, v3f(250.0, 250.0, 250.0), 34329, 3, 0.50);
736 void MapgenV7::generateCaves(int max_stone_y) {
737 PseudoRandom ps(blockseed + 21343);
739 int volume_nodes = (node_max.X - node_min.X + 1) *
740 (node_max.Y - node_min.Y + 1) *
741 (node_max.Z - node_min.Z + 1);
742 float cave_amount = NoisePerlin2D(&nparams_v7_def_cave,
743 node_min.X, node_min.Y, seed);
745 u32 caves_count = MYMAX(0.0, cave_amount) * volume_nodes / 250000;
746 for (u32 i = 0; i < caves_count; i++) {
747 CaveV7 cave(this, &ps, false);
748 cave.makeCave(node_min, node_max, max_stone_y);
751 u32 bruises_count = (ps.range(1, 8) == 1) ? ps.range(0, ps.range(0, 2)) : 1;
752 for (u32 i = 0; i < bruises_count; i++) {
753 CaveV7 cave(this, &ps, true);
754 cave.makeCave(node_min, node_max, max_stone_y);