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
|
|
@ -26,13 +26,24 @@ public class ShieldData : BehaviorData
|
|||
}
|
||||
}
|
||||
|
||||
public class Shield : Behavior, IProgressBehavior
|
||||
public class Shield : Behavior, IProgressBehavior, IPowerConsumer
|
||||
{
|
||||
public float Efficiency { get; private set; }
|
||||
public float EnergyUsage { get; private set; }
|
||||
|
||||
private ShieldData _data;
|
||||
|
||||
// Cut 4 (docs/stats-and-power-cut.md, Cut 4): "a shield hit is not an activation the player chose, so its
|
||||
// 'instant' draw is really a continuous reserve. Name it as such rather than giving it an activation
|
||||
// buffer." Unlike InstantWeapon/Sensor above, TrySpend below is never called with exactly Capacity -- a hit
|
||||
// can partially draw the reserve, same as the old direct capacitor spend could. Shield has no Energy/
|
||||
// Cooldown pair to derive a size from (only EnergyUsage, a per-damage-point multiplier), so this is a
|
||||
// judgment call, not a formula the map states: the reserve's Capacity and Rate both default to EnergyUsage
|
||||
// itself, refilling in full every second (Cooldown's implicit identity value -- the same "absent means
|
||||
// identity" convention InputCapacitor and PerformanceStat itself already use). Flagged for operator review
|
||||
// against real catalog EnergyUsage magnitudes rather than presented as spec'd.
|
||||
private readonly InputCapacitor _reserve = new InputCapacitor();
|
||||
|
||||
public Shield(ShieldData data, EquippedItem item) : base(data, item)
|
||||
{
|
||||
_data = data;
|
||||
|
|
@ -42,24 +53,44 @@ public class Shield : Behavior, IProgressBehavior
|
|||
_data = data;
|
||||
}
|
||||
|
||||
// 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 RefreshReserve()
|
||||
{
|
||||
var energyUsage = Evaluate(_data.EnergyUsage);
|
||||
_reserve.UpdateStats(energyUsage, cooldown: 1f);
|
||||
}
|
||||
|
||||
// Cut 4: the request PowerBus needs before Execute runs.
|
||||
public float PowerRequest(float dt)
|
||||
{
|
||||
RefreshReserve();
|
||||
return _reserve.RequestedFill(dt);
|
||||
}
|
||||
|
||||
public override bool Execute(float dt)
|
||||
{
|
||||
Efficiency = Evaluate(_data.Efficiency);
|
||||
EnergyUsage = Evaluate(_data.EnergyUsage);
|
||||
// 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 CanTakeHit/TakeHit) and so never accrues charge.
|
||||
if (Item != null)
|
||||
_reserve.AddCharge(_reserve.RequestedFill(dt) * Item.PowerSupply);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Cut 3 (docs/stats-and-power-cut.md): one of the four instant draws out of scope for the bus this cut (a
|
||||
// hit taken, not a chosen activation) -- named, temporary exception, spending capacitor charge directly
|
||||
// instead of through PowerBus. Cut 4 gives it a real continuous reserve model and closes this.
|
||||
// Cut 4 (docs/stats-and-power-cut.md, Cut 4): a hit taken, not a chosen activation, drawing from the
|
||||
// shield's own continuous reserve instead of the entity's shared bus capacitors -- closing Cut 3's named,
|
||||
// temporary exception. A consumable-hosted instance (Item == null) has no PowerBus entry, so nothing would
|
||||
// ever fill this reserve; bypass it rather than starving such an instance forever.
|
||||
public bool CanTakeHit(DamageType type, float damage)
|
||||
{
|
||||
return Entity.CanSpendCapacitorCharge(damage * EnergyUsage);
|
||||
return Item == null || _reserve.CanSpend(damage * EnergyUsage);
|
||||
}
|
||||
|
||||
public void TakeHit(DamageType type, float damage)
|
||||
{
|
||||
Entity.TrySpendCapacitorCharge(damage * EnergyUsage);
|
||||
if (Item != null) _reserve.TrySpend(damage * EnergyUsage);
|
||||
AddHeat(damage / Efficiency);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue