tiger-lib 1.18.0

Library used by the tools ck3-tiger, vic3-tiger, and imperator-tiger. This library holds the bulk of the code for them. It can be built either for ck3-tiger with the feature ck3, or for vic3-tiger with the feature vic3, or for imperator-tiger with the feature imperator, but not both at the same time.
Documentation
use crate::block::Block;
use crate::ck3::data::titles::Tier;
use crate::ck3::modif::ModifKinds;
use crate::db::{Db, DbKind};
use crate::everything::Everything;
use crate::game::GameFlags;
use crate::item::{Item, ItemLoader};
use crate::modif::validate_modifs;
use crate::report::{ErrorKey, fatal, warn};
use crate::token::Token;
use crate::validator::Validator;

#[derive(Clone, Debug)]
pub struct HolySite {}

inventory::submit! {
    ItemLoader::Normal(GameFlags::Ck3, Item::HolySite, HolySite::add)
}

impl HolySite {
    pub fn add(db: &mut Db, key: Token, block: Block) {
        db.add(Item::HolySite, key, block, Box::new(Self {}));
    }
}

impl DbKind for HolySite {
    fn add_subitems(&self, _key: &Token, block: &Block, db: &mut Db) {
        if let Some(block) = block.get_field_block("parameters") {
            for token in block.iter_values() {
                db.add_flag(Item::HolySiteParameter, token.clone());
            }
        }
    }

    fn validate(&self, key: &Token, block: &Block, data: &Everything) {
        let mut vd = Validator::new(block, data);

        let loca = format!("holy_site_{key}_name");
        data.verify_exists_implied(Item::Localization, &loca, key);
        let loca = format!("holy_site_{key}_effects");
        data.mark_used(Item::Localization, &loca);

        vd.req_field("county");
        vd.field_item("county", Item::Title);
        vd.field_item("barony", Item::Title);

        if let Some(county) = block.get_field_value("county") {
            if Tier::try_from(county) != Ok(Tier::County) {
                warn(ErrorKey::TitleTier).msg("must be a county").loc(county).push();
            }
            if let Some(barony) = block.get_field_value("barony") {
                if Tier::try_from(barony) != Ok(Tier::Barony) {
                    warn(ErrorKey::TitleTier).msg("must be a barony").loc(barony).push();
                }
                if let Some(title) = data.titles.get(barony.as_str())
                    && title.parent != Some(county.as_str())
                {
                    let msg = format!("barony not in specified county {county}");
                    fatal(ErrorKey::Crash).strong().msg(msg).loc(barony).push();
                }
            }
        }

        vd.field_list("parameters");

        vd.multi_field_validated_block("character_modifier", |block, data| {
            let mut vd = Validator::new(block, data);
            if let Some(token) = vd.field_value("name") {
                data.verify_exists(Item::Localization, token);
            } else {
                let loca = format!("holy_site_{key}_effects");
                data.verify_exists_implied(Item::Localization, &loca, key);
            }
            validate_modifs(block, data, ModifKinds::Character, vd);
        });

        // undocumented

        vd.field_bool("is_active");
    }
}