Skip to main content

Module battle

Module battle 

Source
Expand description

Battle system trait definitions for a JRPG engine framework.

This module defines the core abstractions for turn-based battle systems: battle state, battler state, type charts, AI decision-making, and move effect handling. All types are generic over a BattleProvider implementation — the engine is game-agnostic.

§Architecture

  • BattleProvider — Central trait supplying battle data, damage formula, and factory methods. All methods take &self (read-only provider).
  • TypeChart — N×N type effectiveness matrix, parameterized by game types.
  • BattleAI — Move selection, switching, and item-use decisions.
  • EffectHandler — Dispatches move effects (damage, healing, status, stat changes) on battler state.

§Design Principles

  • Generic over game data — No concrete game-specific, monster, or move types. All identifiers are associated types on BattleProvider.
  • Provider pattern — Battle systems query the provider, which delegates to type charts, AI, and effect handlers internally.
  • No I/O, no platform — Pure data and trait definitions only.

Re-exports§

pub use ai::BattleAi;
pub use ai::BattleAiProvider;
pub use driver::BattleDriver;
pub use driver::BattleEnd;
pub use driver::TurnEvent;
pub use driver::TurnOutcome;
pub use rng::BattleRng;

Modules§

ai
Generic, game-agnostic battle AI driver (P0c).
driver
Generic, game-agnostic battle turn-execution driver (P0b).
rng
Injected randomness for the battle turn-execution driver (P0b).
stack
Showdown-style effect-stack battle engine (Pattern C) — vertical-slice POC (design doc 06-battle-engine-effect-stack-design.md, §8).

Structs§

BattleState
The complete state of an ongoing battle.
BattlerRef
A reference to one battler position on the battlefield.
BattlerState
The battle state of a single monster/character.
DamageResult
Result of a damage calculation.
EnumMap
A map from enum-like keys to values, backed by a Vec of (K, V) pairs.
OrderKey
A turn-ordering sort key produced by BattleProvider::turn_order_key.
ResourcePool
A per-battler pool of generic, game-defined consumable resources (MP / SP / TP / mana / charge — the engine assigns the concept no name; doc 13 §4, the highest-value STATE-SEAM).

Enums§

BattleAction
The action a battler has chosen to take this turn.
EffectResult
Outcome of applying a move effect.
MoveEffect
Categories of additional effects a move can have.
MoveGate
Result of BattleProvider::before_move: the pre-move status gate.
Terrain
Field terrain condition.
Weather
Field weather condition.

Traits§

BattleAI
AI decision-making for battle actions.
BattleProvider
Central trait for battle system data and formula implementations.
EffectHandler
Handles move effects on battler state.
TypeChart
N×N type effectiveness matrix.