Expand description
Shield absorption and delayed regeneration independent of health/damage types.
State uses independent axes, with no phase precedence: an empty shield can
be delayed or recharging. A zero maximum is both full and broken. A zero
maximum or rate disables recharge, but confirmed positive hits still start
the delay and simulation time still consumes it. recharging means eligible
to recharge; very small advances can round to no stored value change.
Advance only on executed simulation ticks. Restart by replacing the shield
with Shield::new using the run’s authored configuration. This helper has
no attack admission, health, feedback queue, save format, or clock ownership.
use ferravex_play::gameplay::shield::{Shield, ShieldValuePolicy};
let mut shield = Shield::new(20., 8., 4.).unwrap();
assert_eq!((shield.maximum(), shield.recharge_rate(), shield.recharge_delay()),
(20., 8., 4.));
let hit = shield.absorb_detailed(25.).unwrap(); // After host hit admission.
assert_eq!((hit.absorbed, hit.unabsorbed), (20., 5.));
assert_eq!(hit.change.value_change(), -20.);
assert!(hit.change.depleted());
assert!(shield.state().broken && shield.state().delayed);
assert_eq!(shield.delay_remaining(), 4.);
let waiting = shield.advance_detailed(4.).unwrap();
assert!(waiting.after.recharging);
assert!(!waiting.recovered()); // Delay expiry alone is not recovery.
let recharge = shield.advance_detailed(1.).unwrap();
assert_eq!(recharge.value_change(), 8.);
assert!(recharge.recovered());
shield.reconfigure(40., 8., 4., ShieldValuePolicy::PreserveValue).unwrap();
assert_eq!(shield.value(), 8.); // Growth grants no free charge.
shield.reconfigure(20., 8., 4., ShieldValuePolicy::PreserveRatio).unwrap();
assert_eq!(shield.value(), 4.);
assert!(shield.advance_detailed(3600.).unwrap().filled());
assert!(!shield.advance_detailed(0.).unwrap().filled());Structs§
- Shield
- Fixed-storage, Copy shield; existing fields and legacy arithmetic retained.
- Shield
Absorption - Damage routing plus actual stored charge change for one accepted hit.
absorbeduses legacy damage arithmetic and can differ from the magnitude ofchange.value_change()because f32 subtraction rounds.unabsorbedis exactly what legacyShield::absorbreturns for the host’s health rules. - Shield
Change - Before/after values for one successful operation, without queued events.
Reconfiguration transitions describe charge edits, not gameplay recovery;
consume recovery feedback from an accepted
advance_detailedreceipt only. - Shield
State - Read-only snapshot. Flags are independent; see the module’s state contract and executable example. No field is an emitted event.
Enums§
- Shield
Value Policy - Explicit charge policy for
Shield::reconfigure.