2026-12-04 15:14:00 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using RustToDust.Core;
|
|
|
|
|
using RustToDust.Ymir;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace RustToDust.Tests
|
|
|
|
|
{
|
|
|
|
|
public sealed class DetectionLosTests
|
|
|
|
|
{
|
|
|
|
|
private static TerrainBrush FindTallMesa(TerrainField terrain)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < terrain.Brushes.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var b = terrain.Brushes[i];
|
|
|
|
|
if (b.Kind == TerrainBrushKind.Mesa && b.HeightDelta >= 22f)
|
|
|
|
|
{
|
|
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
throw new InvalidOperationException("Expected at least one tall Mesa in generated terrain.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void MesaBetweenSpectatorAndContender_BlocksLosAndPreventsFiringThroughTerrain()
|
|
|
|
|
{
|
|
|
|
|
using var session = new ArenaSession(seed: 42);
|
|
|
|
|
var mesa = FindTallMesa(session.State.Terrain);
|
|
|
|
|
var player = session.State.Player;
|
|
|
|
|
var spec = session.State.Spectators.Spectators.First(s => s.Tier == SpectatorTier.Patron);
|
|
|
|
|
|
|
|
|
|
// Place player and spectator on opposite sides of the tall mesa
|
|
|
|
|
float playerX = mesa.X - mesa.RadiusX - 18f;
|
|
|
|
|
float specX = mesa.X + mesa.RadiusX + 18f;
|
|
|
|
|
session.SetContenderPose(player.Id, playerX, mesa.Z);
|
|
|
|
|
session.SetSpectatorPose(spec.Id, specX, mesa.Z);
|
|
|
|
|
|
|
|
|
|
// Provoke this spectator onto the player so it actively hunts, while terrain blocks sightline
|
|
|
|
|
session.State.Spectators.OnSpectatorDamaged(spec, player.Id);
|
|
|
|
|
float initialCoreHp = player.Grid.CoreHp;
|
|
|
|
|
|
|
|
|
|
for (int tick = 0; tick < 10; tick++)
|
|
|
|
|
{
|
|
|
|
|
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
|
|
|
|
|
|
|
|
|
|
Assert.False(session.HasLineOfSight(
|
|
|
|
|
spec.X, MatchRules.GetObserverEyeY(spec.Y, spec.Grid.Spec.HalfHeight), spec.Z,
|
|
|
|
|
player.X, MatchRules.GetTargetAimY(player.Y, player.Grid.Spec.HalfHeight), player.Z));
|
|
|
|
|
Assert.False(spec.HasTargetLos);
|
|
|
|
|
|
|
|
|
|
MatchRules.ComputeSpectatorBehavior(spec, session.State, out _, out _, out _, out _, out bool shouldFire);
|
|
|
|
|
Assert.False(shouldFire, "Occluded spectator must NOT fire through a mesa");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.Equal(initialCoreHp, player.Grid.CoreHp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CrestingRidge_RestoresLosAndAllowsSpectatorEngagement()
|
|
|
|
|
{
|
|
|
|
|
using var session = new ArenaSession(seed: 42);
|
|
|
|
|
var mesa = FindTallMesa(session.State.Terrain);
|
|
|
|
|
var player = session.State.Player;
|
|
|
|
|
var spec = session.State.Spectators.Spectators.First(s => s.Tier == SpectatorTier.Patron);
|
|
|
|
|
|
|
|
|
|
// Start occluded across the mesa
|
|
|
|
|
session.SetContenderPose(player.Id, mesa.X - mesa.RadiusX - 18f, mesa.Z);
|
|
|
|
|
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));
|
|
|
|
|
Assert.False(spec.HasTargetLos);
|
|
|
|
|
|
|
|
|
|
// Now player crests onto the high mesa plateau overlooking the spectator
|
|
|
|
|
session.SetContenderPose(player.Id, mesa.X + mesa.RadiusX * 0.25f, mesa.Z);
|
|
|
|
|
session.SetSpectatorPose(spec.Id, mesa.X + mesa.RadiusX + 18f, mesa.Z);
|
|
|
|
|
|
|
|
|
|
bool sawTracer = false;
|
|
|
|
|
for (int tick = 0; tick < 30; tick++)
|
|
|
|
|
{
|
|
|
|
|
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
|
|
|
|
|
if (session.State.Tracers.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
sawTracer = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.True(spec.HasTargetLos, "Cresting the mesa must restore spectator LOS");
|
|
|
|
|
MatchRules.ComputeSpectatorBehavior(spec, session.State, out _, out _, out _, out _, out bool shouldFire);
|
|
|
|
|
Assert.True(shouldFire, "Spectator with restored LOS within range should be cleared to fire");
|
|
|
|
|
Assert.True(sawTracer, "Expected spectator to fire weapons once LOS was restored");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void LowSignatureExemplar_HiddenBehindRidge_IsInvisibleOnRadar_WhileInLosContactIsVisible()
|
|
|
|
|
{
|
|
|
|
|
using var session = new ArenaSession(seed: 42);
|
|
|
|
|
var mesa = FindTallMesa(session.State.Terrain);
|
|
|
|
|
var player = session.State.Player;
|
|
|
|
|
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();
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
var exMem = session.State.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];
|
|
|
|
|
Assert.True(rivalMem.VisibleToPlayer, "In-LOS contact must be live-visible to player");
|
|
|
|
|
Assert.True(MatchState.IsContactOnRadar(rivalMem));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void StaticCoverWall_BlocksLineOfSight()
|
|
|
|
|
{
|
|
|
|
|
using var session = new ArenaSession(seed: 12);
|
|
|
|
|
var box = session.State.ArenaCoverBoxes[0];
|
|
|
|
|
var player = session.State.Player;
|
|
|
|
|
var rival = session.State.Contenders[1];
|
|
|
|
|
|
2026-12-04 19:11:33 +01:00
|
|
|
// Ensure rival is a low-profile ground vehicle shorter than the 4m ruin cover wall
|
|
|
|
|
if (rival.Grid.Spec.IsVtol || rival.Grid.Spec.HalfHeight * 2f >= box.HalfY * 2f)
|
|
|
|
|
{
|
|
|
|
|
session.SetContenderPose(rival.Id, box.X, box.Z + box.HalfZ + 4f);
|
|
|
|
|
session.State.SpawnChassisDrop(box.X, box.Z + box.HalfZ + 4f, Catalog.Jackal);
|
|
|
|
|
Assert.True(session.State.TrySwapNearbyChassis(rival.Id));
|
|
|
|
|
}
|
|
|
|
|
|
2026-12-04 15:14:00 +01:00
|
|
|
session.SetContenderPose(player.Id, box.X, box.Z - box.HalfZ - 4f);
|
|
|
|
|
session.SetContenderPose(rival.Id, box.X, box.Z + box.HalfZ + 4f);
|
|
|
|
|
|
|
|
|
|
bool los = 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(los, "Static cover ruin wall between two vehicles must block HasLineOfSight");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void NeutralTierPositioning_PatronsClaimHigherGroundThanTouristsAndExemplars_AndHoldSpots()
|
|
|
|
|
{
|
|
|
|
|
var state = new MatchState(seed: 42);
|
|
|
|
|
var ring = state.Spectators;
|
|
|
|
|
|
|
|
|
|
var touristHeights = new List<float>();
|
|
|
|
|
var patronHeights = new List<float>();
|
|
|
|
|
var exemplarHeights = new List<float>();
|
|
|
|
|
var initialGoals = new Dictionary<int, (float X, float Z)>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < ring.Spectators.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var s = ring.Spectators[i];
|
|
|
|
|
var (gx, gz) = ring.GetNeutralGoal(s, state.Terrain, state.ArenaCoverBoxes);
|
|
|
|
|
initialGoals[s.Id] = (gx, gz);
|
|
|
|
|
float h = state.Terrain.SampleHeight(gx, gz);
|
|
|
|
|
|
|
|
|
|
switch (s.Tier)
|
|
|
|
|
{
|
|
|
|
|
case SpectatorTier.Tourist: touristHeights.Add(h); break;
|
|
|
|
|
case SpectatorTier.Patron: patronHeights.Add(h); break;
|
|
|
|
|
case SpectatorTier.Exemplar: exemplarHeights.Add(h); break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float avgPatronH = patronHeights.Average();
|
|
|
|
|
float avgTouristH = touristHeights.Average();
|
|
|
|
|
float avgExemplarH = exemplarHeights.Average();
|
|
|
|
|
|
|
|
|
|
Assert.True(avgPatronH > avgTouristH + 1.0f,
|
|
|
|
|
$"Expected Patrons ({avgPatronH:F2}m) to claim higher ground than Tourists ({avgTouristH:F2}m)");
|
|
|
|
|
Assert.True(avgPatronH > avgExemplarH + 1.0f,
|
|
|
|
|
$"Expected Patrons ({avgPatronH:F2}m) to claim higher ground than Exemplars ({avgExemplarH:F2}m)");
|
|
|
|
|
|
|
|
|
|
// Advance perimeter orbits while SafeRadius is within grace period: Tourists orbit, Patrons & Exemplars hold!
|
|
|
|
|
ring.AdvancePerimeterOrbits(15f);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < ring.Spectators.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var s = ring.Spectators[i];
|
|
|
|
|
var (gx, gz) = ring.GetNeutralGoal(s, state.Terrain, state.ArenaCoverBoxes);
|
|
|
|
|
var prev = initialGoals[s.Id];
|
|
|
|
|
float moved = MathF.Sqrt((gx - prev.X) * (gx - prev.X) + (gz - prev.Z) * (gz - prev.Z));
|
|
|
|
|
|
|
|
|
|
if (s.Tier == SpectatorTier.Tourist)
|
|
|
|
|
{
|
|
|
|
|
Assert.True(moved > 10f, "Expected Neutral Tourists to continue orbiting perimeter");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Assert.True(moved < 0.01f, $"Expected Neutral {s.Tier} to hold chosen vantage/ambush spot, moved {moved:F2}m");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-12-04 15:41:02 +01:00
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void OccludedSpectators_DoNotLeakLiveTargetAfterMemoryExpires_FiveSeconds()
|
|
|
|
|
{
|
|
|
|
|
using var session = new ArenaSession(seed: 42);
|
|
|
|
|
// Shrink safe circle so the tall mesa perimeter is outside SafeRadius
|
|
|
|
|
session.State.Time = 360f;
|
|
|
|
|
session.State.Spectators.UpdateSafeRadius(session.State.Time);
|
|
|
|
|
|
|
|
|
|
TerrainBrush mesa = default;
|
2026-12-04 15:43:54 +01:00
|
|
|
float bestMinRadius = -1f;
|
2026-12-04 15:41:02 +01:00
|
|
|
for (int i = 0; i < session.State.Terrain.Brushes.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var b = session.State.Terrain.Brushes[i];
|
|
|
|
|
if (b.Kind == TerrainBrushKind.Mesa && b.HeightDelta >= 22f)
|
|
|
|
|
{
|
2026-12-04 15:43:54 +01:00
|
|
|
float minR = MathF.Min(b.RadiusX, b.RadiusZ);
|
|
|
|
|
if (minR > bestMinRadius)
|
2026-12-04 15:41:02 +01:00
|
|
|
{
|
2026-12-04 15:43:54 +01:00
|
|
|
bestMinRadius = minR;
|
2026-12-04 15:41:02 +01:00
|
|
|
mesa = b;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-12-04 15:43:54 +01:00
|
|
|
Assert.True(bestMinRadius > 0f, "Expected at least one tall Mesa in generated terrain.");
|
2026-12-04 15:41:02 +01:00
|
|
|
|
|
|
|
|
var player = session.State.Player;
|
|
|
|
|
var tourists = session.State.Spectators.Spectators.Where(s => s.Tier == SpectatorTier.Tourist).ToList();
|
|
|
|
|
var provokedSpec = tourists[0];
|
|
|
|
|
var clearedSpec = tourists[1];
|
|
|
|
|
|
2026-12-04 19:11:33 +01:00
|
|
|
// Place player on the side of the mesa further from center (strictly outside SafeRadius)
|
|
|
|
|
float xNeg = mesa.X - mesa.RadiusX - 18f;
|
|
|
|
|
float xPos = mesa.X + mesa.RadiusX + 18f;
|
|
|
|
|
bool negIsFurther = (xNeg * xNeg + mesa.Z * mesa.Z) >= (xPos * xPos + mesa.Z * mesa.Z);
|
|
|
|
|
float occludedX = negIsFurther ? xNeg : xPos;
|
|
|
|
|
float specSideX = negIsFurther ? (mesa.X + mesa.RadiusX + 45f) : (mesa.X - mesa.RadiusX - 45f);
|
|
|
|
|
|
|
|
|
|
// Keep AI contenders safely inside the safe circle and other spectators behind the mesa shadow so they don't peek around the flank
|
2026-12-04 16:08:52 +01:00
|
|
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
session.SetContenderPose(session.State.Contenders[i].Id, (i - 6) * 12f, 0f);
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < session.State.Spectators.Spectators.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var other = session.State.Spectators.Spectators[i];
|
|
|
|
|
if (other.Id != provokedSpec.Id && other.Id != clearedSpec.Id)
|
|
|
|
|
{
|
2026-12-04 19:11:33 +01:00
|
|
|
float farX = (mesa.X >= 0f ? -1f : 1f) * 680f;
|
|
|
|
|
float farZ = (mesa.Z >= 0f ? -1f : 1f) * 680f;
|
|
|
|
|
session.SetSpectatorPose(other.Id, farX, farZ);
|
2026-12-04 16:08:52 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-12-04 15:41:02 +01:00
|
|
|
// Briefly establish visual contact for provokedSpec at initial spot, then move player behind the mesa
|
|
|
|
|
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));
|
|
|
|
|
Assert.True(provokedSpec.HasTargetLos, "Expected initial LOS before player drops behind cover");
|
|
|
|
|
|
|
|
|
|
float provokedKnownX = provokedSpec.LastKnownTargetX;
|
|
|
|
|
float provokedKnownZ = provokedSpec.LastKnownTargetZ;
|
|
|
|
|
|
|
|
|
|
// Now hide player behind the mesa and place clearedSpec on the opposite side closest to the breach
|
|
|
|
|
session.SetContenderPose(player.Id, occludedX, mesa.Z - 14f);
|
|
|
|
|
session.SetSpectatorPose(provokedSpec.Id, specSideX, mesa.Z - 4f);
|
|
|
|
|
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));
|
|
|
|
|
Assert.False(provokedSpec.HasTargetLos);
|
|
|
|
|
Assert.Equal(SpectatorStance.Cleared, clearedSpec.Stance);
|
|
|
|
|
Assert.False(clearedSpec.HasTargetLos);
|
|
|
|
|
|
|
|
|
|
float clearedInitialKnownX = clearedSpec.LastKnownTargetX;
|
|
|
|
|
float clearedInitialKnownZ = clearedSpec.LastKnownTargetZ;
|
|
|
|
|
|
|
|
|
|
// Run 300 ticks (5.0s > 4.0s TargetMemoryDuration) while player moves laterally behind cover
|
|
|
|
|
for (int tick = 0; tick < 300; tick++)
|
|
|
|
|
{
|
2026-12-04 15:43:54 +01:00
|
|
|
float latZ = mesa.Z - 14f + (tick / 299f) * 28f;
|
2026-12-04 15:41:02 +01:00
|
|
|
if (tick % 10 == 0)
|
|
|
|
|
{
|
|
|
|
|
session.SetContenderPose(player.Id, occludedX, latZ);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
|
|
|
|
|
|
|
|
|
|
Assert.False(provokedSpec.HasTargetLos, $"Provoked spectator regained unexpected LOS at tick {tick}");
|
|
|
|
|
Assert.False(clearedSpec.HasTargetLos, $"Cleared spectator regained unexpected LOS at tick {tick}");
|
|
|
|
|
|
|
|
|
|
if (tick == 270) // 4.5s > 4.0s memory window
|
|
|
|
|
{
|
|
|
|
|
Assert.True(provokedSpec.TimeSinceLastSeen >= 4.5f,
|
|
|
|
|
$"Provoked TimeSinceLastSeen reset unexpectedly: {provokedSpec.TimeSinceLastSeen:F2}s");
|
|
|
|
|
Assert.True(clearedSpec.TimeSinceLastSeen >= 4.5f,
|
|
|
|
|
$"Cleared TimeSinceLastSeen reset unexpectedly: {clearedSpec.TimeSinceLastSeen:F2}s");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Neither spectator's LastKnownTarget or aim vector may track the player's new occluded position
|
|
|
|
|
float provokedDistToPlayer = MathF.Sqrt(
|
|
|
|
|
(provokedSpec.LastKnownTargetX - player.X) * (provokedSpec.LastKnownTargetX - player.X) +
|
|
|
|
|
(provokedSpec.LastKnownTargetZ - player.Z) * (provokedSpec.LastKnownTargetZ - player.Z));
|
|
|
|
|
Assert.Equal(provokedKnownX, provokedSpec.LastKnownTargetX, precision: 3);
|
|
|
|
|
Assert.Equal(provokedKnownZ, provokedSpec.LastKnownTargetZ, precision: 3);
|
|
|
|
|
Assert.True(provokedDistToPlayer > 25f,
|
|
|
|
|
$"Provoked LastKnownTarget leaked live player position (dist={provokedDistToPlayer:F2}m)");
|
|
|
|
|
|
|
|
|
|
float clearedDistToPlayer = MathF.Sqrt(
|
|
|
|
|
(clearedSpec.LastKnownTargetX - player.X) * (clearedSpec.LastKnownTargetX - player.X) +
|
|
|
|
|
(clearedSpec.LastKnownTargetZ - player.Z) * (clearedSpec.LastKnownTargetZ - player.Z));
|
|
|
|
|
Assert.Equal(clearedInitialKnownX, clearedSpec.LastKnownTargetX, precision: 3);
|
|
|
|
|
Assert.Equal(clearedInitialKnownZ, clearedSpec.LastKnownTargetZ, precision: 3);
|
|
|
|
|
Assert.True(clearedDistToPlayer > 20f,
|
|
|
|
|
$"Cleared LastKnownTarget leaked live player position (dist={clearedDistToPlayer:F2}m)");
|
|
|
|
|
|
|
|
|
|
MatchRules.ComputeSpectatorBehavior(provokedSpec, session.State, out _, out _, out float pAimX, out float pAimZ, out bool pFire);
|
|
|
|
|
Assert.False(pFire);
|
|
|
|
|
Assert.Equal(provokedKnownX, pAimX, precision: 3);
|
|
|
|
|
Assert.Equal(provokedKnownZ, pAimZ, precision: 3);
|
|
|
|
|
|
|
|
|
|
MatchRules.ComputeSpectatorBehavior(clearedSpec, session.State, out _, out _, out float cAimX, out float cAimZ, out bool cFire);
|
|
|
|
|
Assert.False(cFire);
|
|
|
|
|
Assert.Equal(clearedInitialKnownX, cAimX, precision: 3);
|
|
|
|
|
Assert.Equal(clearedInitialKnownZ, cAimZ, precision: 3);
|
|
|
|
|
}
|
2026-12-04 16:48:10 +01:00
|
|
|
|
|
|
|
|
[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}");
|
|
|
|
|
}
|
2026-12-04 15:14:00 +01:00
|
|
|
}
|
|
|
|
|
}
|