Cut 7 Soul Pass #1 fixes: terrain beam occlusion, WhileAlive fan-out check, PVS scrub
This commit is contained in:
parent
6447155efb
commit
248bb1f053
4 changed files with 383 additions and 39 deletions
|
|
@ -231,27 +231,28 @@ namespace RustToDust.Core
|
|||
visitedSet[node] = (byte)depth;
|
||||
}
|
||||
|
||||
int maxBranchMultiplier = 1;
|
||||
int maxChildSubSpawns = 0;
|
||||
|
||||
if (node.WhileAlive is { } wa)
|
||||
{
|
||||
if (!float.IsFinite(wa.Interval) || wa.Interval <= 0f ||
|
||||
!float.IsFinite(wa.TriggerScanRadius) ||
|
||||
!float.IsFinite(wa.TargetConeDeg) ||
|
||||
!float.IsFinite(wa.RadialDamage) ||
|
||||
!float.IsFinite(wa.RadialHeat) ||
|
||||
!float.IsFinite(wa.RadialRadius))
|
||||
!float.IsFinite(wa.TriggerScanRadius) || wa.TriggerScanRadius < 0f ||
|
||||
!float.IsFinite(wa.TargetConeDeg) || wa.TargetConeDeg < 0f ||
|
||||
!float.IsFinite(wa.RadialDamage) || wa.RadialDamage < 0f ||
|
||||
!float.IsFinite(wa.RadialHeat) || wa.RadialHeat < 0f ||
|
||||
!float.IsFinite(wa.RadialRadius) || wa.RadialRadius < 0f ||
|
||||
wa.MaxPulses < 0)
|
||||
{
|
||||
throw new InvalidOperationException("OrdnanceWhileAliveDef contains invalid non-finite or non-positive values.");
|
||||
throw new InvalidOperationException("OrdnanceWhileAliveDef contains invalid non-finite or negative values.");
|
||||
}
|
||||
|
||||
if (wa.ChildNode is not null)
|
||||
{
|
||||
int childBudget = ValidateNode(wa.ChildNode, depth + 1, activeStack, visited, visitedSet);
|
||||
if (wa.ChildNode.Motion != OrdnanceMotion.HitscanBeam)
|
||||
if (childBudget > 0)
|
||||
{
|
||||
int pulses = Math.Clamp(wa.MaxPulses, 1, 32);
|
||||
maxBranchMultiplier = Math.Max(maxBranchMultiplier, pulses * childBudget);
|
||||
maxChildSubSpawns = Math.Max(maxChildSubSpawns, pulses * childBudget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -261,9 +262,11 @@ namespace RustToDust.Core
|
|||
for (int i = 0; i < node.Triggers.Length; i++)
|
||||
{
|
||||
var tr = node.Triggers[i];
|
||||
if (!float.IsFinite(tr.Threshold) || !float.IsFinite(tr.MinAge) || !float.IsFinite(tr.SplitConeDeg))
|
||||
if (!float.IsFinite(tr.Threshold) || tr.Threshold < 0f ||
|
||||
!float.IsFinite(tr.MinAge) || tr.MinAge < 0f ||
|
||||
!float.IsFinite(tr.SplitConeDeg) || tr.SplitConeDeg < 0f)
|
||||
{
|
||||
throw new InvalidOperationException("OrdnanceTriggerRule contains non-finite values.");
|
||||
throw new InvalidOperationException("OrdnanceTriggerRule contains non-finite or negative values.");
|
||||
}
|
||||
|
||||
if (tr.Action == OrdnanceTriggerAction.Split)
|
||||
|
|
@ -278,7 +281,7 @@ namespace RustToDust.Core
|
|||
throw new InvalidOperationException("Split trigger requires non-null ChildNode.");
|
||||
}
|
||||
int childBudget = ValidateNode(tr.ChildNode, depth + 1, activeStack, visited, visitedSet);
|
||||
maxBranchMultiplier = Math.Max(maxBranchMultiplier, tr.SplitCount * childBudget);
|
||||
maxChildSubSpawns = Math.Max(maxChildSubSpawns, tr.SplitCount * Math.Max(1, childBudget));
|
||||
}
|
||||
else if (tr.Action == OrdnanceTriggerAction.Transition)
|
||||
{
|
||||
|
|
@ -287,13 +290,15 @@ namespace RustToDust.Core
|
|||
throw new InvalidOperationException("Transition trigger requires non-null ChildNode.");
|
||||
}
|
||||
int childBudget = ValidateNode(tr.ChildNode, depth + 1, activeStack, visited, visitedSet);
|
||||
maxBranchMultiplier = Math.Max(maxBranchMultiplier, childBudget);
|
||||
maxChildSubSpawns = Math.Max(maxChildSubSpawns, Math.Max(1, childBudget));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
activeStack.Remove(node);
|
||||
return maxBranchMultiplier;
|
||||
return node.Motion == OrdnanceMotion.HitscanBeam
|
||||
? maxChildSubSpawns
|
||||
: Math.Max(1, maxChildSubSpawns);
|
||||
}
|
||||
|
||||
private static void ValidateFiniteFields(OrdnanceNodeDef n)
|
||||
|
|
@ -308,7 +313,7 @@ namespace RustToDust.Core
|
|||
float.IsFinite(n.TurnRateRad) && n.TurnRateRad >= 0f &&
|
||||
float.IsFinite(n.SeekerConeDeg) &&
|
||||
float.IsFinite(n.SeekerRange) && n.SeekerRange >= 0f &&
|
||||
float.IsFinite(n.LoiterAltitudeAgl) &&
|
||||
float.IsFinite(n.LoiterAltitudeAgl) && n.LoiterAltitudeAgl >= 0f &&
|
||||
float.IsFinite(n.LoiterOrbitRadius) && n.LoiterOrbitRadius >= 0f &&
|
||||
float.IsFinite(n.LoiterOrbitSpeedRad) &&
|
||||
float.IsFinite(n.ArmDelay) && n.ArmDelay >= 0f &&
|
||||
|
|
@ -323,7 +328,7 @@ namespace RustToDust.Core
|
|||
float.IsFinite(n.CraterRadius) && n.CraterRadius >= 0f &&
|
||||
float.IsFinite(n.CraterDepth) && n.CraterDepth >= 0f &&
|
||||
float.IsFinite(n.ScorchRadius) && n.ScorchRadius >= 0f &&
|
||||
float.IsFinite(n.PenetrationDamageDecay) &&
|
||||
float.IsFinite(n.PenetrationDamageDecay) && n.PenetrationDamageDecay >= 0f &&
|
||||
float.IsFinite(n.TracerTtl) && n.TracerTtl >= 0f;
|
||||
|
||||
if (!valid)
|
||||
|
|
|
|||
|
|
@ -841,10 +841,34 @@ namespace RustToDust.Net
|
|||
if (isTerminal)
|
||||
{
|
||||
bool wasSent = peer.SentOrdnanceIds.Remove(ord.OrdnanceId);
|
||||
if (wasSent || shooterInPvs || pointInPvs)
|
||||
if (pointInPvs)
|
||||
{
|
||||
filtered.Add(ord);
|
||||
}
|
||||
else if (wasSent)
|
||||
{
|
||||
filtered.Add(new OrdnanceNodeEvent
|
||||
{
|
||||
OrdnanceId = ord.OrdnanceId,
|
||||
ParentOrdnanceId = ord.ParentOrdnanceId,
|
||||
Kind = (byte)OrdnanceEventKind.Expired,
|
||||
IsSpectatorShooter = ord.IsSpectatorShooter,
|
||||
ShooterId = shooterInPvs ? ord.ShooterId : -1,
|
||||
WeaponKey = ord.WeaponKey,
|
||||
NodeDefIndex = ord.NodeDefIndex,
|
||||
PosX = 0f,
|
||||
PosY = 0f,
|
||||
PosZ = 0f,
|
||||
VelX = 0f,
|
||||
VelY = 0f,
|
||||
VelZ = 0f,
|
||||
TargetEntityId = -1,
|
||||
TargetIsSpectator = false,
|
||||
SimTime = ord.SimTime,
|
||||
VisualShape = ord.VisualShape,
|
||||
ColorRgba = ord.ColorRgba
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (shooterInPvs || pointInPvs)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1268,6 +1268,8 @@ namespace RustToDust.Ymir
|
|||
float currDmgScale = damageScale;
|
||||
|
||||
bool hitAny = false;
|
||||
bool hitTerrain = false;
|
||||
float terrainHitX = 0f, terrainHitY = 0f, terrainHitZ = 0f;
|
||||
ulong hitStableId = 0;
|
||||
(float X, float Y, float Z) hitPoint = default;
|
||||
Vector3 hitNormal = -dir;
|
||||
|
|
@ -1278,13 +1280,60 @@ namespace RustToDust.Ymir
|
|||
(castOrigin.X, castOrigin.Y, castOrigin.Z),
|
||||
(dir.X * remainingRange, dir.Y * remainingRange, dir.Z * remainingRange));
|
||||
|
||||
// Also check interceptable airborne ordnance along [castOrigin .. castOrigin + dir * maxDist]
|
||||
float rayDist = rayHit.Hit
|
||||
float boxSegDist = rayHit.Hit
|
||||
? Vector3.Distance(castOrigin, new Vector3(rayHit.Point.X, rayHit.Point.Y, rayHit.Point.Z))
|
||||
: remainingRange;
|
||||
if (TryHitInterceptableOrdnance(castOrigin, dir, rayDist, shooterStableId, out int ordSlot, out float ordDist, out Vector3 ordHitPt))
|
||||
|
||||
bool isSelfOrPenetrated = rayHit.Hit &&
|
||||
(rayHit.StableId == shooterStableId || (lastPenetratedId != 0 && rayHit.StableId == lastPenetratedId));
|
||||
if (isSelfOrPenetrated)
|
||||
{
|
||||
if (ordDist < rayDist)
|
||||
float skip = MathF.Max(0.15f, boxSegDist + 0.08f);
|
||||
float skipCheckDist = MathF.Min(remainingRange, skip);
|
||||
if (_sink.State.Terrain.Raycast(
|
||||
castOrigin.X, castOrigin.Y, castOrigin.Z,
|
||||
dir.X, dir.Y, dir.Z,
|
||||
skipCheckDist,
|
||||
out float sTx, out float sTy, out float sTz, out float sTDist))
|
||||
{
|
||||
if (!TryHitInterceptableOrdnance(castOrigin, dir, sTDist, shooterStableId, out int ordSlotPre, out float ordDistPre, out Vector3 ordHitPre) ||
|
||||
ordDistPre >= sTDist)
|
||||
{
|
||||
hitTerrain = true;
|
||||
terrainHitX = sTx;
|
||||
terrainHitY = sTy;
|
||||
terrainHitZ = sTz;
|
||||
hitAny = false;
|
||||
break;
|
||||
}
|
||||
ref var targetOrdPre = ref _pool[ordSlotPre];
|
||||
targetOrdPre.Hp -= def.DirectDamage * currDmgScale;
|
||||
if (targetOrdPre.Hp <= 0f)
|
||||
{
|
||||
EmitNetEvent(in targetOrdPre, OrdnanceEventKind.Intercepted);
|
||||
FreeSlot(ordSlotPre);
|
||||
}
|
||||
_sink.EmitNonActorHit(HitTargetKind.StaticCover, -1, ordHitPre, -dir, shooterPos, def.VisualClass, weaponId, isAirburst: true, isSpectatorShooter, shooterEntityId);
|
||||
_sink.EmitTracer(muzzle, ordHitPre, def.ColorRgba, def.TracerTtl, def.VisualClass, weaponId, isSpectatorShooter, shooterEntityId);
|
||||
return;
|
||||
}
|
||||
|
||||
castOrigin += dir * skip;
|
||||
remainingRange = MathF.Max(0f, remainingRange - skip);
|
||||
continue;
|
||||
}
|
||||
|
||||
bool hitTerrainSeg = _sink.State.Terrain.Raycast(
|
||||
castOrigin.X, castOrigin.Y, castOrigin.Z,
|
||||
dir.X, dir.Y, dir.Z,
|
||||
boxSegDist,
|
||||
out float stx, out float sty, out float stz, out float terrainSegDist);
|
||||
float solidSegDist = (hitTerrainSeg && terrainSegDist <= boxSegDist) ? terrainSegDist : boxSegDist;
|
||||
|
||||
// Also check interceptable airborne ordnance strictly before any solid terrain/Box3D hit
|
||||
if (TryHitInterceptableOrdnance(castOrigin, dir, solidSegDist, shooterStableId, out int ordSlot, out float ordDist, out Vector3 ordHitPt))
|
||||
{
|
||||
if (ordDist < solidSegDist)
|
||||
{
|
||||
ref var targetOrd = ref _pool[ordSlot];
|
||||
targetOrd.Hp -= def.DirectDamage * currDmgScale;
|
||||
|
|
@ -1309,20 +1358,22 @@ namespace RustToDust.Ymir
|
|||
}
|
||||
}
|
||||
|
||||
if (hitTerrainSeg && (!rayHit.Hit || terrainSegDist <= boxSegDist))
|
||||
{
|
||||
hitTerrain = true;
|
||||
terrainHitX = stx;
|
||||
terrainHitY = sty;
|
||||
terrainHitZ = stz;
|
||||
hitAny = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!rayHit.Hit)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var ptVec = new Vector3(rayHit.Point.X, rayHit.Point.Y, rayHit.Point.Z);
|
||||
if (rayHit.StableId == shooterStableId || (lastPenetratedId != 0 && rayHit.StableId == lastPenetratedId))
|
||||
{
|
||||
float skip = MathF.Max(0.15f, Vector3.Distance(castOrigin, ptVec) + 0.08f);
|
||||
castOrigin += dir * skip;
|
||||
remainingRange = MathF.Max(0f, remainingRange - skip);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_sink.TryResolveActor(rayHit.StableId, out _, out _) && penetrations < def.MaxPenetrations)
|
||||
{
|
||||
_sink.ApplyDirectHit(
|
||||
|
|
@ -1359,19 +1410,12 @@ namespace RustToDust.Ymir
|
|||
break;
|
||||
}
|
||||
|
||||
float boxDist = hitAny
|
||||
? Vector3.Distance(muzzle, new Vector3(hitPoint.X, hitPoint.Y, hitPoint.Z))
|
||||
: range;
|
||||
|
||||
bool hitTerrain = _sink.State.Terrain.Raycast(
|
||||
muzzle.X, muzzle.Y, muzzle.Z,
|
||||
dir.X, dir.Y, dir.Z,
|
||||
boxDist,
|
||||
out float tx, out float ty, out float tz, out float terrainDist);
|
||||
|
||||
Vector3 endPt;
|
||||
if (hitTerrain && terrainDist < boxDist)
|
||||
if (hitTerrain)
|
||||
{
|
||||
float tx = terrainHitX;
|
||||
float ty = terrainHitY;
|
||||
float tz = terrainHitZ;
|
||||
endPt = new Vector3(tx, ty, tz);
|
||||
bool allowCrater = !def.CraterFirstBurstOnly || burstIndex == 0;
|
||||
if (allowCrater && (def.CraterRadius > 0f || def.ScorchRadius > 0f))
|
||||
|
|
|
|||
|
|
@ -656,5 +656,276 @@ namespace RustToDust.Tests
|
|||
|
||||
Assert.True(clientReceivedOrdnanceEvent, "Expected remote client in PVS to receive [Union(13)] OrdnanceNodeEvent");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PiercingHitscanBeam_BlockedByDesertTerrainRidge_ZeroOccludedDamage()
|
||||
{
|
||||
var piercingArchs = new[]
|
||||
{
|
||||
WeaponArchetypeKind.RefractingPrismLance,
|
||||
WeaponArchetypeKind.RailPlasmaBeam
|
||||
};
|
||||
|
||||
foreach (var arch in piercingArchs)
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert, slot0Human: true, skipInitialDrop: true);
|
||||
IsolateContenders(session, 0, 1);
|
||||
|
||||
TerrainBrush tallMesa = default;
|
||||
bool foundMesa = false;
|
||||
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)
|
||||
{
|
||||
tallMesa = b;
|
||||
foundMesa = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.True(foundMesa, "Expected tall >= 22m Mesa in Desert terrain");
|
||||
|
||||
float shooterX = tallMesa.X - tallMesa.RadiusX - 16f;
|
||||
float targetX = tallMesa.X + tallMesa.RadiusX + 16f;
|
||||
session.SetContenderPose(0, shooterX, tallMesa.Z, yaw: MathF.PI * 0.5f);
|
||||
session.SetContenderPose(1, targetX, tallMesa.Z, yaw: -MathF.PI * 0.5f);
|
||||
|
||||
session.State.SpawnChassisDrop(shooterX, tallMesa.Z, Catalog.Anvil);
|
||||
Assert.True(session.TrySwapNearbyChassis(0));
|
||||
session.SetContenderPose(0, shooterX, tallMesa.Z, yaw: MathF.PI * 0.5f);
|
||||
|
||||
var spec = ProceduralWeaponGenerator.CreateDreamWeapon(arch, seed: 0xBEEF01UL, tier: 3);
|
||||
Assert.True(spec.RootNode.Motion == OrdnanceMotion.HitscanBeam);
|
||||
Assert.True(spec.RootNode.MaxPenetrations >= 1, $"Expected piercing beam on {arch}");
|
||||
|
||||
var shooter = session.State.Contenders[0];
|
||||
var target = session.State.Contenders[1];
|
||||
shooter.Grid.Mounted.RemoveAll(m => m.Spec.Kind == HardpointKind.Weapon);
|
||||
Assert.True(shooter.Grid.TryMount(spec.Module, "hp.weapon.siege_l"));
|
||||
|
||||
// Force beam range to reach past targetX if unoccluded
|
||||
float distToTarget = MathF.Abs(targetX - shooterX);
|
||||
Assert.True(spec.RootNode.Range > distToTarget,
|
||||
$"Expected beam range {spec.RootNode.Range} > target distance {distToTarget}");
|
||||
|
||||
float targetCoreBefore = target.Grid.CoreHp;
|
||||
float targetArmorBefore = target.Grid.TotalArmorRatio();
|
||||
|
||||
var stepEvents = new List<ISimEvent>();
|
||||
session.DrainStepEvents(stepEvents);
|
||||
stepEvents.Clear();
|
||||
|
||||
// Aim directly at target's center on the far side of the mountain ridge
|
||||
for (int t = 0; t < 4; t++)
|
||||
{
|
||||
session.SetHumanInput(0, new PlayerInput(
|
||||
Throttle: 0f,
|
||||
Steer: 0f,
|
||||
AimWorldX: target.X,
|
||||
AimWorldZ: target.Z,
|
||||
Fire: t == 0,
|
||||
InteractPickup: false,
|
||||
Brake: true));
|
||||
session.Step();
|
||||
}
|
||||
|
||||
session.DrainStepEvents(stepEvents);
|
||||
var shots = stepEvents.OfType<ShotFiredEvent>()
|
||||
.Where(s => !s.IsSpectatorShooter && s.ShooterId == 0)
|
||||
.ToList();
|
||||
Assert.NotEmpty(shots);
|
||||
|
||||
// Beam must terminate on the near face of the mesa, strictly before targetX
|
||||
foreach (var shot in shots)
|
||||
{
|
||||
Assert.True(shot.EndX < targetX - 5f,
|
||||
$"Expected {arch} beam to terminate on Desert ridge before targetX={targetX:F1}, got EndX={shot.EndX:F1}");
|
||||
}
|
||||
|
||||
// Occluded target must take ZERO armor & core damage
|
||||
Assert.Equal(targetCoreBefore, target.Grid.CoreHp);
|
||||
Assert.Equal(targetArmorBefore, target.Grid.TotalArmorRatio());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validator_RejectsWhileAliveHitscanSplitFanOutBypass_AndNegativeScalars()
|
||||
{
|
||||
// WhileAlive pulsing a HitscanBeam whose Impact triggers Split(12) -> 9 * 12 = 108 > MaxShotSubSpawnBudget (16)
|
||||
var bomblet = new OrdnanceNodeDef
|
||||
{
|
||||
Motion = OrdnanceMotion.Ballistic,
|
||||
InitialSpeed = 24f,
|
||||
DirectDamage = 15f,
|
||||
MaxLifetime = 3f
|
||||
};
|
||||
var pulsedBeamWithSplit = new OrdnanceNodeDef
|
||||
{
|
||||
Motion = OrdnanceMotion.HitscanBeam,
|
||||
Range = 110f,
|
||||
DirectDamage = 12f,
|
||||
Triggers = new[]
|
||||
{
|
||||
new OrdnanceTriggerRule
|
||||
{
|
||||
Kind = OrdnanceTriggerKind.Impact,
|
||||
Action = OrdnanceTriggerAction.Split,
|
||||
ChildNode = bomblet,
|
||||
SplitCount = 12,
|
||||
SplitConeDeg = 45f
|
||||
}
|
||||
}
|
||||
};
|
||||
var droneFanOutBypass = new OrdnanceNodeDef
|
||||
{
|
||||
Motion = OrdnanceMotion.LoiterOrbit,
|
||||
LoiterAltitudeAgl = 35f,
|
||||
LoiterOrbitRadius = 15f,
|
||||
WhileAlive = new OrdnanceWhileAliveDef
|
||||
{
|
||||
Interval = 0.45f,
|
||||
MaxPulses = 9,
|
||||
TriggerScanRadius = 95f,
|
||||
ChildNode = pulsedBeamWithSplit
|
||||
}
|
||||
};
|
||||
Assert.Throws<InvalidOperationException>(() => OrdnanceGraphValidator.ValidateAndFlatten(droneFanOutBypass));
|
||||
|
||||
// Negative Trigger Threshold
|
||||
Assert.Throws<InvalidOperationException>(() => OrdnanceGraphValidator.ValidateAndFlatten(new OrdnanceNodeDef
|
||||
{
|
||||
Motion = OrdnanceMotion.Ballistic,
|
||||
Triggers = new[] { new OrdnanceTriggerRule { Kind = OrdnanceTriggerKind.Timeout, Threshold = -0.5f, Action = OrdnanceTriggerAction.Detonate } }
|
||||
}));
|
||||
|
||||
// Negative Trigger MinAge
|
||||
Assert.Throws<InvalidOperationException>(() => OrdnanceGraphValidator.ValidateAndFlatten(new OrdnanceNodeDef
|
||||
{
|
||||
Motion = OrdnanceMotion.Ballistic,
|
||||
Triggers = new[] { new OrdnanceTriggerRule { Kind = OrdnanceTriggerKind.Apex, MinAge = -0.1f, Action = OrdnanceTriggerAction.Detonate } }
|
||||
}));
|
||||
|
||||
// Negative LoiterAltitudeAgl
|
||||
Assert.Throws<InvalidOperationException>(() => OrdnanceGraphValidator.ValidateAndFlatten(new OrdnanceNodeDef
|
||||
{
|
||||
Motion = OrdnanceMotion.LoiterOrbit,
|
||||
LoiterAltitudeAgl = -5f
|
||||
}));
|
||||
|
||||
// Negative WhileAlive RadialDamage
|
||||
Assert.Throws<InvalidOperationException>(() => OrdnanceGraphValidator.ValidateAndFlatten(new OrdnanceNodeDef
|
||||
{
|
||||
Motion = OrdnanceMotion.StationaryMine,
|
||||
WhileAlive = new OrdnanceWhileAliveDef { Interval = 0.5f, RadialDamage = -10f, RadialRadius = 4f }
|
||||
}));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PvsTerminalOrdnanceEvent_OutsidePvs_ScrubsFinalCoordinates()
|
||||
{
|
||||
using var host = new ServerMatchHost(IPAddress.Loopback, 0, seed: 42, ArenaMapKind.Desert, maxHumans: 12, autoRestartSec: 0);
|
||||
var serverEp = new IPEndPoint(IPAddress.Loopback, host.BoundPort);
|
||||
using var client = new RemoteArenaSession(serverEp, "PvsObserver");
|
||||
|
||||
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
var deadline = DateTimeOffset.UtcNow.AddSeconds(3);
|
||||
while (DateTimeOffset.UtcNow < deadline && !client.IsJoined)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
client.PumpNetwork();
|
||||
System.Threading.Thread.Sleep(2);
|
||||
}
|
||||
Assert.True(client.IsJoined);
|
||||
|
||||
TerrainBrush tallMesa = default;
|
||||
bool foundMesa = false;
|
||||
for (int i = 0; i < host.Session.State.Terrain.Brushes.Count; i++)
|
||||
{
|
||||
var b = host.Session.State.Terrain.Brushes[i];
|
||||
if (b.Kind == TerrainBrushKind.Mesa && b.HeightDelta >= 22f)
|
||||
{
|
||||
tallMesa = b;
|
||||
foundMesa = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.True(foundMesa);
|
||||
|
||||
int obsSlot = client.LocalContenderId;
|
||||
int shooterSlot = (obsSlot + 1) % MatchState.ContenderCount;
|
||||
|
||||
// Place observer and shooter together on the near side of the tall mesa with clear LOS
|
||||
float nearX = tallMesa.X - tallMesa.RadiusX - 30f;
|
||||
float farX = tallMesa.X + tallMesa.RadiusX + 35f;
|
||||
host.Session.SetContenderPose(obsSlot, nearX - 10f, tallMesa.Z, yaw: MathF.PI * 0.5f);
|
||||
host.Session.SetContenderPose(shooterSlot, nearX, tallMesa.Z, yaw: MathF.PI * 0.5f);
|
||||
host.Session.State.SpawnChassisDrop(nearX, tallMesa.Z, Catalog.Anvil);
|
||||
Assert.True(host.Session.TrySwapNearbyChassis(shooterSlot));
|
||||
host.Session.SetContenderPose(shooterSlot, nearX, tallMesa.Z, yaw: MathF.PI * 0.5f);
|
||||
host.Session.SetHumanSlot(shooterSlot, true, "Shooter");
|
||||
|
||||
var rocketSpec = ProceduralWeaponGenerator.CreateDreamWeapon(WeaponArchetypeKind.DumbRocketPod, seed: 0x5511UL, tier: 1);
|
||||
var shooter = host.Session.State.Contenders[shooterSlot];
|
||||
shooter.Grid.Mounted.RemoveAll(m => m.Spec.Kind == HardpointKind.Weapon);
|
||||
Assert.True(shooter.Grid.TryMount(rocketSpec.Module, "hp.weapon.siege_l"));
|
||||
|
||||
var clientEvents = new List<ISimEvent>();
|
||||
var receivedSpawnedIds = new HashSet<int>();
|
||||
OrdnanceNodeEvent? scrubbedTerminal = null;
|
||||
bool movedObserverBehindMesa = false;
|
||||
|
||||
for (int t = 0; t < 240 && scrubbedTerminal is null; t++)
|
||||
{
|
||||
nowMs += 17;
|
||||
host.Session.SetHumanInput(shooterSlot, new PlayerInput(
|
||||
Throttle: 0f,
|
||||
Steer: 0f,
|
||||
AimWorldX: nearX - 80f, // fire away from the mesa so projectile stays on near side while observer moves behind mesa
|
||||
AimWorldZ: tallMesa.Z + 18f,
|
||||
Fire: receivedSpawnedIds.Count == 0,
|
||||
InteractPickup: false,
|
||||
Brake: true));
|
||||
|
||||
if (receivedSpawnedIds.Count > 0 && !movedObserverBehindMesa)
|
||||
{
|
||||
// Move observer behind the >=22m tall mesa so both shooter & rocket exit observer PVS before detonation
|
||||
host.Session.SetContenderPose(obsSlot, farX, tallMesa.Z, yaw: MathF.PI * 0.5f);
|
||||
movedObserverBehindMesa = true;
|
||||
}
|
||||
|
||||
host.StepOnce(nowMs);
|
||||
client.PumpNetwork();
|
||||
client.BeginRenderFrame(1f / 60f, 1f);
|
||||
clientEvents.Clear();
|
||||
client.DrainSimEvents(clientEvents);
|
||||
|
||||
foreach (var ev in clientEvents.OfType<OrdnanceNodeEvent>())
|
||||
{
|
||||
if (ev.Kind == (byte)OrdnanceEventKind.Spawned)
|
||||
{
|
||||
receivedSpawnedIds.Add(ev.OrdnanceId);
|
||||
}
|
||||
else if (ev.Kind is 3 or 4 or 5 && receivedSpawnedIds.Contains(ev.OrdnanceId))
|
||||
{
|
||||
// If terminal happened outside observer PVS, it must arrive scrubbed as Expired at (0,0,0)
|
||||
if (ev.Kind == (byte)OrdnanceEventKind.Expired && ev.PosX == 0f && ev.PosY == 0f && ev.PosZ == 0f)
|
||||
{
|
||||
scrubbedTerminal = ev;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
System.Threading.Thread.Sleep(2);
|
||||
}
|
||||
|
||||
Assert.NotEmpty(receivedSpawnedIds);
|
||||
Assert.NotNull(scrubbedTerminal);
|
||||
Assert.Equal((byte)OrdnanceEventKind.Expired, scrubbedTerminal!.Kind);
|
||||
Assert.Equal(0f, scrubbedTerminal.PosX);
|
||||
Assert.Equal(0f, scrubbedTerminal.PosY);
|
||||
Assert.Equal(0f, scrubbedTerminal.PosZ);
|
||||
Assert.Equal(-1, scrubbedTerminal.TargetEntityId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue