tiger_lib/imperator/tables/
datafunctions.rs

1use std::sync::LazyLock;
2
3use crate::datatype::{Arg, Args, CaseInsensitiveStr, Datatype, ImperatorDatatype};
4use crate::helpers::{BiTigerHashMap, TigerHashMap, TigerHashSet};
5use crate::item::Item;
6use crate::scopes::Scopes;
7
8use Arg::*;
9use Datatype::*;
10use ImperatorDatatype::*;
11
12pub static LOWERCASE_DATATYPE_SET: LazyLock<TigerHashSet<CaseInsensitiveStr>> =
13    LazyLock::new(|| {
14        let mut set = TigerHashSet::default();
15
16        for (name, _, _) in GLOBAL_PROMOTES.iter().copied() {
17            set.insert(CaseInsensitiveStr(name));
18        }
19
20        for (name, _, _) in GLOBAL_FUNCTIONS.iter().copied() {
21            set.insert(CaseInsensitiveStr(name));
22        }
23
24        for (name, _, _, _) in PROMOTES.iter().copied() {
25            set.insert(CaseInsensitiveStr(name));
26        }
27
28        for (name, _, _, _) in FUNCTIONS.iter().copied() {
29            set.insert(CaseInsensitiveStr(name));
30        }
31        set
32    });
33
34pub static DATATYPE_AND_SCOPE_MAP: LazyLock<BiTigerHashMap<Datatype, Scopes>> =
35    LazyLock::new(|| {
36        let mut map = BiTigerHashMap::default();
37        for (datatype, scope) in DATATYPE_AND_SCOPE.iter().copied() {
38            map.insert(datatype, scope);
39        }
40        map
41    });
42
43pub static GLOBAL_PROMOTES_MAP: LazyLock<TigerHashMap<&'static str, (Args, Datatype)>> =
44    LazyLock::new(|| {
45        let mut map = TigerHashMap::default();
46        for (name, args, datatype) in GLOBAL_PROMOTES.iter().copied() {
47            map.insert(name, (args, datatype));
48        }
49        map
50    });
51
52pub static GLOBAL_FUNCTIONS_MAP: LazyLock<TigerHashMap<&'static str, (Args, Datatype)>> =
53    LazyLock::new(|| {
54        let mut map = TigerHashMap::default();
55        for (name, args, datatype) in GLOBAL_FUNCTIONS.iter().copied() {
56            map.insert(name, (args, datatype));
57        }
58        map
59    });
60
61#[allow(clippy::type_complexity)]
62pub static PROMOTES_MAP: LazyLock<TigerHashMap<&'static str, Vec<(Datatype, Args, Datatype)>>> =
63    LazyLock::new(|| {
64        let mut map = TigerHashMap::<&'static str, Vec<(Datatype, Args, Datatype)>>::default();
65        for (name, from, args, to) in PROMOTES.iter().copied() {
66            map.entry(name).or_default().push((from, args, to));
67        }
68        map
69    });
70
71#[allow(clippy::type_complexity)]
72pub static FUNCTIONS_MAP: LazyLock<TigerHashMap<&'static str, Vec<(Datatype, Args, Datatype)>>> =
73    LazyLock::new(|| {
74        let mut map = TigerHashMap::<&'static str, Vec<(Datatype, Args, Datatype)>>::default();
75        for (name, from, args, to) in FUNCTIONS.iter().copied() {
76            map.entry(name).or_default().push((from, args, to));
77        }
78        map
79    });
80
81// The include/ files are converted from the game's data_type_* output files.
82
83const DATATYPE_AND_SCOPE: &[(Datatype, Scopes)] = &[
84    (Imperator(Country), Scopes::Country),
85    (Imperator(Character), Scopes::Character),
86    (Imperator(Province), Scopes::Province),
87    (Imperator(Siege), Scopes::Siege),
88    (Imperator(Unit), Scopes::Unit),
89    (Imperator(Pop), Scopes::Pop),
90    (Imperator(Family), Scopes::Family),
91    (Imperator(Party), Scopes::Party),
92    (Imperator(Religion), Scopes::Religion),
93    (Imperator(Culture), Scopes::Culture),
94    (Imperator(CharacterJob), Scopes::Job),
95    (Imperator(CultureGroup), Scopes::CultureGroup),
96    (Imperator(CountryCulture), Scopes::CountryCulture),
97    (Imperator(Area), Scopes::Area),
98    (Imperator(State), Scopes::State),
99    (Imperator(SubUnit), Scopes::SubUnit),
100    (Imperator(Governorship), Scopes::Governorship),
101    (Imperator(Region), Scopes::Region),
102    (Imperator(Deity), Scopes::Deity),
103    (Imperator(GreatWork), Scopes::GreatWork),
104    (Imperator(Treasure), Scopes::Treasure),
105    (Imperator(War), Scopes::War),
106    (Imperator(Legion), Scopes::Legion),
107    (Imperator(LevyTemplate), Scopes::LevyTemplate),
108];
109
110const GLOBAL_PROMOTES: &[(&str, Args, Datatype)] = include!("include/data_global_promotes.rs");
111
112const GLOBAL_FUNCTIONS: &[(&str, Args, Datatype)] = include!("include/data_global_functions.rs");
113
114const PROMOTES: &[(&str, Datatype, Args, Datatype)] = include!("include/data_promotes.rs");
115
116const FUNCTIONS: &[(&str, Datatype, Args, Datatype)] = include!("include/data_functions.rs");