diff options
author | paramat <mat.gregory@virginmedia.com> | 2016-02-04 01:03:31 +0000 |
---|---|---|
committer | paramat <mat.gregory@virginmedia.com> | 2016-02-09 07:14:45 +0000 |
commit | 4adbd69a3701608876b50665ed3f7a150750d26e (patch) | |
tree | de3ec585173cbf4e480004c8d64c23489222677f /src/mapgen_fractal.cpp | |
parent | 38e712260046f159aa201259569054bdf9793b7f (diff) | |
download | minetest-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_fractal.cpp')
-rw-r--r-- | src/mapgen_fractal.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/mapgen_fractal.cpp b/src/mapgen_fractal.cpp index 9cb682a91..8a5c1e2bc 100644 --- a/src/mapgen_fractal.cpp +++ b/src/mapgen_fractal.cpp @@ -209,17 +209,28 @@ void MapgenFractalParams::writeParams(Settings *settings) const ///////////////////////////////////////////////////////////////// -int MapgenFractal::getGroundLevelAtPoint(v2s16 p) +int MapgenFractal::getSpawnLevelAtPoint(v2s16 p) { - s16 search_start = 128; - s16 search_end = -128; - - for (s16 y = search_start; y >= search_end; y--) { - if (getFractalAtPoint(p.X, y, p.Y)) - return y; + bool solid_below = false; // Dry solid node is present below to spawn on + u8 air_count = 0; // Consecutive air nodes above the dry solid node + s16 seabed_level = NoisePerlin2D(&noise_seabed->np, p.X, p.Y, seed); + // Seabed can rise above water_level or might be raised to create dry land + s16 search_start = MYMAX(seabed_level, water_level + 1); + if (seabed_level > water_level) + solid_below = true; + + for (s16 y = search_start; y <= search_start + 128; y++) { + if (getFractalAtPoint(p.X, y, p.Y)) { // Fractal node + solid_below = true; + air_count = 0; + } else if (solid_below) { // Air above solid node + air_count++; + if (air_count == 2) + return y - 2; + } } - return -MAX_MAP_GENERATION_LIMIT; + return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point } |