Cut 10a: cross-zone orbital drop altitudes, squad formation spawns, and wide drop FOV

This commit is contained in:
Meta Vens 2026-12-05 19:32:20 +01:00
commit 26f5438ed5
24 changed files with 1754 additions and 211 deletions

View file

@ -142,4 +142,39 @@ public sealed class CameraJuiceTests
float expected = 0.14f * (1f - 20f / 90f);
Assert.InRange(juice.Trauma, expected - 1e-4f, expected + 1e-4f);
}
[Fact]
public void DropPodFov_WidensTo82DegAndEasesTo58DegOnTouchdown()
{
var juice = new CameraJuiceState();
const float dt = 1f / 60f;
// 1. Freefall at max cross-zone glide speed (124 m/s) -> widens to 82..84 deg smoothly
for (int i = 0; i < 120; i++)
{
juice.Update(dt, localSpeedMps: 124f, isVtol: false, isInDropPod: true, podPhase: OrbitalPodPhase.Freefall);
}
float freefallFov = CameraJuiceState.BaseFovDeg + juice.FovOffsetDeg;
Assert.InRange(freefallFov, 80.0f, 85.0f);
// 2. RetroBurn -> tightens to ~76 deg
for (int i = 0; i < 90; i++)
{
juice.Update(dt, localSpeedMps: 15f, isVtol: false, isInDropPod: true, podPhase: OrbitalPodPhase.RetroBurn);
}
float retroFov = CameraJuiceState.BaseFovDeg + juice.FovOffsetDeg;
Assert.InRange(retroFov, 74.5f, 77.5f);
// 3. Touchdown ground release -> eases monotonically back toward 58 deg within ~1.5s
float prevFov = retroFov;
for (int i = 0; i < 90; i++)
{
juice.Update(dt, localSpeedMps: 0f, isVtol: false, isInDropPod: false);
float curFov = CameraJuiceState.BaseFovDeg + juice.FovOffsetDeg;
Assert.True(curFov <= prevFov + 1e-4f, $"Expected monotonic FOV release, jumped {prevFov:F3} -> {curFov:F3}");
Assert.True(prevFov - curFov < 2.0f, $"Expected smooth FOV release without discontinuity: delta={prevFov - curFov:F2}");
prevFov = curFov;
}
Assert.InRange(prevFov, 57.9f, 59.0f);
}
}

View file

@ -633,5 +633,80 @@ namespace RustToDust.Tests
Assert.NotNull(res.Summary);
Assert.Equal(new string('\u2022', 16), res.Summary!.Value.ServerName);
}
[Fact]
public void LobbySquadSwap_ReliableRoundTrip()
{
using var listenHost = new ListenHostArenaSession(
IPAddress.Loopback,
0,
seed: 42,
mapKind: ArenaMapKind.Desert,
startInLobby: true,
minHumansToStart: 2,
squadSize: 3);
using var remote = new RemoteArenaSession(
new IPEndPoint(IPAddress.Loopback, listenHost.Host.BoundPort),
"WingBuddy");
var deadline = DateTime.UtcNow.AddSeconds(3);
while (!remote.IsJoined && DateTime.UtcNow < deadline)
{
PumpListenHostAndClient(listenHost, remote);
}
Assert.True(remote.IsJoined);
int remoteId = remote.LocalContenderId;
Assert.Equal((byte)3, listenHost.LobbyState?.SquadSize);
Assert.Equal((byte)3, remote.LobbyState?.SquadSize);
Assert.Equal((byte)0, remote.LobbyState!.Slots[remoteId].SquadId);
// 1. Remote client swaps to Squad 2 -> swaps cleanly with an AI in Squad 2
Assert.True(remote.RequestLobbySquad(2));
PumpListenHostAndClient(listenHost, remote, ticks: 15);
Assert.Equal((byte)2, listenHost.LobbyState!.Slots[remoteId].SquadId);
Assert.Equal((byte)2, remote.LobbyState!.Slots[remoteId].SquadId);
// 2. Host switches SquadMode to Duos (2) -> slots regroup cleanly to 2-player squads
Assert.True(listenHost.RequestLobbyConfig(77, ArenaMapKind.Desert, 2));
PumpListenHostAndClient(listenHost, remote, ticks: 15);
Assert.Equal((byte)2, listenHost.LobbyState!.SquadSize);
Assert.Equal((byte)2, remote.LobbyState!.SquadSize);
Assert.Equal((byte)0, remote.LobbyState!.Slots[remoteId].SquadId);
// 3. Remote swaps to Squad 3, then back to Squad 0 (Host's Duo), both ready up & launch!
Assert.True(remote.RequestLobbySquad(3));
PumpListenHostAndClient(listenHost, remote, ticks: 15);
Assert.Equal((byte)3, remote.LobbyState!.Slots[remoteId].SquadId);
Assert.True(remote.RequestLobbySquad(0));
PumpListenHostAndClient(listenHost, remote, ticks: 15);
Assert.Equal((byte)0, remote.LobbyState!.Slots[remoteId].SquadId);
Assert.True(listenHost.SetLobbyReady(true));
Assert.True(remote.SetLobbyReady(true));
for (int tick = 0; tick < 340; tick++)
{
listenHost.SubmitLocalInput(default, isPhysicsTick: true);
remote.PumpNetwork();
if (listenHost.ViewState.Phase == MatchPhase.Active &&
remote.ViewState.Phase == MatchPhase.Active &&
remote.ActivePods.Count > 0)
{
break;
}
Thread.Sleep(1);
}
PumpListenHostAndClient(listenHost, remote, ticks: 10);
Assert.Equal(MatchPhase.Active, listenHost.ViewState.Phase);
Assert.Equal(MatchPhase.Active, remote.ViewState.Phase);
Assert.Equal((byte)2, listenHost.ViewState.SquadSize);
Assert.Equal((byte)2, remote.ViewState.SquadSize);
Assert.Equal(0, listenHost.ViewState.Contenders[remoteId].SquadId);
Assert.Equal(0, remote.ViewState.Contenders[remoteId].SquadId);
Assert.True(listenHost.ViewState.AreAllies(0, remoteId));
Assert.True(remote.ViewState.AreAllies(0, remoteId));
}
}
}

