tiger-lib 1.19.0

Library used by the tools ck3-tiger, vic3-tiger, and imperator-tiger. This library holds the bulk of the code for them. It can be built either for ck3-tiger with the feature ck3, or for vic3-tiger with the feature vic3, or for imperator-tiger with the feature imperator, but not both at the same time.
Documentation
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
use std::sync::LazyLock;

use crate::helpers::TigerHashMap;
use crate::scopes::{ArgumentValue, Scopes};

#[inline]
pub fn scope_to_scope(name: &str) -> Option<(Scopes, Scopes)> {
    SCOPE_TO_SCOPE_MAP.get(name).copied()
}

static SCOPE_TO_SCOPE_MAP: LazyLock<TigerHashMap<&'static str, (Scopes, Scopes)>> =
    LazyLock::new(|| {
        let mut hash = TigerHashMap::default();
        for (from, s, to) in SCOPE_TO_SCOPE.iter().copied() {
            hash.insert(s, (from, to));
        }
        hash
    });

/// LAST UPDATED VIC3 VERSION 1.12.2
/// See `event_targets.log` from the game data dumps
/// These are scope transitions that can be chained like `root.joined_faction.faction_leader`
const SCOPE_TO_SCOPE: &[(Scopes, &str, Scopes)] = &[
    (Scopes::Treaty.union(Scopes::TreatyOptions), "amended_treaty", Scopes::Treaty),
    (Scopes::Country, "army_size", Scopes::Value),
    (Scopes::Country, "army_size_including_conscripts", Scopes::Value),
    (Scopes::Country, "army_size_including_raised_conscripts", Scopes::Value),
    (Scopes::Amendment, "attached_law", Scopes::Law),
    (Scopes::Battle, "attacker_side", Scopes::BattleSide),
    (Scopes::War, "attacker_warleader", Scopes::Country),
    (Scopes::Country.union(Scopes::State), "average_expected_sol", Scopes::Value),
    (Scopes::Character.union(Scopes::InterestGroup), "average_progressiveness", Scopes::Value),
    (Scopes::Country.union(Scopes::State), "average_sol", Scopes::Value),
    (Scopes::Goods, "base_price", Scopes::Value),
    (Scopes::BattleSide, "battle", Scopes::Battle),
    (Scopes::Treaty.union(Scopes::TreatyOptions), "binding_period", Scopes::Value),
    (Scopes::NewCombatUnit, "building", Scopes::Building),
    (Scopes::Country, "building_levels", Scopes::Value),
    (Scopes::Country, "cached_ai_coastal_population", Scopes::Value),
    (Scopes::Country, "cached_ai_incorporated_coastal_population", Scopes::Value),
    (Scopes::Country, "cached_ai_incorporated_population", Scopes::Value),
    (Scopes::Country, "cached_ai_overseas_subject_population", Scopes::Value),
    (Scopes::Country, "cached_ai_subject_population", Scopes::Value),
    (Scopes::Country, "cached_ai_total_population", Scopes::Value),
    (Scopes::Country, "cached_ai_unincorporated_coastal_population", Scopes::Value),
    (Scopes::Country, "cached_ai_unincorporated_population", Scopes::Value),
    (Scopes::Country, "capital", Scopes::State),
    (Scopes::PoliticalMovement, "civil_war", Scopes::CivilWar),
    (Scopes::Country, "civil_war_origin_country", Scopes::Country),
    (Scopes::Country, "colonial_growth_per_colony", Scopes::Value),
    (Scopes::Province, "combat_width", Scopes::Value),
    (Scopes::Character, "command_limit_num_units", Scopes::Value),
    (Scopes::MilitaryFormation, "commander", Scopes::Character),
    (Scopes::Character, "commander_military_formation", Scopes::MilitaryFormation),
    (Scopes::Province.union(Scopes::State), "controller", Scopes::Country),
    (Scopes::MilitaryFormation.union(Scopes::Ship), "country", Scopes::Country),
    (Scopes::Country, "country_definition", Scopes::CountryDefinition),
    (Scopes::Country, "credit", Scopes::Value),
    (
        Scopes::Character
            .union(Scopes::NewCombatUnit)
            .union(Scopes::PoliticalMovement)
            .union(Scopes::Pop),
        "culture",
        Scopes::Culture,
    ),
    (Scopes::MilitaryFormation, "current_hq", Scopes::Hq),
    (Scopes::Law, "currently_active_law_in_group", Scopes::Law),
    (Scopes::Country, "currently_enacting_law", Scopes::Law),
    (Scopes::Battle, "defender_side", Scopes::BattleSide),
    (Scopes::War, "defender_warleader", Scopes::Country),
    (Scopes::NewCombatUnit, "defense", Scopes::Value),
    (Scopes::NewCombatUnit, "demoralized", Scopes::Value),
    (Scopes::MilitaryFormation, "detection", Scopes::Value),
    (Scopes::Country, "diplomatic_pact_expense_ratio", Scopes::Value),
    (Scopes::War, "diplomatic_play", Scopes::DiplomaticPlay),
    (Scopes::Treaty, "enforced_on_country", Scopes::Country),
    (Scopes::Treaty, "enforcer_country", Scopes::Country),
    (Scopes::Company, "executive", Scopes::Character),
    (
        Scopes::DiplomaticPact
            .union(Scopes::TreatyArticle)
            .union(Scopes::TreatyOptions)
            .union(Scopes::TreatyArticleOptions)
            .union(Scopes::Treaty),
        "first_country",
        Scopes::Country,
    ),
    (Scopes::Country, "flagship", Scopes::Ship),
    (
        Scopes::Battle
            .union(Scopes::Character)
            .union(Scopes::Province)
            .union(Scopes::Invasion)
            .union(Scopes::MilitaryFormation),
        "front",
        Scopes::Front,
    ),
    (Scopes::Front, "front_length", Scopes::Value),
    (
        Scopes::Country.union(Scopes::State).union(Scopes::Market).union(Scopes::StrategicRegion),
        "gdp",
        Scopes::Value,
    ),
    (Scopes::None, "global_gdp", Scopes::Value),
    (Scopes::JournalEntry, "goal_value", Scopes::Value),
    (Scopes::MarketGoods.union(Scopes::StateGoods), "goods", Scopes::Goods),
    (Scopes::Country.union(Scopes::PoliticalMovement), "government_size", Scopes::Value),
    (Scopes::Building.union(Scopes::BuildingType), "group", Scopes::BuildingGroup),
    (Scopes::Country, "heir", Scopes::Character),
    (Scopes::Character.union(Scopes::Pop), "home_country", Scopes::Country),
    (Scopes::MilitaryFormation, "home_hq", Scopes::Hq),
    (Scopes::PowerBloc, "identity", Scopes::PowerBlocIdentity),
    (Scopes::Character, "ideology", Scopes::Ideology),
    (Scopes::Country, "imposed_law", Scopes::Law),
    (Scopes::Country.union(Scopes::Law), "imposer_of_law", Scopes::Country),
    (Scopes::Country, "income", Scopes::Value),
    (Scopes::Country, "income_transfer_expenses", Scopes::Value),
    (Scopes::Country, "income_transfer_relative_expenses", Scopes::Value),
    (Scopes::Country, "infamy", Scopes::Value),
    (Scopes::DiplomaticPlay, "initiator", Scopes::Country),
    (
        Scopes::TreatyArticle.union(Scopes::TreatyArticleOptions),
        "input_building_type",
        Scopes::BuildingType,
    ),
    (Scopes::TreatyArticle.union(Scopes::TreatyArticleOptions), "input_company", Scopes::Company),
    (Scopes::TreatyArticle.union(Scopes::TreatyArticleOptions), "input_country", Scopes::Country),
    (Scopes::TreatyArticle.union(Scopes::TreatyArticleOptions), "input_goods", Scopes::Goods),
    (Scopes::TreatyArticle.union(Scopes::TreatyArticleOptions), "input_law", Scopes::LawType),
    (Scopes::TreatyArticle.union(Scopes::TreatyArticleOptions), "input_quantity", Scopes::Value),
    (Scopes::TreatyArticle.union(Scopes::TreatyArticleOptions), "input_ship", Scopes::Ship),
    (Scopes::TreatyArticle.union(Scopes::TreatyArticleOptions), "input_state", Scopes::State),
    (
        Scopes::TreatyArticle.union(Scopes::TreatyArticleOptions),
        "input_strategic_region",
        Scopes::StrategicRegion,
    ),
    (Scopes::Character, "interest_group", Scopes::InterestGroup),
    (Scopes::Character, "interest_group_type", Scopes::InterestGroupType),
    (Scopes::Front, "invasion", Scopes::Invasion),
    (Scopes::Invasion, "invasion_attacker", Scopes::Country),
    (Scopes::Invasion, "invasion_defender", Scopes::Country),
    (Scopes::Institution, "investment", Scopes::Value),
    (Scopes::Institution, "investment_max", Scopes::Value),
    (Scopes::Country, "investment_pool_income", Scopes::Value),
    (Scopes::None, "is_setup", Scopes::Value),
    (Scopes::None, "je_tutorial", Scopes::JournalEntry),
    (Scopes::Province.union(Scopes::State), "land_controller_hq", Scopes::Hq),
    (Scopes::Province.union(Scopes::State), "land_hq", Scopes::Hq),
    (Scopes::MarketGoods, "largest_exporting_market", Scopes::Market),
    (Scopes::MarketGoods, "largest_importing_market", Scopes::Market),
    (Scopes::Law, "law_type", Scopes::LawType),
    (Scopes::InterestGroup, "leader", Scopes::Character),
    (Scopes::Country, "legitimacy", Scopes::Value),
    (Scopes::Building, "level", Scopes::Value),
    (Scopes::Building, "level_after_queued_constructions", Scopes::Value),
    (Scopes::NewCombatUnit, "manpower", Scopes::Value),
    (
        Scopes::Country
            .union(Scopes::Building)
            .union(Scopes::Market)
            .union(Scopes::MarketGoods)
            .union(Scopes::Province)
            .union(Scopes::State)
            .union(Scopes::StateGoods)
            .union(Scopes::StateRegion),
        "market",
        Scopes::Market,
    ),
    (Scopes::Country, "market_capital", Scopes::State),
    (Scopes::MarketGoods, "market_export_cap", Scopes::Value),
    (Scopes::MarketGoods, "market_import_cap", Scopes::Value),
    (Scopes::State, "mass_migration_culture", Scopes::Culture),
    (Scopes::Country.union(Scopes::State), "migration_pull", Scopes::Value),
    (Scopes::Country, "military_expenses", Scopes::Value),
    (Scopes::Country, "military_expenses_share", Scopes::Value),
    (Scopes::NewCombatUnit, "mobilization", Scopes::Value),
    (Scopes::Party, "momentum", Scopes::Value),
    (Scopes::NewCombatUnit, "morale", Scopes::Value),
    (Scopes::PoliticalMovement, "most_desired_law", Scopes::LawType),
    (Scopes::Culture, "national_awakening_state_region", Scopes::StateRegion),
    (Scopes::Country, "naval_combat_power", Scopes::Value),
    (Scopes::Province, "naval_controller_hq", Scopes::Hq),
    (Scopes::Country, "naval_hostility_average_damage_dealt", Scopes::Value),
    (Scopes::Province, "naval_hq", Scopes::Hq),
    (Scopes::Country, "naval_vulnerability", Scopes::Value),
    (Scopes::Country, "navy_size", Scopes::Value),
    (Scopes::None, "no", Scopes::Bool),
    (Scopes::None, "NO", Scopes::Bool),
    (Scopes::Country, "num_active_interests", Scopes::Value),
    (Scopes::Country, "num_active_natural_interests", Scopes::Value),
    (Scopes::Country, "num_active_plays", Scopes::Value),
    (
        Scopes::Country.union(Scopes::Character).union(Scopes::MilitaryFormation),
        "num_active_ships",
        Scopes::Value,
    ),
    (
        Scopes::Country.union(Scopes::Character).union(Scopes::MilitaryFormation),
        "num_active_ships_in_battle",
        Scopes::Value,
    ),
    (
        Scopes::Country.union(Scopes::Character).union(Scopes::MilitaryFormation),
        "num_active_ships_not_in_battle",
        Scopes::Value,
    ),
    (Scopes::Country, "num_admirals", Scopes::Value),
    (Scopes::Country, "num_alliances", Scopes::Value),
    (Scopes::MilitaryFormation, "num_assigned_supply_ships", Scopes::Value),
    (Scopes::Character, "num_battalions", Scopes::Value),
    (Scopes::Country, "num_characters", Scopes::Value),
    (Scopes::Country, "num_colony_projects", Scopes::Value),
    (Scopes::MilitaryFormation, "num_commanderless_units", Scopes::Value),
    (Scopes::Country, "num_commanders", Scopes::Value),
    (Scopes::Country, "num_defensive_pacts", Scopes::Value),
    (Scopes::Hq, "num_garrison_units", Scopes::Value),
    (Scopes::Country, "num_generals", Scopes::Value),
    (Scopes::Country, "num_income_transfer_pacts", Scopes::Value),
    (Scopes::Country, "num_income_transfer_treaty_articles", Scopes::Value),
    (Scopes::Country, "num_income_transfers", Scopes::Value),
    (Scopes::Country, "num_incorporated_states", Scopes::Value),
    (Scopes::Country, "num_interests", Scopes::Value),
    (Scopes::PowerBloc, "num_mandates", Scopes::Value),
    (Scopes::Character, "num_mobilized_battalions", Scopes::Value),
    (Scopes::Country, "num_natural_interests", Scopes::Value),
    (
        Scopes::Country.union(Scopes::Character).union(Scopes::MilitaryFormation),
        "num_non_destroyed_ships",
        Scopes::Value,
    ),
    (
        Scopes::Country.union(Scopes::Character).union(Scopes::MilitaryFormation),
        "num_non_destroyed_ships_in_battle",
        Scopes::Value,
    ),
    (
        Scopes::Country.union(Scopes::Character).union(Scopes::MilitaryFormation),
        "num_non_destroyed_ships_not_in_battle",
        Scopes::Value,
    ),
    (Scopes::Country, "num_obligations_earned", Scopes::Value),
    (Scopes::Country, "num_pending_events", Scopes::Value),
    (Scopes::Country, "num_politicians", Scopes::Value),
    (Scopes::Country, "num_positive_relations", Scopes::Value),
    (Scopes::Front.union(Scopes::State).union(Scopes::StateRegion), "num_provinces", Scopes::Value),
    (Scopes::Country, "num_queued_constructions", Scopes::Value),
    (Scopes::Country, "num_queued_government_constructions", Scopes::Value),
    (Scopes::Country, "num_queued_private_constructions", Scopes::Value),
    (Scopes::Country, "num_rivals", Scopes::Value),
    (Scopes::Country, "num_ruling_igs", Scopes::Value),
    (
        Scopes::Country.union(Scopes::Character).union(Scopes::MilitaryFormation),
        "num_ships",
        Scopes::Value,
    ),
    (
        Scopes::Country.union(Scopes::Character).union(Scopes::MilitaryFormation),
        "num_ships_in_battle",
        Scopes::Value,
    ),
    (
        Scopes::Country.union(Scopes::Character).union(Scopes::MilitaryFormation),
        "num_ships_not_in_battle",
        Scopes::Value,
    ),
    (Scopes::Country, "num_states", Scopes::Value),
    (Scopes::Country, "num_unincorporated_states", Scopes::Value),
    (Scopes::Character.union(Scopes::MilitaryFormation), "num_units", Scopes::Value),
    (Scopes::Character.union(Scopes::MilitaryFormation), "num_units_in_battle", Scopes::Value),
    (Scopes::Character.union(Scopes::MilitaryFormation), "num_units_not_in_battle", Scopes::Value),
    (Scopes::Character, "num_units_share", Scopes::Value),
    (Scopes::State, "num_world_market_hub_trade_center_levels", Scopes::Value),
    (Scopes::NewCombatUnit, "offense", Scopes::Value),
    (Scopes::Character, "opposing_commander", Scopes::Character),
    (Scopes::BattleSide, "opposite_battle_side", Scopes::BattleSide),
    (Scopes::Country, "overlord", Scopes::Country),
    (
        Scopes::Country
            .union(Scopes::Building)
            .union(Scopes::Character)
            .union(Scopes::NewCombatUnit)
            .union(Scopes::Company)
            .union(Scopes::Decree)
            .union(Scopes::Institution)
            .union(Scopes::InterestMarker)
            .union(Scopes::InterestGroup)
            .union(Scopes::JournalEntry)
            .union(Scopes::Law)
            .union(Scopes::Market)
            .union(Scopes::MarketGoods)
            .union(Scopes::MilitaryFormation)
            .union(Scopes::PoliticalMovement)
            .union(Scopes::Pop)
            .union(Scopes::Province)
            .union(Scopes::Ship)
            .union(Scopes::State),
        "owner",
        Scopes::Country,
    ),
    (Scopes::Country, "owning_company", Scopes::Company),
    (Scopes::Amendment, "parent_law_type", Scopes::LawType),
    (Scopes::Market, "participants", Scopes::Value),
    (Scopes::InterestGroup, "party", Scopes::Party),
    (Scopes::None, "player", Scopes::Country), // TODO "do not use this outside tutorial"
    (Scopes::DiplomaticRelations, "player_owed_obligation_days_left", Scopes::Value),
    (Scopes::Character.union(Scopes::CivilWar), "political_movement", Scopes::PoliticalMovement),
    (Scopes::Pop, "pop_weight_modifier_scale", Scopes::Value),
    (Scopes::Character, "popularity", Scopes::Value),
    (Scopes::State, "population_below_expected_sol", Scopes::Value),
    (Scopes::Country, "power_bloc", Scopes::PowerBloc),
    (Scopes::PowerBloc, "power_bloc_leader", Scopes::Country),
    (
        Scopes::NewCombatUnit.union(Scopes::MilitaryFormation).union(Scopes::Ship),
        "power_projection",
        Scopes::Value,
    ),
    (Scopes::PowerBloc, "power_struggle_contender", Scopes::Country),
    (Scopes::Country, "principal", Scopes::Value),
    (Scopes::Company, "prosperity", Scopes::Value),
    (Scopes::BattleSide, "province", Scopes::Province),
    (
        Scopes::Building
            .union(Scopes::DiplomaticPlay)
            .union(Scopes::Hq)
            .union(Scopes::InterestMarker)
            .union(Scopes::Province)
            .union(Scopes::State)
            .union(Scopes::StateRegion),
        "region",
        Scopes::StrategicRegion,
    ),
    (
        Scopes::Country
            .union(Scopes::Character)
            .union(Scopes::CountryDefinition)
            .union(Scopes::PoliticalMovement)
            .union(Scopes::Pop),
        "religion",
        Scopes::Religion,
    ),
    (Scopes::TreatyOptions.union(Scopes::Treaty), "remaining_binding_period", Scopes::Value),
    (Scopes::BuildingType, "required_construction", Scopes::Value),
    (Scopes::Country, "ruler", Scopes::Character),
    (Scopes::DiplomaticRelations, "scope_relations", Scopes::Value),
    (Scopes::DiplomaticRelations, "scope_tension", Scopes::Value),
    (Scopes::MilitaryFormation, "screening", Scopes::Value),
    (
        Scopes::DiplomaticPact
            .union(Scopes::TreatyArticle)
            .union(Scopes::TreatyOptions)
            .union(Scopes::TreatyArticleOptions)
            .union(Scopes::Treaty),
        "second_country",
        Scopes::Country,
    ),
    (Scopes::Ship, "ship_fleet", Scopes::MilitaryFormation),
    (Scopes::Ship, "ship_group", Scopes::ShipGroup),
    (Scopes::TreatyArticle, "shipping_lane", Scopes::ShippingLanes),
    (Scopes::BuildingType, "slaves_role", Scopes::PopType),
    (Scopes::TreatyArticle.union(Scopes::TreatyArticleOptions), "source_country", Scopes::Country),
    (Scopes::Amendment, "sponsor", Scopes::InterestGroup),
    (
        Scopes::Building.union(Scopes::Market).union(Scopes::Pop).union(Scopes::Province),
        "state",
        Scopes::State,
    ),
    (Scopes::State, "state_region", Scopes::StateRegion),
    (
        Scopes::DiplomaticPlay
            .union(Scopes::DiplomaticCatalyst)
            .union(Scopes::PoliticalLobby)
            .union(Scopes::JournalEntry),
        "target",
        Scopes::all(),
    ), // TODO: scope type?
    (Scopes::TreatyArticle.union(Scopes::TreatyArticleOptions), "target_country", Scopes::Country),
    (Scopes::Country, "technology_being_researched", Scopes::Technology),
    (Scopes::Country, "techs_researched", Scopes::Value),
    (Scopes::BattleSide.union(Scopes::State), "theater", Scopes::Theater),
    (Scopes::Country, "top_overlord", Scopes::Country),
    (Scopes::Country, "total_export_value", Scopes::Value),
    (Scopes::Country, "total_import_value", Scopes::Value),
    (Scopes::Country, "total_marine_capacity", Scopes::Value),
    (Scopes::DiplomaticRelations, "total_pirated_trade_value", Scopes::Value),
    (Scopes::Country, "total_trade_value", Scopes::Value),
    (Scopes::Market, "trade_center", Scopes::State),
    (Scopes::Building, "training_rate", Scopes::Value),
    (Scopes::TreatyArticle, "treaty", Scopes::Treaty),
    (Scopes::MarketGoods, "treaty_exports", Scopes::Value),
    (Scopes::MarketGoods, "treaty_imports", Scopes::Value),
    // The input and output scopes for this are special cased
    (
        Scopes::Building
            .union(Scopes::Company)
            .union(Scopes::DiplomaticPlay)
            .union(Scopes::DiplomaticCatalyst)
            .union(Scopes::PoliticalLobby)
            .union(Scopes::Institution)
            .union(Scopes::InterestGroup)
            .union(Scopes::Law)
            .union(Scopes::PoliticalMovement)
            .union(Scopes::Ship)
            .union(Scopes::Strait)
            .union(Scopes::HarvestCondition)
            .union(Scopes::Amendment),
        "type",
        Scopes::BuildingType
            .union(Scopes::CompanyType)
            .union(Scopes::DiplomaticPlayType)
            .union(Scopes::DiplomaticCatalystType)
            .union(Scopes::PoliticalLobbyType)
            .union(Scopes::InstitutionType)
            .union(Scopes::InterestGroupType)
            .union(Scopes::LawType)
            .union(Scopes::PoliticalMovementType)
            .union(Scopes::ShipType)
            .union(Scopes::StraitType)
            .union(Scopes::HarvestConditionType)
            .union(Scopes::AmendmentType),
    ),
    (Scopes::MilitaryFormation, "visibility", Scopes::Value),
    (Scopes::MilitaryFormation, "vulnerability", Scopes::Value),
    (Scopes::DiplomaticPlay, "war", Scopes::War),
    (Scopes::Company, "weekly_prosperity_change", Scopes::Value),
    (Scopes::Pop, "workplace", Scopes::Building),
    (Scopes::State, "world_market_hub", Scopes::State),
    (Scopes::None, "yes", Scopes::Bool),
    (Scopes::None, "YES", Scopes::Bool),
];

