2026-12-05 11:26:18 +01:00
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 ) ;
2026-12-05 12:50:13 +01:00
var skyCheck = session . QueryDropSurface ( pod . X , pod . Z , 0f , 500f ) ;
Assert . False ( skyCheck . IsBuildingRoof ,
$"Target #{i} ({tx:F1},{tz:F1}) landed inside solid Sion building at ({pod.X:F1},{pod.Z:F1})!" ) ;
Assert . False ( touchSample . IsInsideSolidBuilding ,
$"Target #{i} ({tx:F1},{tz:F1}) landed with IsInsideSolidBuilding=true at ({pod.X:F1},{pod.Z:F1})!" ) ;
2026-12-05 11:26:18 +01:00
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()}" ) ;
}
2026-12-05 12:11:51 +01:00
[Fact]
public void RemoteArenaSession_Wave0Pods_AdvanceSmoothlyAndZeroGhostPodsAfterTouchdown ( )
{
using var host = new ServerMatchHost ( IPAddress . Loopback , 0 , seed : 42 , ArenaMapKind . Sion , maxHumans : 12 , autoRestartSec : 0 ) ;
var ep = new IPEndPoint ( IPAddress . Loopback , host . BoundPort ) ;
using var client = new RemoteArenaSession ( ep , "SionDropPilot" ) ;
IClientArenaSession clientIface = client ;
long nowMs = DateTimeOffset . UtcNow . ToUnixTimeMilliseconds ( ) ;
var deadline = DateTimeOffset . UtcNow . AddSeconds ( 4 ) ;
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 ) ;
var initialLocalPod = clientIface . ActivePods . FirstOrDefault (
p = > p . PodKind = = OrbitalPodKind . Contender & & p . ContenderId = = clientIface . LocalContenderId ) ;
var initialGearPod = clientIface . ActivePods . FirstOrDefault ( p = > p . PodKind ! = OrbitalPodKind . Contender ) ;
Assert . NotNull ( initialLocalPod ) ;
Assert . NotNull ( initialGearPod ) ;
float localY0 = initialLocalPod ! . Y ;
float localAgl0 = initialLocalPod . LastAgl ;
int trackedGearId = initialGearPod ! . PodId ;
float gearY0 = initialGearPod . Y ;
float gearAgl0 = initialGearPod . LastAgl ;
Assert . True ( localAgl0 > 50f , $"Expected initialized local LastAgl > 50m, got {localAgl0:F2}" ) ;
Assert . True ( gearAgl0 > 50f , $"Expected initialized gear LastAgl > 50m, got {gearAgl0:F2}" ) ;
// Step 60 ticks (1.0s) and verify BOTH local pod and replicated gear pods descend smoothly and update LastAgl
for ( int t = 0 ; t < 60 ; t + + )
{
nowMs + = 16 ;
clientIface . SubmitLocalInput ( new PlayerInput (
Throttle : 0.4f ,
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 . BeginRenderFrame ( ArenaSession . FixedDt , 1.0f ) ;
}
var midLocalPod = clientIface . ActivePods . FirstOrDefault (
p = > p . PodKind = = OrbitalPodKind . Contender & & p . ContenderId = = clientIface . LocalContenderId ) ;
var midGearPod = clientIface . ActivePods . FirstOrDefault ( p = > p . PodId = = trackedGearId ) ;
Assert . NotNull ( midLocalPod ) ;
Assert . NotNull ( midGearPod ) ;
Assert . True ( midLocalPod ! . Y < localY0 - 15f , $"Local pod froze on client: {localY0:F2} -> {midLocalPod.Y:F2}" ) ;
Assert . True ( midLocalPod . LastAgl < localAgl0 - 15f & & midLocalPod . LastAgl > 0f ,
$"Local pod LastAgl failed to update: {localAgl0:F2} -> {midLocalPod.LastAgl:F2}" ) ;
Assert . True ( midGearPod ! . Y < gearY0 - 20f , $"Gear pod froze on client: {gearY0:F2} -> {midGearPod.Y:F2}" ) ;
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
var simEvents = new List < ISimEvent > ( ) ;
for ( int t = 0 ; t < 560 ; t + + )
{
nowMs + = 16 ;
clientIface . SubmitLocalInput ( new PlayerInput (
Throttle : 0f ,
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 . BeginRenderFrame ( ArenaSession . FixedDt , 1.0f ) ;
clientIface . DrainSimEvents ( simEvents ) ;
}
Assert . True ( clientIface . LocalContender . IsGroundedActive ,
$"Expected LocalContender grounded after Wave 0, lifecycle={clientIface.LocalContender.Lifecycle}" ) ;
Assert . Empty ( host . Session . State . OrbitalDrop . ActivePods ) ;
Assert . Empty ( clientIface . ActivePods ) ;
_output . WriteLine ( $"Sion net Wave 0: local {localY0:F1}->{midLocalPod.Y:F1}, gear {gearY0:F1}->{midGearPod.Y:F1}, final ActivePods={clientIface.ActivePods.Count}" ) ;
}
[Fact]
public void RemoteArenaSession_Wave1Respawn_ReplicatesResetJackalChassisToLocalClient ( )
{
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 , "RespawnPilot" ) ;
IClientArenaSession clientIface = client ;
long nowMs = DateTimeOffset . UtcNow . ToUnixTimeMilliseconds ( ) ;
var deadline = DateTimeOffset . UtcNow . AddSeconds ( 4 ) ;
while ( DateTimeOffset . UtcNow < deadline & & ! client . IsJoined )
{
nowMs + = 16 ;
host . StepOnce ( nowMs ) ;
client . PumpNetwork ( nowMs ) ;
Thread . Sleep ( 2 ) ;
}
Assert . True ( client . IsJoined ) ;
int localId = clientIface . LocalContenderId ;
void PumpStep ( int ticks )
{
var evs = new List < ISimEvent > ( ) ;
for ( int t = 0 ; t < ticks ; t + + )
{
nowMs + = 16 ;
clientIface . SubmitLocalInput ( new PlayerInput (
Throttle : 0f ,
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 . BeginRenderFrame ( ArenaSession . FixedDt , 1.0f ) ;
clientIface . DrainSimEvents ( evs ) ;
}
}
// 1. Land Wave 0
for ( int i = 0 ; i < 480 & & ! clientIface . LocalContender . IsGroundedActive ; i + + )
{
PumpStep ( 1 ) ;
}
Assert . True ( clientIface . LocalContender . IsGroundedActive ) ;
// 2. Swap local player to Paladin on server and replicate to client
var serverLocal = host . Session . State . Contenders [ localId ] ;
host . Session . State . SpawnChassisDrop ( serverLocal . X , serverLocal . Z , Catalog . Paladin ) ;
Assert . True ( host . Session . TrySwapNearbyChassis ( localId ) ) ;
PumpStep ( 12 ) ;
Assert . Equal ( Catalog . Paladin . Id , clientIface . LocalContender . Grid . Spec . Id ) ;
// 3. Eliminate local player -> WaitingForRespawnWave
host . Session . ForceEliminateContender ( localId ) ;
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 ;
PumpStep ( 30 ) ;
Assert . Equal ( ContenderLifecycle . Deploying , clientIface . LocalContender . Lifecycle ) ;
Assert . Equal ( Catalog . Jackal . Id , clientIface . LocalContender . Grid . Spec . Id ) ;
Assert . Equal ( 256f , clientIface . LocalContender . Grid . MaxCoreHp ) ;
Assert . Equal ( 256f , clientIface . LocalContender . Grid . CoreHp ) ;
_output . WriteLine ( $"Wave 1 respawn replicated: chassis={clientIface.LocalContender.Grid.Spec.Id}, core={clientIface.LocalContender.Grid.CoreHp}/{clientIface.LocalContender.Grid.MaxCoreHp}" ) ;
}
[Fact]
public void SionQueryDropSurface_1mOutsideBuildingWall_DoesNotReturnPhantomRoofAbovePod ( )
{
using var session = new ArenaSession ( seed : 42 , ArenaMapKind . Sion , slot0Human : true ) ;
var sion = session . State . SionMap ! ;
var alleySpots = new List < ( SionBuildingAabb Bldg , float X , float Z ) > ( ) ;
for ( int i = 0 ; i < sion . Buildings . Count & & alleySpots . Count < 10 ; i + + )
{
var b = sion . Buildings [ i ] ;
if ( ( b . RoofY - b . GroundY ) < 8f | | MathF . Abs ( b . CenterX ) > 1000f | | MathF . Abs ( b . CenterZ ) > 1000f )
{
continue ;
}
float px = b . CenterX ;
float pz = b . CenterZ - b . HalfZ - 1.0f ;
if ( ! sion . IsInsideAnyBuildingXz ( px , pz , 0f ) )
{
alleySpots . Add ( ( b , px , pz ) ) ;
}
}
Assert . Equal ( 10 , alleySpots . Count ) ;
for ( int i = 0 ; i < alleySpots . Count ; i + + )
{
var ( b , px , pz ) = alleySpots [ i ] ;
float terrainY = session . State . Terrain . SampleHeight ( px , pz ) ;
float midWallY = terrainY + ( b . RoofY - terrainY ) * 0.5f ;
var simSample = session . QueryDropSurface ( px , pz , OrbitalPodPreset . Contender . PodFootRadius , midWallY + 1.0f ) ;
var coreSample = session . State . DefaultDropSurfaceQuery ( px , pz , OrbitalPodPreset . Contender . PodFootRadius , midWallY + 1.0f ) ;
Assert . False ( simSample . IsBuildingRoof , $"Point {i} 1.0m outside {b.Id} returned IsBuildingRoof=true!" ) ;
Assert . True ( simSample . SurfaceY < = midWallY ,
$"Point {i} 1.0m outside {b.Id}: QueryDropSurface returned phantom SurfaceY={simSample.SurfaceY:F2} > midWallY={midWallY:F2} (roof={b.RoofY:F2})" ) ;
Assert . False ( coreSample . IsBuildingRoof ) ;
Assert . True ( coreSample . SurfaceY < = midWallY ,
$"Point {i} 1.0m outside {b.Id}: DefaultDropSurfaceQuery returned phantom SurfaceY={coreSample.SurfaceY:F2} > midWallY={midWallY:F2}" ) ;
// Verify a descending pod 1.0m outside the wall does NOT mid-air instant-pop at 33.67 m/s
var pod = new OrbitalPod
{
PodId = 9000 + i ,
PodKind = OrbitalPodKind . Contender ,
Phase = OrbitalPodPhase . Freefall ,
X = px ,
Y = midWallY + 18f ,
Z = pz ,
VelY = - 33.67f ,
AllowFlatRoofLanding = true
} ;
bool touched = false ;
for ( int t = 0 ; t < 360 ; t + + )
{
if ( OrbitalDropKinematics . StepPod (
pod ,
ArenaSession . FixedDt ,
session . State . Terrain ,
session . QueryDropSurface ,
session . State . FindClearDropPoint ,
out _ ,
out _ ) )
{
touched = true ;
break ;
}
}
Assert . True ( touched , $"Pod {i} outside {b.Id} failed to land" ) ;
float finalTerrain = session . State . Terrain . SampleHeight ( pod . X , pod . Z ) ;
Assert . True ( pod . Y < = finalTerrain + 0.5f ,
$"Pod {i} outside {b.Id} popped in mid-air at Y={pod.Y:F2} vs terrain={finalTerrain:F2}" ) ;
Assert . InRange ( pod . TouchdownSpeed , 0.5f , 2.99f ) ;
}
}
[Fact]
public void SionRoofEdgeAndSteppedRoof_HorizontalSteering_AlwaysLandsUnder3MsWithoutWarp ( )
{
using var session = new ArenaSession ( seed : 42 , ArenaMapKind . Sion , slot0Human : true ) ;
var sion = session . State . SionMap ! ;
// 1. Test horizontal entry onto flat Sion roofs (including sion_0146, sion_0665) at 1..3m above roof edge during RetroBurn
var targetRoofs = new List < SionBuildingAabb > ( ) ;
foreach ( var targetId in new [ ] { "sion_0146" , "sion_0665" } )
{
var found = sion . Buildings . FirstOrDefault ( b = > b . Id = = targetId ) ;
Assert . Equal ( targetId , found . Id ) ;
targetRoofs . Add ( found ) ;
}
foreach ( var b in targetRoofs )
{
// Find a clear approach side 1.0m outside the building AABB and sample actual roof height inside the edge
float probeInX = b . CenterX ;
float probeInZ = b . CenterZ - b . HalfZ + 4.0f ;
var roofSample = session . QueryDropSurface ( probeInX , probeInZ , 1.65f , b . RoofY + 20f ) ;
float edgeRoofY = roofSample . IsBuildingRoof ? roofSample . SurfaceY : b . RoofY ;
float startX = b . CenterX ;
float startZ = b . CenterZ - b . HalfZ - 0.8f ;
if ( sion . IsInsideAnyBuildingXz ( startX , startZ , 0f ) ) continue ;
foreach ( float hAboveEdge in new [ ] { 1.0f , 2.0f , 3.0f } )
{
foreach ( float vyDown in new [ ] { 12f , 22f , 35f } )
{
var pod = new OrbitalPod
{
PodId = 9100 ,
PodKind = OrbitalPodKind . Contender ,
Phase = OrbitalPodPhase . RetroBurn ,
AllowFlatRoofLanding = true ,
X = startX ,
Y = edgeRoofY + hAboveEdge ,
Z = startZ ,
VelX = 0f ,
VelY = - vyDown ,
VelZ = 18f
} ;
bool landed = false ;
float maxStepDeltaY = 0f ;
for ( int t = 0 ; t < 360 ; t + + )
{
float prevY = pod . Y ;
bool touched = OrbitalDropKinematics . StepPod (
pod ,
ArenaSession . FixedDt ,
session . State . Terrain ,
session . QueryDropSurface ,
session . State . FindClearDropPoint ,
out _ ,
out _ ) ;
maxStepDeltaY = MathF . Max ( maxStepDeltaY , MathF . Abs ( pod . Y - prevY ) ) ;
if ( touched )
{
landed = true ;
break ;
}
}
Assert . True ( landed , $"Pod near {b.Id} (h={hAboveEdge}m, vy={vyDown}) failed to land" ) ;
Assert . InRange ( pod . TouchdownSpeed , 0.5f , 2.99f ) ;
Assert . True ( maxStepDeltaY < = 2.0f ,
$"Pod near {b.Id} (h={hAboveEdge}m, vy={vyDown}) warped vertically by {maxStepDeltaY:F2}m" ) ;
}
}
}
// 2. Test AllowFlatRoofLanding = false near stepped Old Town roofs -> never warps > 2m and always < 3.0 m/s
int steppedTested = 0 ;
for ( int i = 0 ; i < sion . Buildings . Count & & steppedTested < 12 ; i + + )
{
var b = sion . Buildings [ ( i * 53 ) % sion . Buildings . Count ] ;
if ( ( b . RoofY - b . GroundY ) < 10f | | MathF . Abs ( b . CenterX ) > 900f | | MathF . Abs ( b . CenterZ ) > 900f )
{
continue ;
}
float startX = b . CenterX ;
float startZ = b . CenterZ - b . HalfZ - 1.2f ;
if ( sion . IsInsideAnyBuildingXz ( startX , startZ , 0f ) ) continue ;
foreach ( float startOffset in new [ ] { 2.0f , 18.0f , 55.0f } )
{
var pod = new OrbitalPod
{
PodId = 9200 + steppedTested ,
PodKind = OrbitalPodKind . Contender ,
Phase = startOffset < 10f ? OrbitalPodPhase . RetroBurn : OrbitalPodPhase . Freefall ,
AllowFlatRoofLanding = false ,
X = startX ,
Y = b . RoofY + startOffset ,
Z = startZ ,
VelX = 0f ,
VelY = - 28f ,
VelZ = 16f ,
LookForwardX = 0f ,
LookForwardZ = 1f ,
SteerForwardCmd = 1f
} ;
bool landed = false ;
float maxStepDeltaY = 0f ;
for ( int t = 0 ; t < 480 ; t + + )
{
float prevY = pod . Y ;
bool touched = OrbitalDropKinematics . StepPod (
pod ,
ArenaSession . FixedDt ,
session . State . Terrain ,
session . QueryDropSurface ,
session . State . FindClearDropPoint ,
out _ ,
out var touchSample ) ;
maxStepDeltaY = MathF . Max ( maxStepDeltaY , MathF . Abs ( pod . Y - prevY ) ) ;
if ( touched )
{
landed = true ;
Assert . False ( touchSample . IsBuildingRoof , $"AllowFlatRoofLanding=false pod landed on roof of {b.Id}" ) ;
Assert . False ( sion . IsInsideAnyBuildingXz ( pod . X , pod . Z , 0f ) , $"Pod landed inside {b.Id}" ) ;
break ;
}
}
Assert . True ( landed , $"AllowFlatRoofLanding=false pod near {b.Id} failed to land" ) ;
Assert . InRange ( pod . TouchdownSpeed , 0.5f , 2.99f ) ;
Assert . True ( maxStepDeltaY < = 2.0f ,
$"AllowFlatRoofLanding=false pod near {b.Id} (offset={startOffset}m) warped by {maxStepDeltaY:F2}m" ) ;
}
steppedTested + + ;
}
Assert . Equal ( 12 , steppedTested ) ;
}
2026-12-05 12:28:35 +01:00
[Fact]
public void Sion410mDrop_SteeringIntoTallWallAndSteepTerrain_NeverBreachesWallOrIgnitesStratosphericRetro ( )
{
using var session = new ArenaSession ( seed : 42 , ArenaMapKind . Sion , slot0Human : true ) ;
var sion = session . State . SionMap ! ;
var tall = sion . Buildings . First ( b = > b . Id = = "sion_1365" ) ;
Assert . True ( ( tall . RoofY - tall . GroundY ) > 60f , $"Expected sion_1365 H>60m, got {tall.RoofY - tall.GroundY:F1}m" ) ;
// 1. 410m AGL human drop outside sion_1365 steering straight toward sion_1365 center, plus low wall-approach & roof-edge sweeps
var approachStarts = new ( float X , float Z , float StartAgl , float Vy0 ) [ ]
{
( tall . CenterX , tall . CenterZ - tall . HalfZ - 18f , 410f , OrbitalPodPreset . Contender . InitialVelY ) ,
( tall . CenterX - tall . HalfX - 18f , tall . CenterZ , 410f , OrbitalPodPreset . Contender . InitialVelY ) ,
( tall . CenterX , tall . CenterZ + tall . HalfZ + 4.5f , 35f , - 35f ) ,
( tall . CenterX + tall . HalfX + 1.2f , tall . CenterZ , tall . RoofY - session . State . Terrain . SampleHeight ( tall . CenterX + tall . HalfX + 1.2f , tall . CenterZ ) + 2.0f , - 22f ) ,
} ;
for ( int c = 0 ; c < approachStarts . Length ; c + + )
{
var ( sx , sz , agl0 , vy0 ) = approachStarts [ c ] ;
float terrain0 = session . State . Terrain . SampleHeight ( sx , sz ) ;
float dx = tall . CenterX - sx ;
float dz = tall . CenterZ - sz ;
float len = MathF . Sqrt ( dx * dx + dz * dz ) ;
float dirX = dx / len ;
float dirZ = dz / len ;
var pod = new OrbitalPod
{
PodId = 9500 + c ,
PodKind = OrbitalPodKind . Contender ,
Phase = OrbitalPodPhase . Freefall ,
AllowFlatRoofLanding = true ,
X = sx ,
Y = terrain0 + agl0 ,
Z = sz ,
VelY = vy0 ,
LookForwardX = dirX ,
LookForwardZ = dirZ ,
SteerForwardCmd = 1f ,
Yaw = MathF . Atan2 ( dirX , dirZ )
} ;
bool landed = false ;
float maxStepDeltaY = 0f ;
for ( int t = 0 ; t < 720 ; t + + )
{
float prevY = pod . Y ;
bool touched = OrbitalDropKinematics . StepPod (
pod ,
ArenaSession . FixedDt ,
session . State . Terrain ,
session . QueryDropSurface ,
session . State . FindClearDropPoint ,
out bool retroStarted ,
out _ ) ;
maxStepDeltaY = MathF . Max ( maxStepDeltaY , MathF . Abs ( pod . Y - prevY ) ) ;
if ( retroStarted )
{
float surfY = session . QueryDropSurface ( pod . X , pod . Z , OrbitalPodPreset . Contender . PodFootRadius , pod . Y + 1.0f ) . SurfaceY ;
float startAgl = pod . Y - MathF . Max ( session . State . Terrain . SampleHeight ( pod . X , pod . Z ) , surfY ) ;
Assert . True ( startAgl < = 160f , $"Case {c}: RetroBurn ignited in stratosphere at {startAgl:F1}m AGL" ) ;
}
if ( sion . TryGetBuildingAt ( pod . X , pod . Z , 0f , out var bInside ) )
{
Assert . True ( pod . Y > = bInside . RoofY - 0.1f ,
$"Case {c} tick {t}: pod breached wall of {bInside.Id} at Y={pod.Y:F2} < RoofY={bInside.RoofY:F2}" ) ;
}
if ( touched )
{
landed = true ;
break ;
}
}
Assert . True ( landed , $"Case {c} pod near sion_1365 failed to land" ) ;
Assert . True ( pod . FlightTime < = 10.5f , $"Case {c} exceeded 10.5s flight time: {pod.FlightTime:F2}s" ) ;
Assert . True ( maxStepDeltaY < = 2.0f , $"Case {c} had vertical teleport step {maxStepDeltaY:F2}m" ) ;
Assert . InRange ( pod . TouchdownSpeed , 0.5f , 2.99f ) ;
}
// 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 + + )
{
var p0 = session . State . Contenders [ 0 ] ;
session . SetHumanInput ( 0 , new PlayerInput (
Throttle : 1f ,
Steer : 0f ,
AimWorldX : tall . CenterX ,
AimWorldZ : tall . CenterZ ,
Fire : false ,
InteractPickup : false ,
Brake : false ) ) ;
session . Step ( ) ;
foreach ( var pod in session . State . OrbitalDrop . ActivePods )
{
if ( sion . TryGetBuildingAt ( pod . X , pod . Z , 0f , out var bHit ) )
{
Assert . True ( pod . Y > = bHit . RoofY - 0.1f ,
$"Wave 0 pod {pod.PodId} breached {bHit.Id} wall at Y={pod.Y:F2} < RoofY={bHit.RoofY:F2}" ) ;
}
if ( pod . Phase = = OrbitalPodPhase . RetroBurn & & ! maxBurnStartAgl . ContainsKey ( pod . PodId ) )
{
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" ) ;
}
if ( session . State . OrbitalDrop . ActivePods . Count = = 0 & & p0 . IsGroundedActive )
{
break ;
}
}
Assert . Empty ( session . State . OrbitalDrop . ActivePods ) ;
Assert . True ( session . State . Contenders [ 0 ] . IsGroundedActive ) ;
}
[Fact]
public void RemoteArenaSession_RivalEntersPvsMidDrop_BecomesVisibleWithActivePod ( )
{
using var host = new ServerMatchHost ( IPAddress . Loopback , 0 , seed : 42 , ArenaMapKind . Sion , maxHumans : 12 , autoRestartSec : 0 ) ;
var ep = new IPEndPoint ( IPAddress . Loopback , host . BoundPort ) ;
using var client = new RemoteArenaSession ( ep , "PvsObserver" ) ;
IClientArenaSession clientIface = client ;
long nowMs = DateTimeOffset . UtcNow . ToUnixTimeMilliseconds ( ) ;
var deadline = DateTimeOffset . UtcNow . AddSeconds ( 4 ) ;
while ( DateTimeOffset . UtcNow < deadline & & ! client . IsJoined )
{
nowMs + = 16 ;
host . StepOnce ( nowMs ) ;
client . PumpNetwork ( nowMs ) ;
Thread . Sleep ( 2 ) ;
}
Assert . True ( client . IsJoined ) ;
int localId = clientIface . LocalContenderId ;
int rivalId = localId = = 0 ? 1 : 0 ;
void PumpStep ( int ticks )
{
var evs = new List < ISimEvent > ( ) ;
for ( int t = 0 ; t < ticks ; t + + )
{
nowMs + = 16 ;
clientIface . SubmitLocalInput ( new PlayerInput (
Throttle : 0f ,
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 . BeginRenderFrame ( ArenaSession . FixedDt , 1.0f ) ;
clientIface . DrainSimEvents ( evs ) ;
}
}
// Land Wave 0 immediately and place observer far away from rival's Wave 1 drop
host . Session . State . OrbitalDrop . DeployAllPodsImmediately ( host . Session . QueryDropSurface ) ;
PumpStep ( 5 ) ;
Assert . True ( clientIface . LocalContender . IsGroundedActive ) ;
// Eliminate rival -> WaitingForRespawnWave, then move observer far away (-900, -900)
host . Session . ForceEliminateContender ( rivalId ) ;
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 ;
for ( int i = 0 ; i < 20 & & host . Session . State . Contenders [ rivalId ] . Lifecycle ! = ContenderLifecycle . Deploying ; i + + )
{
PumpStep ( 1 ) ;
}
Assert . Equal ( ContenderLifecycle . Deploying , host . Session . State . Contenders [ rivalId ] . Lifecycle ) ;
PumpStep ( 5 ) ;
var rivalPod = host . Session . State . OrbitalDrop . ActivePods . FirstOrDefault (
p = > p . PodKind = = OrbitalPodKind . Contender & & p . ContenderId = = rivalId ) ;
Assert . NotNull ( rivalPod ) ;
Assert . False ( host . Session . IsEntityInPeerPvs ( localId , true , rivalId ) , "Rival should start out of observer PVS" ) ;
Assert . False ( clientIface . IsContenderVisible ( rivalId ) , "Rival should not be visible on client before entering PVS" ) ;
// Move observer within 20m of rival's pod mid-drop, then step 15 ticks
host . Session . SetContenderPose ( localId , rivalPod ! . X + 18f , rivalPod . Z , 0f ) ;
PumpStep ( 15 ) ;
Assert . True ( clientIface . IsContenderVisible ( rivalId ) , "Rival should become visible on client after entering PVS mid-drop" ) ;
Assert . Contains ( clientIface . ActivePods ,
p = > p . PodKind = = OrbitalPodKind . Contender & & p . ContenderId = = rivalId ) ;
}
2026-12-05 12:50:13 +01:00
[Fact]
public void Sion0005_LShapedCornerAndWallSteering_ZeroWallBreachesAndZeroTouchdownWarps ( )
{
using var session = new ArenaSession ( seed : 42 , ArenaMapKind . Sion , slot0Human : true ) ;
var sion = session . State . SionMap ! ;
var b = sion . Buildings . First ( x = > x . Id = = "sion_0005" ) ;
// Find an open-sky AABB corner inside sion_0005 (IsInsideAnyBuildingXz == true, no solid roof overhead)
// and a solid-roof interior target inside sion_0005 to steer toward.
float? openCornerX = null , openCornerZ = null ;
float? solidTargetX = null , solidTargetZ = null ;
float solidTargetRoofY = b . RoofY ;
for ( float z = b . CenterZ - b . HalfZ + 1.5f ; z < = b . CenterZ + b . HalfZ - 1.5f ; z + = 2.0f )
{
for ( float x = b . CenterX - b . HalfX + 1.5f ; x < = b . CenterX + b . HalfX - 1.5f ; x + = 2.0f )
{
var sky = session . QueryDropSurface ( x , z , 0f , b . RoofY + 50f ) ;
if ( ! sky . IsBuildingRoof )
{
openCornerX ? ? = x ;
openCornerZ ? ? = z ;
}
else if ( solidTargetX is null & & sky . SurfaceY > session . State . Terrain . SampleHeight ( x , z ) + 2f )
{
solidTargetX = x ;
solidTargetZ = z ;
solidTargetRoofY = sky . SurfaceY ;
}
}
}
Assert . True ( solidTargetX . HasValue , "Expected solid roof interior point on sion_0005" ) ;
float tx = solidTargetX ! . Value ;
float tz = solidTargetZ ! . Value ;
var startPoints = new List < ( string Label , float X , float Z ) > ( ) ;
if ( openCornerX . HasValue )
{
startPoints . Add ( ( "L-corner" , openCornerX . Value , openCornerZ ! . Value ) ) ;
}
foreach ( float offset in new [ ] { 1.2f , 5.0f , 18.0f , 35.0f } )
{
startPoints . Add ( ( $"+{offset:F1}m_W" , b . CenterX - b . HalfX - offset , tx ! = b . CenterX ? tz : b . CenterZ ) ) ;
startPoints . Add ( ( $"+{offset:F1}m_S" , tx , b . CenterZ - b . HalfZ - offset ) ) ;
}
int totalCases = 0 ;
int wallBreachFrames = 0 ;
int touchdownWarps = 0 ;
float maxHorizStep = 0f ;
float maxTouchdownStep = 0f ;
float maxTouchSpeed = 0f ;
foreach ( bool allowFlat in new [ ] { false , true } )
{
foreach ( float startAgl in new [ ] { 410f , 80f } )
{
foreach ( var ( label , sx , sz ) in startPoints )
{
float terrain0 = session . State . Terrain . SampleHeight ( sx , sz ) ;
float dx = tx - sx ;
float dz = tz - sz ;
float len = MathF . Max ( 0.001f , MathF . Sqrt ( dx * dx + dz * dz ) ) ;
float dirX = dx / len ;
float dirZ = dz / len ;
var pod = new OrbitalPod
{
PodId = 9800 + totalCases ,
PodKind = OrbitalPodKind . Contender ,
Phase = OrbitalPodPhase . Freefall ,
AllowFlatRoofLanding = allowFlat ,
X = sx ,
Y = terrain0 + startAgl ,
Z = sz ,
VelY = startAgl > 200f ? OrbitalPodPreset . Contender . InitialVelY : - 28f ,
LookForwardX = dirX ,
LookForwardZ = dirZ ,
SteerForwardCmd = 1f ,
Yaw = MathF . Atan2 ( dirX , dirZ )
} ;
bool landed = false ;
for ( int t = 0 ; t < 720 ; t + + )
{
float prevX = pod . X ;
float prevY = pod . Y ;
float prevZ = pod . Z ;
bool touched = OrbitalDropKinematics . StepPod (
pod ,
ArenaSession . FixedDt ,
session . State . Terrain ,
session . QueryDropSurface ,
session . State . FindClearDropPoint ,
out _ ,
out _ ) ;
float horizStep = MathF . Sqrt ( ( pod . X - prevX ) * ( pod . X - prevX ) + ( pod . Z - prevZ ) * ( pod . Z - prevZ ) ) ;
maxHorizStep = MathF . Max ( maxHorizStep , horizStep ) ;
var skyProbe = session . QueryDropSurface ( pod . X , pod . Z , 0f , solidTargetRoofY + 60f ) ;
if ( skyProbe . IsBuildingRoof & & pod . Y < skyProbe . SurfaceY - 0.1f )
{
wallBreachFrames + + ;
}
if ( touched )
{
float tdStep3D = MathF . Sqrt (
( pod . X - prevX ) * ( pod . X - prevX ) +
( pod . Y - prevY ) * ( pod . Y - prevY ) +
( pod . Z - prevZ ) * ( pod . Z - prevZ ) ) ;
maxTouchdownStep = MathF . Max ( maxTouchdownStep , tdStep3D ) ;
if ( tdStep3D > 1.0f | | horizStep > 1.0f )
{
touchdownWarps + + ;
}
maxTouchSpeed = MathF . Max ( maxTouchSpeed , pod . TouchdownSpeed ) ;
landed = true ;
break ;
}
}
Assert . True ( landed , $"sion_0005 case {label} (agl={startAgl}, flat={allowFlat}) failed to land" ) ;
totalCases + + ;
}
}
}
_output . WriteLine (
$"sion_0005 sweep: cases={totalCases}, hasLCorner={openCornerX.HasValue}, " +
$"wallBreachFrames={wallBreachFrames}, touchdownWarps={touchdownWarps}, " +
$"maxHorizStep={maxHorizStep:F3}m, maxTouchdownStep={maxTouchdownStep:F3}m, maxTouchSpeed={maxTouchSpeed:F2} m/s" ) ;
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" ) ;
}
2026-12-05 11:26:18 +01:00
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)" ) ;
}
}
}
}