Skip to main content

BattleCtx

Struct BattleCtx 

Source
pub struct BattleCtx<'a, P: EffectProvider + ?Sized> {
    pub state: &'a mut BattleState<P>,
    pub effects: &'a mut Vec<EffectState<P>>,
    pub mv: &'a mut MoveContext,
    pub rng: &'a mut dyn BattleRng,
}
Expand description

Split-borrow context handed to every handler (design §3.2). A handler’s only mutable path into the battle is through this struct’s accessors.

Fields§

§state: &'a mut BattleState<P>

The shared battle state (the two party Vecs live here).

§effects: &'a mut Vec<EffectState<P>>

The per-effect-instance arena, kept sorted by id.

§mv: &'a mut MoveContext

Per-move scratch.

§rng: &'a mut dyn BattleRng

The ONLY randomness source (design §4).

Implementations§

Source§

impl<'a, P: EffectProvider + ?Sized> BattleCtx<'a, P>

Source

pub fn battler_mut(&mut self, r: BattlerRef) -> &mut BattlerState<P>

One battler as &mut. Cross-side is trivial (two different Vecs).

Source

pub fn battler(&self, r: BattlerRef) -> &BattlerState<P>

One battler as & (read-only).

Source

pub fn pair_mut( &mut self, a: BattlerRef, b: BattlerRef, ) -> (&mut BattlerState<P>, &mut BattlerState<P>)

Two disjoint battler refs as two &mut (design §3.2). This is the borrow-checker crux that lets a Counter-shaped handler mutate target while reading source’s host.

  • Cross-side (a.side != b.side): the two sides are separate Vecs, so the refs are provably non-aliasing. This is the one localized, documented unsafe in the engine hot path (design §3.2).
  • Same-side: a real disjoint split via split_at_mutfully safe, no raw pointer. (Once MSRV permits, <[T]>::get_disjoint_mut.)
§Panics

Debug-asserts a != b (the two refs must address distinct battlers).

Source

pub fn effect_mut(&mut self, id: EffectId) -> Option<&mut EffectState<P>>

Mutable access to a live effect’s state by id (binary search; the arena is kept sorted). Returns None if no such effect is live.

Source

pub fn effect(&self, id: EffectId) -> Option<&EffectState<P>>

Read access to a live effect’s state by id.

Source

pub fn install_effect( &mut self, host: BattlerRef, kind: P::EffectStateKind, ) -> EffectId

Install a new game-defined effect (volatile) on host, allocating a fresh arena id + creation order and keeping the arena sorted by id. Returns the new id. The engine treats kind OPAQUELY — this is the generic seam a data InflictVolatile op uses; the game constructs the P::EffectStateKind (via its binding) and the engine only stores it.

Auto Trait Implementations§

§

impl<'a, P> !RefUnwindSafe for BattleCtx<'a, P>

§

impl<'a, P> !Send for BattleCtx<'a, P>

§

impl<'a, P> !Sync for BattleCtx<'a, P>

§

impl<'a, P> !UnwindSafe for BattleCtx<'a, P>

§

impl<'a, P> Freeze for BattleCtx<'a, P>
where P: ?Sized,

§

impl<'a, P> Unpin for BattleCtx<'a, P>
where P: ?Sized,

§

impl<'a, P> UnsafeUnpin for BattleCtx<'a, P>
where P: ?Sized,

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> 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, 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.