#[inline]
pub fn scope_prefix(name: &str) -> Option<(Scopes, Scopes, ArgumentValue)> {
    SCOPE_PREFIX_MAP.get(name).copied()
}

static SCOPE_PREFIX_MAP: LazyLock<TigerHashMap<&'static str, (Scopes, Scopes, ArgumentValue)>> =
    LazyLock::new(|| {
        let mut hash = TigerHashMap::default();
        for (from, s, to, argument) in SCOPE_PREFIX.iter().copied() {
            hash.insert(s, (from, to, argument));
        }
        hash
    });

/// LAST UPDATED VIC3 VERSION 1.10.0
/// See `event_targets.log` from the game data dumps
/// These are absolute scopes (like character:100000) and scope transitions that require
/// a key (like `root.cp:councillor_steward`)
const SCOPE_PREFIX: &[(Scopes, &str, Scopes, ArgumentValue)] = {
    use crate::item::Item;
    use ArgumentValue::*;
    &[
        (Scopes::Country, "active_law", Scopes::Law, Item(Item::LawGroup)),
        (Scopes::Country, "ai_army_comparison", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::StrategicRegion, "ai_colonization_value", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Country, "ai_gdp_comparison", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Country, "ai_ideological_opinion", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Country, "ai_navy_comparison", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::State, "ai_state_value", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Country, "ai_subject_value", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Country, "ai_transit_rights_value", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::MarketGoods, "ai_treaty_export_value", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Country, "ai_treaty_fairness", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::MarketGoods, "ai_treaty_import_value", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::State, "ai_treaty_port_value", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::MarketGoods, "ai_treaty_trade_value", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Country, "ai_treaty_value", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::None, "amendment_type", Scopes::AmendmentType, Item(Item::Amendment)),
        (Scopes::None, "array_define", Scopes::Value, UncheckedValue),
        (Scopes::Front, "average_defense", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Front, "average_offense", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::State, "b", Scopes::Building, Item(Item::BuildingType)),
        (Scopes::None, "bg", Scopes::BuildingGroup, Item(Item::BuildingGroup)),
        (Scopes::None, "bt", Scopes::BuildingType, Item(Item::BuildingType)),
        (Scopes::None, "c", Scopes::Country, Item(Item::Country)),
        (
            Scopes::None,
            "catalyst_type",
            Scopes::DiplomaticCatalystType,
            Item(Item::DiplomaticCatalyst),
        ),
        (Scopes::None, "cd", Scopes::CountryDefinition, Item(Item::Country)),
        (Scopes::Country, "company", Scopes::Company, Item(Item::CompanyType)),
        (Scopes::None, "company_type", Scopes::CompanyType, Item(Item::CompanyType)),
        (Scopes::None, "cu", Scopes::Culture, Item(Item::Culture)),
        (Scopes::State, "decree_cost", Scopes::Value, Item(Item::Decree)),
        (Scopes::None, "define", Scopes::Value, Item(Item::Define)),
        (Scopes::None, "flag", Scopes::Flag, UncheckedValue),
        (Scopes::None, "g", Scopes::Goods, Item(Item::Goods)),
        (Scopes::Country, "get_ruler_for", Scopes::Character, Item(Item::TransferOfPower)),
        // TODO: figure out how this one works
        (Scopes::None, "global_productivity", Scopes::Value, Scope(Scopes::Value)),
        (Scopes::None, "global_var", Scopes::all(), UncheckedValue),
        (
            Scopes::None,
            "harvest_condition_type",
            Scopes::HarvestConditionType,
            Item(Item::HarvestConditionType),
        ),
        (Scopes::None, "i", Scopes::Ideology, Item(Item::Ideology)),
        (Scopes::None, "identity", Scopes::PowerBlocIdentity, Item(Item::PowerBlocIdentity)),
        (Scopes::None, "ideology", Scopes::Ideology, Item(Item::Ideology)), // TODO difference with i:
        (
            Scopes::Country.union(Scopes::PoliticalMovement),
            "ig",
            Scopes::InterestGroup,
            Item(Item::InterestGroup),
        ),
        (Scopes::None, "ig_trait", Scopes::InterestGroupTrait, Item(Item::InterestGroupTrait)),
        (Scopes::None, "ig_type", Scopes::InterestGroupType, Item(Item::InterestGroup)),
        (Scopes::None, "infamy_threshold", Scopes::Value, Item(Item::InfamyThreshold)),
        (
            Scopes::TreatyArticle.union(Scopes::TreatyArticleOptions),
            "input_market_goods",
            Scopes::MarketGoods,
            Scope(Scopes::Country),
        ),
        (Scopes::Country, "institution", Scopes::Institution, Item(Item::Institution)),
        (Scopes::Country, "je", Scopes::JournalEntry, Item(Item::JournalEntry)),
        (Scopes::None, "law_type", Scopes::LawType, Item(Item::LawType)),
        (Scopes::None, "list_size", Scopes::Value, UncheckedValue),
        (Scopes::Country, "lobby_foreign_anti_clout", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Country, "lobby_foreign_pro_clout", Scopes::Value, Scope(Scopes::Country)),
        (
            Scopes::Country,
            "lobby_in_government_foreign_anti_clout",
            Scopes::Value,
            Scope(Scopes::Country),
        ),
        (
            Scopes::Country,
            "lobby_in_government_foreign_pro_clout",
            Scopes::Value,
            Scope(Scopes::Country),
        ),
        (Scopes::InterestGroup, "lobby_join_weight", Scopes::Value, Scope(Scopes::PoliticalLobby)),
        (Scopes::None, "lobby_type", Scopes::PoliticalLobbyType, Item(Item::PoliticalLobby)),
        (Scopes::Country, "lobby_war_opposition", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Country, "lobby_war_support", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::None, "local_var", Scopes::all(), UncheckedValue),
        (Scopes::Market, "mg", Scopes::MarketGoods, Item(Item::Goods)),
        (
            Scopes::None,
            "mobilization_option",
            Scopes::MobilizationOption,
            Item(Item::MobilizationOption),
        ),
        (
            Scopes::Country
                .union(Scopes::BattleSide)
                .union(Scopes::Building)
                .union(Scopes::Character)
                .union(Scopes::InterestGroup)
                .union(Scopes::Market)
                .union(Scopes::PowerBloc)
                .union(Scopes::State),
            "modifier",
            Scopes::Value.union(Scopes::Bool),
            Modif,
        ),
        (
            Scopes::None,
            "movement_type",
            Scopes::PoliticalMovementType,
            Item(Item::PoliticalMovement),
        ),
        (Scopes::Country, "mutual_trade_value_with_country", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Country, "naval_hostility_damage", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::State, "nf", Scopes::Decree, Item(Item::Decree)),
        (Scopes::Province, "num_active_ships", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Province, "num_active_ships_in_battle", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Province, "num_active_ships_not_in_battle", Scopes::Value, Scope(Scopes::Country)),
        (
            Scopes::Country,
            "num_alliances_and_defensive_pacts_with_allies",
            Scopes::Value,
            Scope(Scopes::Country),
        ),
        (
            Scopes::Country,
            "num_alliances_and_defensive_pacts_with_rivals",
            Scopes::Value,
            Scope(Scopes::Country),
        ),
        (Scopes::Front, "num_defending_battalions", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Province, "num_non_destroyed_ships", Scopes::Value, Scope(Scopes::Country)),
        (
            Scopes::Province,
            "num_non_destroyed_ships_in_battle",
            Scopes::Value,
            Scope(Scopes::Country),
        ),
        (
            Scopes::Province,
            "num_non_destroyed_ships_not_in_battle",
            Scopes::Value,
            Scope(Scopes::Country),
        ),
        (Scopes::Province, "num_ships", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Province, "num_ships_in_battle", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Province, "num_ships_not_in_battle", Scopes::Value, Scope(Scopes::Country)),
        (
            Scopes::Country.union(Scopes::MilitaryFormation),
            "num_ships_of_group",
            Scopes::Value,
            Scope(Scopes::ShipGroup),
        ),
        (Scopes::Country, "num_pending_events", Scopes::Value, Item(Item::EventCategory)),
        (Scopes::Country, "num_shared_rivals", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Front, "num_total_battalions", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Province, "num_units", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Province, "num_units_in_battle", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Province, "num_units_not_in_battle", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::None, "p", Scopes::Province, Item(Item::Province)),
        (Scopes::Country, "pirated_trade_value_by", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::None, "play_type", Scopes::DiplomaticPlayType, Item(Item::DiplomaticPlay)),
        (Scopes::None, "pop_type", Scopes::PopType, Item(Item::PopType)),
        (Scopes::None, "principle", Scopes::PowerBlocPrinciple, Item(Item::Principle)),
        (
            Scopes::None,
            "principle_group",
            Scopes::PowerBlocPrincipleGroup,
            Item(Item::PrincipleGroup),
        ),
        (Scopes::Country, "py", Scopes::Party, Item(Item::Party)),
        (Scopes::None, "rank_value", Scopes::Value, Item(Item::CountryRank)),
        (Scopes::StateRegion, "region_state", Scopes::State, Item(Item::Country)), // undocumented
        (Scopes::None, "rel", Scopes::Religion, Item(Item::Religion)),
        (Scopes::Country, "relations", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::Country, "relations_change_rate", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::None, "relations_threshold", Scopes::Value, Item(Item::RelationsThreshold)),
        (Scopes::None, "s", Scopes::StateRegion, Item(Item::StateRegion)),
        (Scopes::None, "scope", Scopes::all(), UncheckedValue),
        (Scopes::State, "sg", Scopes::StateGoods, Item(Item::Goods)),
        (Scopes::None, "ship_group", Scopes::ShipGroup, Item(Item::ShipGroup)),
        (Scopes::None, "ship_type", Scopes::ShipType, Item(Item::ShipType)),
        (Scopes::None, "sr", Scopes::StrategicRegion, Item(Item::StrategicRegion)),
        (Scopes::Country, "strait_trade_importance_by", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::None, "strait_type", Scopes::StraitType, Item(Item::StraitDefinition)),
        (Scopes::Country, "tension", Scopes::Value, Scope(Scopes::Country)),
        (Scopes::None, "tension_threshold", Scopes::Value, UncheckedValue),
        (Scopes::None, "unit_type", Scopes::CombatUnitType, Item(Item::CombatUnit)),
        (Scopes::all(), "var", Scopes::all(), UncheckedValue),
    ]
};

