1use std::sync::LazyLock;
2
3use crate::helpers::TigerHashMap;
4use crate::scopes::{ArgumentValue, Scopes};
5
6#[inline]
7pub fn scope_to_scope(name: &str) -> Option<(Scopes, Scopes)> {
8 SCOPE_TO_SCOPE_MAP.get(name).copied()
9}
10
11static SCOPE_TO_SCOPE_MAP: LazyLock<TigerHashMap<&'static str, (Scopes, Scopes)>> =
12 LazyLock::new(|| {
13 let mut hash = TigerHashMap::default();
14 for (from, s, to) in SCOPE_TO_SCOPE.iter().copied() {
15 hash.insert(s, (from, to));
16 }
17 hash
18 });
19
20const SCOPE_TO_SCOPE: &[(Scopes, &str, Scopes)] = &[
24 (Scopes::Character, "character_party", Scopes::Party),
25 (Scopes::Character, "employer", Scopes::Country),
26 (Scopes::Character, "family", Scopes::Family),
27 (Scopes::Character, "father", Scopes::Character),
28 (Scopes::Character, "home_country", Scopes::Country),
29 (Scopes::Character, "job", Scopes::Job),
30 (Scopes::Character, "mother", Scopes::Character),
31 (Scopes::Character, "next_in_family", Scopes::Character),
32 (Scopes::Character, "preferred_heir", Scopes::Character),
33 (Scopes::Character, "ruler", Scopes::Character),
34 (Scopes::Character, "spouse", Scopes::Character),
35 (
36 Scopes::Treasure,
37 "treasure_owner",
38 Scopes::Country.union(Scopes::Character).union(Scopes::Province),
39 ),
40 (Scopes::Country, "color1", Scopes::Color),
41 (Scopes::Country, "color2", Scopes::Color),
42 (Scopes::Country, "color3", Scopes::Color),
43 (Scopes::Country, "consort", Scopes::Character),
44 (Scopes::Country, "current_co_ruler", Scopes::Character),
45 (Scopes::Country, "current_heir", Scopes::Character),
46 (Scopes::Country, "current_ruler", Scopes::Character),
47 (Scopes::Country, "fam", Scopes::Family),
48 (Scopes::Country, "overlord", Scopes::Country),
49 (Scopes::Country.union(Scopes::Character), "party", Scopes::Party),
50 (Scopes::Country, "primary_heir", Scopes::Character),
51 (Scopes::Country, "secondary_heir", Scopes::Character),
52 (Scopes::Character.union(Scopes::Pop).union(Scopes::Job), "country", Scopes::Country),
53 (Scopes::Character.union(Scopes::Unit).union(Scopes::Governorship), "legion", Scopes::Legion),
54 (
55 Scopes::Country
56 .union(Scopes::Character)
57 .union(Scopes::Province)
58 .union(Scopes::Pop)
59 .union(Scopes::Deity),
60 "religion",
61 Scopes::Religion,
62 ),
63 (Scopes::Party, "party_country", Scopes::Country),
64 (Scopes::Party, "party_leader", Scopes::Character),
65 (Scopes::Country.union(Scopes::Religion).union(Scopes::CultureGroup), "color", Scopes::Color),
66 (Scopes::Siege, "siege_controller", Scopes::Country),
67 (Scopes::Province.union(Scopes::State), "area", Scopes::Area),
68 (Scopes::Province.union(Scopes::State), "governorship", Scopes::Governorship),
69 (
70 Scopes::Country.union(Scopes::Province).union(Scopes::Pop),
71 "country_culture",
72 Scopes::CountryCulture,
73 ),
74 (Scopes::Deity, "deified_ruler", Scopes::Character),
75 (Scopes::Deity, "holy_site", Scopes::Province),
76 (Scopes::Character.union(Scopes::Siege).union(Scopes::Pop), "location", Scopes::Province),
77 (Scopes::Province.union(Scopes::Area).union(Scopes::State), "region", Scopes::Region),
78 (Scopes::Color, "blue", Scopes::Value),
79 (Scopes::Color, "brightness", Scopes::Value),
80 (Scopes::Color, "green", Scopes::Value),
81 (Scopes::Color, "hue", Scopes::Value),
82 (Scopes::Color, "red", Scopes::Value),
83 (Scopes::Color, "saturation", Scopes::Value),
84 (Scopes::Unit.union(Scopes::Legion), "commander", Scopes::Character),
85 (Scopes::Unit.union(Scopes::Legion), "unit_destination", Scopes::Province),
86 (Scopes::Unit.union(Scopes::Legion), "unit_location", Scopes::Province),
87 (Scopes::Unit.union(Scopes::Legion), "unit_next_location", Scopes::Province),
88 (Scopes::Unit.union(Scopes::Legion), "unit_objective_destination", Scopes::Province),
89 (Scopes::Unit.union(Scopes::Legion), "unit_owner", Scopes::Country),
90 (
91 Scopes::Country
92 .union(Scopes::Character)
93 .union(Scopes::Province)
94 .union(Scopes::Pop)
95 .union(Scopes::CountryCulture)
96 .union(Scopes::Culture),
97 "culture_group",
98 Scopes::CultureGroup,
99 ),
100 (Scopes::SubUnit, "owning_unit", Scopes::Unit),
101 (Scopes::SubUnit, "personal_loyalty", Scopes::Character),
102 (Scopes::Job, "character", Scopes::Character),
103 (
104 Scopes::Province.union(Scopes::State).union(Scopes::Governorship).union(Scopes::Legion),
105 "owner",
106 Scopes::Country,
107 ),
108 (Scopes::Family, "family_country", Scopes::Country),
109 (Scopes::Family, "head_of_family", Scopes::Character),
110 (
111 Scopes::Country
112 .union(Scopes::Character)
113 .union(Scopes::Province)
114 .union(Scopes::Pop)
115 .union(Scopes::CultureGroup)
116 .union(Scopes::CountryCulture),
117 "culture",
118 Scopes::Culture,
119 ),
120 (
121 Scopes::Province.union(Scopes::State).union(Scopes::Governorship),
122 "governor",
123 Scopes::Character,
124 ),
125 (
126 Scopes::Province.union(Scopes::State).union(Scopes::Governorship),
127 "governor_or_ruler",
128 Scopes::Character,
129 ),
130 (Scopes::War, "attacker_warleader", Scopes::Country),
131 (Scopes::War, "defender_warleader", Scopes::Country),
132 (Scopes::Province, "controller", Scopes::Country),
133 (Scopes::Province, "dominant_province_culture", Scopes::Culture),
134 (Scopes::Province, "dominant_province_culture_group", Scopes::CultureGroup),
135 (Scopes::Province, "dominant_province_religion", Scopes::Religion),
136 (Scopes::Province, "holding_owner", Scopes::Character),
137 (Scopes::Province, "province_deity", Scopes::Deity),
138 (Scopes::Province, "state", Scopes::State),
139 (Scopes::Province.union(Scopes::Unit), "siege", Scopes::Siege),
140 (
141 Scopes::Country.union(Scopes::State).union(Scopes::Governorship),
142 "capital_scope",
143 Scopes::Province,
144 ),
145 (Scopes::None, "yes", Scopes::Bool),
146 (Scopes::None, "no", Scopes::Bool),
147];
148
149#[inline]
150pub fn scope_prefix(name: &str) -> Option<(Scopes, Scopes, ArgumentValue)> {
151 SCOPE_PREFIX_MAP.get(name).copied()
152}
153
154static SCOPE_PREFIX_MAP: LazyLock<TigerHashMap<&'static str, (Scopes, Scopes, ArgumentValue)>> =
155 LazyLock::new(|| {
156 let mut hash = TigerHashMap::default();
157 for (from, s, to, argument) in SCOPE_PREFIX.iter().copied() {
158 hash.insert(s, (from, to, argument));
159 }
160 hash
161 });
162
163const SCOPE_PREFIX: &[(Scopes, &str, Scopes, ArgumentValue)] = {
169 use crate::item::Item;
170 use ArgumentValue::*;
171 &[
173 (Scopes::None, "array_define", Scopes::Value, UncheckedValue),
174 (Scopes::Country, "fam", Scopes::Family, UncheckedValue),
175 (Scopes::Country, "party", Scopes::Party, Item(Item::PartyType)),
176 (
177 Scopes::Country
178 .union(Scopes::Province)
179 .union(Scopes::State)
180 .union(Scopes::Governorship),
181 "job",
182 Scopes::Job,
183 UncheckedValue,
184 ),
185 (
186 Scopes::Country
187 .union(Scopes::Province)
188 .union(Scopes::State)
189 .union(Scopes::Governorship),
190 "job_holder",
191 Scopes::Character,
192 Item(Item::Office),
193 ),
194 (Scopes::None, "treasure", Scopes::Treasure, UncheckedValue),
195 (Scopes::None, "character", Scopes::Character, UncheckedValue),
196 (Scopes::None, "region", Scopes::Region, Item(Item::Region)),
197 (Scopes::None, "area", Scopes::Area, Item(Item::Area)),
198 (Scopes::None, "culture", Scopes::Culture, Item(Item::Culture)),
199 (Scopes::None, "culture_group", Scopes::CultureGroup, Item(Item::CultureGroup)),
200 (Scopes::None, "deity", Scopes::Deity, Item(Item::Deity)),
201 (Scopes::None, "c", Scopes::Country, UncheckedValue),
202 (Scopes::None, "char", Scopes::Character, UncheckedValue),
203 (Scopes::None, "define", Scopes::Value, UncheckedValue),
204 (Scopes::None, "flag", Scopes::Flag, UncheckedValue),
205 (Scopes::None, "global_var", Scopes::all(), UncheckedValue),
206 (Scopes::None, "local_var", Scopes::all(), UncheckedValue),
207 (Scopes::None, "modifier", Scopes::Value, Modif), (Scopes::None, "p", Scopes::Province, UncheckedValue),
209 (Scopes::None, "religion", Scopes::Religion, Item(Item::Religion)),
210 (Scopes::None, "scope", Scopes::all(), UncheckedValue),
211 (Scopes::all(), "var", Scopes::all(), UncheckedValue),
212 ]
213};
214
215pub fn scope_to_scope_removed(name: &str) -> Option<(&'static str, &'static str)> {
216 for (removed_name, version, explanation) in SCOPE_TO_SCOPE_REMOVED.iter().copied() {
217 if name == removed_name {
218 return Some((version, explanation));
219 }
220 }
221 None
222}
223
224const SCOPE_TO_SCOPE_REMOVED: &[(&str, &str, &str)] = &[];