Skip to main content

CompiledRuleset

Struct CompiledRuleset 

Source
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

Source

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.

Source

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

Source

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

Source

pub fn hook(&self, id: EffectId) -> Option<&CompiledHook>

The compiled hook for an EffectId (the interpreter’s lookup).

Source

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.

Source

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

Source§

fn clone(&self) -> CompiledRuleset

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CompiledRuleset

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.