aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorparamat <paramat@users.noreply.github.com>2017-08-09 14:23:30 +0100
committerrubenwardy <rubenwardy@gmail.com>2017-08-12 19:37:53 +0100
commit3aab517775d1095f9f24c17b6e880dffd372e3ef (patch)
treed337a91037c445dbafdff2da8d5353b62e16730d
parentbb1c71158613c1f17c57e53ad489b076a11e3828 (diff)
downloadminetest-3aab517775d1095f9f24c17b6e880dffd372e3ef.tar.gz
minetest-3aab517775d1095f9f24c17b6e880dffd372e3ef.tar.bz2
minetest-3aab517775d1095f9f24c17b6e880dffd372e3ef.zip
Mgv5: Make spawn position search more reliable
-rw-r--r--src/mapgen_v5.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/mapgen_v5.cpp b/src/mapgen_v5.cpp
index faca0e16a..2cfb065f9 100644
--- a/src/mapgen_v5.cpp
+++ b/src/mapgen_v5.cpp
@@ -134,7 +134,6 @@ void MapgenV5Params::writeParams(Settings *settings) const
int MapgenV5::getSpawnLevelAtPoint(v2s16 p)
{
- //TimeTaker t("getGroundLevelAtPoint", NULL, PRECISION_MICRO);
float f = 0.55 + NoisePerlin2D(&noise_factor->np, p.X, p.Y, seed);
if (f < 0.01)
@@ -143,25 +142,27 @@ int MapgenV5::getSpawnLevelAtPoint(v2s16 p)
f *= 1.6;
float h = NoisePerlin2D(&noise_height->np, p.X, p.Y, seed);
- for (s16 y = 128; y >= -128; y--) {
+ // noise_height 'offset' is the average level of terrain. At least 50% of
+ // terrain will be below this.
+ // Raising the maximum spawn level above 'water_level + 16' is necessary
+ // for when noise_height 'offset' is set much higher than water_level.
+ s16 max_spawn_y = MYMAX(noise_height->np.offset, water_level + 16);
+
+ // Starting spawn search at max_spawn_y + 128 ensures 128 nodes of open
+ // space above spawn position. Avoids spawning in possibly sealed voids.
+ for (s16 y = max_spawn_y + 128; y >= water_level; y--) {
float n_ground = NoisePerlin3D(&noise_ground->np, p.X, y, p.Y, seed);
if (n_ground * f > y - h) { // If solid
- // If either top 2 nodes of search are solid this is inside a
- // mountain or floatland with possibly no space for the player to spawn.
- if (y >= 127) {
+ if (y < water_level || y > max_spawn_y)
return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
- } else { // Ground below at least 2 nodes of empty space
- if (y <= water_level || y > water_level + 16)
- return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
- else
- return y;
- }
+ else
+ // y + 2 because y is surface and due to biome 'dust' nodes.
+ return y + 2;
}
}
-
- //printf("getGroundLevelAtPoint: %dus\n", t.stop());
- return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn position, no ground found
+ // Unsuitable spawn position, no ground found
+ return MAX_MAP_GENERATION_LIMIT;
}