Cut 5c-1: Multi-human authoritative sim, SimSnapshot/SimEvent boundary, RustToDust.Net & RustToDust.Server

This commit is contained in:
Meta Vens 2026-12-05 08:35:07 +01:00
commit d8f5c49b8d
34 changed files with 5785 additions and 700 deletions

View file

@ -11,8 +11,8 @@ namespace RustToDust.Tests
[Fact]
public void DrivingAndFiring_MovesBuggyInYmirAndBuildsWeaponHeat()
{
using var session = new ArenaSession(seed: 42);
var player = session.State.Player;
using var session = new ArenaSession(seed: 42, slot0Human: true);
var player = session.State.Contenders[0];
float startX = player.X;
float startZ = player.Z;
float startYaw = player.Yaw;
@ -20,7 +20,7 @@ namespace RustToDust.Tests
for (int tick = 0; tick < 120; tick++)
{
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 1f,
Steer: 0.45f,
AimWorldX: player.X + 40f,
@ -28,6 +28,7 @@ namespace RustToDust.Tests
Fire: true,
InteractPickup: false,
Brake: false));
session.Step();
if (session.State.Tracers.Count > 0)
{
@ -52,30 +53,30 @@ namespace RustToDust.Tests
[Fact]
public void ChassisSwap_ToManticoreAndRaptor_ReplacesBodyWithoutLeakingYmirLanes()
{
using var session = new ArenaSession(seed: 77);
var player = session.State.Player;
using var session = new ArenaSession(seed: 77, slot0Human: true);
var player = session.State.Contenders[0];
int initialFreeSlots = session.World.FreeBodySlots;
// Step once to settle world
session.Step(new PlayerInput(0f, 0f, 0f, 0f, false, false, false));
session.Step();
// Spawn Manticore (Dorsal) right beside player and swap
session.State.SpawnChassisDrop(player.X + 1f, player.Z + 1f, Catalog.Manticore);
Assert.True(session.TrySwapNearbyChassis());
Assert.True(session.TrySwapNearbyChassis(0));
Assert.Equal("manticore", player.Grid.Spec.Id);
Assert.Equal(GridPlane.Dorsal, player.Grid.Spec.Plane);
// Step so Ymir reclaims old tombstone lane
session.Step(new PlayerInput(0f, 0f, 0f, 0f, false, false, false));
session.Step();
Assert.Equal(initialFreeSlots, session.World.FreeBodySlots);
// Now spawn Raptor (Coronal) beside player and swap
session.State.SpawnChassisDrop(player.X + 1f, player.Z + 1f, Catalog.Raptor);
Assert.True(session.TrySwapNearbyChassis());
Assert.True(session.TrySwapNearbyChassis(0));
Assert.Equal("raptor", player.Grid.Spec.Id);
Assert.Equal(GridPlane.Coronal, player.Grid.Spec.Plane);
session.Step(new PlayerInput(0f, 0f, 0f, 0f, false, false, false));
session.Step();
Assert.Equal(initialFreeSlots, session.World.FreeBodySlots);
}
@ -101,20 +102,21 @@ namespace RustToDust.Tests
[Fact]
public void BroadsideFire_UsesDirectionalSupportRadiusNotMaxExtent()
{
using var session = new ArenaSession(seed: 19);
var player = session.State.Player;
using var session = new ArenaSession(seed: 19, slot0Human: 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.
session.State.SpawnChassisDrop(player.X + 0.5f, player.Z + 0.5f, Catalog.Tank);
Assert.True(session.TrySwapNearbyChassis());
Assert.True(session.TrySwapNearbyChassis(0));
Assert.Equal(Catalog.Tank.Id, player.Grid.Spec.Id);
// Step once to settle body, then aim strictly perpendicular (broadside) to player's Yaw.
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, false));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, false));
session.Step();
float broadsideX = MathF.Cos(player.Yaw);
float broadsideZ = -MathF.Sin(player.Yaw);
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 0f,
Steer: 0f,
AimWorldX: player.X + broadsideX * 30f,
@ -122,6 +124,7 @@ namespace RustToDust.Tests
Fire: true,
InteractPickup: false,
Brake: true));
session.Step();
Assert.NotEmpty(session.State.Tracers);
var tracer = session.State.Tracers[^1];
@ -136,15 +139,16 @@ namespace RustToDust.Tests
[Fact]
public void TracerEvent_AssignsMonotonicId_AndPreservesAcrossAdvance()
{
using var session = new ArenaSession(seed: 19);
var player = session.State.Player;
using var session = new ArenaSession(seed: 19, slot0Human: 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;
var ids = new List<int>();
for (int tick = 0; tick < 30 && ids.Count < 2; tick++)
{
session.Step(new PlayerInput(0f, 0f, aimX, aimZ, Fire: true, InteractPickup: false, Brake: true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, aimX, aimZ, Fire: true, InteractPickup: false, Brake: true));
session.Step();
foreach (var t in session.State.Tracers)
{
if (!ids.Contains(t.Id))

View file

@ -0,0 +1,357 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Numerics;
using System.Threading;
using GameCult.Mesh;
using RustToDust.Core;
using RustToDust.Net;
using RustToDust.Ymir;
using Xunit;
using Xunit.Abstractions;
namespace RustToDust.Tests
{
public sealed class CultNetMultiplayerTests
{
private readonly ITestOutputHelper _output;
public CultNetMultiplayerTests(ITestOutputHelper output)
{
_output = output;
}
[Fact]
public void SnapshotCodec_WorstCase12ContendersAndWalkersAndCombatSpecs_StrictlyFitsIn1152Bytes()
{
var state = new MatchState(seed: 42, ArenaMapKind.Desert);
var local = state.Contenders[0];
local.Grid.SwapChassis(Catalog.Bastion); // large 8x8 dorsal mech grid
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 = true,
Fire = true,
Brake = false,
Snap = false,
Pos = new Vector3(i * 10f, 3f, -i * 5f),
Rot = Quaternion.Identity,
Vel = new Vector3(12f, 0f, 4f),
AimYaw = 0.5f,
AimPitchDeg = 10f,
Throttle = 1f,
Steer = -0.5f,
CoreHpRatio = 0.85f,
MaxThermalRatio = 0.45f
});
var ws = new WalkerVisualSnapshot { LegCount = 4 };
for (int l = 0; l < 4; l++)
{
ws.LegAngles[l] = new WalkerLegAngles { HipPitch = 0.4f, HipRoll = 0.1f, KneeFlex = -0.8f, HockFlex = 0.3f, AnklePitch = 0.2f };
ws.FootNormal[l] = Vector3.UnitY;
ws.LoadG[l] = 1.2f;
}
walkers.Add(new NetWalkerEntry { IsContender = true, EntityId = (byte)i, Snapshot = ws });
}
for (int i = 0; i < 10; i++)
{
specs.Add(new NetSpectatorState
{
Id = (byte)i,
Alive = true,
Stance = SpectatorStance.Provoked,
TargetContenderId = 0,
Pos = new Vector3(100f + i * 5f, 4f, -80f),
Rot = Quaternion.Identity,
Vel = new Vector3(2f, 0f, -3f)
});
}
byte[] p1 = SnapshotCodec.EncodeCorePvs(
1, 42, 84, 1.4f, 10, 100, 450f, MatchPhase.Active, null, 2, 0xFFF,
local, new Vector3(0.1f, 0.2f, 0.05f), contenders, walkers, specs);
byte[] w1 = SnapshotCodec.WrapLatest(p1, 1, 1);
byte[] p2 = SnapshotCodec.EncodeSpectatorOrbitHalf(1, 42, 0, Enumerable.Range(0, 28).Select(i => specs[i % specs.Count]).ToList());
byte[] w2 = SnapshotCodec.WrapLatest(p2, 1, 2);
var radarList = Enumerable.Range(0, 32).Select(i => new NetRadarContact { EntityId = (byte)i, Visible = true, LastSeenX = i * 5f, LastSeenZ = -i * 5f }).ToList();
byte[] p3 = SnapshotCodec.EncodeRadarContacts(1, 42, radarList.Take(11).ToList(), radarList);
byte[] w3 = SnapshotCodec.WrapLatest(p3, 1, 3);
byte[] pIn = SnapshotCodec.EncodeClientInput(new ClientInputPacket(1, 99, 1234, new PlayerInput(1f, -0.5f, 10f, 20f, true, true, false, 2f, 0.5f)));
byte[] wIn = SnapshotCodec.WrapLatest(pIn, 1, 4, SnapshotCodec.SchemaInputId);
_output.WriteLine($"Max wire bytes: Packet1={w1.Length}B, Packet2={w2.Length}B, Packet3={w3.Length}B, Input={wIn.Length}B");
Assert.True(w1.Length <= SnapshotCodec.MaxLatestDatagramBytes, $"Packet1 {w1.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
Assert.True(w2.Length <= SnapshotCodec.MaxLatestDatagramBytes, $"Packet2 {w2.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
Assert.True(w3.Length <= SnapshotCodec.MaxLatestDatagramBytes, $"Packet3 {w3.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
Assert.True(wIn.Length <= SnapshotCodec.MaxLatestDatagramBytes, $"Input {wIn.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
var decoded = SnapshotCodec.DecodeCorePvs(SnapshotCodec.Unwrap(w1).Payload.Span);
Assert.Equal(12, decoded.Contenders.Count);
Assert.Equal(42u, decoded.SnapshotSeq);
}
[Fact]
public void RealUdpLoopback_TwoClientsSion_DriveFireDamageCargoAndSimEvents()
{
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 clientA = new RemoteArenaSession(ep, "Alpha");
using var clientB = new RemoteArenaSession(ep, "Bravo");
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
Assert.True(PumpUntil(host, new[] { clientA, clientB }, () => clientA.IsJoined && clientB.IsJoined, ref nowMs, 3000),
"Both UDP clients should join ServerMatchHost");
Assert.NotEqual(clientA.LocalContenderId, clientB.LocalContenderId);
int slotA = clientA.LocalContenderId;
int slotB = clientB.LocalContenderId;
// Place A and B facing each other 28m apart in open Sion plaza
var anchor = host.Session.State.Contenders[slotA];
host.Session.SetContenderPose(slotA, anchor.X, anchor.Z, 0f);
host.Session.SetContenderPose(slotB, anchor.X, anchor.Z + 28f, MathF.PI);
// Give clientB a cargo module & equip it over reliable schema channel -> verify private cargo not leaked to A!
host.Session.State.Contenders[slotB].Grid.TryAddCargo(Catalog.Autocannon);
host.Session.State.Contenders[slotA].Grid.TryAddCargo(Catalog.CopperRad);
int cargoIdxB = host.Session.State.Contenders[slotB].Grid.Cargo.Count - 1;
Assert.True(clientB.RequestEquipCargo(cargoIdxB, "hp.weapon.roof"));
float startAz = clientA.LocalContender.Z;
float bArmorBefore = host.Session.State.Contenders[slotB].Grid.TotalArmorRatio();
// Step 90 ticks: Client A drives forward + fires at Client B
for (int t = 0; t < 90; t++)
{
var posB = host.Session.State.Contenders[slotB];
clientA.SubmitLocalInput(new PlayerInput(0.6f, 0f, posB.X, posB.Z, Fire: true, InteractPickup: false, Brake: false, AimWorldY: posB.Y), true);
clientB.SubmitLocalInput(new PlayerInput(0f, 0f, anchor.X, anchor.Z, Fire: false, InteractPickup: false, Brake: true), true);
nowMs += 16;
host.StepOnce(nowMs);
clientA.BeginRenderFrame(1.0 / 60.0, 1f);
clientB.BeginRenderFrame(1.0 / 60.0, 1f);
Thread.Sleep(1);
}
Assert.True(clientA.LocalContender.Z > startAz + 1.5f, "Client A should have advanced under Option M + server auth");
Assert.True(host.Session.State.Contenders[slotB].Grid.TotalArmorRatio() < bArmorBefore, "Client A's fire should damage Client B on server");
Assert.True(clientB.LocalContender.Grid.TotalArmorRatio() < 1.0f, "Client B should receive HitImpactEvent armor damage");
Assert.Equal(Catalog.Autocannon.Id, clientA.ViewState.Contenders[slotB].Grid.GetMountedOn("hp.weapon.roof")?.Spec.Id);
Assert.Empty(clientA.ViewState.Contenders[slotB].Grid.Cargo); // Private cargo NOT leaked!
Assert.True(clientA.ViewState.Tracers.Count > 0 || host.Session.State.Contenders[slotB].Grid.HitSequence > 0);
}
[Fact]
public void AntiWallhack_PvsPayloadAudit_OccludedRivalAndExemplarOmittedUntilPvsEnter()
{
using var host = new ServerMatchHost(IPAddress.Loopback, 0, seed: 12, ArenaMapKind.Desert, maxHumans: 12, autoRestartSec: 0);
var ep = new IPEndPoint(IPAddress.Loopback, host.BoundPort);
using var clientA = new RemoteArenaSession(ep, "Alpha");
using var clientB = new RemoteArenaSession(ep, "Bravo");
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
Assert.True(PumpUntil(host, new[] { clientA, clientB }, () => clientA.IsJoined && clientB.IsJoined, ref nowMs, 3000));
int slotA = clientA.LocalContenderId;
int slotB = clientB.LocalContenderId;
// Place A and B on opposite sides of tall cover box (> 65m apart so outside proximity PVS envelope!)
var box = host.Session.State.ArenaCoverBoxes.First(b => b.HalfY >= 2.3f);
host.Session.SetContenderPose(slotA, box.X, box.Z - box.HalfZ - 40f, 0f);
host.Session.SetContenderPose(slotB, box.X, box.Z + box.HalfZ + 40f, 0f);
if (host.Session.State.ObserverStates.TryGetValue(slotA, out var obsA)) obsA.ContenderContacts.Remove(slotB);
if (host.Session.State.ObserverStates.TryGetValue(slotB, out var obsB)) obsB.ContenderContacts.Remove(slotA);
// Step 10 ticks so server recomputes PVS & snapshots while B also tries moving behind cover
float preBClientX = clientA.ViewState.Contenders[slotB].X;
float preBClientZ = clientA.ViewState.Contenders[slotB].Z;
float preBServerZ = host.Session.State.Contenders[slotB].Z;
for (int t = 0; t < 10; t++)
{
clientB.SubmitLocalInput(new PlayerInput(1f, 0f, 0f, 0f, false, false, false), true);
nowMs += 16;
host.StepOnce(nowMs);
clientA.BeginRenderFrame(1.0 / 60.0, 1f);
clientB.BeginRenderFrame(1.0 / 60.0, 1f);
Thread.Sleep(1);
}
Assert.False(host.Session.IsEntityInPeerPvs(slotA, true, slotB), "Occluded rival > 65m must NOT be in Peer A PVS");
Assert.False(clientA.IsContenderVisible(slotB), "Client A must mark occluded rival invisible");
Assert.False(clientA.LocalContenderContacts.TryGetValue(slotB, out var memB) && MatchState.IsContactOnRadar(memB));
Assert.True(MathF.Abs(host.Session.State.Contenders[slotB].Z - preBServerZ) > 0.25f, "Server B actually moved behind cover");
Assert.Equal(preBClientX, clientA.ViewState.Contenders[slotB].X);
Assert.Equal(preBClientZ, clientA.ViewState.Contenders[slotB].Z);
// Now move B into open plaza right in front of A AND swap B's chassis while occluded -> verify PvsEnter delivers chassis & pose!
host.Session.State.SpawnChassisDrop(box.X, box.Z + box.HalfZ + 40f, Catalog.Anvil);
Assert.True(host.Session.TrySwapNearbyChassis(slotB));
host.Session.SetContenderPose(slotB, box.X + 18f, box.Z - box.HalfZ - 40f, 0f);
for (int t = 0; t < 12; t++)
{
nowMs += 16;
host.StepOnce(nowMs);
clientA.BeginRenderFrame(1.0 / 60.0, 1f);
clientB.BeginRenderFrame(1.0 / 60.0, 1f);
Thread.Sleep(1);
}
Assert.True(clientA.IsContenderVisible(slotB), "Rival entering open LOS must become PVS visible");
Assert.Equal(Catalog.Anvil.Id, clientA.ViewState.Contenders[slotB].Grid.Spec.Id);
}
[Fact]
public void OptionM_LocalPredictionMovesImmediatelyAtZeroMs_ReconcilesSmoothly_AndHardSnapsOver4m()
{
using var host = new ServerMatchHost(IPAddress.Loopback, 0, seed: 42, ArenaMapKind.Desert, maxHumans: 12, autoRestartSec: 0);
var serverEp = new IPEndPoint(IPAddress.Loopback, host.BoundPort);
using var client = new RemoteArenaSession(serverEp, "Predictor");
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
Assert.True(PumpUntil(host, new[] { client }, () => client.IsJoined, ref nowMs, 3000));
int slot = client.LocalContenderId;
host.Session.SetContenderPose(slot, 0f, 0f, 0f);
for (int t = 0; t < 4; t++)
{
nowMs += 16;
host.StepOnce(nowMs);
client.BeginRenderFrame(1.0 / 60.0, 1f);
Thread.Sleep(1);
}
float initialZ = client.GetInterpolatedContenderPose(slot, 1f).Pos.Z;
// Drop ALL inbound snapshots temporarily while client drives 10 ticks -> Option M must predict movement immediately!
client.DebugInboundLatestDropFilter = _ => true;
for (int t = 0; t < 10; t++)
{
client.SubmitLocalInput(new PlayerInput(1f, 0f, 0f, 60f, false, false, false), true);
}
float predictedZ = client.GetInterpolatedContenderPose(slot, 1f).Pos.Z;
Assert.True(predictedZ > initialZ + 0.10f, $"Option M must move immediately at 0ms before snapshots arrive ({initialZ:F3} -> {predictedZ:F3})");
Assert.True(client.UnackedInputCount >= 10);
// Re-enable snapshots & let server process delayed packets -> verify reconciliation replays unacked & decays error smoothly
client.DebugInboundLatestDropFilter = null;
for (int t = 0; t < 12; t++)
{
nowMs += 16;
host.StepOnce(nowMs);
client.BeginRenderFrame(1.0 / 60.0, 1f);
Thread.Sleep(1);
}
Assert.Equal(0, client.UnackedInputCount);
// Force > 4.0m authoritative displacement (teleport) -> Option M MUST hard-snap residual error to zero!
host.Session.SetContenderPose(slot, 45f, 45f, 0f);
bool sawTeleportSnap = false;
float errAtSnap = float.MaxValue;
for (int t = 0; t < 10; t++)
{
nowMs += 16;
host.StepOnce(nowMs);
client.BeginRenderFrame(1.0 / 60.0, 1f);
var p = client.GetInterpolatedContenderPose(slot, 1f).Pos;
if (Vector2.Distance(new Vector2(p.X, p.Z), new Vector2(45f, 45f)) < 2.0f)
{
sawTeleportSnap = true;
errAtSnap = client.CurrentPredictionError.Length();
break;
}
Thread.Sleep(1);
}
Assert.True(sawTeleportSnap, "Client should receive >4m teleport snapshot");
Assert.True(errAtSnap < 0.001f,
$"Expected >4m teleport to hard-snap prediction error to zero, got {errAtSnap:F4}m");
var snappedPos = client.GetInterpolatedContenderPose(slot, 1f).Pos;
Assert.InRange(Vector2.Distance(new Vector2(snappedPos.X, snappedPos.Z), new Vector2(45f, 45f)), 0f, 1.5f);
}
[Fact]
public void OptionL1_DisconnectAndTimeoutHandBackToAi_AndReconnectTokenReclaimsExactSlot()
{
using var host = new ServerMatchHost(IPAddress.Loopback, 0, seed: 42, ArenaMapKind.Desert, maxHumans: 12, autoRestartSec: 0);
var serverEp = new IPEndPoint(IPAddress.Loopback, host.BoundPort);
var clientA = new RemoteArenaSession(serverEp, "Nomad");
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
Assert.True(PumpUntil(host, new[] { clientA }, () => clientA.IsJoined, ref nowMs, 3000));
int originalSlot = clientA.LocalContenderId;
Guid token = clientA.ReconnectToken;
Assert.NotEqual(Guid.Empty, token);
Assert.True(host.Session.State.Contenders[originalSlot].IsHuman);
// 1. Graceful disconnect -> IsHuman flips to false (AI takes over surviving chassis)
clientA.DisconnectGracefully("BRB");
clientA.Dispose();
for (int t = 0; t < 35; t++)
{
nowMs += 16;
host.StepOnce(nowMs);
Thread.Sleep(1);
}
Assert.False(host.Session.State.Contenders[originalSlot].IsHuman, "Graceful disconnect must hand slot back to AI");
Assert.Equal(0, host.ConnectedHumanCount);
// 2. Reconnect presenting matching ReconnectToken -> reclaims exact same slot!
using var clientAReconnect = new RemoteArenaSession(serverEp, "Nomad", token);
Assert.True(PumpUntil(host, new[] { clientAReconnect }, () => clientAReconnect.IsJoined, ref nowMs, 3000));
Assert.Equal(originalSlot, clientAReconnect.LocalContenderId);
Assert.True(host.Session.State.Contenders[originalSlot].IsHuman);
// 3. Simulate > 5000ms silence (timeout) -> server releases slot back to AI cleanly!
nowMs += ServerMatchHost.IdleTimeoutMs + 250;
host.StepOnce(nowMs);
Assert.False(host.Session.State.Contenders[originalSlot].IsHuman, "5s silence timeout must hand slot back to AI");
Assert.Equal(0, host.ConnectedHumanCount);
}
private static bool PumpUntil(
ServerMatchHost host,
RemoteArenaSession[] clients,
Func<bool> condition,
ref long nowMs,
int timeoutMs)
{
var deadline = DateTimeOffset.UtcNow.AddMilliseconds(timeoutMs);
while (DateTimeOffset.UtcNow < deadline)
{
nowMs += 16;
host.StepOnce(nowMs);
for (int i = 0; i < clients.Length; i++)
{
clients[i].PumpNetwork();
}
if (condition()) return true;
Thread.Sleep(2);
}
return condition();
}
}
}

View file

@ -25,9 +25,9 @@ namespace RustToDust.Tests
[Fact]
public void MesaBetweenSpectatorAndContender_BlocksLosAndPreventsFiringThroughTerrain()
{
using var session = new ArenaSession(seed: 42);
using var session = new ArenaSession(seed: 42, slot0Human: true);
var mesa = FindTallMesa(session.State.Terrain);
var player = session.State.Player;
var player = session.State.Contenders[0];
var spec = session.State.Spectators.Spectators.First(s => s.Tier == SpectatorTier.Patron);
// Place player and spectator on opposite sides of the tall mesa
@ -42,7 +42,8 @@ namespace RustToDust.Tests
for (int tick = 0; tick < 10; tick++)
{
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
Assert.False(session.HasLineOfSight(
spec.X, MatchRules.GetObserverEyeY(spec.Y, spec.Grid.Spec.HalfHeight), spec.Z,
@ -59,9 +60,9 @@ namespace RustToDust.Tests
[Fact]
public void CrestingRidge_RestoresLosAndAllowsSpectatorEngagement()
{
using var session = new ArenaSession(seed: 42);
using var session = new ArenaSession(seed: 42, slot0Human: true);
var mesa = FindTallMesa(session.State.Terrain);
var player = session.State.Player;
var player = session.State.Contenders[0];
var spec = session.State.Spectators.Spectators.First(s => s.Tier == SpectatorTier.Patron);
// Start occluded across the mesa
@ -69,7 +70,8 @@ namespace RustToDust.Tests
session.SetSpectatorPose(spec.Id, mesa.X + mesa.RadiusX + 18f, mesa.Z);
session.State.Spectators.OnSpectatorDamaged(spec, player.Id);
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
Assert.False(spec.HasTargetLos);
// Now player crests onto the high mesa plateau overlooking the spectator
@ -79,7 +81,8 @@ namespace RustToDust.Tests
bool sawTracer = false;
for (int tick = 0; tick < 30; tick++)
{
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
if (session.State.Tracers.Count > 0)
{
sawTracer = true;
@ -95,30 +98,32 @@ namespace RustToDust.Tests
[Fact]
public void LowSignatureExemplar_HiddenBehindRidge_IsInvisibleOnRadar_WhileInLosContactIsVisible()
{
using var session = new ArenaSession(seed: 42);
using var session = new ArenaSession(seed: 42, slot0Human: true);
var mesa = FindTallMesa(session.State.Terrain);
var player = session.State.Player;
var player = session.State.Contenders[0];
var exemplar = session.State.Spectators.Spectators.First(s => s.Tier == SpectatorTier.Exemplar);
var visibleRival = session.State.Contenders[1];
Assert.True(exemplar.RadarSignature <= 0.25f);
// Reset memory so exemplar has never been seen yet, then hide it on the far side of the mesa
session.State.SpectatorContacts[exemplar.Id] = new PlayerContactMemory();
var obs0 = session.State.GetOrCreateObserverState(0);
obs0.SpectatorContacts[exemplar.Id] = new PlayerContactMemory();
session.SetContenderPose(player.Id, mesa.X - mesa.RadiusX - 18f, mesa.Z);
session.SetSpectatorPose(exemplar.Id, mesa.X + mesa.RadiusX + 18f, mesa.Z);
// Place rival contender nearby in clear open LOS on the player's side of the mesa
session.SetContenderPose(visibleRival.Id, mesa.X - mesa.RadiusX - 50f, mesa.Z + 12f);
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
var exMem = session.State.SpectatorContacts[exemplar.Id];
var exMem = obs0.SpectatorContacts[exemplar.Id];
Assert.False(exMem.VisibleToPlayer);
Assert.False(exMem.FaintHorizonPing);
Assert.False(MatchState.IsContactOnRadar(exMem), "Hidden low-signature Exemplar must vanish off player radar");
var rivalMem = session.State.ContenderContacts[visibleRival.Id];
var rivalMem = obs0.ContenderContacts[visibleRival.Id];
Assert.True(rivalMem.VisibleToPlayer, "In-LOS contact must be live-visible to player");
Assert.True(MatchState.IsContactOnRadar(rivalMem));
}
@ -126,9 +131,9 @@ namespace RustToDust.Tests
[Fact]
public void StaticCoverWall_BlocksLineOfSight()
{
using var session = new ArenaSession(seed: 12);
using var session = new ArenaSession(seed: 12, slot0Human: true);
var box = session.State.ArenaCoverBoxes[0];
var player = session.State.Player;
var player = session.State.Contenders[0];
var rival = session.State.Contenders[1];
// Ensure rival is a low-profile ground vehicle shorter than the 4m ruin cover wall
@ -208,7 +213,7 @@ namespace RustToDust.Tests
[Fact]
public void OccludedSpectators_DoNotLeakLiveTargetAfterMemoryExpires_FiveSeconds()
{
using var session = new ArenaSession(seed: 42);
using var session = new ArenaSession(seed: 42, slot0Human: true);
// Shrink safe circle so the tall mesa perimeter is outside SafeRadius
session.State.Time = 360f;
session.State.Spectators.UpdateSafeRadius(session.State.Time);
@ -230,7 +235,7 @@ namespace RustToDust.Tests
}
Assert.True(bestMinRadius > 0f, "Expected at least one tall Mesa in generated terrain.");
var player = session.State.Player;
var player = session.State.Contenders[0];
var tourists = session.State.Spectators.Spectators.Where(s => s.Tier == SpectatorTier.Tourist).ToList();
var provokedSpec = tourists[0];
var clearedSpec = tourists[1];
@ -265,7 +270,8 @@ namespace RustToDust.Tests
session.SetContenderPose(player.Id, specSideX - (negIsFurther ? 12f : -12f), mesa.Z);
session.SetSpectatorPose(provokedSpec.Id, specSideX, mesa.Z);
session.State.Spectators.OnSpectatorDamaged(provokedSpec, player.Id);
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
Assert.True(provokedSpec.HasTargetLos, "Expected initial LOS before player drops behind cover");
float provokedKnownX = provokedSpec.LastKnownTargetX;
@ -277,7 +283,8 @@ namespace RustToDust.Tests
session.SetSpectatorPose(clearedSpec.Id, specSideX, mesa.Z + 4f);
// Verify clearedSpec gets Pass-2 Cleared assignment without LOS
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
Assert.False(provokedSpec.HasTargetLos);
Assert.Equal(SpectatorStance.Cleared, clearedSpec.Stance);
Assert.False(clearedSpec.HasTargetLos);
@ -294,7 +301,8 @@ namespace RustToDust.Tests
session.SetContenderPose(player.Id, occludedX, latZ);
}
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
Assert.False(provokedSpec.HasTargetLos, $"Provoked spectator regained unexpected LOS at tick {tick}");
Assert.False(clearedSpec.HasTargetLos, $"Cleared spectator regained unexpected LOS at tick {tick}");
@ -427,9 +435,9 @@ namespace RustToDust.Tests
[Fact]
public void AiContender_ImmediatelyDropsTrackingAndFiring_OnExactTickLosBreaks()
{
using var session = new ArenaSession(seed: 12);
using var session = new ArenaSession(seed: 12, slot0Human: true);
var box = session.State.ArenaCoverBoxes[0];
var player = session.State.Player;
var player = session.State.Contenders[0];
var ai = session.State.Contenders[1];
// Move other rivals far away so only ai <-> player interaction is isolated
@ -467,7 +475,8 @@ namespace RustToDust.Tests
// Advance `phase` ticks in open LOS; open-LOS acquisition must be immediate on tick 0!
for (int t = 0; t <= phase; t++)
{
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
Assert.Equal(player.Id, ai.AiTargetContenderId);
Assert.True(ai.FireCmd, $"Expected AI to acquire open-LOS target and fire immediately (phase={phase}, t={t})");
}
@ -484,7 +493,8 @@ namespace RustToDust.Tests
// Move laterally behind cover to verify AI never steers/aims toward hidden coords
session.SetContenderPose(player.Id, box.X + (occTick % 2 == 0 ? 1.5f : -1.5f), box.Z + box.HalfZ + 8f, yaw: 0f);
}
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
Assert.Null(ai.AiTargetContenderId);
Assert.False(ai.FireCmd, $"AI leaked FireCmd on occluded tick {occTick} (phase={phase})");
@ -497,9 +507,9 @@ namespace RustToDust.Tests
[Fact]
public void PlayerDetectedByCount_StaysExactZero_UnderAsymmetricCover_NoFlicker()
{
using var session = new ArenaSession(seed: 12);
using var session = new ArenaSession(seed: 12, slot0Human: true);
var box = session.State.ArenaCoverBoxes.First(b => b.HalfY >= 2.8f);
var player = session.State.Player;
var player = session.State.Contenders[0];
var rival = session.State.Contenders[1];
// Move all other rivals and spectators far away (> 500m) so only rival <-> player is tested
@ -536,10 +546,12 @@ namespace RustToDust.Tests
// Re-pin poses each tick so drift never alters cover geometry
session.SetContenderPose(player.Id, box.X, box.Z - box.HalfZ - 4f);
session.SetContenderPose(rival.Id, box.X, box.Z + box.HalfZ + 40f);
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
Assert.True(session.State.ContenderContacts[rival.Id].VisibleToPlayer);
Assert.Equal(0, session.State.PlayerDetectedByCount);
var obs0 = session.State.GetOrCreateObserverState(0);
Assert.True(obs0.ContenderContacts[rival.Id].VisibleToPlayer);
Assert.Equal(0, obs0.DetectedByCount);
}
}

View file

@ -50,7 +50,7 @@ namespace RustToDust.Tests
// 1. Walk, turn, and climb slopes across all 7 mechs + exemplar_frame
foreach (var spec in specs)
{
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert);
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true);
for (int i = 1; i < session.State.Contenders.Count; i++)
{
session.SetContenderPose(i, 500f + i * 16f, 500f);
@ -59,8 +59,8 @@ namespace RustToDust.Tests
// Phase A: start on flat/gentle ground near origin (60 ticks) to verify honest walk slip < 8cm
session.SetContenderPose(0, 0f, 0f, 0f);
session.State.SpawnChassisDrop(0f, 0f, spec);
Assert.True(session.TrySwapNearbyChassis(), $"Failed swap to {spec.Id}");
var player = session.State.Player;
Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id}");
var player = session.State.Contenders[0];
Assert.Equal(spec.Id, player.Grid.Spec.Id);
var ws = session.GetWalkerState(true, player.Id);
@ -70,7 +70,7 @@ namespace RustToDust.Tests
for (int t = 0; t < 60; t++)
{
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 0.45f,
Steer: 0f,
AimWorldX: player.X,
@ -78,6 +78,7 @@ namespace RustToDust.Tests
Fire: false,
InteractPickup: false,
Brake: false));
session.Step();
}
Assert.True(ws.MaxFootSlipM < 0.08f,
$"{spec.Id}: normal walk foot slip {ws.MaxFootSlipM:F4}m >= 0.08m (maxSpd={spec.MaxSpeed:F1})");
@ -123,7 +124,7 @@ namespace RustToDust.Tests
for (int t = 0; t < 180; t++)
{
float steer = MathF.Sin(t * 0.06f) * 0.65f;
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 0.85f,
Steer: steer,
AimWorldX: player.X + 40f * MathF.Sin(player.Yaw),
@ -131,6 +132,7 @@ namespace RustToDust.Tests
Fire: false,
InteractPickup: false,
Brake: false));
session.Step();
Assert.True(float.IsFinite(player.X) && float.IsFinite(player.Y) && float.IsFinite(player.Z),
$"{spec.Id}: non-finite pose at tick {t}");
@ -199,7 +201,7 @@ namespace RustToDust.Tests
// 2. Benchmark 12 simultaneous mechs CPU < 1.5 ms/tick
{
using var benchSession = new ArenaSession(seed: 99, mapKind: ArenaMapKind.Desert);
using var benchSession = new ArenaSession(seed: 99, mapKind: ArenaMapKind.Desert, slot0Human: true);
for (int i = 0; i < benchSession.State.Contenders.Count; i++)
{
var spec = specs[i % 7];
@ -225,7 +227,8 @@ namespace RustToDust.Tests
// Warmup JIT
for (int w = 0; w < 20; w++)
{
benchSession.Step(new PlayerInput(0.8f, 0.2f, 0f, 100f, false, false, false));
benchSession.SetHumanInput(0, new PlayerInput(0.8f, 0.2f, 0f, 100f, false, false, false));
benchSession.Step();
}
var view = benchSession.World.View;
@ -261,16 +264,16 @@ namespace RustToDust.Tests
Span<float> legIntegrities = stackalloc float[4];
foreach (var spec in new[] { Catalog.Breaker, Catalog.Bastion })
{
using var session = new ArenaSession(seed: 17, mapKind: ArenaMapKind.Desert);
using var session = new ArenaSession(seed: 17, mapKind: ArenaMapKind.Desert, slot0Human: true);
for (int i = 1; i < session.State.Contenders.Count; i++)
{
session.SetContenderPose(i, 450f + i * 16f, 450f);
}
session.SetContenderPose(0, 0f, 0f, 0f);
session.State.SpawnChassisDrop(0f, 0f, spec);
Assert.True(session.TrySwapNearbyChassis());
Assert.True(session.TrySwapNearbyChassis(0));
var player = session.State.Player;
var player = session.State.Contenders[0];
var grid = player.Grid;
// Strip all left-leg cells (Breaker Coronal L: y>=H-2, x<W/2; Bastion Dorsal FL: y<H/2, x<W/2)
@ -310,7 +313,7 @@ namespace RustToDust.Tests
for (int t = 0; t < 180; t++)
{
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 0.9f,
Steer: 0f,
AimWorldX: player.X,
@ -318,6 +321,7 @@ namespace RustToDust.Tests
Fire: false,
InteractPickup: false,
Brake: false));
session.Step();
Assert.True(float.IsFinite(player.X) && float.IsFinite(player.Y) && float.IsFinite(player.Z));
peakLeftGrf = MathF.Max(peakLeftGrf, ws.LastGrfY[0]);
@ -346,12 +350,12 @@ namespace RustToDust.Tests
{
foreach (var spec in new[] { Catalog.Breaker, Catalog.Manticore })
{
using var session = new ArenaSession(seed: 7, mapKind: ArenaMapKind.Desert);
using var session = new ArenaSession(seed: 7, mapKind: ArenaMapKind.Desert, slot0Human: true);
session.SetContenderPose(0, 0f, 0f, 0f);
session.State.SpawnChassisDrop(0f, 0f, spec);
Assert.True(session.TrySwapNearbyChassis());
Assert.True(session.TrySwapNearbyChassis(0));
var player = session.State.Player;
var player = session.State.Contenders[0];
var body = session.GetContenderBody(player.Id)!.Value;
var view = session.World.View;
int lane = body.Lane;
@ -395,7 +399,8 @@ namespace RustToDust.Tests
bool sawAirborneTick = false;
for (int t = 0; t < 20; t++)
{
session.Step(new PlayerInput(1f, 0f, 0f, 50f, false, false, false));
session.SetHumanInput(0, new PlayerInput(1f, 0f, 0f, 50f, false, false, false));
session.Step();
if (ws.IsAirborne)
{
sawAirborneTick = true;
@ -427,7 +432,7 @@ namespace RustToDust.Tests
foreach (float yawDeg in yawsDeg)
{
float yawRad = yawDeg * MathF.PI / 180f;
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert);
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true);
for (int i = 1; i < session.State.Contenders.Count; i++)
{
session.SetContenderPose(i, 500f + i * 16f, 500f);
@ -435,14 +440,15 @@ namespace RustToDust.Tests
session.SetContenderPose(0, 0f, 0f, yawRad);
session.State.SpawnChassisDrop(0f, 0f, spec);
Assert.True(session.TrySwapNearbyChassis(), $"Failed swap to {spec.Id}");
Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id}");
session.SetContenderPose(0, 0f, 0f, yawRad);
var player = session.State.Player;
var player = session.State.Contenders[0];
// Lettle -> Wait 5 idle ticks to verify zero rest creep from dead stop
for (int t = 0; t < 5; t++)
{
session.Step(new PlayerInput(0f, 0f, player.X, player.Z + 50f, false, false, false));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 50f, false, false, false));
session.Step();
}
Vector2 cmdFwd = new(MathF.Sin(yawRad), MathF.Cos(yawRad));
@ -452,7 +458,7 @@ namespace RustToDust.Tests
Vector2 wStart = new(player.X, player.Z);
for (int t = 0; t < 120; t++)
{
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 1f,
Steer: 0f,
AimWorldX: player.X + cmdFwd.X * 50f,
@ -460,6 +466,7 @@ namespace RustToDust.Tests
Fire: false,
InteractPickup: false,
Brake: false));
session.Step();
}
float endWSpeed = player.Speed;
Vector2 wDelta = new Vector2(player.X, player.Z) - wStart;
@ -477,7 +484,7 @@ namespace RustToDust.Tests
Vector2 finalWindowStart = Vector2.Zero;
for (int t = 0; t < 180; t++)
{
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 0f,
Steer: 0f,
AimWorldX: player.X + cmdFwd.X * 50f,
@ -485,6 +492,7 @@ namespace RustToDust.Tests
Fire: false,
InteractPickup: false,
Brake: false));
session.Step();
if (timeToStop < 0f && player.Speed < 0.30f)
{
@ -515,7 +523,7 @@ namespace RustToDust.Tests
Vector2 revDir = new(MathF.Sin(player.Yaw), MathF.Cos(player.Yaw));
for (int t = 0; t < 90; t++)
{
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: -1f,
Steer: 0f,
AimWorldX: player.X + revDir.X * 50f,
@ -523,6 +531,7 @@ namespace RustToDust.Tests
Fire: false,
InteractPickup: false,
Brake: false));
session.Step();
}
float revDisp = Vector2.Dot(new Vector2(player.X, player.Z) - sStart, -revDir);
Assert.True(revDisp >= 3.0f,
@ -531,7 +540,8 @@ namespace RustToDust.Tests
// Settle until stopped before turning test
for (int t = 0; t < 180 && (t < 20 || player.Speed > 0.05f); t++)
{
session.Step(new PlayerInput(0f, 0f, player.X, player.Z + 50f, false, false, false));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 50f, false, false, false));
session.Step();
}
// 4. Hold D (Steer = +1, Throttle = 0) for 1.5s (90 ticks)
@ -540,7 +550,7 @@ namespace RustToDust.Tests
float accumYaw = 0f;
for (int t = 0; t < 90; t++)
{
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 0f,
Steer: 1f,
AimWorldX: player.X,
@ -548,6 +558,7 @@ namespace RustToDust.Tests
Fire: false,
InteractPickup: false,
Brake: false));
session.Step();
accumYaw += MatchRules.NormalizeAngle(player.Yaw - prevYaw);
prevYaw = player.Yaw;
}
@ -573,7 +584,7 @@ namespace RustToDust.Tests
{
foreach (var spec in new[] { Catalog.Breaker, Catalog.Bastion })
{
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion);
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true);
for (int i = 1; i < session.State.Contenders.Count; i++)
{
session.SetContenderPose(i, 900f + i * 16f, 900f);
@ -581,8 +592,8 @@ namespace RustToDust.Tests
var sion = session.State.SionMap!;
// Find a clear sloped hillside on Sion (slope ~7-18 deg, free of buildings and low wall meshes along a +/-7m corridor)
float slopeX = session.State.Player.X;
float slopeZ = session.State.Player.Z;
float slopeX = session.State.Contenders[0].X;
float slopeZ = session.State.Contenders[0].Z;
float slopeYaw = 0f;
bool foundSlope = false;
for (float r = 40f; r <= 560f && !foundSlope; r += 20f)
@ -642,9 +653,9 @@ namespace RustToDust.Tests
session.SetContenderPose(0, slopeX, slopeZ, slopeYaw);
session.State.SpawnChassisDrop(slopeX, slopeZ, spec);
Assert.True(session.TrySwapNearbyChassis(), $"Failed swap to {spec.Id} on Sion");
Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id} on Sion");
session.SetContenderPose(0, slopeX, slopeZ, slopeYaw);
var player = session.State.Player;
var player = session.State.Contenders[0];
// 1. Drive forward up/along slope (2.0s)
Vector2 startPos = new(player.X, player.Z);
@ -654,7 +665,7 @@ namespace RustToDust.Tests
float startY = player.Y;
for (int t = 0; t < 120; t++)
{
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 1f,
Steer: 0f,
AimWorldX: player.X + fwdDir.X * 50f,
@ -662,6 +673,7 @@ namespace RustToDust.Tests
Fire: false,
InteractPickup: false,
Brake: false));
session.Step();
}
float gEnd = session.State.Terrain.SampleHeight(player.X, player.Z);
float fwdDisp = Vector2.Dot(new Vector2(player.X, player.Z) - startPos, fwdDir);
@ -685,7 +697,8 @@ namespace RustToDust.Tests
float accumYaw = 0f;
for (int t = 0; t < 90; t++)
{
session.Step(new PlayerInput(0f, 1f, player.X, player.Z + 50f, false, false, false));
session.SetHumanInput(0, new PlayerInput(0f, 1f, player.X, player.Z + 50f, false, false, false));
session.Step();
accumYaw += MatchRules.NormalizeAngle(player.Yaw - prevYaw);
prevYaw = player.Yaw;
}
@ -697,7 +710,8 @@ namespace RustToDust.Tests
Vector2 finalWinStart = Vector2.Zero;
for (int t = 0; t < 180; t++)
{
session.Step(new PlayerInput(0f, 0f, player.X, player.Z + 50f, false, false, false));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 50f, false, false, false));
session.Step();
if (timeToStop < 0f && player.Speed < 0.35f) timeToStop = (t + 1) * ArenaSession.FixedDt;
if (t == 71) speedAt1_2s = player.Speed;
if (t == 119) finalWinStart = new Vector2(player.X, player.Z);
@ -714,7 +728,7 @@ namespace RustToDust.Tests
[Fact]
public void HybridB_Bastion_SteepSionHills_15To22Deg_ClimbsWithoutBeaching()
{
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion);
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true);
for (int i = 1; i < session.State.Contenders.Count; i++)
{
session.SetContenderPose(i, 900f + i * 16f, 900f);
@ -775,8 +789,8 @@ namespace RustToDust.Tests
session.SetContenderPose(0, sites[0].X, sites[0].Z, sites[0].Yaw);
session.State.SpawnChassisDrop(sites[0].X, sites[0].Z, Catalog.Bastion);
Assert.True(session.TrySwapNearbyChassis(), "Failed swap to Bastion on Sion");
var player = session.State.Player;
Assert.True(session.TrySwapNearbyChassis(0), "Failed swap to Bastion on Sion");
var player = session.State.Contenders[0];
foreach (var site in sites)
{
@ -787,7 +801,7 @@ namespace RustToDust.Tests
for (int t = 0; t < 120; t++)
{
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 1f,
Steer: 0f,
AimWorldX: player.X + fwdDir.X * 50f,
@ -795,6 +809,7 @@ namespace RustToDust.Tests
Fire: false,
InteractPickup: false,
Brake: false));
session.Step();
}
float disp2s = Vector2.Dot(new Vector2(player.X, player.Z) - startPos, fwdDir);
@ -845,7 +860,7 @@ namespace RustToDust.Tests
{
foreach (var spec in new[] { Catalog.Bastion, Catalog.Manticore })
{
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert);
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true);
for (int i = 2; i < session.State.Contenders.Count; i++)
{
session.SetContenderPose(i, 900f + i * 16f, 900f);
@ -860,7 +875,8 @@ namespace RustToDust.Tests
session.SetContenderPose(0, 0f, 0f, 0f);
for (int t = 0; t < 45; t++)
{
session.Step(new PlayerInput(0f, 0f, 0f, 80f, false, false, false));
session.SetHumanInput(0, new PlayerInput(0f, 0f, 0f, 80f, false, false, false));
session.Step();
}
var target = session.State.Contenders[1];
@ -925,7 +941,7 @@ namespace RustToDust.Tests
foreach (var spec in new[] { Catalog.Bastion, Catalog.Manticore })
{
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion);
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true);
for (int i = 1; i < session.State.Contenders.Count; i++)
{
session.SetContenderPose(i, 900f + i * 16f, 900f);
@ -933,8 +949,8 @@ namespace RustToDust.Tests
session.SetContenderPose(0, failingSites[0].X, failingSites[0].Z, 0f);
session.State.SpawnChassisDrop(failingSites[0].X, failingSites[0].Z, spec);
Assert.True(session.TrySwapNearbyChassis(), $"Failed swap to {spec.Id}");
var player = session.State.Player;
Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id}");
var player = session.State.Contenders[0];
foreach (var site in failingSites)
{
@ -948,7 +964,7 @@ namespace RustToDust.Tests
for (int t = 0; t < 120; t++)
{
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 1f,
Steer: 0f,
AimWorldX: player.X + fwdDir.X * 50f,
@ -956,6 +972,7 @@ namespace RustToDust.Tests
Fire: false,
InteractPickup: false,
Brake: false));
session.Step();
}
float disp2s = Vector2.Dot(new Vector2(player.X, player.Z) - startPos, fwdDir);
@ -973,7 +990,7 @@ namespace RustToDust.Tests
[Fact]
public void HybridB_Bastion_StationaryFacingHill_DoesNotHyperExtendLegs()
{
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion);
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true);
for (int i = 1; i < session.State.Contenders.Count; i++)
{
session.SetContenderPose(i, 900f + i * 16f, 900f);
@ -986,10 +1003,10 @@ namespace RustToDust.Tests
session.SetContenderPose(0, siteX, siteZ, uphillYaw);
session.State.SpawnChassisDrop(siteX, siteZ, Catalog.Bastion);
Assert.True(session.TrySwapNearbyChassis(), "Failed swap to Bastion at Site#0");
Assert.True(session.TrySwapNearbyChassis(0), "Failed swap to Bastion at Site#0");
session.SetContenderPose(0, siteX, siteZ, uphillYaw);
var player = session.State.Player;
var player = session.State.Contenders[0];
var ws = session.GetWalkerState(true, player.Id)!;
float modelRide = WalkerLocomotion.GetRideHeight(Catalog.Bastion);
float maxRelCom = 0f;
@ -997,7 +1014,7 @@ namespace RustToDust.Tests
for (int t = 0; t < 120; t++)
{
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 0f,
Steer: 0f,
AimWorldX: player.X + MathF.Sin(uphillYaw) * 50f,
@ -1005,6 +1022,7 @@ namespace RustToDust.Tests
Fire: false,
InteractPickup: false,
Brake: false));
session.Step();
float groundY = session.State.Terrain.SampleHeight(player.X, player.Z);
float relCom = player.Y - groundY;

