Damage falloff: effective range and damage at max range replace DamageCurve
WeaponData.RangeFactor is the one function of damage over range: 0 outside [MinRange, Range], 1 up to EffectiveRange, one lerp to DamageAtMaxRange. DamageCurve (key 7, retired) and its formula parameters, CurveField's BezierCurve path, and every fixture curve line are deleted. Fire freezes damage times the factor at BurstReach; the AI's DPS reads, Combat's optimum sampling and the properties panel chart read the same function. AetherDb gains range-falloff (command only; the catalog is re-saved in a later commit). Cut and wiring land in one commit rather than two; this commit has not been built yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b836af4850
commit
5e0ec92509
33 changed files with 282 additions and 127 deletions
|
|
@ -32,7 +32,7 @@ public class CombatState : BaseState
|
|||
_availableLockingWeapons.Clear();
|
||||
|
||||
var toTarget = target.Position - _agent.Ship.Position;
|
||||
var targetDistance = length(toTarget);
|
||||
var targetDistance = length(toTarget.xz);
|
||||
|
||||
// Cut 2 (docs/fire-control-cut.md): aim at whichever revealed weapon on the target hits hardest at
|
||||
// this range, or clear the aim point when nothing qualifies -- the same predicate
|
||||
|
|
@ -139,8 +139,8 @@ public class CombatState : BaseState
|
|||
var maxRange = Single.MinValue;
|
||||
foreach (var weapon in _agent.Ship.Weapons)
|
||||
{
|
||||
if (weapon.Range < minRange)
|
||||
minRange = weapon.Range;
|
||||
if (weapon.MinRange < minRange)
|
||||
minRange = weapon.MinRange;
|
||||
if (weapon.Range > maxRange)
|
||||
maxRange = weapon.Range;
|
||||
}
|
||||
|
|
@ -153,7 +153,7 @@ public class CombatState : BaseState
|
|||
float dps = 0;
|
||||
foreach (var weapon in _agent.Ship.Weapons)
|
||||
{
|
||||
if (weapon.Item.Online.Value && weapon.MinRange < range && range < weapon.Range)
|
||||
if (weapon.Item.Online.Value)
|
||||
dps += weapon.RangeDamagePerSecond(range);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,13 +56,13 @@ public class ChargedWeaponData : InstantWeaponData
|
|||
}
|
||||
|
||||
// The one formula of a charged weapon's damage per second at a range (see InstantWeaponData.RangeDamagePerSecond).
|
||||
internal static float RangeDamagePerSecond(BezierCurve damageCurve, float damage, float chargeFiringDamageMultiplier,
|
||||
float minRange, float range, float cooldown, float chargeTime, float atRange) =>
|
||||
damage * chargeFiringDamageMultiplier * damageCurve.Evaluate(saturate(unlerp(minRange, range, atRange))) / (cooldown + chargeTime);
|
||||
internal static float RangeDamagePerSecond(float damage, float chargeFiringDamageMultiplier, float cooldown, float chargeTime,
|
||||
float rangeFactor) =>
|
||||
damage * chargeFiringDamageMultiplier * rangeFactor / (cooldown + chargeTime);
|
||||
|
||||
public override float RatedRangeDamagePerSecond(float range) =>
|
||||
RangeDamagePerSecond(DamageCurve, PerRound(Damage.Max, Count.Max), ChargeFiringDamageMultiplier, MinRange.Max, Range.Max,
|
||||
Cooldown.Max, ChargeTime.Max, range);
|
||||
RangeDamagePerSecond(PerRound(Damage.Max, Count.Max), ChargeFiringDamageMultiplier, Cooldown.Max, ChargeTime.Max,
|
||||
RatedRangeFactor(range));
|
||||
}
|
||||
|
||||
public class ChargedWeapon : InstantWeapon
|
||||
|
|
@ -90,8 +90,8 @@ public class ChargedWeapon : InstantWeapon
|
|||
public override float DamagePerSecond => _unchargedDamage * _data.ChargeFiringDamageMultiplier / (Cooldown + ChargeTime);
|
||||
public override float RangeDamagePerSecond(float range)
|
||||
{
|
||||
return ChargedWeaponData.RangeDamagePerSecond(_data.DamageCurve, _unchargedDamage, _data.ChargeFiringDamageMultiplier,
|
||||
MinRange, Range, Cooldown, ChargeTime, range);
|
||||
return ChargedWeaponData.RangeDamagePerSecond(_unchargedDamage, _data.ChargeFiringDamageMultiplier, Cooldown, ChargeTime,
|
||||
RangeFactor(range));
|
||||
}
|
||||
|
||||
public event Action OnStartCharging;
|
||||
|
|
|
|||
|
|
@ -25,11 +25,10 @@ public class ConstantWeaponData : WeaponData
|
|||
}
|
||||
|
||||
// The one formula of a beam's damage per second at a range (see InstantWeaponData.RangeDamagePerSecond).
|
||||
internal static float RangeDamagePerSecond(BezierCurve damageCurve, float damage, float minRange, float range, float atRange) =>
|
||||
damage * damageCurve.Evaluate(saturate(unlerp(minRange, range, atRange)));
|
||||
internal static float RangeDamagePerSecond(float damage, float rangeFactor) => damage * rangeFactor;
|
||||
|
||||
public override float RatedRangeDamagePerSecond(float range) =>
|
||||
RangeDamagePerSecond(DamageCurve, Damage.Max, MinRange.Max, Range.Max, range);
|
||||
RangeDamagePerSecond(Damage.Max, RatedRangeFactor(range));
|
||||
}
|
||||
|
||||
public class ConstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerConsumer
|
||||
|
|
@ -56,7 +55,7 @@ public class ConstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerC
|
|||
public override float DamagePerSecond => Damage;
|
||||
public override float RangeDamagePerSecond(float range)
|
||||
{
|
||||
return ConstantWeaponData.RangeDamagePerSecond(_data.DamageCurve, Damage, MinRange, Range, range);
|
||||
return ConstantWeaponData.RangeDamagePerSecond(Damage, RangeFactor(range));
|
||||
}
|
||||
|
||||
public event Action OnReloadBegin;
|
||||
|
|
|
|||
|
|
@ -36,11 +36,10 @@ public class InstantWeaponData : WeaponData
|
|||
// UpdateStats and the rated read both use.
|
||||
internal static float PerRound(float total, float burstCount) => total / (int) burstCount;
|
||||
|
||||
internal static float RangeDamagePerSecond(BezierCurve damageCurve, float damage, float minRange, float range, float cooldown, float atRange) =>
|
||||
damage * damageCurve.Evaluate(saturate(unlerp(minRange, range, atRange))) / cooldown;
|
||||
internal static float RangeDamagePerSecond(float damage, float cooldown, float rangeFactor) => damage * rangeFactor / cooldown;
|
||||
|
||||
public override float RatedRangeDamagePerSecond(float range) =>
|
||||
RangeDamagePerSecond(DamageCurve, PerRound(Damage.Max, Count.Max), MinRange.Max, Range.Max, Cooldown.Max, range);
|
||||
RangeDamagePerSecond(PerRound(Damage.Max, Count.Max), Cooldown.Max, RatedRangeFactor(range));
|
||||
}
|
||||
|
||||
public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerConsumer
|
||||
|
|
@ -72,7 +71,7 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerCo
|
|||
public override float DamagePerSecond => Damage / Cooldown;
|
||||
public override float RangeDamagePerSecond(float range)
|
||||
{
|
||||
return InstantWeaponData.RangeDamagePerSecond(_data.DamageCurve, Damage, MinRange, Range, Cooldown, range);
|
||||
return InstantWeaponData.RangeDamagePerSecond(Damage, Cooldown, RangeFactor(range));
|
||||
}
|
||||
|
||||
public override int Ammo
|
||||
|
|
|
|||
|
|
@ -37,8 +37,16 @@ public abstract class WeaponData : BehaviorData
|
|||
[Inspectable, JsonProperty("range"), Key(6)]
|
||||
public PerformanceStat Range = new PerformanceStat();
|
||||
|
||||
[InspectableAnimationCurve, JsonProperty("damageCurve"), Key(7)]
|
||||
public BezierCurve DamageCurve;
|
||||
// Key 7 was the damage curve, retired and never reused.
|
||||
|
||||
// The range up to which a round does its full damage; from here to Range damage lerps to DamageAtMaxRange. Unauthored
|
||||
// is no falloff (Tracking's precedent): +infinity clamps to Range in RangeFactor.
|
||||
[Inspectable, JsonProperty("effectiveRange"), Key(35)]
|
||||
public PerformanceStat EffectiveRange = new PerformanceStat { Min = float.PositiveInfinity, Max = float.PositiveInfinity };
|
||||
|
||||
// The multiplier on damage at Range, the end of the lerp (0 is nothing arriving at maximum range).
|
||||
[Inspectable, JsonProperty("damageAtMaxRange"), Key(36)]
|
||||
public float DamageAtMaxRange;
|
||||
|
||||
[Inspectable, CultInspectorAssetGuid, JsonProperty("effect"), Key(8)]
|
||||
public string EffectPrefab;
|
||||
|
|
@ -76,6 +84,18 @@ public abstract class WeaponData : BehaviorData
|
|||
// design's rated figures, each stat's Max (what a stat with no terms resolves to), through the same formula the
|
||||
// live weapon's RangeDamagePerSecond runs over its evaluated stats. Never the carrier's quality, heat, wear or power.
|
||||
public abstract float RatedRangeDamagePerSecond(float range);
|
||||
public float RatedRangeFactor(float at) => RangeFactor(MinRange.Max, EffectiveRange.Max, Range.Max, DamageAtMaxRange, at);
|
||||
|
||||
// The one function of how much of a weapon's damage arrives at a planar range: 0 outside [min, max] (inclusive, as
|
||||
// FireControl.Designated), 1 up to the effective range, then one lerp to damageAtMax at max. An effective range outside
|
||||
// [min, max] clamps into it.
|
||||
public static float RangeFactor(float min, float effective, float max, float damageAtMax, float at)
|
||||
{
|
||||
if (at < min || at > max) return 0f;
|
||||
var e = clamp(effective, min, max);
|
||||
return e >= max ? 1f : lerp(1f, damageAtMax, saturate(unlerp(e, max, at)));
|
||||
}
|
||||
|
||||
[IgnoreMember]
|
||||
public float RatedRange => Range.Max;
|
||||
}
|
||||
|
|
@ -88,11 +108,13 @@ public abstract class Weapon : Behavior, IActivatedBehavior
|
|||
public abstract float RangeDamagePerSecond(float range);
|
||||
public abstract int Ammo { get; }
|
||||
public WeaponData WeaponData => _data;
|
||||
public float RangeFactor(float at) => WeaponData.RangeFactor(MinRange, EffectiveRange, Range, _data.DamageAtMaxRange, at);
|
||||
|
||||
public float Damage { get; protected set; }
|
||||
public float Penetration { get; protected set; }
|
||||
public float DamageSpread { get; protected set; }
|
||||
public float MinRange { get; protected set; }
|
||||
public float EffectiveRange { get; protected set; }
|
||||
public float Range { get; protected set; }
|
||||
public float Energy { get; protected set; }
|
||||
public float Heat { get; protected set; }
|
||||
|
|
@ -141,6 +163,7 @@ public abstract class Weapon : Behavior, IActivatedBehavior
|
|||
Penetration = Evaluate(_data.Penetration);
|
||||
DamageSpread = Evaluate(_data.DamageSpread);
|
||||
MinRange = Evaluate(_data.MinRange);
|
||||
EffectiveRange = Evaluate(_data.EffectiveRange);
|
||||
Range = Evaluate(_data.Range);
|
||||
Energy = Evaluate(_data.Energy);
|
||||
Heat = Evaluate(_data.Heat);
|
||||
|
|
|
|||
|
|
@ -584,7 +584,8 @@ public static class FireControl
|
|||
// it whether a round is refused before they spend anything -- so a refusal is decided once, by the same
|
||||
// code that would have flown the round, and the HUD cannot forecast a burst the trigger will not fire.
|
||||
// Direct: a round that resolves against its target (a weapon without a fuse). Burst: a fused round, with
|
||||
// BurstReach the planar distance from the shooter at which it bursts. Refused: a fused round whose blast
|
||||
// BurstReach the planar distance from the shooter at which the payload is delivered (a direct round's target, a fused
|
||||
// round's burst point, 0 for an untargeted direct round), which Fire's range factor reads for every outcome. Refused: a fused round whose blast
|
||||
// radius (its arming distance) exceeds the weapon's Range; it cannot be fired.
|
||||
public static FireSolution Solve(Weapon weapon, EquippedItem item, Entity source, Entity target)
|
||||
{
|
||||
|
|
@ -722,7 +723,8 @@ public static class FireControl
|
|||
Target = engaged,
|
||||
Weapon = item,
|
||||
Aimed = source.ResolvedTargetItem,
|
||||
Damage = damageOverride ?? weapon.Damage,
|
||||
// The one place a shot's damage meets range, frozen here: BurstReach is where the payload is delivered.
|
||||
Damage = (damageOverride ?? weapon.Damage) * weapon.RangeFactor(solution.BurstReach),
|
||||
Penetration = weapon.Penetration,
|
||||
DamageSpread = weapon.DamageSpread,
|
||||
DamageType = weapon.WeaponData.DamageType,
|
||||
|
|
@ -2038,8 +2040,8 @@ public struct GunSolution
|
|||
public float2 Direction;
|
||||
}
|
||||
|
||||
// Solve's answer. Outcome and BurstReach (planar distance from the shooter to the burst point, read for Burst
|
||||
// only) are what the HUD shows; the rest is what Fire freezes into the PendingShot.
|
||||
// Solve's answer. Outcome and BurstReach (planar distance from the shooter to the burst point; the HUD reads it for
|
||||
// Burst, Fire's range factor for both outcomes) are what the HUD shows; the rest is what Fire freezes into the PendingShot.
|
||||
public struct FireSolution
|
||||
{
|
||||
public FireOutcome Outcome;
|
||||
|
|
|
|||
Loading…
Reference in a new issue