Read the range factor where the delivery point is decided; mines and unauthored stats go through the one function

A no-lock fused round reads RangeFactor in CommitBurst at the distance it travelled to the hull it stops on; every round whose point
Solve plans reads it once at Fire (PendingShot.DeliveredAtCommit says which). Lay reads it at its own distance 0. PerformanceStat.Evaluate
no longer interpolates a single-value span, so an unauthored +infinity stat evaluates unequipped. Tests: the round that stops short, the
Fused Rounds hull ahead, a mine layer's authored ranges, the group pick at the target's real distance, unequipped SRMM72/Mine Launcher.
Not yet built (verify job follows).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-14 06:49:56 +02:00
commit b713c42503
6 changed files with 173 additions and 18 deletions

View file

@ -723,9 +723,10 @@ public static class FireControl
Target = engaged,
Weapon = item,
Aimed = source.ResolvedTargetItem,
// The one place a shot's damage meets range, frozen here: BurstReach is where the payload is delivered. A burst is
// never farther than Range (it is pulled back to it), so rounding in its distance must not read as beyond it.
Damage = (damageOverride ?? weapon.Damage) * weapon.RangeFactor(min(solution.BurstReach, weapon.Range)),
Damage = damageOverride ?? weapon.Damage,
FireMinRange = weapon.MinRange,
FireEffectiveRange = weapon.EffectiveRange,
FireDamageAtMaxRange = weapon.WeaponData.DamageAtMaxRange,
Penetration = weapon.Penetration,
DamageSpread = weapon.DamageSpread,
DamageType = weapon.WeaponData.DamageType,
@ -751,11 +752,20 @@ public static class FireControl
BlastRadius = blastRadius,
Committed = false
};
// A round whose delivery point Solve plans reads the falloff here, at that point (BurstReach); a no-lock fused round's
// point is decided at its commit (CommitBurst), which reads it there. Each shot reads it once.
if (!shot.DeliveredAtCommit) Deliver(ref shot, solution.BurstReach);
zone.PendingShots.Add(shot);
return shot.ShotId;
}
// The one place a shot's damage meets range: the weapon's falloff at the planar distance its payload is delivered at,
// over the stats frozen at Fire. A delivery is never farther than the Range it was fired with (a burst is pulled back to
// it), so rounding in its distance must not read as beyond it.
private static void Deliver(ref PendingShot shot, float reach) =>
shot.Damage *= WeaponData.RangeFactor(shot.FireMinRange, shot.FireEffectiveRange, shot.MaxRange, shot.FireDamageAtMaxRange, min(reach, shot.MaxRange));
// Lays a mine for a mine layer: freezes the payload as evaluated now (stats, the item's blast radius, the
// layer and its faction) and hands the body to Zone.Lay, the one adder. It launches at the shooter's velocity
// plus the mount direction turned by a dice angle within +-Spread/2, times Velocity; the dice are the mine's
@ -787,7 +797,9 @@ public static class FireControl
FuseDelay = data.FuseDelay,
Lifetime = data.Lifetime,
BlastRadius = blastRadius,
Damage = weapon.Damage,
// A mine is laid at the layer, distance 0: it goes through the same falloff as every other payload, so a layer's
// authored ranges decide its mines, the AI's reading of it and its panel alike.
Damage = weapon.Damage * weapon.RangeFactor(0f),
DamageType = weapon.WeaponData.DamageType,
Layer = source,
LayerFaction = source.Faction
@ -831,7 +843,7 @@ public static class FireControl
if (!shot.Committed && now >= shot.CommitTime)
{
shot.Outcome = Commit(zone, shot, now);
shot.Outcome = Commit(zone, ref 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.
@ -888,11 +900,11 @@ public static class FireControl
return p * PSpread(shot.Spread, sil.Span, shot.FireRange, settings.SchematicCellSize) * sil.POnHull;
}
private static ShotOutcome Commit(Zone zone, PendingShot shot, float now)
private static ShotOutcome Commit(Zone zone, ref 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);
if (shot.DeliveredAtCommit) return CommitBurst(zone, ref 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) --
@ -984,12 +996,14 @@ public static class FireControl
// nothing locked stops on what is in its way), and at the max-range point when the line is clear. 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)
private static ShotOutcome CommitBurst(Zone zone, ref PendingShot shot, float now)
{
var outcome = MakeOutcome(shot, ShotResult.Burst, false, false, int2.zero, float2.zero, 0f, now);
outcome.HasBurstPoint = true;
var reach = length(shot.BurstPosition.xz - shot.FireOrigin.xz);
var travelled = min(reach, max(HullDistance(zone, shot, reach), shot.BlastRadius));
// The delivery point is decided here, so the falloff is read here, at the distance the round travelled to it.
Deliver(ref shot, travelled);
if (travelled < reach)
{
outcome.BurstPoint = shot.FireOrigin.xz + shot.TravelDirection * travelled;
@ -1978,6 +1992,11 @@ public struct PendingShot
// The frozen payload (R10, Q6): the gun's own stats at the instant the trigger was pulled. Nothing
// downstream re-evaluates any of these.
public float Damage;
// The weapon's falloff stats at Fire (with MaxRange below), frozen like the rest: what the range factor reads, at Fire or
// at commit.
public float FireMinRange;
public float FireEffectiveRange;
public float FireDamageAtMaxRange;
public float Penetration;
public float DamageSpread;
public DamageType DamageType;
@ -2020,6 +2039,10 @@ public struct PendingShot
public bool Committed;
public ShotOutcome Outcome;
// A fused round with no target: where it bursts is decided at its commit (the first hull its aim line meets), so its
// damage reads the falloff there rather than at Fire.
public bool DeliveredAtCommit => Fuse != null && Target == null;
}
// What a round does when fired (FireControl.Solve): Direct resolves against its target, Burst detonates at a

View file

@ -725,7 +725,10 @@ public class PerformanceStat
_ => throw new ArgumentOutOfRangeException(nameof(term.Source), term.Source, $"Unknown StatSource on {Min}-{Max} stat")
};
}
return (lerp(Min, Max, factor) * context.ScaleModifier(this) + context.ConstantModifier(this)) * powerMultiplier;
// A stat whose span is a single value has nothing to interpolate: an unauthored stat is +infinity at both ends
// (Tracking, EffectiveRange), and lerp(+inf, +inf, f) is NaN.
var interpolated = Min == Max ? Min : lerp(Min, Max, factor);
return (interpolated * context.ScaleModifier(this) + context.ConstantModifier(this)) * powerMultiplier;
}
}

View file

@ -83,7 +83,8 @@ public sealed class FireControlPerWeaponTests : IDisposable
private Rig Build(
(ItemRotation Rotation, float Arc)[] mounts = null, bool beam = false, WeaponFuse? fuse = null, float blast = 0f,
float range = 100f, float targetRange = 60f, float accuracy = 1f, float minHit = .2f, bool lockWeapon = false,
bool turret = false, float energy = 0f, float heat = 0f, float visibility = 0f, int magazine = 0, bool singleAmmoBurst = false, bool decoy = false, bool charged = false, bool auto = false)
bool turret = false, float energy = 0f, float heat = 0f, float visibility = 0f, int magazine = 0, bool singleAmmoBurst = false, bool decoy = false, bool charged = false, bool auto = false,
float effective = float.PositiveInfinity, float damageAtMax = 0f)
{
mounts ??= new[] { (ItemRotation.None, 0f) };
var hullData = new HullData
@ -132,6 +133,8 @@ public sealed class FireControlPerWeaponTests : IDisposable
behavior.Damage = Constant(100);
behavior.Range = Constant(range);
behavior.MinRange = Constant(0);
behavior.EffectiveRange = Constant(effective);
behavior.DamageAtMaxRange = damageAtMax;
behavior.Velocity = Constant(0);
behavior.Spread = Constant(0);
behavior.DamageSpread = Constant(0);
@ -599,6 +602,28 @@ public sealed class FireControlPerWeaponTests : IDisposable
Assert.True(r.Decoy.Weapon.Firing, "the group that reaches is the one picked");
}
// Combat's group pick reads the falloff at the target's real distance. The gun falls off from 10 to 0 at 100, the decoy
// is flat at 50: at 60 the gun makes 44 (the decoy is picked) while at half that distance it makes 78 and at double it
// makes 0; with the gun flat to 40 it makes 67 at 60 (picked) and 0 at double. The fixture states both neighbours so a
// pick made at a scaled distance reads the other way. Kills: the group's DPS read at a distance other than the target's.
[Theory]
[InlineData(10f, false)]
[InlineData(40f, true)]
public void CombatPicksTheGroupStrongestAtTheTargetsDistance(float effective, bool gunPicked)
{
var r = Build(range: 100f, targetRange: 60f, effective: effective, decoy: true);
var decoy = r.Decoy.Weapon.RangeDamagePerSecond(60f);
Assert.Equal(gunPicked, r.Gun.Weapon.RangeDamagePerSecond(60f) > decoy);
Assert.True(r.Gun.Weapon.RangeDamagePerSecond(effective == 10f ? 30f : 120f) > decoy == !gunPicked, "fixture: the scaled distance reads the other way");
r.Zone.Agents.Add(new Minion(r.Shooter));
r.Zone.Update(1f);
r.Zone.Update(1f);
Assert.Equal(gunPicked, r.Gun.Weapon.Firing);
Assert.Equal(!gunPicked, r.Decoy.Weapon.Firing);
}
// Combat's range test is Designated's, not a second one: a target exactly at max range is in reach (the old
// private test was strict). Kills: a range comparison of Combat's own.
[Fact]

View file

@ -66,7 +66,8 @@ public sealed class MineTests : IDisposable
private Lab Build(float blast = 4f, float arming = 2f, float fuse = 2f, float life = 30f, float spread = 0f, float velocity = 0f,
float damage = 100f, float range = 1000f, float cooldown = 1000f, Faction layerFaction = null,
WeaponFuse? fuseKind = WeaponFuse.Proximity, bool well = false, float3? layerAt = null, int magazine = 100)
WeaponFuse? fuseKind = WeaponFuse.Proximity, bool well = false, float3? layerAt = null, int magazine = 100,
float minRange = 0f, float effectiveRange = float.PositiveInfinity, float damageAtMaxRange = 0f)
{
var settings = new GameplaySettings
{
@ -91,7 +92,8 @@ public sealed class MineTests : IDisposable
var data = new MineLayerData
{
ArmingDelay = arming, FuseDelay = fuse, Lifetime = life,
Damage = Constant(damage), Range = Constant(range), MinRange = Constant(0), Velocity = Constant(velocity),
Damage = Constant(damage), Range = Constant(range), MinRange = Constant(minRange),
EffectiveRange = Constant(effectiveRange), DamageAtMaxRange = damageAtMaxRange, Velocity = Constant(velocity),
Spread = Constant(spread), DamageSpread = Constant(0), Penetration = Constant(0), Count = Constant(1),
BurstTime = Constant(0), Cooldown = Constant(cooldown), MagazineSize = magazine,
};
@ -545,6 +547,24 @@ public sealed class MineTests : IDisposable
Assert.True(angles.Max() > 10f && angles.Min() < -10f, "the angle spans +-Spread/2, not a narrower cone");
}
// A mine goes through the same falloff as every payload, read at its lay distance (0, at the layer): the layer's authored
// ranges decide the mine's damage, the AI's reading of the layer and the panel's chart alike. Authored flat to 10 with
// a .3 end, a mine layer with no minimum range lays a full-damage mine; with a minimum of 5 the layer has no reach at the
// lay point and the mine is worth nothing, in the AI's figure too. Kills: Lay without the factor, Lay reading it at any
// other distance (20 reads under 1 for both fixtures).
[Theory]
[InlineData(0f, 100f)]
[InlineData(5f, 0f)]
public void ALayersAuthoredRangesDecideItsMinesAndTheAILikewise(float minRange, float damage)
{
var lab = Build(damage: 100f, range: 1000f, minRange: minRange, effectiveRange: 10f, damageAtMaxRange: .3f, layerFaction: A);
Assert.NotEqual(damage, 100f * lab.Weapon.RangeFactor(20f));
var mine = LayOne(lab);
Assert.Equal(damage, mine.Damage, 3);
Assert.Equal(damage, lab.Weapon.RangeDamagePerSecond(0f) * lab.Weapon.Cooldown, 3);
}
[Fact]
public void ThePayloadIsFrozen()
{

View file

@ -5,6 +5,7 @@
using System;
using System.Linq;
using CultMath;
using UniRx;
using Xunit;
using static CultMath.math;
using float2 = CultMath.float2;
@ -47,6 +48,27 @@ public sealed class RangeFalloffTests
Assert.Equal(1f, WeaponData.RangeFactor(20f, 500f, 120f, 0f, 70f));
}
// The properties panel evaluates an unequipped item's stats through ItemManager.Evaluate. An unauthored stat is +infinity at
// both ends (EffectiveRange, Tracking) and must evaluate to that, not throw: a span of one value has nothing to interpolate.
[Theory]
[InlineData("SRMM72", true)]
[InlineData("Mine Launcher", true)]
[InlineData("Autocannon", false)]
public void AnUnequippedWeaponsUnauthoredStatsEvaluate(string design, bool unauthored)
{
using var cache = RestoredHullsTests.OpenCatalog();
var items = new ItemManager(cache, new ProvenanceLedger(), RunSaveTests.TestSettings(), _ => { });
var data = cache.GetAll<WeaponItemData>().Single(x => x.Name == design);
var lot = items.Lots.Add(new Lot { Design = cache.RefOf<ItemData>(data), Origin = new Attributed(), Quality = .5f, Roles = new System.Collections.Generic.List<RoleFill>() });
var item = (EquippableItem) items.CreateInstance(lot);
var weapon = data.Behaviors.OfType<WeaponData>().Single();
var effective = items.Evaluate(weapon.EffectiveRange, item);
Assert.Equal(unauthored, float.IsPositiveInfinity(effective));
Assert.False(float.IsNaN(effective));
Assert.True(float.IsPositiveInfinity(items.Evaluate(weapon.Tracking, item)) || !unauthored);
}
[Fact]
public void ShippedWeaponsFallOffAsAuthored()
{
@ -91,17 +113,44 @@ public sealed partial class FireControlCut124Tests
Assert.Equal(0f, FreezeAt(150f).Damage, 3); // at the maximum range
}
// A fused round with no target bursts at Range ("bomb fishing"), so it lands at the end multiplier.
// A no-lock fused round reads the falloff where its burst point is decided, at its commit: the shot right after the tick
// that committed it, still in the air (velocity 20). With a clear line it travels to Range ("bomb fishing") and lands at
// the end multiplier.
private float NoLockDamageAfterCommit(float effective, float blockerAt, out float travelled)
{
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 20f, fuse: WeaponFuse.Proximity, blastRadius: 4f, penetration: 1f,
damage: 100f, weaponRange: NoLockRange, effectiveRange: effective, damageAtMaxRange: .25f);
e.Shooter.SetTarget(TargetRef.None);
Aim(e, float2(0, 1));
if (blockerAt > 0f) AddShip(e, PointAlong(e, float2(0, 1), blockerAt), 100000f, 300);
ShotOutcome outcome = null;
using var c = e.Zone.ShotCommitted.Subscribe(o => outcome = o);
var shotId = FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter);
Assert.NotEqual(0, shotId);
e.Zone.Update(.01f);
Assert.True(outcome != null && outcome.HasBurstPoint, "the round committed a burst");
travelled = length(outcome.BurstPoint - e.Shooter.Position.xz);
return e.Zone.PendingShots.Single(s => s.ShotId == shotId).Damage;
}
[Fact]
public void AFusedRoundFishedToRangeLandsAtTheEndMultiplier()
{
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: WeaponFuse.Proximity, blastRadius: 4f, damage: 100f,
weaponRange: 150f, effectiveRange: 50f, damageAtMaxRange: .25f);
e.Shooter.SetTarget(TargetRef.None);
Aim(e, float2(0, 1));
var shotId = FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter);
Assert.NotEqual(0, shotId);
Assert.Equal(25f, e.Zone.PendingShots.Single(s => s.ShotId == shotId).Damage, 3);
Assert.Equal(25f, NoLockDamageAfterCommit(effective: 20f, blockerAt: 0f, out var travelled), 3);
Assert.Equal(NoLockRange, travelled, 3);
}
// The round stops on the first hull ahead, 21 out (well inside a 30 effective range of a 60 range weapon): it delivers
// full damage there, not the end multiplier of the point it was planned to. With a shorter effective range (10) the
// factor is the lerp at the distance it actually travelled.
[Fact]
public void ANoLockRoundStoppingShortReadsTheFactorWhereItStops()
{
Assert.Equal(100f, NoLockDamageAfterCommit(effective: 30f, blockerAt: 25f, out var travelled), 3);
Assert.True(travelled < NoLockRange - 20f, "the round stopped short of Range");
var damage = NoLockDamageAfterCommit(effective: 10f, blockerAt: 25f, out var stopped);
Assert.Equal(travelled, stopped, 3);
Assert.Equal(100f * lerp(1f, .25f, (stopped - 10f) / (NoLockRange - 10f)), damage, 3);
}
// A beam roll fires through damageOverride: the override is what the factor multiplies.

View file

@ -20,6 +20,41 @@ public sealed partial class RunStartTests
return (arena, staged);
}
// The scenario's own check (operator checks "aim at the hull ahead and it stops and bursts on it"): the Smoke Proximity round
// stops on the bare hull 300 m ahead (its planned point is at the weapon's Range, out past the effective range) and that hull takes damage.
// Selected, a targeted round reaches it too (the control).
[Theory]
[InlineData(false)]
[InlineData(true)]
public void FusedRoundsBurstDamagesTheHullAhead(bool selected)
{
var (arena, staged) = LaunchStepped(new FusedRounds());
var player = staged.Player;
var ahead = arena.Entities.Single(x => length(x.Position.xz - FusedRounds.Ahead) < 1f);
if (selected)
{
player.SetTarget(ahead);
player.SetIff(ahead, true);
player.EntityInfoGathered[ahead] = 1f;
}
player.Aim = float3(0, 0, 1);
var weapon = (InstantWeapon) WeaponOf(Carried(player, "Smoke Proximity"));
var taken = 0f;
using var armor = ahead.ArmorDamage.Subscribe(x => taken += x.damage);
using var hull = ahead.HullDamage.Subscribe(x => taken += x);
using var item = ahead.ItemDamage.Subscribe(x => taken += x.damage);
var fired = 0;
weapon.OnFire += _ => fired++;
weapon.Activate();
for (var t = 0; t < 120 && fired == 0; t++) arena.Update(SteppedDt);
weapon.Deactivate();
for (var t = 0; t < 120; t++) arena.Update(SteppedDt);
Assert.True(fired > 0, "the round was fired");
Assert.True(taken > 0f, $"the hull ahead took no damage (selected {selected})");
}
// Fused Rounds, nothing selected, the player aiming down the bare hull ahead. The DeathCluster is the control: it fires
// in this arena, so a fused weapon that does not is not a harness that cannot fire. A fused round flies slowly enough
// to be in the air when the direct weapon kills the fragile hull (check A.3) and bursts on the first hull on the aim line.