diff --git a/Tools/Scripts/MapGenerator.cs b/Tools/Scripts/MapGenerator.cs index a281436..7f721b9 100644 --- a/Tools/Scripts/MapGenerator.cs +++ b/Tools/Scripts/MapGenerator.cs @@ -1010,12 +1010,20 @@ public partial class MapGenerator : TextureRect if (t < minTemp || t > maxTemp) continue; float centerH = _heightMap[rx, ry]; - // Sample slope a bit wider (10px) due to higher resolution + // Sample slope a bit wider (10px) due to higher resolution. + // Samples are clamped to map bounds (task 05): candidates spawn at + // [20, MapSize-20] but slopeRadius is 40 at 8K, so the unclamped reads + // were out of bounds near the border — previously unreachable only + // because border land stayed underwater and failed the sea test first. int slopeRadius = (int)(MapSize * 0.005f); // Automatically scales! - if (Mathf.Abs(_heightMap[rx+slopeRadius, ry] - centerH) > maxSlope) continue; - if (Mathf.Abs(_heightMap[rx-slopeRadius, ry] - centerH) > maxSlope) continue; - if (Mathf.Abs(_heightMap[rx, ry+slopeRadius] - centerH) > maxSlope) continue; - if (Mathf.Abs(_heightMap[rx, ry-slopeRadius] - centerH) > maxSlope) continue; + int sxHi = Mathf.Clamp(rx + slopeRadius, 0, MapSize - 1); + int sxLo = Mathf.Clamp(rx - slopeRadius, 0, MapSize - 1); + int syHi = Mathf.Clamp(ry + slopeRadius, 0, MapSize - 1); + int syLo = Mathf.Clamp(ry - slopeRadius, 0, MapSize - 1); + if (Mathf.Abs(_heightMap[sxHi, ry] - centerH) > maxSlope) continue; + if (Mathf.Abs(_heightMap[sxLo, ry] - centerH) > maxSlope) continue; + if (Mathf.Abs(_heightMap[rx, syHi] - centerH) > maxSlope) continue; + if (Mathf.Abs(_heightMap[rx, syLo] - centerH) > maxSlope) continue; bool nearTrueOcean = false; bool nearAnyWater = false;