Fix uphill normal-velocity terrain support, walker tilt arrest, and incoming-fire seeding
This commit is contained in:
parent
2fdbc56d9f
commit
edcc143f74
3 changed files with 140 additions and 58 deletions
|
|
@ -261,65 +261,108 @@ namespace RustToDust.Tests
|
|||
[Theory]
|
||||
[InlineData(42)]
|
||||
[InlineData(101)]
|
||||
public void SteepMesaAndCanyonTraversal_BuggyAndPaladin_NoTunnelingSkyLaunchOrOverturning(int seed)
|
||||
public void SteepMesaAndDuneTraversal_AllSixChassis_NoTunnelingSkyLaunchOrOverturning(int seed)
|
||||
{
|
||||
RunSteepTerrainStress(seed, usePaladin: false);
|
||||
RunSteepTerrainStress(seed, usePaladin: true);
|
||||
foreach (var chassis in Catalog.AllChassis)
|
||||
{
|
||||
RunSteepTerrainStress(seed, chassis, testDune: false);
|
||||
RunSteepTerrainStress(seed, chassis, testDune: true);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RunSteepTerrainStress(int seed, bool usePaladin)
|
||||
private static void RunSteepTerrainStress(int seed, ChassisSpec chassis, bool testDune)
|
||||
{
|
||||
using var session = new ArenaSession(seed);
|
||||
var player = session.State.Player;
|
||||
|
||||
TerrainBrush mesa = default;
|
||||
bool foundMesa = false;
|
||||
TerrainBrush targetBrush = default;
|
||||
float startX = 0f;
|
||||
float startZ = 0f;
|
||||
float bestScore = -1f;
|
||||
for (int i = 0; i < session.State.Terrain.Brushes.Count; i++)
|
||||
{
|
||||
var b = session.State.Terrain.Brushes[i];
|
||||
if (b.Kind == TerrainBrushKind.Mesa && b.HeightDelta >= 22f)
|
||||
bool matches = testDune
|
||||
? b.Kind == TerrainBrushKind.DuneRidge && b.HeightDelta >= 14f
|
||||
: b.Kind == TerrainBrushKind.Mesa && b.HeightDelta >= 22f;
|
||||
if (!matches)
|
||||
{
|
||||
mesa = b;
|
||||
foundMesa = true;
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (MathF.Sqrt(b.X * b.X + b.Z * b.Z) > SpectatorRing.InitialRadius - 90f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float peakH = session.State.Terrain.SampleHeight(b.X, b.Z);
|
||||
for (int k = 0; k < 8; k++)
|
||||
{
|
||||
float localAng = k * (MathF.PI * 0.25f);
|
||||
float localX = MathF.Cos(localAng) * (b.RadiusX + 18f);
|
||||
float localZ = MathF.Sin(localAng) * (b.RadiusZ + 18f);
|
||||
float cosR = MathF.Cos(b.RotationRad);
|
||||
float sinR = MathF.Sin(b.RotationRad);
|
||||
float candX = b.X + localX * cosR - localZ * sinR;
|
||||
float candZ = b.Z + localX * sinR + localZ * cosR;
|
||||
if (MathF.Sqrt(candX * candX + candZ * candZ) > SpectatorRing.InitialRadius - 35f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float baseH = session.State.Terrain.SampleHeight(candX, candZ);
|
||||
float relief = peakH - baseH;
|
||||
if (relief > bestScore)
|
||||
{
|
||||
bestScore = relief;
|
||||
targetBrush = b;
|
||||
startX = candX;
|
||||
startZ = candZ;
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert.True(foundMesa, $"Expected at least one tall mesa in seed {seed}");
|
||||
Assert.True(bestScore >= 10f, $"Expected a climbable {(testDune ? "dune" : "mesa")} approach inside safe circle in seed {seed}");
|
||||
|
||||
float startX = mesa.X - mesa.RadiusX - 24f;
|
||||
float startZ = mesa.Z;
|
||||
float yawToMesa = MathF.Atan2(mesa.X - startX, mesa.Z - startZ);
|
||||
session.SetContenderPose(player.Id, startX, startZ, yawToMesa);
|
||||
|
||||
if (usePaladin)
|
||||
// Keep AI contenders on the opposite side of the safe zone so combat does not kill the vehicle mid-traversal
|
||||
for (int i = 1; i < session.State.Contenders.Count; i++)
|
||||
{
|
||||
session.State.SpawnChassisDrop(player.X, player.Z, Catalog.Paladin);
|
||||
Assert.True(session.TrySwapNearbyChassis());
|
||||
Assert.Equal(GridPlane.Coronal, player.Grid.Spec.Plane);
|
||||
session.SetContenderPose(session.State.Contenders[i].Id, -targetBrush.X * 0.5f + (i - 6) * 14f, -targetBrush.Z * 0.5f);
|
||||
}
|
||||
|
||||
float yawToTarget = MathF.Atan2(targetBrush.X - startX, targetBrush.Z - startZ);
|
||||
session.SetContenderPose(player.Id, startX, startZ, yawToTarget);
|
||||
|
||||
if (chassis.Id != player.Grid.Spec.Id)
|
||||
{
|
||||
session.State.SpawnChassisDrop(player.X, player.Z, chassis);
|
||||
Assert.True(session.TrySwapNearbyChassis(), $"Expected swap to {chassis.Id} to succeed");
|
||||
Assert.Equal(chassis.Id, player.Grid.Spec.Id);
|
||||
}
|
||||
|
||||
float startGroundY = session.State.Terrain.SampleHeight(player.X, player.Z);
|
||||
float maxGroundY = startGroundY;
|
||||
float minBottomRel = float.PositiveInfinity;
|
||||
float maxAirGap = float.NegativeInfinity;
|
||||
float minUpDot = float.PositiveInfinity;
|
||||
|
||||
for (int tick = 0; tick < 600; tick++)
|
||||
{
|
||||
float steer = MathF.Sin(tick * 0.03f) * 0.2f;
|
||||
float steer = MathF.Sin(tick * 0.03f) * 0.15f;
|
||||
session.Step(new PlayerInput(
|
||||
Throttle: 1f,
|
||||
Steer: steer,
|
||||
AimWorldX: mesa.X,
|
||||
AimWorldZ: mesa.Z,
|
||||
AimWorldX: targetBrush.X,
|
||||
AimWorldZ: targetBrush.Z,
|
||||
Fire: false,
|
||||
InteractPickup: false,
|
||||
Brake: false));
|
||||
|
||||
Assert.False(
|
||||
float.IsNaN(player.X) || float.IsNaN(player.Y) || float.IsNaN(player.Z),
|
||||
$"NaN pose at tick {tick} (seed={seed}, paladin={usePaladin})");
|
||||
$"NaN pose at tick {tick} (seed={seed}, chassis={chassis.Id}, dune={testDune})");
|
||||
|
||||
var body = session.GetContenderBody(player.Id);
|
||||
Assert.True(body.HasValue, $"Expected live contender body at tick {tick} (seed={seed}, paladin={usePaladin})");
|
||||
Assert.True(body.HasValue, $"Expected live contender body at tick {tick} (seed={seed}, chassis={chassis.Id})");
|
||||
|
||||
int lane = body!.Value.Lane;
|
||||
var view = session.World.View;
|
||||
|
|
@ -330,17 +373,24 @@ namespace RustToDust.Tests
|
|||
float gh = session.State.Terrain.SampleHeight(player.X, player.Z);
|
||||
float bottomRel = (player.Y - player.Grid.Spec.HalfHeight) - gh;
|
||||
|
||||
maxGroundY = MathF.Max(maxGroundY, gh);
|
||||
minBottomRel = MathF.Min(minBottomRel, bottomRel);
|
||||
maxAirGap = MathF.Max(maxAirGap, bottomRel);
|
||||
minUpDot = MathF.Min(minUpDot, up.Y);
|
||||
}
|
||||
|
||||
Assert.True(minBottomRel >= -1.2f,
|
||||
$"Deep terrain tunneling detected (seed={seed}, paladin={usePaladin}): minBottomRel={minBottomRel:F2}m");
|
||||
Assert.True(maxAirGap <= 10.0f,
|
||||
$"Excessive sky launch detected (seed={seed}, paladin={usePaladin}): maxAirGap={maxAirGap:F2}m");
|
||||
Assert.True(minUpDot > 0.25f,
|
||||
$"Chassis overturned onto side/back (seed={seed}, paladin={usePaladin}): minUpDot={minUpDot:F3}");
|
||||
float climbProgress = maxGroundY - startGroundY;
|
||||
float minRequiredClimb = testDune ? 4.0f : 2.0f;
|
||||
float minAllowedUpDot = chassis.IsWalker ? 0.927f : 0.50f;
|
||||
|
||||
Assert.True(climbProgress >= minRequiredClimb,
|
||||
$"Insufficient uphill climb progress (seed={seed}, chassis={chassis.Id}, dune={testDune}): climb={climbProgress:F2}m start=({startX:F1},{startZ:F1},h={startGroundY:F2}) end=({player.X:F1},{player.Z:F1},maxH={maxGroundY:F2}) brush=({targetBrush.X:F1},{targetBrush.Z:F1},rx={targetBrush.RadiusX:F1},rz={targetBrush.RadiusZ:F1},rot={targetBrush.RotationRad:F2},dh={targetBrush.HeightDelta:F1})");
|
||||
Assert.True(minBottomRel >= -0.35f,
|
||||
$"Terrain tunneling detected (seed={seed}, chassis={chassis.Id}, dune={testDune}): minBottomRel={minBottomRel:F2}m");
|
||||
Assert.True(maxAirGap <= 5.0f,
|
||||
$"Excessive sky launch detected (seed={seed}, chassis={chassis.Id}, dune={testDune}): maxAirGap={maxAirGap:F2}m");
|
||||
Assert.True(minUpDot >= minAllowedUpDot,
|
||||
$"Excessive chassis tilt (seed={seed}, chassis={chassis.Id}, dune={testDune}): minUpDot={minUpDot:F3} (req>={minAllowedUpDot:F3})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue