Cut 6a: headless orbital drop kinematics, hover-slam, wave respawns, and DropPodEvent net seam
This commit is contained in:
parent
8ce9bece1f
commit
c2f1e5bf90
25 changed files with 2931 additions and 118 deletions
|
|
@ -11,7 +11,7 @@ namespace RustToDust.Tests
|
|||
[Fact]
|
||||
public void DrivingAndFiring_MovesBuggyInYmirAndBuildsWeaponHeat()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, slot0Human: true);
|
||||
using var session = new ArenaSession(seed: 42, slot0Human: true, skipInitialDrop: true);
|
||||
var player = session.State.Contenders[0];
|
||||
float startX = player.X;
|
||||
float startZ = player.Z;
|
||||
|
|
@ -53,7 +53,7 @@ namespace RustToDust.Tests
|
|||
[Fact]
|
||||
public void ChassisSwap_ToManticoreAndRaptor_ReplacesBodyWithoutLeakingYmirLanes()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 77, slot0Human: true);
|
||||
using var session = new ArenaSession(seed: 77, slot0Human: true, skipInitialDrop: true);
|
||||
var player = session.State.Contenders[0];
|
||||
int initialFreeSlots = session.World.FreeBodySlots;
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ namespace RustToDust.Tests
|
|||
[Fact]
|
||||
public void BroadsideFire_UsesDirectionalSupportRadiusNotMaxExtent()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 19, slot0Human: true);
|
||||
using var session = new ArenaSession(seed: 19, slot0Human: true, skipInitialDrop: true);
|
||||
var player = session.State.Contenders[0];
|
||||
|
||||
// Swap to Tank / Anvil (HalfWidth = 1.93m, HalfLength = 2.83m) where broadside vs forward differs by ~0.9m.
|
||||
|
|
@ -139,7 +139,7 @@ namespace RustToDust.Tests
|
|||
[Fact]
|
||||
public void TracerEvent_AssignsMonotonicId_AndPreservesAcrossAdvance()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 19, slot0Human: true);
|
||||
using var session = new ArenaSession(seed: 19, slot0Human: true, skipInitialDrop: true);
|
||||
var player = session.State.Contenders[0];
|
||||
float aimX = player.X + MathF.Sin(player.Yaw) * 25f;
|
||||
float aimZ = player.Z + MathF.Cos(player.Yaw) * 25f;
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ public sealed class AudioSynthTests
|
|||
[Fact]
|
||||
public void ClientArenaSession_DrainSimEvents_WorksInSoloAndLoopbackRemote()
|
||||
{
|
||||
using var local = new LocalArenaSession(seed: 42, ArenaMapKind.Desert, "AudioTester");
|
||||
using var local = new LocalArenaSession(seed: 42, ArenaMapKind.Desert, "AudioTester", skipInitialDrop: true);
|
||||
IClientArenaSession localIface = local;
|
||||
var events = new List<ISimEvent>();
|
||||
|
||||
|
|
@ -264,6 +264,12 @@ public sealed class AudioSynthTests
|
|||
remoteIface.BeginRenderFrame(1.0 / 60.0, 1.0f);
|
||||
}
|
||||
Assert.True(remote.IsJoined);
|
||||
host.Session.SetContenderPose(remote.LocalContenderId, 0f, 0f, 0f);
|
||||
for (int s = 0; s < 4; s++)
|
||||
{
|
||||
host.StepOnce(nowMs + 240 + s * 16);
|
||||
remoteIface.BeginRenderFrame(1.0 / 60.0, 1.0f);
|
||||
}
|
||||
|
||||
var rLocal = remoteIface.LocalContender;
|
||||
var fireInput = new PlayerInput(0f, 0f, rLocal.X + 30f, rLocal.Z, true, false, false);
|
||||
|
|
|
|||
|
|
@ -697,7 +697,7 @@ namespace RustToDust.Tests
|
|||
// b) Malformed 120B packet with cellCount=200 must return false cleanly without throwing!
|
||||
byte[] bad = new byte[120];
|
||||
bad[0] = (byte)LatestPacketKind.CorePvs;
|
||||
bad[88] = 200; // cellCount = 200 > 64 and > remaining bytes
|
||||
bad[91] = 200; // cellCount = 200 > 64 and > remaining bytes
|
||||
Assert.False(SnapshotCodec.TryDecodeCorePvs(bad, out _));
|
||||
bad[0] = (byte)LatestPacketKind.SpectatorOrbitHalf;
|
||||
bad[10] = 250;
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ namespace RustToDust.Tests
|
|||
[Fact]
|
||||
public void PerObserverDetectionIsolation_Human0SeesRivalWhileOccludedHuman5DoesNot()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 12, mapKind: ArenaMapKind.Desert, slot0Human: false);
|
||||
using var session = new ArenaSession(seed: 12, mapKind: ArenaMapKind.Desert, slot0Human: false, skipInitialDrop: true);
|
||||
session.SetHumanSlot(0, true, "Alpha");
|
||||
session.SetHumanSlot(5, true, "Bravo");
|
||||
|
||||
|
|
|
|||
586
tests/RustToDust.Tests/OrbitalDropTests.cs
Normal file
586
tests/RustToDust.Tests/OrbitalDropTests.cs
Normal file
|
|
@ -0,0 +1,586 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Numerics;
|
||||
using System.Threading;
|
||||
using GameCult.Networking;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Net;
|
||||
using RustToDust.Ymir;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace RustToDust.Tests
|
||||
{
|
||||
public sealed class OrbitalDropTests
|
||||
{
|
||||
private readonly ITestOutputHelper _output;
|
||||
|
||||
public OrbitalDropTests(ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HoverSlam_FlatDesertAnd30DegSionSlope_TouchdownUnder3MsAndZeroPenetration()
|
||||
{
|
||||
// 1. Flat Desert trajectory & cross-range steering [120m, 180m]
|
||||
{
|
||||
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;
|
||||
|
||||
int maxTicks = 600;
|
||||
float impactSpeed = -1f;
|
||||
float touchTime = -1f;
|
||||
float snapDiffAtTouchdown = float.NaN;
|
||||
session.State.ContenderPodTouchedDown += c =>
|
||||
{
|
||||
if (c.Id == 0)
|
||||
{
|
||||
snapDiffAtTouchdown = MathF.Abs(c.PrevY - c.Y);
|
||||
}
|
||||
};
|
||||
for (int t = 0; t < maxTicks; t++)
|
||||
{
|
||||
session.SetHumanInput(0, new PlayerInput(
|
||||
Throttle: 1.0f,
|
||||
Steer: 0f,
|
||||
AimWorldX: player.X,
|
||||
AimWorldZ: player.Z + 100f,
|
||||
Fire: false,
|
||||
InteractPickup: false,
|
||||
Brake: false));
|
||||
session.Step();
|
||||
|
||||
if (player.IsGroundedActive)
|
||||
{
|
||||
touchTime = session.State.Time;
|
||||
var tdEvent = session.State.PodEvents.LastOrDefault(e =>
|
||||
e.Kind == DropPodEventKind.PodTouchdownBlowPetals && e.ContenderId == 0);
|
||||
impactSpeed = MathF.Abs(tdEvent.VelY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
float glideDist = MathF.Sqrt((player.X - startX) * (player.X - startX) + (player.Z - startZ) * (player.Z - startZ));
|
||||
Assert.InRange(glideDist, 120f, 180f);
|
||||
|
||||
// Verify PrevY == Y right at touchdown SnapPreviousPose() and continuous post-Step settlement (< 0.06m, zero sky pop)
|
||||
Assert.True(snapDiffAtTouchdown < 1e-4f,
|
||||
$"Expected SnapPreviousPose clean right at touchdown: diff={snapDiffAtTouchdown:F6}");
|
||||
Assert.True(MathF.Abs(player.PrevY - player.Y) < 0.06f,
|
||||
$"Expected smooth 1-tick settlement post-touchdown: PrevY={player.PrevY:F5}, Y={player.Y:F5}");
|
||||
AssertZeroChassisPenetration(session.State, player);
|
||||
_output.WriteLine($"Desert flat glide: touchTime={touchTime:F2}s, impactSpeed={impactSpeed:F2} m/s, glide={glideDist:F1}m");
|
||||
}
|
||||
|
||||
// 2. ~30 deg Sion mountain slope (uphill + downhill)
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion, slot0Human: true);
|
||||
var sion = session.State.SionMap!;
|
||||
|
||||
// Find a steep Sion mountain slope spot (~25-33 deg, Ny in [0.83, 0.90]) outside buildings
|
||||
float slopeX = 0f;
|
||||
float slopeZ = 0f;
|
||||
float bestDiff = float.PositiveInfinity;
|
||||
float targetNy = MathF.Cos(30f * MathF.PI / 180f); // ~0.866
|
||||
for (float z = -1200f; z <= 1200f; z += 24f)
|
||||
{
|
||||
for (float x = -1200f; x <= 1200f; x += 24f)
|
||||
{
|
||||
if (sion.IsInsideAnyBuildingXz(x, z, 14f)) continue;
|
||||
var (_, ny, _) = session.State.Terrain.SampleNormal(x, z);
|
||||
if (ny >= 0.80f && ny <= 0.91f)
|
||||
{
|
||||
float diff = MathF.Abs(ny - targetNy);
|
||||
if (diff < bestDiff)
|
||||
{
|
||||
bestDiff = diff;
|
||||
slopeX = x;
|
||||
slopeZ = z;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert.True(bestDiff < 0.08f, "Expected to find a ~30 deg Sion slope test site");
|
||||
|
||||
var (snx, sny, snz) = session.State.Terrain.SampleNormal(slopeX, slopeZ);
|
||||
float slopeDeg = MathF.Acos(Math.Clamp(sny, -1f, 1f)) * (180f / MathF.PI);
|
||||
|
||||
// Test launching pod directly above slope with uphill lateral input
|
||||
var c = session.State.Contenders[1];
|
||||
float uphillYaw = MathF.Atan2(-snx, -snz);
|
||||
var pod = session.State.OrbitalDrop.LaunchContenderPod(
|
||||
c, waveIndex: 0, slopeX, slopeZ, uphillYaw, session.QueryDropSurface, isRespawn: false);
|
||||
pod.AllowFlatRoofLanding = false;
|
||||
|
||||
float snapDiffAtTouchdown = float.NaN;
|
||||
session.State.ContenderPodTouchedDown += tc =>
|
||||
{
|
||||
if (tc.Id == c.Id) snapDiffAtTouchdown = MathF.Abs(tc.PrevY - tc.Y);
|
||||
};
|
||||
|
||||
float impactSpeed = -1f;
|
||||
for (int t = 0; t < 600; t++)
|
||||
{
|
||||
pod.LookForwardX = -snx;
|
||||
pod.LookForwardZ = -snz;
|
||||
pod.SteerForwardCmd = 0.8f;
|
||||
session.Step();
|
||||
if (c.IsGroundedActive)
|
||||
{
|
||||
var td = session.State.PodEvents.Last(e =>
|
||||
e.Kind == DropPodEventKind.PodTouchdownBlowPetals && e.PodId == pod.PodId);
|
||||
impactSpeed = MathF.Abs(td.VelY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.True(c.IsGroundedActive, $"Pod failed to land on {slopeDeg:F1} deg Sion slope");
|
||||
Assert.InRange(impactSpeed, 0.5f, 2.99f);
|
||||
Assert.True(snapDiffAtTouchdown < 1e-4f);
|
||||
Assert.True(MathF.Abs(c.PrevY - c.Y) < 0.06f);
|
||||
AssertZeroChassisPenetration(session.State, c);
|
||||
_output.WriteLine($"Sion {slopeDeg:F1} deg slope: impactSpeed={impactSpeed:F2} m/s, terrainY={session.State.Terrain.SampleHeight(c.X, c.Z):F2}, chassisY={c.Y:F2}");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Wave0_GearPodsTouchDownAheadOfContenders_Around3Point3Seconds()
|
||||
{
|
||||
foreach (var map in new[] { ArenaMapKind.Desert, ArenaMapKind.Sion })
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, map, slot0Human: true);
|
||||
Assert.True(session.State.OrbitalDrop.ActivePods.Count >= 52,
|
||||
$"Expected 12 contender + 40 gear pods at t=0, got {session.State.OrbitalDrop.ActivePods.Count}");
|
||||
Assert.Empty(session.State.GroundDrops);
|
||||
|
||||
float maxGearTouchTime = 0f;
|
||||
float minContenderTouchTime = float.PositiveInfinity;
|
||||
|
||||
for (int t = 0; t < 660; t++)
|
||||
{
|
||||
session.Step();
|
||||
if (session.State.OrbitalDrop.ActivePods.Count == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.Empty(session.State.OrbitalDrop.ActivePods);
|
||||
Assert.True(session.State.GroundDrops.Count >= 40,
|
||||
$"Expected >= 40 GroundDrops after Wave 0, got {session.State.GroundDrops.Count}");
|
||||
Assert.Equal(40, session.State.PodEvents.Count(e =>
|
||||
e.Kind == DropPodEventKind.PodTouchdownBlowPetals && e.PodKind != OrbitalPodKind.Contender));
|
||||
|
||||
foreach (var ev in session.State.PodEvents)
|
||||
{
|
||||
if (ev.Kind != DropPodEventKind.PodTouchdownBlowPetals) continue;
|
||||
// Use Wave 0 launch time (0s) and PodEvents order/timestamps via simulation
|
||||
}
|
||||
|
||||
// Re-measure exact per-pod FlightTime on a MatchState sweep
|
||||
var state = new MatchState(seed: 42, map);
|
||||
var gearTouchTimes = new List<float>();
|
||||
var contenderTouchTimes = new List<float>();
|
||||
for (int t = 0; t < 660; t++)
|
||||
{
|
||||
state.Time += ArenaSession.FixedDt;
|
||||
state.OrbitalDrop.Step(ArenaSession.FixedDt, state.DefaultDropSurfaceQuery, (pod, _) =>
|
||||
{
|
||||
if (pod.PodKind == OrbitalPodKind.Contender) contenderTouchTimes.Add(pod.FlightTime);
|
||||
else gearTouchTimes.Add(pod.FlightTime);
|
||||
});
|
||||
}
|
||||
|
||||
maxGearTouchTime = gearTouchTimes.Max();
|
||||
minContenderTouchTime = contenderTouchTimes.Min();
|
||||
float lead = minContenderTouchTime - maxGearTouchTime;
|
||||
_output.WriteLine($"{map}: maxGearTouch={maxGearTouchTime:F2}s, minContenderTouch={minContenderTouchTime:F2}s, lead={lead:F2}s");
|
||||
|
||||
Assert.Equal(40, gearTouchTimes.Count);
|
||||
Assert.Equal(12, contenderTouchTimes.Count);
|
||||
Assert.InRange(lead, 2.5f, 4.2f);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Sion64TargetSweep_ZeroBuildingInteriorLandings_AndZeroHoverStalls()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion, slot0Human: true);
|
||||
var sion = session.State.SionMap!;
|
||||
|
||||
// Pick 64 targets deliberately across Old Town dense buildings (center & towers) + valley
|
||||
var rng = new Random(101);
|
||||
int tested = 0;
|
||||
int buildingOverTargets = 0;
|
||||
float worstTouchTime = 0f;
|
||||
float worstImpactSpeed = 0f;
|
||||
|
||||
for (int i = 0; i < 64; i++)
|
||||
{
|
||||
float tx;
|
||||
float tz;
|
||||
if (i < 32)
|
||||
{
|
||||
// Aim directly onto real Sion building rooftops in Old Town & towers to stress deflection!
|
||||
var b = sion.Buildings[(i * 71) % sion.Buildings.Count];
|
||||
tx = Math.Clamp(b.CenterX, -1350f, 1350f);
|
||||
tz = Math.Clamp(b.CenterZ, -1350f, 1350f);
|
||||
buildingOverTargets++;
|
||||
}
|
||||
else
|
||||
{
|
||||
tx = (float)(rng.NextDouble() * 1800.0 - 900.0);
|
||||
tz = (float)(rng.NextDouble() * 1800.0 - 900.0);
|
||||
}
|
||||
|
||||
var pod = session.State.OrbitalDrop.LaunchGearPod(0, tx, tz, null, Catalog.Autocannon, session.QueryDropSurface);
|
||||
bool landed = false;
|
||||
for (int t = 0; t < 600; t++)
|
||||
{
|
||||
bool touched = OrbitalDropKinematics.StepPod(
|
||||
pod,
|
||||
ArenaSession.FixedDt,
|
||||
session.State.Terrain,
|
||||
session.QueryDropSurface,
|
||||
session.State.FindClearDropPoint,
|
||||
out _,
|
||||
out var touchSample);
|
||||
if (touched)
|
||||
{
|
||||
landed = true;
|
||||
worstTouchTime = MathF.Max(worstTouchTime, pod.FlightTime);
|
||||
worstImpactSpeed = MathF.Max(worstImpactSpeed, pod.TouchdownSpeed);
|
||||
Assert.False(sion.IsInsideAnyBuildingXz(pod.X, pod.Z, 0f),
|
||||
$"Target #{i} ({tx:F1},{tz:F1}) landed inside Sion building at ({pod.X:F1},{pod.Z:F1})!");
|
||||
Assert.False(touchSample.IsBuildingRoof);
|
||||
Assert.InRange(pod.TouchdownSpeed, 0.5f, 2.99f);
|
||||
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");
|
||||
tested++;
|
||||
}
|
||||
|
||||
_output.WriteLine($"Sion 64-target sweep ({buildingOverTargets} directly over buildings): {tested}/64 clear street landings, maxFlight={worstTouchTime:F2}s, maxImpact={worstImpactSpeed:F2} m/s");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SionHumanPod_FlatRoofValidLanding_AndSkyscraperLateralWallGuard()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion, slot0Human: true);
|
||||
var sion = session.State.SionMap!;
|
||||
|
||||
// 1. Find a tall wide flat-roofed Sion building (HalfX >= 7m, HalfZ >= 7m, height >= 10m)
|
||||
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;
|
||||
|
||||
// Land human player pod on that flat roof and verify driving on roof works!
|
||||
var player = session.State.Contenders[0];
|
||||
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 < 600 && !player.IsGroundedActive; t++)
|
||||
{
|
||||
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 20f, false, false, false));
|
||||
session.Step();
|
||||
}
|
||||
|
||||
Assert.True(player.IsGroundedActive);
|
||||
Assert.True(player.TouchdownOnRoof);
|
||||
float terrainUnder = session.State.Terrain.SampleHeight(player.X, player.Z);
|
||||
Assert.True(player.Y > terrainUnder + 6f, $"Expected player seated on roof above terrain ({player.Y:F2} > {terrainUnder + 6f:F2})");
|
||||
|
||||
// Drive forward slightly on roof -> stays supported on roof (doesn't fall through roof)
|
||||
float yStartOnRoof = player.Y;
|
||||
for (int t = 0; t < 20; t++)
|
||||
{
|
||||
session.SetHumanInput(0, new PlayerInput(0.4f, 0f, player.X, player.Z + 20f, false, false, false));
|
||||
session.Step();
|
||||
}
|
||||
Assert.True(player.Y >= yStartOnRoof - 0.6f, $"Player sank through flat Sion roof: {yStartOnRoof:F2} -> {player.Y:F2}");
|
||||
|
||||
// 2. Lateral Building Wall Guard: steer straight into a tall Sion building face at mid-height
|
||||
SionBuildingAabb? tallBldg = null;
|
||||
for (int i = 0; i < sion.Buildings.Count; i++)
|
||||
{
|
||||
var b = sion.Buildings[i];
|
||||
if ((b.RoofY - b.GroundY) >= 22f && MathF.Abs(b.CenterX) < 900f && MathF.Abs(b.CenterZ) < 900f)
|
||||
{
|
||||
if (!sion.IsInsideAnyBuildingXz(b.CenterX, b.CenterZ - b.HalfZ - 12f, 3f))
|
||||
{
|
||||
tallBldg = b;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert.NotNull(tallBldg);
|
||||
var tb = tallBldg!.Value;
|
||||
|
||||
var c2 = session.State.Contenders[2];
|
||||
c2.IsHuman = true;
|
||||
float wallStartX = tb.CenterX;
|
||||
float wallStartZ = tb.CenterZ - tb.HalfZ - 10f;
|
||||
var wallPod = session.State.OrbitalDrop.LaunchContenderPod(
|
||||
c2, 0, wallStartX, wallStartZ, 0f, session.QueryDropSurface, isRespawn: false);
|
||||
// Position pod below roof height (~mid-wall) with high speed straight into the building wall
|
||||
wallPod.Y = tb.GroundY + (tb.RoofY - tb.GroundY) * 0.5f + 45f;
|
||||
wallPod.VelY = -30f;
|
||||
|
||||
for (int t = 0; t < 360 && !c2.IsGroundedActive; t++)
|
||||
{
|
||||
session.SetHumanInput(c2.Id, new PlayerInput(
|
||||
Throttle: 1f,
|
||||
Steer: 0f,
|
||||
AimWorldX: tb.CenterX,
|
||||
AimWorldZ: tb.CenterZ + 50f,
|
||||
Fire: false,
|
||||
InteractPickup: false,
|
||||
Brake: false));
|
||||
session.Step();
|
||||
|
||||
if (wallPod.Phase != OrbitalPodPhase.Popped && wallPod.Y < tb.RoofY - 1.0f)
|
||||
{
|
||||
Assert.False(sion.IsInsideAnyBuildingXz(wallPod.X, wallPod.Z, 0f),
|
||||
$"Pod clipped laterally inside tall building {tb.Id} at y={wallPod.Y:F1}m (roof={tb.RoofY:F1}m)");
|
||||
}
|
||||
}
|
||||
|
||||
Assert.True(c2.IsGroundedActive, "Pod stalled against building wall");
|
||||
Assert.False(sion.IsInsideAnyBuildingXz(c2.X, c2.Z, 0f), "Pod ended inside tall building interior!");
|
||||
_output.WriteLine($"Wall guard verified against {tb.Id} (height={tb.RoofY - tb.GroundY:F1}m): landed outside at ({c2.X:F1}, {c2.Z:F1})");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Wave1To3Respawns_AndFinalRingCutoff_CompletesMatchCleanly()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert, slot0Human: true);
|
||||
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++)
|
||||
{
|
||||
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)
|
||||
{
|
||||
session.Step();
|
||||
}
|
||||
for (int i = 1; i < state.Contenders.Count; i++)
|
||||
{
|
||||
session.ForceEliminateContender(i);
|
||||
}
|
||||
MatchRules.UpdateMatchOutcome(state);
|
||||
Assert.Equal(MatchPhase.Active, state.Phase);
|
||||
for (int i = 1; i < state.Contenders.Count; i++)
|
||||
{
|
||||
Assert.Equal(ContenderLifecycle.WaitingForRespawnWave, state.Contenders[i].Lifecycle);
|
||||
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)
|
||||
{
|
||||
session.Step();
|
||||
}
|
||||
Assert.Equal(1, state.OrbitalDrop.CurrentWaveIndex);
|
||||
for (int i = 1; i < state.Contenders.Count; i++)
|
||||
{
|
||||
Assert.Equal(ContenderLifecycle.Deploying, state.Contenders[i].Lifecycle);
|
||||
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++)
|
||||
{
|
||||
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)
|
||||
{
|
||||
session.Step();
|
||||
}
|
||||
session.ForceEliminateContender(0);
|
||||
MatchRules.UpdateMatchOutcome(state);
|
||||
|
||||
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)
|
||||
{
|
||||
session.Step();
|
||||
}
|
||||
Assert.Equal(2, state.OrbitalDrop.CurrentWaveIndex);
|
||||
Assert.True(state.OrbitalDrop.RespawnCutoffReached);
|
||||
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)
|
||||
{
|
||||
session.Step();
|
||||
}
|
||||
var aiLate = state.Contenders[1];
|
||||
session.ForceEliminateContender(1);
|
||||
Assert.Equal(ContenderLifecycle.Eliminated, aiLate.Lifecycle);
|
||||
|
||||
// Kill all remaining rivals after cutoff -> MatchPhase becomes Completed, WinnerContenderId == 0!
|
||||
for (int i = 2; i < state.Contenders.Count; i++)
|
||||
{
|
||||
session.ForceEliminateContender(i);
|
||||
}
|
||||
MatchRules.UpdateMatchOutcome(state);
|
||||
Assert.Equal(MatchPhase.Completed, state.Phase);
|
||||
Assert.Equal(0, state.WinnerContenderId);
|
||||
|
||||
// 5. Verify SetContenderPose mid-drop cleanly cancels active pod
|
||||
using var midDropSession = new ArenaSession(seed: 77, ArenaMapKind.Desert, slot0Human: true);
|
||||
Assert.True(midDropSession.State.Contenders[0].IsInDropPod);
|
||||
midDropSession.SetContenderPose(0, 15f, -20f, 0.5f);
|
||||
Assert.True(midDropSession.State.Contenders[0].IsGroundedActive);
|
||||
Assert.Null(midDropSession.State.Contenders[0].ActivePodId);
|
||||
Assert.DoesNotContain(midDropSession.State.OrbitalDrop.ActivePods,
|
||||
p => p.PodKind == OrbitalPodKind.Contender && p.ContenderId == 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NetworkSync_Wave0OrbitalPods_ReplicateUnder1152ByteUdpCap()
|
||||
{
|
||||
using var host = new ServerMatchHost(IPAddress.Loopback, 0, seed: 42, ArenaMapKind.Desert, maxHumans: 12, autoRestartSec: 0);
|
||||
var ep = new IPEndPoint(IPAddress.Loopback, host.BoundPort);
|
||||
|
||||
using var client = new RemoteArenaSession(ep, "DropPilot");
|
||||
IClientArenaSession clientIface = client;
|
||||
|
||||
int maxUdpBytes = 0;
|
||||
int latestPacketsSeen = 0;
|
||||
client.DebugInboundLatestDropFilter = payload =>
|
||||
{
|
||||
byte[] frame = SnapshotCodec.WrapLatest(payload, host.MatchGeneration, (uint)(latestPacketsSeen + 1));
|
||||
byte[] udp = CultNetRudpPacketCodec.Encode(new CultNetRudpPacket
|
||||
{
|
||||
PacketType = CultNetRudpPacketType.Data,
|
||||
ConnectionId = 0x52544431,
|
||||
Sequence = (uint)(latestPacketsSeen + 1),
|
||||
ChannelId = SnapshotCodec.ChannelLatest,
|
||||
Sequenced = true,
|
||||
Payload = frame
|
||||
});
|
||||
maxUdpBytes = Math.Max(maxUdpBytes, udp.Length);
|
||||
latestPacketsSeen++;
|
||||
return false;
|
||||
};
|
||||
|
||||
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
var deadline = DateTimeOffset.UtcNow.AddSeconds(3);
|
||||
while (DateTimeOffset.UtcNow < deadline && !client.IsJoined)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
client.PumpNetwork(nowMs);
|
||||
Thread.Sleep(2);
|
||||
}
|
||||
Assert.True(client.IsJoined);
|
||||
Assert.True(clientIface.LocalContender.IsInDropPod);
|
||||
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
|
||||
var simEvents = new List<ISimEvent>();
|
||||
for (int t = 0; t < 480; t++)
|
||||
{
|
||||
nowMs += 16;
|
||||
clientIface.SubmitLocalInput(new PlayerInput(
|
||||
Throttle: 0.7f,
|
||||
Steer: 0f,
|
||||
AimWorldX: clientIface.LocalContender.X,
|
||||
AimWorldZ: clientIface.LocalContender.Z + 50f,
|
||||
Fire: false,
|
||||
InteractPickup: false,
|
||||
Brake: false), isPhysicsTick: true);
|
||||
host.StepOnce(nowMs);
|
||||
client.PumpNetwork(nowMs);
|
||||
clientIface.DrainSimEvents(simEvents);
|
||||
if (clientIface.LocalContender.IsGroundedActive &&
|
||||
host.Session.State.Contenders[clientIface.LocalContenderId].IsGroundedActive)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.True(latestPacketsSeen > 10);
|
||||
Assert.True(maxUdpBytes > 0 && maxUdpBytes <= SnapshotCodec.MaxLatestDatagramBytes,
|
||||
$"UDP latest datagram exceeded {SnapshotCodec.MaxLatestDatagramBytes}B cap: max={maxUdpBytes}B");
|
||||
Assert.True(clientIface.LocalContender.IsGroundedActive,
|
||||
$"Expected RemoteArenaSession LocalContender grounded after drop, lifecycle={clientIface.LocalContender.Lifecycle}");
|
||||
Assert.Contains(simEvents, e => e is DropPodEvent dpe && dpe.Kind == (byte)DropPodEventKind.PodTouchdownBlowPetals && dpe.ContenderId == clientIface.LocalContenderId);
|
||||
|
||||
_output.WriteLine($"Network orbital drop: maxUdpBytes={maxUdpBytes}B (cap {SnapshotCodec.MaxLatestDatagramBytes}B), packets={latestPacketsSeen}, podEvents={simEvents.OfType<DropPodEvent>().Count()}");
|
||||
}
|
||||
|
||||
private static void AssertZeroChassisPenetration(MatchState state, ContenderState c)
|
||||
{
|
||||
var spec = c.Grid.Spec;
|
||||
float physHalfH = ArenaSession.GetPhysicsHalfHeight(spec);
|
||||
Quaternion q = Quaternion.Normalize(new Quaternion(c.CurrRotX, c.CurrRotY, c.CurrRotZ, c.CurrRotW));
|
||||
Vector3 center = new(c.X, c.Y, c.Z);
|
||||
|
||||
float groundCenter = state.Terrain.SampleHeight(c.X, c.Z);
|
||||
float centerClearance = (c.Y - physHalfH) - groundCenter;
|
||||
Assert.True(centerClearance >= 0f,
|
||||
$"Chassis center penetrated terrain: bottom={c.Y - physHalfH:F4} < ground={groundCenter:F4} (clearance={centerClearance:F4}m)");
|
||||
|
||||
Span<Vector3> localCorners = stackalloc Vector3[4]
|
||||
{
|
||||
new Vector3(-spec.HalfWidth, -physHalfH, -spec.HalfLength),
|
||||
new Vector3( spec.HalfWidth, -physHalfH, -spec.HalfLength),
|
||||
new Vector3(-spec.HalfWidth, -physHalfH, spec.HalfLength),
|
||||
new Vector3( spec.HalfWidth, -physHalfH, spec.HalfLength)
|
||||
};
|
||||
for (int k = 0; k < 4; k++)
|
||||
{
|
||||
Vector3 wp = center + Vector3.Transform(localCorners[k], q);
|
||||
float gh = state.Terrain.SampleHeight(wp.X, wp.Z);
|
||||
float clearance = wp.Y - gh;
|
||||
Assert.True(clearance >= 0f,
|
||||
$"Chassis corner {k} penetrated terrain: cornerY={wp.Y:F4} < ground={gh:F4} (clearance={clearance:F4}m)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -67,7 +67,11 @@ namespace RustToDust.Tests
|
|||
}
|
||||
}
|
||||
|
||||
// 3. All 14 non-Jackal chassis drops exist in GroundDrops
|
||||
// 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++)
|
||||
{
|
||||
session.Step();
|
||||
}
|
||||
var droppedChassisIds = state.GroundDrops
|
||||
.Where(d => d.Chassis is not null)
|
||||
.Select(d => d.Chassis!.Id)
|
||||
|
|
@ -91,15 +95,17 @@ namespace RustToDust.Tests
|
|||
$"Sion Seed={seed}: Expected >= 3 reachable drops within 110-190m ring sector, got {nearRingDrops}");
|
||||
}
|
||||
|
||||
// 4. Zero tick-0 spawn ambush
|
||||
var player = state.Contenders[0];
|
||||
// 4. Zero tick-0 spawn ambush (instant ground start check)
|
||||
using var instantSession = new ArenaSession(seed, map, skipInitialDrop: true);
|
||||
var instantState = instantSession.State;
|
||||
var player = instantState.Contenders[0];
|
||||
float initialHp = player.Grid.CoreHp;
|
||||
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 10f, false, false, true));
|
||||
session.Step();
|
||||
instantSession.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 10f, false, false, true));
|
||||
instantSession.Step();
|
||||
|
||||
for (int i = 1; i < state.Contenders.Count; i++)
|
||||
for (int i = 1; i < instantState.Contenders.Count; i++)
|
||||
{
|
||||
var ai = state.Contenders[i];
|
||||
var ai = instantState.Contenders[i];
|
||||
Assert.False(ai.FireCmd, $"Map={map}, Seed={seed}: AI {ai.Id} fired on tick 0!");
|
||||
}
|
||||
Assert.Equal(initialHp, player.Grid.CoreHp);
|
||||
|
|
@ -293,7 +299,7 @@ namespace RustToDust.Tests
|
|||
[Fact]
|
||||
public void RenderInterpolation_CameraAnchorAndContenderPose_ZeroHorizPhaseMismatchAcrossAlpha()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert, slot0Human: true);
|
||||
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert, slot0Human: true, skipInitialDrop: true);
|
||||
IsolateContenders(session, 0);
|
||||
var player = session.State.Contenders[0];
|
||||
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ namespace RustToDust.Tests
|
|||
[Fact]
|
||||
public void ArenaSession_SionLoadsHeightfieldAndMeshesSpawnsClearBlocksLosAndStepsCleanly()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion, slot0Human: true);
|
||||
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion, slot0Human: true, skipInitialDrop: true);
|
||||
var state = session.State;
|
||||
var sion = state.SionMap!;
|
||||
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ namespace RustToDust.Tests
|
|||
[Fact]
|
||||
public void ArenaSession_BuggyDrivesAcrossDunesWithoutNanAndTracksElevation()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, slot0Human: true);
|
||||
using var session = new ArenaSession(seed: 42, slot0Human: true, skipInitialDrop: true);
|
||||
var player = session.State.Contenders[0];
|
||||
int initialBrushes = session.State.Terrain.Brushes.Count;
|
||||
|
||||
|
|
|
|||
|
|
@ -123,8 +123,13 @@ namespace RustToDust.Tests
|
|||
Assert.True(Catalog.Condor.BaseCellArmor < Catalog.Anvil.BaseCellArmor,
|
||||
$"Condor armor ({Catalog.Condor.BaseCellArmor}) must be lighter than Anvil ({Catalog.Anvil.BaseCellArmor})");
|
||||
|
||||
// All 14 non-starter chassis spawn as salvageable drops in MatchState
|
||||
// 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++)
|
||||
{
|
||||
state.Time += 1f / 60f;
|
||||
state.OrbitalDrop.Step(1f / 60f);
|
||||
}
|
||||
var droppedChassisIds = state.GroundDrops
|
||||
.Where(d => d.Chassis is not null)
|
||||
.Select(d => d.Chassis!.Id)
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ namespace RustToDust.Tests
|
|||
[Fact]
|
||||
public void QuickBolt_MountsScavengedModuleIntoEmptyMatchingHardpointBeforeCargo()
|
||||
{
|
||||
var state = new MatchState(seed: 42);
|
||||
var state = new MatchState(seed: 42, skipInitialDrop: true);
|
||||
var player = state.Contenders[0];
|
||||
player.IsHuman = true;
|
||||
|
||||
|
|
@ -269,7 +269,7 @@ namespace RustToDust.Tests
|
|||
[Fact]
|
||||
public void Vtol_ReverseIntoTallMesaAndCliffDrop_ZeroUndergroundTicks()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, slot0Human: true);
|
||||
using var session = new ArenaSession(seed: 42, slot0Human: true, skipInitialDrop: true);
|
||||
var player = session.State.Contenders[0];
|
||||
IsolateContenders(session, player.Id);
|
||||
|
||||
|
|
@ -494,7 +494,7 @@ namespace RustToDust.Tests
|
|||
[Fact]
|
||||
public void InteractPickup_UsesUnifiedNearestDropPriority_ChassisCloserThanModule()
|
||||
{
|
||||
var state = new MatchState(seed: 42);
|
||||
var state = new MatchState(seed: 42, skipInitialDrop: true);
|
||||
var player = state.Contenders[0];
|
||||
player.IsHuman = true;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue