tiger_lib/ck3/tables/
datafunctions.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use std::sync::LazyLock;

use crate::datatype::{Arg, Args, CaseInsensitiveStr, Ck3Datatype, Datatype};
use crate::helpers::{BiTigerHashMap, TigerHashMap, TigerHashSet};
use crate::item::Item;
use crate::scopes::Scopes;

use Arg::*;
use Ck3Datatype::*;
use Datatype::*;

pub static LOWERCASE_DATATYPE_SET: LazyLock<TigerHashSet<CaseInsensitiveStr>> =
    LazyLock::new(|| {
        let mut set = TigerHashSet::default();

        for (name, _, _) in GLOBAL_PROMOTES.iter().copied() {
            set.insert(CaseInsensitiveStr(name));
        }

        for (name, _, _) in GLOBAL_FUNCTIONS.iter().copied() {
            set.insert(CaseInsensitiveStr(name));
        }

        for (name, _, _, _) in PROMOTES.iter().copied() {
            set.insert(CaseInsensitiveStr(name));
        }

        for (name, _, _, _) in FUNCTIONS.iter().copied() {
            set.insert(CaseInsensitiveStr(name));
        }
        set
    });

pub static DATATYPE_AND_SCOPE_MAP: LazyLock<BiTigerHashMap<Datatype, Scopes>> =
    LazyLock::new(|| {
        let mut map = BiTigerHashMap::default();
        for (datatype, scope) in DATATYPE_AND_SCOPE.iter().copied() {
            map.insert(datatype, scope);
        }
        map
    });

pub static GLOBAL_PROMOTES_MAP: LazyLock<TigerHashMap<&'static str, (Args, Datatype)>> =
    LazyLock::new(|| {
        let mut map = TigerHashMap::default();
        for (name, args, datatype) in GLOBAL_PROMOTES.iter().copied() {
            map.insert(name, (args, datatype));
        }
        map
    });

pub static GLOBAL_FUNCTIONS_MAP: LazyLock<TigerHashMap<&'static str, (Args, Datatype)>> =
    LazyLock::new(|| {
        let mut map = TigerHashMap::default();
        for (name, args, datatype) in GLOBAL_FUNCTIONS.iter().copied() {
            map.insert(name, (args, datatype));
        }
        map
    });

#[allow(clippy::type_complexity)]
pub static PROMOTES_MAP: LazyLock<TigerHashMap<&'static str, Vec<(Datatype, Args, Datatype)>>> =
    LazyLock::new(|| {
        let mut map = TigerHashMap::<&'static str, Vec<(Datatype, Args, Datatype)>>::default();
        for (name, from, args, to) in PROMOTES.iter().copied() {
            map.entry(name).or_default().push((from, args, to));
        }
        map
    });

#[allow(clippy::type_complexity)]
pub static FUNCTIONS_MAP: LazyLock<TigerHashMap<&'static str, Vec<(Datatype, Args, Datatype)>>> =
    LazyLock::new(|| {
        let mut map = TigerHashMap::<&'static str, Vec<(Datatype, Args, Datatype)>>::default();
        for (name, from, args, to) in FUNCTIONS.iter().copied() {
            map.entry(name).or_default().push((from, args, to));
        }
        map
    });

// The include/ files are converted from the game's data_type_* output files.

const DATATYPE_AND_SCOPE: &[(Datatype, Scopes)] = &[
    (Ck3(Character), Scopes::Character),
    (Ck3(Title), Scopes::LandedTitle),
    (Ck3(Activity), Scopes::Activity),
    (Ck3(Secret), Scopes::Secret),
    (Ck3(Province), Scopes::Province),
    (Ck3(Scheme), Scopes::Scheme),
    (Ck3(Combat), Scopes::Combat),
    (Ck3(CombatSide), Scopes::CombatSide),
    (Ck3(Faith), Scopes::Faith),
    (Ck3(GreatHolyWar), Scopes::GreatHolyWar),
    (Ck3(Religion), Scopes::Religion),
    (Ck3(War), Scopes::War),
    (Ck3(Story), Scopes::StoryCycle),
    (Ck3(CasusBelliItem), Scopes::CasusBelli),
    (Ck3(Dynasty), Scopes::Dynasty),
    (Ck3(DynastyHouse), Scopes::DynastyHouse),
    (Ck3(Faction), Scopes::Faction),
    (Ck3(Culture), Scopes::Culture),
    (Ck3(Army), Scopes::Army),
    (Ck3(HolyOrder), Scopes::HolyOrder),
    (Ck3(ActiveCouncilTask), Scopes::CouncilTask),
    (Ck3(MercenaryCompany), Scopes::MercenaryCompany),
    (Ck3(Artifact), Scopes::Artifact),
    (Ck3(Inspiration), Scopes::Inspiration),
    (Ck3(Struggle), Scopes::Struggle),
    (Ck3(CharacterMemory), Scopes::CharacterMemory),
    (Ck3(TravelPlan), Scopes::TravelPlan),
    (Ck3(Accolade), Scopes::Accolade),
    (Ck3(AccoladeType), Scopes::AccoladeType),
    (Ck3(Decision), Scopes::Decision),
    (Ck3(FaithDoctrine), Scopes::Doctrine),
    (Ck3(ActivityType), Scopes::ActivityType),
    (Ck3(CultureTradition), Scopes::CultureTradition),
    (Ck3(CulturePillar), Scopes::CulturePillar),
    (Ck3(GovernmentType), Scopes::GovernmentType),
    (Ck3(HoldingType), Scopes::HoldingType),
    (Ck3(Trait), Scopes::Trait),
    (Ck3(TaxSlot), Scopes::TaxSlot),
    (Ck3(VassalContract), Scopes::VassalContract),
    (Ck3(ObligationLevel), Scopes::VassalObligationLevel),
];

const GLOBAL_PROMOTES: &[(&str, Args, Datatype)] = include!("include/data_global_promotes.rs");

const GLOBAL_FUNCTIONS: &[(&str, Args, Datatype)] = include!("include/data_global_functions.rs");

const PROMOTES: &[(&str, Datatype, Args, Datatype)] = include!("include/data_promotes.rs");

const FUNCTIONS: &[(&str, Datatype, Args, Datatype)] = include!("include/data_functions.rs");