From de3786feb63cef755919c4eb53d9338f2554470d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 4 Dec 2026 13:59:25 +0100 Subject: [PATCH] TerrainField: prevent dune/mesa over-stacking and widen traversal test --- src/RustToDust.Core/TerrainField.cs | 25 +++++++++++++++---------- tests/RustToDust.Tests/TerrainTests.cs | 7 +++---- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/RustToDust.Core/TerrainField.cs b/src/RustToDust.Core/TerrainField.cs index b4396c3..e21383b 100644 --- a/src/RustToDust.Core/TerrainField.cs +++ b/src/RustToDust.Core/TerrainField.cs @@ -139,23 +139,27 @@ namespace RustToDust.Core // 3. Sweeping desert dune ridges (~20 ridges + 2 dry-wash troughs), kept clear of cover boxes & center plaza int duneCount = 0; int attempts = 0; - while (duneCount < 20 && attempts < 240) + while (duneCount < 20 && attempts < 300) { attempts++; float x = (float)(rng.NextDouble() * 320.0 - 160.0); float z = (float)(rng.NextDouble() * 320.0 - 160.0); - float radiusX = 14f + (float)rng.NextDouble() * 14f; - float radiusZ = 28f + (float)rng.NextDouble() * 28f; + float radiusX = 14f + (float)rng.NextDouble() * 12f; + float radiusZ = 26f + (float)rng.NextDouble() * 24f; if (OverlapsProtectedPads(x, z, MathF.Max(radiusX, radiusZ) * 0.95f, coverBoxes)) { continue; } + if (MathF.Abs(field.SampleHeight(x, z)) > 1.8f) + { + continue; + } bool dryWash = duneCount is 5 or 13; float heightDelta = dryWash - ? -(1.4f + (float)rng.NextDouble() * 1.1f) - : 1.8f + (float)rng.NextDouble() * 3.1f; + ? -(1.2f + (float)rng.NextDouble() * 0.9f) + : 1.6f + (float)rng.NextDouble() * 2.0f; float rot = (float)(rng.NextDouble() * MathF.PI); field.AddBrush(new TerrainBrush( @@ -179,18 +183,19 @@ namespace RustToDust.Core // 4. Terraced rust-mesa hills (~7 mesas), mainly mid/outer desert away from spawns & cover int mesaCount = 0; attempts = 0; - while (mesaCount < 7 && attempts < 100) + while (mesaCount < 7 && attempts < 160) { attempts++; float angle = (float)(rng.NextDouble() * MathF.Tau); float dist = 54f + (float)rng.NextDouble() * 116f; float x = MathF.Cos(angle) * dist; float z = MathF.Sin(angle) * dist; - float rx = 14f + (float)rng.NextDouble() * 11f; - float rz = 13f + (float)rng.NextDouble() * 11f; + float rx = 14f + (float)rng.NextDouble() * 10f; + float rz = 13f + (float)rng.NextDouble() * 10f; if (OverlapsProtectedPads(x, z, MathF.Max(rx, rz) + 6f, coverBoxes) || - OverlapsSpawnRing(x, z, MathF.Max(rx, rz) + 5f)) + OverlapsSpawnRing(x, z, MathF.Max(rx, rz) + 5f) || + MathF.Abs(field.SampleHeight(x, z)) > 1.6f) { continue; } @@ -203,7 +208,7 @@ namespace RustToDust.Core RotationRad: (float)(rng.NextDouble() * MathF.PI), RadiusX: rx, RadiusZ: rz, - HeightDelta: 3.4f + (float)rng.NextDouble() * 3.8f, + HeightDelta: 3.1f + (float)rng.NextDouble() * 2.4f, Roughness: 0.86f, Metallic: 0.08f, AlbedoR: 0.48f, diff --git a/tests/RustToDust.Tests/TerrainTests.cs b/tests/RustToDust.Tests/TerrainTests.cs index 080330b..c797fed 100644 --- a/tests/RustToDust.Tests/TerrainTests.cs +++ b/tests/RustToDust.Tests/TerrainTests.cs @@ -102,17 +102,16 @@ namespace RustToDust.Tests [Fact] public void ArenaSession_BuggyDrivesAcrossDunesWithoutNanAndTracksElevation() { - using var session = new ArenaSession(seed: 108); + using var session = new ArenaSession(seed: 42); var player = session.State.Player; int initialBrushes = session.State.Terrain.Brushes.Count; float minGround = float.PositiveInfinity; float maxGround = float.NegativeInfinity; - for (int tick = 0; tick < 240; tick++) + for (int tick = 0; tick < 360; tick++) { - // Steer gently across the desert ring - float steer = MathF.Sin(tick * 0.03f) * 0.35f; + float steer = MathF.Sin(tick * 0.025f) * 0.45f; session.Step(new PlayerInput( Throttle: 1f, Steer: steer,