pub struct CompiledRuleset {
pub hooks: HashMap<EffectId, CompiledHook>,
pub types: Vec<String>,
pub stats: Vec<String>,
pub resources: Vec<String>,
pub move_costs: HashMap<String, Vec<(usize, u16)>>,
pub statuses: HashMap<String, usize>,
pub type_chart: HashMap<(usize, usize), (u32, u32)>,
}Expand description
A compiled ruleset: the synthesized-id → CompiledHook map plus the
interned types/stats vocabularies (doc 11 §2 side registry). Built once at
load, addressed by EffectId, so a hot-reload swaps the map between turns
without invalidating in-flight engine EffectState (doc 11 §4.2).
Fields§
§hooks: HashMap<EffectId, CompiledHook>EffectId → compiled hook (the interpreter’s lookup; doc 11 §2).
types: Vec<String>Interned type names (index = chart index).
stats: Vec<String>Interned stat names (index = stat index).
resources: Vec<String>Interned resource names (index = resource index; the MP/SP/mana cost gate, doc 13 §4). The game binding maps each ↔ the engine’s opaque resource id.
move_costs: HashMap<String, Vec<(usize, u16)>>Per-move resource cost: the move record’s source_id → the list of
(resource_index, amount) it costs (doc 13 §4). The game reads this to
implement BattleProvider::move_cost
so the engine’s cost gate fires. Empty for a move with no cost:.
statuses: HashMap<String, usize>Status-name → the GAME’s status index (resolved at compile via the
game-supplied status_index_of). The RON stats: list does NOT carry
statuses; this map is the closed status vocabulary the interpreter reads.
type_chart: HashMap<(usize, usize), (u32, u32)>The interned type chart (doc 12 §2): (atk_type_index, def_type_index) →
(num, den), keyed by the ruleset’s types: intern indices. Omitted pairs
default to (1, 1) at lookup via chart_mult.
The DATA layer OWNS the chart here — a hot-reload of the RON type_chart
rebuilds this map and the binding reads it, so the relation is genuinely
data-driven (not a hardcoded native const). Built once at compile; an
unknown type name in an edge is a LoadError.
Implementations§
Source§impl CompiledRuleset
impl CompiledRuleset
Sourcepub fn status_index(&self, name: &str) -> Option<usize>
pub fn status_index(&self, name: &str) -> Option<usize>
The game status index for a status name (the interpreter’s InflictStatus
lookup), validated at compile.
Sourcepub fn chart_mult(
&self,
atk_type_index: usize,
def_type_index: usize,
) -> (u32, u32)
pub fn chart_mult( &self, atk_type_index: usize, def_type_index: usize, ) -> (u32, u32)
The interned chart multiplier (num, den) for an attacker-type index vs a
defender-type index (the indices are the ruleset’s types: positions).
Omitted pairs default to (1, 1) (neutral) — doc 12 §2. Pure; no RNG. The
game binding folds the product over a defender’s type(s) and applies ONE
scale (doc 12 §5.3), so the data path owns the relation end to end.
Source§impl CompiledRuleset
impl CompiledRuleset
Sourcepub fn compile<P, B>(
ruleset: &Ruleset,
id_base: u32,
bindings: &B,
status_index_of: impl Fn(&str) -> Option<usize>,
) -> Result<Self, LoadError>where
P: EffectProvider,
B: RuleBindings<P>,
pub fn compile<P, B>(
ruleset: &Ruleset,
id_base: u32,
bindings: &B,
status_index_of: impl Fn(&str) -> Option<usize>,
) -> Result<Self, LoadError>where
P: EffectProvider,
B: RuleBindings<P>,
Compile a Ruleset, minting one EffectId per hook starting at
id_base (doc 11 §2.2 Option A). All closed-vocabulary binding happens
here: every on: event, every HasType/StatIs/chart type name, every
chance fraction is validated NOW — an unknown name/op is a LoadError
at LOAD, never at battle time (doc 11 §4.2).
bindings resolves status/stat names to indices (defense-in-depth: the
loader also pre-validates names against the ruleset’s stats: list, but
status names are the game’s vocabulary, so the binding is the authority).
Sourcepub fn hook(&self, id: EffectId) -> Option<&CompiledHook>
pub fn hook(&self, id: EffectId) -> Option<&CompiledHook>
The compiled hook for an EffectId (the interpreter’s lookup).
Sourcepub fn move_cost(&self, source_id: &str) -> &[(usize, u16)]
pub fn move_cost(&self, source_id: &str) -> &[(usize, u16)]
The resource cost of the move with record id source_id, as interned
(resource_index, amount) pairs (doc 13 §4). Empty for a move with no
cost:. The game maps each resource_index to its engine resource id (via
the binding) to build BattleProvider::move_cost.
Sourcepub fn build_effects<P>(&self) -> Vec<&'static Effect<P>>where
P: RulesProvider,
pub fn build_effects<P>(&self) -> Vec<&'static Effect<P>>where
P: RulesProvider,
Build the &'static-shaped per-hook Effect registry that the game’s
defaulted resolvers hand back to the engine. Because the engine requires
&'static [EventHook], the caller leaks these once at load (a deliberate
one-time leak — the registry lives for the whole battle; doc 11 §4.2 notes
a reload swaps the map, not in-flight state). Each Effect has ONE hook
whose call is interpret::<P> and whose id keys the op-list.
Trait Implementations§
Source§impl Clone for CompiledRuleset
impl Clone for CompiledRuleset
Source§fn clone(&self) -> CompiledRuleset
fn clone(&self) -> CompiledRuleset
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more