View file

@ -25,16 +25,18 @@ namespace RustToDust.Tests
[Fact]
public void HoverSlam_FlatDesertAnd30DegSionSlope_TouchdownUnder3MsAndZeroPenetration()
{
// 1. Flat Desert trajectory & cross-range steering [120m, 180m]
// 1. Flat Desert trajectory & cross-range steering
{
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert, slot0Human: true);
var player = session.State.Contenders[0];
float startX = player.X;
float startZ = player.Z;
float aimX = startX;
float aimZ = startZ + 100f;
// Steer straight across the arena center so boundary clamp does not reverse heading
float dirLen = MathF.Max(1f, MathF.Sqrt(startX * startX + startZ * startZ));
float dirX = -startX / dirLen;
float dirZ = -startZ / dirLen;
int maxTicks = 600;
int maxTicks = 1200;
float impactSpeed = -1f;
float touchTime = -1f;
float snapDiffAtTouchdown = float.NaN;
@ -50,8 +52,8 @@ namespace RustToDust.Tests
session.SetHumanInput(0, new PlayerInput(
Throttle: 1.0f,
Steer: 0f,
AimWorldX: player.X,
AimWorldZ: player.Z + 100f,
AimWorldX: player.X + dirX * 100f,
AimWorldZ: player.Z + dirZ * 100f,
Fire: false,
InteractPickup: false,
Brake: false));
@ -67,12 +69,12 @@ namespace RustToDust.Tests
}
}
Assert.True(player.IsGroundedActive, "Player pod failed to touch down within 10s on Desert");
Assert.InRange(impactSpeed, 0.5f, 2.99f);
Assert.InRange(touchTime, 5.5f, 9.5f);
Assert.True(player.IsGroundedActive, "Player pod failed to touch down within 20s on Desert");
Assert.InRange(impactSpeed, 0.5f, 2.49f);
Assert.InRange(touchTime, 12.5f, 18.0f);
float glideDist = MathF.Sqrt((player.X - startX) * (player.X - startX) + (player.Z - startZ) * (player.Z - startZ));
Assert.InRange(glideDist, 120f, 180f);
Assert.True(glideDist >= 800f, $"Expected cross-arena Desert glide >= 800m, got {glideDist:F1}m");
// Verify PrevY == Y right at touchdown SnapPreviousPose() and continuous post-Step settlement (< 0.06m, zero sky pop)
Assert.True(snapDiffAtTouchdown < 1e-4f,
@ -130,7 +132,7 @@ namespace RustToDust.Tests
};
float impactSpeed = -1f;
for (int t = 0; t < 600; t++)
for (int t = 0; t < 2000; t++)
{
pod.LookForwardX = -snx;
pod.LookForwardZ = -snz;
@ -146,7 +148,7 @@ namespace RustToDust.Tests
}
Assert.True(c.IsGroundedActive, $"Pod failed to land on {slopeDeg:F1} deg Sion slope");
Assert.InRange(impactSpeed, 0.5f, 2.99f);
Assert.InRange(impactSpeed, 0.5f, 2.49f);
Assert.True(snapDiffAtTouchdown < 1e-4f);
Assert.True(MathF.Abs(c.PrevY - c.Y) < 0.06f);
AssertZeroChassisPenetration(session.State, c);
@ -167,7 +169,7 @@ namespace RustToDust.Tests
float maxGearTouchTime = 0f;
float minContenderTouchTime = float.PositiveInfinity;
for (int t = 0; t < 660; t++)
for (int t = 0; t < 2000; t++)
{
session.Step();
if (session.State.OrbitalDrop.ActivePods.Count == 0)
@ -192,7 +194,7 @@ namespace RustToDust.Tests
var state = new MatchState(seed: 42, map);
var gearTouchTimes = new List<float>();
var contenderTouchTimes = new List<float>();
for (int t = 0; t < 660; t++)
for (int t = 0; t < 2000; t++)
{
state.Time += ArenaSession.FixedDt;
state.OrbitalDrop.Step(ArenaSession.FixedDt, state.DefaultDropSurfaceQuery, (pod, _) =>
@ -246,7 +248,7 @@ namespace RustToDust.Tests
var pod = session.State.OrbitalDrop.LaunchGearPod(0, tx, tz, null, Catalog.Autocannon, session.QueryDropSurface);
bool landed = false;
for (int t = 0; t < 600; t++)
for (int t = 0; t < 1800; t++)
{
bool touched = OrbitalDropKinematics.StepPod(
pod,
@ -267,12 +269,12 @@ namespace RustToDust.Tests
Assert.False(touchSample.IsInsideSolidBuilding,
$"Target #{i} ({tx:F1},{tz:F1}) landed with IsInsideSolidBuilding=true at ({pod.X:F1},{pod.Z:F1})!");
Assert.False(touchSample.IsBuildingRoof);
Assert.InRange(pod.TouchdownSpeed, 0.5f, 2.99f);
Assert.InRange(pod.TouchdownSpeed, 0.5f, 2.5f);
break;
}
}
Assert.True(landed, $"Target #{i} ({tx:F1},{tz:F1}) hover-stalled!");
Assert.True(pod.FlightTime <= 9.5f, $"Target #{i} took too long: {pod.FlightTime:F2}s");
Assert.True(pod.FlightTime <= 28.0f, $"Target #{i} took too long: {pod.FlightTime:F2}s");
tested++;
}
@ -312,7 +314,7 @@ namespace RustToDust.Tests
player, 0, fr.CenterX, fr.CenterZ, 0f, session.QueryDropSurface, isRespawn: false);
roofPod.AllowFlatRoofLanding = true;
for (int t = 0; t < 600 && !player.IsGroundedActive; t++)
for (int t = 0; t < 2000 && !player.IsGroundedActive; t++)
{
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 20f, false, false, false));
session.Step();
@ -390,15 +392,15 @@ namespace RustToDust.Tests
var state = session.State;
var player = state.Contenders[0];
// Step until Wave 0 contenders touch down (~7.5s)
for (int t = 0; t < 480 && !state.Contenders.All(c => c.IsGroundedActive); t++)
// Step until Wave 0 contenders touch down (~15s on Desert)
for (int t = 0; t < 1200 && !state.Contenders.All(c => c.IsGroundedActive); t++)
{
session.Step();
}
Assert.All(state.Contenders, c => Assert.True(c.IsGroundedActive));
// 1. Kill 11 AIs at t = 15s -> must enter WaitingForRespawnWave and match stays Active!
while (state.Time < 15f)
// 1. Kill 11 AIs at t = 20s -> must enter WaitingForRespawnWave and match stays Active!
while (state.Time < 20f)
{
session.Step();
}
@ -414,8 +416,8 @@ namespace RustToDust.Tests
Assert.True(state.Contenders[i].WaitingForRespawn);
}
// 2. Step past Wave 1 (t = 75s) + drop time -> all 11 AIs re-drop in stock Jackals with RespawnsRemaining == 0!
while (state.Time < 75.5f)
// 2. Step past Wave 1 (t = 85s) + drop time -> all 11 AIs re-drop in stock Jackals with RespawnsRemaining == 0!
while (state.Time < 85.5f)
{
session.Step();
}
@ -426,15 +428,15 @@ namespace RustToDust.Tests
Assert.Equal(0, state.Contenders[i].RespawnsRemaining);
Assert.Equal(Catalog.Jackal.Id, state.Contenders[i].Grid.Spec.Id);
}
for (int t = 0; t < 480; t++)
for (int t = 0; t < 1200; t++)
{
session.Step();
if (state.Contenders.All(c => c.IsGroundedActive)) break;
}
Assert.All(state.Contenders, c => Assert.True(c.IsGroundedActive));
// 3. Kill Player before Wave 2 (t = 120s) -> match MUST stay Active (Player.WaitingForRespawn == true)
while (state.Time < 120f)
// 3. Kill Player before Wave 2 (t = 130s) -> match MUST stay Active (Player.WaitingForRespawn == true)
while (state.Time < 130f)
{
session.Step();
}
@ -444,8 +446,8 @@ namespace RustToDust.Tests
Assert.Equal(MatchPhase.Active, state.Phase);
Assert.True(player.WaitingForRespawn);
// Step past Wave 2 (t = 155s) -> Player re-drops in stock Jackal (RespawnsRemaining == 0), RespawnCutoffReached == true!
while (state.Time < 155.5f)
// Step past Wave 2 (t = 165s) -> Player re-drops in stock Jackal (RespawnsRemaining == 0), RespawnCutoffReached == true!
while (state.Time < 165.5f)
{
session.Step();
}
@ -454,8 +456,8 @@ namespace RustToDust.Tests
Assert.Equal(ContenderLifecycle.Deploying, player.Lifecycle);
Assert.Equal(0, player.RespawnsRemaining);
// 4. Kill an AI at t = 158.1s (after Wave 2 cutoff) -> immediately Eliminated (never WaitingForRespawnWave)!
while (state.Time < 158.1f)
// 4. Kill an AI at t = 168.1s (after Wave 2 cutoff) -> immediately Eliminated (never WaitingForRespawnWave)!
while (state.Time < 168.1f)
{
session.Step();
}
@ -524,9 +526,9 @@ namespace RustToDust.Tests
Assert.True(clientIface.ActivePods.Count >= 12,
$"Expected active Wave 0 pods on RemoteArenaSession join, got {clientIface.ActivePods.Count}");
// Step through full Wave 0 orbital drop (~7.8s = 470 ticks) with steering input
// Step through full Wave 0 orbital drop (~15.1s = 905 ticks) with steering input
var simEvents = new List<ISimEvent>();
for (int t = 0; t < 480; t++)
for (int t = 0; t < 1100; t++)
{
nowMs += 16;
clientIface.SubmitLocalInput(new PlayerInput(
@ -621,9 +623,9 @@ namespace RustToDust.Tests
Assert.True(midGearPod.LastAgl < gearAgl0 - 20f && midGearPod.LastAgl > 0f,
$"Gear pod LastAgl failed to update: {gearAgl0:F2} -> {midGearPod.LastAgl:F2}");
// Step through remainder of Wave 0 + 30 settle ticks so all pods touch down across Sion PVS
// Step through remainder of Wave 0 + 30 settle ticks so all pods touch down across Sion PVS (~27.6s = 1658 ticks)
var simEvents = new List<ISimEvent>();
for (int t = 0; t < 560; t++)
for (int t = 0; t < 1900; t++)
{
nowMs += 16;
clientIface.SubmitLocalInput(new PlayerInput(
@ -690,7 +692,7 @@ namespace RustToDust.Tests
}
// 1. Land Wave 0
for (int i = 0; i < 480 && !clientIface.LocalContender.IsGroundedActive; i++)
for (int i = 0; i < 1100 && !clientIface.LocalContender.IsGroundedActive; i++)
{
PumpStep(1);
}
@ -708,8 +710,8 @@ namespace RustToDust.Tests
PumpStep(12);
Assert.Equal(ContenderLifecycle.WaitingForRespawnWave, clientIface.LocalContender.Lifecycle);
// 4. Advance past Wave 1 (75.0s) -> server resets local player to Jackal (256/256) and launches Wave 1 pod
host.Session.State.Time = 74.85f;
// 4. Advance past Wave 1 (85.0s) -> server resets local player to Jackal (256/256) and launches Wave 1 pod
host.Session.State.Time = 84.85f;
PumpStep(30);
Assert.Equal(ContenderLifecycle.Deploying, clientIface.LocalContender.Lifecycle);
@ -1019,7 +1021,7 @@ namespace RustToDust.Tests
// 2. Full Sion Wave 0 drop steering human toward sion_1365 + steep Sion terrain checks across all 12 contenders
var maxBurnStartAgl = new Dictionary<int, float>();
for (int t = 0; t < 700; t++)
for (int t = 0; t < 2200; t++)
{
var p0 = session.State.Contenders[0];
session.SetHumanInput(0, new PlayerInput(
@ -1044,7 +1046,7 @@ namespace RustToDust.Tests
maxBurnStartAgl[pod.PodId] = pod.LastAgl;
Assert.True(pod.LastAgl <= 160f, $"Wave 0 pod {pod.PodId} ignited RetroBurn at {pod.LastAgl:F1}m AGL");
}
Assert.True(pod.FlightTime <= 10.5f, $"Wave 0 pod {pod.PodId} exceeded 10.5s flight time: {pod.FlightTime:F2}s");
Assert.True(pod.FlightTime <= 34.0f, $"Wave 0 pod {pod.PodId} exceeded 34.0s flight time: {pod.FlightTime:F2}s");
}
if (session.State.OrbitalDrop.ActivePods.Count == 0 && p0.IsGroundedActive)
@ -1110,8 +1112,8 @@ namespace RustToDust.Tests
host.Session.SetContenderPose(localId, -900f, -900f, 0f);
PumpStep(5);
// Trigger Wave 1 (75.0s) so rival launches its drop pod out of observer PVS
host.Session.State.Time = 74.9f;
// Trigger Wave 1 (85.0s) so rival launches its drop pod out of observer PVS
host.Session.State.Time = 84.9f;
for (int i = 0; i < 20 && host.Session.State.Contenders[rivalId].Lifecycle != ContenderLifecycle.Deploying; i++)
{
PumpStep(1);
@ -1189,7 +1191,7 @@ namespace RustToDust.Tests
foreach (bool allowFlat in new[] { false, true })
{
foreach (float startAgl in new[] { 410f, 80f })
foreach (float startAgl in new[] { 1620f, 80f })
{
foreach (var (label, sx, sz) in startPoints)
{
@ -1209,7 +1211,7 @@ namespace RustToDust.Tests
X = sx,
Y = terrain0 + startAgl,
Z = sz,
VelY = startAgl > 200f ? OrbitalPodPreset.Contender.InitialVelY : -28f,
VelY = startAgl > 200f ? OrbitalPodPreset.GetContender(ArenaMapKind.Sion).InitialVelY : -28f,
LookForwardX = dirX,
LookForwardZ = dirZ,
SteerForwardCmd = 1f,
@ -1217,7 +1219,7 @@ namespace RustToDust.Tests
};
bool landed = false;
for (int t = 0; t < 720; t++)
for (int t = 0; t < 2200; t++)
{
float prevX = pod.X;
float prevY = pod.Y;
@ -1248,7 +1250,7 @@ namespace RustToDust.Tests
(pod.Y - prevY) * (pod.Y - prevY) +
(pod.Z - prevZ) * (pod.Z - prevZ));
maxTouchdownStep = MathF.Max(maxTouchdownStep, tdStep3D);
if (tdStep3D > 1.0f || horizStep > 1.0f)
if (tdStep3D > 1.0f || horizStep > 2.25f)
{
touchdownWarps++;
}
@ -1271,8 +1273,270 @@ namespace RustToDust.Tests
Assert.Equal(0, wallBreachFrames);
Assert.Equal(0, touchdownWarps);
Assert.True(maxHorizStep <= 1.0f, $"Horizontal warp {maxHorizStep:F3}m > 1.0m/tick");
Assert.True(maxTouchSpeed < 3.0f, $"Touchdown speed {maxTouchSpeed:F2} m/s >= 3.0 m/s");
Assert.True(maxHorizStep <= 2.25f, $"Horizontal warp {maxHorizStep:F3}m > 2.25m/tick");
Assert.True(maxTouchSpeed < 2.5f, $"Touchdown speed {maxTouchSpeed:F2} m/s >= 2.5 m/s");
}
[Fact]
public void HoverSlam_CrossZoneDrop_SionAndDesert()
{
// Large synthetic flat terrain to measure unobstructed max-burn cross-zone horizontal glide
var largeHeights = new float[17 * 17];
var largeFlat = TerrainField.LoadHeightmap(sizeMeters: 10000f, gridRes: 17, largeHeights, minY: 0f, maxY: 0f, seed: 1);
DropSurfaceSample FlatQuery(float x, float z, float footR, float refMaxY) =>
new(0f, Vector3.UnitY, false, false, false, false);
(float X, float Z) FlatClear(float x, float z, float pad) => (x, z);
foreach (var (map, minGlideM) in new[] { (ArenaMapKind.Sion, 3000f), (ArenaMapKind.Desert, 1400f) })
{
var preset = OrbitalPodPreset.GetContender(map);
var pod = new OrbitalPod
{
PodId = 100 + (int)map,
PodKind = OrbitalPodKind.Contender,
Phase = OrbitalPodPhase.Freefall,
X = 0f,
Y = preset.StartAltAgl,
Z = 0f,
VelY = preset.InitialVelY,
LookForwardX = 0f,
LookForwardZ = 1f,
SteerForwardCmd = 1.0f,
Yaw = 0f
};
float burnStartAgl = -1f;
bool touched = false;
for (int t = 0; t < 2400; t++)
{
if (OrbitalDropKinematics.StepPod(pod, ArenaSession.FixedDt, largeFlat, FlatQuery, FlatClear, out bool retroStarted, out _))
{
touched = true;
break;
}
if (retroStarted)
{
burnStartAgl = pod.Y;
}
}
Assert.True(touched, $"{map} cross-zone pod failed to touch down");
Assert.True(pod.Z >= minGlideM, $"{map} max-burn horizontal glide {pod.Z:F1}m < {minGlideM:F1}m");
Assert.True(pod.TouchdownSpeed < 2.5f, $"{map} flat touchdown speed {pod.TouchdownSpeed:F2} >= 2.5 m/s");
Assert.InRange(burnStartAgl, 8f, 160f);
Assert.Equal(0f, pod.Y, precision: 3);
_output.WriteLine($"{map} flat cross-zone: glide={pod.Z:F1}m, flight={pod.FlightTime:F2}s, retroAgl={burnStartAgl:F2}m, tdVel={pod.TouchdownSpeed:F2} m/s");
}
// +-30 deg slope hover-slam verification
float slopeTan = MathF.Tan(30f * MathF.PI / 180f); // ~0.57735
foreach (float sign in new[] { 1f, -1f })
{
const int res = 129;
const float size = 8000f;
var slopeHeights = new float[res * res];
for (int gz = 0; gz < res; gz++)
{
float wz = -size * 0.5f + (gz / (float)(res - 1)) * size;
float h = sign > 0f ? MathF.Max(0f, wz * slopeTan) : MathF.Max(0f, (1000f - wz) * slopeTan);
for (int gx = 0; gx < res; gx++)
{
slopeHeights[gz * res + gx] = h;
}
}
var slopeTerrain = TerrainField.LoadHeightmap(size, res, slopeHeights, 0f, 3000f, 2UL);
DropSurfaceSample SlopeQuery(float x, float z, float footR, float refMaxY)
{
float sy = slopeTerrain.SampleHeight(x, z);
var (nx, ny, nz) = slopeTerrain.SampleNormal(x, z);
return new DropSurfaceSample(sy, Vector3.Normalize(new Vector3(nx, ny, nz)), false, false, false, false);
}
var sionPreset = OrbitalPodPreset.GetContender(ArenaMapKind.Sion);
float startZ = -400f;
float startSurf = slopeTerrain.SampleHeight(0f, startZ);
var pod = new OrbitalPod
{
PodId = 300 + (sign > 0 ? 1 : 2),
PodKind = OrbitalPodKind.Contender,
Phase = OrbitalPodPhase.Freefall,
X = 0f,
Y = startSurf + sionPreset.StartAltAgl,
Z = startZ,
VelY = sionPreset.InitialVelY,
LookForwardX = 0f,
LookForwardZ = 1f,
SteerForwardCmd = 1.0f,
Yaw = 0f
};
float burnStartAgl = -1f;
bool touched = false;
for (int t = 0; t < 3000; t++)
{
if (OrbitalDropKinematics.StepPod(pod, ArenaSession.FixedDt, slopeTerrain, SlopeQuery, FlatClear, out bool retroStarted, out _))
{
touched = true;
break;
}
if (retroStarted)
{
burnStartAgl = pod.Y - slopeTerrain.SampleHeight(pod.X, pod.Z);
}
}
Assert.True(touched, $"Slope sign={sign} pod failed to touch down");
Assert.True(pod.TouchdownSpeed < 2.5f, $"Slope sign={sign} touchdown speed {pod.TouchdownSpeed:F2} >= 2.5 m/s");
Assert.InRange(burnStartAgl, 5f, 160f);
float endTerrain = slopeTerrain.SampleHeight(pod.X, pod.Z);
Assert.True(MathF.Abs(pod.Y - endTerrain) < 0.001f, $"Slope sign={sign} penetration/hover error {pod.Y - endTerrain:F5}m");
_output.WriteLine($"Slope sign={sign:+#;-#}: flight={pod.FlightTime:F2}s, retroAgl={burnStartAgl:F2}m, tdVel={pod.TouchdownSpeed:F2} m/s");
}
}
[Fact]
public void SquadFormation_TrioDrop_ZeroPodOverlapAndFormationVisible()
{
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion, slot0Human: true, squadSize: 3);
var state = session.State;
Assert.Equal(3, state.SquadSize);
// Verify 4 squads of 3; inter-squad anchors >= 220m apart, intra-squad pods >= 14m apart at launch
var squadGroups = state.Contenders.GroupBy(c => c.SquadId).ToList();
Assert.Equal(4, squadGroups.Count);
foreach (var grp in squadGroups)
{
var members = grp.ToList();
Assert.Equal(3, members.Count);
for (int a = 0; a < members.Count; a++)
{
for (int b = a + 1; b < members.Count; b++)
{
float d = MathF.Sqrt(
(members[a].X - members[b].X) * (members[a].X - members[b].X) +
(members[a].Z - members[b].Z) * (members[a].Z - members[b].Z));
Assert.True(d >= 14f, $"Same-squad launch separation too small: {d:F2}m");
}
}
}
// Different squad leaders >= 200m apart (anchors >= 220m, leaders +8m fwd)
for (int i = 0; i < squadGroups.Count; i++)
{
var li = state.GetSquadLeader(squadGroups[i].Key)!;
for (int j = i + 1; j < squadGroups.Count; j++)
{
var lj = state.GetSquadLeader(squadGroups[j].Key)!;
float d = MathF.Sqrt((li.X - lj.X) * (li.X - lj.X) + (li.Z - lj.Z) * (li.Z - lj.Z));
Assert.True(d >= 195f, $"Inter-squad separation too small: {d:F1}m");
}
}
// Allied persistent PVS + zero false DetectedBy from allies
Assert.True(session.IsEntityInPeerPvs(0, true, 1));
Assert.True(session.IsEntityInPeerPvs(0, true, 2));
Assert.Equal(0, state.ObserverStates[0].DetectedByCount);
// Step Wave 0 drop while player glides gently forward; track formation and touchdown separation
for (int t = 0; t < 2200; t++)
{
var p0 = state.Contenders[0];
session.SetHumanInput(0, new PlayerInput(
Throttle: 0.45f,
Steer: 0f,
AimWorldX: p0.X + MathF.Sin(p0.Yaw) * 100f,
AimWorldZ: p0.Z + MathF.Cos(p0.Yaw) * 100f,
Fire: false,
InteractPickup: false,
Brake: false));
session.Step();
if (state.Contenders.All(c => c.IsGroundedActive))
{
break;
}
}
Assert.All(state.Contenders, c => Assert.True(c.IsGroundedActive));
// Wingmen (1, 2) landed >= 12m apart from player (0) and each other, with 0 penetration
for (int a = 0; a < 3; a++)
{
AssertZeroChassisPenetration(state, state.Contenders[a]);
for (int b = a + 1; b < 3; b++)
{
float d = MathF.Sqrt(
(state.Contenders[a].X - state.Contenders[b].X) * (state.Contenders[a].X - state.Contenders[b].X) +
(state.Contenders[a].Z - state.Contenders[b].Z) * (state.Contenders[a].Z - state.Contenders[b].Z));
Assert.True(d >= 11.5f, $"Squadmates {a} & {b} landed too close: {d:F2}m");
}
}
// Verify AI allies do not target allies and friendly fire does 0 damage
var ally1 = state.Contenders[1];
float allyHpBefore = ally1.Grid.CoreHp;
session.SetContenderPose(0, 0f, 0f, 0f);
session.SetContenderPose(1, 0f, 20f, MathF.PI);
for (int t = 0; t < 30; t++)
{
session.SetHumanInput(0, new PlayerInput(0f, 0f, ally1.X, ally1.Z, Fire: true, InteractPickup: false, Brake: true));
session.Step();
Assert.False(ally1.AiTargetContenderId.HasValue && state.AreAllies(1, ally1.AiTargetContenderId.Value),
"AI wingman targeted an allied squadmate!");
}
Assert.Equal(allyHpBefore, ally1.Grid.CoreHp);
// Advance past Wave 2 cutoff and eliminate all 9 non-Squad-0 contenders -> Squad 0 wins!
state.Time = 250f;
session.Step();
Assert.True(state.OrbitalDrop.RespawnCutoffReached);
for (int i = 3; i < state.Contenders.Count; i++)
{
session.ForceEliminateContender(i);
}
MatchRules.UpdateMatchOutcome(state);
Assert.Equal(MatchPhase.Completed, state.Phase);
Assert.Equal(0, state.WinnerContenderId);
}
[Fact]
public void CorePvs_MaxDatagramCap_StrictlyUnder1152B()
{
var state = new MatchState(seed: 42, ArenaMapKind.Desert, skipInitialDrop: true, squadSize: 3);
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>(10);
for (int i = 0; i < 12; i++)
{
contenders.Add(new NetContenderState
{
SlotId = (byte)i,
Alive = true,
IsHuman = i < 3,
Lifecycle = ContenderLifecycle.Active,
Pos = new Vector3(i * 12f, 3f, -i * 6f),
Rot = Quaternion.Identity,
Vel = Vector3.Zero,
CoreHpRatio = 1f
});
walkers.Add(new NetWalkerEntry
{
IsContender = true,
EntityId = (byte)i,
Snapshot = new WalkerVisualSnapshot { LegCount = 4 }
});
}
byte[] payload = SnapshotCodec.EncodeCorePvs(
1, 10, 20, 12.5f, 0, 0, 772f, MatchPhase.Active, null, 0, 0xFFF,
local, Vector3.Zero, contenders, walkers, specs);
byte[] wire = SnapshotCodec.WrapLatest(payload, 1, 10);
Assert.True(wire.Length <= SnapshotCodec.MaxLatestDatagramBytes,
$"CorePvs wire frame {wire.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
}
private static void AssertZeroChassisPenetration(MatchState state, ContenderState c)

View file

@ -67,8 +67,9 @@ namespace RustToDust.Tests
}
}
// 3. Step 4.5s (270 ticks) so Wave 0 gear pods touch down into GroundDrops; all 14 non-Jackal chassis exist
for (int t = 0; t < 270; t++)
// 3. Step Wave 0 gear drop duration so Wave 0 gear pods touch down into GroundDrops; all 14 non-Jackal chassis exist
int gearDropTicks = map == ArenaMapKind.Sion ? 1600 : 900;
for (int t = 0; t < gearDropTicks; t++)
{
session.Step();
}

View file

@ -125,7 +125,7 @@ namespace RustToDust.Tests
// All 14 non-starter chassis launch in Wave 0 orbital gear pods and touch down into GroundDrops
var state = new MatchState(seed: 42);
for (int t = 0; t < 300; t++)
for (int t = 0; t < 900; t++)
{
state.Time += 1f / 60f;
state.OrbitalDrop.Step(1f / 60f);