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"
39 #include "mg_decoration.h"
40 #include "mapgen_v7.h"
43 FlagDesc flagdesc_mapgen_v7[] = {
44 {"mountains", MGV7_MOUNTAINS},
45 {"ridges", MGV7_RIDGES},
49 ///////////////////////////////////////////////////////////////////////////////
52 MapgenV7::MapgenV7(int mapgenid, MapgenParams *params, EmergeManager *emerge) {
53 this->generating = false;
55 this->emerge = emerge;
56 this->bmgr = emerge->biomemgr;
58 this->seed = (int)params->seed;
59 this->water_level = params->water_level;
60 this->flags = params->flags;
61 this->gennotify = emerge->gennotify;
63 this->csize = v3s16(1, 1, 1) * params->chunksize * MAP_BLOCKSIZE;
65 //// amount of elements to skip for the next index
66 //// for noise/height/biome maps (not vmanip)
67 this->ystride = csize.X;
68 this->zstride = csize.X * csize.Y;
70 this->biomemap = new u8[csize.X * csize.Z];
71 this->heightmap = new s16[csize.X * csize.Z];
72 this->ridge_heightmap = new s16[csize.X * csize.Z];
74 MapgenV7Params *sp = (MapgenV7Params *)params->sparams;
75 this->spflags = sp->spflags;
78 noise_terrain_base = new Noise(&sp->np_terrain_base, seed, csize.X, csize.Z);
79 noise_terrain_alt = new Noise(&sp->np_terrain_alt, seed, csize.X, csize.Z);
80 noise_terrain_persist = new Noise(&sp->np_terrain_persist, seed, csize.X, csize.Z);
81 noise_height_select = new Noise(&sp->np_height_select, seed, csize.X, csize.Z);
82 noise_filler_depth = new Noise(&sp->np_filler_depth, seed, csize.X, csize.Z);
83 noise_mount_height = new Noise(&sp->np_mount_height, seed, csize.X, csize.Z);
84 noise_ridge_uwater = new Noise(&sp->np_ridge_uwater, seed, csize.X, csize.Z);
87 noise_mountain = new Noise(&sp->np_mountain, seed, csize.X, csize.Y, csize.Z);
88 noise_ridge = new Noise(&sp->np_ridge, seed, csize.X, csize.Y, csize.Z);
91 noise_heat = new Noise(bmgr->np_heat, seed, csize.X, csize.Z);
92 noise_humidity = new Noise(bmgr->np_humidity, seed, csize.X, csize.Z);
94 //// Resolve nodes to be used
95 INodeDefManager *ndef = emerge->ndef;
97 c_stone = ndef->getId("mapgen_stone");
98 c_dirt = ndef->getId("mapgen_dirt");
99 c_dirt_with_grass = ndef->getId("mapgen_dirt_with_grass");
100 c_sand = ndef->getId("mapgen_sand");
101 c_water_source = ndef->getId("mapgen_water_source");
102 c_lava_source = ndef->getId("mapgen_lava_source");
103 c_ice = ndef->getId("default:ice");
104 if (c_ice == CONTENT_IGNORE)
109 MapgenV7::~MapgenV7() {
110 delete noise_terrain_base;
111 delete noise_terrain_persist;
112 delete noise_height_select;
113 delete noise_terrain_alt;
114 delete noise_filler_depth;
115 delete noise_mount_height;
116 delete noise_ridge_uwater;
117 delete noise_mountain;
121 delete noise_humidity;
123 delete[] ridge_heightmap;
129 MapgenV7Params::MapgenV7Params() {
130 spflags = MGV7_MOUNTAINS | MGV7_RIDGES;
132 np_terrain_base = NoiseParams(4, 70, v3f(300, 300, 300), 82341, 6, 0.7);
133 np_terrain_alt = NoiseParams(4, 25, v3f(600, 600, 600), 5934, 5, 0.6);
134 np_terrain_persist = NoiseParams(0.6, 0.1, v3f(500, 500, 500), 539, 3, 0.6);
135 np_height_select = NoiseParams(-0.5, 1, v3f(250, 250, 250), 4213, 5, 0.69);
136 np_filler_depth = NoiseParams(0, 1.2, v3f(150, 150, 150), 261, 4, 0.7);
137 np_mount_height = NoiseParams(100, 30, v3f(500, 500, 500), 72449, 4, 0.6);
138 np_ridge_uwater = NoiseParams(0, 1, v3f(500, 500, 500), 85039, 4, 0.6);
139 np_mountain = NoiseParams(0, 1, v3f(250, 350, 250), 5333, 5, 0.68);
140 np_ridge = NoiseParams(0, 1, v3f(100, 100, 100), 6467, 4, 0.75);
144 void MapgenV7Params::readParams(Settings *settings) {
145 settings->getFlagStrNoEx("mgv7_spflags", spflags, flagdesc_mapgen_v7);
147 settings->getNoiseParams("mgv7_np_terrain_base", np_terrain_base);
148 settings->getNoiseParams("mgv7_np_terrain_alt", np_terrain_alt);
149 settings->getNoiseParams("mgv7_np_terrain_persist", np_terrain_persist);
150 settings->getNoiseParams("mgv7_np_height_select", np_height_select);
151 settings->getNoiseParams("mgv7_np_filler_depth", np_filler_depth);
152 settings->getNoiseParams("mgv7_np_mount_height", np_mount_height);
153 settings->getNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater);
154 settings->getNoiseParams("mgv7_np_mountain", np_mountain);
155 settings->getNoiseParams("mgv7_np_ridge", np_ridge);
159 void MapgenV7Params::writeParams(Settings *settings) {
160 settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7, (u32)-1);
162 settings->setNoiseParams("mgv7_np_terrain_base", np_terrain_base);
163 settings->setNoiseParams("mgv7_np_terrain_alt", np_terrain_alt);
164 settings->setNoiseParams("mgv7_np_terrain_persist", np_terrain_persist);
165 settings->setNoiseParams("mgv7_np_height_select", np_height_select);
166 settings->setNoiseParams("mgv7_np_filler_depth", np_filler_depth);
167 settings->setNoiseParams("mgv7_np_mount_height", np_mount_height);
168 settings->setNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater);
169 settings->setNoiseParams("mgv7_np_mountain", np_mountain);
170 settings->setNoiseParams("mgv7_np_ridge", np_ridge);
174 ///////////////////////////////////////
177 int MapgenV7::getGroundLevelAtPoint(v2s16 p) {
178 // Base terrain calculation
179 s16 y = baseTerrainLevelAtPoint(p.X, p.Y);
181 // Ridge/river terrain calculation
183 float uwatern = NoisePerlin2DNoTxfm(noise_ridge_uwater->np, p.X, p.Y, seed) * 2;
184 // actually computing the depth of the ridge is much more expensive;
185 // if inside a river, simply guess
186 if (uwatern >= -width && uwatern <= width)
187 return water_level - 10;
189 // Mountain terrain calculation
190 int iters = 128; // don't even bother iterating more than 128 times..
192 //current point would have been air
193 if (!getMountainTerrainAtPoint(p.X, y, p.Y))
203 void MapgenV7::makeChunk(BlockMakeData *data) {
204 assert(data->vmanip);
205 assert(data->nodedef);
206 assert(data->blockpos_requested.X >= data->blockpos_min.X &&
207 data->blockpos_requested.Y >= data->blockpos_min.Y &&
208 data->blockpos_requested.Z >= data->blockpos_min.Z);
209 assert(data->blockpos_requested.X <= data->blockpos_max.X &&
210 data->blockpos_requested.Y <= data->blockpos_max.Y &&
211 data->blockpos_requested.Z <= data->blockpos_max.Z);
213 this->generating = true;
214 this->vm = data->vmanip;
215 this->ndef = data->nodedef;
216 //TimeTaker t("makeChunk");
218 v3s16 blockpos_min = data->blockpos_min;
219 v3s16 blockpos_max = data->blockpos_max;
220 node_min = blockpos_min * MAP_BLOCKSIZE;
221 node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
222 full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
223 full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
225 blockseed = emerge->getBlockSeed(full_node_min); //////use getBlockSeed2()!
230 // Generate base terrain, mountains, and ridges with initial heightmaps
231 s16 stone_surface_max_y = generateTerrain();
233 updateHeightmap(node_min, node_max);
236 BiomeNoiseInput binput;
237 binput.mapsize = v2s16(csize.X, csize.Z);
238 binput.heat_map = noise_heat->result;
239 binput.humidity_map = noise_humidity->result;
240 binput.height_map = heightmap;
241 bmgr->calcBiomes(&binput, biomemap);
243 // Actually place the biome-specific nodes and what not
246 if (flags & MG_CAVES)
247 generateCaves(stone_surface_max_y);
249 if (flags & MG_DUNGEONS) {
250 DungeonGen dgen(this, NULL);
251 dgen.generate(blockseed, full_node_min, full_node_max);
254 // Generate the registered decorations
255 emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);
257 // Generate the registered ores
258 emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
260 // Sprinkle some dust on top after everything else was generated
263 //printf("makeChunk: %dms\n", t.stop());
265 updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
267 if (flags & MG_LIGHT)
268 calcLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
269 node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE);
270 //setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
271 // node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);
273 this->generating = false;
277 void MapgenV7::calculateNoise() {
278 //TimeTaker t("calculateNoise", NULL, PRECISION_MICRO);
283 noise_height_select->perlinMap2D(x, z);
284 noise_height_select->transformNoiseMap();
286 noise_terrain_persist->perlinMap2D(x, z);
287 noise_terrain_persist->transformNoiseMap();
288 float *persistmap = noise_terrain_persist->result;
289 for (int i = 0; i != csize.X * csize.Z; i++)
290 persistmap[i] = rangelim(persistmap[i], 0.4, 0.9);
292 noise_terrain_base->perlinMap2DModulated(x, z, persistmap);
293 noise_terrain_base->transformNoiseMap();
295 noise_terrain_alt->perlinMap2DModulated(x, z, persistmap);
296 noise_terrain_alt->transformNoiseMap();
298 noise_filler_depth->perlinMap2D(x, z);
300 if (spflags & MGV7_MOUNTAINS) {
301 noise_mountain->perlinMap3D(x, y, z);
302 noise_mount_height->perlinMap2D(x, z);
303 noise_mount_height->transformNoiseMap();
306 if (spflags & MGV7_RIDGES) {
307 noise_ridge->perlinMap3D(x, y, z);
308 noise_ridge_uwater->perlinMap2D(x, z);
311 noise_heat->perlinMap2D(x, z);
312 noise_humidity->perlinMap2D(x, z);
314 //printf("calculateNoise: %dus\n", t.stop());
318 Biome *MapgenV7::getBiomeAtPoint(v3s16 p) {
319 float heat = NoisePerlin2D(bmgr->np_heat, p.X, p.Z, seed);
320 float humidity = NoisePerlin2D(bmgr->np_humidity, p.X, p.Z, seed);
321 s16 groundlevel = baseTerrainLevelAtPoint(p.X, p.Z);
323 return bmgr->getBiome(heat, humidity, groundlevel);
326 //needs to be updated
327 float MapgenV7::baseTerrainLevelAtPoint(int x, int z) {
328 float hselect = NoisePerlin2D(noise_height_select->np, x, z, seed);
329 hselect = rangelim(hselect, 0.0, 1.0);
331 float persist = NoisePerlin2D(noise_terrain_persist->np, x, z, seed);
332 persist = rangelim(persist, 0.4, 0.9);
334 noise_terrain_base->np->persist = persist;
335 float height_base = NoisePerlin2D(noise_terrain_base->np, x, z, seed);
337 noise_terrain_alt->np->persist = persist;
338 float height_alt = NoisePerlin2D(noise_terrain_alt->np, x, z, seed);
340 if (height_alt > height_base)
343 return (height_base * hselect) + (height_alt * (1.0 - hselect));
347 float MapgenV7::baseTerrainLevelFromMap(int index) {
348 float hselect = rangelim(noise_height_select->result[index], 0.0, 1.0);
349 float height_base = noise_terrain_base->result[index];
350 float height_alt = noise_terrain_alt->result[index];
352 if (height_alt > height_base)
355 return (height_base * hselect) + (height_alt * (1.0 - hselect));
359 bool MapgenV7::getMountainTerrainAtPoint(int x, int y, int z) {
360 float mnt_h_n = NoisePerlin2D(noise_mount_height->np, x, z, seed);
361 float height_modifier = -((float)y / rangelim(mnt_h_n, 80.0, 150.0));
362 float mnt_n = NoisePerlin3D(noise_mountain->np, x, y, z, seed);
364 return mnt_n + height_modifier >= 0.6;
368 bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, int y) {
369 float mounthn = noise_mount_height->result[idx_xz];
370 float height_modifier = -((float)y / rangelim(mounthn, 80.0, 150.0));
371 return (noise_mountain->result[idx_xyz] + height_modifier >= 0.6);
376 void MapgenV7::carveRivers() {
377 MapNode n_air(CONTENT_AIR), n_water_source(c_water_source);
378 MapNode n_stone(c_stone);
383 for (s16 z = node_min.Z; z <= node_max.Z; z++)
384 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
385 float terrain_mod = noise_terrain_mod->result[index];
386 NoiseParams *np = noise_terrain_river->np;
387 np->persist = noise_terrain_persist->result[index];
388 float terrain_river = NoisePerlin2DNoTxfm(np, x, z, seed);
389 float height = terrain_river * (1 - abs(terrain_mod)) *
390 noise_terrain_river->np->scale;
391 height = log(height * height); //log(h^3) is pretty interesting for terrain
393 s16 y = heightmap[index];
394 if (height < 1.0 && y > river_depth &&
395 y - river_depth >= node_min.Y && y <= node_max.Y) {
397 for (s16 ry = y; ry != y - river_depth; ry--) {
398 u32 vi = vm->m_area.index(x, ry, z);
399 vm->m_data[vi] = n_air;
402 u32 vi = vm->m_area.index(x, y - river_depth, z);
403 vm->m_data[vi] = n_water_source;
410 int MapgenV7::generateTerrain() {
411 int ymax = generateBaseTerrain();
413 if (spflags & MGV7_MOUNTAINS)
414 generateMountainTerrain();
416 if (spflags & MGV7_RIDGES)
417 generateRidgeTerrain();
423 int MapgenV7::generateBaseTerrain() {
424 MapNode n_air(CONTENT_AIR);
425 MapNode n_stone(c_stone);
426 MapNode n_water(c_water_source);
428 int stone_surface_max_y = -MAP_GENERATION_LIMIT;
429 v3s16 em = vm->m_area.getExtent();
432 for (s16 z = node_min.Z; z <= node_max.Z; z++)
433 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
434 float surface_height = baseTerrainLevelFromMap(index);
435 s16 surface_y = (s16)surface_height;
437 heightmap[index] = surface_y;
438 ridge_heightmap[index] = surface_y;
440 if (surface_y > stone_surface_max_y)
441 stone_surface_max_y = surface_y;
443 u32 i = vm->m_area.index(x, node_min.Y, z);
444 for (s16 y = node_min.Y; y <= node_max.Y; y++) {
445 if (vm->m_data[i].getContent() == CONTENT_IGNORE) {
447 vm->m_data[i] = n_stone;
448 else if (y <= water_level)
449 vm->m_data[i] = n_water;
451 vm->m_data[i] = n_air;
453 vm->m_area.add_y(em, i, 1);
457 return stone_surface_max_y;
461 void MapgenV7::generateMountainTerrain() {
462 if (node_max.Y <= water_level)
465 MapNode n_stone(c_stone);
468 for (s16 z = node_min.Z; z <= node_max.Z; z++)
469 for (s16 y = node_min.Y; y <= node_max.Y; y++) {
470 u32 vi = vm->m_area.index(node_min.X, y, z);
471 for (s16 x = node_min.X; x <= node_max.X; x++) {
472 int index = (z - node_min.Z) * csize.X + (x - node_min.X);
474 if (getMountainTerrainFromMap(j, index, y))
475 vm->m_data[vi] = n_stone;
484 void MapgenV7::generateRidgeTerrain() {
485 MapNode n_water(c_water_source);
486 MapNode n_air(CONTENT_AIR);
489 for (s16 z = node_min.Z; z <= node_max.Z; z++)
490 for (s16 y = node_min.Y; y <= node_max.Y; y++) {
491 u32 vi = vm->m_area.index(node_min.X, y, z);
492 for (s16 x = node_min.X; x <= node_max.X; x++, index++, vi++) {
493 int j = (z - node_min.Z) * csize.X + (x - node_min.X);
495 if (heightmap[j] < water_level - 4)
498 float widthn = (noise_terrain_persist->result[j] - 0.6) / 0.1;
499 //widthn = rangelim(widthn, -0.05, 0.5);
501 float width = 0.3; // TODO: figure out acceptable perlin noise values
502 float uwatern = noise_ridge_uwater->result[j] * 2;
503 if (uwatern < -width || uwatern > width)
506 float height_mod = (float)(y + 17) / 2.5;
507 float width_mod = (width - fabs(uwatern));
508 float nridge = noise_ridge->result[index] * (float)y / 7.0;
511 nridge = -fabs(nridge) * 3.0 * widthn * 0.3;
513 if (nridge + width_mod * height_mod < 0.6)
516 if (y < ridge_heightmap[j])
517 ridge_heightmap[j] = y - 1;
519 vm->m_data[vi] = (y > water_level) ? n_air : n_water;
525 void MapgenV7::generateBiomes() {
526 if (node_max.Y < water_level)
529 MapNode n_air(CONTENT_AIR);
530 MapNode n_stone(c_stone);
531 MapNode n_water(c_water_source);
533 v3s16 em = vm->m_area.getExtent();
536 for (s16 z = node_min.Z; z <= node_max.Z; z++)
537 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
538 Biome *biome = (Biome *)bmgr->get(biomemap[index]);
539 s16 dfiller = biome->depth_filler + noise_filler_depth->result[index];
540 s16 y0_top = biome->depth_top;
541 s16 y0_filler = biome->depth_filler + biome->depth_top + dfiller;
544 u32 i = vm->m_area.index(x, node_max.Y, z);
546 content_t c_above = vm->m_data[i + em.X].getContent();
547 bool have_air = c_above == CONTENT_AIR;
549 for (s16 y = node_max.Y; y >= node_min.Y; y--) {
550 content_t c = vm->m_data[i].getContent();
552 // It could be the case that the elevation is equal to the chunk
553 // boundary, but the chunk above has not been generated yet
554 if (y == node_max.Y && c_above == CONTENT_IGNORE &&
555 y == heightmap[index] && c == c_stone) {
556 int j = (z - node_min.Z) * zstride +
557 (y - node_min.Y) * ystride +
559 have_air = !getMountainTerrainFromMap(j, index, y);
562 if (c == c_stone && have_air) {
563 content_t c_below = vm->m_data[i - em.X].getContent();
565 if (c_below != CONTENT_AIR) {
566 if (nplaced < y0_top) {
567 // A hack to prevent dirt_with_grass from being
568 // placed below water. TODO: fix later
569 content_t c_place = ((y < water_level) &&
570 (biome->c_top == c_dirt_with_grass)) ?
571 c_dirt : biome->c_top;
573 vm->m_data[i] = MapNode(c_place);
575 } else if (nplaced < y0_filler && nplaced >= y0_top) {
576 vm->m_data[i] = MapNode(biome->c_filler);
583 } else if (c == c_water_source) {
586 vm->m_data[i] = MapNode(biome->c_water);
587 } else if (c == CONTENT_AIR) {
592 vm->m_area.add_y(em, i, -1);
598 void MapgenV7::dustTopNodes() {
599 v3s16 em = vm->m_area.getExtent();
602 if (water_level > node_max.Y)
605 for (s16 z = node_min.Z; z <= node_max.Z; z++)
606 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
607 Biome *biome = (Biome *)bmgr->get(biomemap[index]);
609 if (biome->c_dust == CONTENT_IGNORE)
613 u32 vi = vm->m_area.index(x, y, z);
614 for (; y >= node_min.Y; y--) {
615 if (vm->m_data[vi].getContent() != CONTENT_AIR)
618 vm->m_area.add_y(em, vi, -1);
621 content_t c = vm->m_data[vi].getContent();
622 if (c == biome->c_water && biome->c_dust_water != CONTENT_IGNORE) {
626 vm->m_data[vi] = MapNode(biome->c_dust_water);
627 } else if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE) {
631 vm->m_area.add_y(em, vi, 1);
632 vm->m_data[vi] = MapNode(biome->c_dust);
639 void MapgenV7::addTopNodes() {
640 v3s16 em = vm->m_area.getExtent();
644 for (s16 z = node_min.Z; z <= node_max.Z; z++)
645 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
646 Biome *biome = bmgr->biomes[biomemap[index]];
648 //////////////////// First, add top nodes below the ridge
649 s16 y = ridge_heightmap[index];
651 // This cutoff is good enough, but not perfect.
652 // It will cut off potentially placed top nodes at chunk boundaries
655 if (y > node_max.Y) {
656 y = node_max.Y; // Let's see if we can still go downward anyway
657 u32 vi = vm->m_area.index(x, y, z);
658 content_t c = vm->m_data[vi].getContent();
659 if (ndef->get(c).walkable)
663 // N.B. It is necessary to search downward since ridge_heightmap[i]
664 // might not be the actual height, just the lowest part in the chunk
665 // where a ridge had been carved
666 u32 i = vm->m_area.index(x, y, z);
667 for (; y >= node_min.Y; y--) {
668 content_t c = vm->m_data[i].getContent();
669 if (ndef->get(c).walkable)
671 vm->m_area.add_y(em, i, -1);
674 if (y != node_min.Y - 1 && y >= water_level) {
675 ridge_heightmap[index] = y; //update ridgeheight
676 ntopnodes = biome->top_depth;
677 for (; y <= node_max.Y && ntopnodes; y++) {
679 vm->m_data[i] = MapNode(biome->c_top);
680 vm->m_area.add_y(em, i, 1);
682 // If dirt, grow grass on it.
683 if (y > water_level - 10 &&
684 vm->m_data[i].getContent() == CONTENT_AIR) {
685 vm->m_area.add_y(em, i, -1);
686 if (vm->m_data[i].getContent() == c_dirt)
687 vm->m_data[i] = MapNode(c_dirt_with_grass);
691 //////////////////// Now, add top nodes on top of the ridge
692 y = heightmap[index];
693 if (y > node_max.Y) {
694 y = node_max.Y; // Let's see if we can still go downward anyway
695 u32 vi = vm->m_area.index(x, y, z);
696 content_t c = vm->m_data[vi].getContent();
697 if (ndef->get(c).walkable)
701 i = vm->m_area.index(x, y, z);
702 for (; y >= node_min.Y; y--) {
703 content_t c = vm->m_data[i].getContent();
704 if (ndef->get(c).walkable)
706 vm->m_area.add_y(em, i, -1);
709 if (y != node_min.Y - 1) {
710 ntopnodes = biome->top_depth;
711 // Let's see if we've already added it...
712 if (y == ridge_heightmap[index] + ntopnodes - 1)
715 for (; y <= node_max.Y && ntopnodes; y++) {
717 vm->m_data[i] = MapNode(biome->c_top);
718 vm->m_area.add_y(em, i, 1);
720 // If dirt, grow grass on it.
721 if (y > water_level - 10 &&
722 vm->m_data[i].getContent() == CONTENT_AIR) {
723 vm->m_area.add_y(em, i, -1);
724 if (vm->m_data[i].getContent() == c_dirt)
725 vm->m_data[i] = MapNode(c_dirt_with_grass);
733 NoiseParams nparams_v7_def_cave(6, 6.0, v3f(250.0, 250.0, 250.0), 34329, 3, 0.50);
735 void MapgenV7::generateCaves(int max_stone_y) {
736 PseudoRandom ps(blockseed + 21343);
738 int volume_nodes = (node_max.X - node_min.X + 1) *
739 (node_max.Y - node_min.Y + 1) *
740 (node_max.Z - node_min.Z + 1);
741 float cave_amount = NoisePerlin2D(&nparams_v7_def_cave,
742 node_min.X, node_min.Y, seed);
744 u32 caves_count = MYMAX(0.0, cave_amount) * volume_nodes / 250000;
745 for (u32 i = 0; i < caves_count; i++) {
746 CaveV7 cave(this, &ps, false);
747 cave.makeCave(node_min, node_max, max_stone_y);
750 u32 bruises_count = (ps.range(1, 8) == 1) ? ps.range(0, ps.range(0, 2)) : 1;
751 for (u32 i = 0; i < bruises_count; i++) {
752 CaveV7 cave(this, &ps, true);
753 cave.makeCave(node_min, node_max, max_stone_y);