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

@ -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);
}