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 : Mapgen(mapgenid, params, emerge)
55 this->m_emerge = emerge;
56 this->bmgr = emerge->biomemgr;
58 //// amount of elements to skip for the next index
59 //// for noise/height/biome maps (not vmanip)
60 this->ystride = csize.X;
61 this->zstride = csize.X * csize.Y;
63 this->biomemap = new u8[csize.X * csize.Z];
64 this->heightmap = new s16[csize.X * csize.Z];
65 this->ridge_heightmap = new s16[csize.X * csize.Z];
67 MapgenV7Params *sp = (MapgenV7Params *)params->sparams;
68 this->spflags = sp->spflags;
71 noise_terrain_base = new Noise(&sp->np_terrain_base, seed, csize.X, csize.Z);
72 noise_terrain_alt = new Noise(&sp->np_terrain_alt, seed, csize.X, csize.Z);
73 noise_terrain_persist = new Noise(&sp->np_terrain_persist, seed, csize.X, csize.Z);
74 noise_height_select = new Noise(&sp->np_height_select, seed, csize.X, csize.Z);
75 noise_filler_depth = new Noise(&sp->np_filler_depth, seed, csize.X, csize.Z);
76 noise_mount_height = new Noise(&sp->np_mount_height, seed, csize.X, csize.Z);
77 noise_ridge_uwater = new Noise(&sp->np_ridge_uwater, seed, csize.X, csize.Z);
80 noise_mountain = new Noise(&sp->np_mountain, seed, csize.X, csize.Y, csize.Z);
81 noise_ridge = new Noise(&sp->np_ridge, seed, csize.X, csize.Y, csize.Z);
82 noise_cave1 = new Noise(&sp->np_cave1, seed, csize.X, csize.Y, csize.Z);
83 noise_cave2 = new Noise(&sp->np_cave2, seed, csize.X, csize.Y, csize.Z);
86 noise_heat = new Noise(¶ms->np_biome_heat, seed, csize.X, csize.Z);
87 noise_humidity = new Noise(¶ms->np_biome_humidity, seed, csize.X, csize.Z);
89 //// Resolve nodes to be used
90 INodeDefManager *ndef = emerge->ndef;
92 c_stone = ndef->getId("mapgen_stone");
93 c_dirt = ndef->getId("mapgen_dirt");
94 c_dirt_with_grass = ndef->getId("mapgen_dirt_with_grass");
95 c_sand = ndef->getId("mapgen_sand");
96 c_water_source = ndef->getId("mapgen_water_source");
97 c_lava_source = ndef->getId("mapgen_lava_source");
98 c_ice = ndef->getId("default:ice");
99 if (c_ice == CONTENT_IGNORE)
104 MapgenV7::~MapgenV7()
106 delete noise_terrain_base;
107 delete noise_terrain_persist;
108 delete noise_height_select;
109 delete noise_terrain_alt;
110 delete noise_filler_depth;
111 delete noise_mount_height;
112 delete noise_ridge_uwater;
113 delete noise_mountain;
119 delete noise_humidity;
121 delete[] ridge_heightmap;
127 MapgenV7Params::MapgenV7Params()
129 spflags = MGV7_MOUNTAINS | MGV7_RIDGES;
131 np_terrain_base = NoiseParams(4, 70, v3f(300, 300, 300), 82341, 6, 0.7, 2.0);
132 np_terrain_alt = NoiseParams(4, 25, v3f(600, 600, 600), 5934, 5, 0.6, 2.0);
133 np_terrain_persist = NoiseParams(0.6, 0.1, v3f(500, 500, 500), 539, 3, 0.6, 2.0);
134 np_height_select = NoiseParams(-0.5, 1, v3f(250, 250, 250), 4213, 5, 0.69, 2.0);
135 np_filler_depth = NoiseParams(0, 1.2, v3f(150, 150, 150), 261, 4, 0.7, 2.0);
136 np_mount_height = NoiseParams(100, 30, v3f(500, 500, 500), 72449, 4, 0.6, 2.0);
137 np_ridge_uwater = NoiseParams(0, 1, v3f(500, 500, 500), 85039, 4, 0.6, 2.0);
138 np_mountain = NoiseParams(0, 1, v3f(250, 350, 250), 5333, 5, 0.68, 2.0);
139 np_ridge = NoiseParams(0, 1, v3f(100, 100, 100), 6467, 4, 0.75, 2.0);
140 np_cave1 = NoiseParams(0, 12, v3f(100, 100, 100), 52534, 4, 0.5, 2.0);
141 np_cave2 = NoiseParams(0, 12, v3f(100, 100, 100), 10325, 4, 0.5, 2.0);
145 void MapgenV7Params::readParams(Settings *settings)
147 settings->getFlagStrNoEx("mgv7_spflags", spflags, flagdesc_mapgen_v7);
149 settings->getNoiseParams("mgv7_np_terrain_base", np_terrain_base);
150 settings->getNoiseParams("mgv7_np_terrain_alt", np_terrain_alt);
151 settings->getNoiseParams("mgv7_np_terrain_persist", np_terrain_persist);
152 settings->getNoiseParams("mgv7_np_height_select", np_height_select);
153 settings->getNoiseParams("mgv7_np_filler_depth", np_filler_depth);
154 settings->getNoiseParams("mgv7_np_mount_height", np_mount_height);
155 settings->getNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater);
156 settings->getNoiseParams("mgv7_np_mountain", np_mountain);
157 settings->getNoiseParams("mgv7_np_ridge", np_ridge);
158 settings->getNoiseParams("mgv7_np_cave1", np_cave1);
159 settings->getNoiseParams("mgv7_np_cave2", np_cave2);
163 void MapgenV7Params::writeParams(Settings *settings)
165 settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7, (u32)-1);
167 settings->setNoiseParams("mgv7_np_terrain_base", np_terrain_base);
168 settings->setNoiseParams("mgv7_np_terrain_alt", np_terrain_alt);
169 settings->setNoiseParams("mgv7_np_terrain_persist", np_terrain_persist);
170 settings->setNoiseParams("mgv7_np_height_select", np_height_select);
171 settings->setNoiseParams("mgv7_np_filler_depth", np_filler_depth);
172 settings->setNoiseParams("mgv7_np_mount_height", np_mount_height);
173 settings->setNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater);
174 settings->setNoiseParams("mgv7_np_mountain", np_mountain);
175 settings->setNoiseParams("mgv7_np_ridge", np_ridge);
176 settings->setNoiseParams("mgv7_np_cave1", np_cave1);
177 settings->setNoiseParams("mgv7_np_cave2", np_cave2);
181 ///////////////////////////////////////
184 int MapgenV7::getGroundLevelAtPoint(v2s16 p)
186 // Base terrain calculation
187 s16 y = baseTerrainLevelAtPoint(p.X, p.Y);
189 // Ridge/river terrain calculation
191 float uwatern = NoisePerlin2D(&noise_ridge_uwater->np, p.X, p.Y, seed) * 2;
192 // actually computing the depth of the ridge is much more expensive;
193 // if inside a river, simply guess
194 if (uwatern >= -width && uwatern <= width)
195 return water_level - 10;
197 // Mountain terrain calculation
198 int iters = 128; // don't even bother iterating more than 128 times..
200 //current point would have been air
201 if (!getMountainTerrainAtPoint(p.X, y, p.Y))
211 void MapgenV7::makeChunk(BlockMakeData *data)
213 assert(data->vmanip);
214 assert(data->nodedef);
215 assert(data->blockpos_requested.X >= data->blockpos_min.X &&
216 data->blockpos_requested.Y >= data->blockpos_min.Y &&
217 data->blockpos_requested.Z >= data->blockpos_min.Z);
218 assert(data->blockpos_requested.X <= data->blockpos_max.X &&
219 data->blockpos_requested.Y <= data->blockpos_max.Y &&
220 data->blockpos_requested.Z <= data->blockpos_max.Z);
222 this->generating = true;
223 this->vm = data->vmanip;
224 this->ndef = data->nodedef;
225 //TimeTaker t("makeChunk");
227 v3s16 blockpos_min = data->blockpos_min;
228 v3s16 blockpos_max = data->blockpos_max;
229 node_min = blockpos_min * MAP_BLOCKSIZE;
230 node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
231 full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
232 full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
234 blockseed = getBlockSeed2(full_node_min, seed);
239 // Generate base terrain, mountains, and ridges with initial heightmaps
240 s16 stone_surface_max_y = generateTerrain();
242 updateHeightmap(node_min, node_max);
245 bmgr->calcBiomes(csize.X, csize.Z, noise_heat->result,
246 noise_humidity->result, heightmap, biomemap);
248 // Actually place the biome-specific nodes and what not
251 if (flags & MG_CAVES)
252 generateCaves(stone_surface_max_y);
254 if ((flags & MG_DUNGEONS) && (stone_surface_max_y >= node_min.Y)) {
255 DungeonGen dgen(this, NULL);
256 dgen.generate(blockseed, full_node_min, full_node_max);
259 // Generate the registered decorations
260 m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);
262 // Generate the registered ores
263 m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
265 // Sprinkle some dust on top after everything else was generated
268 //printf("makeChunk: %dms\n", t.stop());
270 updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
272 if (flags & MG_LIGHT)
273 calcLighting(node_min, node_max);
274 //setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
275 // node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);
277 this->generating = false;
281 void MapgenV7::calculateNoise()
283 //TimeTaker t("calculateNoise", NULL, PRECISION_MICRO);
288 noise_terrain_persist->perlinMap2D(x, z);
289 float *persistmap = noise_terrain_persist->result;
291 noise_terrain_base->perlinMap2D(x, z, persistmap);
292 noise_terrain_alt->perlinMap2D(x, z, persistmap);
293 noise_height_select->perlinMap2D(x, z);
295 if (flags & MG_CAVES) {
296 noise_cave1->perlinMap3D(x, y, z);
297 noise_cave2->perlinMap3D(x, y, z);
300 if (node_max.Y >= water_level) {
301 noise_filler_depth->perlinMap2D(x, z);
302 noise_heat->perlinMap2D(x, z);
303 noise_humidity->perlinMap2D(x, z);
305 if (spflags & MGV7_MOUNTAINS) {
306 noise_mountain->perlinMap3D(x, y, z);
307 noise_mount_height->perlinMap2D(x, z);
310 if (spflags & MGV7_RIDGES) {
311 noise_ridge->perlinMap3D(x, y, z);
312 noise_ridge_uwater->perlinMap2D(x, z);
316 //printf("calculateNoise: %dus\n", t.stop());
320 Biome *MapgenV7::getBiomeAtPoint(v3s16 p)
322 float heat = NoisePerlin2D(&noise_heat->np, p.X, p.Z, seed);
323 float humidity = NoisePerlin2D(&noise_humidity->np, p.X, p.Z, seed);
324 s16 groundlevel = baseTerrainLevelAtPoint(p.X, p.Z);
326 return bmgr->getBiome(heat, humidity, groundlevel);
329 //needs to be updated
330 float MapgenV7::baseTerrainLevelAtPoint(int x, int z)
332 float hselect = NoisePerlin2D(&noise_height_select->np, x, z, seed);
333 hselect = rangelim(hselect, 0.0, 1.0);
335 float persist = NoisePerlin2D(&noise_terrain_persist->np, x, z, seed);
336 persist = rangelim(persist, 0.4, 0.9);
338 noise_terrain_base->np.persist = persist;
339 float height_base = NoisePerlin2D(&noise_terrain_base->np, x, z, seed);
341 noise_terrain_alt->np.persist = persist;
342 float height_alt = NoisePerlin2D(&noise_terrain_alt->np, x, z, seed);
344 if (height_alt > height_base)
347 return (height_base * hselect) + (height_alt * (1.0 - hselect));
351 float MapgenV7::baseTerrainLevelFromMap(int index)
353 float hselect = rangelim(noise_height_select->result[index], 0.0, 1.0);
354 float height_base = noise_terrain_base->result[index];
355 float height_alt = noise_terrain_alt->result[index];
357 if (height_alt > height_base)
360 return (height_base * hselect) + (height_alt * (1.0 - hselect));
364 bool MapgenV7::getMountainTerrainAtPoint(int x, int y, int z)
366 float mnt_h_n = NoisePerlin2D(&noise_mount_height->np, x, z, seed);
367 float height_modifier = -((float)y / mnt_h_n);
368 float mnt_n = NoisePerlin3D(&noise_mountain->np, x, y, z, seed);
370 return mnt_n + height_modifier >= 0.6;
374 bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, int y)
376 float mounthn = noise_mount_height->result[idx_xz];
377 float height_modifier = -((float)y / mounthn);
378 return (noise_mountain->result[idx_xyz] + height_modifier >= 0.6);
383 void MapgenV7::carveRivers() {
384 MapNode n_air(CONTENT_AIR), n_water_source(c_water_source);
385 MapNode n_stone(c_stone);
390 for (s16 z = node_min.Z; z <= node_max.Z; z++)
391 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
392 float terrain_mod = noise_terrain_mod->result[index];
393 NoiseParams *np = noise_terrain_river->np;
394 np.persist = noise_terrain_persist->result[index];
395 float terrain_river = NoisePerlin2DNoTxfm(np, x, z, seed);
396 float height = terrain_river * (1 - abs(terrain_mod)) *
397 noise_terrain_river->np.scale;
398 height = log(height * height); //log(h^3) is pretty interesting for terrain
400 s16 y = heightmap[index];
401 if (height < 1.0 && y > river_depth &&
402 y - river_depth >= node_min.Y && y <= node_max.Y) {
404 for (s16 ry = y; ry != y - river_depth; ry--) {
405 u32 vi = vm->m_area.index(x, ry, z);
406 vm->m_data[vi] = n_air;
409 u32 vi = vm->m_area.index(x, y - river_depth, z);
410 vm->m_data[vi] = n_water_source;
417 int MapgenV7::generateTerrain()
419 int ymax = generateBaseTerrain();
421 if (spflags & MGV7_MOUNTAINS)
422 ymax = generateMountainTerrain(ymax);
424 if (spflags & MGV7_RIDGES)
425 generateRidgeTerrain();
431 int MapgenV7::generateBaseTerrain()
433 MapNode n_air(CONTENT_AIR);
434 MapNode n_stone(c_stone);
435 MapNode n_water(c_water_source);
437 int stone_surface_max_y = -MAP_GENERATION_LIMIT;
438 v3s16 em = vm->m_area.getExtent();
441 for (s16 z = node_min.Z; z <= node_max.Z; z++)
442 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
443 float surface_height = baseTerrainLevelFromMap(index);
444 s16 surface_y = (s16)surface_height;
446 heightmap[index] = surface_y;
447 ridge_heightmap[index] = surface_y;
449 if (surface_y > stone_surface_max_y)
450 stone_surface_max_y = surface_y;
452 u32 i = vm->m_area.index(x, node_min.Y, z);
453 for (s16 y = node_min.Y; y <= node_max.Y; y++) {
454 if (vm->m_data[i].getContent() == CONTENT_IGNORE) {
456 vm->m_data[i] = n_stone;
457 else if (y <= water_level)
458 vm->m_data[i] = n_water;
460 vm->m_data[i] = n_air;
462 vm->m_area.add_y(em, i, 1);
466 return stone_surface_max_y;
470 int MapgenV7::generateMountainTerrain(int ymax)
472 if (node_max.Y < water_level)
475 MapNode n_stone(c_stone);
478 for (s16 z = node_min.Z; z <= node_max.Z; z++)
479 for (s16 y = node_min.Y; y <= node_max.Y; y++) {
480 u32 vi = vm->m_area.index(node_min.X, y, z);
481 for (s16 x = node_min.X; x <= node_max.X; x++) {
482 int index = (z - node_min.Z) * csize.X + (x - node_min.X);
483 content_t c = vm->m_data[vi].getContent();
485 if (getMountainTerrainFromMap(j, index, y)
486 && (c == CONTENT_AIR || c == c_water_source)) {
487 vm->m_data[vi] = n_stone;
501 void MapgenV7::generateRidgeTerrain()
503 if (node_max.Y < water_level)
506 MapNode n_water(c_water_source);
507 MapNode n_air(CONTENT_AIR);
510 for (s16 z = node_min.Z; z <= node_max.Z; z++)
511 for (s16 y = node_min.Y; y <= node_max.Y; y++) {
512 u32 vi = vm->m_area.index(node_min.X, y, z);
513 for (s16 x = node_min.X; x <= node_max.X; x++, index++, vi++) {
514 int j = (z - node_min.Z) * csize.X + (x - node_min.X);
516 if (heightmap[j] < water_level - 16)
519 float width = 0.2; // TODO: figure out acceptable perlin noise values
520 float uwatern = noise_ridge_uwater->result[j] * 2;
521 if (fabs(uwatern) > width)
524 float altitude = y - water_level;
525 float height_mod = (altitude + 17) / 2.5;
526 float width_mod = width - fabs(uwatern);
527 float nridge = noise_ridge->result[index] * MYMAX(altitude, 0) / 7.0;
529 if (nridge + width_mod * height_mod < 0.6)
532 if (y < ridge_heightmap[j])
533 ridge_heightmap[j] = y - 1;
535 vm->m_data[vi] = (y > water_level) ? n_air : n_water;
541 void MapgenV7::generateBiomes()
543 if (node_max.Y < water_level)
546 MapNode n_air(CONTENT_AIR);
547 MapNode n_stone(c_stone);
548 MapNode n_water(c_water_source);
550 v3s16 em = vm->m_area.getExtent();
553 for (s16 z = node_min.Z; z <= node_max.Z; z++)
554 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
555 Biome *biome = (Biome *)bmgr->get(biomemap[index]);
556 s16 dfiller = biome->depth_filler + noise_filler_depth->result[index];
557 s16 y0_top = biome->depth_top;
558 s16 y0_filler = biome->depth_top + dfiller;
559 s16 shore_max = water_level + biome->height_shore;
560 s16 depth_water_top = biome->depth_water_top;
563 u32 i = vm->m_area.index(x, node_max.Y, z);
565 content_t c_above = vm->m_data[i + em.X].getContent();
566 bool have_air = c_above == CONTENT_AIR;
568 for (s16 y = node_max.Y; y >= node_min.Y; y--) {
569 content_t c = vm->m_data[i].getContent();
571 // It could be the case that the elevation is equal to the chunk
572 // boundary, but the chunk above has not been generated yet
573 if (y == node_max.Y && c_above == CONTENT_IGNORE &&
574 y == heightmap[index] && c == c_stone) {
575 int j = (z - node_min.Z) * zstride +
576 (y - node_min.Y) * ystride +
578 have_air = !getMountainTerrainFromMap(j, index, y);
581 if (c == c_stone && have_air) {
582 content_t c_below = vm->m_data[i - em.X].getContent();
584 if (c_below != CONTENT_AIR) {
585 if (nplaced < y0_top) {
587 vm->m_data[i] = MapNode(biome->c_underwater);
588 else if(y <= shore_max)
589 vm->m_data[i] = MapNode(biome->c_shore_top);
591 vm->m_data[i] = MapNode(biome->c_top);
593 } else if (nplaced < y0_filler && nplaced >= y0_top) {
595 vm->m_data[i] = MapNode(biome->c_underwater);
596 else if(y <= shore_max)
597 vm->m_data[i] = MapNode(biome->c_shore_filler);
599 vm->m_data[i] = MapNode(biome->c_filler);
601 } else if (c == c_stone) {
604 vm->m_data[i] = MapNode(biome->c_stone);
609 } else if (c == c_stone) {
612 vm->m_data[i] = MapNode(biome->c_stone);
614 } else if (c == c_stone) {
617 vm->m_data[i] = MapNode(biome->c_stone);
618 } else if (c == c_water_source) {
621 if(y > water_level - depth_water_top)
622 vm->m_data[i] = MapNode(biome->c_water_top);
624 vm->m_data[i] = MapNode(biome->c_water);
625 } else if (c == CONTENT_AIR) {
630 vm->m_area.add_y(em, i, -1);
636 void MapgenV7::dustTopNodes()
638 if (node_max.Y < water_level)
641 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 = (Biome *)bmgr->get(biomemap[index]);
648 if (biome->c_dust == CONTENT_IGNORE)
652 u32 vi = vm->m_area.index(x, y, z);
653 for (; y >= node_min.Y; y--) {
654 if (vm->m_data[vi].getContent() != CONTENT_AIR)
657 vm->m_area.add_y(em, vi, -1);
660 content_t c = vm->m_data[vi].getContent();
661 if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE) {
665 vm->m_area.add_y(em, vi, 1);
666 vm->m_data[vi] = MapNode(biome->c_dust);
673 void MapgenV7::addTopNodes()
675 v3s16 em = vm->m_area.getExtent();
679 for (s16 z = node_min.Z; z <= node_max.Z; z++)
680 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
681 Biome *biome = bmgr->biomes[biomemap[index]];
683 //////////////////// First, add top nodes below the ridge
684 s16 y = ridge_heightmap[index];
686 // This cutoff is good enough, but not perfect.
687 // It will cut off potentially placed top nodes at chunk boundaries
690 if (y > node_max.Y) {
691 y = node_max.Y; // Let's see if we can still go downward anyway
692 u32 vi = vm->m_area.index(x, y, z);
693 content_t c = vm->m_data[vi].getContent();
694 if (ndef->get(c).walkable)
698 // N.B. It is necessary to search downward since ridge_heightmap[i]
699 // might not be the actual height, just the lowest part in the chunk
700 // where a ridge had been carved
701 u32 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 && y >= water_level) {
710 ridge_heightmap[index] = y; //update ridgeheight
711 ntopnodes = biome->top_depth;
712 for (; y <= node_max.Y && ntopnodes; y++) {
714 vm->m_data[i] = MapNode(biome->c_top);
715 vm->m_area.add_y(em, i, 1);
717 // If dirt, grow grass on it.
718 if (y > water_level - 10 &&
719 vm->m_data[i].getContent() == CONTENT_AIR) {
720 vm->m_area.add_y(em, i, -1);
721 if (vm->m_data[i].getContent() == c_dirt)
722 vm->m_data[i] = MapNode(c_dirt_with_grass);
726 //////////////////// Now, add top nodes on top of the ridge
727 y = heightmap[index];
728 if (y > node_max.Y) {
729 y = node_max.Y; // Let's see if we can still go downward anyway
730 u32 vi = vm->m_area.index(x, y, z);
731 content_t c = vm->m_data[vi].getContent();
732 if (ndef->get(c).walkable)
736 i = vm->m_area.index(x, y, z);
737 for (; y >= node_min.Y; y--) {
738 content_t c = vm->m_data[i].getContent();
739 if (ndef->get(c).walkable)
741 vm->m_area.add_y(em, i, -1);
744 if (y != node_min.Y - 1) {
745 ntopnodes = biome->top_depth;
746 // Let's see if we've already added it...
747 if (y == ridge_heightmap[index] + ntopnodes - 1)
750 for (; y <= node_max.Y && ntopnodes; y++) {
752 vm->m_data[i] = MapNode(biome->c_top);
753 vm->m_area.add_y(em, i, 1);
755 // If dirt, grow grass on it.
756 if (y > water_level - 10 &&
757 vm->m_data[i].getContent() == CONTENT_AIR) {
758 vm->m_area.add_y(em, i, -1);
759 if (vm->m_data[i].getContent() == c_dirt)
760 vm->m_data[i] = MapNode(c_dirt_with_grass);
768 void MapgenV7::generateCaves(int max_stone_y)
770 if (max_stone_y >= node_min.Y) {
774 for (s16 z = node_min.Z; z <= node_max.Z; z++) {
775 for (s16 y = node_min.Y; y <= node_max.Y; y++) {
776 u32 i = vm->m_area.index(node_min.X, y, z);
777 for (s16 x = node_min.X; x <= node_max.X;
778 x++, i++, index++, index2d++) {
779 Biome *biome = (Biome *)bmgr->get(biomemap[index2d]);
780 content_t c = vm->m_data[i].getContent();
781 if (c == CONTENT_AIR || (y <= water_level &&
782 c != biome->c_stone && c != c_stone))
785 float d1 = contour(noise_cave1->result[index]);
786 float d2 = contour(noise_cave2->result[index]);
788 vm->m_data[i] = MapNode(CONTENT_AIR);
796 PseudoRandom ps(blockseed + 21343);
797 u32 bruises_count = (ps.range(1, 6) == 1) ? ps.range(1, 2) : 0;
798 for (u32 i = 0; i < bruises_count; i++) {
799 CaveV7 cave(this, &ps, true);
800 cave.makeCave(node_min, node_max, max_stone_y);