pub struct Fac {
pub factions: Vec<FacFaction>,
pub reputations: Vec<FacReputation>,
}Expand description
Typed FAC model built from/to Gff data.
Fields§
§factions: Vec<FacFaction>Faction roster (FactionList). A faction’s id is its index here.
reputations: Vec<FacReputation>Stored pairwise standings (RepList). Sparse: see Fac::reputation.
The write is hand-written because the filter runs on the typed element, where the standing it tests is reachable. The read generates, and reaches the element’s own hand-written codec through it.
Implementations§
Source§impl Fac
impl Fac
Sourcepub const PARTS: &'static [&'static [Field]]
pub const PARTS: &'static [&'static [Field]]
This type’s schema in parts, which is what a container holding it references.
Own fields first, then one part per flattened child in the order they are declared.
Sourcepub fn read_declared(root: &GffStruct) -> Self
pub fn read_declared(root: &GffStruct) -> Self
Reads every declared field off root.
Absent fields take the entry’s own answer, so a fallback is derived from the declaration rather than restated beside it.
A field declaring a hand-written read is left at that answer for the view to overwrite.
Sourcepub fn write_declared(&self, root: &mut GffStruct)
pub fn write_declared(&self, root: &mut GffStruct)
Writes every declared field onto root, leaving out the ones
their entry says the engine’s own writer leaves out.
A field declaring a hand-written write is not touched here.
Sourcepub fn read_element(structure: &GffStruct) -> Self
pub fn read_element(structure: &GffStruct) -> Self
Reads one element of a list of this type.
Source§impl Fac
impl Fac
Sourcepub fn reputation(&self, source: u32, target: u32) -> u8
pub fn reputation(&self, source: u32, target: u32) -> u8
Returns how source regards target.
Applies the sparse-matrix rule: a pair with no stored entry is
DEFAULT_REPUTATION. Ids are faction indices into
Self::factions; an id no faction occupies still answers with the
baseline, matching the engine rebuilding its matrix before applying
overrides.
Sourcepub fn reaction(&self, source: u32, target: u32) -> FacReaction
pub fn reaction(&self, source: u32, target: u32) -> FacReaction
Returns how source reacts to target.
Sourcepub fn faction(&self, id: u32) -> Option<&FacFaction>
pub fn faction(&self, id: u32) -> Option<&FacFaction>
Returns the faction at id, when the roster has one.
Sourcepub fn from_gff(gff: &Gff) -> Result<Self, FacError>
pub fn from_gff(gff: &Gff) -> Result<Self, FacError>
Builds typed FAC data from a parsed GFF container.
§Errors
Returns an error when the container is not a FAC (or generic GFF).
Sourcepub fn to_gff(&self) -> Gff
pub fn to_gff(&self) -> Gff
Converts this typed FAC value into a GFF container.
Writes the table the way the engine’s own writer does, which means pairs at the default standing are dropped rather than emitted. The two forms are identical to the engine, but other tools read these files too, and a diff against a vanilla save should not show pairs the game would never have written.
Only pairs whose effective standing is the default are dropped, so a deliberately out-of-range value is still written out.
§Panics
Panics where the reputation list holds more than i32::MAX entries,
since an element’s struct id is its own index. A table that large
cannot be built from any file this crate reads.