tiger_lib/ck3/data/
vassalstance.rs

1use crate::block::Block;
2use crate::context::ScopeContext;
3use crate::db::{Db, DbKind};
4use crate::everything::Everything;
5use crate::game::GameFlags;
6use crate::item::{Item, ItemLoader};
7use crate::scopes::Scopes;
8use crate::token::Token;
9use crate::tooltipped::Tooltipped;
10use crate::trigger::validate_trigger;
11use crate::validator::Validator;
12
13#[derive(Clone, Debug)]
14pub struct VassalStance {}
15
16inventory::submit! {
17    ItemLoader::Normal(GameFlags::Ck3, Item::VassalStance, VassalStance::add)
18}
19
20impl VassalStance {
21    pub fn add(db: &mut Db, key: Token, block: Block) {
22        db.add(Item::VassalStance, key, block, Box::new(Self {}));
23    }
24}
25
26impl DbKind for VassalStance {
27    fn validate(&self, key: &Token, block: &Block, data: &Everything) {
28        let mut vd = Validator::new(block, data);
29        let mut sc = ScopeContext::new(Scopes::Character, key);
30        sc.define_name("liege", Scopes::Character, key);
31
32        // `_ai_<value>` are checked in `lookup_modif` when called
33        // as their format may not be defined if not used
34        for sfx in [
35            "_opinion",
36            "_same_faith_opinion",
37            "_different_faith_opinion",
38            "_same_culture_opinion",
39            "_different_culture_opinion",
40            "_tax_contribution_add",
41            "_tax_contribution_mult",
42            "_levy_contribution_add",
43            "_levy_contribution_mult",
44        ] {
45            let modif = format!("{key}{sfx}");
46            data.verify_exists_implied(Item::ModifierFormat, &modif, key);
47        }
48
49        vd.multi_field_validated_block("is_valid", |block, data| {
50            validate_trigger(block, data, &mut sc, Tooltipped::No);
51        });
52
53        vd.field_script_value("score", &mut sc);
54        vd.field_script_value("heir_score", &mut sc);
55    }
56}