Keep SpectatorRing Cleared sticky and prevent occluded lateral coordinate leaks
This commit is contained in:
parent
f41b9249e3
commit
2fdbc56d9f
2 changed files with 379 additions and 97 deletions
|
|
@ -322,5 +322,93 @@ namespace RustToDust.Tests
|
|||
Assert.Equal(clearedInitialKnownX, cAimX, precision: 3);
|
||||
Assert.Equal(clearedInitialKnownZ, cAimZ, precision: 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Probe2_OccludedLateralArc_FullRingDoesNotLeakOrTrackPlayerPosition()
|
||||
{
|
||||
var ring = new SpectatorRing(seed: 42);
|
||||
Assert.Equal(56, ring.Spectators.Count);
|
||||
const float dt = 1f / 60f;
|
||||
|
||||
// Phase 1 (10 ticks): Player pops out of safe circle briefly at 0 degrees with LOS to nearby 0-deg watchers.
|
||||
float startR = ring.SafeRadius + 15f;
|
||||
for (int tick = 0; tick < 10; tick++)
|
||||
{
|
||||
var contact = new RingContact(0, startR, 0f, true);
|
||||
ring.UpdateClearance(new[] { contact }, dt, (spec, _) =>
|
||||
{
|
||||
float specAng = MathF.Atan2(spec.Z, spec.X);
|
||||
return MathF.Abs(specAng) < 0.45f;
|
||||
});
|
||||
}
|
||||
|
||||
int initialCleared = ring.CountClearedFor(0);
|
||||
Assert.True(initialCleared >= 1, "Expected at least one Cleared spectator at 0 degrees during initial pop-out");
|
||||
Assert.Contains(ring.Spectators, s => s.Stance == SpectatorStance.Cleared && s.HasTargetLos);
|
||||
|
||||
// Phase 2 (600 ticks = 10s): 100% occlusion while player moves laterally 0 -> 80 deg and steps further out.
|
||||
float playerX = startR;
|
||||
float playerZ = 0f;
|
||||
float maxArcRad = 80f * (MathF.PI / 180f);
|
||||
|
||||
for (int tick = 0; tick < 600; tick++)
|
||||
{
|
||||
float t = tick / 599f;
|
||||
float angle = t * maxArcRad;
|
||||
float r = ring.SafeRadius + 15f + t * 70f;
|
||||
playerX = MathF.Cos(angle) * r;
|
||||
playerZ = MathF.Sin(angle) * r;
|
||||
|
||||
var contact = new RingContact(0, playerX, playerZ, true);
|
||||
ring.UpdateClearance(new[] { contact }, dt, static (_, _) => false);
|
||||
|
||||
foreach (var s in ring.Spectators)
|
||||
{
|
||||
Assert.False(s.HasTargetLos, $"No spectator may have LOS during occluded arc (tick {tick}, spec {s.Id})");
|
||||
if (s.Stance == SpectatorStance.Cleared)
|
||||
{
|
||||
float targetAngle = MathF.Atan2(s.LastKnownTargetZ, s.LastKnownTargetX);
|
||||
Assert.True(MathF.Abs(targetAngle) < 0.35f,
|
||||
$"Cleared spectator {s.Id} leaked lateral angle {targetAngle * 180f / MathF.PI:F1} deg at tick {tick}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// At end of 80-deg hidden move, no spectator has LastKnownTarget near the player's hidden position,
|
||||
// and spectators stationed along 35..90 degrees remain Neutral.
|
||||
foreach (var s in ring.Spectators)
|
||||
{
|
||||
if (s.Stance == SpectatorStance.Cleared)
|
||||
{
|
||||
float dx = s.LastKnownTargetX - playerX;
|
||||
float dz = s.LastKnownTargetZ - playerZ;
|
||||
float distToHiddenPlayer = MathF.Sqrt(dx * dx + dz * dz);
|
||||
Assert.True(distToHiddenPlayer > 400f,
|
||||
$"Cleared spectator {s.Id} LastKnownTarget ({s.LastKnownTargetX:F1}, {s.LastKnownTargetZ:F1}) too close to hidden player ({distToHiddenPlayer:F1}m)");
|
||||
}
|
||||
|
||||
float specAngleDeg = MathF.Atan2(s.Z, s.X) * (180f / MathF.PI);
|
||||
if (specAngleDeg >= 35f && specAngleDeg <= 95f)
|
||||
{
|
||||
Assert.Equal(SpectatorStance.Neutral, s.Stance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OnSpectatorDamaged_WithoutLos_SeedsIncomingDirectionInsteadOfStaleTarget()
|
||||
{
|
||||
var ring = new SpectatorRing(seed: 77);
|
||||
var spec = ring.Spectators[0];
|
||||
spec.LastKnownTargetX = 0f;
|
||||
spec.LastKnownTargetZ = 0f;
|
||||
|
||||
bool provoked = ring.OnSpectatorDamaged(spec, attackerContenderId: 0, incomingDirX: 0f, incomingDirZ: 1f);
|
||||
Assert.True(provoked);
|
||||
Assert.Equal(SpectatorStance.Provoked, spec.Stance);
|
||||
Assert.False(spec.HasTargetLos);
|
||||
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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue