Skip to main content

Module driver

Module driver 

Source
Expand description

Generic, game-agnostic battle turn-execution driver (P0b).

BattleDriver::execute_turn sits above the existing BattleProvider/BattlerState/BattleState abstraction and owns the control flow of a single battle turn:

  1. Ask the provider for each actor’s OrderKey and stable-sort them ascending (turn order — C4).
  2. For each actor in order: run the before_move pre-move status gate, then execute its action — for Fight, an accuracy_check followed by calculate_damage; for Switch, apply_switch. Faints are detected after each hit.
  3. Run the end_of_turn residual hook.
  4. Fold everything into a TurnOutcome and detect a BattleEnd.

Every number and rule decision (the damage formula, accuracy/crit math, status semantics, residual ordering, turn-order tie-breaks) lives in the provider; the driver only sequences. All randomness is injected through BattleRng so the engine never links rand and the game controls the exact draw sequence (C2).

The driver is event-sourced: it returns a Vec<TurnEvent> that the game maps onto its own UI/animation state machine, keeping rendering out of the engine and making the driver unit-testable without a screen.

Structs§

BattleDriver
The generic turn-execution driver. Stateless: state goes in, events come out.
TurnOutcome
The result of executing one turn.

Enums§

BattleEnd
How a battle ended, if it ended this turn.
TurnEvent
A single observable event produced during turn execution.