View file

@ -0,0 +1,125 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RustToDust.Core;
using RustToDust.Ymir;
using Xunit;
namespace RustToDust.Tests
{
public sealed class MultiplayerSimulationTests
{
[Fact]
public void TwoHumanSlots_DriveFireSwapAndMatchPhaseStaysActiveUntilSoleSurvivor()
{
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: false);
session.SetHumanSlot(0, true, "Alpha");
session.SetHumanSlot(5, true, "Bravo");
Assert.True(session.State.Contenders[0].IsHuman);
Assert.True(session.State.Contenders[5].IsHuman);
Assert.False(session.State.Contenders[1].IsHuman);
var h0 = session.State.Contenders[0];
var h5 = session.State.Contenders[5];
session.SetContenderPose(0, -30f, 0f, 0f);
session.SetContenderPose(5, 30f, 0f, 0f);
// Place Rival 2 in open LOS for h0, and behind tall mesa or far away from h5
session.SetContenderPose(2, -30f, 55f, MathF.PI);
float h0StartZ = h0.Z;
float h5StartZ = h5.Z;
var events = new List<ISimEvent>();
for (int t = 0; t < 45; t++)
{
session.SetHumanInput(0, new PlayerInput(1f, 0f, -30f, 55f, Fire: true, InteractPickup: false, Brake: false));
session.SetHumanInput(5, new PlayerInput(-1f, 0.3f, 30f, -50f, Fire: false, InteractPickup: false, Brake: false));
session.Step();
session.DrainStepEvents(events);
}
Assert.True(h0.Z > h0StartZ + 3f, $"Human 0 should drive forward independently, deltaZ={h0.Z - h0StartZ:F2}");
Assert.True(h5.Z < h5StartZ - 2f, $"Human 5 should reverse independently, deltaZ={h5.Z - h5StartZ:F2}");
Assert.Contains(events, e => e is ShotFiredEvent sf && !sf.IsSpectatorShooter && sf.ShooterId == 0);
Assert.Contains(events, e => e is HitImpactEvent hi && hi.IsContenderShooter && hi.ShooterId == 0 && hi.ArmorDamage > 0f);
// Kill slot 0 -> match MUST stay Active while multiple contenders remain!
h0.Grid.ApplyHit(0f, 0f, 0.5f, 50000f, 0f);
Assert.False(h0.Alive);
MatchRules.UpdateMatchOutcome(session.State);
Assert.Equal(MatchPhase.Active, session.State.Phase);
// Kill all contenders except slot 5 -> MatchPhase becomes Completed and WinnerContenderId == 5!
for (int i = 0; i < session.State.Contenders.Count; i++)
{
if (i != 5 && session.State.Contenders[i].Alive)
{
session.State.Contenders[i].Grid.ApplyHit(0f, 0f, 0.5f, 50000f, 0f);
}
}
MatchRules.UpdateMatchOutcome(session.State);
Assert.Equal(MatchPhase.Completed, session.State.Phase);
Assert.Equal(5, session.State.WinnerContenderId);
}
[Fact]
public void PerObserverDetectionIsolation_Human0SeesRivalWhileOccludedHuman5DoesNot()
{
using var session = new ArenaSession(seed: 12, mapKind: ArenaMapKind.Desert, slot0Human: false);
session.SetHumanSlot(0, true, "Alpha");
session.SetHumanSlot(5, true, "Bravo");
var box = session.State.ArenaCoverBoxes[0];
var h0 = session.State.Contenders[0];
var h5 = session.State.Contenders[5];
var rival = session.State.Contenders[2];
// Move others far away
for (int i = 0; i < session.State.Contenders.Count; i++)
{
if (i != 0 && i != 5 && i != 2)
{
session.SetContenderPose(i, -650f + i * 12f, -650f);
}
}
// Place h0 and rival on same open side of cover wall; place h5 behind cover wall
session.SetContenderPose(h0.Id, box.X - 10f, box.Z - box.HalfZ - 12f, 0f);
session.SetContenderPose(rival.Id, box.X + 4f, box.Z - box.HalfZ - 12f, 0f);
session.SetContenderPose(h5.Id, box.X + 4f, box.Z + box.HalfZ + 8f, 0f);
session.SetHumanInput(0, new PlayerInput(0f, 0f, rival.X, rival.Z, false, false, true));
session.SetHumanInput(5, new PlayerInput(0f, 0f, h5.X, h5.Z, false, false, true));
session.Step();
var obs0 = session.State.ObserverStates[0];
var obs5 = session.State.ObserverStates[5];
Assert.True(obs0.ContenderContacts[rival.Id].VisibleToPlayer);
Assert.False(obs5.ContenderContacts[rival.Id].VisibleToPlayer);
Assert.False(MatchState.IsContactOnRadar(obs5.ContenderContacts[rival.Id]));
Assert.Equal(0, obs5.DetectedByCount);
}
[Fact]
public void LocalArenaSession_ImplementsUnifiedClientBoundary()
{
using var local = new LocalArenaSession(seed: 42, ArenaMapKind.Desert, "TestSolo");
Assert.Equal(0, local.LocalContenderId);
Assert.Equal("TestSolo", local.LocalContender.Name);
Assert.Equal(ClientMatchOutcome.Active, local.LocalOutcome);
Assert.Equal(NetworkMode.Solo, local.ConnectionStatus.Mode);
float startZ = local.LocalContender.Z;
for (int t = 0; t < 30; t++)
{
local.SubmitLocalInput(new PlayerInput(1f, 0f, local.LocalContender.X, local.LocalContender.Z + 50f, false, false, false), isPhysicsTick: true);
}
var (pos, _, _) = local.GetInterpolatedContenderPose(0, 1f);
Assert.NotEqual(startZ, pos.Z);
}
}
}

