Skip to main content

tiger_lib/vic3/tables/
datafunctions.rs

1use std::sync::LazyLock;
2
3use tiger_tables::datatype::*;
4
5use crate::datatype::CaseInsensitiveStr;
6use crate::helpers::{BiTigerHashMap, TigerHashMap, TigerHashSet};
7use crate::scopes::Scopes;
8
9use Datatype::Vic3;
10use Vic3Datatype::*;
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_VIC3.iter().copied() {
17            set.insert(CaseInsensitiveStr(name));
18        }
19
20        for (name, _, _) in GLOBAL_FUNCTIONS_VIC3.iter().copied() {
21            set.insert(CaseInsensitiveStr(name));
22        }
23
24        for (name, _, _, _) in PROMOTES_VIC3.iter().copied() {
25            set.insert(CaseInsensitiveStr(name));
26        }
27
28        for (name, _, _, _) in FUNCTIONS_VIC3.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_VIC3.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_VIC3.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_VIC3.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_VIC3.iter().copied() {
76            map.entry(name).or_default().push((from, args, to));
77        }
78        map
79    });
80
81// TODO: find the right datatypes for the commented out ones
82const DATATYPE_AND_SCOPE: &[(Datatype, Scopes)] = &[
83    (Vic3(Country), Scopes::Country),
84    (Vic3(Battle), Scopes::Battle),
85    // (Vic3(BattleSide),Scopes::BattleSide),
86    (Vic3(Building), Scopes::Building),
87    (Vic3(BuildingType), Scopes::BuildingType),
88    (Vic3(Character), Scopes::Character),
89    (Vic3(CivilWar), Scopes::CivilWar),
90    (Vic3(CommanderOrderType), Scopes::CommanderOrderType),
91    (Vic3(CountryCreation), Scopes::CountryCreation),
92    (Vic3(CountryDefinition), Scopes::CountryDefinition),
93    (Vic3(CountryFormation), Scopes::CountryFormation),
94    (Vic3(Culture), Scopes::Culture),
95    (Vic3(Decree), Scopes::Decree),
96    (Vic3(DiplomaticAction), Scopes::DiplomaticAction),
97    (Vic3(DiplomaticPact), Scopes::DiplomaticPact),
98    (Vic3(DiplomaticPlay), Scopes::DiplomaticPlay),
99    (Vic3(DiplomaticRelations), Scopes::DiplomaticRelations),
100    (Vic3(Front), Scopes::Front),
101    (Vic3(Goods), Scopes::Goods),
102    (Vic3(Hq), Scopes::Hq),
103    (Vic3(Ideology), Scopes::Ideology),
104    (Vic3(Institution), Scopes::Institution),
105    (Vic3(InstitutionType), Scopes::InstitutionType),
106    // (Vic3(InterestMarker),Scopes::InterestMarker),
107    (Vic3(InterestGroup), Scopes::InterestGroup),
108    (Vic3(InterestGroupTrait), Scopes::InterestGroupTrait),
109    // (Vic3(InterestGroupType),Scopes::InterestGroupType),
110    (Vic3(JournalEntry), Scopes::JournalEntry),
111    (Vic3(Law), Scopes::Law),
112    (Vic3(LawType), Scopes::LawType),
113    (Vic3(Market), Scopes::Market),
114    (Vic3(MarketGoods), Scopes::MarketGoods),
115    (Vic3(Objective), Scopes::Objective),
116    (Vic3(Party), Scopes::Party),
117    (Vic3(PoliticalMovement), Scopes::PoliticalMovement),
118    (Vic3(Pop), Scopes::Pop),
119    (Vic3(PopType), Scopes::PopType),
120    (Vic3(Province), Scopes::Province),
121    (Vic3(Religion), Scopes::Religion),
122    (Vic3(ShippingLane), Scopes::ShippingLanes),
123    (Vic3(State), Scopes::State),
124    (Vic3(StateRegion), Scopes::StateRegion),
125    (Vic3(StateTrait), Scopes::StateTrait),
126    (Vic3(StrategicRegion), Scopes::StrategicRegion),
127    (Vic3(Technology), Scopes::Technology),
128    // (Vic3(TechnologyStatus),Scopes::TechnologyStatus),
129    (Vic3(Theater), Scopes::Theater),
130    (Vic3(War), Scopes::War),
131];