summaryrefslogtreecommitdiff
path: root/src/mapgen_v7.cpp
diff options
context:
space:
mode:
authorparamat <mat.gregory@virginmedia.com>2016-09-26 23:21:33 +0100
committerparamat <mat.gregory@virginmedia.com>2016-09-30 18:56:39 +0100
commit56ea77ea96b62059c03ba53c15da56c72ea7e140 (patch)
tree093d8427da24e6cee15096272274271241fdb6d2 /src/mapgen_v7.cpp
parent33a606c034a6dfea4a011b6d69077455bbb56746 (diff)
downloadminetest-56ea77ea96b62059c03ba53c15da56c72ea7e140.tar.gz
minetest-56ea77ea96b62059c03ba53c15da56c72ea7e140.tar.bz2
minetest-56ea77ea96b62059c03ba53c15da56c72ea7e140.zip
Mgv7: Avoid mid-air spawn on disabled mountain terrain, optimise function
'getSpawnLevelAtPoint()' did not account for disabled mountains, it was possible to be spawned in mid-air where a mountain surface would have been. Avoid check for river area if rivers are disabled.
Diffstat (limited to 'src/mapgen_v7.cpp')
-rw-r--r--src/mapgen_v7.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/mapgen_v7.cpp b/src/mapgen_v7.cpp
index d14fdb97a..86f559af3 100644
--- a/src/mapgen_v7.cpp
+++ b/src/mapgen_v7.cpp
@@ -154,17 +154,27 @@ int MapgenV7::getSpawnLevelAtPoint(v2s16 p)
// Base terrain calculation
s16 y = baseTerrainLevelAtPoint(p.X, p.Y);
- // Ridge/river terrain calculation
- float width = 0.2;
- float uwatern = NoisePerlin2D(&noise_ridge_uwater->np, p.X, p.Y, seed) * 2;
- // if inside a river this is an unsuitable spawn point
- if (fabs(uwatern) <= width)
- return MAX_MAP_GENERATION_LIMIT;
+ // If enabled, check if inside a river
+ if (spflags & MGV7_RIDGES) {
+ float width = 0.2;
+ float uwatern = NoisePerlin2D(&noise_ridge_uwater->np, p.X, p.Y, seed) * 2;
+ if (fabs(uwatern) <= width)
+ return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
+ }
+
+ // If mountains are disabled, terrain level is base terrain level
+ // Avoids spawn on non-existant mountain terrain
+ if (!(spflags & MGV7_MOUNTAINS)) {
+ if (y <= water_level || y > water_level + 16)
+ return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
+ else
+ return y;
+ }
// Mountain terrain calculation
int iters = 128;
while (iters--) {
- if (!getMountainTerrainAtPoint(p.X, y + 1, p.Y)) { // Air, y is ground level
+ if (!getMountainTerrainAtPoint(p.X, y + 1, p.Y)) { // If air above
if (y <= water_level || y > water_level + 16)
return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
else
@@ -173,7 +183,7 @@ int MapgenV7::getSpawnLevelAtPoint(v2s16 p)
y++;
}
- // Unsuitable spawn point, no ground surface found
+ // Unsuitable spawn point, no mountain surface found
return MAX_MAP_GENERATION_LIMIT;
}