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 MoveContextPer-move scratch.
rng: &'a mut dyn BattleRngThe ONLY randomness source (design §4).
Implementations§
Source§impl<'a, P: EffectProvider + ?Sized> BattleCtx<'a, P>
impl<'a, P: EffectProvider + ?Sized> BattleCtx<'a, P>
Sourcepub fn battler_mut(&mut self, r: BattlerRef) -> &mut BattlerState<P>
pub fn battler_mut(&mut self, r: BattlerRef) -> &mut BattlerState<P>
One battler as &mut. Cross-side is trivial (two different Vecs).
Sourcepub fn battler(&self, r: BattlerRef) -> &BattlerState<P>
pub fn battler(&self, r: BattlerRef) -> &BattlerState<P>
One battler as & (read-only).
Sourcepub fn pair_mut(
&mut self,
a: BattlerRef,
b: BattlerRef,
) -> (&mut BattlerState<P>, &mut BattlerState<P>)
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 separateVecs, so the refs are provably non-aliasing. This is the one localized, documentedunsafein the engine hot path (design §3.2). - Same-side: a real disjoint split via
split_at_mut— fully safe, no raw pointer. (Once MSRV permits,<[T]>::get_disjoint_mut.)
§Panics
Debug-asserts a != b (the two refs must address distinct battlers).
Sourcepub fn effect_mut(&mut self, id: EffectId) -> Option<&mut EffectState<P>>
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.
Sourcepub fn effect(&self, id: EffectId) -> Option<&EffectState<P>>
pub fn effect(&self, id: EffectId) -> Option<&EffectState<P>>
Read access to a live effect’s state by id.
Sourcepub fn install_effect(
&mut self,
host: BattlerRef,
kind: P::EffectStateKind,
) -> EffectId
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.