Struct Shield

Source
pub struct Shield { /* private fields */ }
Expand description

Fixed-storage, Copy shield; existing fields and legacy arithmetic retained.

Implementations§

Source§

impl Shield

Source

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.

Source

pub fn value(&self) -> f32

Source

pub fn maximum(&self) -> f32

Configured capacity; inspection does not advance the shield.

Source

pub fn recharge_rate(&self) -> f32

Configured charge per simulation second; zero disables recharge.

Source

pub fn recharge_delay(&self) -> f32

Configured delay for subsequent positive confirmed hits, in seconds.

Source

pub fn delay_remaining(&self) -> f64

Live delay in seconds without reducing the precision of the f64 timer.

Source

pub fn state(&self) -> ShieldState

Inspect independent state axes; see the module example and contract.

Source

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.

Source

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.

Source

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.

Source

pub fn advance(&mut self, dt: f32) -> Result<(), LoopError>

Advance using legacy delay/recharge arithmetic; see Self::advance_detailed.

Source

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.

Trait Implementations§

Source§

impl Clone for Shield

Source§

fn clone(&self) -> Shield

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Shield

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Copy for Shield

Auto Trait Implementations§

§

impl Freeze for Shield

§

impl RefUnwindSafe for Shield

§

impl Send for Shield

§

impl Sync for Shield

§

impl Unpin for Shield

§

impl UnwindSafe for Shield

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.