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.
This commit is contained in:
parent
33a606c034
commit
56ea77ea96
@ -154,17 +154,27 @@ int MapgenV7::getSpawnLevelAtPoint(v2s16 p)
|
|||||||
// Base terrain calculation
|
// Base terrain calculation
|
||||||
s16 y = baseTerrainLevelAtPoint(p.X, p.Y);
|
s16 y = baseTerrainLevelAtPoint(p.X, p.Y);
|
||||||
|
|
||||||
// Ridge/river terrain calculation
|
// If enabled, check if inside a river
|
||||||
float width = 0.2;
|
if (spflags & MGV7_RIDGES) {
|
||||||
float uwatern = NoisePerlin2D(&noise_ridge_uwater->np, p.X, p.Y, seed) * 2;
|
float width = 0.2;
|
||||||
// if inside a river this is an unsuitable spawn point
|
float uwatern = NoisePerlin2D(&noise_ridge_uwater->np, p.X, p.Y, seed) * 2;
|
||||||
if (fabs(uwatern) <= width)
|
if (fabs(uwatern) <= width)
|
||||||
return MAX_MAP_GENERATION_LIMIT;
|
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
|
// Mountain terrain calculation
|
||||||
int iters = 128;
|
int iters = 128;
|
||||||
while (iters--) {
|
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)
|
if (y <= water_level || y > water_level + 16)
|
||||||
return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
|
return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
|
||||||
else
|
else
|
||||||
@ -173,7 +183,7 @@ int MapgenV7::getSpawnLevelAtPoint(v2s16 p)
|
|||||||
y++;
|
y++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unsuitable spawn point, no ground surface found
|
// Unsuitable spawn point, no mountain surface found
|
||||||
return MAX_MAP_GENERATION_LIMIT;
|
return MAX_MAP_GENERATION_LIMIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user