View file

@ -92,9 +92,10 @@ namespace RustToDust.Tests
}
// 4. Zero tick-0 spawn ambush
var player = state.Player;
var player = state.Contenders[0];
float initialHp = player.Grid.CoreHp;
session.Step(new PlayerInput(0f, 0f, player.X, player.Z + 10f, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 10f, false, false, true));
session.Step();
for (int i = 1; i < state.Contenders.Count; i++)
{
@ -111,9 +112,9 @@ namespace RustToDust.Tests
{
// Part A: AI Jackal (950 kg) must pick up Hornet (820 kg) via GetChassisUpgradeScore (> 0)
{
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert);
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert, slot0Human: true);
IsolateContenders(session, 0, 1);
var player = session.State.Player;
var player = session.State.Contenders[0];
var ai = session.State.Contenders[1];
// Clear unrelated drops so Hornet is the clean target
@ -131,7 +132,8 @@ namespace RustToDust.Tests
for (int tick = 0; tick < 240 && ai.Grid.Spec.Id == Catalog.Jackal.Id; tick++)
{
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
}
Assert.Equal(Catalog.Hornet.Id, ai.Grid.Spec.Id);
@ -139,9 +141,9 @@ namespace RustToDust.Tests
// Part B: AI Jackal picks up heavy mech drop (Breaker)
{
using var session = new ArenaSession(seed: 77, ArenaMapKind.Desert);
using var session = new ArenaSession(seed: 77, ArenaMapKind.Desert, slot0Human: true);
IsolateContenders(session, 0, 1);
var player = session.State.Player;
var player = session.State.Contenders[0];
var ai = session.State.Contenders[1];
foreach (var d in session.State.GroundDrops)
@ -156,7 +158,8 @@ namespace RustToDust.Tests
session.State.SpawnChassisDrop(0f, 48f, Catalog.Breaker);
for (int tick = 0; tick < 240 && ai.Grid.Spec.Id == Catalog.Jackal.Id; tick++)
{
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
}
Assert.Equal(Catalog.Breaker.Id, ai.Grid.Spec.Id);
@ -167,10 +170,10 @@ namespace RustToDust.Tests
public void NaturalizedBotAim_OffAxisSlewAndJinkOvershoot_ZeroOccludedLeak()
{
// 1. 90-degree off-axis slew delay
using (var session = new ArenaSession(seed: 42, ArenaMapKind.Desert))
using (var session = new ArenaSession(seed: 42, ArenaMapKind.Desert, slot0Human: true))
{
IsolateContenders(session, 0, 1);
var player = session.State.Player;
var player = session.State.Contenders[0];
var ai = session.State.Contenders[1];
// Place AI facing +Z (yaw = 0) and player 60m due +X (90 degrees off-axis) in open LOS
@ -178,7 +181,8 @@ namespace RustToDust.Tests
session.SetContenderPose(player.Id, 60f, 0f, yaw: 0f);
ai.AiScavengeCooldown = 999f;
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
Assert.Equal(player.Id, ai.AiTargetContenderId);
Assert.False(ai.FireCmd, "90-degree off-axis AI must not snap-fire on tick 0 before slewing into cone");
@ -186,7 +190,8 @@ namespace RustToDust.Tests
for (int t = 0; t < 75; t++)
{
session.SetContenderPose(player.Id, 60f, 0f, yaw: 0f);
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
if (ai.FireCmd)
{
eventuallyFired = true;
@ -249,11 +254,11 @@ namespace RustToDust.Tests
}
// 3. Zero occluded fire / target leak when LOS breaks behind cover
using (var session = new ArenaSession(seed: 12, ArenaMapKind.Desert))
using (var session = new ArenaSession(seed: 12, ArenaMapKind.Desert, slot0Human: true))
{
IsolateContenders(session, 0, 1);
var box = session.State.ArenaCoverBoxes[0];
var player = session.State.Player;
var player = session.State.Contenders[0];
var ai = session.State.Contenders[1];
float aiX = box.X;
@ -262,7 +267,8 @@ namespace RustToDust.Tests
float pz = box.Z - box.HalfZ - 14f;
session.SetContenderPose(ai.Id, aiX, aiZ, MathF.Atan2(px - aiX, pz - aiZ));
session.SetContenderPose(player.Id, px, pz, 0f);
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
Assert.Equal(player.Id, ai.AiTargetContenderId);
Assert.True(ai.AimTracker.HasTarget);
@ -272,7 +278,8 @@ namespace RustToDust.Tests
for (int t = 0; t < 10; t++)
{
session.SetContenderPose(player.Id, box.X + (t % 2 == 0 ? 2f : -2f), box.Z + box.HalfZ + 8f, 0f);
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
Assert.Null(ai.AiTargetContenderId);
Assert.False(ai.FireCmd);
@ -286,14 +293,14 @@ namespace RustToDust.Tests
[Fact]
public void RenderInterpolation_CameraAnchorAndContenderPose_ZeroHorizPhaseMismatchAcrossAlpha()
{
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert);
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert, slot0Human: true);
IsolateContenders(session, 0);
var player = session.State.Player;
var player = session.State.Contenders[0];
// Accelerate player forward for 30 ticks so Prev != Curr with genuine horizontal displacement & rotation
for (int t = 0; t < 30; t++)
{
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 1f,
Steer: 0.35f,
AimWorldX: player.X + MathF.Sin(player.Yaw) * 40f,
@ -301,6 +308,7 @@ namespace RustToDust.Tests
Fire: false,
InteractPickup: false,
Brake: false));
session.Step();
}
float stepHoriz = MathF.Sqrt(
@ -337,15 +345,15 @@ namespace RustToDust.Tests
[Fact]
public void PointBlankConvergence_LargeChassis_NeverFiresBackward()
{
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert);
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert, slot0Human: true);
IsolateContenders(session, 0, 1);
var player = session.State.Player;
var player = session.State.Contenders[0];
var target = session.State.Contenders[1];
// Swap player to Bastion (largest heavy chassis) and target to Raptor (tall mech, small 0.8m footprint)
session.SetContenderPose(player.Id, 0f, 0f, yaw: 0f);
session.State.SpawnChassisDrop(0f, 0f, Catalog.Bastion);
Assert.True(session.TrySwapNearbyChassis());
Assert.True(session.TrySwapNearbyChassis(0));
Assert.Equal(Catalog.Bastion.Id, player.Grid.Spec.Id);
session.SetContenderPose(target.Id, 0f, 4.5f, yaw: MathF.PI);
@ -356,14 +364,15 @@ namespace RustToDust.Tests
// Step 1 tick to seat bodies, re-pin poses, then fire point-blank 4.5m in front (+Z)
float aimY = player.Y + player.Grid.Spec.HalfHeight * 0.25f;
session.Step(new PlayerInput(0f, 0f, target.X, target.Z, false, false, true, AimWorldY: aimY));
session.SetHumanInput(0, new PlayerInput(0f, 0f, target.X, target.Z, false, false, true, AimWorldY: aimY));
session.Step();
session.SetContenderPose(player.Id, 0f, 0f, yaw: 0f);
session.SetContenderPose(target.Id, 0f, 4.5f, yaw: MathF.PI);
session.State.Tracers.Clear();
aimY = player.Y + player.Grid.Spec.HalfHeight * 0.25f;
float targetArmorBefore = target.Grid.TotalArmorRatio();
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 0f,
Steer: 0f,
AimWorldX: target.X,
@ -372,6 +381,7 @@ namespace RustToDust.Tests
InteractPickup: false,
Brake: true,
AimWorldY: aimY));
session.Step();
float bastionMuzzleY = player.Y + player.Grid.Spec.HalfHeight * 0.25f;
var playerTracers1 = session.State.Tracers
@ -396,7 +406,7 @@ namespace RustToDust.Tests
{
m.Cooldown = 0f;
}
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 0f,
Steer: 0f,
AimWorldX: target.X,
@ -405,6 +415,7 @@ namespace RustToDust.Tests
InteractPickup: false,
Brake: true,
AimWorldY: aimY));
session.Step();
bastionMuzzleY = player.Y + player.Grid.Spec.HalfHeight * 0.25f;
var playerTracersFront = session.State.Tracers
@ -429,7 +440,7 @@ namespace RustToDust.Tests
{
m.Cooldown = 0f;
}
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 0f,
Steer: 0f,
AimWorldX: target.X,
@ -438,6 +449,7 @@ namespace RustToDust.Tests
InteractPickup: false,
Brake: true,
AimWorldY: aimY));
session.Step();
bastionMuzzleY = player.Y + player.Grid.Spec.HalfHeight * 0.25f;
var playerTracers2 = session.State.Tracers
@ -490,9 +502,9 @@ namespace RustToDust.Tests
[Fact]
public void AiScavenge_PrefersBetterUpgradeInPickupRange_OverCloserInferiorWreck()
{
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert);
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert, slot0Human: true);
IsolateContenders(session, 0, 1);
var player = session.State.Player;
var player = session.State.Contenders[0];
var ai = session.State.Contenders[1];
foreach (var d in session.State.GroundDrops)
@ -508,7 +520,8 @@ namespace RustToDust.Tests
session.State.SpawnChassisDrop(0f, 1.5f, Catalog.Jackal);
session.State.SpawnChassisDrop(0f, 5.5f, Catalog.Hornet);
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
Assert.Equal(Catalog.Hornet.Id, ai.Grid.Spec.Id);
}

