Cut 4: input capacitors close the last direct capacitor spend
Deletes Entity.CanSpendCapacitorCharge/TrySpendCapacitorCharge (and the now-dead _capacitors bookkeeping list that only fed them) -- Cut 3's named, temporary exception for the four instant draws. InstantWeapon (both fire sites), Sensor.Ping, and Shield.CanTakeHit/TakeHit now spend from their own InputCapacitor, filled continuously by PowerBus like every other IPowerConsumer instead of touching the entity's shared bus capacitors directly. InputCapacitor's Capacity/Rate derive from the owning item's Energy and Cooldown, with an authored-override hook (ChargedWeapon repurposes its previously-unused ChargeEnergy stat as that override, per the map's own instruction, rather than adding a new field). A weapon/sensor fire attempt only ever spends exactly Capacity, so it only ever succeeds at full charge -- no fractional shot. Shield is the map's named exception: its reserve is continuous, not an activation buffer, so it allows a partial draw; its size (no Energy/Cooldown pair exists on Shield) is a flagged judgment call, not a spec'd formula. Adds InputCapacitorTests.cs (8 tests) and mutation_tests_stats_power_cut4.py (7 mutations, all behave as declared); removes the one PowerBusTests.cs test and Cut 3 mutation case that exercised the now-deleted Entity methods. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
fc80c8944b
commit
8dacabb3d8
12 changed files with 677 additions and 90 deletions
|
|
@ -50,9 +50,13 @@ public class SensorData : BehaviorData
|
|||
}
|
||||
}
|
||||
|
||||
public class Sensor : Behavior, IEventBehavior
|
||||
public class Sensor : Behavior, IEventBehavior, IPowerConsumer
|
||||
{
|
||||
private SensorData _data;
|
||||
|
||||
// Cut 4 (docs/stats-and-power-cut.md, Cut 4): replaces the direct Entity.TrySpendCapacitorCharge spend in
|
||||
// Ping() below -- the named, temporary exception Cut 3 left standing.
|
||||
private readonly InputCapacitor _capacitor = new InputCapacitor();
|
||||
private float _pingCooldown;
|
||||
private float _pingLerp;
|
||||
private bool _pinging;
|
||||
|
|
@ -80,11 +84,28 @@ public class Sensor : Behavior, IEventBehavior
|
|||
OnPingEnd = null;
|
||||
}
|
||||
|
||||
// Cut 3 (docs/stats-and-power-cut.md): one of the four instant draws out of scope for the bus this cut (a
|
||||
// ping) -- named, temporary exception, spending capacitor charge directly. Cut 4 closes this.
|
||||
// Cut 4: capacity/rate, resolved fresh (Capacitor.ResolveCapacity's precedent -- PowerBus.Step calls
|
||||
// PowerRequest below before this behaviour's own Execute runs this tick).
|
||||
private void RefreshInputCapacitor()
|
||||
{
|
||||
var energy = Evaluate(_data.PingEnergy);
|
||||
var cooldown = Evaluate(_data.PingCooldown);
|
||||
_capacitor.UpdateStats(energy, cooldown);
|
||||
}
|
||||
|
||||
// Cut 4: the request PowerBus needs before Execute runs.
|
||||
public float PowerRequest(float dt)
|
||||
{
|
||||
RefreshInputCapacitor();
|
||||
return _capacitor.RequestedFill(dt);
|
||||
}
|
||||
|
||||
public void Ping()
|
||||
{
|
||||
if(_pingCooldown < 0 && Entity.TrySpendCapacitorCharge(Evaluate(_data.PingEnergy)))
|
||||
// Whole-or-nothing against the ping's own input capacitor -- fires only at full charge (operator
|
||||
// ruling: no fraction of a shot). A consumable-hosted instance (Item == null) has no PowerBus entry, so
|
||||
// nothing would ever fill this capacitor; bypass it rather than starving such an instance forever.
|
||||
if(_pingCooldown < 0 && (Item == null || _capacitor.TrySpend(_capacitor.Capacity)))
|
||||
{
|
||||
Entity.VisibilitySources[this] = Evaluate(_data.PingVisibility);
|
||||
_pinging = true;
|
||||
|
|
@ -108,6 +129,10 @@ public class Sensor : Behavior, IEventBehavior
|
|||
|
||||
public override bool Execute(float dt)
|
||||
{
|
||||
// Cut 4: this tick's grant, read back via Item.PowerSupply -- Item is non-null here because a null-Item
|
||||
// instance never reaches PowerBus.Step (see Ping()) and so never accrues charge.
|
||||
if (Item != null)
|
||||
_capacitor.AddCharge(_capacitor.RequestedFill(dt) * Item.PowerSupply);
|
||||
if (_pinging)
|
||||
{
|
||||
_pingLerp += dt / _data.PingDuration;
|
||||
|
|
|
|||
Loading…
Reference in a new issue