Fix all 6 60 FPS Soul Pass findings and add permanent regression tests
This commit is contained in:
parent
0f36eed3a0
commit
f5d23ce49e
12 changed files with 1031 additions and 305 deletions
|
|
@ -420,5 +420,149 @@ namespace RustToDust.Tests
|
|||
Assert.True(spec.LastKnownTargetZ > spec.Z + 10f,
|
||||
$"Expected LastKnownTarget to point along incoming +Z direction, got Z={spec.LastKnownTargetZ:F1} vs spec.Z={spec.Z:F1}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AiContender_ImmediatelyDropsTrackingAndFiring_OnExactTickLosBreaks()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 12);
|
||||
var box = session.State.ArenaCoverBoxes[0];
|
||||
var player = session.State.Player;
|
||||
var ai = session.State.Contenders[1];
|
||||
|
||||
// Move other rivals far away so only ai <-> player interaction is isolated
|
||||
for (int i = 2; i < session.State.Contenders.Count; i++)
|
||||
{
|
||||
session.SetContenderPose(session.State.Contenders[i].Id, -680f + i * 8f, -680f);
|
||||
}
|
||||
|
||||
// Ensure both player and AI are low-profile ground vehicles shorter than the cover wall
|
||||
if (player.Grid.Spec.IsVtol || player.Grid.Spec.HalfHeight * 2f >= box.HalfY * 2f)
|
||||
{
|
||||
session.SetContenderPose(player.Id, box.X, box.Z - box.HalfZ - 8f);
|
||||
session.State.SpawnChassisDrop(box.X, box.Z - box.HalfZ - 8f, Catalog.Jackal);
|
||||
Assert.True(session.State.TrySwapNearbyChassis(player.Id));
|
||||
}
|
||||
if (ai.Grid.Spec.IsVtol || ai.Grid.Spec.HalfHeight * 2f >= box.HalfY * 2f)
|
||||
{
|
||||
session.SetContenderPose(ai.Id, box.X + 8f, box.Z - box.HalfZ - 8f);
|
||||
session.State.SpawnChassisDrop(box.X + 8f, box.Z - box.HalfZ - 8f, Catalog.Jackal);
|
||||
Assert.True(session.State.TrySwapNearbyChassis(ai.Id));
|
||||
}
|
||||
|
||||
// Test breaking LOS across multiple step-tick phases (would catch any % 3 stagger!)
|
||||
for (int phase = 0; phase < 3; phase++)
|
||||
{
|
||||
// Place both on the same open side of the cover box within firing range (< 165m)
|
||||
session.SetContenderPose(ai.Id, box.X, box.Z - box.HalfZ - 14f, yaw: 0f);
|
||||
session.SetContenderPose(player.Id, box.X + 18f, box.Z - box.HalfZ - 14f, yaw: 0f);
|
||||
|
||||
// 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));
|
||||
Assert.Equal(player.Id, ai.AiTargetContenderId);
|
||||
Assert.True(ai.FireCmd, $"Expected AI to acquire open-LOS target and fire immediately (phase={phase}, t={t})");
|
||||
}
|
||||
|
||||
// Now break LOS behind the static cover wall while staying within weapon range
|
||||
session.SetContenderPose(ai.Id, box.X, box.Z - box.HalfZ - 8f, yaw: 0f);
|
||||
session.SetContenderPose(player.Id, box.X, box.Z + box.HalfZ + 8f, yaw: 0f);
|
||||
session.State.Tracers.Clear();
|
||||
|
||||
for (int occTick = 0; occTick < 6; occTick++)
|
||||
{
|
||||
if (occTick > 0)
|
||||
{
|
||||
// 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));
|
||||
|
||||
Assert.Null(ai.AiTargetContenderId);
|
||||
Assert.False(ai.FireCmd, $"AI leaked FireCmd on occluded tick {occTick} (phase={phase})");
|
||||
float aimToHidden = MathF.Sqrt((ai.AimX - player.X) * (ai.AimX - player.X) + (ai.AimZ - player.Z) * (ai.AimZ - player.Z));
|
||||
Assert.True(aimToHidden > 5f, $"AI aim leaked hidden player coords on occluded tick {occTick} (dist={aimToHidden:F2}m)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PlayerDetectedByCount_StaysExactZero_UnderAsymmetricCover_NoFlicker()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 12);
|
||||
var box = session.State.ArenaCoverBoxes.First(b => b.HalfY >= 2.8f);
|
||||
var player = session.State.Player;
|
||||
var rival = session.State.Contenders[1];
|
||||
|
||||
// Move all other rivals and spectators far away (> 500m) so only rival <-> player is tested
|
||||
for (int i = 2; i < session.State.Contenders.Count; i++)
|
||||
{
|
||||
session.SetContenderPose(session.State.Contenders[i].Id, -680f + i * 8f, -680f);
|
||||
}
|
||||
for (int i = 0; i < session.State.Spectators.Spectators.Count; i++)
|
||||
{
|
||||
var s = session.State.Spectators.Spectators[i];
|
||||
session.SetSpectatorPose(s.Id, (box.X >= 0f ? -1f : 1f) * 680f, (box.Z >= 0f ? -1f : 1f) * 680f);
|
||||
}
|
||||
|
||||
// Medium-tall player (Breaker) right next to the 5.6m bunker sees over it onto a low rival (Jackal) 40m on the far side,
|
||||
// while the low rival's eye cannot see the Breaker's lower target center behind the bunker.
|
||||
session.SetContenderPose(player.Id, box.X, box.Z - box.HalfZ - 4f);
|
||||
session.State.SpawnChassisDrop(player.X, player.Z, Catalog.Breaker);
|
||||
Assert.True(session.State.TrySwapNearbyChassis(player.Id));
|
||||
|
||||
session.SetContenderPose(rival.Id, box.X, box.Z + box.HalfZ + 40f);
|
||||
session.State.SpawnChassisDrop(rival.X, rival.Z, Catalog.Jackal);
|
||||
Assert.True(session.State.TrySwapNearbyChassis(rival.Id));
|
||||
|
||||
// Confirm asymmetric LOS precondition
|
||||
Assert.True(session.HasLineOfSight(
|
||||
player.X, MatchRules.GetObserverEyeY(player.Y, player.Grid.Spec.HalfHeight), player.Z,
|
||||
rival.X, MatchRules.GetTargetAimY(rival.Y, rival.Grid.Spec.HalfHeight), rival.Z));
|
||||
Assert.False(session.HasLineOfSight(
|
||||
rival.X, MatchRules.GetObserverEyeY(rival.Y, rival.Grid.Spec.HalfHeight), rival.Z,
|
||||
player.X, MatchRules.GetTargetAimY(player.Y, player.Grid.Spec.HalfHeight), player.Z));
|
||||
|
||||
for (int tick = 0; tick < 18; tick++)
|
||||
{
|
||||
// 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));
|
||||
|
||||
Assert.True(session.State.ContenderContacts[rival.Id].VisibleToPlayer);
|
||||
Assert.Equal(0, session.State.PlayerDetectedByCount);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SpectatorRing_ClearsNearestOpenLosNeutralWatcher_OnFirstTickOutsideSafeRadius()
|
||||
{
|
||||
// Test every tick phase 0..5 so % 6 staggering cannot hide
|
||||
for (int tickIndex = 0; tickIndex < 6; tickIndex++)
|
||||
{
|
||||
var ring = new SpectatorRing(seed: 42);
|
||||
// Pick a spectator whose (Id + tickIndex) % 6 != 0 so % 6 staggering would have skipped it
|
||||
var targetNearest = ring.Spectators.First(s => (s.Id + tickIndex) % 6 != 0);
|
||||
|
||||
// Place contender just outside SafeRadius directly beside targetNearest (within 12m outside => allowedCleared = 1)
|
||||
float len = MathF.Sqrt(targetNearest.X * targetNearest.X + targetNearest.Z * targetNearest.Z);
|
||||
float nx = targetNearest.X / len;
|
||||
float nz = targetNearest.Z / len;
|
||||
float outR = ring.SafeRadius + 4f;
|
||||
float cx = nx * outR;
|
||||
float cz = nz * outR;
|
||||
|
||||
ring.UpdateClearance(
|
||||
new[] { new RingContact(0, cx, cz, true) },
|
||||
1f / 60f,
|
||||
static (_, _) => true,
|
||||
tickIndex: tickIndex);
|
||||
|
||||
Assert.Equal(1, ring.CountClearedFor(0));
|
||||
Assert.Equal(SpectatorStance.Cleared, targetNearest.Stance);
|
||||
Assert.Equal(0, targetNearest.TargetContenderId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue