diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index 6d3c0491c..bc9bce8a2 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -1282,6 +1282,13 @@ public class ActionGameManager : MonoBehaviour } } + private static string ResultLabel(ShotResult result) => result switch + { + ShotResult.Hit => "HIT", + ShotResult.Burst => "BURST", + _ => "MISS" + }; + private void UpdateFireControlDebug(Entity target) { if (DebugInfoText == null) return; @@ -1310,7 +1317,7 @@ public class ActionGameManager : MonoBehaviour var shot = CurrentEntity.Zone.PendingShots[i]; if (shot.Source != CurrentEntity || shot.Weapon != selectedItem) continue; if (shot.Committed) - pendingLine = $"shot {shot.ShotId}: committed {(shot.Outcome.Hit ? "HIT" : "MISS")}"; + pendingLine = $"shot {shot.ShotId}: committed {ResultLabel(shot.Outcome.Result)}"; else { var pDeviation = FireControl.DeviationProbability(shot, CurrentEntity.Zone.Time, out var deviation); @@ -1324,7 +1331,7 @@ public class ActionGameManager : MonoBehaviour } var lastLine = _debugLastShots.TryGetValue(selectedItem, out var lastShot) - ? $"last {lastShot.ShotId}: {(lastShot.Hit ? "HIT" : "MISS")} cell {lastShot.Cell.x},{lastShot.Cell.y}" + ? $"last {lastShot.ShotId}: {ResultLabel(lastShot.Result)} cell {lastShot.Cell.x},{lastShot.Cell.y}" : "last: none"; var gates = target == null ? "target: none" diff --git a/Assets/Scripts/ServerShared/FireControl.cs b/Assets/Scripts/ServerShared/FireControl.cs index f3fcf6b8c..3d08172d8 100644 --- a/Assets/Scripts/ServerShared/FireControl.cs +++ b/Assets/Scripts/ServerShared/FireControl.cs @@ -57,6 +57,26 @@ public static class FireControl return dot(MountDirection(weapon), planarTarget) >= cos(radians(arc / 2f)); } + // Operator ruling 2026-09-30: a shot with nothing to bear on flies along where its shooter is aiming + // (Entity.LookDirection -- the player's mouse or a turret's tracking), restricted by the mount's arc. The + // arc is InArc's own cone: an aim inside it is used as is, one outside it is turned to the nearest edge of + // the same cone. There is no second bearing test here; the edge is where InArc stops passing. A shooter + // with no aim set (LookDirection zero) aims down the mount, the same fallback InArc takes for a zero bearing. + // The simulation had no aim clamp before this: the Unity barrel's ArticulationPoint clamps the picture, + // and a target outside the arc merely priced the shot at zero. + public static float2 AimDirection(EquippedItem item, Entity shooter) + { + var mount = MountDirection(item).xz; + var look = shooter.LookDirection.xz; + if (lengthsq(look) < 1e-6f) return mount; + look = normalize(look); + if (InArc(item, float3(look.x, 0, look.y))) return look; + + var half = radians(ArcFor(item) / 2f); + var turn = mount.x * look.y - mount.y * look.x >= 0f ? half : -half; + return float2(mount.x * cos(turn) - mount.y * sin(turn), mount.x * sin(turn) + mount.y * cos(turn)); + } + // Cut 2, R5: whether `observer` has resolved `item` (which must belong to some entity in the zone) well // enough to aim at it. Derived fresh from EntityInfoGathered on every call -- nothing caches a reveal // result, so decay drops it the moment info falls back below tier, with no clearing loop anywhere. @@ -152,15 +172,23 @@ public static class FireControl // freezes (R10), gated exactly as HitProbability gates. Nothing about the target's facing or silhouette // enters here; that is Silhouette's and PSpread's job, priced fresh by HitProbability below and again, // live, by Commit at the commit tick. 0 the moment any gate closes. - private static float PFire(Weapon weapon, Entity source, Entity target) => PFire(weapon, source, target, out _); + private static float PFire(Weapon weapon, Entity source, Entity target) => PFire(weapon, source, target, out _, out _); // The `out range` overload is HitProbability's own gate call -- one computation of `target.Position - // source.Position`, not two. HitProbability used to recompute its own copy for PSpread, which is exactly // the kind of split authority Cut 3 named as the risk (two places computing the same vector, free to // drift or to have their subtraction order flipped in only one of them). - private static float PFire(Weapon weapon, Entity source, Entity target, out float range) + private static float PFire(Weapon weapon, Entity source, Entity target, out float range) => + PFire(weapon, source, target, out range, out _); + + // `bears` is the one answer to "is this target one the weapon can fire at": in range, visible, locked (for a + // LockWeapon) and in arc. PFire prices a shot at zero when it is false; Fire reads it to decide that a + // fused round has no target at all (operator ruling 2026-09-30: an invalid target counts as no lock). + // Inspect recomputes the four gates one by one, to show the HUD which is closed; it decides nothing. + private static float PFire(Weapon weapon, Entity source, Entity target, out float range, out bool bears) { range = 0f; + bears = false; if (target == null) return 0f; // F8 correction (Soul's fix batch, 2026-09-24): range is computed for any non-null target, before any @@ -174,6 +202,7 @@ public static class FireControl if (range < weapon.MinRange || range > weapon.Range) return 0f; if (weapon is LockWeapon lockWeapon && !lockWeapon.IsLocked) return 0f; if (!InArc(weapon.Item, toTarget)) return 0f; + bears = true; var settings = source.ItemManager.GameplaySettings; var info = source.EntityInfoGathered.TryGetValue(target, out var gathered) ? gathered : 0f; @@ -364,20 +393,7 @@ public static class FireControl // F8 (Soul's fix batch, 2026-09-24): the `out range` overload is the one range HitProbability now // reads too -- Fire used to recompute its own second copy of `target.Position - source.Position` for // fireRange, right beside the copy PFire's gate already computed. - var pFire = PFire(weapon, source, target, out var fireRange); - var travelDirection = target != null ? TravelDirection(weapon, source, target) : float2(0, 1); - - var targetVelocity = float3.zero; - var targetPosition = source.Position; - var flightTime = 0f; - if (target != null) - { - targetVelocity = float3(target.Velocity.x, 0, target.Velocity.y); - targetPosition = target.Position; - flightTime = weapon.Velocity > .01f ? fireRange / weapon.Velocity : 0f; - } - - var commitHorizon = source.ItemManager.GameplaySettings.CommitHorizon; + var pFire = PFire(weapon, source, target, out var fireRange, out var bears); // Cut 12.4(a) (Q12-6, "WeaponModifiers are labels, not behaviour"): a blast is a property of the // weapon's data fields alone, resolved and frozen here like every other payload field -- never decided @@ -388,14 +404,33 @@ public static class FireControl var weaponItemData = item.Data as WeaponItemData; var blastRadius = weaponItemData?.BlastRadius > 0f ? weaponItemData.BlastRadius.Value : 0f; var fuse = blastRadius > 0f ? weaponItemData.Fuse : null; - var burstPosition = blastRadius > 0f && target != null ? PredictedIntercept(weapon, source, target) : targetPosition; - // Operator ruling 2026-09-30 ("fused weapons without a lock explode at max range"): a fused shot with no - // target bursts where its own aim line ends -- the mount direction at the weapon's Range stat, the same - // stat PFire's range gate reads -- and flies there at the weapon's Velocity, like a targeted shot flies - // to its intercept. Only the burst point and flight time differ; Apply detonates it through Detonate. - if (fuse != null && target == null) + + // Operator rulings 2026-09-30: an invalid target counts as no lock -- a fused round whose selected + // target is out of range, out of arc, not visible or not locked (PFire's `bears`) is fired at nothing. + // A fused shot with no target bursts where its own aim line ends: the shooter's aim (AimDirection) at + // the weapon's Range stat, the same stat PFire's range gate reads, flown at the weapon's Velocity like + // a targeted shot flies to its intercept. The round carries no target from here on, so nothing at + // resolution asks whether one is still around. A shot without a fuse keeps its target as before. + var engaged = fuse != null && !bears ? null : target; + var origin = source.Position; + var travelDirection = engaged != null ? TravelDirection(weapon, source, engaged) : AimDirection(item, source); + + var targetVelocity = float3.zero; + var targetPosition = origin; + var flightTime = 0f; + if (engaged != null) { - burstPosition = source.Position + MountDirection(item) * weapon.Range; + targetVelocity = float3(engaged.Velocity.x, 0, engaged.Velocity.y); + targetPosition = engaged.Position; + flightTime = weapon.Velocity > .01f ? fireRange / weapon.Velocity : 0f; + } + + var commitHorizon = source.ItemManager.GameplaySettings.CommitHorizon; + + var burstPosition = blastRadius > 0f && engaged != null ? PredictedIntercept(weapon, source, engaged) : targetPosition; + if (fuse != null && engaged == null) + { + burstPosition = origin + float3(travelDirection.x, 0, travelDirection.y) * weapon.Range; flightTime = weapon.Velocity > .01f ? weapon.Range / weapon.Velocity : 0f; } @@ -403,7 +438,7 @@ public static class FireControl { ShotId = zone.NextShotId(), Source = source, - Target = target, + Target = engaged, Weapon = item, Aimed = source.ResolvedTargetItem, Damage = damageOverride ?? weapon.Damage, @@ -417,10 +452,14 @@ public static class FireControl Spread = weapon.Spread, FireRange = fireRange, FireTime = now, + FireOrigin = origin, FireTargetPosition = targetPosition, FireTargetVelocity = targetVelocity, ArrivalTime = now + flightTime, - CommitTime = now + max(0f, flightTime - commitHorizon), + // The commit horizon exists so the target's facing can be read late (Bearing timing). A round fired at + // nothing has no facing to read, so it commits at Fire: its burst point is decided from the poses of + // the moment it leaves, and a Contact round short of max range can arrive as early as it truly does. + CommitTime = fuse != null && engaged == null ? now : now + max(0f, flightTime - commitHorizon), BurstPosition = burstPosition, Fuse = fuse, BlastRadius = blastRadius, @@ -432,8 +471,11 @@ public static class FireControl } // Cut 3, R4: ages every shot in the zone, commits the ones that have reached their horizon and resolves - // the ones that have arrived. Called from Zone.Update after the entity loop. A shot whose source or target - // has left the zone resolves as a miss and is removed outright (0b table), whichever stage it is at. + // the ones that have arrived. Called from Zone.Update after the entity loop. A shot whose target has left + // the zone resolves as a miss and is removed outright (0b table), whichever stage it is at. A round outlives + // its shooter (operator ruling 2026-09-30): the shooter is only an identity a shot carries, never asked + // for at resolution, so a shooter that died or left the zone in flight changes nothing about the shot. + // Resolution reads the zone and the target; there is no credit or loot for a shooter to receive. public static void Step(Zone zone, float dt) { var shots = zone.PendingShots; @@ -444,16 +486,15 @@ public static class FireControl { var shot = shots[i]; - var sourceGone = !zone.Entities.Contains(shot.Source); var targetGone = shot.Target != null && !zone.Entities.Contains(shot.Target); - if (sourceGone || targetGone) + if (targetGone) { - // Cut 11 (Soul C4): a shot whose source or target has left the zone resolves as a miss whichever + // Cut 11 (Soul C4): a shot whose target has left the zone resolves as a miss whichever // stage it is at (0b table). The resolution is published as a fresh miss rather than by // rewriting shot.Outcome: a committed outcome is immutable (R4) and stays a true record of what // the commit decided, while ShotResolved reports what actually happened -- nothing, because the // target is gone. Republishing the committed outcome here used to put a hit marker on a corpse. - var miss = MakeOutcome(shot, false, false, false, int2.zero, float2.zero, 0f, now); + var miss = MakeOutcome(shot, ShotResult.Miss, false, false, int2.zero, float2.zero, 0f, now); if (!shot.Committed) zone.ShotCommitted.OnNext(miss); zone.ShotResolved.OnNext(miss); shots.RemoveAt(i); @@ -464,6 +505,9 @@ public static class FireControl { shot.Outcome = Commit(zone, shot, now); shot.Committed = true; + // A contact burst short of max range arrives when the round has flown that far, not at the frozen + // max-range time (CommitBurst). Never later than the frozen time. + if (shot.Outcome.Result == ShotResult.Burst) shot.ArrivalTime = min(shot.ArrivalTime, now + shot.Outcome.ArrivalIn); zone.ShotCommitted.OnNext(shot.Outcome); shots[i] = shot; } @@ -474,7 +518,7 @@ public static class FireControl // which model a shot uses, through its own switch on the frozen Fuse -- Step has no damage // branch left. A direct hit, a proximity burst and a contact or delayed blast all arrive here // the same way; only Apply decides what that means. - Apply(shot); + Apply(zone, shot); zone.ShotResolved.OnNext(shot.Outcome); shots.RemoveAt(i); } @@ -522,14 +566,18 @@ public static class FireControl if (p <= 0f) return 0f; var bearing = Bearing(shot.Target, shot.TravelDirection); - var hullData = shot.Source.ItemManager.GetData(shot.Target.Hull) as HullData; + var hullData = shot.Target.ItemManager.GetData(shot.Target.Hull) as HullData; sil = Silhouette(shot.Target, hullData, shot.Aimed, bearing, shot.Precision); - var settings = shot.Source.ItemManager.GameplaySettings; + var settings = shot.Target.ItemManager.GameplaySettings; return p * PSpread(shot.Spread, sil.Span, shot.FireRange, settings.SchematicCellSize) * sil.POnHull; } private static ShotOutcome Commit(Zone zone, PendingShot shot, float now) { + // A fused round with no target rolls nothing: it bursts. Where is decided here, at the commit, from the + // poses of this tick (R4); Apply performs it. + if (shot.Fuse != null && shot.Target == null) return CommitBurst(zone, shot, now); + // Cut 6b, 6.1 (Soul finding 6): a shot's dice belong to the shot, not to whatever else happened to // draw from the engine-wide shared generator first. A pure function of (zone identity, shot id) -- // the `| 1u` guards @@ -567,7 +615,7 @@ public static class FireControl bearing = Bearing(shot.Target, shot.TravelDirection); lateral = LateralDraw(sil, random.NextFloat()); - var hullData = shot.Source.ItemManager.GetData(shot.Target.Hull) as HullData; + var hullData = shot.Target.ItemManager.GetData(shot.Target.Hull) as HullData; var buffer = ArrayPool.Shared.Rent(hullData.Shape.Coordinates.Length); try { @@ -601,7 +649,70 @@ public static class FireControl } } - return MakeOutcome(shot, hit, shielded, shieldBroken, cell, bearing, lateral, now); + return MakeOutcome(shot, hit ? ShotResult.Hit : ShotResult.Miss, shielded, shieldBroken, cell, bearing, lateral, now); + } + + // Operator rulings 2026-09-30. A fused round with no target bursts at the max-range point Fire froze along + // the aim line, whatever its fuse -- except a Contact round, which bursts at the first hull that line crosses + // before that point (a Proximity or Delayed fuse does not trip on a hull with nothing locked). The point is + // read from this tick's poses and frozen into the outcome (R4, the same timing Commit reads facing at). + // Nothing is rolled or drawn, so determinism needs nothing beyond the frozen inputs. + private static ShotOutcome CommitBurst(Zone zone, PendingShot shot, float now) + { + var outcome = MakeOutcome(shot, ShotResult.Burst, false, false, int2.zero, float2.zero, 0f, now); + var reach = length(shot.BurstPosition.xz - shot.FireOrigin.xz); + var travelled = shot.Fuse == WeaponFuse.Contact ? ContactDistance(zone, shot, reach) : reach; + if (travelled < reach) + { + outcome.BurstPoint = shot.FireOrigin.xz + shot.TravelDirection * travelled; + // The round arrives once it has flown that far, which is sooner than the frozen max-range arrival. + outcome.ArrivalIn = max(0f, shot.FireTime + (shot.ArrivalTime - shot.FireTime) * travelled / reach - now); + } + else outcome.BurstPoint = shot.BurstPosition.xz; + return outcome; + } + + // The distance along a no-lock round's aim line to the first thing a contact fuse trips on, or `reach` (the + // max-range point) when it meets nothing first. The shooter's own hull is never a candidate. + // SEAM FOR THE MINING CAMPAIGN: mining chunks are not Entities and are not on this branch. When they land, + // whatever they are contributes its own entry distance to this minimum, and nothing else in the file changes. + private static float ContactDistance(Zone zone, PendingShot shot, float reach) + { + var nearest = reach; + foreach (var entity in zone.Entities) + { + if (entity == shot.Source) continue; + nearest = min(nearest, HullEntryDistance(entity, shot.FireOrigin.xz, shot.TravelDirection)); + } + return nearest; + } + + // World distance from `origin` along the unit planar `direction` to the first metal cell of `entity`'s hull, + // or +infinity when the line meets none ahead of it. Read through Lane's own cell admission (CellsOnLine), in + // the entity's schematic frame: the line's lateral offset is its own, and cells wholly behind the origin + // are skipped. An origin already inside the hull is a distance of zero. + private static float HullEntryDistance(Entity entity, float2 origin, float2 direction) + { + var hullData = entity.ItemManager.GetData(entity.Hull) as HullData; + var cellSize = entity.ItemManager.GameplaySettings.SchematicCellSize; + var start = entity.ToSchematicPoint(origin); + var bearing = Bearing(entity, direction); + var lateral = dot(start, Lateral(bearing)); + var along = dot(start, bearing); + + var buffer = ArrayPool.Shared.Rent(hullData.Shape.Coordinates.Length); + try + { + var count = CellsOnLine(hullData, bearing, lateral, buffer); + for (var i = 0; i < count; i++) + if (buffer[i].Exit > along) + return max(buffer[i].Entry - along, 0f) * cellSize; + return float.PositiveInfinity; + } + finally + { + ArrayPool.Shared.Return(buffer); + } } // R4: the commit is authoritative and immutable from here on -- this only performs what Commit already @@ -657,13 +768,13 @@ public static class FireControl // contact or delayed fuse detonates only on a committed hit, at a point 12.3's own Lane/Reach machinery // locates. This is a default, not a ruling: a blast shot's DamageSpread is not read, and P sits on the // centre lane (see the fuse-point comment on the Contact/Delayed branch below). - private static void Apply(PendingShot shot) + private static void Apply(Zone zone, PendingShot shot) { - // A fused shot with no target has nothing to hit or miss: whatever its fuse, it bursts at the point Fire - // froze (max range along the aim line). Detonate is still the one blast path. - if (shot.Fuse != null && shot.Target == null) + // A fused shot with no target has nothing to hit or miss: its committed outcome is a Burst, and it + // detonates at the point Commit decided (Burst outcome's BurstPoint). Detonate is still the one blast path. + if (shot.Outcome.Result == ShotResult.Burst) { - Detonate(shot.Source.Zone, shot.BurstPosition.xz, shot.BlastRadius, shot.Damage, shot.DamageType); + Detonate(zone, shot.Outcome.BurstPoint, shot.BlastRadius, shot.Damage, shot.DamageType); return; } @@ -675,7 +786,7 @@ public static class FireControl case WeaponFuse.Proximity: // Detonates at shot.BurstPosition.xz, which PredictedIntercept froze at Fire (today's airburst // rule, unchanged) -- no roll, and no gate on shot.Outcome.Hit. - Detonate(shot.Source.Zone, shot.BurstPosition.xz, shot.BlastRadius, shot.Damage, shot.DamageType); + Detonate(zone, shot.BurstPosition.xz, shot.BlastRadius, shot.Damage, shot.DamageType); return; case WeaponFuse.Contact: case WeaponFuse.Delayed: @@ -1042,7 +1153,7 @@ public static class FireControl return walked; } - private static ShotOutcome MakeOutcome(PendingShot shot, bool hit, bool shielded, bool shieldBroken, int2 cell, float2 bearing, float lateral, float now) + private static ShotOutcome MakeOutcome(PendingShot shot, ShotResult result, bool shielded, bool shieldBroken, int2 cell, float2 bearing, float lateral, float now) { return new ShotOutcome { @@ -1050,7 +1161,7 @@ public static class FireControl Source = shot.Source, Target = shot.Target, Weapon = shot.Weapon, - Hit = hit, + Result = result, Shielded = shielded, ShieldBroken = shieldBroken, Cell = cell, @@ -1381,24 +1492,10 @@ public static class FireControl return sil.A; // sil.Count == 0: no metal in the shadow at all -- unreachable while POnHull > 0 gated Commit's roll } - // Cut 12.2 (docs/fire-control-cut.md, "the rules every sub-cut reads"): exact slab traversal along the - // bearing at a fixed lateral offset s, replacing the old 0.5-step sampling march. Collects the occupied - // cells whose shadow interval contains s, each with its own entry/exit parameter along b, ordered by - // entry (ties broken by dot(cell, b), then cell index for full determinism), then walks forward while - // consecutive cells are contiguous (`next.entry <= current.exit + 1e-4`) -- the first gap ends the walk, - // the same rule Entity.cs's old march kept. A direct hit starts outside the hull (t -> -infinity), so the - // walk's first element is the impact cell. Only that first element is read in 12.2; the rest is 12.3's - // armour-first absorption march. Writes into the caller-supplied pooled buffer and returns the walked - // count; never allocates on its own. - // Cut 12.2 fix batch (S1, Soul's second pass): admission is now decided ONCE, by the exact same shadow - // interval Silhouette sums over (Extent(c, ell), the shared function above) -- not by a re-derivation and - // not by a second, independent geometric test. The old code ran two tests: this shadow prefilter (a - // "re-derivation" of Silhouette's own centre/h, inline) AND SlabAlongB, an independent 2-axis ray-box - // intersection that could reject a cell the shadow test had just admitted, purely on float rounding at an - // interval edge -- an empty lane for a shot that had already passed its roll (R3 violation, the crash Soul - // reproduced through Zone.Update). Deleting the second gate removes the split authority: a cell the shadow - // sum counted metal for can no longer be un-counted here. - public static int Lane(HullData hull, float2 b, float s, LaneCell[] buffer) + // Every occupied cell the line meets, sorted by entry, in the pooled buffer; returns how many. Lane below + // walks the contiguous run from the first; a caller that needs the whole line (a contact fuse looking for + // the first cell ahead of its origin) reads all of them. One admission test either way. + private static int CellsOnLine(HullData hull, float2 b, float s, LaneCell[] buffer) { var ell = Lateral(b); var coords = hull.Shape.Coordinates; @@ -1420,7 +1517,29 @@ public static class FireControl } Array.Sort(buffer, 0, n); + return n; + } + // Cut 12.2 (docs/fire-control-cut.md, "the rules every sub-cut reads"): exact slab traversal along the + // bearing at a fixed lateral offset s, replacing the old 0.5-step sampling march. Collects the occupied + // cells whose shadow interval contains s, each with its own entry/exit parameter along b, ordered by + // entry (ties broken by dot(cell, b), then cell index for full determinism), then walks forward while + // consecutive cells are contiguous (`next.entry <= current.exit + 1e-4`) -- the first gap ends the walk, + // the same rule Entity.cs's old march kept. A direct hit starts outside the hull (t -> -infinity), so the + // walk's first element is the impact cell. Only that first element is read in 12.2; the rest is 12.3's + // armour-first absorption march. Writes into the caller-supplied pooled buffer and returns the walked + // count; never allocates on its own. + // Cut 12.2 fix batch (S1, Soul's second pass): admission is now decided ONCE, by the exact same shadow + // interval Silhouette sums over (Extent(c, ell), the shared function above) -- not by a re-derivation and + // not by a second, independent geometric test. The old code ran two tests: this shadow prefilter (a + // "re-derivation" of Silhouette's own centre/h, inline) AND SlabAlongB, an independent 2-axis ray-box + // intersection that could reject a cell the shadow test had just admitted, purely on float rounding at an + // interval edge -- an empty lane for a shot that had already passed its roll (R3 violation, the crash Soul + // reproduced through Zone.Update). Deleting the second gate removes the split authority: a cell the shadow + // sum counted metal for can no longer be un-counted here. + public static int Lane(HullData hull, float2 b, float s, LaneCell[] buffer) + { + var n = CellsOnLine(hull, b, s, buffer); var walked = n > 0 ? 1 : 0; for (var i = 1; i < n; i++) { @@ -1515,6 +1634,9 @@ public struct PendingShot public WeaponFuse? Fuse; public float BlastRadius; + // Frozen with the rest of the shooter's decision: where the round left from. A round outlives its shooter, so + // nothing at resolution reads the shooter's position. + public float3 FireOrigin; public float3 FireTargetPosition; public float3 FireTargetVelocity; public float FireTime; @@ -1614,7 +1736,12 @@ public sealed class ShotOutcome public Entity Source; public Entity Target; public EquippedItem Weapon; - public bool Hit; + // What the commit decided, typed: a shot rolled and missed, rolled and hit, or was a fused round with no + // target and so burst without rolling (Burst, at BurstPoint). Hit is derived from it, not stored beside it. + public ShotResult Result; + public bool Hit => Result == ShotResult.Hit; + // World planar point a Burst detonates at, frozen by the commit. Meaningless for any other Result. + public float2 BurstPoint; public bool Shielded; // Cut 5, 5.2 (Soul finding 4): frozen alongside the rest of the outcome (R4) -- a shield present, active, // and unable to CanTakeHit this shot is decided broken right here, so Apply performs Break() rather than @@ -1629,3 +1756,12 @@ public sealed class ShotOutcome public float ArrivalIn; public DamageType DamageType; } + +// What a committed shot came to. A Burst is a fused round that had no valid target: it rolled nothing, so it is +// neither a hit nor a miss, and the presentation must not call it one. +public enum ShotResult +{ + Miss, + Hit, + Burst +} diff --git a/tests/Aetheria.Shared.Tests/FireControlCut124Tests.cs b/tests/Aetheria.Shared.Tests/FireControlCut124Tests.cs index 3f5e28e97..d25718137 100644 --- a/tests/Aetheria.Shared.Tests/FireControlCut124Tests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlCut124Tests.cs @@ -1127,13 +1127,14 @@ public sealed class FireControlCut124Tests : IDisposable Assert.NotNull(outcome); Assert.False(outcome.Hit); // fixture: a guaranteed miss + Assert.Equal(ShotResult.Miss, outcome.Result); Assert.Empty(e.Zone.PendingShots); Assert.Equal(0, events); Assert.Equal(before, e.Target.Hull.Durability); } // Operator ruling 2026-09-30: "fused weapons without a lock explode at max range." A fused shot with no - // target bursts at the weapon's Range along its aim (the mount direction), whatever its fuse. The fixture + // target bursts at the weapon's Range along its aim (Entity.LookDirection), whatever its fuse. The fixture // aims the shooter along (2,1), a non-axis facing; witnesses sit at the burst point and beside it. Radius 4 // with the witness hull 5x4 cells of 2 world units: a witness centred on the burst point is covered, and // one 30 units off the aim line is not. @@ -1153,7 +1154,7 @@ public sealed class FireControlCut124Tests : IDisposable { var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: fuse, blastRadius: 4f, penetration: 1f, damage: 100f, weaponRange: NoLockRange); - e.Shooter.Direction = normalize(float2(2, 1)); + Aim(e, float2(2, 1)); e.Shooter.Target.Value = null; var burst = AimLine(e); var onLine = AddShip(e, burst, 1f, 300); @@ -1178,7 +1179,7 @@ public sealed class FireControlCut124Tests : IDisposable { var e = Build(TestSettings(), SolidShape(5, 4), velocity: 20f, fuse: WeaponFuse.Proximity, blastRadius: 4f, damage: 100f, weaponRange: NoLockRange); - e.Shooter.Direction = normalize(float2(2, 1)); + Aim(e, float2(2, 1)); e.Shooter.Target.Value = null; FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter); @@ -1210,6 +1211,276 @@ public sealed class FireControlCut124Tests : IDisposable Assert.Equal(5.65884256f, damage, 3); } + // ==== Operator rulings 2026-09-30 (Soul's pass on the no-lock fix): aim, invalid target, contact, shooter ==== + + private static void Aim(Engagement e, float2 direction) => e.Shooter.LookDirection = float3(direction.x, 0, direction.y); + + private static float3 PointAlong(Engagement e, float2 direction, float distance) => + e.Shooter.Position + float3(direction.x, 0, direction.y) * distance; + + private static bool Alive(Engagement e, Entity entity) => e.Zone.Entities.Contains(entity); + + // Ruling 1: an aim beyond the mount's arc flies along the nearest edge of that arc. The mount is (0,1), the + // arc 170 degrees (edge 85), and the aim (+-1,-1) sits 135 degrees off it; the witness on the edge dies and + // the one under the unclamped aim does not (they are 50 units apart). Kills: no clamp; the turn taken the + // wrong way round (the mirrored edge holds no witness). + [Theory] + [InlineData(1f)] + [InlineData(-1f)] + public void ANoLockShotOutsideTheMountArcFliesAlongTheNearestEdgeOfIt(float side) + { + var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: WeaponFuse.Proximity, blastRadius: 4f, damage: 100f, + weaponRange: NoLockRange); + e.Shooter.Target.Value = null; + Aim(e, float2(side, -1)); + var edge = float2(side * sin(radians(85f)), cos(radians(85f))); + var onEdge = AddShip(e, PointAlong(e, edge, NoLockRange), 1f, 300); + var underAim = AddShip(e, PointAlong(e, normalize(float2(side, -1)), NoLockRange), 1f, 302); + + FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter); + e.Zone.Update(.01f); + + Assert.False(Alive(e, onEdge), "the blast must land on the arc's edge"); + Assert.True(Alive(e, underAim), "the blast must not follow an aim the arc does not allow"); + } + + // Ruling 1: an aim inside the arc is used as it is (unnormalised here), and a shooter aiming at nothing + // (LookDirection zero) fires down its mount. Kills: reading MountDirection instead of the aim; a missing + // zero-aim fallback, which would normalise to NaN and burst nowhere. + [Fact] + public void ANoLockShotFliesAlongTheAimAndDownTheMountWhenNothingIsAimed() + { + var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: WeaponFuse.Proximity, blastRadius: 4f, damage: 100f, + weaponRange: NoLockRange); + e.Shooter.Target.Value = null; + var mount = float2(0, 1); + var aim = normalize(float2(2, 1)); + var onAim = AddShip(e, PointAlong(e, aim, NoLockRange), 1f, 300); + var onMount = AddShip(e, PointAlong(e, mount, NoLockRange), 1f, 302); + + Aim(e, float2(6, 3)); + FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter); + e.Zone.Update(.01f); + Assert.False(Alive(e, onAim), "the blast must follow the aim"); + Assert.True(Alive(e, onMount), "the mount direction is not the aim"); + + Aim(e, float2(0, 0)); + FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter); + e.Zone.Update(.01f); + Assert.False(Alive(e, onMount), "with nothing aimed the blast follows the mount"); + } + + public enum Invalid { OutOfRange, NotVisible, OutOfArc } + + // Ruling 2: a selected target that is out of range, not visible or out of arc counts as no lock -- the round + // bursts at max range along the aim, and the target is left alone. The aim is (2,1) except when the target is + // behind the mount, where the mount is flipped and the aim follows it. Kills: reading "no lock" as + // Target == null alone (the round would burst at the target's intercept, 100 / 40 / 100 units out). + // (An unlocked LockWeapon shares the same predicate; the fixture has no LockWeapon.) + [Theory] + [InlineData(Invalid.OutOfRange)] + [InlineData(Invalid.NotVisible)] + [InlineData(Invalid.OutOfArc)] + public void AnInvalidTargetCountsAsNoLock(Invalid reason) + { + var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: WeaponFuse.Proximity, blastRadius: 4f, damage: 100f, + weaponRange: NoLockRange, targetRange: reason == Invalid.NotVisible ? 40f : 100f); + var aim = normalize(float2(2, 1)); + if (reason == Invalid.NotVisible) e.Shooter.VisibleEntities.Remove(e.Target); + if (reason == Invalid.OutOfArc) + { + e.Shooter.Direction = float2(0, -1); + aim = float2(0, -1); + } + Aim(e, aim); + var burst = PointAlong(e, aim, NoLockRange); + var onAim = AddShip(e, burst, 1f, 300); + var targetBefore = e.Target.Hull.Durability; + + FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter); + var shot = Assert.Single(e.Zone.PendingShots); + Assert.Null(shot.Target); + Assert.Equal(burst.x, shot.BurstPosition.x, 3); + Assert.Equal(burst.z, shot.BurstPosition.z, 3); + e.Zone.Update(.01f); + + Assert.False(Alive(e, onAim), "the blast must land at max range along the aim"); + Assert.Equal(targetBefore, e.Target.Hull.Durability); + } + + // Ruling 3: a Contact round with no lock stops on the first hull its aim line crosses before max range; a + // Proximity or Delayed round keeps the max-range burst. The blocker's near face sits 21 units out (a 5x4-cell + // hull of 2-unit cells centred 25 out), the witness at max range (60). Kills: a Contact fuse that ignores + // hulls; a Proximity or Delayed fuse that trips on one. + [Theory] + [InlineData(WeaponFuse.Contact, true)] + [InlineData(WeaponFuse.Proximity, false)] + [InlineData(WeaponFuse.Delayed, false)] + public void OnlyAContactRoundWithNoLockStopsOnTheFirstHullItCrosses(WeaponFuse fuse, bool stopsOnTheBlocker) + { + var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: fuse, blastRadius: 4f, penetration: 1f, damage: 100f, + weaponRange: NoLockRange); + e.Shooter.Target.Value = null; + Aim(e, float2(0, 1)); + var blocker = AddShip(e, PointAlong(e, float2(0, 1), 25f), 1f, 300); + var atMaxRange = AddShip(e, PointAlong(e, float2(0, 1), NoLockRange), 1f, 302); + ShotOutcome outcome = null; + using var c = e.Zone.ShotCommitted.Subscribe(o => outcome = o); + + FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter); + e.Zone.Update(.01f); + + Assert.NotNull(outcome); + var expectedReach = stopsOnTheBlocker ? 21f : NoLockRange; + Assert.Equal(e.Shooter.Position.z + expectedReach, outcome.BurstPoint.y, 2); + Assert.Equal(e.Shooter.Position.x, outcome.BurstPoint.x, 2); + Assert.Equal(!stopsOnTheBlocker, Alive(e, blocker)); + Assert.Equal(stopsOnTheBlocker, Alive(e, atMaxRange)); + } + + // Ruling 3: a hull beyond max range is not on the round's way, and the shooter's own hull, which the line + // starts inside, is never a candidate. Here the target (100 out) lies on the line of a 60-range Contact + // round. Kills: a burst point beyond the max-range point; a Contact search that admits the shooter. + [Fact] + public void AContactRoundWithNoLockBurstsAtMaxRangeWhenNoHullIsInReach() + { + var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: WeaponFuse.Contact, blastRadius: 4f, damage: 100f, + weaponRange: NoLockRange); + e.Shooter.Target.Value = null; + Aim(e, float2(0, 1)); + var targetBefore = e.Target.Hull.Durability; + var shooterHit = 0f; + using var a = e.Shooter.ArmorDamage.Subscribe(x => shooterHit += x.damage); + using var h = e.Shooter.HullDamage.Subscribe(x => shooterHit += x); + using var i = e.Shooter.ItemDamage.Subscribe(x => shooterHit += x.damage); + ShotOutcome outcome = null; + using var c = e.Zone.ShotCommitted.Subscribe(o => outcome = o); + + FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter); + e.Zone.Update(.01f); + + Assert.Equal(e.Shooter.Position.z + NoLockRange, outcome.BurstPoint.y, 2); + Assert.Equal(targetBefore, e.Target.Hull.Durability); + Assert.Equal(0f, shooterHit); + } + + // Ruling 3: a Contact round bursting short of max range arrives when it has flown that far -- 21 of 60 units + // at 20 units/s is 1.05 s into a 3 s flight -- and the commit says so through ArrivalIn. Kills: an arrival + // left at the max-range time (the round would still be pending at 1.2 s, and ArrivalIn would read ~3). + [Fact] + public void AContactBurstShortOfMaxRangeArrivesWhenTheRoundHasFlownThatFar() + { + var e = Build(TestSettings(), SolidShape(5, 4), velocity: 20f, fuse: WeaponFuse.Contact, blastRadius: 4f, damage: 100f, + weaponRange: NoLockRange); + e.Shooter.Target.Value = null; + Aim(e, float2(0, 1)); + var blocker = AddShip(e, PointAlong(e, float2(0, 1), 25f), 1f, 300); + ShotOutcome outcome = null; + using var c = e.Zone.ShotCommitted.Subscribe(o => outcome = o); + + FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter); + e.Zone.Update(.01f); + Assert.NotNull(outcome); + Assert.Equal(1.05f - .01f, outcome.ArrivalIn, 2); + Assert.True(Alive(e, blocker)); + + e.Zone.Update(1.1f); + Assert.Empty(e.Zone.PendingShots); + Assert.False(Alive(e, blocker)); + } + + // Ruling 4: a round outlives its shooter. A no-lock proximity round whose shooter leaves the zone in flight + // still detonates at max range, whether the shooter goes before or after the commit; a targeted proximity + // round does the same at its intercept, for the same damage a shooter who stayed would have dealt (the value + // measured for ATargetedFusedShotIsUnchangedByTheNoLockRule at b66ba524, 5.65884256). Kills: Step + // cancelling a shot whose source has left the zone. + [Theory] + [InlineData(0)] + [InlineData(1)] + public void ANoLockRoundStillBurstsAfterItsShooterLeavesTheZone(int updatesBeforeLeaving) + { + var e = Build(TestSettings(), SolidShape(5, 4), velocity: 20f, fuse: WeaponFuse.Proximity, blastRadius: 4f, damage: 100f, + weaponRange: NoLockRange); + e.Shooter.Target.Value = null; + Aim(e, float2(0, 1)); + var witness = AddShip(e, PointAlong(e, float2(0, 1), NoLockRange), 1f, 300); + + FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter); + for (var i = 0; i < updatesBeforeLeaving; i++) e.Zone.Update(.01f); + e.Zone.Entities.Remove(e.Shooter); + e.Zone.Update(4f); + + Assert.Empty(e.Zone.PendingShots); + Assert.False(Alive(e, witness), "the round must still burst at max range"); + } + + [Fact] + public void ATargetedFusedRoundStillBurstsAfterItsShooterLeavesTheZone() + { + var e = Build(TestSettings(), SolidShape(5, 4), velocity: 20f, fuse: WeaponFuse.Proximity, blastRadius: 30f, damage: 100f); + var damage = 0f; + using var a = e.Target.ArmorDamage.Subscribe(x => damage += x.damage); + using var h = e.Target.HullDamage.Subscribe(x => damage += x); + using var i = e.Target.ItemDamage.Subscribe(x => damage += x.damage); + + FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter); + e.Zone.Update(.01f); + e.Zone.Entities.Remove(e.Shooter); + e.Zone.Update(6f); + + Assert.Empty(e.Zone.PendingShots); + Assert.Equal(5.65884256f, damage, 3); + } + + // Ruling 4, direct hits: rounds fired at a target and in flight when their shooter leaves still hit it. A dozen + // shots each roll their own dice (seeded by shot id), and with a stationary target and a full-accuracy + // targeting system nearly all land; the test needs only that all resolve and some hit, and that each hit + // still names the departed shooter (identity carried, never asked anything). + [Fact] + public void ADirectRoundStillHitsAfterItsShooterLeavesTheZone() + { + var e = Build(TestSettings(), SolidShape(5, 4), velocity: 20f, damage: 5f); + var resolved = new List(); + using var r = e.Zone.ShotResolved.Subscribe(o => resolved.Add(o)); + var struck = 0; + using var s = e.Target.IncomingHit.Subscribe(src => { if (src == e.Shooter) struck++; }); + + for (var i = 0; i < 12; i++) FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter); + e.Zone.Update(.01f); + e.Zone.Entities.Remove(e.Shooter); + e.Zone.Update(6f); + + Assert.Empty(e.Zone.PendingShots); + Assert.Equal(12, resolved.Count); + Assert.True(resolved.Any(o => o.Hit), "at least one round must land on the stationary target"); + Assert.Equal(resolved.Count(o => o.Hit), struck); + } + + // Ruling 6: what a commit came to is typed. A no-lock burst is neither a hit nor a miss, and reads as neither. + // Kills: MakeOutcome collapsing a burst back to a miss (the debug HUD read MISS for a real explosion). + [Fact] + public void ANoLockBurstCommitsAsABurstNotAMiss() + { + var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: WeaponFuse.Proximity, blastRadius: 4f, damage: 100f, + weaponRange: NoLockRange); + e.Shooter.Target.Value = null; + Aim(e, float2(2, 1)); + ShotOutcome committed = null, resolved = null; + using var c = e.Zone.ShotCommitted.Subscribe(o => committed = o); + using var r = e.Zone.ShotResolved.Subscribe(o => resolved = o); + + FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter); + e.Zone.Update(.01f); + + Assert.NotNull(committed); + Assert.Equal(ShotResult.Burst, committed.Result); + Assert.False(committed.Hit); + var burst = PointAlong(e, normalize(float2(2, 1)), NoLockRange); + Assert.Equal(burst.x, committed.BurstPoint.x, 3); + Assert.Equal(burst.z, committed.BurstPoint.y, 3); + Assert.Same(committed, resolved); + } + // ToWorldPoint and ToSchematicPoint are inverses, and ToWorldPoint puts one cell to starboard of the centre // of mass two world units along the starboard axis (right = (forward.y, -forward.x), spelled out here). At // facing (0,1) a flipped right axis is still masked by a centre-lane point; (2,1) is not. @@ -1352,6 +1623,7 @@ public sealed class FireControlCut124Tests : IDisposable } Assert.NotNull(outcome); Assert.True(outcome.Hit); + Assert.Equal(ShotResult.Hit, outcome.Result); Assert.True(armorEvents > 0); var shot = e.Zone.PendingShots.Count == 0 ? null : (PendingShot?) e.Zone.PendingShots[0]; Assert.Null(shot); // resolved and removed -- confirms it went through Apply's null-fuse path to completion