From 1b6f89f5ba8de2895e05365f8bfbf04e723c9e99 Mon Sep 17 00:00:00 2001 From: hop311 Date: Thu, 18 Jan 2024 22:00:51 +0000 Subject: Minor enum cleanup, changed string functions into stream overloads --- src/openvic-simulation/scripts/Condition.cpp | 271 +++++++++++++-------------- src/openvic-simulation/scripts/Condition.hpp | 63 +++++-- 2 files changed, 175 insertions(+), 159 deletions(-) (limited to 'src/openvic-simulation/scripts') diff --git a/src/openvic-simulation/scripts/Condition.cpp b/src/openvic-simulation/scripts/Condition.cpp index ce18824..045649b 100644 --- a/src/openvic-simulation/scripts/Condition.cpp +++ b/src/openvic-simulation/scripts/Condition.cpp @@ -6,6 +6,10 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; +using enum value_type_t; +using enum scope_t; +using enum identifier_type_t; + Condition::Condition( std::string_view new_identifier, value_type_t new_value_type, scope_t new_scope, scope_t new_scope_change, identifier_type_t new_key_identifier_type, @@ -30,23 +34,23 @@ bool ConditionManager::add_condition( return false; } - if (value_type == value_type_t::NO_TYPE || value_type > value_type_t::MAX_VALUE) { + if (value_type == NO_TYPE || value_type > MAX_VALUE) { Logger::error("Condition ", identifier, " has invalid value type: ", static_cast(value_type)); return false; } - if (scope == scope_t::NO_SCOPE || scope > scope_t::MAX_SCOPE) { + if (scope == NO_SCOPE || scope > MAX_SCOPE) { Logger::error("Condition ", identifier, " has invalid scope: ", static_cast(scope)); return false; } - if (share_value_type(value_type, value_type_t::IDENTIFIER) && value_identifier_type == identifier_type_t::NONE) { + if (share_value_type(value_type, IDENTIFIER) && value_identifier_type == NO_IDENTIFIER) { Logger::error("Condition ", identifier, " has no identifier type!"); return false; } // don't perform the check for complex types - if (!share_value_type(value_type, value_type_t::COMPLEX)) { - if (!share_value_type(value_type, value_type_t::IDENTIFIER) && value_identifier_type != identifier_type_t::NONE) { + if (!share_value_type(value_type, COMPLEX)) { + if (!share_value_type(value_type, IDENTIFIER) && value_identifier_type != NO_IDENTIFIER) { Logger::warning("Condition ", identifier, " specified an identifier type, but doesn't have an identifier!"); } } @@ -64,10 +68,6 @@ bool ConditionManager::add_condition( bool ConditionManager::setup_conditions(GameManager const& game_manager) { bool ret = true; - using enum value_type_t; - using enum scope_t; - using enum identifier_type_t; - /* Special Scopes */ ret &= add_condition("THIS", GROUP, COUNTRY, THIS); ret &= add_condition("FROM", GROUP, COUNTRY, FROM); @@ -109,7 +109,7 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { /* Global Conditions */ ret &= add_condition("year", INTEGER, COUNTRY); ret &= add_condition("month", INTEGER, COUNTRY); - ret &= add_condition("has_global_flag", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, GLOBAL_FLAG); + ret &= add_condition("has_global_flag", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, GLOBAL_FLAG); ret &= add_condition("is_canal_enabled", INTEGER, COUNTRY); ret &= add_condition("always", BOOLEAN, COUNTRY); ret &= add_condition("world_wars_enabled", BOOLEAN, COUNTRY); @@ -117,76 +117,76 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { /* Country Scope Conditions */ ret &= add_condition("administration_spending", REAL, COUNTRY); ret &= add_condition("ai", BOOLEAN, COUNTRY); - ret &= add_condition("alliance_with", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); + ret &= add_condition("alliance_with", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); ret &= add_condition("average_consciousness", REAL, COUNTRY); ret &= add_condition("average_militancy", REAL, COUNTRY); ret &= add_condition("badboy", REAL, COUNTRY); - ret &= add_condition("big_producer", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, TRADE_GOOD); + ret &= add_condition("big_producer", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, TRADE_GOOD); ret &= add_condition("blockade", REAL, COUNTRY); ret &= add_condition("brigades_compare", REAL, COUNTRY); - ret &= add_condition("can_build_factory_in_capital_state", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, BUILDING); + ret &= add_condition("can_build_factory_in_capital_state", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, BUILDING); ret &= add_condition("can_build_fort_in_capital", COMPLEX, COUNTRY); ret &= add_condition("can_build_railway_in_capital", COMPLEX, COUNTRY); ret &= add_condition("can_nationalize", BOOLEAN, COUNTRY); ret &= add_condition("can_create_vassals", BOOLEAN, COUNTRY); - ret &= add_condition("capital", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, PROVINCE_ID); - ret &= add_condition("casus_belli", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); - ret &= add_condition("check_variable", COMPLEX, COUNTRY, NO_SCOPE, NONE, VARIABLE); - ret &= add_condition("citizenship_policy", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, ISSUE); + ret &= add_condition("capital", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, PROVINCE_ID); + ret &= add_condition("casus_belli", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); + ret &= add_condition("check_variable", COMPLEX, COUNTRY, NO_SCOPE, NO_IDENTIFIER, VARIABLE); + ret &= add_condition("citizenship_policy", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, ISSUE); ret &= add_condition("civilization_progress", REAL, COUNTRY); ret &= add_condition("civilized", BOOLEAN, COUNTRY); ret &= add_condition("colonial_nation", BOOLEAN, COUNTRY); ret &= add_condition("consciousness", REAL, COUNTRY); ret &= add_condition("constructing_cb_progress", REAL, COUNTRY); - ret &= add_condition("constructing_cb_type", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, CASUS_BELLI); - ret &= add_condition("continent", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, CONTINENT); - ret &= add_condition("controls", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, PROVINCE_ID); + ret &= add_condition("constructing_cb_type", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, CASUS_BELLI); + ret &= add_condition("continent", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, CONTINENT); + ret &= add_condition("controls", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, PROVINCE_ID); ret &= add_condition("crime_fighting", REAL, COUNTRY); ret &= add_condition("crime_higher_than_education", BOOLEAN, COUNTRY); ret &= add_condition("crisis_exist", BOOLEAN, COUNTRY); - ret &= add_condition("culture", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, CULTURE); + ret &= add_condition("culture", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, CULTURE); ret &= add_condition("culture_has_union_tag", BOOLEAN, COUNTRY); ret &= add_condition("diplomatic_influence", COMPLEX, COUNTRY); - ret &= add_condition("economic_policy", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, ISSUE); + ret &= add_condition("economic_policy", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, ISSUE); ret &= add_condition("education_spending", REAL, COUNTRY); ret &= add_condition("election", BOOLEAN, COUNTRY); - ret &= add_condition("exists", IDENTIFIER | BOOLEAN, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); - ret &= add_condition("government", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, GOVERNMENT_TYPE); + ret &= add_condition("exists", IDENTIFIER | BOOLEAN, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); + ret &= add_condition("government", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, GOVERNMENT_TYPE); ret &= add_condition("great_wars_enabled", BOOLEAN, COUNTRY); - ret &= add_condition("have_core_in", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); - ret &= add_condition("has_country_flag", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_FLAG); - ret &= add_condition("has_country_modifier", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, MODIFIER); + ret &= add_condition("have_core_in", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); + ret &= add_condition("has_country_flag", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_FLAG); + ret &= add_condition("has_country_modifier", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, MODIFIER); ret &= add_condition("has_cultural_sphere", BOOLEAN, COUNTRY); ret &= add_condition("has_leader", STRING, COUNTRY); - ret &= add_condition("has_pop_culture", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, CULTURE); - ret &= add_condition("has_pop_religion", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, RELIGION); - ret &= add_condition("has_pop_type", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, POP_TYPE); + ret &= add_condition("has_pop_culture", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, CULTURE); + ret &= add_condition("has_pop_religion", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, RELIGION); + ret &= add_condition("has_pop_type", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, POP_TYPE); ret &= add_condition("has_recently_lost_war", BOOLEAN, COUNTRY); ret &= add_condition("has_unclaimed_cores", BOOLEAN, COUNTRY); - ret &= add_condition("ideology", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, IDEOLOGY); - ret &= add_condition("industrial_score", REAL | IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); - ret &= add_condition("in_sphere", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); - ret &= add_condition("in_default", IDENTIFIER | BOOLEAN, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); - ret &= add_condition("invention", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, INVENTION); + ret &= add_condition("ideology", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, IDEOLOGY); + ret &= add_condition("industrial_score", REAL | IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); + ret &= add_condition("in_sphere", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); + ret &= add_condition("in_default", IDENTIFIER | BOOLEAN, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); + ret &= add_condition("invention", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, INVENTION); ret &= add_condition("involved_in_crisis", BOOLEAN, COUNTRY); ret &= add_condition("is_claim_crisis", BOOLEAN, COUNTRY); ret &= add_condition("is_colonial_crisis", BOOLEAN, COUNTRY); - ret &= add_condition("is_cultural_union", IDENTIFIER | BOOLEAN, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); + ret &= add_condition("is_cultural_union", IDENTIFIER | BOOLEAN, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); ret &= add_condition("is_disarmed", BOOLEAN, COUNTRY); ret &= add_condition("is_greater_power", BOOLEAN, COUNTRY); ret &= add_condition("is_colonial", BOOLEAN, STATE); - ret &= add_condition("is_core", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG | PROVINCE_ID); - ret &= add_condition("is_culture_group", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG | CULTURE_GROUP); - ret &= add_condition("is_ideology_enabled", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, IDEOLOGY); + ret &= add_condition("is_core", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG | PROVINCE_ID); + ret &= add_condition("is_culture_group", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG | CULTURE_GROUP); + ret &= add_condition("is_ideology_enabled", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, IDEOLOGY); ret &= add_condition("is_independant", BOOLEAN, COUNTRY); //paradox typo ret &= add_condition("is_liberation_crisis", BOOLEAN, COUNTRY); ret &= add_condition("is_mobilised", BOOLEAN, COUNTRY); - ret &= add_condition("is_next_reform", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, REFORM); - ret &= add_condition("is_our_vassal", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); - ret &= add_condition("is_possible_vassal", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); - ret &= add_condition("is_releasable_vassal", IDENTIFIER | BOOLEAN, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); + ret &= add_condition("is_next_reform", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, REFORM); + ret &= add_condition("is_our_vassal", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); + ret &= add_condition("is_possible_vassal", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); + ret &= add_condition("is_releasable_vassal", IDENTIFIER | BOOLEAN, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); ret &= add_condition("is_secondary_power", BOOLEAN, COUNTRY); - ret &= add_condition("is_sphere_leader_of", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); + ret &= add_condition("is_sphere_leader_of", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); ret &= add_condition("is_substate", BOOLEAN, COUNTRY); ret &= add_condition("is_vassal", BOOLEAN, COUNTRY); ret &= add_condition("literacy", REAL, COUNTRY); @@ -196,14 +196,14 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { ret &= add_condition("middle_strata_life_needs", REAL, COUNTRY); ret &= add_condition("middle_strata_luxury_needs", REAL, COUNTRY); ret &= add_condition("middle_tax", REAL, COUNTRY); - ret &= add_condition("military_access", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); - ret &= add_condition("military_score", REAL | IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); + ret &= add_condition("military_access", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); + ret &= add_condition("military_score", REAL | IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); ret &= add_condition("militancy", REAL, COUNTRY); ret &= add_condition("military_spending", REAL, COUNTRY); ret &= add_condition("money", REAL, COUNTRY); - ret &= add_condition("nationalvalue", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, NATIONAL_VALUE); + ret &= add_condition("nationalvalue", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, NATIONAL_VALUE); ret &= add_condition("national_provinces_occupied", REAL, COUNTRY); - ret &= add_condition("neighbour", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); + ret &= add_condition("neighbour", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); ret &= add_condition("num_of_allies", INTEGER, COUNTRY); ret &= add_condition("num_of_cities", INTEGER, COUNTRY); ret &= add_condition("num_of_ports", INTEGER, COUNTRY); @@ -212,14 +212,14 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { ret &= add_condition("num_of_substates", INTEGER, COUNTRY); ret &= add_condition("num_of_vassals", INTEGER, COUNTRY); ret &= add_condition("num_of_vassals_no_substates", INTEGER, COUNTRY); - ret &= add_condition("owns", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, PROVINCE_ID); + ret &= add_condition("owns", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, PROVINCE_ID); ret &= add_condition("part_of_sphere", BOOLEAN, COUNTRY); ret &= add_condition("plurality", REAL, COUNTRY); ret &= add_condition("political_movement_strength", REAL, COUNTRY); ret &= add_condition("political_reform_want", REAL, COUNTRY); - ret &= add_condition("pop_majority_culture", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, CULTURE); - ret &= add_condition("pop_majority_ideology", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, IDEOLOGY); - ret &= add_condition("pop_majority_religion", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, RELIGION); + ret &= add_condition("pop_majority_culture", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, CULTURE); + ret &= add_condition("pop_majority_ideology", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, IDEOLOGY); + ret &= add_condition("pop_majority_religion", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, RELIGION); ret &= add_condition("pop_militancy", REAL, COUNTRY); ret &= add_condition("poor_strata_militancy", REAL, COUNTRY); ret &= add_condition("poor_strata_everyday_needs", REAL, COUNTRY); @@ -227,15 +227,15 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { ret &= add_condition("poor_strata_luxury_needs", REAL, COUNTRY); ret &= add_condition("poor_tax", REAL, COUNTRY); ret &= add_condition("prestige", REAL, COUNTRY); - ret &= add_condition("primary_culture", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, CULTURE); - ret &= add_condition("accepted_culture", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, CULTURE); - ret &= add_condition("produces", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, TRADE_GOOD); + ret &= add_condition("primary_culture", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, CULTURE); + ret &= add_condition("accepted_culture", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, CULTURE); + ret &= add_condition("produces", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, TRADE_GOOD); ret &= add_condition("rank", INTEGER, COUNTRY); ret &= add_condition("rebel_power_fraction", REAL, COUNTRY); ret &= add_condition("recruited_percentage", REAL, COUNTRY); ret &= add_condition("relation", COMPLEX, COUNTRY); - ret &= add_condition("religion", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, RELIGION); - ret &= add_condition("religious_policy", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, ISSUE); + ret &= add_condition("religion", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, RELIGION); + ret &= add_condition("religious_policy", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, ISSUE); ret &= add_condition("revanchism", REAL, COUNTRY); ret &= add_condition("revolt_percentage", REAL, COUNTRY); ret &= add_condition("rich_strata_militancy", REAL, COUNTRY); @@ -244,16 +244,16 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { ret &= add_condition("rich_strata_luxury_needs", REAL, COUNTRY); ret &= add_condition("rich_tax", REAL, COUNTRY); ret &= add_condition("rich_tax_above_poor", BOOLEAN, COUNTRY); - ret &= add_condition("ruling_party", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); - ret &= add_condition("ruling_party_ideology", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, IDEOLOGY); + ret &= add_condition("ruling_party", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); + ret &= add_condition("ruling_party_ideology", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, IDEOLOGY); ret &= add_condition("social_movement_strength", REAL, COUNTRY); ret &= add_condition("social_reform_want", REAL, COUNTRY); ret &= add_condition("social_spending", REAL, COUNTRY); - ret &= add_condition("stronger_army_than", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); - ret &= add_condition("substate_of", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); - ret &= add_condition("tag", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); - ret &= add_condition("tech_school", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, TECH_SCHOOL); - ret &= add_condition("this_culture_union", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, CULTURE_UNION); + ret &= add_condition("stronger_army_than", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); + ret &= add_condition("substate_of", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); + ret &= add_condition("tag", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); + ret &= add_condition("tech_school", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, TECH_SCHOOL); + ret &= add_condition("this_culture_union", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, CULTURE_UNION); ret &= add_condition("total_amount_of_divisions", INTEGER, COUNTRY); ret &= add_condition("total_amount_of_ships", INTEGER, COUNTRY); ret &= add_condition("total_defensives", INTEGER, COUNTRY); @@ -262,62 +262,62 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { ret &= add_condition("total_pops", INTEGER, COUNTRY); ret &= add_condition("total_sea_battles", INTEGER, COUNTRY); ret &= add_condition("total_sunk_by_us", INTEGER, COUNTRY); - ret &= add_condition("trade_policy", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, ISSUE); + ret &= add_condition("trade_policy", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, ISSUE); ret &= add_condition("treasury", REAL, COUNTRY); - ret &= add_condition("truce_with", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); + ret &= add_condition("truce_with", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); ret &= add_condition("unemployment", REAL, COUNTRY); ret &= add_condition("unit_has_leader", BOOLEAN, COUNTRY); ret &= add_condition("unit_in_battle", BOOLEAN, COUNTRY); ret &= add_condition("upper_house", COMPLEX, COUNTRY); - ret &= add_condition("vassal_of", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); + ret &= add_condition("vassal_of", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); ret &= add_condition("war", BOOLEAN, COUNTRY); ret &= add_condition("war_exhaustion", REAL, COUNTRY); - ret &= add_condition("war_policy", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, ISSUE); + ret &= add_condition("war_policy", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, ISSUE); ret &= add_condition("war_score", REAL, COUNTRY); - ret &= add_condition("war_with", IDENTIFIER, COUNTRY, NO_SCOPE, NONE, COUNTRY_TAG); + ret &= add_condition("war_with", IDENTIFIER, COUNTRY, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); /* State Scope Conditions */ - ret &= add_condition("controlled_by", IDENTIFIER, STATE, NO_SCOPE, NONE, COUNTRY_TAG); + ret &= add_condition("controlled_by", IDENTIFIER, STATE, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); ret &= add_condition("empty", BOOLEAN, STATE); ret &= add_condition("flashpoint_tension", REAL, STATE); - ret &= add_condition("has_building", IDENTIFIER, STATE, NO_SCOPE, NONE, BUILDING); + ret &= add_condition("has_building", IDENTIFIER, STATE, NO_SCOPE, NO_IDENTIFIER, BUILDING); ret &= add_condition("has_factories", BOOLEAN, STATE); ret &= add_condition("has_flashpoint", BOOLEAN, STATE); ret &= add_condition("is_slave", BOOLEAN, STATE); - ret &= add_condition("owned_by", IDENTIFIER, STATE, NO_SCOPE, NONE, COUNTRY_TAG); - ret &= add_condition("trade_goods_in_state", IDENTIFIER, STATE, NO_SCOPE, NONE, TRADE_GOOD); + ret &= add_condition("owned_by", IDENTIFIER, STATE, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); + ret &= add_condition("trade_goods_in_state", IDENTIFIER, STATE, NO_SCOPE, NO_IDENTIFIER, TRADE_GOOD); ret &= add_condition("work_available", COMPLEX, STATE); /* Province Scope Conditions */ ret &= add_condition("can_build_factory", BOOLEAN, PROVINCE); ret &= add_condition("controlled_by_rebels", BOOLEAN, PROVINCE); - ret &= add_condition("country_units_in_province", IDENTIFIER, PROVINCE, NO_SCOPE, NONE, COUNTRY_TAG); - ret &= add_condition("country_units_in_state", IDENTIFIER, PROVINCE, NO_SCOPE, NONE, COUNTRY_TAG); - ret &= add_condition("has_crime", IDENTIFIER, PROVINCE, NO_SCOPE, NONE, CRIME); + ret &= add_condition("country_units_in_province", IDENTIFIER, PROVINCE, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); + ret &= add_condition("country_units_in_state", IDENTIFIER, PROVINCE, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); + ret &= add_condition("has_crime", IDENTIFIER, PROVINCE, NO_SCOPE, NO_IDENTIFIER, CRIME); ret &= add_condition("has_culture_core", BOOLEAN, PROVINCE); ret &= add_condition("has_empty_adjacent_province", BOOLEAN, PROVINCE); ret &= add_condition("has_empty_adjacent_state", BOOLEAN, PROVINCE); ret &= add_condition("has_national_minority", BOOLEAN, PROVINCE); - ret &= add_condition("has_province_flag", IDENTIFIER, PROVINCE, NO_SCOPE, NONE, PROVINCE_FLAG); - ret &= add_condition("has_province_modifier", IDENTIFIER, PROVINCE, NO_SCOPE, NONE, MODIFIER); + ret &= add_condition("has_province_flag", IDENTIFIER, PROVINCE, NO_SCOPE, NO_IDENTIFIER, PROVINCE_FLAG); + ret &= add_condition("has_province_modifier", IDENTIFIER, PROVINCE, NO_SCOPE, NO_IDENTIFIER, MODIFIER); ret &= add_condition("has_recent_imigration", INTEGER, PROVINCE); //paradox typo ret &= add_condition("is_blockaded", BOOLEAN, PROVINCE); - ret &= add_condition("is_accepted_culture", IDENTIFIER | BOOLEAN, PROVINCE, NO_SCOPE, NONE, COUNTRY_TAG); + ret &= add_condition("is_accepted_culture", IDENTIFIER | BOOLEAN, PROVINCE, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); ret &= add_condition("is_capital", BOOLEAN, PROVINCE); ret &= add_condition("is_coastal", BOOLEAN, PROVINCE); ret &= add_condition("is_overseas", BOOLEAN, PROVINCE); - ret &= add_condition("is_primary_culture", IDENTIFIER | BOOLEAN, PROVINCE, NO_SCOPE, NONE, COUNTRY_TAG); + ret &= add_condition("is_primary_culture", IDENTIFIER | BOOLEAN, PROVINCE, NO_SCOPE, NO_IDENTIFIER, COUNTRY_TAG); ret &= add_condition("is_state_capital", BOOLEAN, PROVINCE); ret &= add_condition("is_state_religion", BOOLEAN, PROVINCE); ret &= add_condition("life_rating", REAL, PROVINCE); ret &= add_condition("minorities", BOOLEAN, PROVINCE); ret &= add_condition("port", BOOLEAN, PROVINCE); ret &= add_condition("province_control_days", INTEGER, PROVINCE); - ret &= add_condition("province_id", IDENTIFIER, PROVINCE, NO_SCOPE, NONE, PROVINCE_ID); - ret &= add_condition("region", IDENTIFIER, PROVINCE, NO_SCOPE, NONE, REGION); - ret &= add_condition("state_id", IDENTIFIER, PROVINCE, NO_SCOPE, NONE, PROVINCE_ID); - ret &= add_condition("terrain", IDENTIFIER, PROVINCE, NO_SCOPE, NONE, TERRAIN); - ret &= add_condition("trade_goods", IDENTIFIER, PROVINCE, NO_SCOPE, NONE, TRADE_GOOD); + ret &= add_condition("province_id", IDENTIFIER, PROVINCE, NO_SCOPE, NO_IDENTIFIER, PROVINCE_ID); + ret &= add_condition("region", IDENTIFIER, PROVINCE, NO_SCOPE, NO_IDENTIFIER, REGION); + ret &= add_condition("state_id", IDENTIFIER, PROVINCE, NO_SCOPE, NO_IDENTIFIER, PROVINCE_ID); + ret &= add_condition("terrain", IDENTIFIER, PROVINCE, NO_SCOPE, NO_IDENTIFIER, TERRAIN); + ret &= add_condition("trade_goods", IDENTIFIER, PROVINCE, NO_SCOPE, NO_IDENTIFIER, TRADE_GOOD); ret &= add_condition("unemployment_by_type", COMPLEX, PROVINCE); ret &= add_condition("units_in_province", INTEGER, PROVINCE); @@ -328,19 +328,19 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { ret &= add_condition("life_needs", REAL, POP); ret &= add_condition("luxury_needs", REAL, POP); ret &= add_condition("political_movement", BOOLEAN, POP); - ret &= add_condition("pop_majority_issue", IDENTIFIER, POP, NO_SCOPE, NONE, ISSUE); - ret &= add_condition("pop_type", IDENTIFIER, POP, NO_SCOPE, NONE, POP_TYPE); + ret &= add_condition("pop_majority_issue", IDENTIFIER, POP, NO_SCOPE, NO_IDENTIFIER, ISSUE); + ret &= add_condition("pop_type", IDENTIFIER, POP, NO_SCOPE, NO_IDENTIFIER, POP_TYPE); ret &= add_condition("social_movement", BOOLEAN, POP); - ret &= add_condition("strata", IDENTIFIER, POP, NO_SCOPE, NONE, POP_STRATA); - ret &= add_condition("type", IDENTIFIER, POP, NO_SCOPE, NONE, POP_TYPE); + ret &= add_condition("strata", IDENTIFIER, POP, NO_SCOPE, NO_IDENTIFIER, POP_STRATA); + ret &= add_condition("type", IDENTIFIER, POP, NO_SCOPE, NO_IDENTIFIER, POP_TYPE); const auto import_identifiers = [this, &ret]( std::vector const& identifiers, value_type_t value_type, scope_t scope, - scope_t scope_change = scope_t::NO_SCOPE, - identifier_type_t key_identifier_type = identifier_type_t::NONE, - identifier_type_t value_identifier_type = identifier_type_t::NONE + scope_t scope_change = NO_SCOPE, + identifier_type_t key_identifier_type = NO_IDENTIFIER, + identifier_type_t value_identifier_type = NO_IDENTIFIER ) -> void { for (std::string_view const& identifier : identifiers) { ret &= add_condition( @@ -357,7 +357,7 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { COUNTRY, COUNTRY, COUNTRY_TAG, - NONE + NO_IDENTIFIER ); import_identifiers( @@ -366,7 +366,7 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { COUNTRY, STATE, REGION, - NONE + NO_IDENTIFIER ); import_identifiers( @@ -375,7 +375,7 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { COUNTRY, PROVINCE, PROVINCE_ID, - NONE + NO_IDENTIFIER ); /* Conditions from other registries */ @@ -385,7 +385,7 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { COUNTRY, NO_SCOPE, IDEOLOGY, - NONE + NO_IDENTIFIER ); import_identifiers( @@ -403,7 +403,7 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { COUNTRY, NO_SCOPE, REFORM, - NONE + NO_IDENTIFIER ); import_identifiers( @@ -412,7 +412,7 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { COUNTRY, NO_SCOPE, ISSUE, - NONE + NO_IDENTIFIER ); import_identifiers( @@ -421,7 +421,7 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { COUNTRY, NO_SCOPE, POP_TYPE, - NONE + NO_IDENTIFIER ); import_identifiers( @@ -430,7 +430,7 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { COUNTRY, NO_SCOPE, TECHNOLOGY, - NONE + NO_IDENTIFIER ); import_identifiers( @@ -439,7 +439,7 @@ bool ConditionManager::setup_conditions(GameManager const& game_manager) { COUNTRY, NO_SCOPE, TRADE_GOOD, - NONE + NO_IDENTIFIER ); lock_conditions(); @@ -459,7 +459,6 @@ callback_t ConditionManager::expect_parse_identifier( GameManager const& game_manager, identifier_type_t identifier_type, callback_t callback ) const { - using enum identifier_type_t; return [this, &game_manager, identifier_type, callback](std::string_view identifier) -> bool { HasIdentifier const* identified = nullptr; @@ -479,7 +478,7 @@ callback_t ConditionManager::expect_parse_identifier( //TODO: placeholder for not implemented stuff #define EXPECT_CALL_PLACEHOLDER(type) \ - if (share_identifier_type(identifier_type, type)) return true; + if (share_identifier_type(identifier_type, type)) { return true; } EXPECT_CALL_PLACEHOLDER(VARIABLE); EXPECT_CALL_PLACEHOLDER(GLOBAL_FLAG); @@ -524,7 +523,6 @@ node_callback_t ConditionManager::expect_condition_node( GameManager const& game_manager, Condition const& condition, scope_t this_scope, scope_t from_scope, scope_t cur_scope, callback_t callback ) const { - using enum value_type_t; return [this, &game_manager, &condition, callback, this_scope, from_scope, cur_scope]( ast::NodeCPtr node ) -> bool { @@ -551,16 +549,14 @@ node_callback_t ConditionManager::expect_condition_node( )(id); if (log && !ret) { Logger::error( - "Invalid identifier ", id, - " expected to have type ", get_identifier_type_string(item_type), - " found during condition node parsing!" + "Invalid identifier ", id, " expected to have type ", item_type, " found during condition node parsing!" ); } return keyval; }; if (!ret && share_value_type(value_type, IDENTIFIER)) { - std::string_view value_identifier; + std::string_view value_identifier {}; ret |= expect_identifier_or_string(assign_variable_callback(value_identifier))(node); if (ret) { value = ConditionNode::string_t { value_identifier }; @@ -574,7 +570,7 @@ node_callback_t ConditionManager::expect_condition_node( } if (!ret && share_value_type(value_type, STRING)) { - std::string_view value_identifier; + std::string_view value_identifier {}; bool local_ret = expect_identifier_or_string( assign_variable_callback(value_identifier) )(node); @@ -595,43 +591,43 @@ node_callback_t ConditionManager::expect_condition_node( //entries with magic syntax, thanks paradox! if (!ret && share_value_type(value_type, COMPLEX)) { - #define EXPECT_PAIR(key, value) \ - std::string_view key; \ - fixed_point_t real_##value; \ - ret |= expect_dictionary_keys( \ - #key, ONE_EXACTLY, expect_identifier_or_string(assign_variable_callback(key)), \ - #value, ONE_EXACTLY, expect_fixed_point(assign_variable_callback(real_##value)) \ - )(node); \ - if (ret) { \ - value = ConditionNode::identifier_real_t { key, real_##value }; \ + const auto expect_pair = [&ret, &value, node](std::string_view identifier_key, std::string_view value_key) -> void { + std::string_view pair_identifier {}; + fixed_point_t pair_value = 0; + ret |= expect_dictionary_keys( + identifier_key, ONE_EXACTLY, expect_identifier_or_string(assign_variable_callback(pair_identifier)), + value_key, ONE_EXACTLY, expect_fixed_point(assign_variable_callback(pair_value)) + )(node); + if (ret) { + value = ConditionNode::identifier_real_t { pair_identifier, pair_value }; } + }; if (identifier == "can_build_railway_in_capital" || identifier == "can_build_fort_in_capital") { bool in_whole_capital_state = false, limit_to_world_greatest_level = false; ret |= expect_dictionary_keys( "in_whole_capital_state", ONE_EXACTLY, expect_bool(assign_variable_callback(in_whole_capital_state)), - "limit_to_world_greatest_level", ONE_EXACTLY, expect_bool(assign_variable_callback(limit_to_world_greatest_level)) + "limit_to_world_greatest_level", ONE_EXACTLY, + expect_bool(assign_variable_callback(limit_to_world_greatest_level)) )(node); if (ret) { value = ConditionNode::double_boolean_t { in_whole_capital_state, limit_to_world_greatest_level }; } } else if (identifier == "check_variable") { - EXPECT_PAIR(which, value); // { which = [name of variable] value = x } + expect_pair("which", "value"); // { which = [name of variable] value = x } } else if (identifier == "diplomatic_influence") { - EXPECT_PAIR(who, value); // { who = [THIS/FROM/TAG] value = x } + expect_pair("who", "value"); // { who = [THIS/FROM/TAG] value = x } } else if (identifier == "relation") { - EXPECT_PAIR(who, value); // { who = [tag/this/from] value = x } + expect_pair("who", "value"); // { who = [tag/this/from] value = x } } else if (identifier == "unemployment_by_type") { - EXPECT_PAIR(type, value); // {type = [poptype] value = x } + expect_pair("type", "value"); // {type = [poptype] value = x } } else if (identifier == "upper_house") { - EXPECT_PAIR(ideology, value); // { ideology = name value = 0.x } + expect_pair("ideology", "value"); // { ideology = name value = 0.x } } else if (identifier == "work_available") { // { worker = [type] } - std::string_view worker; + std::string_view worker {}; ret |= expect_dictionary_keys( - "worker", - ONE_EXACTLY, - expect_identifier_or_string(assign_variable_callback(worker)) + "worker", ONE_EXACTLY, expect_identifier_or_string(assign_variable_callback(worker)) )(node); if (ret) { value = ConditionNode::string_t { worker }; @@ -647,7 +643,7 @@ node_callback_t ConditionManager::expect_condition_node( ConditionNode::condition_list_t node_list; ret |= expect_condition_node_list( game_manager, this_scope, from_scope, - scope_change == scope_t::NO_SCOPE ? cur_scope : scope_change, + scope_change == NO_SCOPE ? cur_scope : scope_change, false, vector_callback(node_list) )(node); @@ -656,24 +652,23 @@ node_callback_t ConditionManager::expect_condition_node( // scope validation scope_t effective_current_scope = cur_scope; - if (share_scope(effective_current_scope, scope_t::THIS)) { + if (share_scope(effective_current_scope, THIS)) { effective_current_scope = this_scope; - } else if (share_scope(effective_current_scope, scope_t::FROM)) { + } else if (share_scope(effective_current_scope, FROM)) { effective_current_scope = from_scope; } if (!share_scope(scope, effective_current_scope) && effective_current_scope > scope) { Logger::warning( - "Condition or scope ", identifier, " was found in wrong scope ", - get_scope_string(effective_current_scope), ", expected ", - get_scope_string(scope), "!" + "Condition or scope ", identifier, " was found in wrong scope ", effective_current_scope, ", expected ", + scope, "!" ); ret = false; } // key parsing HasIdentifier const* key_item = nullptr; - if (condition.key_identifier_type != identifier_type_t::NONE) { + if (condition.key_identifier_type != NO_IDENTIFIER) { key_item = get_identifiable(key_identifier_type, identifier, true); ret &= key_item != nullptr; } @@ -709,8 +704,6 @@ node_callback_t ConditionManager::expect_condition_node_list( GameManager const& game_manager, scope_t this_scope, scope_t from_scope, scope_t cur_scope, bool top_scope, callback_t callback ) const { - using enum value_type_t; - using enum scope_t; return [this, &game_manager, callback, this_scope, from_scope, cur_scope, top_scope](ast::NodeCPtr node) -> bool { const auto expect_node = [ this, &game_manager, callback, this_scope, from_scope, cur_scope @@ -731,8 +724,8 @@ node_callback_t ConditionManager::expect_condition_node_list( } node_callback_t ConditionManager::expect_condition_script( - GameManager const& game_manager, scope_t initial_scope, scope_t this_scope, scope_t from_scope, - callback_t callback + GameManager const& game_manager, scope_t initial_scope, scope_t this_scope, + scope_t from_scope, callback_t callback ) const { return [this, &game_manager, initial_scope, this_scope, from_scope, callback](ast::NodeCPtr node) -> bool { diff --git a/src/openvic-simulation/scripts/Condition.hpp b/src/openvic-simulation/scripts/Condition.hpp index 55fe8fc..e239142 100644 --- a/src/openvic-simulation/scripts/Condition.hpp +++ b/src/openvic-simulation/scripts/Condition.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -23,7 +24,6 @@ namespace OpenVic { GROUP = 1 << 7, MAX_VALUE = (1 << 8) - 1 }; - template<> struct enable_bitfield : std::true_type {}; // Order matters in this enum, for the fallback system to work // smaller entities must have smaller integers associated! @@ -37,10 +37,9 @@ namespace OpenVic { FROM = 1 << 5, MAX_SCOPE = (1 << 6) - 1 }; - template<> struct enable_bitfield : std::true_type {}; enum class identifier_type_t : uint32_t { - NONE = 0, + NO_IDENTIFIER = 0, VARIABLE = 1 << 0, GLOBAL_FLAG = 1 << 1, COUNTRY_FLAG = 1 << 2, @@ -71,6 +70,10 @@ namespace OpenVic { CRIME = 1 << 27, TERRAIN = 1 << 28, }; + + /* Allows enum types to be used with bitwise operators. */ + template<> struct enable_bitfield : std::true_type {}; + template<> struct enable_bitfield : std::true_type {}; template<> struct enable_bitfield : std::true_type {}; /* Returns true if the values have any bit in common. */ @@ -81,19 +84,28 @@ namespace OpenVic { return (lhs & rhs) != scope_t::NO_SCOPE; } constexpr inline bool share_identifier_type(identifier_type_t lhs, identifier_type_t rhs) { - return (lhs & rhs) != identifier_type_t::NONE; + return (lhs & rhs) != identifier_type_t::NO_IDENTIFIER; } -#define _BUILD_STRING(entry, share) if (share(value, entry)) { ret += #entry " | "; } +#define _BUILD_STRING(entry, share) \ + if (share(value, entry)) { \ + if (type_found) { \ + stream << " | "; \ + } else { \ + type_found = true; \ + } \ + stream << #entry; \ + } #define BUILD_STRING(entry) _BUILD_STRING(entry, share_value_type) - inline std::string get_value_type_string(value_type_t value) { + inline std::ostream& operator<<(std::ostream& stream, value_type_t value) { using enum value_type_t; if (value == NO_TYPE) { - return "[NO_TYPE]"; + return stream << "[NO_TYPE]"; } - std::string ret = {}; + bool type_found = false; + stream << '['; BUILD_STRING(IDENTIFIER); BUILD_STRING(STRING); BUILD_STRING(BOOLEAN); @@ -102,36 +114,44 @@ namespace OpenVic { BUILD_STRING(REAL); BUILD_STRING(COMPLEX); BUILD_STRING(GROUP); - return "[" + ret.substr(0, ret.length() - 3) + "]"; + if (!type_found) { + stream << "INVALID VALUE TYPE"; + } + return stream << ']'; } #undef BUILD_STRING #define BUILD_STRING(entry) _BUILD_STRING(entry, share_scope) - inline std::string get_scope_string(scope_t value) { + inline std::ostream& operator<<(std::ostream& stream, scope_t value) { using enum scope_t; if (value == NO_SCOPE) { - return "[NO_SCOPE]"; + return stream << "[NO_SCOPE]"; } - std::string ret = {}; + bool type_found = false; + stream << '['; BUILD_STRING(COUNTRY); BUILD_STRING(STATE); BUILD_STRING(PROVINCE); BUILD_STRING(POP); BUILD_STRING(THIS); BUILD_STRING(FROM); - return "[" + ret.substr(0, ret.length() - 3) + "]"; + if (!type_found) { + stream << "INVALID SCOPE"; + } + return stream << ']'; } #undef BUILD_STRING #define BUILD_STRING(entry) _BUILD_STRING(entry, share_identifier_type) - inline std::string get_identifier_type_string(identifier_type_t value) { + inline std::ostream& operator<<(std::ostream& stream, identifier_type_t value) { using enum identifier_type_t; - if (value == NONE) { - return "[NONE]"; + if (value == NO_IDENTIFIER) { + return stream << "[NO_IDENTIFIER]"; } - std::string ret = {}; + bool type_found = false; + stream << '['; BUILD_STRING(VARIABLE); BUILD_STRING(GLOBAL_FLAG); BUILD_STRING(COUNTRY_FLAG); @@ -161,7 +181,10 @@ namespace OpenVic { BUILD_STRING(CONTINENT); BUILD_STRING(CRIME); BUILD_STRING(TERRAIN); - return "[" + ret.substr(0, ret.length() - 3) + "]"; + if (!type_found) { + stream << "INVALID IDENTIFIER TYPE"; + } + return stream << ']'; } #undef BUILD_STRING @@ -224,8 +247,8 @@ namespace OpenVic { bool add_condition( std::string_view identifier, value_type_t value_type, scope_t scope, scope_t scope_change = scope_t::NO_SCOPE, - identifier_type_t key_identifier_type = identifier_type_t::NONE, - identifier_type_t value_identifier_type = identifier_type_t::NONE + identifier_type_t key_identifier_type = identifier_type_t::NO_IDENTIFIER, + identifier_type_t value_identifier_type = identifier_type_t::NO_IDENTIFIER ); NodeTools::callback_t expect_parse_identifier( -- cgit v1.2.3-56-ga3b1