pub struct Shield { /* private fields */ }Expand description
Fixed-storage, Copy shield; existing fields and legacy arithmetic retained.
Implementations§
Source§impl Shield
impl Shield
Sourcepub fn new(maximum: f32, rate: f32, delay: f32) -> Result<Shield, LoopError>
pub fn new(maximum: f32, rate: f32, delay: f32) -> Result<Shield, LoopError>
Start full with finite maximum/rate in 0..=1e6, delay in 0..=3600
seconds. Invalid input returns LoopError::Invalid. See module example.
pub fn value(&self) -> f32
Sourcepub fn recharge_rate(&self) -> f32
pub fn recharge_rate(&self) -> f32
Configured charge per simulation second; zero disables recharge.
Sourcepub fn recharge_delay(&self) -> f32
pub fn recharge_delay(&self) -> f32
Configured delay for subsequent positive confirmed hits, in seconds.
Sourcepub fn delay_remaining(&self) -> f64
pub fn delay_remaining(&self) -> f64
Live delay in seconds without reducing the precision of the f64 timer.
Sourcepub fn state(&self) -> ShieldState
pub fn state(&self) -> ShieldState
Inspect independent state axes; see the module example and contract.
Sourcepub fn reconfigure(
&mut self,
maximum: f32,
rate: f32,
delay: f32,
policy: ShieldValuePolicy,
) -> Result<ShieldChange, LoopError>
pub fn reconfigure( &mut self, maximum: f32, rate: f32, delay: f32, policy: ShieldValuePolicy, ) -> Result<ShieldChange, LoopError>
Atomically validate and replace maximum/rate/delay using Self::new’s
ranges, then apply the explicit value policy. See the module example.
The live timer becomes min(old_remaining, new_delay): shorter delays
cap a pending wait, longer delays never extend it, and elapsed waits
never restart. Rate-only and repeated identical edits preserve the wait.
The next positive hit uses the new full delay, even when empty/disabled.
PreserveValue clamps on shrink and never heals on growth. PreserveRatio
may deliberately add charge, with fraction zero for an old zero maximum.
Rejected configurations leave every field unchanged.
Sourcepub fn absorb(&mut self, damage: f32) -> Result<f32, LoopError>
pub fn absorb(&mut self, damage: f32) -> Result<f32, LoopError>
Returns unabsorbed damage for the host’s health rules. Zero damage does not reset recovery; nonzero confirmed hits reset even an empty shield.
Sourcepub fn absorb_detailed(
&mut self,
damage: f32,
) -> Result<ShieldAbsorption, LoopError>
pub fn absorb_detailed( &mut self, damage: f32, ) -> Result<ShieldAbsorption, LoopError>
Apply an already admitted hit with legacy arithmetic. Finite damage in
0..=1e6 is accepted; invalid damage changes nothing. Zero never refreshes
delay or emits depletion. Positive damage refreshes even an empty shield.
See the module example. This method does not admit/deduplicate attacks.
Sourcepub fn advance(&mut self, dt: f32) -> Result<(), LoopError>
pub fn advance(&mut self, dt: f32) -> Result<(), LoopError>
Advance using legacy delay/recharge arithmetic; see Self::advance_detailed.
Sourcepub fn advance_detailed(&mut self, dt: f32) -> Result<ShieldChange, LoopError>
pub fn advance_detailed(&mut self, dt: f32) -> Result<ShieldChange, LoopError>
Advance finite simulation seconds in 0..=3600, consuming delay first.
Invalid dt changes nothing. Reports actual f32 charge change after capping
and rounding; no repeat recovery/full signal on no-op advances. See the
module example. A large step can both recover from zero and fill.
Each call rounds charge to f32, as before. Partitioning time therefore has floating-point tolerance, not a bitwise equality guarantee (and very small increments may all round away). Delay is retained in f64.