Cut 10a Soul Pass #1 fixes: allied ordnance immunity, squad ID sync, 12m AI drop split
This commit is contained in:
parent
26f5438ed5
commit
10df4ae522
9 changed files with 536 additions and 33 deletions
|
|
@ -708,5 +708,129 @@ namespace RustToDust.Tests
|
|||
Assert.True(listenHost.ViewState.AreAllies(0, remoteId));
|
||||
Assert.True(remote.ViewState.AreAllies(0, remoteId));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LobbySquadSwap_MidMatchReconnectAndLateJoin_PreservesAll12SquadIdsOutsidePvs()
|
||||
{
|
||||
using var host = new ServerMatchHost(
|
||||
IPAddress.Loopback,
|
||||
0,
|
||||
seed: 42,
|
||||
mapKind: ArenaMapKind.Desert,
|
||||
startInLobby: true,
|
||||
minHumansToStart: 1,
|
||||
squadSize: 3);
|
||||
var ep = new IPEndPoint(IPAddress.Loopback, host.BoundPort);
|
||||
|
||||
using var clientA = new RemoteArenaSession(ep, "LeaderSwap");
|
||||
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
var deadline = DateTime.UtcNow.AddSeconds(3);
|
||||
while (!clientA.IsJoined && DateTime.UtcNow < deadline)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
clientA.PumpNetwork();
|
||||
Thread.Sleep(2);
|
||||
}
|
||||
Assert.True(clientA.IsJoined);
|
||||
int slotA = clientA.LocalContenderId;
|
||||
Assert.Equal(0, slotA);
|
||||
|
||||
// Polish check: out-of-range TargetSquadId >= maxSquads (4 for SquadSize=3) must be rejected, not clamped
|
||||
Assert.False(host.MovePeerToSquad(slotA, 4));
|
||||
Assert.Equal((byte)0, host.Session.State.Contenders[slotA].SquadId);
|
||||
|
||||
// Swap Slot 0 (0 -> 2) and Slot 6 (2 -> 0) in Lobby (SquadSize = 3)
|
||||
Assert.True(clientA.RequestLobbySquad(2));
|
||||
for (int t = 0; t < 20; t++)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
clientA.PumpNetwork();
|
||||
Thread.Sleep(2);
|
||||
}
|
||||
Assert.Equal((byte)2, host.Session.State.Contenders[0].SquadId);
|
||||
Assert.Equal((byte)0, host.Session.State.Contenders[6].SquadId);
|
||||
|
||||
// Launch to MatchPhase.Active
|
||||
Assert.True(host.SetLobbyReady(slotA, true));
|
||||
for (int tick = 0; tick < 340; tick++)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
clientA.PumpNetwork();
|
||||
if (host.Session.State.Phase == MatchPhase.Active && clientA.ViewState.Phase == MatchPhase.Active)
|
||||
{
|
||||
break;
|
||||
}
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
Assert.Equal(MatchPhase.Active, host.Session.State.Phase);
|
||||
|
||||
// Position contenders far apart across Desert so non-allies (including Slot 6) are outside PVS
|
||||
host.Session.SetContenderPose(0, -320f, -320f, 0f);
|
||||
for (int i = 1; i < MatchState.ContenderCount; i++)
|
||||
{
|
||||
if (host.Session.State.AreAllies(0, i))
|
||||
{
|
||||
host.Session.SetContenderPose(i, -310f + i * 3f, -320f, 0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
host.Session.SetContenderPose(i, 320f, 320f - i * 8f, MathF.PI);
|
||||
}
|
||||
}
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
Assert.False(host.Session.IsEntityInPeerPvs(0, true, 6));
|
||||
|
||||
// 1. Reconnect clientA mid-match and assert ALL 12 SquadIds and AreAllies match server 12/12
|
||||
Guid tokenA = clientA.ReconnectToken;
|
||||
clientA.DisconnectGracefully("ReconnectSquadTest");
|
||||
clientA.Dispose();
|
||||
for (int t = 0; t < 20; t++)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
|
||||
using var clientARejoin = new RemoteArenaSession(ep, "LeaderSwap", tokenA);
|
||||
deadline = DateTime.UtcNow.AddSeconds(3);
|
||||
while (!clientARejoin.IsJoined && DateTime.UtcNow < deadline)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
clientARejoin.PumpNetwork();
|
||||
Thread.Sleep(2);
|
||||
}
|
||||
Assert.True(clientARejoin.IsJoined);
|
||||
Assert.Equal(0, clientARejoin.LocalContenderId);
|
||||
|
||||
// 2. Late-join a fresh clientB mid-match while non-allies are outside PVS
|
||||
using var clientB = new RemoteArenaSession(ep, "LateJoiner");
|
||||
deadline = DateTime.UtcNow.AddSeconds(3);
|
||||
while (!clientB.IsJoined && DateTime.UtcNow < deadline)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
clientARejoin.PumpNetwork();
|
||||
clientB.PumpNetwork();
|
||||
Thread.Sleep(2);
|
||||
}
|
||||
Assert.True(clientB.IsJoined);
|
||||
|
||||
var serverState = host.Session.State;
|
||||
for (int i = 0; i < MatchState.ContenderCount; i++)
|
||||
{
|
||||
Assert.Equal(serverState.Contenders[i].SquadId, clientARejoin.ViewState.Contenders[i].SquadId);
|
||||
Assert.Equal(serverState.Contenders[i].SquadId, clientB.ViewState.Contenders[i].SquadId);
|
||||
for (int j = 0; j < MatchState.ContenderCount; j++)
|
||||
{
|
||||
Assert.Equal(serverState.AreAllies(i, j), clientARejoin.ViewState.AreAllies(i, j));
|
||||
Assert.Equal(serverState.AreAllies(i, j), clientB.ViewState.AreAllies(i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1539,6 +1539,68 @@ namespace RustToDust.Tests
|
|||
$"CorePvs wire frame {wire.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SquadTrioDrop_AllSeedsAndMaps_AllLandedSquadmatesSeparatedAtLeast12Meters()
|
||||
{
|
||||
int[] seeds = { 1, 7, 42, 1337 };
|
||||
ArenaMapKind[] maps = { ArenaMapKind.Sion, ArenaMapKind.Desert };
|
||||
|
||||
foreach (var mapKind in maps)
|
||||
{
|
||||
foreach (int seed in seeds)
|
||||
{
|
||||
using var session = new ArenaSession(seed: seed, mapKind: mapKind, slot0Human: false, squadSize: 3);
|
||||
var state = session.State;
|
||||
|
||||
var tdPos = new (float X, float Z, int Tick)[MatchState.ContenderCount];
|
||||
var landed = new bool[MatchState.ContenderCount];
|
||||
for (int t = 0; t < 2400; t++)
|
||||
{
|
||||
session.Step();
|
||||
for (int i = 0; i < state.Contenders.Count; i++)
|
||||
{
|
||||
var c = state.Contenders[i];
|
||||
if (!landed[i] && c.IsGroundedActive)
|
||||
{
|
||||
landed[i] = true;
|
||||
tdPos[i] = (c.X, c.Z, t);
|
||||
}
|
||||
}
|
||||
if (state.Contenders.All(c => c.IsGroundedActive))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.All(state.Contenders, c => Assert.True(c.IsGroundedActive,
|
||||
$"Map={mapKind} Seed={seed} contender {c.Id} failed to land"));
|
||||
|
||||
foreach (var grp in state.Contenders.GroupBy(c => c.SquadId))
|
||||
{
|
||||
var members = grp.ToList();
|
||||
for (int a = 0; a < members.Count; a++)
|
||||
{
|
||||
for (int b = a + 1; b < members.Count; b++)
|
||||
{
|
||||
var ma = members[a];
|
||||
var mb = members[b];
|
||||
float tdDx = tdPos[ma.Id].X - tdPos[mb.Id].X;
|
||||
float tdDz = tdPos[ma.Id].Z - tdPos[mb.Id].Z;
|
||||
float tdDist = MathF.Sqrt(tdDx * tdDx + tdDz * tdDz);
|
||||
float dx = ma.X - mb.X;
|
||||
float dz = ma.Z - mb.Z;
|
||||
float d = MathF.Sqrt(dx * dx + dz * dz);
|
||||
Assert.True(tdDist >= 12.0f,
|
||||
$"Map={mapKind} Seed={seed} Squad={grp.Key} pair ({ma.Id}@t{tdPos[ma.Id].Tick},{mb.Id}@t{tdPos[mb.Id].Tick}) touchdown too close: td={tdDist:F2}m (now={d:F2}m)");
|
||||
Assert.True(d >= 12.0f,
|
||||
$"Map={mapKind} Seed={seed} Squad={grp.Key} pair ({ma.Id}@t{tdPos[ma.Id].Tick},{mb.Id}@t{tdPos[mb.Id].Tick}) landed too close: now={d:F2}m (td={tdDist:F2}m)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void AssertZeroChassisPenetration(MatchState state, ContenderState c)
|
||||
{
|
||||
var spec = c.Grid.Spec;
|
||||
|
|
|
|||
|
|
@ -979,5 +979,133 @@ namespace RustToDust.Tests
|
|||
var ex = Assert.Throws<InvalidOperationException>(() => OrdnanceGraphValidator.ValidateAndFlatten(combined));
|
||||
Assert.Contains("sub-spawn budget", ex.Message, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AlliedPdAndHitscan_DoNotInterceptSquadmateOrdnance()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 101, slot0Human: true, skipInitialDrop: true, squadSize: 3);
|
||||
var ally0 = session.State.Contenders[0];
|
||||
var ally1 = session.State.Contenders[1];
|
||||
var enemy = session.State.Contenders[3];
|
||||
Assert.True(session.State.AreAllies(ally0.Id, ally1.Id));
|
||||
Assert.False(session.State.AreAllies(ally0.Id, enemy.Id));
|
||||
IsolateContenders(session, ally0.Id, ally1.Id, enemy.Id);
|
||||
|
||||
// Place Ally 0 and Ally 1 nearby facing Enemy so Ally 1's PD + RailPlasmaBeam shoot across Ally 0's ordnance
|
||||
session.SetContenderPose(ally0.Id, 0f, 0f, 0f);
|
||||
session.SetContenderPose(ally1.Id, 16f, 16f, -0.5f);
|
||||
session.SetContenderPose(enemy.Id, 0f, 80f, MathF.PI);
|
||||
|
||||
foreach (var c in new[] { ally0, ally1, enemy })
|
||||
{
|
||||
session.State.SpawnChassisDrop(c.X, c.Z, Catalog.Anvil);
|
||||
Assert.True(session.State.TrySwapNearbyChassis(c.Id));
|
||||
c.Grid.Mounted.RemoveAll(m => m.Spec.Kind == HardpointKind.Weapon);
|
||||
}
|
||||
session.SetContenderPose(ally0.Id, 0f, 0f, 0f);
|
||||
session.SetContenderPose(ally1.Id, 16f, 16f, -0.5f);
|
||||
session.SetContenderPose(enemy.Id, 0f, 80f, MathF.PI);
|
||||
|
||||
var droneSpec = ProceduralWeaponGenerator.CreateDreamLoiteringDrone();
|
||||
var swarmSpec = ProceduralWeaponGenerator.CreateDreamWeapon(WeaponArchetypeKind.HomingSwarmPod);
|
||||
var railSpec = ProceduralWeaponGenerator.CreateDreamWeapon(WeaponArchetypeKind.RailPlasmaBeam);
|
||||
Assert.True(ally0.Grid.TryMount(droneSpec.Module, "hp.weapon.siege_l"));
|
||||
Assert.True(ally0.Grid.TryMount(swarmSpec.Module, "hp.weapon.siege_r"));
|
||||
Assert.True(ally1.Grid.TryMount(Catalog.ImperialAegisPd, "hp.weapon.sponson_l"));
|
||||
Assert.True(ally1.Grid.TryMount(railSpec.Module, "hp.weapon.siege_l"));
|
||||
Assert.True(ally1.Grid.TryMount(Catalog.GoldRadiator, "hp.radiator.l"));
|
||||
Assert.True(ally1.Grid.TryMount(Catalog.GoldRadiator, "hp.radiator.r"));
|
||||
|
||||
session.SetHumanSlot(ally1.Id, true, "Ally1");
|
||||
session.SetHumanInput(ally0.Id, new PlayerInput(0f, 0f, enemy.X, enemy.Z, Fire: false, InteractPickup: false, Brake: true, AimWorldY: enemy.Y + 2f));
|
||||
session.SetHumanInput(ally1.Id, new PlayerInput(0f, 0f, 0f, 25f, Fire: false, InteractPickup: false, Brake: true, AimWorldY: 12f));
|
||||
session.Step();
|
||||
|
||||
var events = new List<ISimEvent>();
|
||||
session.DrainStepEvents(events);
|
||||
|
||||
int allyOrdnanceSpawned = 0;
|
||||
int allyOrdnanceIntercepted = 0;
|
||||
int railShotsWhileAllyOrdnanceAirborne = 0;
|
||||
|
||||
for (int tick = 0; tick < 360; tick++)
|
||||
{
|
||||
Vector3? allyAirbornePos = null;
|
||||
var pool = session.Ordnance.PoolSpan;
|
||||
for (int i = 0; i < pool.Length; i++)
|
||||
{
|
||||
ref readonly var inst = ref pool[i];
|
||||
if (!inst.Active || inst.IsSpectatorShooter || inst.ShooterContenderId != ally0.Id)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (inst.Def.InterceptHp > 0f &&
|
||||
inst.Def.Motion is OrdnanceMotion.LoiterOrbit or OrdnanceMotion.HomingMissile)
|
||||
{
|
||||
allyAirbornePos = inst.Pos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Keep Ally 1 cool enough to continuously fire PD + RailPlasmaBeam directly at Ally 0's airborne ordnance
|
||||
foreach (var mod in ally1.Grid.Mounted)
|
||||
{
|
||||
mod.CurrentTemp = mod.Spec.OptimalTemp;
|
||||
}
|
||||
|
||||
session.SetHumanInput(ally0.Id, new PlayerInput(
|
||||
0f, 0f,
|
||||
enemy.X, enemy.Z,
|
||||
Fire: tick < 5,
|
||||
InteractPickup: false,
|
||||
Brake: true,
|
||||
AimWorldY: enemy.Y + 2f));
|
||||
|
||||
if (allyAirbornePos.HasValue)
|
||||
{
|
||||
var p = allyAirbornePos.Value;
|
||||
session.SetHumanInput(ally1.Id, new PlayerInput(
|
||||
0f, 0f,
|
||||
p.X, p.Z,
|
||||
Fire: true,
|
||||
InteractPickup: false,
|
||||
Brake: true,
|
||||
AimWorldY: p.Y));
|
||||
railShotsWhileAllyOrdnanceAirborne++;
|
||||
}
|
||||
else
|
||||
{
|
||||
session.SetHumanInput(ally1.Id, new PlayerInput(
|
||||
0f, 0f,
|
||||
enemy.X, enemy.Z,
|
||||
Fire: false,
|
||||
InteractPickup: false,
|
||||
Brake: true,
|
||||
AimWorldY: enemy.Y + 2f));
|
||||
}
|
||||
|
||||
session.Step();
|
||||
events.Clear();
|
||||
session.DrainStepEvents(events);
|
||||
foreach (var ev in events)
|
||||
{
|
||||
if (ev is OrdnanceNodeEvent one && !one.IsSpectatorShooter && one.ShooterId == ally0.Id)
|
||||
{
|
||||
if (one.Kind == (byte)OrdnanceEventKind.Spawned)
|
||||
{
|
||||
allyOrdnanceSpawned++;
|
||||
}
|
||||
else if (one.Kind == (byte)OrdnanceEventKind.Intercepted)
|
||||
{
|
||||
allyOrdnanceIntercepted++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Assert.True(allyOrdnanceSpawned >= 2, $"Expected Ally 0 to spawn drone + swarm ordnance, got {allyOrdnanceSpawned}");
|
||||
Assert.True(railShotsWhileAllyOrdnanceAirborne >= 10, $"Expected Ally 1 to aim RailPlasmaBeam + PD at airborne ally ordnance, got {railShotsWhileAllyOrdnanceAirborne}");
|
||||
Assert.Equal(0, allyOrdnanceIntercepted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue