diff options
author | Paramat <paramat@users.noreply.github.com> | 2019-08-06 02:30:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-06 02:30:28 +0100 |
commit | 8da35c22d1c8933090330b2f3c44b4cf2c6e6760 (patch) | |
tree | ff9ddd97d7cfd08c34603c7c13c4065934869396 | |
parent | ac856b20bfc438ad05cda7649d68155f8b73462b (diff) | |
download | minetest-8da35c22d1c8933090330b2f3c44b4cf2c6e6760.tar.gz minetest-8da35c22d1c8933090330b2f3c44b4cf2c6e6760.tar.bz2 minetest-8da35c22d1c8933090330b2f3c44b4cf2c6e6760.zip |
Mapgen Flat: Fix and improve getSpawnLevelAtPoint() (#8756)
Previously, this wrongly returned ground level (a position containing
a solid node) as spawn level.
Return ground level + 2 (+ 2 to spawn above biome 'dust' nodes).
Improve codestyle and make more consistent with generateTerrain().
-rw-r--r-- | src/mapgen/mapgen_flat.cpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/mapgen/mapgen_flat.cpp b/src/mapgen/mapgen_flat.cpp index d859fa973..773b7b10f 100644 --- a/src/mapgen/mapgen_flat.cpp +++ b/src/mapgen/mapgen_flat.cpp @@ -143,26 +143,31 @@ void MapgenFlatParams::writeParams(Settings *settings) const int MapgenFlat::getSpawnLevelAtPoint(v2s16 p) { - s16 level_at_point = ground_level; - float n_terrain = 0.0f; - if ((spflags & MGFLAT_LAKES) || (spflags & MGFLAT_HILLS)) - n_terrain = NoisePerlin2D(&noise_terrain->np, p.X, p.Y, seed); + s16 stone_level = ground_level; + float n_terrain = + ((spflags & MGFLAT_LAKES) || (spflags & MGFLAT_HILLS)) ? + NoisePerlin2D(&noise_terrain->np, p.X, p.Y, seed) : + 0.0f; if ((spflags & MGFLAT_LAKES) && n_terrain < lake_threshold) { - level_at_point = ground_level - - (lake_threshold - n_terrain) * lake_steepness; + s16 depress = (lake_threshold - n_terrain) * lake_steepness; + stone_level = ground_level - depress; } else if ((spflags & MGFLAT_HILLS) && n_terrain > hill_threshold) { - level_at_point = ground_level + - (n_terrain - hill_threshold) * hill_steepness; + s16 rise = (n_terrain - hill_threshold) * hill_steepness; + stone_level = ground_level + rise; } - if (ground_level < water_level) // Ocean world, allow spawn in water - return MYMAX(level_at_point, water_level); + if (ground_level < water_level) + // Ocean world, may not have islands so allow spawn in water + return MYMAX(stone_level + 2, water_level); - if (level_at_point > water_level) - return level_at_point; // Spawn on land + if (stone_level >= water_level) + // Spawn on land + // + 2 not + 1, to spawn above biome 'dust' nodes + return stone_level + 2; - return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point + // Unsuitable spawn point + return MAX_MAP_GENERATION_LIMIT; } |