pub fn scope_to_scope_removed(name: &str) -> Option<(&'static str, &'static str)> {
    for (removed_name, version, explanation) in SCOPE_TO_SCOPE_REMOVED.iter().copied() {
        if name == removed_name {
            return Some((version, explanation));
        }
    }
    None
}

const SCOPE_TO_SCOPE_REMOVED: &[(&str, &str, &str)] = &[
    ("num_commanded_units", "1.6", ""),
    ("num_enemy_units", "1.6", ""),
    ("supply", "1.6", ""),
    ("active_diplomatic_play", "1.7", ""),
    ("actor_market", "1.9", "replaced by world market system"),
    ("commander", "1.9", ""),
    ("exporter", "1.9", "replaced by world market system"),
    ("importer", "1.9", "replaced by world market system"),
    ("naval_invasion_attacker", "1.9", "replaced with `invasion_attacker`"),
    ("naval_invasion_defender", "1.9", "replaced with `invasion_defender`"),
    ("num_export_trade_routes", "1.9", "replaced by world market system"),
    ("num_import_trade_routes", "1.9", "replaced by world market system"),
    ("num_mutual_trade_route_levels_with_country", "1.9", "replaced by world market system"),
    ("num_trade_routes", "1.9", "replaced by world market system"),
    ("num_treaty_ports", "1.9", "replaced by world market system"),
    ("target_market", "1.9", "replaced by world market system"),
    ("expenses", "1.12", ""),
    ("fixed_expenses", "1.12", ""),
    ("highest_ranked_commander", "1.13", ""),
    ("num_active_declared_interests", "1.13", ""),
    ("num_convoys_available", "1.13", ""),
    ("num_convoys_required", "1.13", ""),
    ("num_declared_interests", "1.13", ""),
];