2683 lines
137 KiB
C#
2683 lines
137 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using GameCult.Networking;
|
|
using RustToDust.Core;
|
|
using RustToDust.Net;
|
|
using RustToDust.Ymir;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
using Ymir.Box3D;
|
|
|
|
namespace RustToDust.Tests
|
|
{
|
|
public sealed class HybridBWalkerTests
|
|
{
|
|
private readonly ITestOutputHelper _output;
|
|
|
|
public HybridBWalkerTests(ITestOutputHelper output)
|
|
{
|
|
_output = output;
|
|
}
|
|
|
|
private static ChassisSpec MakeExemplarSpec() =>
|
|
Catalog.Raptor with
|
|
{
|
|
Id = "exemplar_frame",
|
|
Name = "Exemplar Frame",
|
|
BaseCellArmor = 22f,
|
|
MassKg = 1150f,
|
|
BaseThrust = 26000f,
|
|
BaseTurnRate = 6.2f,
|
|
MaxSpeed = 40f,
|
|
HalfWidth = 0.8f,
|
|
HalfHeight = 1.55f,
|
|
HalfLength = 0.8f
|
|
};
|
|
|
|
[Fact]
|
|
public void HybridB_All7Mechs_WalkTurnSlopes_SmoothLiftoff_ZeroTeleports()
|
|
{
|
|
var specs = new[]
|
|
{
|
|
Catalog.Breaker,
|
|
Catalog.Paladin,
|
|
Catalog.Raptor,
|
|
Catalog.Spectre,
|
|
Catalog.Kestrel,
|
|
Catalog.Manticore,
|
|
Catalog.Bastion,
|
|
MakeExemplarSpec()
|
|
};
|
|
|
|
// 1. Walk, turn, and climb slopes across all 7 mechs + exemplar_frame
|
|
foreach (var spec in specs)
|
|
{
|
|
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true);
|
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
|
{
|
|
session.SetContenderPose(i, 500f + i * 16f, 500f);
|
|
}
|
|
|
|
// Phase A: start on flat/gentle ground near origin (60 ticks) to verify honest walk slip < 8cm
|
|
session.SetContenderPose(0, 0f, 0f, 0f);
|
|
session.State.SpawnChassisDrop(0f, 0f, spec);
|
|
Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id}");
|
|
var player = session.State.Contenders[0];
|
|
Assert.Equal(spec.Id, player.Grid.Spec.Id);
|
|
|
|
var ws = session.GetWalkerState(true, player.Id);
|
|
Assert.NotNull(ws);
|
|
int nLegs = ws!.Geom.LegCount;
|
|
float geomScale = ws.GeomScale;
|
|
|
|
for (int t = 0; t < 60; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(
|
|
Throttle: 0.45f,
|
|
Steer: 0f,
|
|
AimWorldX: player.X,
|
|
AimWorldZ: player.Z + 60f,
|
|
Fire: false,
|
|
InteractPickup: false,
|
|
Brake: false));
|
|
session.Step();
|
|
}
|
|
Assert.True(ws.MaxFootSlipM < 0.08f,
|
|
$"{spec.Id}: normal walk foot slip {ws.MaxFootSlipM:F4}m >= 0.08m (maxSpd={spec.MaxSpeed:F1})");
|
|
|
|
// Phase B: move to dune slope approach, turn & climb (180 ticks) checking liftoff teleport, C1 touchdown, omega continuity
|
|
float duneApproachX = 0f;
|
|
float duneApproachZ = 0f;
|
|
float bestScore = -1f;
|
|
foreach (var b in session.State.Terrain.Brushes)
|
|
{
|
|
if (b.Kind == TerrainBrushKind.DuneRidge && b.HeightDelta > 4f)
|
|
{
|
|
float d = MathF.Sqrt(b.X * b.X + b.Z * b.Z);
|
|
if (d > 40f && d < 280f && b.HeightDelta > bestScore)
|
|
{
|
|
bestScore = b.HeightDelta;
|
|
float dirX = -b.X / d;
|
|
float dirZ = -b.Z / d;
|
|
duneApproachX = b.X + dirX * MathF.Min(36f, b.RadiusX * 0.85f);
|
|
duneApproachZ = b.Z + dirZ * MathF.Min(36f, b.RadiusZ * 0.85f);
|
|
}
|
|
}
|
|
}
|
|
session.SetContenderPose(0, duneApproachX, duneApproachZ, MathF.Atan2(-duneApproachX, -duneApproachZ) + MathF.PI);
|
|
ws = session.GetWalkerState(true, player.Id)!;
|
|
|
|
var prevFoot = new Vector3[nLegs];
|
|
var prevPlanted = new bool[nLegs];
|
|
var prevOmegaHip = new float[nLegs];
|
|
for (int i = 0; i < nLegs; i++)
|
|
{
|
|
prevFoot[i] = ws.FootSole[i];
|
|
prevPlanted[i] = ws.Planted[i];
|
|
prevOmegaHip[i] = ws.Actuators[i].Omega.HipPitch;
|
|
}
|
|
|
|
float maxDeltaFootPerTick = 0f;
|
|
float maxLiftoffDelta = 0f;
|
|
float maxOmegaJumpAtSwap = 0f;
|
|
float maxTouchdownGroundErr = 0f;
|
|
float minUpDot = 1f;
|
|
int swapCount = 0;
|
|
for (int t = 0; t < 180; t++)
|
|
{
|
|
float steer = MathF.Sin(t * 0.06f) * 0.65f;
|
|
session.SetHumanInput(0, new PlayerInput(
|
|
Throttle: 0.85f,
|
|
Steer: steer,
|
|
AimWorldX: player.X + 40f * MathF.Sin(player.Yaw),
|
|
AimWorldZ: player.Z + 40f * MathF.Cos(player.Yaw),
|
|
Fire: false,
|
|
InteractPickup: false,
|
|
Brake: false));
|
|
session.Step();
|
|
|
|
Assert.True(float.IsFinite(player.X) && float.IsFinite(player.Y) && float.IsFinite(player.Z),
|
|
$"{spec.Id}: non-finite pose at tick {t}");
|
|
|
|
var q = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
|
var up = Vector3.Transform(Vector3.UnitY, q);
|
|
minUpDot = MathF.Min(minUpDot, up.Y);
|
|
|
|
for (int i = 0; i < nLegs; i++)
|
|
{
|
|
Vector3 curFoot = ws.FootSole[i];
|
|
float delta = (curFoot - prevFoot[i]).Length();
|
|
if (delta > maxDeltaFootPerTick)
|
|
{
|
|
maxDeltaFootPerTick = delta;
|
|
}
|
|
|
|
bool curPlanted = ws.Planted[i];
|
|
if (prevPlanted[i] && !curPlanted && !ws.IsAirborne)
|
|
{
|
|
if (delta > maxLiftoffDelta)
|
|
{
|
|
maxLiftoffDelta = delta;
|
|
}
|
|
}
|
|
if (!prevPlanted[i] && curPlanted)
|
|
{
|
|
swapCount++;
|
|
float groundY = session.State.Terrain.SampleHeight(curFoot.X, curFoot.Z);
|
|
float gErr = MathF.Abs(curFoot.Y - groundY);
|
|
if (gErr > maxTouchdownGroundErr)
|
|
{
|
|
maxTouchdownGroundErr = gErr;
|
|
}
|
|
|
|
float omegaDelta = MathF.Abs(ws.Actuators[i].Omega.HipPitch - prevOmegaHip[i]);
|
|
if (omegaDelta > maxOmegaJumpAtSwap)
|
|
{
|
|
maxOmegaJumpAtSwap = omegaDelta;
|
|
}
|
|
}
|
|
|
|
prevFoot[i] = curFoot;
|
|
prevPlanted[i] = curPlanted;
|
|
prevOmegaHip[i] = ws.Actuators[i].Omega.HipPitch;
|
|
}
|
|
}
|
|
|
|
float maxFootGroundSpeed = spec.MaxSpeed + MathF.Max(spec.HalfWidth, spec.HalfLength) * spec.BaseTurnRate * 0.5f;
|
|
float maxAllowedTickDelta = MathF.Max(0.55f, maxFootGroundSpeed * ArenaSession.FixedDt * 3.5f);
|
|
_output.WriteLine(
|
|
$"{spec.Id,-15} minUp={minUpDot:F3} slip={ws.MaxFootSlipM:F4}m maxFootDelta/tick={maxDeltaFootPerTick:F4}m " +
|
|
$"liftoffDelta={maxLiftoffDelta:F4}m tdGroundErr={maxTouchdownGroundErr:F5}m swapOmegaJump={maxOmegaJumpAtSwap:F3} swaps={swapCount}");
|
|
|
|
Assert.True(minUpDot >= 0.90f, $"{spec.Id}: unstable tilt minUpDot={minUpDot:F3}");
|
|
Assert.True(swapCount >= 4, $"{spec.Id}: expected >= 4 gait transitions, got {swapCount}");
|
|
Assert.True(maxLiftoffDelta <= 0.35f * MathF.Max(1f, geomScale),
|
|
$"{spec.Id}: Bug 1 liftoff teleport detected: liftoffDelta={maxLiftoffDelta:F4}m");
|
|
Assert.True(maxDeltaFootPerTick <= maxAllowedTickDelta,
|
|
$"{spec.Id}: 1-tick foot teleport detected: maxDelta={maxDeltaFootPerTick:F4}m > {maxAllowedTickDelta:F4}m");
|
|
Assert.True(maxTouchdownGroundErr <= 0.06f * MathF.Max(1f, geomScale),
|
|
$"{spec.Id}: non-C1 liftoff/touchdown height gap {maxTouchdownGroundErr:F4}m");
|
|
Assert.True(maxOmegaJumpAtSwap < 12.0f,
|
|
$"{spec.Id}: discontinuous joint omega jump across swap: {maxOmegaJumpAtSwap:F3} rad/s");
|
|
}
|
|
|
|
// 2. Benchmark 12 simultaneous mechs CPU < 1.5 ms/tick
|
|
{
|
|
using var benchSession = new ArenaSession(seed: 99, mapKind: ArenaMapKind.Desert, slot0Human: true);
|
|
for (int i = 0; i < benchSession.State.Contenders.Count; i++)
|
|
{
|
|
var spec = specs[i % 7];
|
|
float x = (i - 5.5f) * 28f;
|
|
float z = -80f + (i % 3) * 35f;
|
|
benchSession.SetContenderPose(i, x, z, 0f);
|
|
if (benchSession.State.Contenders[i].Grid.Spec.Id != spec.Id)
|
|
{
|
|
benchSession.State.Contenders[i].Grid.SwapChassis(spec);
|
|
benchSession.SetContenderPose(i, x, z, 0f);
|
|
}
|
|
}
|
|
|
|
var walkers = new (ContenderState C, WalkerState Ws, Box3DSoaBodyHandle Body)[12];
|
|
for (int i = 0; i < 12; i++)
|
|
{
|
|
var c = benchSession.State.Contenders[i];
|
|
c.ThrottleCmd = 0.8f;
|
|
c.SteerCmd = (i % 2 == 0 ? 0.2f : -0.2f);
|
|
walkers[i] = (c, benchSession.GetWalkerState(true, c.Id)!, benchSession.GetContenderBody(c.Id)!.Value);
|
|
}
|
|
|
|
// Warmup JIT
|
|
for (int w = 0; w < 20; w++)
|
|
{
|
|
benchSession.SetHumanInput(0, new PlayerInput(0.8f, 0.2f, 0f, 100f, false, false, false));
|
|
benchSession.Step();
|
|
}
|
|
|
|
var view = benchSession.World.View;
|
|
const int benchTicks = 300;
|
|
long t0 = Stopwatch.GetTimestamp();
|
|
for (int t = 0; t < benchTicks; t++)
|
|
{
|
|
for (int i = 0; i < 12; i++)
|
|
{
|
|
var (c, ws, body) = walkers[i];
|
|
int lane = body.Lane;
|
|
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
|
var fwd = Vector3.Transform(Vector3.UnitZ, q);
|
|
fwd.Y = 0f;
|
|
fwd = fwd.LengthSquared() < 1e-4f ? Vector3.UnitZ : Vector3.Normalize(fwd);
|
|
WalkerLocomotion.PreStepWalker(
|
|
ws, c.Grid, benchSession.State.Terrain, benchSession.World, body, view.Mass[lane],
|
|
fwd * (c.ThrottleCmd * c.Grid.Spec.MaxSpeed), 0.3f, false, ArenaSession.FixedDt);
|
|
WalkerLocomotion.PostStepWalker(
|
|
ws, c.Grid, benchSession.State.Terrain, benchSession.World, body, view.Mass[lane], ArenaSession.FixedDt);
|
|
}
|
|
}
|
|
long t1 = Stopwatch.GetTimestamp();
|
|
double msPerTick = (t1 - t0) * 1000.0 / Stopwatch.Frequency / benchTicks;
|
|
_output.WriteLine($"12-mech simultaneous WalkerLocomotion CPU: {msPerTick:F4} ms/tick");
|
|
Assert.True(msPerTick < 1.5, $"12 simultaneous mechs CPU {msPerTick:F4} ms/tick exceeded 1.5 ms/tick budget");
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void HybridB_CrippledLeg_ReducesGrfAndTorque_InducesLimp()
|
|
{
|
|
Span<float> legIntegrities = stackalloc float[4];
|
|
foreach (var spec in new[] { Catalog.Breaker, Catalog.Bastion })
|
|
{
|
|
using var session = new ArenaSession(seed: 17, mapKind: ArenaMapKind.Desert, slot0Human: true);
|
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
|
{
|
|
session.SetContenderPose(i, 450f + i * 16f, 450f);
|
|
}
|
|
session.SetContenderPose(0, 0f, 0f, 0f);
|
|
session.State.SpawnChassisDrop(0f, 0f, spec);
|
|
Assert.True(session.TrySwapNearbyChassis(0));
|
|
|
|
var player = session.State.Contenders[0];
|
|
var grid = player.Grid;
|
|
|
|
// Strip all left-leg cells (Breaker Coronal L: y>=H-2, x<W/2; Bastion Dorsal FL: y<H/2, x<W/2)
|
|
if (spec.Plane == GridPlane.Coronal)
|
|
{
|
|
for (int y = spec.Height - 2; y < spec.Height; y++)
|
|
{
|
|
for (int x = 0; x < spec.Width / 2; x++)
|
|
{
|
|
grid.Armor[x, y] = 0f;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int y = 0; y < spec.Height / 2; y++)
|
|
{
|
|
for (int x = 0; x < spec.Width / 2; x++)
|
|
{
|
|
grid.Armor[x, y] = 0f;
|
|
}
|
|
}
|
|
}
|
|
|
|
legIntegrities.Clear();
|
|
grid.GetLegIntegrities(legIntegrities);
|
|
Assert.Equal(0.25f, legIntegrities[0], precision: 3);
|
|
Assert.Equal(1.00f, legIntegrities[1], precision: 3);
|
|
Assert.True(grid.LegIntegrity < 1.0f, $"Expected {spec.Id} LegIntegrity < 1.0 after leg strip");
|
|
|
|
var ws = session.GetWalkerState(true, player.Id)!;
|
|
float peakLeftLoadG = 0f;
|
|
float peakRightLoadG = 0f;
|
|
float maxLeanRollAbs = 0f;
|
|
float maxOmegaLeft = 0f;
|
|
float maxOmegaRight = 0f;
|
|
|
|
for (int t = 0; t < 180; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(
|
|
Throttle: 0.9f,
|
|
Steer: 0f,
|
|
AimWorldX: player.X,
|
|
AimWorldZ: player.Z + 80f,
|
|
Fire: false,
|
|
InteractPickup: false,
|
|
Brake: false));
|
|
session.Step();
|
|
|
|
Assert.True(float.IsFinite(player.X) && float.IsFinite(player.Y) && float.IsFinite(player.Z));
|
|
peakLeftLoadG = MathF.Max(peakLeftLoadG, ws.LoadG[0]);
|
|
peakRightLoadG = MathF.Max(peakRightLoadG, ws.LoadG[1]);
|
|
maxOmegaLeft = MathF.Max(maxOmegaLeft, MathF.Abs(ws.Actuators[0].Omega.HipPitch));
|
|
maxOmegaRight = MathF.Max(maxOmegaRight, MathF.Abs(ws.Actuators[1].Omega.HipPitch));
|
|
|
|
var q = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
|
var upVec = Vector3.Transform(Vector3.UnitY, q);
|
|
Assert.True(upVec.Y >= 0.9999f, $"{spec.Id}: physics capsule tilted off upright ({upVec.Y:F5})");
|
|
maxLeanRollAbs = MathF.Max(maxLeanRollAbs, MathF.Abs(ws.LeanRoll));
|
|
}
|
|
|
|
_output.WriteLine(
|
|
$"{spec.Id} crippled left leg: peakLeftLoadG={peakLeftLoadG:F2}G peakRightLoadG={peakRightLoadG:F2}G " +
|
|
$"maxLeanRoll={maxLeanRollAbs:F4}rad omegaL={maxOmegaLeft:F2} omegaR={maxOmegaRight:F2}");
|
|
|
|
Assert.True(peakLeftLoadG < peakRightLoadG * 0.55f,
|
|
$"{spec.Id}: expected crippled left LoadG ({peakLeftLoadG:F2}G) << healthy right LoadG ({peakRightLoadG:F2}G)");
|
|
Assert.True(maxLeanRollAbs > 0.002f,
|
|
$"{spec.Id}: expected crippled leg asymmetry to induce measurable visual limp roll");
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void HybridB_AirborneMech_ZeroGrfForce()
|
|
{
|
|
foreach (var spec in new[] { Catalog.Breaker, Catalog.Manticore })
|
|
{
|
|
using var session = new ArenaSession(seed: 7, mapKind: ArenaMapKind.Desert, slot0Human: true);
|
|
session.SetContenderPose(0, 0f, 0f, 0f);
|
|
session.State.SpawnChassisDrop(0f, 0f, spec);
|
|
Assert.True(session.TrySwapNearbyChassis(0));
|
|
|
|
var player = session.State.Contenders[0];
|
|
var body = session.GetContenderBody(player.Id)!.Value;
|
|
var view = session.World.View;
|
|
int lane = body.Lane;
|
|
|
|
// 1. Lift COM 18m above terrain and verify airborne zero support/yaw torque
|
|
float groundY = session.State.Terrain.SampleHeight(0f, 0f);
|
|
session.World.SetBodyMotion(
|
|
body,
|
|
position: (view.PositionX[lane], groundY + spec.HalfHeight + 18f, view.PositionZ[lane]),
|
|
linearVelocity: (0f, 0f, 0f),
|
|
angularVelocity: (0f, 0f, 0f));
|
|
|
|
var ws = session.GetWalkerState(true, player.Id)!;
|
|
WalkerLocomotion.PostStepWalker(ws, player.Grid, session.State.Terrain, session.World, body, view.Mass[lane], ArenaSession.FixedDt);
|
|
Assert.True(ws.IsAirborne, $"{spec.Id}: expected IsAirborne == true when lifted 18m above terrain");
|
|
for (int i = 0; i < ws.Geom.LegCount; i++)
|
|
{
|
|
Assert.Equal(0f, ws.LoadG[i]);
|
|
}
|
|
|
|
WalkerLocomotion.PreStepWalker(
|
|
ws, player.Grid, session.State.Terrain, session.World, body, view.Mass[lane],
|
|
new Vector3(0f, 0f, 10f), targetYawVel: 2.0f, brakeCmd: false, ArenaSession.FixedDt);
|
|
Assert.Equal(0f, view.ForceX[lane]);
|
|
Assert.Equal(0f, view.ForceY[lane]);
|
|
Assert.Equal(0f, view.ForceZ[lane]);
|
|
Assert.Equal(0f, view.TorqueX[lane]);
|
|
Assert.Equal(0f, view.TorqueY[lane]);
|
|
Assert.Equal(0f, view.TorqueZ[lane]);
|
|
Assert.Equal(0f, view.AngularVelocityY[lane]);
|
|
|
|
// 2. Real ballistic freefall (-20 m/s^2) and landing ImpactVelY compression on touchdown
|
|
bool sawAirborneTick = false;
|
|
bool sawLandingCompression = false;
|
|
for (int t = 0; t < 180; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(1f, 0f, 0f, 50f, false, false, false));
|
|
session.Step();
|
|
if (ws.IsAirborne)
|
|
{
|
|
sawAirborneTick = true;
|
|
Assert.Equal(0f, view.ForceY[lane]);
|
|
Assert.Equal(0f, view.AngularVelocityY[lane]);
|
|
}
|
|
else if (sawAirborneTick && ws.CompressionY < -0.04f)
|
|
{
|
|
sawLandingCompression = true;
|
|
break;
|
|
}
|
|
}
|
|
Assert.True(sawAirborneTick, $"{spec.Id}: expected lifted launch to produce airborne ticks");
|
|
Assert.True(sawLandingCompression, $"{spec.Id}: expected ballistic touchdown to drive knee CompressionY dip");
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void HybridB_All7Mechs_ObeyDirectionalInputAtMultipleYaws_NoGooseStepNoDrift()
|
|
{
|
|
var specs = new[]
|
|
{
|
|
Catalog.Breaker,
|
|
Catalog.Paladin,
|
|
Catalog.Raptor,
|
|
Catalog.Spectre,
|
|
Catalog.Kestrel,
|
|
Catalog.Manticore,
|
|
Catalog.Bastion
|
|
};
|
|
float[] yawsDeg = { 0f, 45f, 90f, 135f };
|
|
|
|
foreach (var spec in specs)
|
|
{
|
|
foreach (float yawDeg in yawsDeg)
|
|
{
|
|
float yawRad = yawDeg * MathF.PI / 180f;
|
|
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true);
|
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
|
{
|
|
session.SetContenderPose(i, 500f + i * 16f, 500f);
|
|
}
|
|
|
|
session.SetContenderPose(0, 0f, 0f, yawRad);
|
|
session.State.SpawnChassisDrop(0f, 0f, spec);
|
|
Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id}");
|
|
session.SetContenderPose(0, 0f, 0f, yawRad);
|
|
var player = session.State.Contenders[0];
|
|
|
|
// Lettle -> Wait 5 idle ticks to verify zero rest creep from dead stop
|
|
for (int t = 0; t < 5; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 50f, false, false, false));
|
|
session.Step();
|
|
}
|
|
|
|
Vector2 cmdFwd = new(MathF.Sin(yawRad), MathF.Cos(yawRad));
|
|
Vector2 cmdRight = new(-cmdFwd.Y, cmdFwd.X);
|
|
|
|
// 1. Hold W (Throttle = +1) for 2.0s (120 ticks) from rest
|
|
Vector2 wStart = new(player.X, player.Z);
|
|
for (int t = 0; t < 120; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(
|
|
Throttle: 1f,
|
|
Steer: 0f,
|
|
AimWorldX: player.X + cmdFwd.X * 50f,
|
|
AimWorldZ: player.Z + cmdFwd.Y * 50f,
|
|
Fire: false,
|
|
InteractPickup: false,
|
|
Brake: false));
|
|
session.Step();
|
|
}
|
|
float endWSpeed = player.Speed;
|
|
Vector2 wDelta = new Vector2(player.X, player.Z) - wStart;
|
|
float fwdDisp = Vector2.Dot(wDelta, cmdFwd);
|
|
float latDrift = MathF.Abs(Vector2.Dot(wDelta, cmdRight));
|
|
Assert.True(fwdDisp >= 6.0f,
|
|
$"{spec.Id} @ {yawDeg}deg W 2.0s: fwdDisp={fwdDisp:F2}m < 6.0m (lat={latDrift:F2}m)");
|
|
Assert.True(latDrift < 2.0f,
|
|
$"{spec.Id} @ {yawDeg}deg W 2.0s: latDrift={latDrift:F2}m >= 2.0m (fwd={fwdDisp:F2}m)");
|
|
|
|
// 2. Release W (Throttle = 0) for 3.0s (180 ticks): stop < 0.30 m/s within physical Coulomb limit, final 1.0s (60 ticks) drift < 0.15m
|
|
float speedAt1_2s = 0f;
|
|
float speedAt2_0s = 0f;
|
|
float timeToStop = -1f;
|
|
Vector2 finalWindowStart = Vector2.Zero;
|
|
for (int t = 0; t < 180; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(
|
|
Throttle: 0f,
|
|
Steer: 0f,
|
|
AimWorldX: player.X + cmdFwd.X * 50f,
|
|
AimWorldZ: player.Z + cmdFwd.Y * 50f,
|
|
Fire: false,
|
|
InteractPickup: false,
|
|
Brake: false));
|
|
session.Step();
|
|
|
|
if (timeToStop < 0f && player.Speed < 0.30f)
|
|
{
|
|
timeToStop = (t + 1) * ArenaSession.FixedDt;
|
|
}
|
|
if (t == 71) speedAt1_2s = player.Speed;
|
|
if (t == 119)
|
|
{
|
|
speedAt2_0s = player.Speed;
|
|
finalWindowStart = new Vector2(player.X, player.Z);
|
|
}
|
|
}
|
|
float finalDrift = (new Vector2(player.X, player.Z) - finalWindowStart).Length();
|
|
float maxPhysStopSec = MathF.Max(1.2f, endWSpeed / 16.0f + 0.35f);
|
|
if (yawDeg == 0f)
|
|
{
|
|
_output.WriteLine(
|
|
$"{spec.Id,-10} maxSpd={spec.MaxSpeed:F1} endWSpd={endWSpeed:F2} " +
|
|
$"tStop={timeToStop:F2}s (limit={maxPhysStopSec:F2}s) spd@1.2s={speedAt1_2s:F3} spd@2.0s={speedAt2_0s:F3} finalDrift={finalDrift:F4}m");
|
|
}
|
|
Assert.True(timeToStop > 0f && timeToStop <= maxPhysStopSec,
|
|
$"{spec.Id} @ {yawDeg}deg release W: tStop={timeToStop:F2}s > {maxPhysStopSec:F2}s (endWSpd={endWSpeed:F2}, @2.0s={speedAt2_0s:F3})");
|
|
Assert.True(finalDrift < 0.15f,
|
|
$"{spec.Id} @ {yawDeg}deg release W: final 1.0s drift={finalDrift:F4}m >= 0.15m");
|
|
|
|
// 3. Hold S (Throttle = -1) for 1.5s (90 ticks)
|
|
Vector2 sStart = new(player.X, player.Z);
|
|
Vector2 revDir = new(MathF.Sin(player.Yaw), MathF.Cos(player.Yaw));
|
|
for (int t = 0; t < 90; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(
|
|
Throttle: -1f,
|
|
Steer: 0f,
|
|
AimWorldX: player.X + revDir.X * 50f,
|
|
AimWorldZ: player.Z + revDir.Y * 50f,
|
|
Fire: false,
|
|
InteractPickup: false,
|
|
Brake: false));
|
|
session.Step();
|
|
}
|
|
float revDisp = Vector2.Dot(new Vector2(player.X, player.Z) - sStart, -revDir);
|
|
Assert.True(revDisp >= 3.0f,
|
|
$"{spec.Id} @ {yawDeg}deg S 1.5s: revDisp={revDisp:F2}m < 3.0m");
|
|
|
|
// Settle until stopped before turning test
|
|
for (int t = 0; t < 180 && (t < 20 || player.Speed > 0.05f); t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 50f, false, false, false));
|
|
session.Step();
|
|
}
|
|
|
|
// 4. Hold D (Steer = +1, Throttle = 0) for 1.5s (90 ticks)
|
|
Vector2 dStart = new(player.X, player.Z);
|
|
float prevYaw = player.Yaw;
|
|
float accumYaw = 0f;
|
|
for (int t = 0; t < 90; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(
|
|
Throttle: 0f,
|
|
Steer: 1f,
|
|
AimWorldX: player.X,
|
|
AimWorldZ: player.Z + 50f,
|
|
Fire: false,
|
|
InteractPickup: false,
|
|
Brake: false));
|
|
session.Step();
|
|
accumYaw += MatchRules.NormalizeAngle(player.Yaw - prevYaw);
|
|
prevYaw = player.Yaw;
|
|
}
|
|
float dTrans = (new Vector2(player.X, player.Z) - dStart).Length();
|
|
// Steer = +1 turns right -> negative yaw change (-accumYaw >= 0.5 rad)
|
|
Assert.True(-accumYaw >= 0.5f,
|
|
$"{spec.Id} @ {yawDeg}deg D 1.5s: yawChange={accumYaw:F3} rad (expected <= -0.50 rad)");
|
|
Assert.True(dTrans < 1.0f,
|
|
$"{spec.Id} @ {yawDeg}deg D 1.5s: spurious translation={dTrans:F3}m >= 1.0m");
|
|
|
|
if (yawDeg == 0f || yawDeg == 135f)
|
|
{
|
|
_output.WriteLine(
|
|
$"{spec.Id,-10} yaw={yawDeg,3:F0}deg: fwd={fwdDisp:F2}m lat={latDrift:F2}m " +
|
|
$"stopSpd={speedAt1_2s:F3}m/s drift={finalDrift:F4}m rev={revDisp:F2}m turn={-accumYaw:F2}rad dTrans={dTrans:F3}m");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void HybridB_BreakerAndBastion_SionSlopeControl_ObeysInput()
|
|
{
|
|
foreach (var spec in new[] { Catalog.Breaker, Catalog.Bastion })
|
|
{
|
|
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true);
|
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
|
{
|
|
session.SetContenderPose(i, 900f + i * 16f, 900f);
|
|
}
|
|
|
|
var sion = session.State.SionMap!;
|
|
// Find a clear sloped hillside on Sion (slope ~7-18 deg, free of buildings and low wall meshes along a +/-7m corridor)
|
|
float slopeX = session.State.Contenders[0].X;
|
|
float slopeZ = session.State.Contenders[0].Z;
|
|
float slopeYaw = 0f;
|
|
bool foundSlope = false;
|
|
for (float r = 40f; r <= 560f && !foundSlope; r += 20f)
|
|
{
|
|
for (int a = 0; a < 36 && !foundSlope; a++)
|
|
{
|
|
float ang = a * (MathF.Tau / 36f);
|
|
float x = MathF.Cos(ang) * r;
|
|
float z = MathF.Sin(ang) * r;
|
|
if (sion.IsInsideAnyBuildingXz(x, z, 14f)) continue;
|
|
var (nx, ny, nz) = session.State.Terrain.SampleNormal(x, z);
|
|
if (ny <= 0.992f && ny >= 0.950f)
|
|
{
|
|
float yaw = MathF.Atan2(-nx, -nz); // uphill heading
|
|
float fx = MathF.Sin(yaw);
|
|
float fz = MathF.Cos(yaw);
|
|
float rx = -fz;
|
|
float rz = fx;
|
|
bool clear = true;
|
|
foreach (float lat in new[] { -7f, 0f, 7f })
|
|
{
|
|
float sx = x + rx * lat;
|
|
float sz = z + rz * lat;
|
|
for (float d = 0f; d < 28f; d += 4f)
|
|
{
|
|
float ax = sx + fx * d;
|
|
float az = sz + fz * d;
|
|
float bx = sx + fx * (d + 4f);
|
|
float bz = sz + fz * (d + 4f);
|
|
if (sion.IsInsideAnyBuildingXz(ax, az, 4f) ||
|
|
session.State.Terrain.SampleNormal(ax, az).Ny < 0.90f)
|
|
{
|
|
clear = false;
|
|
break;
|
|
}
|
|
float gyA = session.State.Terrain.SampleHeight(ax, az);
|
|
float gyB = session.State.Terrain.SampleHeight(bx, bz);
|
|
if (!session.HasLineOfSight(ax, gyA + 2.5f, az, bx, gyB + 2.5f, bz))
|
|
{
|
|
clear = false;
|
|
break;
|
|
}
|
|
}
|
|
if (!clear) break;
|
|
}
|
|
if (clear)
|
|
{
|
|
slopeX = x;
|
|
slopeZ = z;
|
|
slopeYaw = yaw;
|
|
foundSlope = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Assert.True(foundSlope, $"{spec.Id}: failed to locate clear Sion slope test site");
|
|
|
|
session.SetContenderPose(0, slopeX, slopeZ, slopeYaw);
|
|
session.State.SpawnChassisDrop(slopeX, slopeZ, spec);
|
|
Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id} on Sion");
|
|
session.SetContenderPose(0, slopeX, slopeZ, slopeYaw);
|
|
var player = session.State.Contenders[0];
|
|
|
|
// 1. Drive forward up/along slope (2.0s)
|
|
Vector2 startPos = new(player.X, player.Z);
|
|
Vector2 fwdDir = new(MathF.Sin(slopeYaw), MathF.Cos(slopeYaw));
|
|
var ws = session.GetWalkerState(true, player.Id)!;
|
|
float gStart = session.State.Terrain.SampleHeight(player.X, player.Z);
|
|
float startY = player.Y;
|
|
for (int t = 0; t < 120; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(
|
|
Throttle: 1f,
|
|
Steer: 0f,
|
|
AimWorldX: player.X + fwdDir.X * 50f,
|
|
AimWorldZ: player.Z + fwdDir.Y * 50f,
|
|
Fire: false,
|
|
InteractPickup: false,
|
|
Brake: false));
|
|
session.Step();
|
|
}
|
|
float gEnd = session.State.Terrain.SampleHeight(player.X, player.Z);
|
|
float fwdDisp = Vector2.Dot(new Vector2(player.X, player.Z) - startPos, fwdDir);
|
|
int pLane = session.GetContenderBody(player.Id)!.Value.Lane;
|
|
string touchesStr = "";
|
|
foreach (var tc in session.World.Facts.Touching)
|
|
{
|
|
if (tc.LaneA == pLane || tc.LaneB == pLane)
|
|
{
|
|
ulong other = tc.LaneA == pLane ? tc.StableIdB : tc.StableIdA;
|
|
touchesStr += $"{other},";
|
|
}
|
|
}
|
|
_output.WriteLine(
|
|
$"{spec.Id} Sion slope ({slopeX:F1},{slopeZ:F1}) gStart={gStart:F2} startY={startY:F2} (H={spec.HalfHeight:F2}) -> " +
|
|
$"({player.X:F1},{player.Y:F2},{player.Z:F1}) gEnd={gEnd:F2} pYaw={player.Yaw:F2} fwdDisp={fwdDisp:F2}m air={ws.IsAirborne} grounded={ws.Grounded} touching=[{touchesStr}]");
|
|
Assert.True(fwdDisp >= 5.0f, $"{spec.Id} Sion slope W 2.0s: fwdDisp={fwdDisp:F2}m < 5.0m");
|
|
|
|
// 2. Turn cleanly on Sion slope (D for 1.5s)
|
|
float prevYaw = player.Yaw;
|
|
float accumYaw = 0f;
|
|
for (int t = 0; t < 90; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(0f, 1f, player.X, player.Z + 50f, false, false, false));
|
|
session.Step();
|
|
accumYaw += MatchRules.NormalizeAngle(player.Yaw - prevYaw);
|
|
prevYaw = player.Yaw;
|
|
}
|
|
Assert.True(-accumYaw >= 0.35f, $"{spec.Id} Sion slope D 1.5s: yawChange={accumYaw:F3} rad");
|
|
|
|
// 3. Release controls on slope (3.0s): must stop cleanly and NOT slide away
|
|
float speedAt1_2s = 0f;
|
|
float timeToStop = -1f;
|
|
Vector2 finalWinStart = Vector2.Zero;
|
|
for (int t = 0; t < 180; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 50f, false, false, false));
|
|
session.Step();
|
|
if (timeToStop < 0f && player.Speed < 0.35f) timeToStop = (t + 1) * ArenaSession.FixedDt;
|
|
if (t == 71) speedAt1_2s = player.Speed;
|
|
if (t == 119) finalWinStart = new Vector2(player.X, player.Z);
|
|
}
|
|
float finalSlide = (new Vector2(player.X, player.Z) - finalWinStart).Length();
|
|
_output.WriteLine(
|
|
$"{spec.Id,-10} Sion slope ({slopeX:F1},{slopeZ:F1}): fwd={fwdDisp:F2}m turn={-accumYaw:F2}rad " +
|
|
$"tStop={timeToStop:F2}s spd@1.2s={speedAt1_2s:F3}m/s slopeSlide={finalSlide:F4}m");
|
|
Assert.True(timeToStop > 0f && timeToStop <= 2.0f, $"{spec.Id} Sion slope release: tStop={timeToStop:F2}s > 2.0s (spd@1.2s={speedAt1_2s:F3}m/s)");
|
|
Assert.True(finalSlide < 0.18f, $"{spec.Id} Sion slope release: 1.0s slide={finalSlide:F4}m >= 0.18m");
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void HybridB_Bastion_SteepSionHills_15To22Deg_ClimbsWithoutBeaching()
|
|
{
|
|
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true);
|
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
|
{
|
|
session.SetContenderPose(i, 900f + i * 16f, 900f);
|
|
}
|
|
|
|
var sion = session.State.SionMap!;
|
|
var sites = new System.Collections.Generic.List<(float X, float Z, float Yaw, float Ny)>();
|
|
for (float r = 60f; r <= 1350f && sites.Count < 3; r += 25f)
|
|
{
|
|
for (int a = 0; a < 48 && sites.Count < 3; a++)
|
|
{
|
|
float ang = a * (MathF.Tau / 48f);
|
|
float x = MathF.Cos(ang) * r;
|
|
float z = MathF.Sin(ang) * r;
|
|
if (sion.IsInsideAnyBuildingXz(x, z, 14f)) continue;
|
|
var (nx, ny, nz) = session.State.Terrain.SampleNormal(x, z);
|
|
if (ny < 0.925f || ny > 0.966f) continue;
|
|
|
|
float yaw = MathF.Atan2(-nx, -nz);
|
|
float fx = MathF.Sin(yaw);
|
|
float fz = MathF.Cos(yaw);
|
|
float rx = -fz;
|
|
float rz = fx;
|
|
bool clear = true;
|
|
foreach (float lat in new[] { -7.5f, 0f, 7.5f })
|
|
{
|
|
float sx = x + rx * lat;
|
|
float sz = z + rz * lat;
|
|
for (float d = 0f; d < 42f; d += 1f)
|
|
{
|
|
float ax = sx + fx * d;
|
|
float az = sz + fz * d;
|
|
float bx = sx + fx * (d + 1f);
|
|
float bz = sz + fz * (d + 1f);
|
|
if (sion.IsInsideAnyBuildingXz(ax, az, 4f) ||
|
|
session.State.Terrain.SampleNormal(ax, az).Ny < 0.86f)
|
|
{
|
|
clear = false;
|
|
break;
|
|
}
|
|
if (sion.Trees is not null)
|
|
{
|
|
for (int ti = 0; ti < sion.Trees.Count; ti++)
|
|
{
|
|
var tr = sion.Trees.Trees[ti];
|
|
if (tr.TrunkRadiusM < SionTreeDestructionState.MinColliderTrunkRadiusM) continue;
|
|
float tdx = tr.X - ax;
|
|
float tdz = tr.Z - az;
|
|
if (tdx * tdx + tdz * tdz <= 4.0f * 4.0f)
|
|
{
|
|
clear = false;
|
|
break;
|
|
}
|
|
}
|
|
if (!clear) break;
|
|
}
|
|
if (((int)d % 4) == 0)
|
|
{
|
|
float gyA = session.State.Terrain.SampleHeight(ax, az);
|
|
float gyB = session.State.Terrain.SampleHeight(bx, bz);
|
|
if (!session.HasLineOfSight(ax, gyA + 2.5f, az, bx, gyB + 2.5f, bz))
|
|
{
|
|
clear = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (!clear) break;
|
|
}
|
|
if (clear && sites.TrueForAll(s => (s.X - x) * (s.X - x) + (s.Z - z) * (s.Z - z) > 60f * 60f))
|
|
{
|
|
sites.Add((x, z, yaw, ny));
|
|
}
|
|
}
|
|
}
|
|
Assert.NotEmpty(sites);
|
|
|
|
session.SetContenderPose(0, sites[0].X, sites[0].Z, sites[0].Yaw);
|
|
session.State.SpawnChassisDrop(sites[0].X, sites[0].Z, Catalog.Bastion);
|
|
Assert.True(session.TrySwapNearbyChassis(0), "Failed swap to Bastion on Sion");
|
|
var player = session.State.Contenders[0];
|
|
|
|
foreach (var site in sites)
|
|
{
|
|
session.SetContenderPose(0, site.X, site.Z, site.Yaw);
|
|
Vector2 startPos = new(player.X, player.Z);
|
|
Vector2 fwdDir = new(MathF.Sin(site.Yaw), MathF.Cos(site.Yaw));
|
|
float gStart = session.State.Terrain.SampleHeight(player.X, player.Z);
|
|
|
|
for (int t = 0; t < 120; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(
|
|
Throttle: 1f,
|
|
Steer: 0f,
|
|
AimWorldX: player.X + fwdDir.X * 50f,
|
|
AimWorldZ: player.Z + fwdDir.Y * 50f,
|
|
Fire: false,
|
|
InteractPickup: false,
|
|
Brake: false));
|
|
session.Step();
|
|
}
|
|
|
|
float disp2s = Vector2.Dot(new Vector2(player.X, player.Z) - startPos, fwdDir);
|
|
float endSpd = player.Speed;
|
|
float gEnd = session.State.Terrain.SampleHeight(player.X, player.Z);
|
|
var ws = session.GetWalkerState(true, player.Id)!;
|
|
_output.WriteLine(
|
|
$"Bastion Sion 15-22deg site ({site.X:F1},{site.Z:F1}) ny={site.Ny:F3}: " +
|
|
$"disp2s={disp2s:F2}m endSpd={endSpd:F2}m/s climb={(gEnd - gStart):F2}m leanP={ws.LeanPitch * 180f / MathF.PI:F1}deg");
|
|
|
|
Assert.True(disp2s >= 10.0f, $"Bastion beached on Sion hill ny={site.Ny:F3}: disp2s={disp2s:F2}m < 10.0m");
|
|
Assert.True(endSpd >= 6.0f, $"Bastion stalled on Sion hill ny={site.Ny:F3}: endSpd={endSpd:F2}m/s < 6.0m/s");
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Kestrel_5x5Coronal_ArmAndEngineDamage_DoesNotCrippleLegs()
|
|
{
|
|
var grid = new ChassisGrid(Catalog.Kestrel);
|
|
Span<float> legs = stackalloc float[4];
|
|
|
|
// Destroy right weapon arm (4,2),(4,3) and engine core (2,2),(2,3)
|
|
grid.Armor[4, 2] = 0f;
|
|
grid.Armor[4, 3] = 0f;
|
|
grid.Armor[2, 2] = 0f;
|
|
grid.Armor[2, 3] = 0f;
|
|
|
|
grid.GetLegIntegrities(legs);
|
|
Assert.Equal(1.0f, legs[0], precision: 3);
|
|
Assert.Equal(1.0f, legs[1], precision: 3);
|
|
Assert.Equal(1.0f, grid.LegIntegrity, precision: 3);
|
|
|
|
// Destroy left leg (1,4) -> only legs[0] drops
|
|
grid.Armor[1, 4] = 0f;
|
|
grid.GetLegIntegrities(legs);
|
|
Assert.True(legs[0] < 1.0f, $"Expected left leg integrity < 1.0 after (1,4) destroyed, got {legs[0]:F3}");
|
|
Assert.Equal(1.0f, legs[1], precision: 3);
|
|
Assert.True(grid.LegIntegrity < 1.0f);
|
|
|
|
// Destroy right leg (3,4) -> legs[1] also drops
|
|
grid.Armor[3, 4] = 0f;
|
|
grid.GetLegIntegrities(legs);
|
|
Assert.True(legs[1] < 1.0f, $"Expected right leg integrity < 1.0 after (3,4) destroyed, got {legs[1]:F3}");
|
|
}
|
|
|
|
[Fact]
|
|
public void DorsalWalkers_AimedShotsWithSpreadAt80m_DoNotSailOverTop()
|
|
{
|
|
foreach (var spec in new[] { Catalog.Bastion, Catalog.Manticore })
|
|
{
|
|
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true);
|
|
for (int i = 2; i < session.State.Contenders.Count; i++)
|
|
{
|
|
session.SetContenderPose(i, 900f + i * 16f, 900f);
|
|
}
|
|
|
|
// Target contender 1 on flat ground facing perpendicular so silhouette is clean
|
|
session.SetContenderPose(1, 0f, 80f, MathF.PI * 0.5f);
|
|
session.State.Contenders[1].Grid.SwapChassis(spec);
|
|
session.SetContenderPose(1, 0f, 80f, MathF.PI * 0.5f);
|
|
|
|
// Shooter contender 0 at 80m away
|
|
session.SetContenderPose(0, 0f, 0f, 0f);
|
|
for (int t = 0; t < 45; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(0f, 0f, 0f, 80f, false, false, false));
|
|
session.Step();
|
|
}
|
|
|
|
var target = session.State.Contenders[1];
|
|
var shooter = session.State.Contenders[0];
|
|
ulong targetStableId = ArenaSession.ContenderStableIdBase + (ulong)target.Id;
|
|
|
|
float aimY = MatchRules.GetTargetAimY(target.Y, target.Grid.Spec.HalfHeight);
|
|
Vector3 muzzle = new(shooter.X, shooter.Y + shooter.Grid.Spec.HalfHeight * 0.25f, shooter.Z + shooter.Grid.Spec.HalfLength + 0.35f);
|
|
Vector3 baseDir = Vector3.Normalize(new Vector3(target.X - muzzle.X, aimY - muzzle.Y, target.Z - muzzle.Z));
|
|
|
|
var rng = new Random(12345);
|
|
const int shotCount = 250;
|
|
const float totalSpread = 0.015f;
|
|
int overTopMisses = 0;
|
|
int hits = 0;
|
|
|
|
for (int s = 0; s < shotCount; s++)
|
|
{
|
|
float yawJitter = ((float)rng.NextDouble() * 2f - 1f) * totalSpread;
|
|
float pitchJitter = ((float)rng.NextDouble() * 2f - 1f) * (totalSpread * 0.35f);
|
|
var yawQ = Quaternion.CreateFromAxisAngle(Vector3.UnitY, yawJitter);
|
|
var rotated = Vector3.Transform(baseDir, yawQ);
|
|
var right = Vector3.Cross(rotated, Vector3.UnitY);
|
|
if (right.LengthSquared() > 1e-4f)
|
|
{
|
|
rotated = Vector3.Transform(rotated, Quaternion.CreateFromAxisAngle(Vector3.Normalize(right), pitchJitter));
|
|
}
|
|
var dir = Vector3.Normalize(rotated);
|
|
|
|
var hit = session.World.CastRayClosest((muzzle.X, muzzle.Y, muzzle.Z), (dir.X * 160f, dir.Y * 160f, dir.Z * 160f));
|
|
if (hit.Hit && hit.StableId == targetStableId)
|
|
{
|
|
hits++;
|
|
}
|
|
else
|
|
{
|
|
float tPlane = (target.Z - muzzle.Z) / MathF.Max(1e-4f, dir.Z);
|
|
float yAtTarget = muzzle.Y + dir.Y * tPlane;
|
|
if (yAtTarget > target.Y)
|
|
{
|
|
overTopMisses++;
|
|
}
|
|
}
|
|
}
|
|
|
|
float overTopRate = (float)overTopMisses / shotCount;
|
|
_output.WriteLine($"{spec.Id}: 80m hits={hits}/{shotCount}, overTopMisses={overTopMisses} ({overTopRate * 100f:F2}%)");
|
|
Assert.True(overTopRate < 0.02f, $"{spec.Id}: over-top miss rate {overTopRate * 100f:F2}% >= 2%");
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void HybridB_BastionAndManticore_ExactSionSteepHills_ClimbWithoutBeaching()
|
|
{
|
|
var failingSites = new (string Name, float X, float Z)[]
|
|
{
|
|
("Site#9", 459.6f, -385.7f),
|
|
("Site#05mA", -173.6f, 984.8f),
|
|
("Site#7", 0.0f, -580.0f),
|
|
("Site#05mB", 0.0f, -1100.0f),
|
|
};
|
|
|
|
foreach (var spec in new[] { Catalog.Bastion, Catalog.Manticore })
|
|
{
|
|
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true);
|
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
|
{
|
|
session.SetContenderPose(i, 900f + i * 16f, 900f);
|
|
}
|
|
|
|
session.SetContenderPose(0, failingSites[0].X, failingSites[0].Z, 0f);
|
|
session.State.SpawnChassisDrop(failingSites[0].X, failingSites[0].Z, spec);
|
|
Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id}");
|
|
var player = session.State.Contenders[0];
|
|
|
|
foreach (var site in failingSites)
|
|
{
|
|
var (nx, ny, nz) = session.State.Terrain.SampleNormal(site.X, site.Z);
|
|
float uphillYaw = MathF.Atan2(-nx, -nz);
|
|
session.SetContenderPose(0, site.X, site.Z, uphillYaw);
|
|
|
|
Vector2 startPos = new(player.X, player.Z);
|
|
Vector2 fwdDir = new(MathF.Sin(uphillYaw), MathF.Cos(uphillYaw));
|
|
float gStart = session.State.Terrain.SampleHeight(player.X, player.Z);
|
|
|
|
for (int t = 0; t < 120; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(
|
|
Throttle: 1f,
|
|
Steer: 0f,
|
|
AimWorldX: player.X + fwdDir.X * 50f,
|
|
AimWorldZ: player.Z + fwdDir.Y * 50f,
|
|
Fire: false,
|
|
InteractPickup: false,
|
|
Brake: false));
|
|
session.Step();
|
|
}
|
|
|
|
float disp2s = Vector2.Dot(new Vector2(player.X, player.Z) - startPos, fwdDir);
|
|
float endSpd = player.Speed;
|
|
float gEnd = session.State.Terrain.SampleHeight(player.X, player.Z);
|
|
_output.WriteLine(
|
|
$"{spec.Id} {site.Name} ({site.X:F1},{site.Z:F1}) ny={ny:F3}: disp2s={disp2s:F2}m endSpd={endSpd:F2}m/s climb={(gEnd - gStart):F2}m");
|
|
|
|
Assert.True(disp2s >= 8.0f, $"{spec.Id} beached at {site.Name} ({site.X:F1},{site.Z:F1}) ny={ny:F3}: disp2s={disp2s:F2}m < 8.0m");
|
|
Assert.True(endSpd >= 4.0f, $"{spec.Id} stalled at {site.Name} ({site.X:F1},{site.Z:F1}) ny={ny:F3}: endSpd={endSpd:F2}m/s < 4.0m/s");
|
|
}
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void HybridB_Bastion_StationaryFacingHill_DoesNotHyperExtendLegs()
|
|
{
|
|
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true);
|
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
|
{
|
|
session.SetContenderPose(i, 900f + i * 16f, 900f);
|
|
}
|
|
|
|
const float siteX = 0f;
|
|
const float siteZ = -180f;
|
|
var (nx, _, nz) = session.State.Terrain.SampleNormal(siteX, siteZ);
|
|
float uphillYaw = (nx * nx + nz * nz) > 1e-5f ? MathF.Atan2(-nx, -nz) : 0f;
|
|
|
|
session.SetContenderPose(0, siteX, siteZ, uphillYaw);
|
|
session.State.SpawnChassisDrop(siteX, siteZ, Catalog.Bastion);
|
|
Assert.True(session.TrySwapNearbyChassis(0), "Failed swap to Bastion at Site#0");
|
|
session.SetContenderPose(0, siteX, siteZ, uphillYaw);
|
|
|
|
var player = session.State.Contenders[0];
|
|
var ws = session.GetWalkerState(true, player.Id)!;
|
|
float modelRide = WalkerLocomotion.GetRideHeight(Catalog.Bastion);
|
|
float maxRelCom = 0f;
|
|
float maxReachOverflow = 0f;
|
|
|
|
for (int t = 0; t < 120; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(
|
|
Throttle: 0f,
|
|
Steer: 0f,
|
|
AimWorldX: player.X + MathF.Sin(uphillYaw) * 50f,
|
|
AimWorldZ: player.Z + MathF.Cos(uphillYaw) * 50f,
|
|
Fire: false,
|
|
InteractPickup: false,
|
|
Brake: false));
|
|
session.Step();
|
|
|
|
float groundY = session.State.Terrain.SampleHeight(player.X, player.Z);
|
|
float relCom = player.Y - groundY;
|
|
if (relCom > maxRelCom)
|
|
{
|
|
maxRelCom = relCom;
|
|
}
|
|
|
|
Vector3 comPos = new(player.X, player.Y, player.Z);
|
|
Quaternion qBody = new(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
|
Quaternion qLean = Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll);
|
|
Quaternion qTotal = Quaternion.Normalize(qBody * qLean);
|
|
Vector3 pelvisShift = Vector3.Transform(ws.PelvisOffset, qBody);
|
|
for (int leg = 0; leg < ws.Geom.LegCount; leg++)
|
|
{
|
|
Vector3 hipW = comPos + pelvisShift + Vector3.Transform(ws.Geom.Legs[leg].HipInCom * ws.GeomScale, qTotal);
|
|
Vector3 ankleW = ws.FootSole[leg] + ws.FootNormal[leg] * (ws.Geom.Legs[leg].AnkleH * ws.GeomScale);
|
|
float dist = Vector3.Distance(hipW, ankleW);
|
|
float maxReach = ws.Geom.Legs[leg].MaxLegReach * ws.GeomScale;
|
|
float overflow = dist - maxReach;
|
|
if (overflow > maxReachOverflow)
|
|
{
|
|
maxReachOverflow = overflow;
|
|
}
|
|
}
|
|
}
|
|
|
|
_output.WriteLine($"Bastion idle Site#0: maxRelCom={maxRelCom:F3}m (ride={modelRide:F3}m) maxReachOverflow={maxReachOverflow:F4}m");
|
|
Assert.True(maxRelCom <= modelRide + 0.25f, $"Bastion idle COM floated too high: {maxRelCom:F3}m > {modelRide + 0.25f:F3}m");
|
|
Assert.True(maxReachOverflow <= 0.05f, $"Bastion idle leg hyper-extended past MaxLegReach by {maxReachOverflow:F4}m > 0.05m");
|
|
}
|
|
|
|
private static (TerrainField Terrain, float[] Heights, int GridRes, float CellSize, float MinY, float MaxY) MakeSyntheticSlope(float slopeDeg)
|
|
{
|
|
const float sizeMeters = 400f;
|
|
const int gridRes = 201;
|
|
const float cellSize = sizeMeters / (gridRes - 1);
|
|
float half = sizeMeters * 0.5f;
|
|
float tan = MathF.Tan(slopeDeg * MathF.PI / 180f);
|
|
var heights = new float[gridRes * gridRes];
|
|
for (int iz = 0; iz < gridRes; iz++)
|
|
{
|
|
float z = -half + iz * cellSize;
|
|
float h = (z + half) * tan;
|
|
int row = iz * gridRes;
|
|
for (int ix = 0; ix < gridRes; ix++)
|
|
{
|
|
heights[row + ix] = h;
|
|
}
|
|
}
|
|
float minY = -10f;
|
|
float maxY = sizeMeters * tan + 10f;
|
|
var terrain = TerrainField.LoadHeightmap(sizeMeters, gridRes, heights, minY, maxY, seed: 1UL);
|
|
return (terrain, heights, gridRes, cellSize, minY, maxY);
|
|
}
|
|
|
|
private static (Box3DSoaWorld World, Box3DSoaBodyHandle Body, WalkerState Walker, ChassisGrid Grid) SpawnWalkerOnSyntheticTerrain(
|
|
ChassisSpec spec,
|
|
in (TerrainField Terrain, float[] Heights, int GridRes, float CellSize, float MinY, float MaxY) syn,
|
|
float startX,
|
|
float startZ)
|
|
{
|
|
var world = new Box3DSoaWorld(capacity: 8, gravityX: 0f, gravityY: -20f, gravityZ: 0f);
|
|
float half = syn.Terrain.MapHalfExtent;
|
|
world.AddStaticHeightField(
|
|
1UL,
|
|
(-half, 0f, -half),
|
|
syn.Heights,
|
|
syn.GridRes,
|
|
syn.GridRes,
|
|
(syn.CellSize, 1.0f, syn.CellSize),
|
|
syn.MinY,
|
|
syn.MaxY,
|
|
friction: 0.15f,
|
|
restitution: 0.0f);
|
|
|
|
WalkerLocomotion.GetWalkerCapsuleParams(spec, out float capR, out float capHalfL);
|
|
float density = WalkerLocomotion.GetWalkerCapsuleDensity(spec, capR, capHalfL);
|
|
Quaternion q0 = Quaternion.Identity;
|
|
float spawnY = syn.Terrain.SampleHeight(startX, startZ) + capR + capHalfL + 0.02f;
|
|
var body = world.AddCapsule(
|
|
1000UL,
|
|
(startX, spawnY, startZ),
|
|
capR,
|
|
capHalfL,
|
|
density,
|
|
(q0.X, q0.Y, q0.Z, q0.W),
|
|
friction: 0.0f,
|
|
restitution: 0.0f,
|
|
flags: Box3DSoaBodyFlags.LockAngularX
|
|
| Box3DSoaBodyFlags.LockAngularZ
|
|
| Box3DSoaBodyFlags.DisableContactRecycling);
|
|
|
|
var grid = new ChassisGrid(spec);
|
|
var ws = new WalkerState(spec);
|
|
ws.InitializePose(new Vector3(startX, spawnY, startZ), q0, world.View.Mass[body.Lane], syn.Terrain, world, body.Lane);
|
|
return (world, body, ws, grid);
|
|
}
|
|
|
|
[Fact]
|
|
public void HybridB_All7Mechs_BoldWeightedStrides_NoTinyBabySteps()
|
|
{
|
|
var specs = new[]
|
|
{
|
|
Catalog.Breaker,
|
|
Catalog.Paladin,
|
|
Catalog.Raptor,
|
|
Catalog.Spectre,
|
|
Catalog.Kestrel,
|
|
Catalog.Manticore,
|
|
Catalog.Bastion
|
|
};
|
|
var flat = MakeSyntheticSlope(0f);
|
|
|
|
foreach (var spec in specs)
|
|
{
|
|
var (world, body, ws, grid) = SpawnWalkerOnSyntheticTerrain(spec, flat, 0f, -140f);
|
|
using (world)
|
|
{
|
|
int lane = body.Lane;
|
|
var view = world.View;
|
|
int nLegs = ws.Geom.LegCount;
|
|
var prevPlanted = new bool[nLegs];
|
|
var lastPlantTime = new float[nLegs];
|
|
for (int i = 0; i < nLegs; i++)
|
|
{
|
|
prevPlanted[i] = ws.Planted[i];
|
|
lastPlantTime[i] = -1f;
|
|
}
|
|
|
|
var minHipPitch = new float[nLegs];
|
|
var maxHipPitch = new float[nLegs];
|
|
Array.Fill(minHipPitch, float.PositiveInfinity);
|
|
Array.Fill(maxHipPitch, float.NegativeInfinity);
|
|
|
|
double stepDurSum = 0.0;
|
|
int stepDurCount = 0;
|
|
double footSepSum = 0.0;
|
|
double swingTravelSum = 0.0;
|
|
int strideCount = 0;
|
|
|
|
for (int t = 0; t < 180; t++)
|
|
{
|
|
WalkerLocomotion.PreStepWalker(
|
|
ws, grid, flat.Terrain, world, body, view.Mass[lane],
|
|
new Vector3(0f, 0f, grid.Spec.MaxSpeed), 0f, false, ArenaSession.FixedDt);
|
|
world.Step(ArenaSession.FixedDt, ArenaSession.SubStepCount);
|
|
WalkerLocomotion.PostStepWalker(
|
|
ws, grid, flat.Terrain, world, body, view.Mass[lane], ArenaSession.FixedDt);
|
|
|
|
if (t >= 60)
|
|
{
|
|
for (int i = 0; i < nLegs; i++)
|
|
{
|
|
float hp = ws.Actuators[i].Theta.HipPitch;
|
|
if (hp < minHipPitch[i]) minHipPitch[i] = hp;
|
|
if (hp > maxHipPitch[i]) maxHipPitch[i] = hp;
|
|
|
|
bool curPlanted = ws.Planted[i];
|
|
if (!prevPlanted[i] && curPlanted)
|
|
{
|
|
if (lastPlantTime[i] >= 0f)
|
|
{
|
|
float cycleSec = ws.SimTime - lastPlantTime[i];
|
|
stepDurSum += cycleSec * 0.5f;
|
|
stepDurCount++;
|
|
}
|
|
lastPlantTime[i] = ws.SimTime;
|
|
|
|
int partner = i ^ 1;
|
|
float foreAftSep = MathF.Abs(ws.FootSole[i].Z - ws.FootSole[partner].Z);
|
|
float swingTravel = Vector2.Distance(
|
|
new Vector2(ws.SwingTargetSole[i].X, ws.SwingTargetSole[i].Z),
|
|
new Vector2(ws.SwingStartSole[i].X, ws.SwingStartSole[i].Z));
|
|
footSepSum += foreAftSep;
|
|
swingTravelSum += swingTravel;
|
|
strideCount++;
|
|
}
|
|
prevPlanted[i] = curPlanted;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < nLegs; i++)
|
|
{
|
|
prevPlanted[i] = ws.Planted[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
Assert.True(stepDurCount >= 2, $"{spec.Id}: expected >= 2 measured step intervals, got {stepDurCount}");
|
|
Assert.True(strideCount >= 2, $"{spec.Id}: expected >= 2 measured strides, got {strideCount}");
|
|
float avgStepDur = (float)(stepDurSum / stepDurCount);
|
|
float avgFootSep = (float)(footSepSum / strideCount);
|
|
float avgSwingTravel = (float)(swingTravelSum / strideCount);
|
|
float maxHipSwingRad = 0f;
|
|
for (int i = 0; i < nLegs; i++)
|
|
{
|
|
maxHipSwingRad = MathF.Max(maxHipSwingRad, maxHipPitch[i] - minHipPitch[i]);
|
|
}
|
|
|
|
bool isCompact = spec.Id == "breaker" || spec.Id == "manticore";
|
|
float minFootSep = isCompact ? 1.25f : 1.80f;
|
|
|
|
_output.WriteLine(
|
|
$"{spec.Id,-10} stepDur={avgStepDur:F3}s ({1f / avgStepDur:F2} Hz) footToFoot={avgFootSep:F2}m " +
|
|
$"swingTravel={avgSwingTravel:F2}m hipPitchP2P={maxHipSwingRad:F3}rad ({maxHipSwingRad * 180f / MathF.PI:F1}deg)");
|
|
|
|
Assert.True(avgStepDur >= 0.21f,
|
|
$"{spec.Id}: tiny baby-step cadence {avgStepDur:F3}s < 0.21s");
|
|
Assert.True(avgFootSep >= minFootSep,
|
|
$"{spec.Id}: foot-to-foot stride {avgFootSep:F2}m < {minFootSep:F2}m");
|
|
Assert.True(maxHipSwingRad >= 0.45f,
|
|
$"{spec.Id}: insufficient hip-pitch actuator swing {maxHipSwingRad:F3} rad < 0.45 rad");
|
|
}
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void HybridB_All7Mechs_ClimbSmallAndMediumSlopes_6To22Deg_NeverDefeated()
|
|
{
|
|
var specs = new[]
|
|
{
|
|
Catalog.Breaker,
|
|
Catalog.Paladin,
|
|
Catalog.Raptor,
|
|
Catalog.Spectre,
|
|
Catalog.Kestrel,
|
|
Catalog.Manticore,
|
|
Catalog.Bastion
|
|
};
|
|
float[] slopesDeg = { 6f, 12f, 18f, 22f };
|
|
var flat = MakeSyntheticSlope(0f);
|
|
var slopeTerrains = new (float Deg, (TerrainField Terrain, float[] Heights, int GridRes, float CellSize, float MinY, float MaxY) Syn)[slopesDeg.Length];
|
|
for (int s = 0; s < slopesDeg.Length; s++)
|
|
{
|
|
slopeTerrains[s] = (slopesDeg[s], MakeSyntheticSlope(slopesDeg[s]));
|
|
}
|
|
|
|
foreach (var spec in specs)
|
|
{
|
|
float flatSpeed;
|
|
{
|
|
var (world, body, ws, grid) = SpawnWalkerOnSyntheticTerrain(spec, flat, 0f, -140f);
|
|
using (world)
|
|
{
|
|
int lane = body.Lane;
|
|
var view = world.View;
|
|
for (int t = 0; t < 150; t++)
|
|
{
|
|
WalkerLocomotion.PreStepWalker(
|
|
ws, grid, flat.Terrain, world, body, view.Mass[lane],
|
|
new Vector3(0f, 0f, grid.Spec.MaxSpeed), 0f, false, ArenaSession.FixedDt);
|
|
world.Step(ArenaSession.FixedDt, ArenaSession.SubStepCount);
|
|
WalkerLocomotion.PostStepWalker(
|
|
ws, grid, flat.Terrain, world, body, view.Mass[lane], ArenaSession.FixedDt);
|
|
}
|
|
flatSpeed = MathF.Sqrt(view.VelocityX[lane] * view.VelocityX[lane] + view.VelocityZ[lane] * view.VelocityZ[lane]);
|
|
}
|
|
}
|
|
|
|
var summary = $"{spec.Id,-10} flat={flatSpeed:F2}m/s";
|
|
foreach (var (deg, syn) in slopeTerrains)
|
|
{
|
|
var (world, body, ws, grid) = SpawnWalkerOnSyntheticTerrain(spec, syn, 0f, -140f);
|
|
using (world)
|
|
{
|
|
int lane = body.Lane;
|
|
var view = world.View;
|
|
float gStart = syn.Terrain.SampleHeight(0f, -140f);
|
|
float minSpeedAfterAccel = float.PositiveInfinity;
|
|
|
|
for (int t = 0; t < 150; t++)
|
|
{
|
|
WalkerLocomotion.PreStepWalker(
|
|
ws, grid, syn.Terrain, world, body, view.Mass[lane],
|
|
new Vector3(0f, 0f, grid.Spec.MaxSpeed), 0f, false, ArenaSession.FixedDt);
|
|
world.Step(ArenaSession.FixedDt, ArenaSession.SubStepCount);
|
|
WalkerLocomotion.PostStepWalker(
|
|
ws, grid, syn.Terrain, world, body, view.Mass[lane], ArenaSession.FixedDt);
|
|
|
|
if (t >= 30)
|
|
{
|
|
float fwdSpd = view.VelocityZ[lane];
|
|
if (fwdSpd < minSpeedAfterAccel) minSpeedAfterAccel = fwdSpd;
|
|
}
|
|
}
|
|
|
|
float endZ = view.PositionZ[lane];
|
|
float endHorizSpeed = MathF.Sqrt(view.VelocityX[lane] * view.VelocityX[lane] + view.VelocityZ[lane] * view.VelocityZ[lane]);
|
|
float gEnd = syn.Terrain.SampleHeight(view.PositionX[lane], endZ);
|
|
float climbM = gEnd - gStart;
|
|
float dispM = endZ - (-140f);
|
|
float ratio = endHorizSpeed / MathF.Max(1f, flatSpeed);
|
|
float reqRatio = deg <= 12f ? 0.60f : 0.45f;
|
|
|
|
summary += $" | {deg:F0}deg:{endHorizSpeed:F1}m/s({ratio * 100f:F0}%,+{climbM:F1}m,min={minSpeedAfterAccel:F1})";
|
|
|
|
Assert.True(dispM > 12f && climbM > 1.2f,
|
|
$"{spec.Id} @ {deg}deg: failed climb (disp={dispM:F2}m, climb={climbM:F2}m)");
|
|
Assert.True(minSpeedAfterAccel > 4.0f,
|
|
$"{spec.Id} @ {deg}deg: stalled or kicked back (minFwdSpd={minSpeedAfterAccel:F2}m/s)");
|
|
Assert.True(ratio >= reqRatio,
|
|
$"{spec.Id} @ {deg}deg: speed {endHorizSpeed:F2}m/s ({ratio * 100f:F1}% of flat {flatSpeed:F2}) < {reqRatio * 100f:F0}%");
|
|
}
|
|
}
|
|
_output.WriteLine(summary);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void HybridB_All7Mechs_YawRelease_StopsCrisplyWithMinimalCoast()
|
|
{
|
|
var specs = new[]
|
|
{
|
|
Catalog.Breaker,
|
|
Catalog.Paladin,
|
|
Catalog.Raptor,
|
|
Catalog.Spectre,
|
|
Catalog.Kestrel,
|
|
Catalog.Manticore,
|
|
Catalog.Bastion
|
|
};
|
|
|
|
foreach (var spec in specs)
|
|
{
|
|
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true);
|
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
|
{
|
|
session.SetContenderPose(i, 500f + i * 16f, 500f);
|
|
}
|
|
|
|
session.SetContenderPose(0, 0f, 0f, 0f);
|
|
session.State.SpawnChassisDrop(0f, 0f, spec);
|
|
Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id}");
|
|
session.SetContenderPose(0, 0f, 0f, 0f);
|
|
var player = session.State.Contenders[0];
|
|
int lane = session.GetContenderBody(player.Id)!.Value.Lane;
|
|
|
|
// Spin 1.0s at full steer
|
|
for (int t = 0; t < 60; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(
|
|
Throttle: 0f,
|
|
Steer: 1.0f,
|
|
AimWorldX: 0f,
|
|
AimWorldZ: 50f,
|
|
Fire: false,
|
|
InteractPickup: false,
|
|
Brake: false));
|
|
session.Step();
|
|
}
|
|
|
|
float yawAtRelease = player.Yaw;
|
|
float spinAngVelY = session.World.View.AngularVelocityY[lane];
|
|
float maxOvershootRad = 0f;
|
|
float angVelAt020s = 0f;
|
|
|
|
// Release for 0.5s (30 ticks)
|
|
for (int t = 0; t < 30; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(
|
|
Throttle: 0f,
|
|
Steer: 0f,
|
|
AimWorldX: 0f,
|
|
AimWorldZ: 50f,
|
|
Fire: false,
|
|
InteractPickup: false,
|
|
Brake: false));
|
|
session.Step();
|
|
|
|
float overshoot = MathF.Abs(MatchRules.NormalizeAngle(player.Yaw - yawAtRelease));
|
|
if (overshoot > maxOvershootRad)
|
|
{
|
|
maxOvershootRad = overshoot;
|
|
}
|
|
if (t == 11)
|
|
{
|
|
angVelAt020s = session.World.View.AngularVelocityY[lane];
|
|
}
|
|
}
|
|
|
|
_output.WriteLine(
|
|
$"{spec.Id,-10} spinOmegaY={spinAngVelY:F2}rad/s overshoot={maxOvershootRad:F4}rad ({maxOvershootRad * 180f / MathF.PI:F2}deg) " +
|
|
$"omegaY@0.20s={angVelAt020s:F4}rad/s");
|
|
|
|
Assert.True(MathF.Abs(spinAngVelY) > 1.0f,
|
|
$"{spec.Id}: failed to spin up before release (omegaY={spinAngVelY:F2})");
|
|
Assert.True(maxOvershootRad <= 0.08f,
|
|
$"{spec.Id}: yaw coast overshoot {maxOvershootRad:F4} rad ({maxOvershootRad * 180f / MathF.PI:F2} deg) > 0.08 rad");
|
|
Assert.True(MathF.Abs(angVelAt020s) <= 0.05f,
|
|
$"{spec.Id}: residual yaw angVel@0.20s={angVelAt020s:F4} rad/s > 0.05 rad/s");
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void OptionA_All7Mechs_ZeroPhysicsTilt_BoundedVisualLean_DunesSionCurbsAndBlast()
|
|
{
|
|
var specs = new[]
|
|
{
|
|
Catalog.Breaker,
|
|
Catalog.Paladin,
|
|
Catalog.Raptor,
|
|
Catalog.Spectre,
|
|
Catalog.Kestrel,
|
|
Catalog.Manticore,
|
|
Catalog.Bastion
|
|
};
|
|
|
|
const float maxBipedLeanRad = 8.05f * (MathF.PI / 180f);
|
|
const float maxQuadLeanRad = 14.55f * (MathF.PI / 180f);
|
|
|
|
foreach (var spec in specs)
|
|
{
|
|
foreach (var map in new[] { ArenaMapKind.Desert, ArenaMapKind.Sion })
|
|
{
|
|
using var session = new ArenaSession(seed: 42, mapKind: map, slot0Human: true);
|
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
|
{
|
|
session.SetContenderPose(i, 900f + i * 16f, 900f);
|
|
}
|
|
|
|
float startX = 0f;
|
|
float startZ = 0f;
|
|
float startYaw = 0f;
|
|
if (map == ArenaMapKind.Sion && session.State.SionMap is { } sion)
|
|
{
|
|
// Aim near a Sion building plinth/curb so col_*.bin edges are crossed
|
|
foreach (var b in sion.Buildings)
|
|
{
|
|
if (b.HalfX > 4f && b.HalfZ > 4f && MathF.Abs(b.CenterX) < 400f && MathF.Abs(b.CenterZ) < 400f)
|
|
{
|
|
startX = b.CenterX;
|
|
startZ = b.CenterZ - b.HalfZ - 10f;
|
|
startYaw = 0f;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
session.SetContenderPose(0, startX, startZ, startYaw);
|
|
session.State.SpawnChassisDrop(startX, startZ, spec);
|
|
Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id}");
|
|
session.SetContenderPose(0, startX, startZ, startYaw);
|
|
|
|
var player = session.State.Contenders[0];
|
|
var body = session.GetContenderBody(player.Id)!.Value;
|
|
var ws = session.GetWalkerState(true, player.Id)!;
|
|
var view = session.World.View;
|
|
int lane = body.Lane;
|
|
|
|
float maxLeanObserved = 0f;
|
|
for (int t = 0; t < 180; t++)
|
|
{
|
|
if (t == 60 || t == 120)
|
|
{
|
|
// Heavy lateral + slight upward blast knockback impulse
|
|
float mass = view.Mass[lane];
|
|
session.World.ApplyImpulse(
|
|
lane,
|
|
(mass * 7.5f, mass * 2.2f, -mass * 4.5f),
|
|
(view.PositionX[lane], view.PositionY[lane] - 1.0f, view.PositionZ[lane]));
|
|
ws.AddRecoilImpulse(new Vector3(1f, 0f, 0.5f), new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW), 70f);
|
|
}
|
|
|
|
float steer = MathF.Sin(t * 0.08f) * 0.8f;
|
|
session.SetHumanInput(0, new PlayerInput(
|
|
Throttle: 1.0f,
|
|
Steer: steer,
|
|
AimWorldX: player.X + 40f * MathF.Sin(player.Yaw),
|
|
AimWorldZ: player.Z + 40f * MathF.Cos(player.Yaw),
|
|
Fire: false,
|
|
InteractPickup: false,
|
|
Brake: false));
|
|
session.Step();
|
|
|
|
var q = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
|
var up = Vector3.Transform(Vector3.UnitY, q);
|
|
Assert.True(up.Y >= 0.9999f, $"{spec.Id} ({map}) tick {t}: physics body tilted! up.Y={up.Y:F6}");
|
|
Assert.True(MathF.Abs(q.X) <= 1e-3f && MathF.Abs(q.Z) <= 1e-3f,
|
|
$"{spec.Id} ({map}) tick {t}: non-zero q.X/q.Z ({q.X:E2}, {q.Z:E2})");
|
|
|
|
if (spec.Plane == GridPlane.Dorsal)
|
|
{
|
|
float leanNorm = MathF.Sqrt(ws.LeanPitch * ws.LeanPitch + ws.LeanRoll * ws.LeanRoll);
|
|
maxLeanObserved = MathF.Max(maxLeanObserved, leanNorm);
|
|
Assert.True(leanNorm <= maxQuadLeanRad,
|
|
$"{spec.Id} ({map}) tick {t}: dorsal visual lean {leanNorm * 180f / MathF.PI:F2}deg > 14.55deg");
|
|
}
|
|
else
|
|
{
|
|
float absP = MathF.Abs(ws.LeanPitch);
|
|
float absR = MathF.Abs(ws.LeanRoll);
|
|
maxLeanObserved = MathF.Max(maxLeanObserved, MathF.Max(absP, absR));
|
|
Assert.True(absP <= maxBipedLeanRad && absR <= maxBipedLeanRad,
|
|
$"{spec.Id} ({map}) tick {t}: biped visual lean ({absP * 180f / MathF.PI:F2}, {absR * 180f / MathF.PI:F2})deg > 8.05deg");
|
|
}
|
|
}
|
|
|
|
_output.WriteLine($"{spec.Id,-10} {map,-6}: physicsTilt=0.00deg maxVisualLean={maxLeanObserved * 180f / MathF.PI:F2}deg");
|
|
}
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void OptionA_All7Mechs_StepUpCurbs030To060_SmoothNoAirLaunch_TallWallStops()
|
|
{
|
|
var specs = new[]
|
|
{
|
|
Catalog.Breaker,
|
|
Catalog.Paladin,
|
|
Catalog.Raptor,
|
|
Catalog.Spectre,
|
|
Catalog.Kestrel,
|
|
Catalog.Manticore,
|
|
Catalog.Bastion
|
|
};
|
|
|
|
foreach (var spec in specs)
|
|
{
|
|
// 1. Climb 0.30m, 0.45m, 0.60m curbs smoothly without catapulting, then step off 3.0m cliff under -20 m/s^2 gravity
|
|
using (var world = new Box3DSoaWorld(capacity: 16, gravityX: 0f, gravityY: -20f, gravityZ: 0f))
|
|
{
|
|
var terrain = MakeSyntheticSlope(0f).Terrain;
|
|
// Base deck raised +3.0m so walking off the end drops 3.0m down to y=0
|
|
world.AddStaticBox(10UL, (0f, 1.5f, 20f), (30f, 1.5f, 35f), friction: 0.4f, restitution: 0.0f);
|
|
// Curbs along +Z on top of y=3.0m deck: 0.30m, 0.45m, 0.60m
|
|
world.AddStaticBox(11UL, (0f, 3.0f + 0.15f, 14f), (20f, 0.15f, 4f), friction: 0.4f, restitution: 0.0f);
|
|
world.AddStaticBox(12UL, (0f, 3.0f + 0.225f, 26f), (20f, 0.225f, 4f), friction: 0.4f, restitution: 0.0f);
|
|
world.AddStaticBox(13UL, (0f, 3.0f + 0.30f, 40f), (20f, 0.30f, 4f), friction: 0.4f, restitution: 0.0f);
|
|
// Ground slab at y=-0.5m (top at y=0)
|
|
world.AddStaticBox(14UL, (0f, -0.5f, 60f), (30f, 0.5f, 30f), friction: 0.4f, restitution: 0.0f);
|
|
|
|
WalkerLocomotion.GetWalkerCapsuleParams(spec, out float capR, out float capHalfL);
|
|
float density = WalkerLocomotion.GetWalkerCapsuleDensity(spec, capR, capHalfL);
|
|
float spawnY = 3.0f + capR + capHalfL + 0.01f;
|
|
var body = world.AddCapsule(
|
|
1000UL,
|
|
(0f, spawnY, -4f),
|
|
capR,
|
|
capHalfL,
|
|
density,
|
|
(0f, 0f, 0f, 1f),
|
|
friction: 0.0f,
|
|
restitution: 0.0f,
|
|
flags: Box3DSoaBodyFlags.LockAngularX | Box3DSoaBodyFlags.LockAngularZ | Box3DSoaBodyFlags.DisableContactRecycling);
|
|
|
|
var grid = new ChassisGrid(spec);
|
|
var ws = new WalkerState(spec);
|
|
ws.InitializePose(new Vector3(0f, spawnY, -4f), Quaternion.Identity, world.View.Mass[body.Lane], terrain, world, body.Lane);
|
|
Vector3[] prevSoles = new Vector3[ws.Geom.LegCount];
|
|
for (int i = 0; i < ws.Geom.LegCount; i++) prevSoles[i] = ws.FootSole[i];
|
|
|
|
float maxVelY = float.NegativeInfinity;
|
|
float minVelY = float.PositiveInfinity;
|
|
float maxReachedY = 0f;
|
|
float maxCurbFootJump = 0f;
|
|
bool sawCliffFall = false;
|
|
bool sawCliffLandingDip = false;
|
|
var view = world.View;
|
|
int lane = body.Lane;
|
|
|
|
for (int t = 0; t < 420; t++)
|
|
{
|
|
WalkerLocomotion.PreStepWalker(
|
|
ws, grid, terrain, world, body, view.Mass[lane],
|
|
new Vector3(0f, 0f, spec.MaxSpeed), 0f, false, ArenaSession.FixedDt);
|
|
world.Step(ArenaSession.FixedDt, ArenaSession.SubStepCount);
|
|
WalkerLocomotion.PostStepWalker(
|
|
ws, grid, terrain, world, body, view.Mass[lane], ArenaSession.FixedDt);
|
|
|
|
float vy = view.VelocityY[lane];
|
|
maxVelY = MathF.Max(maxVelY, vy);
|
|
minVelY = MathF.Min(minVelY, vy);
|
|
maxReachedY = MathF.Max(maxReachedY, view.PositionY[lane]);
|
|
for (int i = 0; i < ws.Geom.LegCount; i++)
|
|
{
|
|
float j = Vector3.Distance(ws.FootSole[i], prevSoles[i]);
|
|
if (view.PositionZ[lane] <= 88f && view.PositionY[lane] >= -0.5f && j > maxCurbFootJump)
|
|
{
|
|
maxCurbFootJump = j;
|
|
}
|
|
prevSoles[i] = ws.FootSole[i];
|
|
}
|
|
|
|
if (view.PositionZ[lane] > 56f && ws.IsAirborne)
|
|
{
|
|
sawCliffFall = true;
|
|
}
|
|
if (sawCliffFall && ws.Grounded && ws.CompressionY < -0.05f)
|
|
{
|
|
sawCliffLandingDip = true;
|
|
}
|
|
}
|
|
|
|
_output.WriteLine(
|
|
$"{spec.Id,-10} curbs 0.30/0.45/0.60m + 3m cliff: endZ={view.PositionZ[lane]:F1}m maxY={maxReachedY:F2}m " +
|
|
$"maxVy={maxVelY:F2}m/s minVy={minVelY:F2}m/s maxFootJump={maxCurbFootJump:F3}m cliffFall={sawCliffFall} landingDip={sawCliffLandingDip}");
|
|
|
|
Assert.True(view.PositionZ[lane] > 58f, $"{spec.Id}: stalled on 0.30-0.60m curbs (endZ={view.PositionZ[lane]:F1}m)");
|
|
Assert.True(maxReachedY >= 3.0f + 0.55f + capR + capHalfL - 0.05f, $"{spec.Id}: failed to climb 0.60m curb (maxY={maxReachedY:F2}m)");
|
|
Assert.True(maxVelY <= 2.5f, $"{spec.Id}: curb catapult detected! maxVelY={maxVelY:F2}m/s > 2.5m/s");
|
|
Assert.True(maxCurbFootJump < 1.65f, $"{spec.Id}: curb/cliff 1-tick foot teleport {maxCurbFootJump:F3}m >= 1.65m");
|
|
Assert.True(sawCliffFall && minVelY < -3.0f, $"{spec.Id}: failed ballistic freefall off 3m cliff (minVelY={minVelY:F2})");
|
|
Assert.True(sawCliffLandingDip, $"{spec.Id}: expected CompressionY landing dip after 3m cliff drop");
|
|
}
|
|
|
|
// 2. Tall 2.50m wall MUST block the mech cleanly (no wall climbing!)
|
|
using (var world = new Box3DSoaWorld(capacity: 8, gravityX: 0f, gravityY: -20f, gravityZ: 0f))
|
|
{
|
|
var terrain = MakeSyntheticSlope(0f).Terrain;
|
|
world.AddStaticBox(10UL, (0f, -0.5f, 0f), (60f, 0.5f, 60f), friction: 0.4f, restitution: 0.0f);
|
|
world.AddStaticBox(11UL, (0f, 1.25f, 12f), (20f, 1.25f, 2f), friction: 0.4f, restitution: 0.0f);
|
|
|
|
WalkerLocomotion.GetWalkerCapsuleParams(spec, out float capR, out float capHalfL);
|
|
float density = WalkerLocomotion.GetWalkerCapsuleDensity(spec, capR, capHalfL);
|
|
float spawnY = capR + capHalfL + 0.01f;
|
|
var body = world.AddCapsule(
|
|
1000UL,
|
|
(0f, spawnY, 0f),
|
|
capR,
|
|
capHalfL,
|
|
density,
|
|
(0f, 0f, 0f, 1f),
|
|
friction: 0.0f,
|
|
restitution: 0.0f,
|
|
flags: Box3DSoaBodyFlags.LockAngularX | Box3DSoaBodyFlags.LockAngularZ | Box3DSoaBodyFlags.DisableContactRecycling);
|
|
|
|
var grid = new ChassisGrid(spec);
|
|
var ws = new WalkerState(spec);
|
|
ws.InitializePose(new Vector3(0f, spawnY, 0f), Quaternion.Identity, world.View.Mass[body.Lane], terrain, world, body.Lane);
|
|
var view = world.View;
|
|
int lane = body.Lane;
|
|
|
|
for (int t = 0; t < 120; t++)
|
|
{
|
|
WalkerLocomotion.PreStepWalker(
|
|
ws, grid, terrain, world, body, view.Mass[lane],
|
|
new Vector3(0f, 0f, spec.MaxSpeed), 0f, false, ArenaSession.FixedDt);
|
|
world.Step(ArenaSession.FixedDt, ArenaSession.SubStepCount);
|
|
WalkerLocomotion.PostStepWalker(
|
|
ws, grid, terrain, world, body, view.Mass[lane], ArenaSession.FixedDt);
|
|
}
|
|
|
|
Assert.True(view.PositionZ[lane] < 10.2f, $"{spec.Id}: breached/climbed 2.50m tall wall (z={view.PositionZ[lane]:F2}m)");
|
|
Assert.True(view.PositionY[lane] < spawnY + 0.10f, $"{spec.Id}: climbed onto 2.50m tall wall (y={view.PositionY[lane]:F2}m)");
|
|
}
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void OptionA_Bipeds_CoMWeightShift_InvertedPendulum_HeelCompression_ZeroFootSkate()
|
|
{
|
|
var bipeds = new[]
|
|
{
|
|
Catalog.Breaker,
|
|
Catalog.Paladin,
|
|
Catalog.Raptor,
|
|
Catalog.Spectre,
|
|
Catalog.Kestrel
|
|
};
|
|
|
|
foreach (var spec in bipeds)
|
|
{
|
|
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true);
|
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
|
{
|
|
session.SetContenderPose(i, 600f + i * 16f, 600f);
|
|
}
|
|
|
|
session.SetContenderPose(0, 0f, 0f, 0f);
|
|
session.State.SpawnChassisDrop(0f, 0f, spec);
|
|
Assert.True(session.TrySwapNearbyChassis(0));
|
|
session.SetContenderPose(0, 0f, 0f, 0f);
|
|
|
|
var player = session.State.Contenders[0];
|
|
var ws = session.GetWalkerState(true, player.Id)!;
|
|
|
|
float maxLeftPelvisX = float.NegativeInfinity;
|
|
float minRightPelvisX = float.PositiveInfinity;
|
|
float minPelvisY = float.PositiveInfinity;
|
|
float maxPelvisY = float.NegativeInfinity;
|
|
float minCompressionY = float.PositiveInfinity;
|
|
float maxStanceSkate = 0f;
|
|
float peakLoadG = 0f;
|
|
Vector3 prevSole0 = ws.FootSole[0];
|
|
Vector3 prevSole1 = ws.FootSole[1];
|
|
bool prevPlanted0 = ws.Planted[0];
|
|
bool prevPlanted1 = ws.Planted[1];
|
|
|
|
for (int t = 0; t < 180; t++)
|
|
{
|
|
float throttle = t < 130 ? 0.50f : 0.0f;
|
|
session.SetHumanInput(0, new PlayerInput(throttle, 0f, player.X, player.Z + 80f, false, false, false));
|
|
session.Step();
|
|
|
|
if (ws.Planted[0] && !ws.Planted[1])
|
|
{
|
|
maxLeftPelvisX = MathF.Max(maxLeftPelvisX, ws.PelvisOffset.X);
|
|
if (prevPlanted0)
|
|
{
|
|
float skate = Vector2.Distance(new Vector2(ws.FootSole[0].X, ws.FootSole[0].Z), new Vector2(prevSole0.X, prevSole0.Z));
|
|
maxStanceSkate = MathF.Max(maxStanceSkate, skate);
|
|
}
|
|
}
|
|
else if (!ws.Planted[0] && ws.Planted[1])
|
|
{
|
|
minRightPelvisX = MathF.Min(minRightPelvisX, ws.PelvisOffset.X);
|
|
if (prevPlanted1)
|
|
{
|
|
float skate = Vector2.Distance(new Vector2(ws.FootSole[1].X, ws.FootSole[1].Z), new Vector2(prevSole1.X, prevSole1.Z));
|
|
maxStanceSkate = MathF.Max(maxStanceSkate, skate);
|
|
}
|
|
}
|
|
|
|
if (t >= 20 && t < 130)
|
|
{
|
|
minPelvisY = MathF.Min(minPelvisY, ws.PelvisOffset.Y);
|
|
maxPelvisY = MathF.Max(maxPelvisY, ws.PelvisOffset.Y);
|
|
minCompressionY = MathF.Min(minCompressionY, ws.CompressionY);
|
|
}
|
|
peakLoadG = MathF.Max(peakLoadG, MathF.Max(ws.LoadG[0], ws.LoadG[1]));
|
|
|
|
prevSole0 = ws.FootSole[0];
|
|
prevSole1 = ws.FootSole[1];
|
|
prevPlanted0 = ws.Planted[0];
|
|
prevPlanted1 = ws.Planted[1];
|
|
}
|
|
|
|
float pelvisYRange = maxPelvisY - minPelvisY;
|
|
_output.WriteLine(
|
|
$"{spec.Id,-10} ZMP_X=[{minRightPelvisX:F3}, +{maxLeftPelvisX:F3}]m pelvisYRange={pelvisYRange:F3}m " +
|
|
$"minCompY={minCompressionY:F3}m maxSkate={maxStanceSkate:F4}m peakLoadG={peakLoadG:F2}G");
|
|
|
|
Assert.True(maxLeftPelvisX > 0.10f, $"{spec.Id}: expected positive ZMP shift over Left stance foot, got {maxLeftPelvisX:F3}m");
|
|
Assert.True(minRightPelvisX < -0.10f, $"{spec.Id}: expected negative ZMP shift over Right stance foot, got {minRightPelvisX:F3}m");
|
|
Assert.True(pelvisYRange >= 0.05f, $"{spec.Id}: expected inverted-pendulum + compression vertical arc >= 0.05m, got {pelvisYRange:F3}m");
|
|
Assert.True(minCompressionY < -0.025f, $"{spec.Id}: expected heel-strike CompressionY dip < -0.025m, got {minCompressionY:F3}m");
|
|
Assert.True(maxStanceSkate < 0.03f, $"{spec.Id}: stance foot skated {maxStanceSkate:F4}m >= 0.03m");
|
|
Assert.True(peakLoadG >= 0.24f, $"{spec.Id}: expected LoadG >= 0.24G for footstep tracker");
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void OptionA_SnapshotCodec_RoundTripsPelvisAndLean_Within1152Bytes()
|
|
{
|
|
var state = new MatchState(seed: 42, ArenaMapKind.Desert);
|
|
var local = state.Contenders[0];
|
|
local.Grid.SwapChassis(Catalog.Bastion);
|
|
|
|
var contenders = new List<NetContenderState>(12);
|
|
var walkers = new List<NetWalkerEntry>(12);
|
|
var specs = new List<NetSpectatorState>(8);
|
|
|
|
for (int i = 0; i < 12; i++)
|
|
{
|
|
contenders.Add(new NetContenderState
|
|
{
|
|
SlotId = (byte)i,
|
|
Alive = true,
|
|
IsHuman = true,
|
|
Pos = new Vector3(i * 10f, 4f, -i * 5f),
|
|
Rot = Quaternion.Identity,
|
|
Vel = new Vector3(5f, 0f, 2f)
|
|
});
|
|
var ws = new WalkerVisualSnapshot
|
|
{
|
|
LegCount = 4,
|
|
PelvisOffset = new Vector3(0.32f, -0.11f, 0.04f),
|
|
LeanPitch = 0.11f,
|
|
LeanRoll = -0.14f
|
|
};
|
|
for (int l = 0; l < 4; l++)
|
|
{
|
|
ws.LegAngles[l] = new WalkerLegAngles { HipPitch = 0.3f, HipRoll = 0.1f, KneeFlex = -0.6f, AnklePitch = 0.15f };
|
|
ws.FootNormal[l] = Vector3.UnitY;
|
|
ws.LoadG[l] = 1.1f;
|
|
}
|
|
walkers.Add(new NetWalkerEntry { IsContender = true, EntityId = (byte)i, Snapshot = ws });
|
|
}
|
|
|
|
byte[] payload = SnapshotCodec.EncodeCorePvs(
|
|
1, 42, 84, 1.4f, 10, 100, 450f, MatchPhase.Active, null, 2, 0xFFF,
|
|
local, new Vector3(0.1f, 0.2f, 0.05f), contenders, walkers, specs);
|
|
byte[] wire = SnapshotCodec.WrapLatest(payload, 1, 1);
|
|
byte[] udp = CultNetRudpPacketCodec.Encode(new CultNetRudpPacket
|
|
{
|
|
ConnectionId = 0x52544431,
|
|
PacketType = CultNetRudpPacketType.Data,
|
|
ChannelId = SnapshotCodec.ChannelLatest,
|
|
Sequence = 1,
|
|
Sequenced = true,
|
|
Payload = wire
|
|
});
|
|
|
|
Assert.True(payload.Length <= SnapshotCodec.MaxLatestPayloadBytes,
|
|
$"Payload {payload.Length}B > {SnapshotCodec.MaxLatestPayloadBytes}B");
|
|
Assert.True(udp.Length <= SnapshotCodec.MaxLatestDatagramBytes,
|
|
$"UDP {udp.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
|
|
Assert.True(SnapshotCodec.TryDecodeCorePvs(payload, out var dec));
|
|
Assert.NotEmpty(dec.Walkers);
|
|
var s0 = dec.Walkers[0].Snapshot;
|
|
Assert.InRange(s0.PelvisOffset.X, 0.30f, 0.34f);
|
|
Assert.InRange(s0.PelvisOffset.Y, -0.13f, -0.09f);
|
|
Assert.InRange(s0.LeanPitch, 0.10f, 0.12f);
|
|
Assert.InRange(s0.LeanRoll, -0.15f, -0.13f);
|
|
}
|
|
|
|
[Fact]
|
|
public void OptionA_AirborneFreefall_FeetClampAboveGround_AndStayWithin3DReach()
|
|
{
|
|
var specs = new[] { Catalog.Breaker, Catalog.Spectre, Catalog.Manticore, Catalog.Bastion };
|
|
foreach (var spec in specs)
|
|
{
|
|
foreach (var map in new[] { ArenaMapKind.Desert, ArenaMapKind.Sion })
|
|
{
|
|
using var session = new ArenaSession(seed: 42, mapKind: map, slot0Human: true);
|
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
|
{
|
|
session.SetContenderPose(i, 900f + i * 16f, 900f);
|
|
}
|
|
|
|
float dropX = 0f;
|
|
float dropZ = 0f;
|
|
if (map == ArenaMapKind.Sion && session.State.SionMap is { } sion)
|
|
{
|
|
bool found = false;
|
|
for (float r = 0f; r <= 300f && !found; r += 15f)
|
|
{
|
|
for (int a = 0; a < 24 && !found; a++)
|
|
{
|
|
float ang = a * (MathF.Tau / 24f);
|
|
float tx = MathF.Cos(ang) * r;
|
|
float tz = MathF.Sin(ang) * r;
|
|
if (!sion.IsInsideAnyBuildingXz(tx, tz, 12f) &&
|
|
session.State.Terrain.SampleNormal(tx, tz).Ny >= 0.96f)
|
|
{
|
|
dropX = tx;
|
|
dropZ = tz;
|
|
found = true;
|
|
}
|
|
}
|
|
}
|
|
Assert.True(found, "Expected flat open spot on Sion");
|
|
}
|
|
|
|
session.SetContenderPose(0, dropX, dropZ, 0f);
|
|
session.State.SpawnChassisDrop(dropX, dropZ, spec);
|
|
Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id}");
|
|
session.SetContenderPose(0, dropX, dropZ, 0f);
|
|
|
|
var player = session.State.Contenders[0];
|
|
var body = session.GetContenderBody(player.Id)!.Value;
|
|
var ws = session.GetWalkerState(true, player.Id)!;
|
|
var view = session.World.View;
|
|
int lane = body.Lane;
|
|
|
|
float groundY = session.QueryDropSurface(dropX, dropZ, 0f, 120f).SurfaceY;
|
|
float physHalfH = MatchRules.GetPhysicsHalfHeight(spec);
|
|
session.World.SetBodyMotion(
|
|
body,
|
|
position: (dropX, groundY + physHalfH + 16f, dropZ),
|
|
linearVelocity: (0f, -2.0f, 0f),
|
|
angularVelocity: (0f, 0f, 0f));
|
|
WalkerLocomotion.PostStepWalker(ws, player.Grid, session.State.Terrain, session.World, body, view.Mass[lane], ArenaSession.FixedDt);
|
|
Assert.True(ws.IsAirborne, $"{spec.Id} ({map}): must start airborne at +16m");
|
|
|
|
Vector3[] prevSoles = new Vector3[ws.Geom.LegCount];
|
|
for (int i = 0; i < ws.Geom.LegCount; i++) prevSoles[i] = ws.FootSole[i];
|
|
bool sawAirborne = false;
|
|
bool landed = false;
|
|
int settledTicks = 0;
|
|
|
|
for (int t = 0; t < 240; t++)
|
|
{
|
|
bool wasAirborne = ws.IsAirborne;
|
|
session.SetHumanInput(0, new PlayerInput(0.35f, 0f, dropX, dropZ + 50f, false, false, false));
|
|
session.Step();
|
|
|
|
var comPos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
|
var qYaw = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
|
var qTotal = Quaternion.Normalize(qYaw * Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll));
|
|
Vector3 pelvisWorld = Vector3.Transform(ws.PelvisOffset, qYaw);
|
|
|
|
for (int i = 0; i < ws.Geom.LegCount; i++)
|
|
{
|
|
Vector3 sole = ws.FootSole[i];
|
|
float surfUnderFoot = session.QueryDropSurface(sole.X, sole.Z, 0f, comPos.Y + 1.0f).SurfaceY;
|
|
if (ws.IsAirborne)
|
|
{
|
|
sawAirborne = true;
|
|
Assert.True(sole.Y >= surfUnderFoot - 0.05f,
|
|
$"{spec.Id} ({map}) tick {t} leg {i}: airborne foot plunged underground ({sole.Y:F3} < {surfUnderFoot:F3})");
|
|
}
|
|
|
|
Vector3 hipWorld = comPos + pelvisWorld + Vector3.Transform(ws.Geom.Legs[i].HipInCom * ws.GeomScale, qTotal);
|
|
Vector3 ankleWorld = sole + ws.FootNormal[i] * (ws.Geom.Legs[i].AnkleH * ws.GeomScale);
|
|
float dist3D = Vector3.Distance(ankleWorld, hipWorld);
|
|
float maxReach = ws.Geom.Legs[i].MaxLegReach * ws.GeomScale;
|
|
Assert.True(dist3D <= maxReach + 0.14f,
|
|
$"{spec.Id} ({map}) tick {t} leg {i}: 3D reach overflow {dist3D:F3} > {maxReach:F3}");
|
|
|
|
float footDelta = Vector3.Distance(sole, prevSoles[i]);
|
|
float maxAllowedDelta = (wasAirborne || ws.IsAirborne)
|
|
? 1.25f * MathF.Max(1f, ws.GeomScale)
|
|
: 1.65f * MathF.Max(1f, ws.GeomScale);
|
|
Assert.True(footDelta < maxAllowedDelta,
|
|
$"{spec.Id} ({map}) tick {t} leg {i}: foot teleport delta {footDelta:F3}m >= {maxAllowedDelta:F3}m");
|
|
prevSoles[i] = sole;
|
|
}
|
|
|
|
if (!ws.IsAirborne)
|
|
{
|
|
landed = true;
|
|
settledTicks++;
|
|
if (settledTicks >= 20) break;
|
|
}
|
|
}
|
|
|
|
Assert.True(sawAirborne, $"{spec.Id} ({map}): never observed airborne state");
|
|
Assert.True(landed, $"{spec.Id} ({map}): walker failed to land within 240 ticks");
|
|
}
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void OptionA_SteepSionAndDesertSlopes_ReachClamped_KestrelUphillGrounded_LowBlastNotZeroed()
|
|
{
|
|
// 1. Steep slope 3D reach & slip check for Bastion & Manticore on Sion steep hill + Desert slope
|
|
using (var sionSession = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true))
|
|
{
|
|
for (int i = 1; i < sionSession.State.Contenders.Count; i++)
|
|
{
|
|
sionSession.SetContenderPose(i, 900f + i * 16f, 900f);
|
|
}
|
|
|
|
var sion = sionSession.State.SionMap!;
|
|
(float X, float Z, float Yaw) steepSite = default;
|
|
bool foundSteep = false;
|
|
float bestMinNy = 1f;
|
|
for (float r = 40f; r <= 950f; r += 20f)
|
|
{
|
|
for (int a = 0; a < 72; a++)
|
|
{
|
|
float ang = a * (MathF.Tau / 72f);
|
|
float x = MathF.Cos(ang) * r;
|
|
float z = MathF.Sin(ang) * r;
|
|
if (sion.IsInsideAnyBuildingXz(x, z, 14f)) continue;
|
|
var (nx, ny, nz) = sionSession.State.Terrain.SampleNormal(x, z);
|
|
if (ny >= 0.78f && ny <= 0.88f && ny < bestMinNy)
|
|
{
|
|
bestMinNy = ny;
|
|
steepSite = (x, z, MathF.Atan2(-nx, -nz));
|
|
foundSteep = true;
|
|
}
|
|
}
|
|
}
|
|
Assert.True(foundSteep, "Expected a clear ~28-38 deg steep hill spot on Sion");
|
|
|
|
foreach (var spec in new[] { Catalog.Bastion, Catalog.Manticore })
|
|
{
|
|
sionSession.SetContenderPose(0, steepSite.X, steepSite.Z, steepSite.Yaw + MathF.PI * 0.5f);
|
|
sionSession.State.SpawnChassisDrop(steepSite.X, steepSite.Z, spec);
|
|
Assert.True(sionSession.TrySwapNearbyChassis(0));
|
|
sionSession.SetContenderPose(0, steepSite.X, steepSite.Z, steepSite.Yaw + MathF.PI * 0.5f);
|
|
|
|
var player = sionSession.State.Contenders[0];
|
|
var body = sionSession.GetContenderBody(player.Id)!.Value;
|
|
var ws = sionSession.GetWalkerState(true, player.Id)!;
|
|
var view = sionSession.World.View;
|
|
int lane = body.Lane;
|
|
Vector3[] prevSoles = new Vector3[ws.Geom.LegCount];
|
|
for (int i = 0; i < ws.Geom.LegCount; i++) prevSoles[i] = ws.FootSole[i];
|
|
|
|
for (int t = 0; t < 120; t++)
|
|
{
|
|
sionSession.SetHumanInput(0, new PlayerInput(1.0f, 0.25f, player.X + 40f * MathF.Sin(player.Yaw), player.Z + 40f * MathF.Cos(player.Yaw), false, false, false));
|
|
sionSession.Step();
|
|
|
|
var comPos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
|
var qYaw = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
|
var qTotal = Quaternion.Normalize(qYaw * Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll));
|
|
Vector3 pelvisWorld = Vector3.Transform(ws.PelvisOffset, qYaw);
|
|
for (int i = 0; i < ws.Geom.LegCount; i++)
|
|
{
|
|
Vector3 hipWorld = comPos + pelvisWorld + Vector3.Transform(ws.Geom.Legs[i].HipInCom * ws.GeomScale, qTotal);
|
|
Vector3 ankleWorld = ws.FootSole[i] + ws.FootNormal[i] * (ws.Geom.Legs[i].AnkleH * ws.GeomScale);
|
|
float dist3D = Vector3.Distance(ankleWorld, hipWorld);
|
|
float maxReach = ws.Geom.Legs[i].MaxLegReach * ws.GeomScale;
|
|
float reachLimit = ws.Planted[i] ? maxReach + 0.05f : maxReach * 1.02f + 0.03f;
|
|
Assert.True(dist3D <= reachLimit,
|
|
$"{spec.Id} Sion steep slope tick {t} leg {i}: 3D reach overflow {dist3D:F3} > {reachLimit:F3}");
|
|
|
|
float soleGroundY = sionSession.QueryDropSurface(ws.FootSole[i].X, ws.FootSole[i].Z, 0f, comPos.Y + 1.0f).SurfaceY;
|
|
float soleRel = ws.FootSole[i].Y - soleGroundY;
|
|
Assert.True(soleRel >= -0.20f,
|
|
$"{spec.Id} Sion steep slope tick {t} leg {i}: sole plunged underground {soleRel:F3}m");
|
|
|
|
float footJump = Vector3.Distance(ws.FootSole[i], prevSoles[i]);
|
|
float maxJump = 1.65f * MathF.Max(1f, ws.GeomScale);
|
|
Assert.True(footJump < maxJump,
|
|
$"{spec.Id} Sion steep slope tick {t} leg {i}: teleport jump {footJump:F3}m >= {maxJump:F3}m");
|
|
prevSoles[i] = ws.FootSole[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
// 2. Kestrel + Spectre + ExemplarFrame sprinting uphill at steepSite must stay grounded with zero non-blast launches & < 1.65m foot deltas
|
|
foreach (var sprintSpec in new[] { Catalog.Kestrel, Catalog.Spectre, MakeExemplarSpec() })
|
|
{
|
|
float startX = steepSite.X;
|
|
float startZ = steepSite.Z;
|
|
float startYaw = steepSite.Yaw;
|
|
sionSession.SetContenderPose(0, startX, startZ, startYaw);
|
|
if (sprintSpec.Id != "exemplar_frame")
|
|
{
|
|
sionSession.State.SpawnChassisDrop(startX, startZ, sprintSpec);
|
|
Assert.True(sionSession.TrySwapNearbyChassis(0));
|
|
}
|
|
else
|
|
{
|
|
sionSession.State.Contenders[0].Grid.SwapChassis(sprintSpec);
|
|
}
|
|
sionSession.SetContenderPose(0, startX, startZ, startYaw);
|
|
|
|
var contender = sionSession.State.Contenders[0];
|
|
var cBody = sionSession.GetContenderBody(contender.Id)!.Value;
|
|
var cWs = sionSession.GetWalkerState(true, contender.Id)!;
|
|
var cView = sionSession.World.View;
|
|
int cLane = cBody.Lane;
|
|
int airborneTicks = 0;
|
|
float maxVelY = 0f;
|
|
float maxAboveGround = 0f;
|
|
float maxFootJump = 0f;
|
|
float minSoleRel = float.PositiveInfinity;
|
|
var prevSprintSoles = new Vector3[cWs.Geom.LegCount];
|
|
for (int i = 0; i < prevSprintSoles.Length; i++) prevSprintSoles[i] = cWs.FootSole[i];
|
|
|
|
for (int t = 0; t < 120; t++)
|
|
{
|
|
float aimYaw = startYaw;
|
|
var (nx, ny, nz) = sionSession.State.Terrain.SampleNormal(contender.X, contender.Z);
|
|
if (ny < 0.995f) aimYaw = MathF.Atan2(-nx, -nz);
|
|
sionSession.SetHumanInput(0, new PlayerInput(
|
|
1.0f,
|
|
0f,
|
|
contender.X + 40f * MathF.Sin(aimYaw),
|
|
contender.Z + 40f * MathF.Cos(aimYaw),
|
|
false, false, false));
|
|
sionSession.Step();
|
|
|
|
if (cWs.IsAirborne) airborneTicks++;
|
|
maxVelY = MathF.Max(maxVelY, cView.VelocityY[cLane]);
|
|
float surfY = sionSession.QueryDropSurface(contender.X, contender.Z, 0f, contender.Y + 1.0f).SurfaceY;
|
|
maxAboveGround = MathF.Max(maxAboveGround, contender.Y - (surfY + MatchRules.GetRideHeight(sprintSpec)));
|
|
for (int i = 0; i < cWs.Geom.LegCount; i++)
|
|
{
|
|
float j = Vector3.Distance(cWs.FootSole[i], prevSprintSoles[i]);
|
|
if (j > maxFootJump) maxFootJump = j;
|
|
prevSprintSoles[i] = cWs.FootSole[i];
|
|
float sY = sionSession.QueryDropSurface(cWs.FootSole[i].X, cWs.FootSole[i].Z, 0f, contender.Y + 1.0f).SurfaceY;
|
|
minSoleRel = MathF.Min(minSoleRel, cWs.FootSole[i].Y - sY);
|
|
}
|
|
}
|
|
|
|
Assert.True(airborneTicks <= 3, $"{sprintSpec.Id} Sion sprint false-launched for {airborneTicks}/120 ticks!");
|
|
Assert.True(maxVelY < 9.5f, $"{sprintSpec.Id} Sion sprint maxVelY spiked to {maxVelY:F2} m/s");
|
|
Assert.True(maxAboveGround < 0.85f, $"{sprintSpec.Id} Sion sprint lifted {maxAboveGround:F2}m above ride height");
|
|
Assert.True(maxFootJump < 1.65f * MathF.Max(1f, cWs.GeomScale), $"{sprintSpec.Id} Sion sprint foot teleport {maxFootJump:F3}m >= 1.65m");
|
|
Assert.True(minSoleRel >= -0.20f, $"{sprintSpec.Id} Sion sprint sole underground {minSoleRel:F3}m < -0.20m");
|
|
}
|
|
}
|
|
|
|
// 3. Low upward splash impulse (< 3.5 m/s) must NOT be zeroed out on tick 1
|
|
foreach (var spec in new[] { Catalog.Breaker, Catalog.Bastion })
|
|
{
|
|
using var session = new ArenaSession(seed: 7, mapKind: ArenaMapKind.Desert, slot0Human: true);
|
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
|
{
|
|
session.SetContenderPose(i, 900f + i * 16f, 900f);
|
|
}
|
|
|
|
session.SetContenderPose(0, 0f, 0f, 0f);
|
|
session.State.SpawnChassisDrop(0f, 0f, spec);
|
|
Assert.True(session.TrySwapNearbyChassis(0));
|
|
session.SetContenderPose(0, 0f, 0f, 0f);
|
|
|
|
for (int settle = 0; settle < 10; settle++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(0f, 0f, 0f, 40f, false, false, false));
|
|
session.Step();
|
|
}
|
|
|
|
var player = session.State.Contenders[0];
|
|
var body = session.GetContenderBody(player.Id)!.Value;
|
|
var ws = session.GetWalkerState(true, player.Id)!;
|
|
var view = session.World.View;
|
|
int lane = body.Lane;
|
|
float mass = view.Mass[lane];
|
|
const float impulseVy = 2.6f; // intentionally below legacy 3.5 m/s bug threshold
|
|
|
|
ws.NotifyExternalUpwardImpulse(impulseVy);
|
|
session.World.ApplyImpulse(lane, (0f, mass * impulseVy, 0f), (view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]));
|
|
session.SetHumanInput(0, new PlayerInput(0f, 0f, 0f, 40f, false, false, false));
|
|
session.Step();
|
|
|
|
float postStepVy = view.VelocityY[lane];
|
|
Assert.True(postStepVy >= 1.5f,
|
|
$"{spec.Id}: genuine {impulseVy:F1} m/s upward blast was suppressed on tick 1 (postStepVy={postStepVy:F2})");
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void OptionA_SionRoofPodTouchdown_WalkerClearsRoofAndWalksUpright()
|
|
{
|
|
foreach (var spec in new[] { Catalog.Bastion, Catalog.Breaker })
|
|
{
|
|
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true);
|
|
var sion = session.State.SionMap!;
|
|
|
|
SionBuildingAabb? flatRoofBldg = null;
|
|
for (int i = 0; i < sion.Buildings.Count; i++)
|
|
{
|
|
var b = sion.Buildings[i];
|
|
if (b.Class == "Gebaeude Einzelhaus" &&
|
|
b.HalfX >= 7f && b.HalfZ >= 7f &&
|
|
(b.RoofY - b.GroundY) >= 10f &&
|
|
MathF.Abs(b.CenterX) < 800f && MathF.Abs(b.CenterZ) < 800f)
|
|
{
|
|
var sample = session.QueryDropSurface(b.CenterX, b.CenterZ, 1.65f, b.RoofY + 20f);
|
|
if (sample.IsBuildingRoof && sample.IsFlatRoofValid)
|
|
{
|
|
flatRoofBldg = b;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
Assert.NotNull(flatRoofBldg);
|
|
var fr = flatRoofBldg!.Value;
|
|
|
|
var player = session.State.Contenders[0];
|
|
player.Grid.SwapChassis(spec);
|
|
var roofPod = session.State.OrbitalDrop.LaunchContenderPod(
|
|
player, 0, fr.CenterX, fr.CenterZ, 0f, session.QueryDropSurface, isRespawn: false);
|
|
roofPod.AllowFlatRoofLanding = true;
|
|
|
|
for (int t = 0; t < 2200 && !player.IsGroundedActive; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 20f, false, false, false));
|
|
session.Step();
|
|
}
|
|
|
|
Assert.True(player.IsGroundedActive, $"{spec.Id}: pod did not touch down within 2200 ticks");
|
|
Assert.True(player.TouchdownOnRoof, $"{spec.Id}: expected TouchdownOnRoof == true");
|
|
|
|
float expectedRideH = MatchRules.GetRideHeight(spec);
|
|
Assert.True(player.Y >= fr.RoofY + expectedRideH - 0.08f,
|
|
$"{spec.Id}: roof spawn buried below ride height ({player.Y:F3} < {fr.RoofY + expectedRideH - 0.08f:F3}, roofY={fr.RoofY:F3})");
|
|
|
|
var qLanding = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
|
var upLanding = Vector3.Transform(Vector3.UnitY, qLanding);
|
|
Assert.True(upLanding.Y >= 0.9995f, $"{spec.Id}: roof landing tilted! up.Y={upLanding.Y:F5}");
|
|
|
|
// Walk forward gently on roof: stays above roof height and stays upright
|
|
for (int t = 0; t < 25; t++)
|
|
{
|
|
session.SetHumanInput(0, new PlayerInput(0.45f, 0f, player.X, player.Z + 25f, false, false, false));
|
|
session.Step();
|
|
|
|
var q = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
|
var up = Vector3.Transform(Vector3.UnitY, q);
|
|
Assert.True(up.Y >= 0.9995f, $"{spec.Id} roof walk tick {t}: tilted up.Y={up.Y:F5}");
|
|
Assert.True(player.Y >= fr.RoofY + expectedRideH - 0.30f,
|
|
$"{spec.Id} roof walk tick {t}: sank into roof ({player.Y:F3} < {fr.RoofY + expectedRideH - 0.30f:F3})");
|
|
}
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void SoulPass3_KestrelSionUphillLowSplash_NoSlopeContactPumping_LandsCleanly()
|
|
{
|
|
using var sionSession = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true);
|
|
for (int i = 1; i < sionSession.State.Contenders.Count; i++)
|
|
{
|
|
sionSession.SetContenderPose(i, 900f + i * 16f, 900f);
|
|
}
|
|
|
|
var sion = sionSession.State.SionMap!;
|
|
(float X, float Z, float Yaw) steepSite = default;
|
|
float bestMinNy = 1f;
|
|
for (float r = 40f; r <= 950f; r += 20f)
|
|
{
|
|
for (int a = 0; a < 72; a++)
|
|
{
|
|
float ang = a * (MathF.Tau / 72f);
|
|
float x = MathF.Cos(ang) * r;
|
|
float z = MathF.Sin(ang) * r;
|
|
if (sion.IsInsideAnyBuildingXz(x, z, 14f)) continue;
|
|
var (nx, ny, nz) = sionSession.State.Terrain.SampleNormal(x, z);
|
|
if (ny >= 0.78f && ny <= 0.88f && ny < bestMinNy)
|
|
{
|
|
bestMinNy = ny;
|
|
steepSite = (x, z, MathF.Atan2(-nx, -nz));
|
|
}
|
|
}
|
|
}
|
|
|
|
sionSession.SetContenderPose(0, steepSite.X, steepSite.Z, steepSite.Yaw);
|
|
sionSession.State.SpawnChassisDrop(steepSite.X, steepSite.Z, Catalog.Kestrel);
|
|
Assert.True(sionSession.TrySwapNearbyChassis(0));
|
|
sionSession.SetContenderPose(0, steepSite.X, steepSite.Z, steepSite.Yaw);
|
|
|
|
var player = sionSession.State.Contenders[0];
|
|
var body = sionSession.GetContenderBody(player.Id)!.Value;
|
|
var ws = sionSession.GetWalkerState(true, player.Id)!;
|
|
var view = sionSession.World.View;
|
|
int lane = body.Lane;
|
|
|
|
for (int t = 0; t < 25; t++)
|
|
{
|
|
var (nx, ny, nz) = sionSession.State.Terrain.SampleNormal(player.X, player.Z);
|
|
float aimYaw = ny < 0.995f ? MathF.Atan2(-nx, -nz) : steepSite.Yaw;
|
|
sionSession.SetHumanInput(0, new PlayerInput(
|
|
1.0f, 0f,
|
|
player.X + 40f * MathF.Sin(aimYaw),
|
|
player.Z + 40f * MathF.Cos(aimYaw),
|
|
false, false, false));
|
|
sionSession.Step();
|
|
}
|
|
|
|
float preBlastVy = view.VelocityY[lane];
|
|
float mass = view.Mass[lane];
|
|
const float splashVy = 2.25f;
|
|
ws.NotifyExternalUpwardImpulse(splashVy);
|
|
sionSession.World.ApplyImpulse(lane, (0f, mass * splashVy, 0f), (view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]));
|
|
|
|
float maxVyAfterBlast = float.NegativeInfinity;
|
|
float tick1Vy = 0f;
|
|
bool regroundedAfterBlast = false;
|
|
float maxAboveSlope = 0f;
|
|
float rideH = MatchRules.GetRideHeight(Catalog.Kestrel);
|
|
for (int t = 0; t < 60; t++)
|
|
{
|
|
var (nx, ny, nz) = sionSession.State.Terrain.SampleNormal(player.X, player.Z);
|
|
float aimYaw = ny < 0.995f ? MathF.Atan2(-nx, -nz) : steepSite.Yaw;
|
|
sionSession.SetHumanInput(0, new PlayerInput(
|
|
1.0f, 0f,
|
|
player.X + 40f * MathF.Sin(aimYaw),
|
|
player.Z + 40f * MathF.Cos(aimYaw),
|
|
false, false, false));
|
|
sionSession.Step();
|
|
|
|
float vy = view.VelocityY[lane];
|
|
if (t == 0) tick1Vy = vy;
|
|
maxVyAfterBlast = MathF.Max(maxVyAfterBlast, vy);
|
|
float surfY = sionSession.QueryDropSurface(player.X, player.Z, 0f, player.Y + 1.0f).SurfaceY;
|
|
maxAboveSlope = MathF.Max(maxAboveSlope, player.Y - (surfY + rideH));
|
|
if (t > 0 && ws.Grounded) regroundedAfterBlast = true;
|
|
}
|
|
|
|
_output.WriteLine($"Kestrel Sion uphill 2.25m/s splash: preVy={preBlastVy:F2}, tick1Vy={tick1Vy:F2}, maxVy={maxVyAfterBlast:F2}, maxAboveSlope={maxAboveSlope:F2}m, landed={regroundedAfterBlast}");
|
|
Assert.True(tick1Vy > preBlastVy + 0.5f, $"Kestrel uphill 2.25 m/s blast was suppressed on tick 1 (pre={preBlastVy:F2}, tick1={tick1Vy:F2})");
|
|
Assert.True(maxVyAfterBlast <= MathF.Max(preBlastVy + splashVy, 9.45f) + 0.15f,
|
|
$"Kestrel uphill blast pumped vel.Y to {maxVyAfterBlast:F2} m/s (pre={preBlastVy:F2}, splash={splashVy:F2})");
|
|
Assert.True(maxVyAfterBlast < 12.5f, $"Kestrel uphill blast pumped to {maxVyAfterBlast:F2} m/s");
|
|
Assert.True(maxAboveSlope < 0.85f, $"Kestrel uphill blast launched {maxAboveSlope:F2}m above slope");
|
|
Assert.True(regroundedAfterBlast, "Kestrel failed to land cleanly within 60 ticks after 2.25 m/s uphill splash");
|
|
}
|
|
|
|
[Fact]
|
|
public void SoulPass3_VerticalCliffAndWall_NoWallSnapTeleport_ReachClamped()
|
|
{
|
|
// 1. Desert Bastion approaching vertical MesaWall
|
|
using (var desert = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true))
|
|
{
|
|
for (int i = 1; i < desert.State.Contenders.Count; i++)
|
|
{
|
|
desert.SetContenderPose(i, 900f + i * 16f, 900f);
|
|
}
|
|
|
|
TerrainBrush? mesa = null;
|
|
foreach (var b in desert.State.Terrain.Brushes)
|
|
{
|
|
if (b.Kind == TerrainBrushKind.Mesa && b.HeightDelta >= 6f)
|
|
{
|
|
mesa = b;
|
|
break;
|
|
}
|
|
}
|
|
Assert.True(mesa.HasValue, "Expected a Mesa brush on Desert seed 42");
|
|
var m = mesa!.Value;
|
|
float startX = m.X;
|
|
float startZ = m.Z - m.RadiusZ - 14f;
|
|
desert.SetContenderPose(0, startX, startZ, 0f);
|
|
desert.State.SpawnChassisDrop(startX, startZ, Catalog.Bastion);
|
|
Assert.True(desert.TrySwapNearbyChassis(0));
|
|
desert.SetContenderPose(0, startX, startZ, 0f);
|
|
|
|
var player = desert.State.Contenders[0];
|
|
var body = desert.GetContenderBody(player.Id)!.Value;
|
|
var ws = desert.GetWalkerState(true, player.Id)!;
|
|
var view = desert.World.View;
|
|
int lane = body.Lane;
|
|
Vector3[] prevSoles = new Vector3[ws.Geom.LegCount];
|
|
for (int i = 0; i < ws.Geom.LegCount; i++) prevSoles[i] = ws.FootSole[i];
|
|
|
|
float maxJump = 0f;
|
|
float maxSwOver = 0f;
|
|
float maxPOver = 0f;
|
|
for (int t = 0; t < 180; t++)
|
|
{
|
|
desert.SetHumanInput(0, new PlayerInput(1.0f, 0f, m.X, m.Z, false, false, false));
|
|
desert.Step();
|
|
var comPos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
|
var qYaw = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
|
var qTotal = Quaternion.Normalize(qYaw * Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll));
|
|
Vector3 pelvisW = Vector3.Transform(ws.PelvisOffset, qYaw);
|
|
for (int i = 0; i < ws.Geom.LegCount; i++)
|
|
{
|
|
float jump = Vector3.Distance(ws.FootSole[i], prevSoles[i]);
|
|
if (jump > maxJump) maxJump = jump;
|
|
|
|
Vector3 hipW = comPos + pelvisW + Vector3.Transform(ws.Geom.Legs[i].HipInCom * ws.GeomScale, qTotal);
|
|
Vector3 ankW = ws.FootSole[i] + ws.FootNormal[i] * (ws.Geom.Legs[i].AnkleH * ws.GeomScale);
|
|
float dist3D = Vector3.Distance(ankW, hipW);
|
|
float maxR = ws.Geom.Legs[i].MaxLegReach * ws.GeomScale;
|
|
if (ws.Planted[i]) maxPOver = MathF.Max(maxPOver, dist3D - maxR);
|
|
else maxSwOver = MathF.Max(maxSwOver, dist3D - maxR);
|
|
|
|
float limit = ws.Planted[i] ? maxR + 0.05f : maxR * 1.02f + 0.03f;
|
|
Assert.True(dist3D <= limit, $"Desert Bastion MesaWall tick {t} leg {i}: reach {dist3D:F3} > {limit:F3}");
|
|
Assert.True(jump < 1.60f, $"Desert Bastion MesaWall tick {t} leg {i}: wall snap teleport {jump:F3}m >= 1.60m");
|
|
prevSoles[i] = ws.FootSole[i];
|
|
}
|
|
}
|
|
_output.WriteLine($"Desert Bastion MesaWall: maxJump={maxJump:F3}m, maxPOver={maxPOver:F3}m, maxSwOver={maxSwOver:F3}m");
|
|
}
|
|
|
|
// 2. Sion Paladin walking alongside tall building wall
|
|
using (var sion = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true))
|
|
{
|
|
for (int i = 1; i < sion.State.Contenders.Count; i++)
|
|
{
|
|
sion.SetContenderPose(i, 900f + i * 16f, 900f);
|
|
}
|
|
var bldg = sion.State.SionMap!.Buildings.First(b => (b.RoofY - b.GroundY) >= 6f && MathF.Abs(b.CenterX) < 500f && MathF.Abs(b.CenterZ) < 500f);
|
|
float startX = bldg.CenterX - bldg.HalfX - 4.5f;
|
|
float startZ = bldg.CenterZ - bldg.HalfZ - 12f;
|
|
sion.SetContenderPose(0, startX, startZ, 0f);
|
|
sion.State.SpawnChassisDrop(startX, startZ, Catalog.Paladin);
|
|
Assert.True(sion.TrySwapNearbyChassis(0));
|
|
sion.SetContenderPose(0, startX, startZ, 0f);
|
|
|
|
var player = sion.State.Contenders[0];
|
|
var body = sion.GetContenderBody(player.Id)!.Value;
|
|
var ws = sion.GetWalkerState(true, player.Id)!;
|
|
var view = sion.World.View;
|
|
int lane = body.Lane;
|
|
Vector3[] prevSoles = new Vector3[ws.Geom.LegCount];
|
|
for (int i = 0; i < ws.Geom.LegCount; i++) prevSoles[i] = ws.FootSole[i];
|
|
|
|
float maxJump = 0f;
|
|
for (int t = 0; t < 150; t++)
|
|
{
|
|
sion.SetHumanInput(0, new PlayerInput(0.8f, 0.08f, startX + 2f, bldg.CenterZ + bldg.HalfZ + 20f, false, false, false));
|
|
sion.Step();
|
|
var comPos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
|
var qYaw = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
|
var qTotal = Quaternion.Normalize(qYaw * Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll));
|
|
Vector3 pelvisW = Vector3.Transform(ws.PelvisOffset, qYaw);
|
|
for (int i = 0; i < ws.Geom.LegCount; i++)
|
|
{
|
|
float jump = Vector3.Distance(ws.FootSole[i], prevSoles[i]);
|
|
if (jump > maxJump) maxJump = jump;
|
|
|
|
Vector3 hipW = comPos + pelvisW + Vector3.Transform(ws.Geom.Legs[i].HipInCom * ws.GeomScale, qTotal);
|
|
Vector3 ankW = ws.FootSole[i] + ws.FootNormal[i] * (ws.Geom.Legs[i].AnkleH * ws.GeomScale);
|
|
float dist3D = Vector3.Distance(ankW, hipW);
|
|
float maxR = ws.Geom.Legs[i].MaxLegReach * ws.GeomScale;
|
|
float limit = ws.Planted[i] ? maxR + 0.05f : maxR * 1.02f + 0.03f;
|
|
Assert.True(dist3D <= limit, $"Sion Paladin wall tick {t} leg {i}: reach {dist3D:F3} > {limit:F3}");
|
|
Assert.True(jump < 1.60f, $"Sion Paladin wall tick {t} leg {i}: wall snap teleport {jump:F3}m >= 1.60m");
|
|
prevSoles[i] = ws.FootSole[i];
|
|
}
|
|
}
|
|
_output.WriteLine($"Sion Paladin wall: maxJump={maxJump:F3}m");
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void SoulPass3_ManticoreArachnid_IkFkParity_ZeroKneeSaturation()
|
|
{
|
|
static Vector3 ComputeArachnidFkAnkleLocal(WalkerLegSpec leg, float scale, in WalkerLegAngles ang)
|
|
{
|
|
Vector3 r0 = leg.LegRight0;
|
|
Vector3 f0 = leg.LegFwd0;
|
|
float coxaYaw = ang.HipRoll;
|
|
Vector3 legOut = f0 * MathF.Cos(coxaYaw) + r0 * MathF.Sin(coxaYaw);
|
|
Vector3 s1Dir = legOut * MathF.Cos(ang.HipPitch) + Vector3.UnitY * MathF.Sin(ang.HipPitch);
|
|
float s2Elev = ang.HipPitch - ang.KneeFlex;
|
|
Vector3 s2Dir = legOut * MathF.Cos(s2Elev) + Vector3.UnitY * MathF.Sin(s2Elev);
|
|
return s1Dir * (leg.L1 * scale) + s2Dir * (leg.L2 * scale);
|
|
}
|
|
|
|
// 1. Direct IK -> FK parity across full 360-degree coxa sweep including dz < 0 behind LegFwd0
|
|
var mGeom = WalkerGeometrySpec.Manticore;
|
|
for (int legIdx = 0; legIdx < mGeom.LegCount; legIdx++)
|
|
{
|
|
var leg = mGeom.Legs[legIdx];
|
|
for (int deg = -165; deg <= 165; deg += 15)
|
|
{
|
|
float rad = deg * (MathF.PI / 180f);
|
|
float r = 1.45f;
|
|
Vector3 deltaLocal = (leg.LegFwd0 * MathF.Cos(rad) + leg.LegRight0 * MathF.Sin(rad)) * r + new Vector3(0f, -0.45f, 0f);
|
|
WalkerLegAngles ang = WalkerLocomotion.SolveLegTargetAngles(
|
|
mGeom, 1f, legIdx, Vector3.Zero, Quaternion.Identity, deltaLocal, Vector3.UnitY, 0f);
|
|
Vector3 fk = ComputeArachnidFkAnkleLocal(leg, 1f, ang);
|
|
float err = Vector3.Distance(fk, deltaLocal);
|
|
Assert.True(err < 0.01f, $"Manticore leg {legIdx} angle {deg}deg: IK/FK mismatch {err:F4}m (coxaYaw={ang.HipRoll:F3})");
|
|
Assert.True(ang.KneeFlex < 2.95f, $"Manticore leg {legIdx} angle {deg}deg: knee saturated {ang.KneeFlex:F3}");
|
|
}
|
|
}
|
|
|
|
// 2. Live flat Desert walk + sharp turns: verify actuator FK parity & zero knee saturation
|
|
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true);
|
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
|
{
|
|
session.SetContenderPose(i, 900f + i * 16f, 900f);
|
|
}
|
|
session.SetContenderPose(0, 0f, 0f, 0f);
|
|
session.State.SpawnChassisDrop(0f, 0f, Catalog.Manticore);
|
|
Assert.True(session.TrySwapNearbyChassis(0));
|
|
session.SetContenderPose(0, 0f, 0f, 0f);
|
|
|
|
var player = session.State.Contenders[0];
|
|
var body = session.GetContenderBody(player.Id)!.Value;
|
|
var ws = session.GetWalkerState(true, player.Id)!;
|
|
var view = session.World.View;
|
|
int lane = body.Lane;
|
|
|
|
float maxFkErr = 0f;
|
|
float maxTargetFkErr = 0f;
|
|
float maxFlatTargetFkErr = 0f;
|
|
float maxAngularFkErr = 0f;
|
|
float maxKneeFlex = 0f;
|
|
float maxFlatKneeFlex = 0f;
|
|
for (int t = 0; t < 180; t++)
|
|
{
|
|
float steer = t < 60 ? 0f : (t < 120 ? 0.45f : -0.45f);
|
|
float aimYaw = player.Yaw + steer * 0.45f;
|
|
session.SetHumanInput(0, new PlayerInput(
|
|
1.0f, steer,
|
|
player.X + 40f * MathF.Sin(aimYaw),
|
|
player.Z + 40f * MathF.Cos(aimYaw),
|
|
false, false, false));
|
|
session.Step();
|
|
|
|
var comPos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
|
var qYaw = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
|
var qTotal = Quaternion.Normalize(qYaw * Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll));
|
|
Quaternion qInv = Quaternion.Conjugate(qTotal);
|
|
Vector3 pelvisW = Vector3.Transform(ws.PelvisOffset, qYaw);
|
|
|
|
for (int i = 0; i < ws.Geom.LegCount; i++)
|
|
{
|
|
var leg = ws.Geom.Legs[i];
|
|
Vector3 hipW = comPos + pelvisW + Vector3.Transform(leg.HipInCom * ws.GeomScale, qTotal);
|
|
Vector3 ankW = ws.FootSole[i] + ws.FootNormal[i] * (leg.AnkleH * ws.GeomScale);
|
|
Vector3 targetLocal = Vector3.Transform(ankW - hipW, qInv);
|
|
|
|
var tgtAng = WalkerLocomotion.SolveLegTargetAngles(
|
|
ws.Geom, ws.GeomScale, i, hipW, qTotal, ankW, ws.FootNormal[i], 0f,
|
|
ws.Actuators[i].Theta.HipRoll, hasPrevCoxaYaw: true);
|
|
Vector3 tgtFk = ComputeArachnidFkAnkleLocal(leg, ws.GeomScale, tgtAng);
|
|
float tErr = Vector3.Distance(tgtFk, targetLocal);
|
|
float tLen = targetLocal.Length();
|
|
float clampedLen = Math.Clamp(tLen, leg.MinLegReach * ws.GeomScale, leg.MaxLegReach * ws.GeomScale);
|
|
Vector3 reachableTarget = tLen > 1e-5f ? targetLocal * (clampedLen / tLen) : targetLocal;
|
|
float angErr = Vector3.Distance(tgtFk, reachableTarget);
|
|
maxAngularFkErr = MathF.Max(maxAngularFkErr, angErr);
|
|
maxTargetFkErr = MathF.Max(maxTargetFkErr, tErr);
|
|
if (t < 60) maxFlatTargetFkErr = MathF.Max(maxFlatTargetFkErr, tErr);
|
|
|
|
var actAng = ws.Actuators[i].Theta;
|
|
Vector3 actFk = ComputeArachnidFkAnkleLocal(leg, ws.GeomScale, actAng);
|
|
float aErr = Vector3.Distance(actFk, targetLocal);
|
|
maxFkErr = MathF.Max(maxFkErr, aErr);
|
|
maxKneeFlex = MathF.Max(maxKneeFlex, actAng.KneeFlex);
|
|
if (t < 60) maxFlatKneeFlex = MathF.Max(maxFlatKneeFlex, actAng.KneeFlex);
|
|
}
|
|
}
|
|
|
|
_output.WriteLine($"Manticore Desert walk/turn: flatMaxTargetFkErr={maxFlatTargetFkErr:F4}m, maxTargetFkErr={maxTargetFkErr:F4}m, maxAngularFkErr={maxAngularFkErr:F4}m, maxActFkErr={maxFkErr:F4}m, flatMaxKnee={maxFlatKneeFlex:F3}rad, maxKneeFlex={maxKneeFlex:F3}rad");
|
|
Assert.True(maxAngularFkErr < 0.01f, $"Manticore IK/FK angular mismatch {maxAngularFkErr:F4}m >= 0.01m");
|
|
Assert.True(maxFlatTargetFkErr < 0.10f, $"Manticore flat Desert IK/FK mismatch {maxFlatTargetFkErr:F4}m >= 0.10m");
|
|
Assert.True(maxTargetFkErr < 0.10f, $"Manticore IK/FK target mismatch {maxTargetFkErr:F4}m >= 0.10m");
|
|
Assert.True(maxFlatKneeFlex < 2.90f, $"Manticore flat knee near saturation {maxFlatKneeFlex:F3} rad");
|
|
Assert.True(maxKneeFlex < 3.05f, $"Manticore knee saturated at {maxKneeFlex:F3} rad");
|
|
}
|
|
|
|
[Fact]
|
|
public void SoulPass4_WalkerSnapshotInterpolate_HipRollShortestAngleAcrossPi()
|
|
{
|
|
var prev = new WalkerVisualSnapshot
|
|
{
|
|
LegCount = 4,
|
|
GeomScale = 1f,
|
|
IsArachnidUp = true,
|
|
ComPos = Vector3.Zero,
|
|
ComRot = Quaternion.Identity
|
|
};
|
|
var curr = prev;
|
|
prev.LegAngles[0] = new WalkerLegAngles { HipRoll = -2.877f, HipPitch = 0.4f, KneeFlex = 1.2f };
|
|
curr.LegAngles[0] = new WalkerLegAngles { HipRoll = +3.111f, HipPitch = 0.6f, KneeFlex = 1.4f };
|
|
prev.FootNormal[0] = Vector3.UnitY;
|
|
curr.FootNormal[0] = Vector3.UnitY;
|
|
|
|
var mid = WalkerVisualSnapshot.Interpolate(in prev, in curr, 0.5f);
|
|
float distToPi = MathF.Abs(MathF.PI - MathF.Abs(mid.LegAngles[0].HipRoll));
|
|
Assert.True(distToPi <= 0.15f,
|
|
$"HipRoll interpolated the long way through 0: mid={mid.LegAngles[0].HipRoll:F4} (distToPi={distToPi:F4})");
|
|
}
|
|
|
|
[Fact]
|
|
public void SoulPass4_ManticoreDuneDownhillAndSionValley_MinSoleRelAboveGround()
|
|
{
|
|
// 1. Desert DuneDownhill (tallest DuneRidge crest -> downhill sprint + turn)
|
|
using (var desert = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true))
|
|
{
|
|
for (int i = 1; i < desert.State.Contenders.Count; i++)
|
|
{
|
|
desert.SetContenderPose(i, 900f + i * 16f, 900f);
|
|
}
|
|
|
|
TerrainBrush? ridge = null;
|
|
float bestH = float.NegativeInfinity;
|
|
foreach (var b in desert.State.Terrain.Brushes)
|
|
{
|
|
if (b.Kind == TerrainBrushKind.DuneRidge && b.HeightDelta > bestH)
|
|
{
|
|
bestH = b.HeightDelta;
|
|
ridge = b;
|
|
}
|
|
}
|
|
Assert.True(ridge.HasValue);
|
|
var r = ridge!.Value;
|
|
desert.SetContenderPose(0, r.X, r.Z, 0f);
|
|
desert.State.SpawnChassisDrop(r.X, r.Z, Catalog.Manticore);
|
|
Assert.True(desert.TrySwapNearbyChassis(0));
|
|
desert.SetContenderPose(0, r.X, r.Z, 0f);
|
|
|
|
var player = desert.State.Contenders[0];
|
|
var ws = desert.GetWalkerState(true, player.Id)!;
|
|
float minSoleRel = float.PositiveInfinity;
|
|
for (int t = 0; t < 180; t++)
|
|
{
|
|
float steer = MathF.Sin(t * 0.08f) * 0.55f;
|
|
float aimYaw = player.Yaw + steer * 0.6f;
|
|
desert.SetHumanInput(0, new PlayerInput(
|
|
1.0f, steer,
|
|
player.X + 40f * MathF.Sin(aimYaw),
|
|
player.Z + 40f * MathF.Cos(aimYaw),
|
|
false, false, false));
|
|
desert.Step();
|
|
|
|
for (int i = 0; i < ws.Geom.LegCount; i++)
|
|
{
|
|
float gY = desert.QueryDropSurface(ws.FootSole[i].X, ws.FootSole[i].Z, 0f, player.Y + 1.0f).SurfaceY;
|
|
minSoleRel = MathF.Min(minSoleRel, ws.FootSole[i].Y - gY);
|
|
}
|
|
}
|
|
_output.WriteLine($"Manticore Desert DuneDownhill: minSoleRel={minSoleRel:F4}m");
|
|
Assert.True(minSoleRel >= -0.05f, $"Manticore Desert DuneDownhill sole dipped underground: {minSoleRel:F4}m < -0.05m");
|
|
}
|
|
|
|
// 2. Sion Valley (low valley/slope clear of buildings with turning sprint)
|
|
using (var sion = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true))
|
|
{
|
|
for (int i = 1; i < sion.State.Contenders.Count; i++)
|
|
{
|
|
sion.SetContenderPose(i, 900f + i * 16f, 900f);
|
|
}
|
|
|
|
var sionMap = sion.State.SionMap!;
|
|
(float X, float Z, float Yaw) valleySite = default;
|
|
float bestMinNy = 1f;
|
|
for (float r = 40f; r <= 900f; r += 25f)
|
|
{
|
|
for (int a = 0; a < 48; a++)
|
|
{
|
|
float ang = a * (MathF.Tau / 48f);
|
|
float x = MathF.Cos(ang) * r;
|
|
float z = MathF.Sin(ang) * r;
|
|
if (sionMap.IsInsideAnyBuildingXz(x, z, 28f)) continue;
|
|
var (nx, ny, nz) = sion.State.Terrain.SampleNormal(x, z);
|
|
if (ny >= 0.78f && ny <= 0.90f && ny < bestMinNy)
|
|
{
|
|
bestMinNy = ny;
|
|
valleySite = (x, z, MathF.Atan2(nx, nz)); // start facing downhill into valley
|
|
}
|
|
}
|
|
}
|
|
|
|
sion.SetContenderPose(0, valleySite.X, valleySite.Z, valleySite.Yaw);
|
|
sion.State.SpawnChassisDrop(valleySite.X, valleySite.Z, Catalog.Manticore);
|
|
Assert.True(sion.TrySwapNearbyChassis(0));
|
|
sion.SetContenderPose(0, valleySite.X, valleySite.Z, valleySite.Yaw);
|
|
|
|
var player = sion.State.Contenders[0];
|
|
var ws = sion.GetWalkerState(true, player.Id)!;
|
|
float minSoleRel = float.PositiveInfinity;
|
|
for (int t = 0; t < 180; t++)
|
|
{
|
|
float steer = MathF.Sin(t * 0.08f) * 0.55f;
|
|
float aimYaw = player.Yaw + steer * 0.6f;
|
|
sion.SetHumanInput(0, new PlayerInput(
|
|
1.0f, steer,
|
|
player.X + 40f * MathF.Sin(aimYaw),
|
|
player.Z + 40f * MathF.Cos(aimYaw),
|
|
false, false, false));
|
|
sion.Step();
|
|
|
|
for (int i = 0; i < ws.Geom.LegCount; i++)
|
|
{
|
|
float gY = sion.QueryDropSurface(ws.FootSole[i].X, ws.FootSole[i].Z, 0f, player.Y + 1.0f).SurfaceY;
|
|
minSoleRel = MathF.Min(minSoleRel, ws.FootSole[i].Y - gY);
|
|
}
|
|
}
|
|
_output.WriteLine($"Manticore Sion Valley: minSoleRel={minSoleRel:F4}m");
|
|
Assert.True(minSoleRel >= -0.05f, $"Manticore Sion Valley sole dipped underground: {minSoleRel:F4}m < -0.05m");
|
|
}
|
|
}
|
|
}
|
|
}
|