fix: clamp town slope-check sampling to map bounds (terrain-water task 05)

PlaceTownNodes read _heightMap[rx ± slopeRadius] unclamped; candidates
spawn at [20, MapSize-20] but slopeRadius is 40 at 8K, so border
candidates indexed out of bounds. Never fired only because border land
stayed underwater and failed the above-sea test first — the
redistribution curve's flat coastal toe arms exactly that path
(D-033 consequence (b), recorded in sweep 01 and task 04).
Behavior-preserving except where it would have crashed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Stewart Howe 2026-08-07 15:20:16 -04:00
parent e435843e9a
commit 9e55324668

View file

@ -1010,12 +1010,20 @@ public partial class MapGenerator : TextureRect
if (t < minTemp || t > maxTemp) continue; if (t < minTemp || t > maxTemp) continue;
float centerH = _heightMap[rx, ry]; 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! int slopeRadius = (int)(MapSize * 0.005f); // Automatically scales!
if (Mathf.Abs(_heightMap[rx+slopeRadius, ry] - centerH) > maxSlope) continue; int sxHi = Mathf.Clamp(rx + slopeRadius, 0, MapSize - 1);
if (Mathf.Abs(_heightMap[rx-slopeRadius, ry] - centerH) > maxSlope) continue; int sxLo = Mathf.Clamp(rx - slopeRadius, 0, MapSize - 1);
if (Mathf.Abs(_heightMap[rx, ry+slopeRadius] - centerH) > maxSlope) continue; int syHi = Mathf.Clamp(ry + slopeRadius, 0, MapSize - 1);
if (Mathf.Abs(_heightMap[rx, ry-slopeRadius] - centerH) > maxSlope) continue; 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 nearTrueOcean = false;
bool nearAnyWater = false; bool nearAnyWater = false;