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
|
|
@ -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