tiger_lib/vic3/tables/
datafunctions.rs

1use std::sync::LazyLock;
2
3use crate::datatype::{Arg, Args, CaseInsensitiveStr, Datatype, Vic3Datatype};
4use crate::helpers::{BiTigerHashMap, TigerHashMap, TigerHashSet};
5use crate::item::Item;
6use crate::scopes::Scopes;
7
8use Arg::*;
9use Datatype::*;
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.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// The include/ files are converted from the game's data_type_* output files.
81
82// TODO: find the right datatypes for the commented out ones
83const DATATYPE_AND_SCOPE: &[(Datatype, Scopes)] = &[
84    (Vic3(Country), Scopes::Country),
85    (Vic3(Battle), Scopes::Battle),
86    // (Vic3(BattleSide),Scopes::BattleSide),
87    (Vic3(Building), Scopes::Building),
88    (Vic3(BuildingType), Scopes::BuildingType),
89    (Vic3(CanalType), Scopes::CanalType),
90    (Vic3(Character), Scopes::Character),
91    (Vic3(CivilWar), Scopes::CivilWar),
92    (Vic3(CommanderOrderType), Scopes::CommanderOrderType),
93    (Vic3(CountryCreation), Scopes::CountryCreation),
94    (Vic3(CountryDefinition), Scopes::CountryDefinition),
95    (Vic3(CountryFormation), Scopes::CountryFormation),
96    (Vic3(Culture), Scopes::Culture),
97    (Vic3(Decree), Scopes::Decree),
98    (Vic3(DiplomaticAction), Scopes::DiplomaticAction),
99    (Vic3(DiplomaticPact), Scopes::DiplomaticPact),
100    (Vic3(DiplomaticPlay), Scopes::DiplomaticPlay),
101    (Vic3(DiplomaticRelations), Scopes::DiplomaticRelations),
102    (Vic3(Front), Scopes::Front),
103    (Vic3(Goods), Scopes::Goods),
104    (Vic3(Hq), Scopes::Hq),
105    (Vic3(Ideology), Scopes::Ideology),
106    (Vic3(Institution), Scopes::Institution),
107    (Vic3(InstitutionType), Scopes::InstitutionType),
108    // (Vic3(InterestMarker),Scopes::InterestMarker),
109    (Vic3(InterestGroup), Scopes::InterestGroup),
110    (Vic3(InterestGroupTrait), Scopes::InterestGroupTrait),
111    // (Vic3(InterestGroupType),Scopes::InterestGroupType),
112    (Vic3(JournalEntry), Scopes::JournalEntry),
113    (Vic3(Law), Scopes::Law),
114    (Vic3(LawType), Scopes::LawType),
115    (Vic3(Market), Scopes::Market),
116    (Vic3(MarketGoods), Scopes::MarketGoods),
117    (Vic3(Objective), Scopes::Objective),
118    (Vic3(Party), Scopes::Party),
119    (Vic3(PoliticalMovement), Scopes::PoliticalMovement),
120    (Vic3(Pop), Scopes::Pop),
121    (Vic3(PopType), Scopes::PopType),
122    (Vic3(Province), Scopes::Province),
123    (Vic3(Religion), Scopes::Religion),
124    (Vic3(ShippingLane), Scopes::ShippingLanes),
125    (Vic3(State), Scopes::State),
126    (Vic3(StateRegion), Scopes::StateRegion),
127    (Vic3(StateTrait), Scopes::StateTrait),
128    (Vic3(StrategicRegion), Scopes::StrategicRegion),
129    (Vic3(Technology), Scopes::Technology),
130    // (Vic3(TechnologyStatus),Scopes::TechnologyStatus),
131    (Vic3(Theater), Scopes::Theater),
132    (Vic3(War), Scopes::War),
133];
134
135const GLOBAL_PROMOTES: &[(&str, Args, Datatype)] = include!("include/data_global_promotes.rs");
136
137const GLOBAL_FUNCTIONS: &[(&str, Args, Datatype)] = include!("include/data_global_functions.rs");
138
139const PROMOTES: &[(&str, Datatype, Args, Datatype)] = include!("include/data_promotes.rs");
140
141const FUNCTIONS: &[(&str, Datatype, Args, Datatype)] = include!("include/data_functions.rs");