View file

@ -16,6 +16,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\RustToDust.Core\RustToDust.Core.csproj" />
<ProjectReference Include="..\..\src\RustToDust.Ymir\RustToDust.Ymir.csproj" />
<ProjectReference Include="..\..\src\RustToDust.Net\RustToDust.Net.csproj" />
<ProjectReference Include="$(YmirRoot)/src/Ymir.Box3D/Ymir.Box3D.csproj" AdditionalProperties="YmirNativeConfiguration=$(YmirNativeConfiguration)" />
</ItemGroup>

View file

@ -121,9 +121,9 @@ namespace RustToDust.Tests
[Fact]
public void Sion_Contenders_ZeroOccludedRadarLeaks_UnderAndOver350m_EveryTick()
{
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion);
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion, slot0Human: true);
var sion = session.State.SionMap!;
var player = session.State.Player;
var player = session.State.Contenders[0];
var nearRival = session.State.Contenders[1];
var farRival = session.State.Contenders[2];
@ -145,7 +145,8 @@ namespace RustToDust.Tests
var (tempFarX, tempFarZ) = FindClearBuildingAdjacentSpot(sion, -1300f, 1300f);
SwapToChassis(session, farRival, Catalog.Jackal, tempFarX, tempFarZ);
session.State.ContenderContacts[nearRival.Id] = new PlayerContactMemory();
var obs0 = session.State.GetOrCreateObserverState(0);
obs0.ContenderContacts[nearRival.Id] = new PlayerContactMemory();
for (int tick = 0; tick < 8; tick++)
{
session.SetContenderPose(player.Id, bldg.CenterX, z1);
@ -154,9 +155,10 @@ namespace RustToDust.Tests
player.X, MatchRules.GetObserverEyeY(player.Y, player.Grid.Spec.HalfHeight), player.Z,
nearRival.X, MatchRules.GetTargetAimY(nearRival.Y, nearRival.Grid.Spec.HalfHeight), nearRival.Z));
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
var mem = session.State.ContenderContacts[nearRival.Id];
var mem = obs0.ContenderContacts[nearRival.Id];
Assert.False(mem.VisibleToPlayer, $"Occluded <350m Sion contender leaked VisibleToPlayer on tick {tick}");
Assert.False(mem.HasEverBeenSeen, $"Occluded <350m Sion contender leaked HasEverBeenSeen on tick {tick}");
Assert.False(MatchState.IsContactOnRadar(mem), $"Occluded <350m Sion contender leaked onto radar on tick {tick}");
@ -170,7 +172,7 @@ namespace RustToDust.Tests
session.SetContenderPose(player.Id, northX, northZ);
session.SetContenderPose(farRival.Id, southX, southZ);
session.State.ContenderContacts[farRival.Id] = new PlayerContactMemory();
obs0.ContenderContacts[farRival.Id] = new PlayerContactMemory();
for (int tick = 0; tick < 8; tick++)
{
@ -180,9 +182,10 @@ namespace RustToDust.Tests
player.X, MatchRules.GetObserverEyeY(player.Y, player.Grid.Spec.HalfHeight), player.Z,
farRival.X, MatchRules.GetTargetAimY(farRival.Y, farRival.Grid.Spec.HalfHeight), farRival.Z));
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
var mem = session.State.ContenderContacts[farRival.Id];
var mem = obs0.ContenderContacts[farRival.Id];
Assert.False(mem.VisibleToPlayer, $"Occluded >350m Sion contender leaked VisibleToPlayer on tick {tick}");
Assert.False(mem.HasEverBeenSeen, $"Occluded >350m Sion contender leaked HasEverBeenSeen on tick {tick}");
Assert.False(MatchState.IsContactOnRadar(mem), $"Occluded >350m Sion contender leaked onto radar on tick {tick}");
@ -193,9 +196,9 @@ namespace RustToDust.Tests
public void Sion_Contenders_Over350m_OpenLosDetectedImmediatelyOnEveryTickPhase()
{
// Verify >350m contenders with open LOS are never delayed by mod-4 staggering across contenders 1..4 on tick 0.
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion);
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion, slot0Human: true);
var sion = session.State.SionMap!;
var player = session.State.Player;
var player = session.State.Contenders[0];
var (px, pz) = FindClearBuildingAdjacentSpot(sion, 113f, -211f);
SwapToChassis(session, player, Catalog.Condor, px, pz);
@ -226,15 +229,18 @@ namespace RustToDust.Tests
c.X, MatchRules.GetTargetAimY(c.Y, c.Grid.Spec.HalfHeight), c.Z),
$"Expected clear elevated LOS to contender {c.Id}");
session.State.ContenderContacts[c.Id] = new PlayerContactMemory();
var obs0 = session.State.GetOrCreateObserverState(0);
obs0.ContenderContacts[c.Id] = new PlayerContactMemory();
tested.Add(c);
}
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
var obs0After = session.State.GetOrCreateObserverState(0);
foreach (var c in tested)
{
var mem = session.State.ContenderContacts[c.Id];
var mem = obs0After.ContenderContacts[c.Id];
Assert.True(mem.VisibleToPlayer, $"Contender {c.Id} >350m with open LOS missed tick-0 detection (staggering leak)");
Assert.True(MatchState.IsContactOnRadar(mem));
}
@ -243,9 +249,9 @@ namespace RustToDust.Tests
[Fact]
public void Sion_Spectators_ZeroOccludedLeaks_ZeroTick0Blindspots_AndNo950mHardCull()
{
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion);
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion, slot0Human: true);
var sion = session.State.SionMap!;
var player = session.State.Player;
var player = session.State.Contenders[0];
// Part 1: Occluded low-signature Exemplar across Valere hill (>450m) never leaks on any tick (0..9)
var exemplar = session.State.Spectators.Spectators.First(s => s.Tier == SpectatorTier.Exemplar);
@ -256,7 +262,8 @@ namespace RustToDust.Tests
SwapToChassis(session, player, Catalog.Jackal, northX, northZ);
session.SetSpectatorPose(exemplar.Id, southX, southZ);
session.State.SpectatorContacts[exemplar.Id] = new PlayerContactMemory();
var obs0 = session.State.GetOrCreateObserverState(0);
obs0.SpectatorContacts[exemplar.Id] = new PlayerContactMemory();
for (int tick = 0; tick < 10; tick++)
{
@ -266,9 +273,10 @@ namespace RustToDust.Tests
player.X, MatchRules.GetObserverEyeY(player.Y, player.Grid.Spec.HalfHeight), player.Z,
exemplar.X, MatchRules.GetTargetAimY(exemplar.Y, exemplar.Grid.Spec.HalfHeight), exemplar.Z));
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
var mem = session.State.SpectatorContacts[exemplar.Id];
var mem = obs0.SpectatorContacts[exemplar.Id];
Assert.False(mem.VisibleToPlayer, $"Occluded Sion Exemplar leaked VisibleToPlayer on tick {tick}");
Assert.False(mem.FaintHorizonPing, $"Occluded Sion Exemplar leaked FaintHorizonPing on tick {tick}");
Assert.False(MatchState.IsContactOnRadar(mem), $"Occluded Sion Exemplar leaked onto radar on tick {tick}");
@ -309,16 +317,17 @@ namespace RustToDust.Tests
s.X, MatchRules.GetTargetAimY(s.Y, s.Grid.Spec.HalfHeight), s.Z),
$"Expected open elevated LOS to spectator {s.Id} at dist={actualDist:F1}m");
session.State.SpectatorContacts[s.Id] = new PlayerContactMemory();
obs0.SpectatorContacts[s.Id] = new PlayerContactMemory();
openSpecs.Add(s);
}
// Step ONE tick: all 8 spectators (covering all %4 and %8 phases and >950m) must be visible immediately.
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
foreach (var s in openSpecs)
{
var mem = session.State.SpectatorContacts[s.Id];
var mem = obs0.SpectatorContacts[s.Id];
float d = MathF.Sqrt((s.X - player.X) * (s.X - player.X) + (s.Z - player.Z) * (s.Z - player.Z));
Assert.True(mem.VisibleToPlayer,
$"Open-LOS Sion spectator {s.Id} at {d:F1}m missed tick-0 detection (blindspot or >950m hard cull)");
@ -329,9 +338,9 @@ namespace RustToDust.Tests
[Fact]
public void Sion_AiContender_NoOddTickTargetDropOrTunnelVision()
{
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion);
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion, slot0Human: true);
var sion = session.State.SionMap!;
var player = session.State.Player;
var player = session.State.Contenders[0];
var ai = session.State.Contenders[1];
var closerRival = session.State.Contenders[2];
@ -357,7 +366,8 @@ namespace RustToDust.Tests
player.X, MatchRules.GetTargetAimY(player.Y, player.Grid.Spec.HalfHeight), player.Z));
// Advance 1 tick so ai locks onto player on tick 1
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
Assert.Equal(player.Id, ai.AiTargetContenderId);
// On the next tick (even/odd opposite phase), bring closerRival into open LOS closer than player
@ -368,7 +378,8 @@ namespace RustToDust.Tests
ai.X, MatchRules.GetObserverEyeY(ai.Y, ai.Grid.Spec.HalfHeight), ai.Z,
closerRival.X, MatchRules.GetTargetAimY(closerRival.Y, closerRival.Grid.Spec.HalfHeight), closerRival.Z));
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
Assert.Equal(closerRival.Id, ai.AiTargetContenderId);
// 2. Immediate target drop and FireCmd=false across consecutive ticks when LOS breaks behind a Sion building
@ -392,7 +403,8 @@ namespace RustToDust.Tests
for (int t = 0; t <= phase; t++)
{
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
Assert.Equal(player.Id, ai.AiTargetContenderId);
Assert.True(ai.FireCmd, $"Expected AI to acquire and fire immediately on Sion (phase={phase}, t={t})");
}
@ -404,7 +416,8 @@ namespace RustToDust.Tests
{
session.SetContenderPose(ai.Id, bldg.CenterX, z1, yaw: 0f);
session.SetContenderPose(player.Id, bldg.CenterX, z2, yaw: 0f);
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
session.Step();
Assert.Null(ai.AiTargetContenderId);
Assert.False(ai.FireCmd, $"AI leaked FireCmd through Sion building on occluded tick {occTick} (phase={phase})");

View file

@ -118,7 +118,7 @@ namespace RustToDust.Tests
[Fact]
public void ArenaSession_SionLoadsHeightfieldAndMeshesSpawnsClearBlocksLosAndStepsCleanly()
{
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion);
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion, slot0Human: true);
var state = session.State;
var sion = state.SionMap!;
@ -186,12 +186,12 @@ namespace RustToDust.Tests
$"Expected HasLineOfSight above Sion building {tb.Id} roof ({tb.RoofY:F1}m) to be clear");
// Step 180 ticks (3 seconds) driving & firing: zero NaNs, zero underground falls, player moves cleanly
var player = state.Player;
var player = state.Contenders[0];
float pStartX = player.X;
float pStartZ = player.Z;
for (int tick = 0; tick < 180; tick++)
{
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 1f,
Steer: MathF.Sin(tick * 0.04f) * 0.25f,
AimWorldX: player.X + MathF.Sin(player.Yaw) * 60f,
@ -199,6 +199,7 @@ namespace RustToDust.Tests
Fire: tick % 10 == 0,
InteractPickup: false,
Brake: false));
session.Step();
for (int cIdx = 0; cIdx < state.Contenders.Count; cIdx++)
{

View file

@ -151,8 +151,8 @@ namespace RustToDust.Tests
[Fact]
public void ArenaSession_BuggyDrivesAcrossDunesWithoutNanAndTracksElevation()
{
using var session = new ArenaSession(seed: 42);
var player = session.State.Player;
using var session = new ArenaSession(seed: 42, slot0Human: true);
var player = session.State.Contenders[0];
int initialBrushes = session.State.Terrain.Brushes.Count;
float minGround = float.PositiveInfinity;
@ -161,7 +161,7 @@ namespace RustToDust.Tests
for (int tick = 0; tick < 360; tick++)
{
float steer = MathF.Sin(tick * 0.025f) * 0.45f;
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 1f,
Steer: steer,
AimWorldX: player.X + 30f,
@ -169,6 +169,7 @@ namespace RustToDust.Tests
Fire: false,
InteractPickup: false,
Brake: false));
session.Step();
Assert.False(float.IsNaN(player.X) || float.IsNaN(player.Y) || float.IsNaN(player.Z),
$"NaN pose at tick {tick}");
@ -272,8 +273,8 @@ namespace RustToDust.Tests
private static void RunSteepTerrainStress(int seed, ChassisSpec chassis, bool testDune)
{
using var session = new ArenaSession(seed);
var player = session.State.Player;
using var session = new ArenaSession(seed, slot0Human: true);
var player = session.State.Contenders[0];
TerrainBrush targetBrush = default;
float startX = 0f;
@ -335,7 +336,7 @@ namespace RustToDust.Tests
if (chassis.Id != player.Grid.Spec.Id)
{
session.State.SpawnChassisDrop(player.X, player.Z, chassis);
Assert.True(session.TrySwapNearbyChassis(), $"Expected swap to {chassis.Id} to succeed");
Assert.True(session.TrySwapNearbyChassis(0), $"Expected swap to {chassis.Id} to succeed");
Assert.Equal(chassis.Id, player.Grid.Spec.Id);
}
@ -348,7 +349,7 @@ namespace RustToDust.Tests
for (int tick = 0; tick < 600; tick++)
{
float steer = MathF.Sin(tick * 0.03f) * 0.15f;
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 1f,
Steer: steer,
AimWorldX: targetBrush.X,
@ -356,6 +357,7 @@ namespace RustToDust.Tests
Fire: false,
InteractPickup: false,
Brake: false));
session.Step();
Assert.False(
float.IsNaN(player.X) || float.IsNaN(player.Y) || float.IsNaN(player.Z),

View file

@ -31,13 +31,13 @@ namespace RustToDust.Tests
{
foreach (var vtolSpec in new[] { Catalog.Hornet, Catalog.Condor })
{
using var session = new ArenaSession(seed: 42);
using var session = new ArenaSession(seed: 42, slot0Human: true);
IsolateContenders(session, 0);
var player = session.State.Player;
var player = session.State.Contenders[0];
session.SetContenderPose(player.Id, 0f, 0f, 0f);
session.State.SpawnChassisDrop(player.X, player.Z, vtolSpec);
Assert.True(session.TrySwapNearbyChassis());
Assert.True(session.TrySwapNearbyChassis(0));
Assert.Equal(vtolSpec.Id, player.Grid.Spec.Id);
Assert.True(player.Grid.Spec.IsVtol);
@ -47,7 +47,8 @@ namespace RustToDust.Tests
// Climb with VerticalThrottle = +1 for 2.5s (150 ticks)
for (int t = 0; t < 150; t++)
{
session.Step(new PlayerInput(0.4f, 0.1f, player.X, player.Z + 30f, false, false, false, VerticalThrottle: 1f));
session.SetHumanInput(0, new PlayerInput(0.4f, 0.1f, player.X, player.Z + 30f, false, false, false, VerticalThrottle: 1f));
session.Step();
}
float ghClimbed = session.State.Terrain.SampleHeight(player.X, player.Z);
@ -60,13 +61,15 @@ namespace RustToDust.Tests
// Hold hover with VerticalThrottle = 0 for 2.0s (120 ticks) -> settles to TargetHoverAltAgl and holds steady
for (int t = 0; t < 60; t++)
{
session.Step(new PlayerInput(0f, 0f, player.X, player.Z + 30f, false, false, false, VerticalThrottle: 0f));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 30f, false, false, false, VerticalThrottle: 0f));
session.Step();
}
float ghSettled = session.State.Terrain.SampleHeight(player.X, player.Z);
float settledAgl = player.Y - vtolSpec.HalfHeight - ghSettled;
for (int t = 0; t < 60; t++)
{
session.Step(new PlayerInput(0f, 0f, player.X, player.Z + 30f, false, false, false, VerticalThrottle: 0f));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 30f, false, false, false, VerticalThrottle: 0f));
session.Step();
}
float ghHeld = session.State.Terrain.SampleHeight(player.X, player.Z);
float heldAgl = player.Y - vtolSpec.HalfHeight - ghHeld;
@ -76,7 +79,8 @@ namespace RustToDust.Tests
// Descend with VerticalThrottle = -1 for 3s (180 ticks) - should settle smoothly near 2.5m clearance
for (int t = 0; t < 180; t++)
{
session.Step(new PlayerInput(0f, 0f, player.X, player.Z + 30f, false, false, false, VerticalThrottle: -1f));
session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 30f, false, false, false, VerticalThrottle: -1f));
session.Step();
}
float ghDesc = session.State.Terrain.SampleHeight(player.X, player.Z);
float descAgl = player.Y - vtolSpec.HalfHeight - ghDesc;
@ -88,8 +92,8 @@ namespace RustToDust.Tests
[Fact]
public void MwllTriangle_ZenithBlindSpot_MainCannonBlocked_WideArcPdAndDistantGroundRigHit()
{
using var session = new ArenaSession(seed: 42);
var player = session.State.Player;
using var session = new ArenaSession(seed: 42, slot0Human: true);
var player = session.State.Contenders[0];
var overheadVtol = session.State.Contenders[1];
var distantGroundRig = session.State.Contenders[2];
IsolateContenders(session, player.Id, overheadVtol.Id);
@ -97,7 +101,7 @@ namespace RustToDust.Tests
// Swap player to Anvil (heavy tracked tank, weapons capped at +30 deg pitch)
session.SetContenderPose(player.Id, 0f, 0f, 0f);
session.State.SpawnChassisDrop(0f, 0f, Catalog.Anvil);
Assert.True(session.TrySwapNearbyChassis());
Assert.True(session.TrySwapNearbyChassis(0));
Assert.Equal("anvil", player.Grid.Spec.Id);
// Swap contender 1 to Hornet and position it high overhead (~14m horizontal, ~38m above player => ~+69 deg pitch!)
@ -109,7 +113,8 @@ namespace RustToDust.Tests
overheadVtol.TargetHoverAltAgl = 38f;
session.SetContenderPose(overheadVtol.Id, 0f, 14f, 0f);
// Step once to seat bodies cleanly
session.Step(new PlayerInput(0f, 0f, overheadVtol.X, overheadVtol.Z, false, false, true, AimWorldY: overheadVtol.Y));
session.SetHumanInput(0, new PlayerInput(0f, 0f, overheadVtol.X, overheadVtol.Z, false, false, true, AimWorldY: overheadVtol.Y));
session.Step();
float vtolArmorBefore = overheadVtol.Grid.TotalArmorRatio();
@ -118,13 +123,14 @@ namespace RustToDust.Tests
{
overheadVtol.TargetHoverAltAgl = 38f;
session.SetContenderPose(overheadVtol.Id, 0f, 14f, 0f);
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
0f, 0f,
overheadVtol.X, overheadVtol.Z,
Fire: true,
InteractPickup: false,
Brake: true,
AimWorldY: overheadVtol.Y));
session.Step();
}
Assert.True(player.AllWeaponsOutOfArc,
$"Expected Anvil main cannons to report AllWeaponsOutOfArc (in={player.InArcWeaponCount}, out={player.OutOfArcWeaponCount}, pY={player.Y:F1}, vY={overheadVtol.Y:F1}, vSpec={overheadVtol.Grid.Spec.Id}, vAlt={overheadVtol.TargetHoverAltAgl:F1}, vAlive={overheadVtol.Alive}, vPos=({overheadVtol.X:F1},{overheadVtol.Z:F1}))");
@ -138,13 +144,14 @@ namespace RustToDust.Tests
{
overheadVtol.TargetHoverAltAgl = 38f;
session.SetContenderPose(overheadVtol.Id, 0f, 14f, 0f);
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
0f, 0f,
overheadVtol.X, overheadVtol.Z,
Fire: true,
InteractPickup: false,
Brake: true,
AimWorldY: overheadVtol.Y));
session.Step();
pdTracers += session.State.Tracers.Count;
}
Assert.False(player.AllWeaponsOutOfArc, "Expected Wide-Arc PD module to clear overhead out-of-arc block");
@ -164,7 +171,8 @@ namespace RustToDust.Tests
float vtolArmorBeforeDistant = overheadVtol.Grid.TotalArmorRatio();
for (int t = 0; t < 90; t++)
{
session.Step(new PlayerInput(0f, 0f, 0f, -20f, false, false, true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, 0f, -20f, false, false, true));
session.Step();
}
Assert.True(overheadVtol.Grid.TotalArmorRatio() < vtolArmorBeforeDistant,
"Expected distant ground rig 140m away (~15 deg pitch) to hit the hovering Hornet inside its 30 deg cannon arc");
@ -173,8 +181,8 @@ namespace RustToDust.Tests
[Fact]
public void GroundRigWithWideArcPd_AutoTracksNearbyAirborneVtolWithoutManualFire()
{
using var session = new ArenaSession(seed: 42);
var player = session.State.Player;
using var session = new ArenaSession(seed: 42, slot0Human: true);
var player = session.State.Contenders[0];
var overheadVtol = session.State.Contenders[1];
IsolateContenders(session, player.Id, overheadVtol.Id);
@ -196,7 +204,7 @@ namespace RustToDust.Tests
{
overheadVtol.TargetHoverAltAgl = 28f;
session.SetContenderPose(overheadVtol.Id, 20f, 25f, 0f);
session.Step(new PlayerInput(
session.SetHumanInput(0, new PlayerInput(
Throttle: 0f,
Steer: 0f,
AimWorldX: 0f,
@ -204,6 +212,7 @@ namespace RustToDust.Tests
Fire: false,
InteractPickup: false,
Brake: true));
session.Step();
if (session.State.Tracers.Count > 0)
{
sawAutoTracer = true;
@ -219,17 +228,18 @@ namespace RustToDust.Tests
public void QuickBolt_MountsScavengedModuleIntoEmptyMatchingHardpointBeforeCargo()
{
var state = new MatchState(seed: 42);
var player = state.Player;
var player = state.Contenders[0];
player.IsHuman = true;
// Swap to Anvil (starter Jackal transfers 1 weapon into hp.weapon.sponson_l, leaving hp.weapon.siege_l, hp.weapon.siege_r, hp.weapon.sponson_r empty!)
state.SpawnChassisDrop(player.X, player.Z, Catalog.Anvil);
Assert.True(state.TrySwapNearbyChassis());
Assert.True(state.TrySwapNearbyChassis(0));
Assert.Null(player.Grid.GetMountedOn("hp.weapon.siege_l"));
int cargoBefore = player.Grid.Cargo.Count;
// Drop 1x1 PointDefenseFlak right at player and press [E]
state.SpawnModuleDrop(player.X + 0.5f, player.Z, Catalog.PointDefenseFlak);
MatchRules.ApplyPlayerInput(state, new PlayerInput(
MatchRules.ApplyHumanInput(state, 0, new PlayerInput(
0f, 0f, player.X, player.Z + 10f,
Fire: false,
InteractPickup: true,
@ -246,7 +256,7 @@ namespace RustToDust.Tests
Assert.True(player.Grid.TryMount(Catalog.Autocannon, "hp.weapon.siege_r"));
Assert.True(player.Grid.TryMount(Catalog.Mg762, "hp.weapon.sponson_r"));
state.SpawnModuleDrop(player.X + 0.5f, player.Z, Catalog.Flak);
MatchRules.ApplyPlayerInput(state, new PlayerInput(
MatchRules.ApplyHumanInput(state, 0, new PlayerInput(
0f, 0f, player.X, player.Z + 10f,
Fire: false,
InteractPickup: true,
@ -259,8 +269,8 @@ namespace RustToDust.Tests
[Fact]
public void Vtol_ReverseIntoTallMesaAndCliffDrop_ZeroUndergroundTicks()
{
using var session = new ArenaSession(seed: 42);
var player = session.State.Player;
using var session = new ArenaSession(seed: 42, slot0Human: true);
var player = session.State.Contenders[0];
IsolateContenders(session, player.Id);
// Pick the tallest Mesa in generated terrain
@ -278,7 +288,7 @@ namespace RustToDust.Tests
Assert.True(bestHeight >= 22f, "Expected a tall Mesa in seed 42");
session.State.SpawnChassisDrop(player.X, player.Z, Catalog.Hornet);
Assert.True(session.TrySwapNearbyChassis());
Assert.True(session.TrySwapNearbyChassis(0));
Assert.Equal("hornet", player.Grid.Spec.Id);
// 1. Reverse (-Z/+X away from yaw) straight into the tall Mesa cliff face
@ -290,7 +300,8 @@ namespace RustToDust.Tests
int undergroundReverseTicks = 0;
for (int t = 0; t < 240; t++)
{
session.Step(new PlayerInput(-1f, 0f, player.X - 30f, player.Z, false, false, false));
session.SetHumanInput(0, new PlayerInput(-1f, 0f, player.X - 30f, player.Z, false, false, false));
session.Step();
float gh = session.State.Terrain.SampleHeight(player.X, player.Z);
float agl = (player.Y - player.Grid.Spec.HalfHeight) - gh;
if (agl < minReverseAgl) minReverseAgl = agl;
@ -312,7 +323,8 @@ namespace RustToDust.Tests
int undergroundDropTicks = 0;
for (int t = 0; t < 240; t++)
{
session.Step(new PlayerInput(1f, 0f, player.X + 30f, player.Z, false, false, false));
session.SetHumanInput(0, new PlayerInput(1f, 0f, player.X + 30f, player.Z, false, false, false));
session.Step();
float gh = session.State.Terrain.SampleHeight(player.X, player.Z);
float agl = (player.Y - player.Grid.Spec.HalfHeight) - gh;
if (agl < minDropAgl) minDropAgl = agl;
@ -326,20 +338,21 @@ namespace RustToDust.Tests
[Fact]
public void Vtol_OverheatedEngineToZeroPerf_LosesClimbAuthorityAndSinksTowardMinClearance()
{
using var session = new ArenaSession(seed: 42);
var player = session.State.Player;
using var session = new ArenaSession(seed: 42, slot0Human: true);
var player = session.State.Contenders[0];
IsolateContenders(session, player.Id);
session.SetContenderPose(player.Id, 0f, 0f, 0f);
session.State.SpawnChassisDrop(0f, 0f, Catalog.Hornet);
Assert.True(session.TrySwapNearbyChassis());
Assert.True(session.TrySwapNearbyChassis(0));
// Establish steady 20m hover
player.TargetHoverAltAgl = 20f;
session.SetContenderPose(player.Id, 0f, 0f, 0f);
for (int t = 0; t < 45; t++)
{
session.Step(new PlayerInput(0f, 0f, 0f, 30f, false, false, false));
session.SetHumanInput(0, new PlayerInput(0f, 0f, 0f, 30f, false, false, false));
session.Step();
}
float hoverAglBefore = (player.Y - player.Grid.Spec.HalfHeight) - session.State.Terrain.SampleHeight(player.X, player.Z);
Assert.InRange(hoverAglBefore, 17.5f, 22.5f);
@ -348,7 +361,8 @@ namespace RustToDust.Tests
for (int t = 0; t < 150; t++)
{
player.Grid.InjectHardpointHeat("hp.engine.core", 15000f);
session.Step(new PlayerInput(0f, 0f, 0f, 30f, false, false, false, VerticalThrottle: 1f));
session.SetHumanInput(0, new PlayerInput(0f, 0f, 0f, 30f, false, false, false, VerticalThrottle: 1f));
session.Step();
}
float hoverAglAfter = (player.Y - player.Grid.Spec.HalfHeight) - session.State.Terrain.SampleHeight(player.X, player.Z);
@ -362,9 +376,9 @@ namespace RustToDust.Tests
public void StrippedZeroArmorHardpoint_DisablesManualFireAndAutoPointDefense()
{
// 1. Manual FireMountedWeapons disabled when hardpoint armor == 0
using (var session = new ArenaSession(seed: 42))
using (var session = new ArenaSession(seed: 42, slot0Human: true))
{
var player = session.State.Player;
var player = session.State.Contenders[0];
var target = session.State.Contenders[1];
IsolateContenders(session, player.Id, target.Id);
@ -390,7 +404,8 @@ namespace RustToDust.Tests
int tracersFired = 0;
for (int t = 0; t < 20; t++)
{
session.Step(new PlayerInput(0f, 0f, target.X, target.Z, Fire: true, InteractPickup: false, Brake: true, AimWorldY: target.Y));
session.SetHumanInput(0, new PlayerInput(0f, 0f, target.X, target.Z, Fire: true, InteractPickup: false, Brake: true, AimWorldY: target.Y));
session.Step();
tracersFired += session.State.Tracers.Count(tr =>
MathF.Abs(tr.StartX - player.X) < 10f && MathF.Abs(tr.StartZ - player.Z) < 10f);
}
@ -402,9 +417,9 @@ namespace RustToDust.Tests
}
// 2. Auto-PD TryAutoPointDefenseFire disabled when PD hardpoint armor == 0
using (var session = new ArenaSession(seed: 42))
using (var session = new ArenaSession(seed: 42, slot0Human: true))
{
var player = session.State.Player;
var player = session.State.Contenders[0];
var overheadVtol = session.State.Contenders[1];
IsolateContenders(session, player.Id, overheadVtol.Id);
@ -434,7 +449,8 @@ namespace RustToDust.Tests
{
overheadVtol.TargetHoverAltAgl = 28f;
session.SetContenderPose(overheadVtol.Id, 20f, 25f, 0f);
session.Step(new PlayerInput(0f, 0f, 0f, -50f, Fire: false, InteractPickup: false, Brake: true));
session.SetHumanInput(0, new PlayerInput(0f, 0f, 0f, -50f, Fire: false, InteractPickup: false, Brake: true));
session.Step();
pdTracers += session.State.Tracers.Count(tr =>
MathF.Abs(tr.StartX - player.X) < 10f && MathF.Abs(tr.StartZ - player.Z) < 10f);
}
@ -447,13 +463,13 @@ namespace RustToDust.Tests
[Fact]
public void SwapChassis_VtolToGroundToVtol_ResetsTargetHoverAltAgl()
{
using var session = new ArenaSession(seed: 42);
var player = session.State.Player;
using var session = new ArenaSession(seed: 42, slot0Human: true);
var player = session.State.Contenders[0];
IsolateContenders(session, player.Id);
session.SetContenderPose(player.Id, 0f, 0f, 0f);
session.State.SpawnChassisDrop(0f, 0f, Catalog.Hornet);
Assert.True(session.TrySwapNearbyChassis());
Assert.True(session.TrySwapNearbyChassis(0));
Assert.Equal(10f, player.TargetHoverAltAgl);
player.TargetHoverAltAgl = 42f;
@ -461,13 +477,13 @@ namespace RustToDust.Tests
// Swap to ground rig
session.State.SpawnChassisDrop(player.X, player.Z, Catalog.Jackal);
Assert.True(session.TrySwapNearbyChassis());
Assert.True(session.TrySwapNearbyChassis(0));
Assert.Equal(3.0f, player.TargetHoverAltAgl);
Assert.Equal(0f, player.VerticalThrottleCmd);
// Swap back to VTOL -> must spawn cleanly at 10m hover, NOT stale 42m
session.State.SpawnChassisDrop(player.X, player.Z, Catalog.Condor);
Assert.True(session.TrySwapNearbyChassis());
Assert.True(session.TrySwapNearbyChassis(0));
Assert.Equal(10.0f, player.TargetHoverAltAgl);
Assert.Equal(0f, player.VerticalThrottleCmd);
float gh = session.State.Terrain.SampleHeight(player.X, player.Z);
@ -479,7 +495,8 @@ namespace RustToDust.Tests
public void InteractPickup_UsesUnifiedNearestDropPriority_ChassisCloserThanModule()
{
var state = new MatchState(seed: 42);
var player = state.Player;
var player = state.Contenders[0];
player.IsHuman = true;
// Remove pre-scattered drops near player to keep test deterministic
state.GroundDrops.Clear();
@ -490,7 +507,7 @@ namespace RustToDust.Tests
var nearest = state.FindNearestInteractableDrop(0);
Assert.Same(chassisDrop, nearest);
MatchRules.ApplyPlayerInput(state, new PlayerInput(
MatchRules.ApplyHumanInput(state, 0, new PlayerInput(
0f, 0f, player.X, player.Z + 10f,
Fire: false,
InteractPickup: true,