TerrainField: exact footprint check keeps cover pads flat while allowing mid-arena dunes

This commit is contained in:
Meta Vens 2026-12-04 14:00:13 +01:00
commit 9c4c68d431

View file

@ -136,21 +136,17 @@ namespace RustToDust.Core
Dynamic: false)); Dynamic: false));
} }
// 3. Sweeping desert dune ridges (~20 ridges + 2 dry-wash troughs), kept clear of cover boxes & center plaza // 3. Sweeping desert dune ridges (~20 ridges + 2 dry-wash troughs), kept clear of cover box pads
int duneCount = 0; int duneCount = 0;
int attempts = 0; int attempts = 0;
while (duneCount < 20 && attempts < 300) while (duneCount < 20 && attempts < 360)
{ {
attempts++; attempts++;
float x = (float)(rng.NextDouble() * 320.0 - 160.0); float x = (float)(rng.NextDouble() * 300.0 - 150.0);
float z = (float)(rng.NextDouble() * 320.0 - 160.0); float z = (float)(rng.NextDouble() * 300.0 - 150.0);
float radiusX = 14f + (float)rng.NextDouble() * 12f; float radiusX = 12f + (float)rng.NextDouble() * 11f;
float radiusZ = 26f + (float)rng.NextDouble() * 24f; float radiusZ = 24f + (float)rng.NextDouble() * 22f;
if (OverlapsProtectedPads(x, z, MathF.Max(radiusX, radiusZ) * 0.95f, coverBoxes))
{
continue;
}
if (MathF.Abs(field.SampleHeight(x, z)) > 1.8f) if (MathF.Abs(field.SampleHeight(x, z)) > 1.8f)
{ {
continue; continue;
@ -162,7 +158,7 @@ namespace RustToDust.Core
: 1.6f + (float)rng.NextDouble() * 2.0f; : 1.6f + (float)rng.NextDouble() * 2.0f;
float rot = (float)(rng.NextDouble() * MathF.PI); float rot = (float)(rng.NextDouble() * MathF.PI);
field.AddBrush(new TerrainBrush( var candidate = new TerrainBrush(
Id: 0, Id: 0,
Kind: TerrainBrushKind.DuneRidge, Kind: TerrainBrushKind.DuneRidge,
X: x, X: x,
@ -176,14 +172,21 @@ namespace RustToDust.Core
AlbedoR: dryWash ? 0.58f : 0.78f, AlbedoR: dryWash ? 0.58f : 0.78f,
AlbedoG: dryWash ? 0.41f : 0.56f, AlbedoG: dryWash ? 0.41f : 0.56f,
AlbedoB: dryWash ? 0.27f : 0.34f, AlbedoB: dryWash ? 0.27f : 0.34f,
Dynamic: false)); Dynamic: false);
if (!IsBrushClearOfCover(in candidate, coverBoxes))
{
continue;
}
field.AddBrush(candidate);
duneCount++; duneCount++;
} }
// 4. Terraced rust-mesa hills (~7 mesas), mainly mid/outer desert away from spawns & cover // 4. Terraced rust-mesa hills (~7 mesas), mainly mid/outer desert away from spawns & cover
int mesaCount = 0; int mesaCount = 0;
attempts = 0; attempts = 0;
while (mesaCount < 7 && attempts < 160) while (mesaCount < 7 && attempts < 200)
{ {
attempts++; attempts++;
float angle = (float)(rng.NextDouble() * MathF.Tau); float angle = (float)(rng.NextDouble() * MathF.Tau);
@ -193,14 +196,13 @@ namespace RustToDust.Core
float rx = 14f + (float)rng.NextDouble() * 10f; float rx = 14f + (float)rng.NextDouble() * 10f;
float rz = 13f + (float)rng.NextDouble() * 10f; float rz = 13f + (float)rng.NextDouble() * 10f;
if (OverlapsProtectedPads(x, z, MathF.Max(rx, rz) + 6f, coverBoxes) || if (OverlapsSpawnRing(x, z, MathF.Max(rx, rz) + 5f) ||
OverlapsSpawnRing(x, z, MathF.Max(rx, rz) + 5f) ||
MathF.Abs(field.SampleHeight(x, z)) > 1.6f) MathF.Abs(field.SampleHeight(x, z)) > 1.6f)
{ {
continue; continue;
} }
field.AddBrush(new TerrainBrush( var candidate = new TerrainBrush(
Id: 0, Id: 0,
Kind: TerrainBrushKind.Mesa, Kind: TerrainBrushKind.Mesa,
X: x, X: x,
@ -214,7 +216,14 @@ namespace RustToDust.Core
AlbedoR: 0.48f, AlbedoR: 0.48f,
AlbedoG: 0.25f, AlbedoG: 0.25f,
AlbedoB: 0.17f, AlbedoB: 0.17f,
Dynamic: false)); Dynamic: false);
if (!IsBrushClearOfCover(in candidate, coverBoxes))
{
continue;
}
field.AddBrush(candidate);
mesaCount++; mesaCount++;
} }
@ -538,26 +547,22 @@ namespace RustToDust.Core
tz = Math.Clamp((int)MathF.Floor(nz), 0, TileGridCount - 1); tz = Math.Clamp((int)MathF.Floor(nz), 0, TileGridCount - 1);
} }
private static bool OverlapsProtectedPads(float x, float z, float radius, IReadOnlyList<ArenaBoxSpec> coverBoxes) private static bool IsBrushClearOfCover(in TerrainBrush candidate, IReadOnlyList<ArenaBoxSpec> coverBoxes)
{ {
// Keep center plaza clear if (MathF.Abs(EvaluateBrushHeight(in candidate, 0f, 0f)) > 0.35f)
if (x * x + z * z < (radius + 20f) * (radius + 20f))
{ {
return true; return false;
} }
for (int i = 0; i < coverBoxes.Count; i++) for (int i = 0; i < coverBoxes.Count; i++)
{ {
var c = coverBoxes[i]; var c = coverBoxes[i];
float dx = x - c.X; if (MathF.Abs(EvaluateBrushHeight(in candidate, c.X, c.Z)) > 0.35f)
float dz = z - c.Z;
float minDist = radius + MathF.Max(c.HalfX, c.HalfZ) + 9f;
if (dx * dx + dz * dz < minDist * minDist)
{ {
return true; return false;
} }
} }
return false; return true;
} }
private static bool OverlapsSpawnRing(float x, float z, float radius) private static bool OverlapsSpawnRing(float x, float z, float radius)