summaryrefslogtreecommitdiff
path: root/src/mapgen_v5.cpp
diff options
context:
space:
mode:
authorparamat <mat.gregory@virginmedia.com>2016-02-04 01:03:31 +0000
committerparamat <mat.gregory@virginmedia.com>2016-02-09 07:14:45 +0000
commit4adbd69a3701608876b50665ed3f7a150750d26e (patch)
treede3ec585173cbf4e480004c8d64c23489222677f /src/mapgen_v5.cpp
parent38e712260046f159aa201259569054bdf9793b7f (diff)
downloadminetest-4adbd69a3701608876b50665ed3f7a150750d26e.tar.gz
minetest-4adbd69a3701608876b50665ed3f7a150750d26e.tar.bz2
minetest-4adbd69a3701608876b50665ed3f7a150750d26e.zip
FindSpawnPos: Let mapgens decide what spawn altitude is suitable
To avoid spawn search failing in new specialised mapgens Increase spawn search range to 4000 nodes Add getSpawnLevelAtPoint() functions to EmergeManager, class Mapgen and all mapgens Remove getGroundLevelAtPoint() functions from all mapgens except mgv6 (possibly to be re-added later in the correct form to return actual ground level) Make mgvalleys flag names consistent with other mapgens Remove now unused 'vertical spawn range' setting
Diffstat (limited to 'src/mapgen_v5.cpp')
-rw-r--r--src/mapgen_v5.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/mapgen_v5.cpp b/src/mapgen_v5.cpp
index 06e5f1ca6..0bb3715a8 100644
--- a/src/mapgen_v5.cpp
+++ b/src/mapgen_v5.cpp
@@ -171,7 +171,7 @@ void MapgenV5Params::writeParams(Settings *settings) const
}
-int MapgenV5::getGroundLevelAtPoint(v2s16 p)
+int MapgenV5::getSpawnLevelAtPoint(v2s16 p)
{
//TimeTaker t("getGroundLevelAtPoint", NULL, PRECISION_MICRO);
@@ -182,24 +182,25 @@ int MapgenV5::getGroundLevelAtPoint(v2s16 p)
f *= 1.6;
float h = NoisePerlin2D(&noise_height->np, p.X, p.Y, seed);
- s16 search_start = 128; // Only bother searching this range, actual
- s16 search_end = -128; // ground level is rarely higher or lower.
-
- for (s16 y = search_start; y >= search_end; y--) {
+ for (s16 y = 128; y >= -128; y--) {
float n_ground = NoisePerlin3D(&noise_ground->np, p.X, y, p.Y, seed);
- // If solid
- if (n_ground * f > y - h) {
+
+ 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 no space for the player to spawn.
- if (y >= search_start - 1)
- return MAX_MAP_GENERATION_LIMIT;
- else
- return y; // Ground below at least 2 nodes of space
+ // mountain or floatland with possibly no space for the player to spawn.
+ if (y >= 127) {
+ 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;
+ }
}
}
//printf("getGroundLevelAtPoint: %dus\n", t.stop());
- return -MAX_MAP_GENERATION_LIMIT;
+ return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn position, no ground found
}