diff --git a/Assets/Scripts/ServerShared/Enums.cs b/Assets/Scripts/ServerShared/Enums.cs index e556ba656..2b5a9637b 100644 --- a/Assets/Scripts/ServerShared/Enums.cs +++ b/Assets/Scripts/ServerShared/Enums.cs @@ -107,6 +107,15 @@ public enum WeaponModifiers Cluster = 1 << 6 } +// Cut 12.4(a) (docs/fire-control-cut.md): what a weapon's blast radius (WeaponItemData.BlastRadius) detonates +// as. Null means no blast at all -- WeaponItemData.Fuse is frozen null unless BlastRadius > 0 (FireControl.Fire). +public enum WeaponFuse +{ + Contact, + Proximity, + Delayed +} + public enum DamageType { Kinetic, diff --git a/Assets/Scripts/ServerShared/FireControl.cs b/Assets/Scripts/ServerShared/FireControl.cs index eebbda665..2c7fcbdba 100644 --- a/Assets/Scripts/ServerShared/FireControl.cs +++ b/Assets/Scripts/ServerShared/FireControl.cs @@ -379,13 +379,16 @@ public static class FireControl var commitHorizon = source.ItemManager.GameplaySettings.CommitHorizon; - // Cut 6b, 6.2 (Soul finding 5): airburst is a property of the weapon, resolved and frozen here like - // every other payload field -- never decided later by a Unity projectile. A weapon without the - // Airburst flag freezes a zero radius, which Step below reads as "resolve this shot with Apply." + // 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 + // later by a Unity projectile, and never by a label. Fire decides "detonates" once: a fuse is frozen + // only when BlastRadius > 0, and null otherwise, so a radius without a fuse or a fuse without a radius + // is inert and resolves as a direct hit (nothing polices that). A zero-radius freeze is what Step below + // still reads as "resolve this shot with Apply." var weaponItemData = item.Data as WeaponItemData; - var isAirburst = weaponItemData != null && weaponItemData.WeaponModifiers.HasFlag(WeaponModifiers.Airburst); - var burstPosition = isAirburst && target != null ? PredictedIntercept(weapon, source, target) : targetPosition; - var burstRadius = isAirburst ? weaponItemData.AirburstRange ?? 0f : 0f; + 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; var shot = new PendingShot { @@ -410,7 +413,8 @@ public static class FireControl ArrivalTime = now + flightTime, CommitTime = now + max(0f, flightTime - commitHorizon), BurstPosition = burstPosition, - BurstRadius = burstRadius, + Fuse = fuse, + BlastRadius = blastRadius, Committed = false }; @@ -457,10 +461,10 @@ public static class FireControl if (shot.Committed && now >= shot.ArrivalTime) { - // Cut 6b, 6.2: an airburst shot (frozen BurstRadius > 0) resolves as an area effect instead of - // a discrete hit -- Splash instead of Apply, never both, which is exactly the double- - // application Soul was told to hunt for. - if (shot.BurstRadius > 0f) Splash(zone, shot.BurstPosition, shot.BurstRadius, shot.Damage, shot.DamageType); + // Cut 6b, 6.2 (renamed 12.4(a)): a shot with a frozen BlastRadius > 0 resolves as an area effect + // instead of a discrete hit -- Splash instead of Apply, never both, which is exactly the + // double-application Soul was told to hunt for. The fuse switch itself is 12.4(b)'s. + if (shot.BlastRadius > 0f) Splash(zone, shot.BurstPosition, shot.BlastRadius, shot.Damage, shot.DamageType); else Apply(shot); zone.ShotResolved.OnNext(shot.Outcome); shots.RemoveAt(i); @@ -1243,11 +1247,13 @@ public struct PendingShot public float Spread; public float FireRange; - // Cut 6b, 6.2: the airburst payload, frozen at fire alongside everything else above. BurstRadius is zero - // for a weapon without the Airburst flag (WeaponModifiers, Enums.cs) -- Step reads that zero as "resolve - // with Apply," not a separate bool. + // Cut 12.4(a): the blast payload, frozen at Fire alongside everything else above. BlastRadius is zero for + // a weapon whose data does not carry one -- Step reads that zero as "resolve with Apply," not a separate + // bool. Fuse is frozen only when BlastRadius > 0 (Fire decides "detonates" once); it is unread until + // Apply's fuse switch (12.4(b)). public float3 BurstPosition; - public float BurstRadius; + public WeaponFuse? Fuse; + public float BlastRadius; public float3 FireTargetPosition; public float3 FireTargetVelocity; diff --git a/Assets/Scripts/ServerShared/ItemData.cs b/Assets/Scripts/ServerShared/ItemData.cs index 1cec438cc..27c647d83 100644 --- a/Assets/Scripts/ServerShared/ItemData.cs +++ b/Assets/Scripts/ServerShared/ItemData.cs @@ -490,12 +490,20 @@ public class WeaponItemData : GearData [Inspectable, JsonProperty("modifiers"), Key(28)] public WeaponModifiers WeaponModifiers; - // Cut 6b (docs/fire-control-cut.md, 6.2): the authored blast radius an Airburst-flagged weapon's shot - // splashes with at arrival, frozen into PendingShot.BurstRadius at fire. Zero (and unread) for a weapon - // without the Airburst flag. No authored value exists yet -- the flag is wired and unexercised until Cut - // 6a or a later authoring pass sets it. - [Inspectable, JsonProperty("airburstRange"), Key(29)] - public float? AirburstRange; + // Cut 12.4(a) (docs/fire-control-cut.md): the authored blast radius a weapon's shot detonates with, in + // world units. Renamed from AirburstRange -- the slot and type are unchanged, so CultCache opens the + // catalog as compatible drift. Null (every shipped record) means no blast; WeaponModifiers no longer + // decides this (Q12-6, "WeaponModifiers are labels, not behaviour"). + [Inspectable, JsonProperty("blastRadius"), Key(29)] + public float? BlastRadius; + + // Cut 12.4(a): what kind of blast BlastRadius describes. Nullable under the 7.4 rule -- null means no + // blast, and every shipped record reads null. FireControl.Fire freezes this from the weapon only when + // BlastRadius > 0; a fuse without a radius, or a radius without a fuse, is inert and resolves as a direct + // hit (nothing polices that, per Q12-6). Key 30 and 31 belong to EquippableItemData's OptimalTemperature + // and PlateauWidth, inherited here -- the next free key across WeaponItemData's own ancestry is 32. + [Inspectable, JsonProperty("fuse"), Key(32)] + public WeaponFuse? Fuse; } [CultDocument("aetheria.hulldata", "1"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] diff --git a/tests/Aetheria.Shared.Tests/FireControlCut6Tests.cs b/tests/Aetheria.Shared.Tests/FireControlCut6Tests.cs index 72421af4e..1f85e2381 100644 --- a/tests/Aetheria.Shared.Tests/FireControlCut6Tests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlCut6Tests.cs @@ -78,7 +78,7 @@ public sealed class FireControlCut6Tests : IDisposable GameplaySettings settings, float damage = 10, float range = 1000, float velocity = 0, float spread = 0, float accuracy = 1, float resolution = 1, float tracking = 100000, - float targetRange = 100, bool airburst = false, float airburstRange = 0) + float targetRange = 100, WeaponFuse? fuse = null, float blastRadius = 0) { var hullShape = SolidShape(5, 5); var hullData = new HullData @@ -91,14 +91,15 @@ public sealed class FireControlCut6Tests : IDisposable _openCaches.Add(cache); cache.Upsert(new TestCatalogGlobal { Name = "Temperament" }); cache.Upsert(hullData); - // Cut 6b, 6.2: a real WeaponItemData (not the bare GearData earlier cuts' fixtures use) -- it is the - // one catalog type carrying WeaponModifiers (the Airburst flag) and, since this cut, AirburstRange. + // Cut 6b, 6.2 (renamed 12.4(a)): a real WeaponItemData (not the bare GearData earlier cuts' fixtures + // use) -- it is the one catalog type carrying Fuse and BlastRadius. WeaponModifiers no longer decides + // behaviour (Q12-6), so the fixture does not bother setting it. cache.Upsert(new WeaponItemData { Name = "Gun", Hardpoint = HardpointType.Sensors, Shape = new Shape(), Durability = 1, MinimumTemperature = -1000, MaximumTemperature = 1000, OptimalTemperature = 0, PlateauWidth = 2000, - WeaponModifiers = airburst ? WeaponModifiers.Airburst : WeaponModifiers.None, - AirburstRange = airburstRange, + Fuse = fuse, + BlastRadius = blastRadius, Behaviors = { new InstantWeaponData { Damage = Constant(damage), Range = Constant(range), MinRange = Constant(0), @@ -246,7 +247,7 @@ public sealed class FireControlCut6Tests : IDisposable { var settings = TestSettings(); var e = Build(settings, damage: 500, velocity: 0, accuracy: 0, resolution: 1, tracking: 100000, - targetRange: 50, airburst: true, airburstRange: 100); + targetRange: 50, fuse: WeaponFuse.Proximity, blastRadius: 100); var before = e.Target.Hull.Durability; FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter); @@ -265,7 +266,7 @@ public sealed class FireControlCut6Tests : IDisposable var settings = TestSettings(); var e = Build(settings, damage: 10, velocity: 0, accuracy: 1, resolution: 1, tracking: 100000, - targetRange: 50, airburst: true, airburstRange: 100); + targetRange: 50, fuse: WeaponFuse.Proximity, blastRadius: 100); var before = e.Target.Hull.Durability; FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter); e.Zone.Update(.01f); @@ -276,7 +277,7 @@ public sealed class FireControlCut6Tests : IDisposable // exactly its own position -- PredictedIntercept falls back to target.Position below weapon.Velocity's // .01f floor). var e2 = Build(settings, damage: 10, velocity: 0, accuracy: 1, resolution: 1, tracking: 100000, - targetRange: 50, airburst: true, airburstRange: 100); + targetRange: 50, fuse: WeaponFuse.Proximity, blastRadius: 100); var before2 = e2.Target.Hull.Durability; FireControl.Splash(e2.Zone, e2.Target.Position, 100, 10, DamageType.Kinetic); var expectedDelta = before2 - e2.Target.Hull.Durability; @@ -285,19 +286,19 @@ public sealed class FireControlCut6Tests : IDisposable Assert.Equal(expectedDelta, actualDelta, 3); } - // The other side: a non-airburst shot must never splash, even one that lands exactly on its own frozen + // The other side: a shot with no blast must never splash, even one that lands exactly on its own frozen // burst position at zero range (a stationary target, so BurstPosition == the target's own position at // arrival) -- the zero-radius edge case a careless "splash unconditionally" mutant would still pass // through, since distance 0 is never greater than radius 0. Accuracy 0 pins the discrete roll to a // guaranteed miss, so the correct path (Apply, gated on Outcome.Hit) deals no damage at all. Mutation: - // splash unconditionally at arrival instead of gating on BurstRadius -- Splash does not check Hit, so it - // would still deal damage even though this shot never carried the Airburst flag. + // splash unconditionally at arrival instead of gating on BlastRadius -- Splash does not check Hit, so it + // would still deal damage even though this shot never froze a blast. [Fact] public void NonAirburstNeverSplashes() { var settings = TestSettings(); var e = Build(settings, damage: 1000, velocity: 0, accuracy: 0, resolution: 1, tracking: 100000, - targetRange: 50, airburst: false); + targetRange: 50); var before = e.Target.Hull.Durability; FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter); @@ -306,6 +307,31 @@ public sealed class FireControlCut6Tests : IDisposable Assert.Equal(before, e.Target.Hull.Durability); } + // ---- Cut 12.4(a): Fire decides "detonates" once, from the weapon's own data fields, never from a label + // (Q12-6, "WeaponModifiers are labels, not behaviour"). A fuse without a radius is inert: it freezes null, + // not the weapon's Fuse. ---- + + // Mutation: freeze `weaponItemData.Fuse` unconditionally instead of gating it on `blastRadius > 0f` -- a + // weapon that carries a fuse but no radius would then freeze a fuse it should not, and Apply's future + // fuse switch (12.4(b)) would try to detonate a shot with nothing to detonate with. + [Fact] + public void FireFreezesFuseOnlyWhenBlastRadiusIsPositive() + { + var settings = TestSettings(); + + var withRadius = Build(settings, fuse: WeaponFuse.Delayed, blastRadius: 40); + FireControl.Fire(withRadius.Weapon, withRadius.WeaponItem, withRadius.Shooter); + var shotWithRadius = withRadius.Zone.PendingShots[0]; + Assert.Equal(WeaponFuse.Delayed, shotWithRadius.Fuse); + Assert.Equal(40f, shotWithRadius.BlastRadius); + + var withoutRadius = Build(settings, fuse: WeaponFuse.Delayed, blastRadius: 0); + FireControl.Fire(withoutRadius.Weapon, withoutRadius.WeaponItem, withoutRadius.Shooter); + var shotWithoutRadius = withoutRadius.Zone.PendingShots[0]; + Assert.Null(shotWithoutRadius.Fuse); + Assert.Equal(0f, shotWithoutRadius.BlastRadius); + } + // ---- negative: ItemManager.Random no longer appears in FireControl.cs; Airburst no longer appears // anywhere under Assets/Scripts/Gameplay (Projectile.cs's fields and ProjectileManager.cs's write-back are // deleted, not merely unused). Enforced by tests/mutation_tests_fire_control_cut6.sh's negative-grep step,