tiger-lib 1.17.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
#![allow(unused_imports)] // TODO EU5: remove this when ready
use std::sync::LazyLock;

use crate::everything::Everything;
use crate::helpers::TigerHashMap;
use crate::item::Item;
use crate::lowercase::Lowercase;
use crate::report::{ErrorKey, err};
use crate::scopes::Scopes;
use crate::token::Token;

#[inline]
pub fn iterator(
    name_lc: &Lowercase,
    _name: &Token,
    _data: &Everything,
) -> Option<(Scopes, Scopes)> {
    ITERATOR_MAP.get(name_lc.as_str()).copied()
}

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

/// See `effects.log` from the game data dumps
/// These are the list iterators. Every entry represents
/// a every_, ordered_, random_, and any_ version.
const ITERATOR: &[(Scopes, &str, Scopes)] = &[
    (Scopes::Country, "accepted_culture", Scopes::Culture),
    (Scopes::Country, "active_disaster", Scopes::Disaster),
    (Scopes::None, "active_estate", Scopes::EstateType),
    (
        Scopes::InternationalOrganization.union(Scopes::Situation),
        "active_resolution",
        Scopes::ActiveResolution,
    ),
    (Scopes::Area, "adjacent_ports_to_area", Scopes::Location),
    (Scopes::None, "advance_definition", Scopes::AdvanceType),
    (Scopes::HeirSelection, "allowed_estate_in_heir_selection", Scopes::EstateType),
    (Scopes::Character, "ancestor", Scopes::Character),
    (Scopes::None, "area", Scopes::Area),
    (Scopes::Region, "area_in_region", Scopes::Area),
    (Scopes::ScriptedGeography, "area_in_scripted_geography", Scopes::Area),
    (Scopes::Country, "area_with_core", Scopes::Area),
    (Scopes::Country, "area_with_owned_province", Scopes::Area),
    (Scopes::Country, "army", Scopes::Unit),
    (Scopes::Country, "artist", Scopes::Character),
    (Scopes::War, "attacker", Scopes::Country),
    (Scopes::God, "avatar_for_god", Scopes::Avatar),
    (Scopes::Siege, "besieging_unit", Scopes::Unit),
    (Scopes::Country, "border_location", Scopes::Location),
    (Scopes::Country, "buildable_building_type", Scopes::BuildingType),
    (Scopes::None, "building_type", Scopes::BuildingType),
    (Scopes::Location, "buildings_in_location", Scopes::Building),
    (Scopes::Country, "cabinet", Scopes::Cabinet),
    (Scopes::Country, "cabinet_action", Scopes::CabinetAction),
    (Scopes::Country, "cabinet_character", Scopes::Character),
    (Scopes::Country, "cardinal_in_country", Scopes::Cardinal),
    (Scopes::Religion, "cardinal_in_religion", Scopes::Cardinal),
    (Scopes::Country, "casus_belli_on_us", Scopes::Country),
    (Scopes::Country, "casus_belli_target", Scopes::Country),
    (Scopes::CombatSide, "center", Scopes::SubUnit),
    (Scopes::Country, "character", Scopes::Character),
    (Scopes::Dynasty, "character_in_dynasty", Scopes::Character),
    (Scopes::Rebels, "character_supporting_rebel", Scopes::Character),
    (Scopes::Character, "child", Scopes::Character),
    (Scopes::Character, "close_relative", Scopes::Character),
    (Scopes::Location, "coast_border_location", Scopes::Location),
    (Scopes::Country, "colonial_charter", Scopes::ColonialCharter),
    (Scopes::Country, "colonial_claim_province_definition", Scopes::ProvinceDefinition),
    (Scopes::None, "colonial_country", Scopes::Country),
    (Scopes::None, "colonial_overlord", Scopes::Country),
    (Scopes::None, "colonial_top_overlord", Scopes::Country),
    (Scopes::Location, "connected_location", Scopes::Location),
    (Scopes::BuildingType, "construction_material_for_building_type", Scopes::Goods),
    (Scopes::None, "continent", Scopes::Continent),
    (Scopes::ScriptedGeography, "continent_in_scripted_geography", Scopes::Continent),
    (Scopes::Country, "controlled_location", Scopes::Location),
    (Scopes::Location, "core_in_location", Scopes::Country),
    (Scopes::Country, "core_location", Scopes::Location),
    (Scopes::None, "country", Scopes::Country),
    (Scopes::Country, "country_annexing_us", Scopes::Country),
    (Scopes::Country, "country_at_war_with", Scopes::Country),
    (Scopes::Culture, "country_in_culture", Scopes::Country),
    (Scopes::CultureGroup, "country_in_culture_group", Scopes::Country),
    (Scopes::Country, "country_in_diplomatic_range", Scopes::Country),
    (Scopes::Dynasty, "country_in_dynasty", Scopes::Country),
    (Scopes::Country, "country_in_hierarchy", Scopes::Country),
    (Scopes::Religion, "country_in_religion", Scopes::Country),
    (Scopes::Group, "country_in_religion_group", Scopes::Country),
    (Scopes::ReligiousSchool, "country_in_religious_school", Scopes::Country),
    (Scopes::Country, "country_lent_to", Scopes::Country),
    (Scopes::None, "country_of_country_type", Scopes::Country),
    (Scopes::Country, "country_sub_unit", Scopes::SubUnit),
    (Scopes::Rebels, "country_supporting_rebel", Scopes::Country),
    (Scopes::Country, "country_that_can_be_called_defensively", Scopes::Country),
    (Scopes::Country, "country_that_can_be_called_offensively", Scopes::Country),
    (Scopes::Country, "country_together_in_war_with", Scopes::Country),
    (Scopes::Country, "country_we_are_annexing", Scopes::Country),
    (Scopes::Country, "country_with_antagonism_against_us", Scopes::Country), // TODO: REMOVED
    (
        Scopes::Location
            .union(Scopes::ProvinceDefinition)
            .union(Scopes::Area)
            .union(Scopes::Region)
            .union(Scopes::SubContinent)
            .union(Scopes::Continent),
        "country_with_capital_in_geography",
        Scopes::Country,
    ),
    (Scopes::Religion, "country_with_cardinals", Scopes::Country),
    (Scopes::Country, "country_with_coalition_grade_antagonism_against_us", Scopes::Country),
    (Scopes::Country, "country_with_relation_that_can_be_annulled", Scopes::Country),
    (Scopes::InternationalOrganization, "country_with_special_status_of_type", Scopes::Country),
    (Scopes::None, "country_with_succession_law", Scopes::Country),
    (Scopes::None, "culture", Scopes::Culture),
    (Scopes::Culture, "culture_group", Scopes::CultureGroup),
    (Scopes::CultureGroup, "culture_in_culture_group", Scopes::Culture),
    (Scopes::CultureGroup, "culture_in_group", Scopes::Culture), // TODO: REMOVED
    (Scopes::Country, "current_avatars", Scopes::Avatar),
    (Scopes::Country, "current_gods", Scopes::God),
    (Scopes::Country, "current_law", Scopes::Law),
    (Scopes::InternationalOrganization, "current_law_in_international_organization", Scopes::Law),
    (Scopes::Country, "current_policy", Scopes::Policy),
    (
        Scopes::InternationalOrganization,
        "current_policy_in_international_organization",
        Scopes::Policy,
    ),
    (Scopes::Country, "current_reforms", Scopes::GovernmentReform),
    (Scopes::Country, "current_war", Scopes::War),
    (Scopes::War, "defender", Scopes::Country),
    (Scopes::Character, "descendant", Scopes::Character),
    (Scopes::Country, "disloyal_subject", Scopes::Country),
    (Scopes::Country, "dynasty", Scopes::Dynasty),
    (Scopes::ProvinceDefinition, "east_of_province_definition", Scopes::ProvinceDefinition),
    (Scopes::Country, "election_candidates", Scopes::Character),
    (Scopes::Country, "enemy", Scopes::Country),
    (Scopes::Country, "enemy_war_leader", Scopes::Country),
    (Scopes::Country, "estate", Scopes::Estate),
    (Scopes::Country, "estate_privilege", Scopes::EstatePrivilege),
    (Scopes::Policy, "estate_type_preferring", Scopes::EstateType),
    (Scopes::Country, "exploration_from_country", Scopes::Exploration),
    (Scopes::Market, "export", Scopes::Trade),
    (Scopes::Location, "export_from_location", Scopes::Location),
    (Scopes::None, "food_goods", Scopes::Goods),
    (Scopes::Location, "foreign_building_countries_in_location", Scopes::Country),
    (Scopes::Location, "foreign_buildings_in_location", Scopes::Building),
    (Scopes::Country, "fort_in_country", Scopes::Location),
    (Scopes::Location, "friendly_coast_border_location", Scopes::Location),
    (Scopes::Country, "friendly_country", Scopes::Country),
    (Scopes::Country, "friendly_or_high_opinion_country", Scopes::Country),
    (Scopes::Country, "friendly_to_friendly_country", Scopes::Country),
    (Scopes::Country, "friendly_to_hostile_country", Scopes::Country),
    (Scopes::Religion, "god_in_religion", Scopes::God),
    (Scopes::Demand, "good_in_demand", Scopes::Goods),
    (Scopes::None, "goods", Scopes::Goods),
    (Scopes::Culture, "graphical_culture_in_culture", Scopes::GraphicalCulture),
    (Scopes::None, "great_power", Scopes::Country),
    (Scopes::Country, "heathen_location", Scopes::Location),
    (Scopes::Country, "heretic_location", Scopes::Location),
    (Scopes::Country, "hired_mercenary", Scopes::Mercenary),
    (Scopes::Country, "historical_enemy", Scopes::Country),
    (Scopes::Country, "historical_rival", Scopes::Country),
    (Scopes::Country, "holy_site_in_country", Scopes::HolySite),
    (Scopes::Religion, "holy_site_in_religion", Scopes::HolySite),
    (Scopes::Country, "hostile_country", Scopes::Country),
    (Scopes::Country, "hostile_or_low_opinion_country", Scopes::Country),
    (Scopes::Country, "hostile_to_friendly_country", Scopes::Country),
    (Scopes::Country, "hostile_to_hostile_country", Scopes::Country),
    (Scopes::Market, "import", Scopes::Trade),
    (Scopes::Location, "import_from_location", Scopes::Location),
    (Scopes::None, "in_global_list", Scopes::all_but_none()),
    (Scopes::None, "in_list", Scopes::all_but_none()),
    (Scopes::None, "in_local_list", Scopes::all_but_none()),
    (Scopes::Country, "institutions_embraced", Scopes::Institution),
    (Scopes::None, "international_organization", Scopes::InternationalOrganization),
    (Scopes::InternationalOrganization, "international_organization_elector", Scopes::Country),
    (Scopes::InternationalOrganization, "international_organization_enemy", Scopes::Country),
    (Scopes::InternationalOrganization, "international_organization_member", Scopes::Country),
    (
        Scopes::InternationalOrganization,
        "international_organization_owned_location",
        Scopes::Location,
    ),
    (Scopes::Location, "international_organization_owner", Scopes::InternationalOrganization),
    (
        Scopes::InternationalOrganization,
        "international_organization_parliament_opposers",
        Scopes::Country,
    ),
    (
        Scopes::InternationalOrganization,
        "international_organization_parliament_supporter",
        Scopes::Country,
    ),
    (Scopes::Country, "international_organizations_member_of", Scopes::InternationalOrganization),
    (Scopes::Country, "international_organizations_target_of", Scopes::InternationalOrganization),
    (Scopes::Country, "invited_religious_figure", Scopes::Character),
    (Scopes::None, "key_in_global_variable_map", Scopes::all_but_none()),
    (Scopes::None, "key_in_local_variable_map", Scopes::all_but_none()),
    (Scopes::None, "key_in_variable_map", Scopes::all_but_none()),
    (Scopes::Country, "known_country", Scopes::Country),
    (Scopes::Country, "known_institution", Scopes::Institution),
    (Scopes::CombatSide, "left_flank", Scopes::SubUnit),
    (Scopes::Country, "lent_loan", Scopes::Loan),
    (Scopes::Country, "loan", Scopes::Loan),
    (Scopes::Country, "loan_lent_to_country", Scopes::Loan),
    (Scopes::Area, "location_in_area", Scopes::Location),
    (Scopes::Continent, "location_in_continent", Scopes::Location),
    (Scopes::Market, "location_in_market", Scopes::Location),
    (Scopes::Province, "location_in_province", Scopes::Location),
    (Scopes::ProvinceDefinition, "location_in_province_definition", Scopes::Location),
    (Scopes::Region, "location_in_region", Scopes::Location),
    (Scopes::ScriptedGeography, "location_in_scripted_geography", Scopes::Location),
    (Scopes::SubContinent, "location_in_sub_continent", Scopes::Location),
    (Scopes::None, "location_in_the_world", Scopes::Location),
    (Scopes::Country, "loyal_subject", Scopes::Country),
    (Scopes::Country, "maritime_area", Scopes::Area),
    (Scopes::Country, "market_center_in_country", Scopes::Market),
    (Scopes::None, "market_in_world", Scopes::Market),
    (Scopes::Country, "market_present_in_country", Scopes::Market),
    (Scopes::Country, "market_with_merchants", Scopes::Market),
    (Scopes::None, "mercenary", Scopes::Mercenary),
    (Scopes::Mercenary, "mercenary_sub_unit", Scopes::SubUnit),
    (Scopes::Market, "merchant_in_market", Scopes::Country),
    (Scopes::Country, "navy", Scopes::Unit),
    (Scopes::Area, "neighbor_area", Scopes::Area),
    (Scopes::Country, "neighbor_country", Scopes::Country),
    (Scopes::Location, "neighbor_location", Scopes::Location),
    (Scopes::ProvinceDefinition, "neighbor_province_definition", Scopes::ProvinceDefinition),
    (Scopes::None, "new_world_goods", Scopes::Goods),
    (Scopes::Location, "nomad_countries_in_location", Scopes::Country),
    (Scopes::Country, "non_state_religion_location", Scopes::Location),
    (Scopes::None, "old_world_goods", Scopes::Goods),
    (Scopes::Country, "other_core_country", Scopes::Country),
    (Scopes::Country, "other_country", Scopes::Country),
    (Scopes::Country, "other_great_power", Scopes::Country),
    (Scopes::Religion, "other_religion_in_same_group", Scopes::Religion),
    (Scopes::Country, "other_revolutionary", Scopes::Country),
    (Scopes::Country, "overlord_or_above", Scopes::Country),
    (Scopes::None, "ownable_location", Scopes::Location),
    (Scopes::Area, "ownable_location_in_area", Scopes::Location),
    (Scopes::Continent, "ownable_location_in_continent", Scopes::Location),
    (Scopes::ProvinceDefinition, "ownable_location_in_province_definition", Scopes::Location),
    (Scopes::Region, "ownable_location_in_region", Scopes::Location),
    (Scopes::ScriptedGeography, "ownable_location_in_scripted_geography", Scopes::Location),
    (Scopes::SubContinent, "ownable_location_in_sub_continent", Scopes::Location),
    (Scopes::Country, "owned_building", Scopes::Building),
    (Scopes::Country, "owned_foreign_building", Scopes::Building),
    (Scopes::Country, "owned_foreign_building_location", Scopes::Location),
    (Scopes::Country, "owned_foreign_building_region", Scopes::Region),
    (Scopes::Country, "owned_location", Scopes::Location),
    (Scopes::Country, "owned_nomad_pop", Scopes::Pop),
    (Scopes::Country, "owned_non_rural_location", Scopes::Location),
    (Scopes::Country, "owned_rural_location", Scopes::Location),
    (Scopes::Region, "owner_in_region", Scopes::Country),
    (Scopes::Character, "parent", Scopes::Character),
    (Scopes::CombatSide, "participating_countries", Scopes::Country),
    (Scopes::CombatSide, "participating_units", Scopes::Unit),
    (Scopes::Country, "past_liturgical_dialect", Scopes::Country),
    (Scopes::Law, "policy_in_law", Scopes::Policy),
    (Scopes::Country, "political_border_location", Scopes::Location),
    (Scopes::Location.union(Scopes::Country), "pop", Scopes::Pop),
    (Scopes::Rebels, "pops_supporting_rebel", Scopes::Pop),
    (Scopes::Country, "port_in_country", Scopes::Location),
    (Scopes::Country, "possible_disaster", Scopes::Disaster),
    (
        Scopes::Country.union(Scopes::InternationalOrganization),
        "possible_parliament_issue",
        Scopes::ParliamentIssue,
    ),
    (Scopes::Country, "possible_policy", Scopes::Policy),
    (Scopes::Estate, "possible_privilege", Scopes::EstatePrivilege),
    (Scopes::Country, "possible_recruit_location", Scopes::Location),
    (
        Scopes::Location
            .union(Scopes::ProvinceDefinition)
            .union(Scopes::Area)
            .union(Scopes::Region)
            .union(Scopes::SubContinent)
            .union(Scopes::Continent),
        "present_country",
        Scopes::Country,
    ),
    (Scopes::Country, "present_culture_in_country", Scopes::Culture),
    (Scopes::Location, "present_culture_in_location", Scopes::Culture),
    (
        Scopes::Location
            .union(Scopes::ProvinceDefinition)
            .union(Scopes::Area)
            .union(Scopes::Region)
            .union(Scopes::SubContinent)
            .union(Scopes::Continent),
        "present_overlord",
        Scopes::Country,
    ),
    (Scopes::Country, "present_religion_in_country", Scopes::Religion),
    (Scopes::Location, "present_religion_in_location", Scopes::Religion),
    (Scopes::Country, "primary_or_accepted_culture", Scopes::Culture),
    (Scopes::Country, "primary_or_accepted_or_tolerated_culture", Scopes::Culture),
    (Scopes::None, "privateer", Scopes::Privateer),
    (Scopes::Country, "privateer_from_country", Scopes::Privateer),
    (Scopes::Area, "privateer_in_area", Scopes::Privateer),
    (Scopes::None, "production_method", Scopes::ProductionMethod),
    (Scopes::Building, "production_method_of_building", Scopes::ProductionMethod),
    (Scopes::Country, "province", Scopes::Province),
    (Scopes::None, "province_definition", Scopes::ProvinceDefinition),
    (Scopes::Area, "province_definition_in_area", Scopes::ProvinceDefinition),
    (
        Scopes::ScriptedGeography,
        "province_definition_in_scripted_geography",
        Scopes::ProvinceDefinition,
    ),
    (Scopes::Area, "province_in_area", Scopes::Province),
    (Scopes::ProvinceDefinition, "province_in_province_definition", Scopes::Province),
    (Scopes::Country, "rebel", Scopes::Rebels),
    (Scopes::None, "region", Scopes::Region),
    (Scopes::SubContinent, "region_in_continent", Scopes::Region),
    (Scopes::ScriptedGeography, "region_in_scripted_geography", Scopes::Region),
    (Scopes::Country, "related_country", Scopes::Country),
    (Scopes::None, "religion", Scopes::Religion),
    (Scopes::God, "religion_for_god", Scopes::Religion),
    (Scopes::Group, "religion_in_religion_group", Scopes::Religion),
    (Scopes::Religion, "religion_international_organization", Scopes::InternationalOrganization),
    (Scopes::Country, "religious_aspect", Scopes::ReligiousAspect),
    (Scopes::Country, "religious_focus", Scopes::ReligiousFocus),
    (Scopes::Religion, "religious_school_in_religion", Scopes::ReligiousSchool),
    (Scopes::Country, "rented_out_mercenary", Scopes::Mercenary),
    (Scopes::ProductionMethod, "required_goods", Scopes::Goods),
    (Scopes::CombatSide, "reserves", Scopes::SubUnit),
    (Scopes::CombatSide, "retreated", Scopes::SubUnit),
    (Scopes::None, "revolutionary", Scopes::Country),
    (Scopes::CombatSide, "right_flank", Scopes::SubUnit),
    (Scopes::Country, "rival", Scopes::Country),
    (Scopes::None, "road_type", Scopes::RoadType),
    (Scopes::Country, "royal_marriage", Scopes::Country),
    (Scopes::Country, "ruler", Scopes::Character),
    (Scopes::Character, "ruling_countries", Scopes::Country),
    (Scopes::Country, "sound_toll_in_country", Scopes::Location),
    (Scopes::Character, "spouse", Scopes::Character),
    (Scopes::Country, "spy_network_built_in_us", Scopes::Country),
    (Scopes::None, "sub_continent", Scopes::SubContinent),
    (Scopes::Continent, "sub_continent_in_continent", Scopes::SubContinent),
    (Scopes::ScriptedGeography, "sub_continent_in_scripted_geography", Scopes::SubContinent),
    (Scopes::Unit, "sub_unit", Scopes::SubUnit),
    (Scopes::Country, "subject", Scopes::Country),
    (Scopes::Country, "subject_or_below", Scopes::Country),
    (Scopes::Country, "tolerated_culture", Scopes::Culture),
    (Scopes::Country, "trade", Scopes::Trade),
    (Scopes::Country, "union_partner", Scopes::Country),
    (Scopes::Country, "unit", Scopes::Unit),
    (Scopes::Location, "unit_in_location", Scopes::Unit),
    (Scopes::ReligiousAspect, "valid_religion_for_aspect", Scopes::Religion),
    (Scopes::ActiveResolution, "voter", Scopes::Country),
    (Scopes::None, "war", Scopes::War),
    (Scopes::War, "war_participant", Scopes::Country),
    (Scopes::Location, "weather_system_in_location", Scopes::WeatherSystem),
    (Scopes::ProvinceDefinition, "west_of_province_definition", Scopes::ProvinceDefinition),
    (Scopes::None, "work_of_art", Scopes::WorkOfArt),
    (Scopes::Character, "work_of_art_by_creator", Scopes::WorkOfArt),
    (Scopes::Country, "work_of_art_in_country", Scopes::WorkOfArt),
    (Scopes::Location, "work_of_art_in_location", Scopes::WorkOfArt),
];

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

const ITERATOR_REMOVED: &[(&str, &str, &str)] = &[];