From fb6b9439c219239691eb0201ec3f431b5dfe4893 Mon Sep 17 00:00:00 2001 From: hop311 Date: Sun, 22 Sep 2024 18:09:37 +0100 Subject: Make ModifierEffect format argument mandatory --- src/openvic-simulation/pop/Pop.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/openvic-simulation/pop/Pop.cpp') diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp index dd829d9..e89d510 100644 --- a/src/openvic-simulation/pop/Pop.cpp +++ b/src/openvic-simulation/pop/Pop.cpp @@ -662,7 +662,7 @@ bool PopManager::generate_modifiers(ModifierManager& modifier_manager) const { std::string_view suffix, bool is_positive_good ) -> void { ret &= modifier_manager.add_modifier_effect( - StringUtils::append_string_views(strata.get_identifier(), suffix), is_positive_good + StringUtils::append_string_views(strata.get_identifier(), suffix), is_positive_good, PROPORTION_DECIMAL ); }; -- cgit v1.2.3-56-ga3b1 From 4f9fd8a327b6de5fb32792a07453e9a2e245dc84 Mon Sep 17 00:00:00 2001 From: hop311 Date: Wed, 25 Sep 2024 22:10:21 +0100 Subject: Add ModifierEffect targets --- src/openvic-simulation/economy/BuildingType.cpp | 5 +- src/openvic-simulation/economy/GoodDefinition.cpp | 3 +- src/openvic-simulation/military/UnitType.cpp | 7 +- src/openvic-simulation/modifier/Modifier.cpp | 346 ++++++++++++---------- src/openvic-simulation/modifier/Modifier.hpp | 20 +- src/openvic-simulation/modifier/ModifierSum.cpp | 38 ++- src/openvic-simulation/modifier/ModifierSum.hpp | 18 +- src/openvic-simulation/politics/Rebel.cpp | 7 +- src/openvic-simulation/pop/Pop.cpp | 6 +- src/openvic-simulation/research/Technology.cpp | 5 +- 10 files changed, 273 insertions(+), 182 deletions(-) (limited to 'src/openvic-simulation/pop/Pop.cpp') diff --git a/src/openvic-simulation/economy/BuildingType.cpp b/src/openvic-simulation/economy/BuildingType.cpp index e7c0d59..d75f1b2 100644 --- a/src/openvic-simulation/economy/BuildingType.cpp +++ b/src/openvic-simulation/economy/BuildingType.cpp @@ -114,16 +114,17 @@ bool BuildingTypeManager::load_buildings_file( for (BuildingType const& building_type : building_types.get_items()) { using enum ModifierEffect::format_t; + using enum ModifierEffect::target_t; static constexpr std::string_view max_prefix = "max_"; static constexpr std::string_view min_prefix = "min_build_"; ret &= modifier_manager.add_modifier_effect( - StringUtils::append_string_views(max_prefix, building_type.get_identifier()), true, INT, + StringUtils::append_string_views(max_prefix, building_type.get_identifier()), true, INT, PROVINCE, StringUtils::append_string_views("$", building_type.get_identifier(), "$ $TECH_MAX_LEVEL$") ); // TODO - add custom localisation for "min_build_$building_type$" modifiers ret &= modifier_manager.add_modifier_effect( - StringUtils::append_string_views(min_prefix, building_type.get_identifier()), false, INT + StringUtils::append_string_views(min_prefix, building_type.get_identifier()), false, INT, PROVINCE ); if (building_type.is_in_province()) { diff --git a/src/openvic-simulation/economy/GoodDefinition.cpp b/src/openvic-simulation/economy/GoodDefinition.cpp index ed24549..97396f2 100644 --- a/src/openvic-simulation/economy/GoodDefinition.cpp +++ b/src/openvic-simulation/economy/GoodDefinition.cpp @@ -89,6 +89,7 @@ bool GoodDefinitionManager::load_goods_file(ast::NodeCPtr root) { bool GoodDefinitionManager::generate_modifiers(ModifierManager& modifier_manager) const { using enum ModifierEffect::format_t; + using enum ModifierEffect::target_t; bool ret = true; @@ -100,7 +101,7 @@ bool GoodDefinitionManager::generate_modifiers(ModifierManager& modifier_manager for (GoodDefinition const& good : get_good_definitions()) { ret &= modifier_manager.add_modifier_effect( ModifierManager::get_flat_identifier(name, good.get_identifier()), is_positive_good, PROPORTION_DECIMAL, - make_localisation_suffix(good.get_identifier()) + COUNTRY, make_localisation_suffix(good.get_identifier()) ); } }; diff --git a/src/openvic-simulation/military/UnitType.cpp b/src/openvic-simulation/military/UnitType.cpp index 71bc5c3..bb227fb 100644 --- a/src/openvic-simulation/military/UnitType.cpp +++ b/src/openvic-simulation/military/UnitType.cpp @@ -321,17 +321,18 @@ bool UnitTypeManager::generate_modifiers(ModifierManager& modifier_manager) cons const auto generate_stat_modifiers = [&modifier_manager, &ret]( std::string_view identifier, UnitType::branch_t branch ) -> void { + using enum ModifierEffect::format_t; + using enum ModifierEffect::target_t; + const auto stat_modifier = [&modifier_manager, &ret, &identifier]( std::string_view suffix, bool is_positive_good, ModifierEffect::format_t format, std::string_view localisation_key ) -> void { ret &= modifier_manager.add_modifier_effect( - ModifierManager::get_flat_identifier(identifier, suffix), is_positive_good, format, + ModifierManager::get_flat_identifier(identifier, suffix), is_positive_good, format, COUNTRY, StringUtils::append_string_views("$", identifier, "$: $", localisation_key, "$") ); }; - using enum ModifierEffect::format_t; - ret &= modifier_manager.register_complex_modifier(identifier); stat_modifier("attack", true, RAW_DECIMAL, "ATTACK"); diff --git a/src/openvic-simulation/modifier/Modifier.cpp b/src/openvic-simulation/modifier/Modifier.cpp index 10e32a4..73b30ce 100644 --- a/src/openvic-simulation/modifier/Modifier.cpp +++ b/src/openvic-simulation/modifier/Modifier.cpp @@ -17,8 +17,9 @@ static std::string make_default_modifier_effect_localisation_key(std::string_vie } ModifierEffect::ModifierEffect( - std::string_view new_identifier, bool new_positive_good, format_t new_format, std::string_view new_localisation_key -) : HasIdentifier { new_identifier }, positive_good { new_positive_good }, format { new_format }, + std::string_view new_identifier, bool new_positive_good, format_t new_format, target_t new_targets, + std::string_view new_localisation_key +) : HasIdentifier { new_identifier }, positive_good { new_positive_good }, format { new_format }, targets { new_targets }, localisation_key { new_localisation_key.empty() ? make_default_modifier_effect_localisation_key(new_identifier) : new_localisation_key } {} @@ -115,12 +116,29 @@ ModifierValue ModifierValue::operator*(fixed_point_t const& right) const { return copy *= right; } -void ModifierValue::multiply_add(ModifierValue const& other, fixed_point_t multiplier) { - if (multiplier == fixed_point_t::_1()) { +void ModifierValue::apply_target_filter(ModifierEffect::target_t targets) { + using enum ModifierEffect::target_t; + + erase_if( + values, + [targets](effect_map_t::value_type const& value) -> bool { + return (value.first->get_targets() & targets) == NO_TARGETS; + } + ); +} + +void ModifierValue::multiply_add_filter( + ModifierValue const& other, fixed_point_t multiplier, ModifierEffect::target_t targets +) { + using enum ModifierEffect::target_t; + + if (multiplier == fixed_point_t::_1() && targets == ALL_TARGETS) { *this += other; - } else if (multiplier != fixed_point_t::_0()) { + } else if (multiplier != fixed_point_t::_0() && targets != NO_TARGETS) { for (effect_map_t::value_type const& value : other.values) { - values[value.first] += value.second * multiplier; + if ((value.first->get_targets() & targets) != NO_TARGETS) { + values[value.first] += value.second * multiplier; + } } } } @@ -145,247 +163,261 @@ ModifierInstance::ModifierInstance(Modifier const& new_modifier, Date new_expiry : modifier { &new_modifier }, expiry_date { new_expiry_date } {} bool ModifierManager::add_modifier_effect( - std::string_view identifier, bool positive_good, ModifierEffect::format_t format, std::string_view localisation_key + std::string_view identifier, bool positive_good, ModifierEffect::format_t format, ModifierEffect::target_t targets, + std::string_view localisation_key ) { if (identifier.empty()) { Logger::error("Invalid modifier effect identifier - empty!"); return false; } - return modifier_effects.add_item({ std::move(identifier), positive_good, format, localisation_key }); + return modifier_effects.add_item({ std::move(identifier), positive_good, format, targets, localisation_key }); } bool ModifierManager::setup_modifier_effects() { bool ret = true; using enum ModifierEffect::format_t; + using enum ModifierEffect::target_t; /* Tech/inventions only */ - ret &= add_modifier_effect("cb_creation_speed", true, PROPORTION_DECIMAL, "CB_MANUFACTURE_TECH"); - ret &= add_modifier_effect("combat_width", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("plurality", true, PERCENTAGE_DECIMAL, "TECH_PLURALITY"); - ret &= add_modifier_effect("pop_growth", true, PROPORTION_DECIMAL, "TECH_POP_GROWTH"); - ret &= add_modifier_effect("regular_experience_level", true, RAW_DECIMAL, "REGULAR_EXP_TECH"); - ret &= add_modifier_effect("reinforce_rate", true, PROPORTION_DECIMAL, "REINFORCE_TECH"); - ret &= add_modifier_effect("seperatism", false, PROPORTION_DECIMAL, "SEPARATISM_TECH"); // paradox typo - ret &= add_modifier_effect("shared_prestige", true, RAW_DECIMAL, "SHARED_PRESTIGE_TECH"); - ret &= add_modifier_effect("tax_eff", true, PROPORTION_DECIMAL, "TECH_TAX_EFF"); + ret &= add_modifier_effect("cb_creation_speed", true, PROPORTION_DECIMAL, COUNTRY, "CB_MANUFACTURE_TECH"); + ret &= add_modifier_effect("combat_width", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("plurality", true, PERCENTAGE_DECIMAL, COUNTRY, "TECH_PLURALITY"); + ret &= add_modifier_effect("pop_growth", true, PROPORTION_DECIMAL, COUNTRY, "TECH_POP_GROWTH"); + ret &= add_modifier_effect("regular_experience_level", true, RAW_DECIMAL, COUNTRY, "REGULAR_EXP_TECH"); + ret &= add_modifier_effect("reinforce_rate", true, PROPORTION_DECIMAL, COUNTRY, "REINFORCE_TECH"); + ret &= add_modifier_effect("seperatism", false, PROPORTION_DECIMAL, COUNTRY, "SEPARATISM_TECH"); // paradox typo + ret &= add_modifier_effect("shared_prestige", true, RAW_DECIMAL, COUNTRY, "SHARED_PRESTIGE_TECH"); + ret &= add_modifier_effect("tax_eff", true, PERCENTAGE_DECIMAL, COUNTRY, "TECH_TAX_EFF"); /* Country Modifier Effects */ - ret &= add_modifier_effect("administrative_efficiency", true, PROPORTION_DECIMAL); + ret &= add_modifier_effect("administrative_efficiency", true, PROPORTION_DECIMAL, COUNTRY); ret &= add_modifier_effect( - "administrative_efficiency_modifier", true, PROPORTION_DECIMAL, + "administrative_efficiency_modifier", true, PROPORTION_DECIMAL, COUNTRY, make_default_modifier_effect_localisation_key("administrative_efficiency") ); - ret &= add_modifier_effect("artisan_input", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("artisan_output", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("artisan_throughput", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("badboy", false, RAW_DECIMAL); - ret &= add_modifier_effect("cb_generation_speed_modifier", true, PROPORTION_DECIMAL); + ret &= add_modifier_effect("artisan_input", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("artisan_output", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("artisan_throughput", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("badboy", false, RAW_DECIMAL, COUNTRY); + ret &= add_modifier_effect("cb_generation_speed_modifier", true, PROPORTION_DECIMAL, COUNTRY); ret &= add_modifier_effect( - "civilization_progress_modifier", true, PROPORTION_DECIMAL, + "civilization_progress_modifier", true, PROPORTION_DECIMAL, COUNTRY, make_default_modifier_effect_localisation_key("civilization_progress") ); - ret &= add_modifier_effect("colonial_life_rating", false, INT, "COLONIAL_LIFE_TECH"); - ret &= add_modifier_effect("colonial_migration", true, PROPORTION_DECIMAL, "COLONIAL_MIGRATION_TECH"); - ret &= add_modifier_effect("colonial_points", true, INT, "COLONIAL_POINTS_TECH"); - ret &= add_modifier_effect("colonial_prestige", true, PROPORTION_DECIMAL, "COLONIAL_PRESTIGE_MODIFIER_TECH"); - ret &= add_modifier_effect("core_pop_consciousness_modifier", false, RAW_DECIMAL); - ret &= add_modifier_effect("core_pop_militancy_modifier", false, RAW_DECIMAL); - ret &= add_modifier_effect("dig_in_cap", true, INT, "DIGIN_FROM_TECH"); - ret &= add_modifier_effect("diplomatic_points", true, PROPORTION_DECIMAL, "DIPLOMATIC_POINTS_TECH"); + ret &= add_modifier_effect("colonial_life_rating", false, INT, COUNTRY, "COLONIAL_LIFE_TECH"); + ret &= add_modifier_effect("colonial_migration", true, PROPORTION_DECIMAL, COUNTRY, "COLONIAL_MIGRATION_TECH"); + ret &= add_modifier_effect("colonial_points", true, INT, COUNTRY, "COLONIAL_POINTS_TECH"); + ret &= add_modifier_effect("colonial_prestige", true, PROPORTION_DECIMAL, COUNTRY, "COLONIAL_PRESTIGE_MODIFIER_TECH"); + ret &= add_modifier_effect("core_pop_consciousness_modifier", false, RAW_DECIMAL, COUNTRY); + ret &= add_modifier_effect("core_pop_militancy_modifier", false, RAW_DECIMAL, COUNTRY); + ret &= add_modifier_effect("dig_in_cap", true, INT, COUNTRY, "DIGIN_FROM_TECH"); + ret &= add_modifier_effect("diplomatic_points", true, PROPORTION_DECIMAL, COUNTRY, "DIPLOMATIC_POINTS_TECH"); ret &= add_modifier_effect( - "diplomatic_points_modifier", true, PROPORTION_DECIMAL, + "diplomatic_points_modifier", true, PROPORTION_DECIMAL, COUNTRY, make_default_modifier_effect_localisation_key("diplopoints_gain") ); - ret &= add_modifier_effect("education_efficiency", true, PROPORTION_DECIMAL); + ret &= add_modifier_effect("education_efficiency", true, PROPORTION_DECIMAL, COUNTRY); ret &= add_modifier_effect( - "education_efficiency_modifier", true, PROPORTION_DECIMAL, + "education_efficiency_modifier", true, PROPORTION_DECIMAL, COUNTRY, make_default_modifier_effect_localisation_key("education_efficiency") ); - ret &= add_modifier_effect("factory_cost", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("factory_input", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("factory_maintenance", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("factory_output", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("factory_owner_cost", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("factory_throughput", true, PROPORTION_DECIMAL); + ret &= add_modifier_effect("factory_cost", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("factory_input", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("factory_maintenance", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("factory_output", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("factory_owner_cost", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("factory_throughput", true, PROPORTION_DECIMAL, COUNTRY); ret &= add_modifier_effect( - "global_assimilation_rate", true, PROPORTION_DECIMAL, + "global_assimilation_rate", true, PROPORTION_DECIMAL, COUNTRY, make_default_modifier_effect_localisation_key("assimilation_rate") ); ret &= add_modifier_effect( - "global_immigrant_attract", true, PROPORTION_DECIMAL, + "global_immigrant_attract", true, PROPORTION_DECIMAL, COUNTRY, make_default_modifier_effect_localisation_key("immigant_attract") ); - ret &= add_modifier_effect("global_pop_consciousness_modifier", false, RAW_DECIMAL); - ret &= add_modifier_effect("global_pop_militancy_modifier", false, RAW_DECIMAL); + ret &= add_modifier_effect("global_pop_consciousness_modifier", false, RAW_DECIMAL, COUNTRY); + ret &= add_modifier_effect("global_pop_militancy_modifier", false, RAW_DECIMAL, COUNTRY); ret &= add_modifier_effect( - "global_population_growth", true, PROPORTION_DECIMAL, + "global_population_growth", true, PROPORTION_DECIMAL, COUNTRY, make_default_modifier_effect_localisation_key("population_growth") ); - ret &= add_modifier_effect("goods_demand", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("import_cost", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("increase_research", true, PROPORTION_DECIMAL, "INC_RES_TECH"); - ret &= add_modifier_effect("influence", true, PROPORTION_DECIMAL, "TECH_GP_INFLUENCE"); + ret &= add_modifier_effect("goods_demand", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("import_cost", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("increase_research", true, PROPORTION_DECIMAL, COUNTRY, "INC_RES_TECH"); + ret &= add_modifier_effect("influence", true, PROPORTION_DECIMAL, COUNTRY, "TECH_GP_INFLUENCE"); ret &= add_modifier_effect( - "influence_modifier", true, PROPORTION_DECIMAL, + "influence_modifier", true, PROPORTION_DECIMAL, COUNTRY, make_default_modifier_effect_localisation_key("greatpower_influence_gain") ); - ret &= add_modifier_effect("issue_change_speed", true, PROPORTION_DECIMAL); + ret &= add_modifier_effect("issue_change_speed", true, PROPORTION_DECIMAL, COUNTRY); ret &= add_modifier_effect( - "land_attack_modifier", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("land_attack") + "land_attack_modifier", true, PROPORTION_DECIMAL, COUNTRY, make_default_modifier_effect_localisation_key("land_attack") ); - ret &= add_modifier_effect("land_attrition", false, PROPORTION_DECIMAL, "LAND_ATTRITION_TECH"); + ret &= add_modifier_effect("land_attrition", false, PROPORTION_DECIMAL, COUNTRY, "LAND_ATTRITION_TECH"); ret &= add_modifier_effect( - "land_defense_modifier", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("land_defense") + "land_defense_modifier", true, PROPORTION_DECIMAL, COUNTRY, + make_default_modifier_effect_localisation_key("land_defense") ); - ret &= add_modifier_effect("land_organisation", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("land_unit_start_experience", true, RAW_DECIMAL); - ret &= add_modifier_effect("leadership", true, RAW_DECIMAL, "LEADERSHIP"); + ret &= add_modifier_effect("land_organisation", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("land_unit_start_experience", true, RAW_DECIMAL, COUNTRY); + ret &= add_modifier_effect("leadership", true, RAW_DECIMAL, COUNTRY, "LEADERSHIP"); ret &= add_modifier_effect( - "leadership_modifier", true, PROPORTION_DECIMAL, + "leadership_modifier", true, PROPORTION_DECIMAL, COUNTRY, make_default_modifier_effect_localisation_key("global_leadership_modifier") ); - ret &= add_modifier_effect("literacy_con_impact", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("loan_interest", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect( - "max_loan_modifier", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("max_loan_amount") - ); - ret &= add_modifier_effect("max_military_spending", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("max_national_focus", true, INT, "TECH_MAX_FOCUS"); - ret &= add_modifier_effect("max_social_spending", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("max_tariff", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("max_tax", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("max_war_exhaustion", true, PERCENTAGE_DECIMAL, "MAX_WAR_EXHAUSTION"); - ret &= add_modifier_effect("military_tactics", true, PROPORTION_DECIMAL, "MIL_TACTICS_TECH"); - ret &= add_modifier_effect("min_military_spending", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("min_social_spending", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("min_tariff", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("min_tax", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect( - "minimum_wage", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("minimun_wage") - ); - ret &= add_modifier_effect("mobilisation_economy_impact", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("mobilisation_size", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("mobilization_impact", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect( - "naval_attack_modifier", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("naval_attack") - ); - ret &= add_modifier_effect("naval_attrition", false, PROPORTION_DECIMAL, "NAVAL_ATTRITION_TECH"); - ret &= add_modifier_effect( - "naval_defense_modifier", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("naval_defense") - ); - ret &= add_modifier_effect("naval_organisation", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("naval_unit_start_experience", true, RAW_DECIMAL); - ret &= add_modifier_effect("non_accepted_pop_consciousness_modifier", false, RAW_DECIMAL); - ret &= add_modifier_effect("non_accepted_pop_militancy_modifier", false, RAW_DECIMAL); - ret &= add_modifier_effect("org_regain", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("pension_level", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("permanent_prestige", true, RAW_DECIMAL, "PERMANENT_PRESTIGE_TECH"); - ret &= add_modifier_effect("political_reform_desire", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("poor_savings_modifier", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("prestige", true, RAW_DECIMAL); - ret &= add_modifier_effect("reinforce_speed", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("research_points", true, RAW_DECIMAL); - ret &= add_modifier_effect("research_points_modifier", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("research_points_on_conquer", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("rgo_output", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("rgo_throughput", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("ruling_party_support", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect( - "self_unciv_economic_modifier", false, PROPORTION_DECIMAL, + ret &= add_modifier_effect("literacy_con_impact", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("loan_interest", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + "max_loan_modifier", true, PROPORTION_DECIMAL, COUNTRY, + make_default_modifier_effect_localisation_key("max_loan_amount") + ); + ret &= add_modifier_effect("max_military_spending", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("max_national_focus", true, INT, COUNTRY, "TECH_MAX_FOCUS"); + ret &= add_modifier_effect("max_social_spending", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("max_tariff", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("max_tax", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("max_war_exhaustion", true, PERCENTAGE_DECIMAL, COUNTRY, "MAX_WAR_EXHAUSTION"); + ret &= add_modifier_effect("military_tactics", true, PROPORTION_DECIMAL, COUNTRY, "MIL_TACTICS_TECH"); + ret &= add_modifier_effect("min_military_spending", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("min_social_spending", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("min_tariff", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("min_tax", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + "minimum_wage", true, PROPORTION_DECIMAL, COUNTRY, make_default_modifier_effect_localisation_key("minimun_wage") + ); + ret &= add_modifier_effect("mobilisation_economy_impact", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("mobilisation_size", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("mobilization_impact", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + "naval_attack_modifier", true, PROPORTION_DECIMAL, COUNTRY, + make_default_modifier_effect_localisation_key("naval_attack") + ); + ret &= add_modifier_effect("naval_attrition", false, PROPORTION_DECIMAL, COUNTRY, "NAVAL_ATTRITION_TECH"); + ret &= add_modifier_effect( + "naval_defense_modifier", true, PROPORTION_DECIMAL, COUNTRY, + make_default_modifier_effect_localisation_key("naval_defense") + ); + ret &= add_modifier_effect("naval_organisation", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("naval_unit_start_experience", true, RAW_DECIMAL, COUNTRY); + ret &= add_modifier_effect("non_accepted_pop_consciousness_modifier", false, RAW_DECIMAL, COUNTRY); + ret &= add_modifier_effect("non_accepted_pop_militancy_modifier", false, RAW_DECIMAL, COUNTRY); + ret &= add_modifier_effect("org_regain", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("pension_level", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("permanent_prestige", true, RAW_DECIMAL, COUNTRY, "PERMANENT_PRESTIGE_TECH"); + ret &= add_modifier_effect("political_reform_desire", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("poor_savings_modifier", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("prestige", true, RAW_DECIMAL, COUNTRY); + ret &= add_modifier_effect("reinforce_speed", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("research_points", true, RAW_DECIMAL, COUNTRY); + ret &= add_modifier_effect("research_points_modifier", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("research_points_on_conquer", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("rgo_output", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("rgo_throughput", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("ruling_party_support", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + "self_unciv_economic_modifier", false, PROPORTION_DECIMAL, COUNTRY, make_default_modifier_effect_localisation_key("self_unciv_economic") ); ret &= add_modifier_effect( - "self_unciv_military_modifier", false, PROPORTION_DECIMAL, + "self_unciv_military_modifier", false, PROPORTION_DECIMAL, COUNTRY, make_default_modifier_effect_localisation_key("self_unciv_military") ); - ret &= add_modifier_effect("social_reform_desire", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("soldier_to_pop_loss", true, PROPORTION_DECIMAL, "SOLDIER_TO_POP_LOSS_TECH"); - ret &= add_modifier_effect("supply_consumption", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("supply_range", true, PROPORTION_DECIMAL, "SUPPLY_RANGE_TECH"); - ret &= add_modifier_effect("suppression_points_modifier", true, PROPORTION_DECIMAL, "SUPPRESSION_TECH"); + ret &= add_modifier_effect("social_reform_desire", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("soldier_to_pop_loss", true, PROPORTION_DECIMAL, COUNTRY, "SOLDIER_TO_POP_LOSS_TECH"); + ret &= add_modifier_effect("supply_consumption", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("supply_range", true, PROPORTION_DECIMAL, COUNTRY, "SUPPLY_RANGE_TECH"); + ret &= add_modifier_effect("suppression_points_modifier", true, PROPORTION_DECIMAL, COUNTRY, "SUPPRESSION_TECH"); ret &= add_modifier_effect( - "tariff_efficiency_modifier", true, PROPORTION_DECIMAL, + "tariff_efficiency_modifier", true, PROPORTION_DECIMAL, COUNTRY, make_default_modifier_effect_localisation_key("tariff_efficiency") ); - ret &= add_modifier_effect("tax_efficiency", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("unemployment_benefit", true, PROPORTION_DECIMAL); + ret &= add_modifier_effect("tax_efficiency", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("unemployment_benefit", true, PROPORTION_DECIMAL, COUNTRY); ret &= add_modifier_effect( - "unciv_economic_modifier", false, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("unciv_economic") + "unciv_economic_modifier", false, PROPORTION_DECIMAL, COUNTRY, + make_default_modifier_effect_localisation_key("unciv_economic") ); ret &= add_modifier_effect( - "unciv_military_modifier", false, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("unciv_military") + "unciv_military_modifier", false, PROPORTION_DECIMAL, COUNTRY, + make_default_modifier_effect_localisation_key("unciv_military") ); - ret &= add_modifier_effect("unit_recruitment_time", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("war_exhaustion", false, PROPORTION_DECIMAL, "WAR_EXHAUST_BATTLES"); + ret &= add_modifier_effect("unit_recruitment_time", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect("war_exhaustion", false, PROPORTION_DECIMAL, COUNTRY, "WAR_EXHAUST_BATTLES"); /* Province Modifier Effects */ - ret &= add_modifier_effect("assimilation_rate", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("boost_strongest_party", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("farm_rgo_eff", true, PROPORTION_DECIMAL, "TECH_FARM_OUTPUT"); + ret &= add_modifier_effect("assimilation_rate", true, PROPORTION_DECIMAL, PROVINCE); + ret &= add_modifier_effect("boost_strongest_party", false, PROPORTION_DECIMAL, PROVINCE); + ret &= add_modifier_effect("farm_rgo_eff", true, PROPORTION_DECIMAL, PROVINCE, "TECH_FARM_OUTPUT"); ret &= add_modifier_effect( - "farm_rgo_size", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("farm_size") + "farm_rgo_size", true, PROPORTION_DECIMAL, PROVINCE, make_default_modifier_effect_localisation_key("farm_size") ); ret &= add_modifier_effect( - "immigrant_attract", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("immigant_attract") + "immigrant_attract", true, PROPORTION_DECIMAL, PROVINCE, + make_default_modifier_effect_localisation_key("immigant_attract") ); ret &= add_modifier_effect( - "immigrant_push", false, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("immigant_push") + "immigrant_push", false, PROPORTION_DECIMAL, PROVINCE, make_default_modifier_effect_localisation_key("immigant_push") ); - ret &= add_modifier_effect("life_rating", true, PROPORTION_DECIMAL); + ret &= add_modifier_effect("life_rating", true, PROPORTION_DECIMAL, PROVINCE); ret &= add_modifier_effect( - "local_artisan_input", false, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("artisan_input") + "local_artisan_input", false, PROPORTION_DECIMAL, PROVINCE, + make_default_modifier_effect_localisation_key("artisan_input") ); ret &= add_modifier_effect( - "local_artisan_output", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("artisan_output") + "local_artisan_output", true, PROPORTION_DECIMAL, PROVINCE, + make_default_modifier_effect_localisation_key("artisan_output") ); ret &= add_modifier_effect( - "local_artisan_throughput", true, PROPORTION_DECIMAL, + "local_artisan_throughput", true, PROPORTION_DECIMAL, PROVINCE, make_default_modifier_effect_localisation_key("artisan_throughput") ); ret &= add_modifier_effect( - "local_factory_input", false, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("factory_input") + "local_factory_input", false, PROPORTION_DECIMAL, PROVINCE, + make_default_modifier_effect_localisation_key("factory_input") ); ret &= add_modifier_effect( - "local_factory_output", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("factory_output") + "local_factory_output", true, PROPORTION_DECIMAL, PROVINCE, + make_default_modifier_effect_localisation_key("factory_output") ); ret &= add_modifier_effect( - "local_factory_throughput", true, PROPORTION_DECIMAL, + "local_factory_throughput", true, PROPORTION_DECIMAL, PROVINCE, make_default_modifier_effect_localisation_key("factory_throughput") ); - ret &= add_modifier_effect("local_repair", true, PROPORTION_DECIMAL); + ret &= add_modifier_effect("local_repair", true, PROPORTION_DECIMAL, PROVINCE); ret &= add_modifier_effect( - "local_rgo_output", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("rgo_output") + "local_rgo_output", true, PROPORTION_DECIMAL, PROVINCE, make_default_modifier_effect_localisation_key("rgo_output") ); ret &= add_modifier_effect( - "local_rgo_throughput", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("rgo_throughput") + "local_rgo_throughput", true, PROPORTION_DECIMAL, PROVINCE, + make_default_modifier_effect_localisation_key("rgo_throughput") ); ret &= add_modifier_effect( - "local_ruling_party_support", true, PROPORTION_DECIMAL, + "local_ruling_party_support", true, PROPORTION_DECIMAL, PROVINCE, make_default_modifier_effect_localisation_key("ruling_party_support") ); - ret &= add_modifier_effect("local_ship_build", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("max_attrition", false, RAW_DECIMAL); - ret &= add_modifier_effect("mine_rgo_eff", true, PROPORTION_DECIMAL, "TECH_MINE_OUTPUT"); + ret &= add_modifier_effect("local_ship_build", false, PROPORTION_DECIMAL, PROVINCE); + ret &= add_modifier_effect("max_attrition", false, RAW_DECIMAL, PROVINCE); + ret &= add_modifier_effect("mine_rgo_eff", true, PROPORTION_DECIMAL, PROVINCE, "TECH_MINE_OUTPUT"); ret &= add_modifier_effect( - "mine_rgo_size", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("mine_size") + "mine_rgo_size", true, PROPORTION_DECIMAL, PROVINCE, make_default_modifier_effect_localisation_key("mine_size") ); - ret &= add_modifier_effect("movement_cost", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("number_of_voters", false, PROPORTION_DECIMAL); - ret &= add_modifier_effect("pop_consciousness_modifier", false, RAW_DECIMAL); - ret &= add_modifier_effect("pop_militancy_modifier", false, RAW_DECIMAL); - ret &= add_modifier_effect("population_growth", true, PROPORTION_DECIMAL); - ret &= add_modifier_effect("supply_limit", true, RAW_DECIMAL); + ret &= add_modifier_effect("movement_cost", false, PROPORTION_DECIMAL, PROVINCE); + ret &= add_modifier_effect("number_of_voters", false, PROPORTION_DECIMAL, PROVINCE); + ret &= add_modifier_effect("pop_consciousness_modifier", false, RAW_DECIMAL, PROVINCE); + ret &= add_modifier_effect("pop_militancy_modifier", false, RAW_DECIMAL, PROVINCE); + ret &= add_modifier_effect("population_growth", true, PROPORTION_DECIMAL, PROVINCE); + ret &= add_modifier_effect("supply_limit", true, RAW_DECIMAL, PROVINCE); /* Military Modifier Effects */ - ret &= add_modifier_effect("attack", true, INT, "TRAIT_ATTACK"); - ret &= add_modifier_effect("attrition", false, RAW_DECIMAL, "ATTRITION"); - ret &= add_modifier_effect("defence", true, INT, "TRAIT_DEFEND"); - ret &= add_modifier_effect("experience", true, PROPORTION_DECIMAL, "TRAIT_EXPERIENCE"); - ret &= add_modifier_effect("morale", true, PROPORTION_DECIMAL, "TRAIT_MORALE"); - ret &= add_modifier_effect("organisation", true, PROPORTION_DECIMAL, "TRAIT_ORGANISATION"); - ret &= add_modifier_effect("reconnaissance", true, PROPORTION_DECIMAL, "TRAIT_RECONAISSANCE"); - ret &= add_modifier_effect("reliability", true, RAW_DECIMAL, "TRAIT_RELIABILITY"); - ret &= add_modifier_effect("speed", true, PROPORTION_DECIMAL, "TRAIT_SPEED"); + ret &= add_modifier_effect("attack", true, INT, UNIT, "TRAIT_ATTACK"); + ret &= add_modifier_effect("attrition", false, RAW_DECIMAL, UNIT, "ATTRITION"); + ret &= add_modifier_effect("defence", true, INT, UNIT, "TRAIT_DEFEND"); + ret &= add_modifier_effect("experience", true, PROPORTION_DECIMAL, UNIT, "TRAIT_EXPERIENCE"); + ret &= add_modifier_effect("morale", true, PROPORTION_DECIMAL, UNIT, "TRAIT_MORALE"); + ret &= add_modifier_effect("organisation", true, PROPORTION_DECIMAL, UNIT, "TRAIT_ORGANISATION"); + ret &= add_modifier_effect("reconnaissance", true, PROPORTION_DECIMAL, UNIT, "TRAIT_RECONAISSANCE"); + ret &= add_modifier_effect("reliability", true, RAW_DECIMAL, UNIT, "TRAIT_RELIABILITY"); + ret &= add_modifier_effect("speed", true, PROPORTION_DECIMAL, UNIT, "TRAIT_SPEED"); return ret; } diff --git a/src/openvic-simulation/modifier/Modifier.hpp b/src/openvic-simulation/modifier/Modifier.hpp index 4b032c0..a848cb8 100644 --- a/src/openvic-simulation/modifier/Modifier.hpp +++ b/src/openvic-simulation/modifier/Modifier.hpp @@ -10,31 +10,43 @@ namespace OpenVic { struct ModifierEffect : HasIdentifier { friend struct ModifierManager; - enum class format_t { + enum class format_t : uint8_t { PROPORTION_DECIMAL, /* An unscaled fraction/ratio, with 1 being "full"/"whole" */ PERCENTAGE_DECIMAL, /* A fraction/ratio scaled so that 100 is "full"/"whole" */ RAW_DECIMAL, /* A continuous quantity, e.g. attack strength */ INT /* A discrete quantity, e.g. building count limit */ }; + enum class target_t : uint8_t { + NO_TARGETS = 0, + COUNTRY = 1 << 0, + PROVINCE = 1 << 1, + UNIT = 1 << 2, + ALL_TARGETS = (1 << 3) - 1 + }; + private: /* If true, positive values will be green and negative values will be red. * If false, the colours will be switced. */ const bool PROPERTY_CUSTOM_PREFIX(positive_good, is); const format_t PROPERTY(format); + const target_t PROPERTY(targets); std::string PROPERTY(localisation_key); // TODO - format/precision, e.g. 80% vs 0.8 vs 0.800, 2 vs 2.0 vs 200% ModifierEffect( - std::string_view new_identifier, bool new_positive_good, format_t new_format, std::string_view new_localisation_key + std::string_view new_identifier, bool new_positive_good, format_t new_format, target_t mew_targets, + std::string_view new_localisation_key ); public: ModifierEffect(ModifierEffect&&) = default; }; + template<> struct enable_bitfield : std::true_type {}; + struct ModifierValue { friend struct ModifierManager; @@ -70,7 +82,8 @@ namespace OpenVic { ModifierValue& operator*=(fixed_point_t const& right); ModifierValue operator*(fixed_point_t const& right) const; - void multiply_add(ModifierValue const& other, fixed_point_t multiplier); + void apply_target_filter(ModifierEffect::target_t targets); + void multiply_add_filter(ModifierValue const& other, fixed_point_t multiplier, ModifierEffect::target_t targets); friend std::ostream& operator<<(std::ostream& stream, ModifierValue const& value); }; @@ -167,6 +180,7 @@ namespace OpenVic { bool add_modifier_effect( std::string_view identifier, bool positive_good, ModifierEffect::format_t format, + ModifierEffect::target_t targets, std::string_view localisation_key = {} ); diff --git a/src/openvic-simulation/modifier/ModifierSum.cpp b/src/openvic-simulation/modifier/ModifierSum.cpp index f603a5b..312432a 100644 --- a/src/openvic-simulation/modifier/ModifierSum.cpp +++ b/src/openvic-simulation/modifier/ModifierSum.cpp @@ -19,9 +19,15 @@ bool ModifierSum::has_effect(ModifierEffect const& effect) const { return value_sum.has_effect(effect); } -void ModifierSum::add_modifier(Modifier const& modifier, modifier_source_t source, fixed_point_t multiplier) { - modifiers.emplace_back(&modifier, multiplier, source); - value_sum.multiply_add(modifier, multiplier); +void ModifierSum::add_modifier( + Modifier const& modifier, modifier_source_t const& source, fixed_point_t multiplier, ModifierEffect::target_t targets +) { + using enum ModifierEffect::target_t; + + if (multiplier != fixed_point_t::_0() && targets != NO_TARGETS) { + modifiers.emplace_back(&modifier, multiplier, source, targets); + value_sum.multiply_add_filter(modifier, multiplier, targets); + } } void ModifierSum::add_modifier_sum(ModifierSum const& modifier_sum) { @@ -29,10 +35,22 @@ void ModifierSum::add_modifier_sum(ModifierSum const& modifier_sum) { value_sum += modifier_sum.value_sum; } +void ModifierSum::add_modifier_sum_filter_targets(ModifierSum const& modifier_sum, ModifierEffect::target_t targets) { + using enum ModifierEffect::target_t; + + for (modifier_entry_t const& modifier_entry : modifier_sum.modifiers) { + ModifierEffect::target_t new_targets = modifier_entry.targets & targets; + + if (new_targets != NO_TARGETS) { + add_modifier(*modifier_entry.modifier, modifier_entry.source, modifier_entry.multiplier, new_targets); + } + } +} + void ModifierSum::add_modifier_sum_exclude_source(ModifierSum const& modifier_sum, modifier_source_t const& excluded_source) { for (modifier_entry_t const& modifier_entry : modifier_sum.modifiers) { if (modifier_entry.source != excluded_source) { - add_modifier(*modifier_entry.modifier, modifier_entry.source, modifier_entry.multiplier); + add_modifier(*modifier_entry.modifier, modifier_entry.source, modifier_entry.multiplier, modifier_entry.targets); } } } @@ -41,14 +59,18 @@ void ModifierSum::add_modifier_sum_exclude_source(ModifierSum const& modifier_su std::vector ModifierSum::get_contributing_modifiers( ModifierEffect const& effect ) const { + using enum ModifierEffect::target_t; + std::vector ret; for (modifier_entry_t const& modifier_entry : modifiers) { - bool effect_found = false; - const fixed_point_t value = modifier_entry.modifier->get_effect(effect, &effect_found); + if ((modifier_entry.targets & effect.get_targets()) != NO_TARGETS) { + bool effect_found = false; + const fixed_point_t value = modifier_entry.modifier->get_effect(effect, &effect_found); - if (effect_found) { - ret.push_back(modifier_entry); + if (effect_found) { + ret.push_back(modifier_entry); + } } } diff --git a/src/openvic-simulation/modifier/ModifierSum.hpp b/src/openvic-simulation/modifier/ModifierSum.hpp index 81ae871..b982ed1 100644 --- a/src/openvic-simulation/modifier/ModifierSum.hpp +++ b/src/openvic-simulation/modifier/ModifierSum.hpp @@ -1,6 +1,9 @@ #pragma once +#include + #include "openvic-simulation/modifier/Modifier.hpp" +#include "openvic-simulation/types/fixed_point/FixedPoint.hpp" namespace OpenVic { struct CountryInstance; @@ -13,10 +16,12 @@ namespace OpenVic { Modifier const* modifier; fixed_point_t multiplier; modifier_source_t source; + ModifierEffect::target_t targets; constexpr modifier_entry_t( - Modifier const* new_modifier, fixed_point_t new_multiplier, modifier_source_t const& new_source - ) : modifier { new_modifier }, multiplier { new_multiplier }, source { new_source } {} + Modifier const* new_modifier, fixed_point_t new_multiplier, modifier_source_t const& new_source, + ModifierEffect::target_t new_targets + ) : modifier { new_modifier }, multiplier { new_multiplier }, source { new_source }, targets { new_targets } {} }; private: @@ -25,7 +30,10 @@ namespace OpenVic { public: ModifierSum() = default; + ModifierSum(ModifierSum const&) = default; ModifierSum(ModifierSum&&) = default; + ModifierSum& operator=(ModifierSum const&) = default; + ModifierSum& operator=(ModifierSum&&) = default; void clear(); bool empty(); @@ -33,8 +41,12 @@ namespace OpenVic { fixed_point_t get_effect(ModifierEffect const& effect, bool* effect_found = nullptr) const; bool has_effect(ModifierEffect const& effect) const; - void add_modifier(Modifier const& modifier, modifier_source_t source, fixed_point_t multiplier = fixed_point_t::_1()); + void add_modifier( + Modifier const& modifier, modifier_source_t const& source, fixed_point_t multiplier = fixed_point_t::_1(), + ModifierEffect::target_t targets = ModifierEffect::target_t::ALL_TARGETS + ); void add_modifier_sum(ModifierSum const& modifier_sum); + void add_modifier_sum_filter_targets(ModifierSum const& modifier_sum, ModifierEffect::target_t targets); void add_modifier_sum_exclude_source(ModifierSum const& modifier_sum, modifier_source_t const& excluded_source); std::vector get_contributing_modifiers(ModifierEffect const& effect) const; diff --git a/src/openvic-simulation/politics/Rebel.cpp b/src/openvic-simulation/politics/Rebel.cpp index fef61c0..395df49 100644 --- a/src/openvic-simulation/politics/Rebel.cpp +++ b/src/openvic-simulation/politics/Rebel.cpp @@ -175,6 +175,7 @@ bool RebelManager::load_rebels_file( bool RebelManager::generate_modifiers(ModifierManager& modifier_manager) const { using enum ModifierEffect::format_t; + using enum ModifierEffect::target_t; bool ret = true; @@ -184,12 +185,14 @@ bool RebelManager::generate_modifiers(ModifierManager& modifier_manager) const { ret &= modifier_manager.register_complex_modifier(identifier); ret &= modifier_manager.add_modifier_effect( - ModifierManager::get_flat_identifier(identifier, "all"), is_positive_good, PROPORTION_DECIMAL, "TECH_REBEL_ORG_GAIN" + ModifierManager::get_flat_identifier(identifier, "all"), is_positive_good, PROPORTION_DECIMAL, COUNTRY, + "TECH_REBEL_ORG_GAIN" ); for (RebelType const& rebel_type : get_rebel_types()) { ret &= modifier_manager.add_modifier_effect( - ModifierManager::get_flat_identifier(identifier, rebel_type.get_identifier()), is_positive_good, PROPORTION_DECIMAL, + ModifierManager::get_flat_identifier(identifier, rebel_type.get_identifier()), is_positive_good, + PROPORTION_DECIMAL, COUNTRY, StringUtils::append_string_views("$", rebel_type.get_identifier(), "_title$ $TECH_REBEL_ORG_GAIN$") ); } diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp index e89d510..aeaeef5 100644 --- a/src/openvic-simulation/pop/Pop.cpp +++ b/src/openvic-simulation/pop/Pop.cpp @@ -654,6 +654,7 @@ bool PopManager::load_pop_bases_into_vector( bool PopManager::generate_modifiers(ModifierManager& modifier_manager) const { using enum ModifierEffect::format_t; + using enum ModifierEffect::target_t; bool ret = true; @@ -662,11 +663,12 @@ bool PopManager::generate_modifiers(ModifierManager& modifier_manager) const { std::string_view suffix, bool is_positive_good ) -> void { ret &= modifier_manager.add_modifier_effect( - StringUtils::append_string_views(strata.get_identifier(), suffix), is_positive_good, PROPORTION_DECIMAL + StringUtils::append_string_views(strata.get_identifier(), suffix), is_positive_good, PROPORTION_DECIMAL, + COUNTRY ); }; - strata_modifier("_income_modifier", true); + strata_modifier("_income_modifier", true); // Has no effect in game strata_modifier("_vote", true); strata_modifier("_life_needs", false); diff --git a/src/openvic-simulation/research/Technology.cpp b/src/openvic-simulation/research/Technology.cpp index a5256f3..3284193 100644 --- a/src/openvic-simulation/research/Technology.cpp +++ b/src/openvic-simulation/research/Technology.cpp @@ -197,13 +197,16 @@ bool TechnologyManager::load_technologies_file( bool TechnologyManager::generate_modifiers(ModifierManager& modifier_manager) const { using enum ModifierEffect::format_t; + using enum ModifierEffect::target_t; bool ret = true; for (TechnologyFolder const& folder : get_technology_folders()) { const std::string modifier_identifier = StringUtils::append_string_views(folder.get_identifier(), "_research_bonus"); - ret &= modifier_manager.add_modifier_effect(modifier_identifier, true, PROPORTION_DECIMAL, modifier_identifier); + ret &= modifier_manager.add_modifier_effect( + modifier_identifier, true, PROPORTION_DECIMAL, COUNTRY, modifier_identifier + ); } return ret; -- cgit v1.2.3-56-ga3b1 From ba4fe5d9a8596e1b73a3aa0735d471e25493d54b Mon Sep 17 00:00:00 2001 From: hop311 Date: Mon, 30 Sep 2024 23:23:35 +0100 Subject: Cache modifier effects in dedicated variables --- src/openvic-simulation/economy/BuildingType.cpp | 16 +- src/openvic-simulation/economy/GoodDefinition.cpp | 92 ++-- src/openvic-simulation/military/UnitType.cpp | 76 ++-- src/openvic-simulation/modifier/Modifier.cpp | 474 ++++++++++++++------- src/openvic-simulation/modifier/Modifier.hpp | 12 +- .../modifier/ModifierEffectCache.cpp | 227 ++++++++++ .../modifier/ModifierEffectCache.hpp | 303 +++++++++++++ src/openvic-simulation/politics/Rebel.cpp | 13 +- src/openvic-simulation/pop/Pop.cpp | 23 +- src/openvic-simulation/research/Technology.cpp | 7 +- 10 files changed, 1015 insertions(+), 228 deletions(-) create mode 100644 src/openvic-simulation/modifier/ModifierEffectCache.cpp create mode 100644 src/openvic-simulation/modifier/ModifierEffectCache.hpp (limited to 'src/openvic-simulation/pop/Pop.cpp') diff --git a/src/openvic-simulation/economy/BuildingType.cpp b/src/openvic-simulation/economy/BuildingType.cpp index d75f1b2..3733a5f 100644 --- a/src/openvic-simulation/economy/BuildingType.cpp +++ b/src/openvic-simulation/economy/BuildingType.cpp @@ -112,19 +112,27 @@ bool BuildingTypeManager::load_buildings_file( )(root); lock_building_types(); - for (BuildingType const& building_type : building_types.get_items()) { + IndexedMap& building_type_effects = + modifier_manager.modifier_effect_cache.building_type_effects; + + building_type_effects.set_keys(&get_building_types()); + + for (BuildingType const& building_type : get_building_types()) { using enum ModifierEffect::format_t; using enum ModifierEffect::target_t; + ModifierEffectCache::building_type_effects_t& this_building_type_effects = building_type_effects[building_type]; + static constexpr std::string_view max_prefix = "max_"; static constexpr std::string_view min_prefix = "min_build_"; ret &= modifier_manager.add_modifier_effect( - StringUtils::append_string_views(max_prefix, building_type.get_identifier()), true, INT, PROVINCE, - StringUtils::append_string_views("$", building_type.get_identifier(), "$ $TECH_MAX_LEVEL$") + this_building_type_effects.max_level, StringUtils::append_string_views(max_prefix, building_type.get_identifier()), + true, INT, PROVINCE, StringUtils::append_string_views("$", building_type.get_identifier(), "$ $TECH_MAX_LEVEL$") ); // TODO - add custom localisation for "min_build_$building_type$" modifiers ret &= modifier_manager.add_modifier_effect( - StringUtils::append_string_views(min_prefix, building_type.get_identifier()), false, INT, PROVINCE + this_building_type_effects.min_level, StringUtils::append_string_views(min_prefix, building_type.get_identifier()), + false, INT, PROVINCE ); if (building_type.is_in_province()) { diff --git a/src/openvic-simulation/economy/GoodDefinition.cpp b/src/openvic-simulation/economy/GoodDefinition.cpp index fcaae11..25281bb 100644 --- a/src/openvic-simulation/economy/GoodDefinition.cpp +++ b/src/openvic-simulation/economy/GoodDefinition.cpp @@ -93,38 +93,80 @@ bool GoodDefinitionManager::generate_modifiers(ModifierManager& modifier_manager using enum ModifierEffect::format_t; using enum ModifierEffect::target_t; + IndexedMap& good_effects = + modifier_manager.modifier_effect_cache.good_effects; + + good_effects.set_keys(&get_good_definitions()); + bool ret = true; - const auto good_modifier = [this, &modifier_manager, &ret]( - std::string_view name, bool is_positive_good, auto make_localisation_suffix - ) -> void { - ret &= modifier_manager.register_complex_modifier(name); + ret &= modifier_manager.register_complex_modifier("artisan_goods_input"); + ret &= modifier_manager.register_complex_modifier("artisan_goods_output"); + ret &= modifier_manager.register_complex_modifier("artisan_goods_throughput"); + ret &= modifier_manager.register_complex_modifier("factory_goods_input"); + ret &= modifier_manager.register_complex_modifier("factory_goods_output"); + ret &= modifier_manager.register_complex_modifier("factory_goods_throughput"); + ret &= modifier_manager.register_complex_modifier("rgo_goods_output"); + ret &= modifier_manager.register_complex_modifier("rgo_goods_throughput"); + ret &= modifier_manager.register_complex_modifier("rgo_size"); - for (GoodDefinition const& good : get_good_definitions()) { + for (GoodDefinition const& good : get_good_definitions()) { + const std::string_view good_identifier = good.get_identifier(); + ModifierEffectCache::good_effects_t& this_good_effects = good_effects[good]; + + const auto good_modifier = [&modifier_manager, &ret, &good_identifier]( + ModifierEffect const*& effect_cache, std::string_view name, bool is_positive_good, + std::string_view localisation_key + ) -> void { ret &= modifier_manager.add_modifier_effect( - ModifierManager::get_flat_identifier(name, good.get_identifier()), is_positive_good, PROPORTION_DECIMAL, - COUNTRY, make_localisation_suffix(good.get_identifier()) + effect_cache, ModifierManager::get_flat_identifier(name, good_identifier), is_positive_good, + PROPORTION_DECIMAL, COUNTRY, localisation_key ); - } - }; + }; - const auto make_production_localisation_suffix = [](std::string_view localisation_suffix) -> auto { - return [localisation_suffix](std::string_view good_identifier) -> std::string { - return StringUtils::append_string_views("$", good_identifier, "$ $", localisation_suffix, "$"); + const auto make_production_localisation_suffix = [&good_identifier]( + std::string_view localisation_suffix + ) -> std::string { + return StringUtils::append_string_views("$", good_identifier, "$ $", localisation_suffix, "$"); }; - }; - - good_modifier("artisan_goods_input", false, make_production_localisation_suffix("TECH_INPUT")); - good_modifier("artisan_goods_output", true, make_production_localisation_suffix("TECH_OUTPUT")); - good_modifier("artisan_goods_throughput", true, make_production_localisation_suffix("TECH_THROUGHPUT")); - good_modifier("factory_goods_input", false, make_production_localisation_suffix("TECH_INPUT")); - good_modifier("factory_goods_output", true, make_production_localisation_suffix("TECH_OUTPUT")); - good_modifier("factory_goods_throughput", true, make_production_localisation_suffix("TECH_THROUGHPUT")); - good_modifier("rgo_goods_output", true, make_production_localisation_suffix("TECH_OUTPUT")); - good_modifier("rgo_goods_throughput", true, make_production_localisation_suffix("TECH_THROUGHPUT")); - good_modifier("rgo_size", true, [](std::string_view good_identifier) -> std::string { - return StringUtils::append_string_views(good_identifier, "_RGO_SIZE"); - }); + + good_modifier( + this_good_effects.artisan_goods_input, "artisan_goods_input", false, + make_production_localisation_suffix("TECH_INPUT") + ); + good_modifier( + this_good_effects.artisan_goods_output, "artisan_goods_output", true, + make_production_localisation_suffix("TECH_OUTPUT") + ); + good_modifier( + this_good_effects.artisan_goods_throughput, "artisan_goods_throughput", true, + make_production_localisation_suffix("TECH_THROUGHPUT") + ); + good_modifier( + this_good_effects.factory_goods_input, "factory_goods_input", false, + make_production_localisation_suffix("TECH_INPUT") + ); + good_modifier( + this_good_effects.factory_goods_output, "factory_goods_output", true, + make_production_localisation_suffix("TECH_OUTPUT") + ); + good_modifier( + this_good_effects.factory_goods_throughput, "factory_goods_throughput", true, + make_production_localisation_suffix("TECH_THROUGHPUT") + ); + good_modifier( + this_good_effects.rgo_goods_output, "rgo_goods_output", true, + make_production_localisation_suffix("TECH_OUTPUT") + ); + good_modifier( + this_good_effects.rgo_goods_throughput, "rgo_goods_throughput", true, + make_production_localisation_suffix("TECH_THROUGHPUT") + ); + good_modifier( + this_good_effects.rgo_size, "rgo_size", true, + StringUtils::append_string_views(good_identifier, "_RGO_SIZE") + ); + } return ret; } diff --git a/src/openvic-simulation/military/UnitType.cpp b/src/openvic-simulation/military/UnitType.cpp index bb227fb..004f766 100644 --- a/src/openvic-simulation/military/UnitType.cpp +++ b/src/openvic-simulation/military/UnitType.cpp @@ -319,60 +319,72 @@ bool UnitTypeManager::generate_modifiers(ModifierManager& modifier_manager) cons bool ret = true; const auto generate_stat_modifiers = [&modifier_manager, &ret]( - std::string_view identifier, UnitType::branch_t branch + std::derived_from auto unit_type_effects, std::string_view identifier ) -> void { using enum ModifierEffect::format_t; using enum ModifierEffect::target_t; const auto stat_modifier = [&modifier_manager, &ret, &identifier]( - std::string_view suffix, bool is_positive_good, ModifierEffect::format_t format, std::string_view localisation_key + ModifierEffect const*& effect_cache, std::string_view suffix, bool is_positive_good, + ModifierEffect::format_t format, std::string_view localisation_key ) -> void { ret &= modifier_manager.add_modifier_effect( - ModifierManager::get_flat_identifier(identifier, suffix), is_positive_good, format, COUNTRY, + effect_cache, ModifierManager::get_flat_identifier(identifier, suffix), is_positive_good, format, COUNTRY, StringUtils::append_string_views("$", identifier, "$: $", localisation_key, "$") ); }; ret &= modifier_manager.register_complex_modifier(identifier); - stat_modifier("attack", true, RAW_DECIMAL, "ATTACK"); - stat_modifier("defence", true, RAW_DECIMAL, "DEFENCE"); - stat_modifier("default_organisation", true, RAW_DECIMAL, "DEFAULT_ORG"); - stat_modifier("maximum_speed", true, RAW_DECIMAL, "MAXIMUM_SPEED"); - stat_modifier("build_time", false, INT, "BUILD_TIME"); - stat_modifier("supply_consumption", false, PROPORTION_DECIMAL, "SUPPLY_CONSUMPTION"); + stat_modifier(unit_type_effects.attack, "attack", true, RAW_DECIMAL, "ATTACK"); + stat_modifier(unit_type_effects.defence, "defence", true, RAW_DECIMAL, "DEFENCE"); + stat_modifier(unit_type_effects.default_organisation, "default_organisation", true, RAW_DECIMAL, "DEFAULT_ORG"); + stat_modifier(unit_type_effects.maximum_speed, "maximum_speed", true, RAW_DECIMAL, "MAXIMUM_SPEED"); + stat_modifier(unit_type_effects.build_time, "build_time", false, INT, "BUILD_TIME"); + stat_modifier( + unit_type_effects.supply_consumption, "supply_consumption", false, PROPORTION_DECIMAL, "SUPPLY_CONSUMPTION" + ); - switch (branch) { - case LAND: - stat_modifier("reconnaissance", true, RAW_DECIMAL, "RECONAISSANCE"); - stat_modifier("discipline", true, PROPORTION_DECIMAL, "DISCIPLINE"); - stat_modifier("support", true, PROPORTION_DECIMAL, "SUPPORT"); - stat_modifier("maneuver", true, INT, "Maneuver"); - stat_modifier("siege", true, RAW_DECIMAL, "SIEGE"); - break; - case NAVAL: - stat_modifier("colonial_points", true, INT, "COLONIAL_POINTS_TECH"); - stat_modifier("supply_consumption_score", false, INT, "SUPPLY_LOAD"); - stat_modifier("hull", true, RAW_DECIMAL, "HULL"); - stat_modifier("gun_power", true, RAW_DECIMAL, "GUN_POWER"); - stat_modifier("fire_range", true, RAW_DECIMAL, "FIRE_RANGE"); - stat_modifier("evasion", true, PROPORTION_DECIMAL, "EVASION"); - stat_modifier("torpedo_attack", true, RAW_DECIMAL, "TORPEDO_ATTACK"); - break; - default: + if constexpr (std::same_as) { + stat_modifier(unit_type_effects.reconnaissance, "reconnaissance", true, RAW_DECIMAL, "RECONAISSANCE"); + stat_modifier(unit_type_effects.discipline, "discipline", true, PROPORTION_DECIMAL, "DISCIPLINE"); + stat_modifier(unit_type_effects.support, "support", true, PROPORTION_DECIMAL, "SUPPORT"); + stat_modifier(unit_type_effects.maneuver, "maneuver", true, INT, "Maneuver"); + stat_modifier(unit_type_effects.siege, "siege", true, RAW_DECIMAL, "SIEGE"); + } else if constexpr(std::same_as) { + stat_modifier(unit_type_effects.colonial_points, "colonial_points", true, INT, "COLONIAL_POINTS_TECH"); + stat_modifier(unit_type_effects.supply_consumption_score, "supply_consumption_score", false, INT, "SUPPLY_LOAD"); + stat_modifier(unit_type_effects.hull, "hull", true, RAW_DECIMAL, "HULL"); + stat_modifier(unit_type_effects.gun_power, "gun_power", true, RAW_DECIMAL, "GUN_POWER"); + stat_modifier(unit_type_effects.fire_range, "fire_range", true, RAW_DECIMAL, "FIRE_RANGE"); + stat_modifier(unit_type_effects.evasion, "evasion", true, PROPORTION_DECIMAL, "EVASION"); + stat_modifier(unit_type_effects.torpedo_attack, "torpedo_attack", true, RAW_DECIMAL, "TORPEDO_ATTACK"); + } else { /* Unreachable - unit types are only added via add_regiment_type or add_ship_type which set branch to LAND or NAVAL. */ - Logger::error("Invalid branch for unit ", identifier, ": ", static_cast(branch)); + Logger::error("Invalid branch for unit ", identifier, " - not LAND or NAVAL!"); } }; - generate_stat_modifiers("army_base", LAND); + generate_stat_modifiers(modifier_manager.modifier_effect_cache.army_base_effects, "army_base"); + + IndexedMap& regiment_type_effects = + modifier_manager.modifier_effect_cache.regiment_type_effects; + + regiment_type_effects.set_keys(&get_regiment_types()); + for (RegimentType const& regiment_type : get_regiment_types()) { - generate_stat_modifiers(regiment_type.get_identifier(), LAND); + generate_stat_modifiers(regiment_type_effects[regiment_type], regiment_type.get_identifier()); } - generate_stat_modifiers("navy_base", NAVAL); + generate_stat_modifiers(modifier_manager.modifier_effect_cache.navy_base_effects, "navy_base"); + + IndexedMap& ship_type_effects = + modifier_manager.modifier_effect_cache.ship_type_effects; + + ship_type_effects.set_keys(&get_ship_types()); + for (ShipType const& ship_type : get_ship_types()) { - generate_stat_modifiers(ship_type.get_identifier(), NAVAL); + generate_stat_modifiers(ship_type_effects[ship_type], ship_type.get_identifier()); } return ret; diff --git a/src/openvic-simulation/modifier/Modifier.cpp b/src/openvic-simulation/modifier/Modifier.cpp index 0867c1b..4e10c76 100644 --- a/src/openvic-simulation/modifier/Modifier.cpp +++ b/src/openvic-simulation/modifier/Modifier.cpp @@ -31,14 +31,29 @@ ModifierInstance::ModifierInstance(Modifier const& new_modifier, Date new_expiry : modifier { &new_modifier }, expiry_date { new_expiry_date } {} bool ModifierManager::add_modifier_effect( - std::string_view identifier, bool positive_good, ModifierEffect::format_t format, ModifierEffect::target_t targets, - std::string_view localisation_key + ModifierEffect const*& effect_cache, std::string_view identifier, bool positive_good, ModifierEffect::format_t format, + ModifierEffect::target_t targets, std::string_view localisation_key ) { if (identifier.empty()) { Logger::error("Invalid modifier effect identifier - empty!"); return false; } - return modifier_effects.add_item({ std::move(identifier), positive_good, format, targets, localisation_key }); + + if (effect_cache != nullptr) { + Logger::error( + "Cache variable for modifier effect \"", identifier, "\" is already filled with modifier effect \"", + effect_cache->get_identifier(), "\"" + ); + return false; + } + + const bool ret = modifier_effects.add_item({ std::move(identifier), positive_good, format, targets, localisation_key }); + + if (ret) { + effect_cache = &modifier_effects.get_items().back(); + } + + return ret; } bool ModifierManager::setup_modifier_effects() { @@ -46,252 +61,405 @@ bool ModifierManager::setup_modifier_effects() { using enum ModifierEffect::format_t; using enum ModifierEffect::target_t; + /* Tech/inventions only */ - ret &= add_modifier_effect("cb_creation_speed", true, PROPORTION_DECIMAL, COUNTRY, "CB_MANUFACTURE_TECH"); - ret &= add_modifier_effect("combat_width", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("plurality", true, PERCENTAGE_DECIMAL, COUNTRY, "TECH_PLURALITY"); - ret &= add_modifier_effect("pop_growth", true, PROPORTION_DECIMAL, COUNTRY, "TECH_POP_GROWTH"); - ret &= add_modifier_effect("regular_experience_level", true, RAW_DECIMAL, COUNTRY, "REGULAR_EXP_TECH"); - ret &= add_modifier_effect("reinforce_rate", true, PROPORTION_DECIMAL, COUNTRY, "REINFORCE_TECH"); - ret &= add_modifier_effect("seperatism", false, PROPORTION_DECIMAL, COUNTRY, "SEPARATISM_TECH"); // paradox typo - ret &= add_modifier_effect("shared_prestige", true, RAW_DECIMAL, COUNTRY, "SHARED_PRESTIGE_TECH"); - ret &= add_modifier_effect("tax_eff", true, PERCENTAGE_DECIMAL, COUNTRY, "TECH_TAX_EFF"); + ret &= add_modifier_effect( + modifier_effect_cache.cb_creation_speed, "cb_creation_speed", true, PROPORTION_DECIMAL, COUNTRY, "CB_MANUFACTURE_TECH" + ); + ret &= add_modifier_effect(modifier_effect_cache.combat_width, "combat_width", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.plurality, "plurality", true, PERCENTAGE_DECIMAL, COUNTRY, "TECH_PLURALITY" + ); + ret &= add_modifier_effect( + modifier_effect_cache.pop_growth, "pop_growth", true, PROPORTION_DECIMAL, COUNTRY, "TECH_POP_GROWTH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.regular_experience_level, "regular_experience_level", true, RAW_DECIMAL, COUNTRY, + "REGULAR_EXP_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.reinforce_rate, "reinforce_rate", true, PROPORTION_DECIMAL, COUNTRY, "REINFORCE_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.separatism, "seperatism", // paradox typo + false, PROPORTION_DECIMAL, COUNTRY, "SEPARATISM_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.shared_prestige, "shared_prestige", true, RAW_DECIMAL, COUNTRY, "SHARED_PRESTIGE_TECH" + ); + ret &= add_modifier_effect(modifier_effect_cache.tax_eff, "tax_eff", true, PERCENTAGE_DECIMAL, COUNTRY, "TECH_TAX_EFF"); /* Country Modifier Effects */ - ret &= add_modifier_effect("administrative_efficiency", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - "administrative_efficiency_modifier", true, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("administrative_efficiency") - ); - ret &= add_modifier_effect("artisan_input", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("artisan_output", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("artisan_throughput", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("badboy", false, RAW_DECIMAL, COUNTRY); - ret &= add_modifier_effect("cb_generation_speed_modifier", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - "civilization_progress_modifier", true, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("civilization_progress") - ); - ret &= add_modifier_effect("colonial_life_rating", false, INT, COUNTRY, "COLONIAL_LIFE_TECH"); - ret &= add_modifier_effect("colonial_migration", true, PROPORTION_DECIMAL, COUNTRY, "COLONIAL_MIGRATION_TECH"); - ret &= add_modifier_effect("colonial_points", true, INT, COUNTRY, "COLONIAL_POINTS_TECH"); - ret &= add_modifier_effect("colonial_prestige", true, PROPORTION_DECIMAL, COUNTRY, "COLONIAL_PRESTIGE_MODIFIER_TECH"); - ret &= add_modifier_effect("core_pop_consciousness_modifier", false, RAW_DECIMAL, COUNTRY); - ret &= add_modifier_effect("core_pop_militancy_modifier", false, RAW_DECIMAL, COUNTRY); - ret &= add_modifier_effect("dig_in_cap", true, INT, COUNTRY, "DIGIN_FROM_TECH"); - ret &= add_modifier_effect("diplomatic_points", true, PROPORTION_DECIMAL, COUNTRY, "DIPLOMATIC_POINTS_TECH"); - ret &= add_modifier_effect( - "diplomatic_points_modifier", true, PROPORTION_DECIMAL, COUNTRY, + ret &= add_modifier_effect( + modifier_effect_cache.administrative_efficiency, "administrative_efficiency", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.administrative_efficiency_modifier, "administrative_efficiency_modifier", true, + PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("administrative_efficiency") + ); + ret &= add_modifier_effect(modifier_effect_cache.artisan_input, "artisan_input", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.artisan_output, "artisan_output", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.artisan_throughput, "artisan_throughput", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.badboy, "badboy", false, RAW_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.cb_generation_speed_modifier, "cb_generation_speed_modifier", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.civilization_progress_modifier, "civilization_progress_modifier", true, PROPORTION_DECIMAL, + COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("civilization_progress") + ); + ret &= add_modifier_effect( + modifier_effect_cache.colonial_life_rating, "colonial_life_rating", false, INT, COUNTRY, "COLONIAL_LIFE_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.colonial_migration, "colonial_migration", true, PROPORTION_DECIMAL, COUNTRY, + "COLONIAL_MIGRATION_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.colonial_points, "colonial_points", true, INT, COUNTRY, "COLONIAL_POINTS_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.colonial_prestige, "colonial_prestige", true, PROPORTION_DECIMAL, COUNTRY, + "COLONIAL_PRESTIGE_MODIFIER_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.core_pop_consciousness_modifier, "core_pop_consciousness_modifier", false, RAW_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.core_pop_militancy_modifier, "core_pop_militancy_modifier", false, RAW_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.dig_in_cap, "dig_in_cap", true, INT, COUNTRY, "DIGIN_FROM_TECH"); + ret &= add_modifier_effect( + modifier_effect_cache.diplomatic_points, "diplomatic_points", true, PROPORTION_DECIMAL, COUNTRY, + "DIPLOMATIC_POINTS_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.diplomatic_points_modifier, "diplomatic_points_modifier", true, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("diplopoints_gain") ); - ret &= add_modifier_effect("education_efficiency", true, PROPORTION_DECIMAL, COUNTRY); ret &= add_modifier_effect( - "education_efficiency_modifier", true, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("education_efficiency") + modifier_effect_cache.education_efficiency, "education_efficiency", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.education_efficiency_modifier, "education_efficiency_modifier", true, PROPORTION_DECIMAL, + COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("education_efficiency") ); - ret &= add_modifier_effect("factory_cost", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("factory_input", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("factory_maintenance", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("factory_output", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("factory_owner_cost", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("factory_throughput", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.factory_cost, "factory_cost", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.factory_input, "factory_input", false, PROPORTION_DECIMAL, COUNTRY); ret &= add_modifier_effect( - "global_assimilation_rate", true, PROPORTION_DECIMAL, COUNTRY, + modifier_effect_cache.factory_maintenance, "factory_maintenance", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.factory_output, "factory_output", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.factory_owner_cost, "factory_owner_cost", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.factory_throughput, "factory_throughput", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.global_assimilation_rate, "global_assimilation_rate", true, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("assimilation_rate") ); ret &= add_modifier_effect( - "global_immigrant_attract", true, PROPORTION_DECIMAL, COUNTRY, + modifier_effect_cache.global_immigrant_attract, "global_immigrant_attract", true, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("immigant_attract") ); - ret &= add_modifier_effect("global_pop_consciousness_modifier", false, RAW_DECIMAL, COUNTRY); - ret &= add_modifier_effect("global_pop_militancy_modifier", false, RAW_DECIMAL, COUNTRY); ret &= add_modifier_effect( - "global_population_growth", true, PROPORTION_DECIMAL, COUNTRY, + modifier_effect_cache.global_pop_consciousness_modifier, "global_pop_consciousness_modifier", false, RAW_DECIMAL, + COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.global_pop_militancy_modifier, "global_pop_militancy_modifier", false, RAW_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.global_population_growth, "global_population_growth", true, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("population_growth") ); - ret &= add_modifier_effect("goods_demand", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("import_cost", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("increase_research", true, PROPORTION_DECIMAL, COUNTRY, "INC_RES_TECH"); - ret &= add_modifier_effect("influence", true, PROPORTION_DECIMAL, COUNTRY, "TECH_GP_INFLUENCE"); + ret &= add_modifier_effect(modifier_effect_cache.goods_demand, "goods_demand", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.import_cost, "import_cost", false, PROPORTION_DECIMAL, COUNTRY); ret &= add_modifier_effect( - "influence_modifier", true, PROPORTION_DECIMAL, COUNTRY, + modifier_effect_cache.increase_research, "increase_research", true, PROPORTION_DECIMAL, COUNTRY, "INC_RES_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.influence, "influence", true, PROPORTION_DECIMAL, COUNTRY, "TECH_GP_INFLUENCE" + ); + ret &= add_modifier_effect( + modifier_effect_cache.influence_modifier, "influence_modifier", true, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("greatpower_influence_gain") ); - ret &= add_modifier_effect("issue_change_speed", true, PROPORTION_DECIMAL, COUNTRY); ret &= add_modifier_effect( - "land_attack_modifier", true, PROPORTION_DECIMAL, COUNTRY, + modifier_effect_cache.issue_change_speed, "issue_change_speed", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.land_attack_modifier, "land_attack_modifier", true, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("land_attack") ); - ret &= add_modifier_effect("land_attrition", false, PROPORTION_DECIMAL, COUNTRY, "LAND_ATTRITION_TECH"); ret &= add_modifier_effect( - "land_defense_modifier", true, PROPORTION_DECIMAL, COUNTRY, + modifier_effect_cache.land_attrition, "land_attrition", false, PROPORTION_DECIMAL, COUNTRY, "LAND_ATTRITION_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.land_defense_modifier, "land_defense_modifier", true, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("land_defense") ); - ret &= add_modifier_effect("land_organisation", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("land_unit_start_experience", true, RAW_DECIMAL, COUNTRY); - ret &= add_modifier_effect("leadership", true, RAW_DECIMAL, COUNTRY, "LEADERSHIP"); ret &= add_modifier_effect( - "leadership_modifier", true, PROPORTION_DECIMAL, COUNTRY, + modifier_effect_cache.land_organisation, "land_organisation", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.land_unit_start_experience, "land_unit_start_experience", true, RAW_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.leadership, "leadership", true, RAW_DECIMAL, COUNTRY, "LEADERSHIP"); + ret &= add_modifier_effect( + modifier_effect_cache.leadership_modifier, "leadership_modifier", true, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("global_leadership_modifier") ); - ret &= add_modifier_effect("literacy_con_impact", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("loan_interest", false, PROPORTION_DECIMAL, COUNTRY); ret &= add_modifier_effect( - "max_loan_modifier", true, PROPORTION_DECIMAL, COUNTRY, + modifier_effect_cache.literacy_con_impact, "literacy_con_impact", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.loan_interest, "loan_interest", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.max_loan_modifier, "max_loan_modifier", true, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("max_loan_amount") ); - ret &= add_modifier_effect("max_military_spending", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("max_national_focus", true, INT, COUNTRY, "TECH_MAX_FOCUS"); - ret &= add_modifier_effect("max_social_spending", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("max_tariff", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("max_tax", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("max_war_exhaustion", true, PERCENTAGE_DECIMAL, COUNTRY, "MAX_WAR_EXHAUSTION"); - ret &= add_modifier_effect("military_tactics", true, PROPORTION_DECIMAL, COUNTRY, "MIL_TACTICS_TECH"); - ret &= add_modifier_effect("min_military_spending", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("min_social_spending", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("min_tariff", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("min_tax", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - "minimum_wage", true, PROPORTION_DECIMAL, COUNTRY, + ret &= add_modifier_effect( + modifier_effect_cache.max_military_spending, "max_military_spending", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.max_national_focus, "max_national_focus", true, INT, COUNTRY, "TECH_MAX_FOCUS" + ); + ret &= add_modifier_effect( + modifier_effect_cache.max_social_spending, "max_social_spending", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.max_tariff, "max_tariff", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.max_tax, "max_tax", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.max_war_exhaustion, "max_war_exhaustion", true, PERCENTAGE_DECIMAL, COUNTRY, "MAX_WAR_EXHAUSTION" + ); + ret &= add_modifier_effect( + modifier_effect_cache.military_tactics, "military_tactics", true, PROPORTION_DECIMAL, COUNTRY, "MIL_TACTICS_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.min_military_spending, "min_military_spending", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.min_social_spending, "min_social_spending", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.min_tariff, "min_tariff", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.min_tax, "min_tax", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.minimum_wage, "minimum_wage", true, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("minimun_wage") ); - ret &= add_modifier_effect("mobilisation_economy_impact", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("mobilisation_size", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("mobilization_impact", false, PROPORTION_DECIMAL, COUNTRY); ret &= add_modifier_effect( - "naval_attack_modifier", true, PROPORTION_DECIMAL, COUNTRY, + modifier_effect_cache.mobilisation_economy_impact, "mobilisation_economy_impact", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.mobilisation_size, "mobilisation_size", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.mobilization_impact, "mobilization_impact", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.naval_attack_modifier, "naval_attack_modifier", true, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("naval_attack") ); - ret &= add_modifier_effect("naval_attrition", false, PROPORTION_DECIMAL, COUNTRY, "NAVAL_ATTRITION_TECH"); ret &= add_modifier_effect( - "naval_defense_modifier", true, PROPORTION_DECIMAL, COUNTRY, + modifier_effect_cache.naval_attrition, "naval_attrition", false, PROPORTION_DECIMAL, COUNTRY, "NAVAL_ATTRITION_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.naval_defense_modifier, "naval_defense_modifier", true, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("naval_defense") ); - ret &= add_modifier_effect("naval_organisation", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("naval_unit_start_experience", true, RAW_DECIMAL, COUNTRY); - ret &= add_modifier_effect("non_accepted_pop_consciousness_modifier", false, RAW_DECIMAL, COUNTRY); - ret &= add_modifier_effect("non_accepted_pop_militancy_modifier", false, RAW_DECIMAL, COUNTRY); - ret &= add_modifier_effect("org_regain", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("pension_level", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("permanent_prestige", true, RAW_DECIMAL, COUNTRY, "PERMANENT_PRESTIGE_TECH"); - ret &= add_modifier_effect("political_reform_desire", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("poor_savings_modifier", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("prestige", true, RAW_DECIMAL, COUNTRY); - ret &= add_modifier_effect("reinforce_speed", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("research_points", true, RAW_DECIMAL, COUNTRY); - ret &= add_modifier_effect("research_points_modifier", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("research_points_on_conquer", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("rgo_output", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("rgo_throughput", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("ruling_party_support", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - "self_unciv_economic_modifier", false, PROPORTION_DECIMAL, COUNTRY, + ret &= add_modifier_effect( + modifier_effect_cache.naval_organisation, "naval_organisation", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.naval_unit_start_experience, "naval_unit_start_experience", true, RAW_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.non_accepted_pop_consciousness_modifier, "non_accepted_pop_consciousness_modifier", false, + RAW_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.non_accepted_pop_militancy_modifier, "non_accepted_pop_militancy_modifier", false, RAW_DECIMAL, + COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.org_regain, "org_regain", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.pension_level, "pension_level", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.permanent_prestige, "permanent_prestige", true, RAW_DECIMAL, COUNTRY, "PERMANENT_PRESTIGE_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.political_reform_desire, "political_reform_desire", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.poor_savings_modifier, "poor_savings_modifier", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.prestige, "prestige", true, RAW_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.reinforce_speed, "reinforce_speed", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.research_points, "research_points", true, RAW_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.research_points_modifier, "research_points_modifier", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.research_points_on_conquer, "research_points_on_conquer", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.rgo_output, "rgo_output", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.rgo_throughput, "rgo_throughput", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.ruling_party_support, "ruling_party_support", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.self_unciv_economic_modifier, "self_unciv_economic_modifier", false, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("self_unciv_economic") ); ret &= add_modifier_effect( - "self_unciv_military_modifier", false, PROPORTION_DECIMAL, COUNTRY, + modifier_effect_cache.self_unciv_military_modifier, "self_unciv_military_modifier", false, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("self_unciv_military") ); - ret &= add_modifier_effect("social_reform_desire", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("soldier_to_pop_loss", true, PROPORTION_DECIMAL, COUNTRY, "SOLDIER_TO_POP_LOSS_TECH"); - ret &= add_modifier_effect("supply_consumption", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("supply_range", true, PROPORTION_DECIMAL, COUNTRY, "SUPPLY_RANGE_TECH"); - ret &= add_modifier_effect("suppression_points_modifier", true, PROPORTION_DECIMAL, COUNTRY, "SUPPRESSION_TECH"); ret &= add_modifier_effect( - "tariff_efficiency_modifier", true, PROPORTION_DECIMAL, COUNTRY, + modifier_effect_cache.social_reform_desire, "social_reform_desire", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.soldier_to_pop_loss, "soldier_to_pop_loss", true, PROPORTION_DECIMAL, COUNTRY, + "SOLDIER_TO_POP_LOSS_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.supply_consumption, "supply_consumption", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.supply_range, "supply_range", true, PROPORTION_DECIMAL, COUNTRY, "SUPPLY_RANGE_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.suppression_points_modifier, "suppression_points_modifier", true, PROPORTION_DECIMAL, COUNTRY, + "SUPPRESSION_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.tariff_efficiency_modifier, "tariff_efficiency_modifier", true, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("tariff_efficiency") ); - ret &= add_modifier_effect("tax_efficiency", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("unemployment_benefit", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.tax_efficiency, "tax_efficiency", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.unemployment_benefit, "unemployment_benefit", true, PROPORTION_DECIMAL, COUNTRY + ); ret &= add_modifier_effect( - "unciv_economic_modifier", false, PROPORTION_DECIMAL, COUNTRY, + modifier_effect_cache.unciv_economic_modifier, "unciv_economic_modifier", false, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("unciv_economic") ); ret &= add_modifier_effect( - "unciv_military_modifier", false, PROPORTION_DECIMAL, COUNTRY, + modifier_effect_cache.unciv_military_modifier, "unciv_military_modifier", false, PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("unciv_military") ); - ret &= add_modifier_effect("unit_recruitment_time", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect("war_exhaustion", false, PROPORTION_DECIMAL, COUNTRY, "WAR_EXHAUST_BATTLES"); + ret &= add_modifier_effect( + modifier_effect_cache.unit_recruitment_time, "unit_recruitment_time", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.war_exhaustion, "war_exhaustion", false, PROPORTION_DECIMAL, COUNTRY, "WAR_EXHAUST_BATTLES" + ); /* Province Modifier Effects */ - ret &= add_modifier_effect("assimilation_rate", true, PROPORTION_DECIMAL, PROVINCE); - ret &= add_modifier_effect("boost_strongest_party", false, PROPORTION_DECIMAL, PROVINCE); - ret &= add_modifier_effect("farm_rgo_eff", true, PROPORTION_DECIMAL, PROVINCE, "TECH_FARM_OUTPUT"); ret &= add_modifier_effect( - "farm_rgo_size", true, PROPORTION_DECIMAL, PROVINCE, + modifier_effect_cache.assimilation_rate, "assimilation_rate", true, PROPORTION_DECIMAL, PROVINCE + ); + ret &= add_modifier_effect( + modifier_effect_cache.boost_strongest_party, "boost_strongest_party", false, PROPORTION_DECIMAL, PROVINCE + ); + ret &= add_modifier_effect( + modifier_effect_cache.farm_rgo_eff, "farm_rgo_eff", true, PROPORTION_DECIMAL, PROVINCE, "TECH_FARM_OUTPUT" + ); + ret &= add_modifier_effect( + modifier_effect_cache.farm_rgo_size, "farm_rgo_size", true, PROPORTION_DECIMAL, PROVINCE, ModifierEffect::make_default_modifier_effect_localisation_key("farm_size") ); ret &= add_modifier_effect( - "immigrant_attract", true, PROPORTION_DECIMAL, PROVINCE, + modifier_effect_cache.immigrant_attract, "immigrant_attract", true, PROPORTION_DECIMAL, PROVINCE, ModifierEffect::make_default_modifier_effect_localisation_key("immigant_attract") ); ret &= add_modifier_effect( - "immigrant_push", false, PROPORTION_DECIMAL, PROVINCE, + modifier_effect_cache.immigrant_push, "immigrant_push", false, PROPORTION_DECIMAL, PROVINCE, ModifierEffect::make_default_modifier_effect_localisation_key("immigant_push") ); - ret &= add_modifier_effect("life_rating", true, PROPORTION_DECIMAL, PROVINCE); + ret &= add_modifier_effect(modifier_effect_cache.life_rating, "life_rating", true, PROPORTION_DECIMAL, PROVINCE); ret &= add_modifier_effect( - "local_artisan_input", false, PROPORTION_DECIMAL, PROVINCE, + modifier_effect_cache.local_artisan_input, "local_artisan_input", false, PROPORTION_DECIMAL, PROVINCE, ModifierEffect::make_default_modifier_effect_localisation_key("artisan_input") ); ret &= add_modifier_effect( - "local_artisan_output", true, PROPORTION_DECIMAL, PROVINCE, + modifier_effect_cache.local_artisan_output, "local_artisan_output", true, PROPORTION_DECIMAL, PROVINCE, ModifierEffect::make_default_modifier_effect_localisation_key("artisan_output") ); ret &= add_modifier_effect( - "local_artisan_throughput", true, PROPORTION_DECIMAL, PROVINCE, + modifier_effect_cache.local_artisan_throughput, "local_artisan_throughput", true, PROPORTION_DECIMAL, PROVINCE, ModifierEffect::make_default_modifier_effect_localisation_key("artisan_throughput") ); ret &= add_modifier_effect( - "local_factory_input", false, PROPORTION_DECIMAL, PROVINCE, + modifier_effect_cache.local_factory_input, "local_factory_input", false, PROPORTION_DECIMAL, PROVINCE, ModifierEffect::make_default_modifier_effect_localisation_key("factory_input") ); ret &= add_modifier_effect( - "local_factory_output", true, PROPORTION_DECIMAL, PROVINCE, + modifier_effect_cache.local_factory_output, "local_factory_output", true, PROPORTION_DECIMAL, PROVINCE, ModifierEffect::make_default_modifier_effect_localisation_key("factory_output") ); ret &= add_modifier_effect( - "local_factory_throughput", true, PROPORTION_DECIMAL, PROVINCE, + modifier_effect_cache.local_factory_throughput, "local_factory_throughput", true, PROPORTION_DECIMAL, PROVINCE, ModifierEffect::make_default_modifier_effect_localisation_key("factory_throughput") ); - ret &= add_modifier_effect("local_repair", true, PROPORTION_DECIMAL, PROVINCE); + ret &= add_modifier_effect(modifier_effect_cache.local_repair, "local_repair", true, PROPORTION_DECIMAL, PROVINCE); ret &= add_modifier_effect( - "local_rgo_output", true, PROPORTION_DECIMAL, PROVINCE, + modifier_effect_cache.local_rgo_output, "local_rgo_output", true, PROPORTION_DECIMAL, PROVINCE, ModifierEffect::make_default_modifier_effect_localisation_key("rgo_output") ); ret &= add_modifier_effect( - "local_rgo_throughput", true, PROPORTION_DECIMAL, PROVINCE, + modifier_effect_cache.local_rgo_throughput, "local_rgo_throughput", true, PROPORTION_DECIMAL, PROVINCE, ModifierEffect::make_default_modifier_effect_localisation_key("rgo_throughput") ); ret &= add_modifier_effect( - "local_ruling_party_support", true, PROPORTION_DECIMAL, PROVINCE, + modifier_effect_cache.local_ruling_party_support, "local_ruling_party_support", true, PROPORTION_DECIMAL, PROVINCE, ModifierEffect::make_default_modifier_effect_localisation_key("ruling_party_support") ); - ret &= add_modifier_effect("local_ship_build", false, PROPORTION_DECIMAL, PROVINCE); - ret &= add_modifier_effect("max_attrition", false, RAW_DECIMAL, PROVINCE); - ret &= add_modifier_effect("mine_rgo_eff", true, PROPORTION_DECIMAL, PROVINCE, "TECH_MINE_OUTPUT"); ret &= add_modifier_effect( - "mine_rgo_size", true, PROPORTION_DECIMAL, PROVINCE, + modifier_effect_cache.local_ship_build, "local_ship_build", false, PROPORTION_DECIMAL, PROVINCE + ); + ret &= add_modifier_effect(modifier_effect_cache.max_attrition, "max_attrition", false, RAW_DECIMAL, PROVINCE); + ret &= add_modifier_effect( + modifier_effect_cache.mine_rgo_eff, "mine_rgo_eff", true, PROPORTION_DECIMAL, PROVINCE, "TECH_MINE_OUTPUT" + ); + ret &= add_modifier_effect( + modifier_effect_cache.mine_rgo_size, "mine_rgo_size", true, PROPORTION_DECIMAL, PROVINCE, ModifierEffect::make_default_modifier_effect_localisation_key("mine_size") ); - ret &= add_modifier_effect("movement_cost", false, PROPORTION_DECIMAL, PROVINCE); - ret &= add_modifier_effect("number_of_voters", false, PROPORTION_DECIMAL, PROVINCE); - ret &= add_modifier_effect("pop_consciousness_modifier", false, RAW_DECIMAL, PROVINCE); - ret &= add_modifier_effect("pop_militancy_modifier", false, RAW_DECIMAL, PROVINCE); - ret &= add_modifier_effect("population_growth", true, PROPORTION_DECIMAL, PROVINCE); - ret &= add_modifier_effect("supply_limit", true, RAW_DECIMAL, PROVINCE); + ret &= add_modifier_effect(modifier_effect_cache.movement_cost, "movement_cost", false, PROPORTION_DECIMAL, PROVINCE); + ret &= add_modifier_effect( + modifier_effect_cache.number_of_voters, "number_of_voters", false, PROPORTION_DECIMAL, PROVINCE + ); + ret &= add_modifier_effect( + modifier_effect_cache.pop_consciousness_modifier, "pop_consciousness_modifier", false, RAW_DECIMAL, PROVINCE + ); + ret &= add_modifier_effect( + modifier_effect_cache.pop_militancy_modifier, "pop_militancy_modifier", false, RAW_DECIMAL, PROVINCE + ); + ret &= add_modifier_effect( + modifier_effect_cache.population_growth, "population_growth", true, PROPORTION_DECIMAL, PROVINCE + ); + ret &= add_modifier_effect(modifier_effect_cache.supply_limit, "supply_limit", true, RAW_DECIMAL, PROVINCE); /* Military Modifier Effects */ - ret &= add_modifier_effect("attack", true, INT, UNIT, "TRAIT_ATTACK"); - ret &= add_modifier_effect("attrition", false, RAW_DECIMAL, UNIT, "ATTRITION"); - ret &= add_modifier_effect("defence", true, INT, UNIT, "TRAIT_DEFEND"); - ret &= add_modifier_effect("experience", true, PROPORTION_DECIMAL, UNIT, "TRAIT_EXPERIENCE"); - ret &= add_modifier_effect("morale", true, PROPORTION_DECIMAL, UNIT, "TRAIT_MORALE"); - ret &= add_modifier_effect("organisation", true, PROPORTION_DECIMAL, UNIT, "TRAIT_ORGANISATION"); - ret &= add_modifier_effect("reconnaissance", true, PROPORTION_DECIMAL, UNIT, "TRAIT_RECONAISSANCE"); - ret &= add_modifier_effect("reliability", true, RAW_DECIMAL, UNIT, "TRAIT_RELIABILITY"); - ret &= add_modifier_effect("speed", true, PROPORTION_DECIMAL, UNIT, "TRAIT_SPEED"); + ret &= add_modifier_effect(modifier_effect_cache.attack, "attack", true, INT, UNIT, "TRAIT_ATTACK"); + ret &= add_modifier_effect(modifier_effect_cache.attrition, "attrition", false, RAW_DECIMAL, UNIT, "ATTRITION"); + ret &= add_modifier_effect(modifier_effect_cache.defence, "defence", true, INT, UNIT, "TRAIT_DEFEND"); + ret &= add_modifier_effect( + modifier_effect_cache.experience, "experience", true, PROPORTION_DECIMAL, UNIT, "TRAIT_EXPERIENCE" + ); + ret &= add_modifier_effect(modifier_effect_cache.morale, "morale", true, PROPORTION_DECIMAL, UNIT, "TRAIT_MORALE"); + ret &= add_modifier_effect( + modifier_effect_cache.organisation, "organisation", true, PROPORTION_DECIMAL, UNIT, "TRAIT_ORGANISATION" + ); + ret &= add_modifier_effect( + modifier_effect_cache.reconnaissance, "reconnaissance", true, PROPORTION_DECIMAL, UNIT, "TRAIT_RECONAISSANCE" + ); + ret &= add_modifier_effect(modifier_effect_cache.reliability, "reliability", true, RAW_DECIMAL, UNIT, "TRAIT_RELIABILITY"); + ret &= add_modifier_effect(modifier_effect_cache.speed, "speed", true, PROPORTION_DECIMAL, UNIT, "TRAIT_SPEED"); return ret; } diff --git a/src/openvic-simulation/modifier/Modifier.hpp b/src/openvic-simulation/modifier/Modifier.hpp index 28e56cd..49194cd 100644 --- a/src/openvic-simulation/modifier/Modifier.hpp +++ b/src/openvic-simulation/modifier/Modifier.hpp @@ -1,6 +1,7 @@ #pragma once #include "openvic-simulation/modifier/ModifierEffect.hpp" +#include "openvic-simulation/modifier/ModifierEffectCache.hpp" #include "openvic-simulation/modifier/ModifierValue.hpp" #include "openvic-simulation/modifier/StaticModifierCache.hpp" #include "openvic-simulation/scripts/ConditionScript.hpp" @@ -74,6 +75,12 @@ namespace OpenVic { struct ModifierManager { friend struct StaticModifierCache; + friend struct BuildingTypeManager; + friend struct GoodDefinitionManager; + friend struct UnitTypeManager; + friend struct RebelManager; + friend struct PopManager; + friend struct TechnologyManager; /* Some ModifierEffects are generated mid-load, such as max/min count modifiers for each building, so * we can't lock it until loading is over. This means we can't rely on locking for pointer stability, @@ -87,6 +94,7 @@ namespace OpenVic { IdentifierRegistry IDENTIFIER_REGISTRY(static_modifier); IdentifierRegistry IDENTIFIER_REGISTRY(triggered_modifier); + ModifierEffectCache PROPERTY(modifier_effect_cache); StaticModifierCache PROPERTY(static_modifier_cache); /* effect_validator takes in ModifierEffect const& */ @@ -97,7 +105,9 @@ namespace OpenVic { public: bool add_modifier_effect( - std::string_view identifier, bool positive_good, + ModifierEffect const*& effect_cache, + std::string_view identifier, + bool positive_good, ModifierEffect::format_t format, ModifierEffect::target_t targets, std::string_view localisation_key = {} diff --git a/src/openvic-simulation/modifier/ModifierEffectCache.cpp b/src/openvic-simulation/modifier/ModifierEffectCache.cpp new file mode 100644 index 0000000..b5d8a31 --- /dev/null +++ b/src/openvic-simulation/modifier/ModifierEffectCache.cpp @@ -0,0 +1,227 @@ +#include "ModifierEffectCache.hpp" + +#include "openvic-simulation/economy/BuildingType.hpp" +#include "openvic-simulation/economy/GoodDefinition.hpp" +#include "openvic-simulation/politics/Rebel.hpp" +#include "openvic-simulation/research/Technology.hpp" + +using namespace OpenVic; + +ModifierEffectCache::building_type_effects_t::building_type_effects_t() + : min_level { nullptr }, + max_level { nullptr } {} + +ModifierEffectCache::good_effects_t::good_effects_t() + : artisan_goods_input { nullptr }, + artisan_goods_output { nullptr }, + artisan_goods_throughput { nullptr }, + factory_goods_input { nullptr }, + factory_goods_output { nullptr }, + factory_goods_throughput { nullptr }, + rgo_goods_output { nullptr }, + rgo_goods_throughput { nullptr }, + rgo_size { nullptr } {} + +ModifierEffectCache::unit_type_effects_t::unit_type_effects_t() + : attack { nullptr }, + defence { nullptr }, + default_organisation { nullptr }, + maximum_speed { nullptr }, + build_time { nullptr }, + supply_consumption { nullptr } {} + +ModifierEffectCache::regiment_type_effects_t::regiment_type_effects_t() + : unit_type_effects_t {}, + reconnaissance { nullptr }, + discipline { nullptr }, + support { nullptr }, + maneuver { nullptr }, + siege { nullptr } {} + +ModifierEffectCache::ship_type_effects_t::ship_type_effects_t() + : unit_type_effects_t {}, + colonial_points { nullptr }, + supply_consumption_score { nullptr }, + hull { nullptr }, + gun_power { nullptr }, + fire_range { nullptr }, + evasion { nullptr }, + torpedo_attack { nullptr } {} + +ModifierEffectCache::strata_effects_t::strata_effects_t() + : income_modifier { nullptr }, + vote { nullptr }, + life_needs { nullptr }, + everyday_needs { nullptr }, + luxury_needs { nullptr } {} + +ModifierEffectCache::ModifierEffectCache() + : /* Tech/inventions only */ + cb_creation_speed { nullptr }, + combat_width { nullptr }, + plurality { nullptr }, + pop_growth { nullptr }, + regular_experience_level { nullptr }, + reinforce_rate { nullptr }, + separatism { nullptr }, + shared_prestige { nullptr }, + tax_eff { nullptr }, + + /* Country Modifier Effects */ + administrative_efficiency { nullptr }, + administrative_efficiency_modifier { nullptr }, + artisan_input { nullptr }, + artisan_output { nullptr }, + artisan_throughput { nullptr }, + badboy { nullptr }, + cb_generation_speed_modifier { nullptr }, + civilization_progress_modifier { nullptr }, + colonial_life_rating { nullptr }, + colonial_migration { nullptr }, + colonial_points { nullptr }, + colonial_prestige { nullptr }, + core_pop_consciousness_modifier { nullptr }, + core_pop_militancy_modifier { nullptr }, + dig_in_cap { nullptr }, + diplomatic_points { nullptr }, + diplomatic_points_modifier { nullptr }, + education_efficiency { nullptr }, + education_efficiency_modifier { nullptr }, + factory_cost { nullptr }, + factory_input { nullptr }, + factory_maintenance { nullptr }, + factory_output { nullptr }, + factory_owner_cost { nullptr }, + factory_throughput { nullptr }, + global_assimilation_rate { nullptr }, + global_immigrant_attract { nullptr }, + global_pop_consciousness_modifier { nullptr }, + global_pop_militancy_modifier { nullptr }, + global_population_growth { nullptr }, + goods_demand { nullptr }, + import_cost { nullptr }, + increase_research { nullptr }, + influence { nullptr }, + influence_modifier { nullptr }, + issue_change_speed { nullptr }, + land_attack_modifier { nullptr }, + land_attrition { nullptr }, + land_defense_modifier { nullptr }, + land_organisation { nullptr }, + land_unit_start_experience { nullptr }, + leadership { nullptr }, + leadership_modifier { nullptr }, + literacy_con_impact { nullptr }, + loan_interest { nullptr }, + max_loan_modifier { nullptr }, + max_military_spending { nullptr }, + max_national_focus { nullptr }, + max_social_spending { nullptr }, + max_tariff { nullptr }, + max_tax { nullptr }, + max_war_exhaustion { nullptr }, + military_tactics { nullptr }, + min_military_spending { nullptr }, + min_social_spending { nullptr }, + min_tariff { nullptr }, + min_tax { nullptr }, + minimum_wage { nullptr }, + mobilisation_economy_impact { nullptr }, + mobilisation_size { nullptr }, + mobilization_impact { nullptr }, + naval_attack_modifier { nullptr }, + naval_attrition { nullptr }, + naval_defense_modifier { nullptr }, + naval_organisation { nullptr }, + naval_unit_start_experience { nullptr }, + non_accepted_pop_consciousness_modifier { nullptr }, + non_accepted_pop_militancy_modifier { nullptr }, + org_regain { nullptr }, + pension_level { nullptr }, + permanent_prestige { nullptr }, + political_reform_desire { nullptr }, + poor_savings_modifier { nullptr }, + prestige { nullptr }, + reinforce_speed { nullptr }, + research_points { nullptr }, + research_points_modifier { nullptr }, + research_points_on_conquer { nullptr }, + rgo_output { nullptr }, + rgo_throughput { nullptr }, + ruling_party_support { nullptr }, + self_unciv_economic_modifier { nullptr }, + self_unciv_military_modifier { nullptr }, + social_reform_desire { nullptr }, + soldier_to_pop_loss { nullptr }, + supply_consumption { nullptr }, + supply_range { nullptr }, + suppression_points_modifier { nullptr }, + tariff_efficiency_modifier { nullptr }, + tax_efficiency { nullptr }, + unemployment_benefit { nullptr }, + unciv_economic_modifier { nullptr }, + unciv_military_modifier { nullptr }, + unit_recruitment_time { nullptr }, + war_exhaustion { nullptr }, + + /* Province Modifier Effects */ + assimilation_rate { nullptr }, + boost_strongest_party { nullptr }, + farm_rgo_eff { nullptr }, + farm_rgo_size { nullptr }, + immigrant_attract { nullptr }, + immigrant_push { nullptr }, + life_rating { nullptr }, + local_artisan_input { nullptr }, + local_artisan_output { nullptr }, + local_artisan_throughput { nullptr }, + local_factory_input { nullptr }, + local_factory_output { nullptr }, + local_factory_throughput { nullptr }, + local_repair { nullptr }, + local_rgo_output { nullptr }, + local_rgo_throughput { nullptr }, + local_ruling_party_support { nullptr }, + local_ship_build { nullptr }, + max_attrition { nullptr }, + mine_rgo_eff { nullptr }, + mine_rgo_size { nullptr }, + movement_cost { nullptr }, + number_of_voters { nullptr }, + pop_consciousness_modifier { nullptr }, + pop_militancy_modifier { nullptr }, + population_growth { nullptr }, + supply_limit { nullptr }, + + /* Military Modifier Effects */ + attack { nullptr }, + attrition { nullptr }, + defence { nullptr }, + experience { nullptr }, + morale { nullptr }, + organisation { nullptr }, + reconnaissance { nullptr }, + reliability { nullptr }, + speed { nullptr }, + + /* BuildingType Effects */ + building_type_effects { nullptr }, + + /* GoodDefinition Effects */ + good_effects { nullptr }, + + /* UnitType Effects */ + army_base_effects {}, + regiment_type_effects { nullptr }, + navy_base_effects {}, + ship_type_effects { nullptr }, + + /* Rebel Effects */ + rebel_org_gain_all { nullptr }, + rebel_org_gain_effects { nullptr }, + + /* Pop Effects */ + strata_effects { nullptr }, + + /* Technology Effects */ + research_bonus_effects { nullptr } {} diff --git a/src/openvic-simulation/modifier/ModifierEffectCache.hpp b/src/openvic-simulation/modifier/ModifierEffectCache.hpp new file mode 100644 index 0000000..3c349e9 --- /dev/null +++ b/src/openvic-simulation/modifier/ModifierEffectCache.hpp @@ -0,0 +1,303 @@ +#pragma once + +#include "openvic-simulation/military/UnitType.hpp" +#include "openvic-simulation/types/IndexedMap.hpp" +#include "openvic-simulation/utility/Getters.hpp" + +namespace OpenVic { + struct ModifierEffect; + struct ModifierManager; + + struct BuildingTypeManager; + struct BuildingType; + struct GoodDefinitionManager; + struct GoodDefinition; + struct RebelManager; + struct RebelType; + struct PopManager; + struct Strata; + struct TechnologyManager; + struct TechnologyFolder; + + struct ModifierEffectCache { + friend struct ModifierManager; + friend struct BuildingTypeManager; + friend struct GoodDefinitionManager; + friend struct UnitTypeManager; + friend struct RebelManager; + friend struct PopManager; + friend struct TechnologyManager; + + private: + /* Tech/inventions only */ + ModifierEffect const* PROPERTY(cb_creation_speed); + ModifierEffect const* PROPERTY(combat_width); + ModifierEffect const* PROPERTY(plurality); + ModifierEffect const* PROPERTY(pop_growth); + ModifierEffect const* PROPERTY(regular_experience_level); + ModifierEffect const* PROPERTY(reinforce_rate); + ModifierEffect const* PROPERTY(separatism); + ModifierEffect const* PROPERTY(shared_prestige); + ModifierEffect const* PROPERTY(tax_eff); + + /* Country Modifier Effects */ + ModifierEffect const* PROPERTY(administrative_efficiency); + ModifierEffect const* PROPERTY(administrative_efficiency_modifier); + ModifierEffect const* PROPERTY(artisan_input); + ModifierEffect const* PROPERTY(artisan_output); + ModifierEffect const* PROPERTY(artisan_throughput); + ModifierEffect const* PROPERTY(badboy); + ModifierEffect const* PROPERTY(cb_generation_speed_modifier); + ModifierEffect const* PROPERTY(civilization_progress_modifier); + ModifierEffect const* PROPERTY(colonial_life_rating); + ModifierEffect const* PROPERTY(colonial_migration); + ModifierEffect const* PROPERTY(colonial_points); + ModifierEffect const* PROPERTY(colonial_prestige); + ModifierEffect const* PROPERTY(core_pop_consciousness_modifier); + ModifierEffect const* PROPERTY(core_pop_militancy_modifier); + ModifierEffect const* PROPERTY(dig_in_cap); + ModifierEffect const* PROPERTY(diplomatic_points); + ModifierEffect const* PROPERTY(diplomatic_points_modifier); + ModifierEffect const* PROPERTY(education_efficiency); + ModifierEffect const* PROPERTY(education_efficiency_modifier); + ModifierEffect const* PROPERTY(factory_cost); + ModifierEffect const* PROPERTY(factory_input); + ModifierEffect const* PROPERTY(factory_maintenance); + ModifierEffect const* PROPERTY(factory_output); + ModifierEffect const* PROPERTY(factory_owner_cost); + ModifierEffect const* PROPERTY(factory_throughput); + ModifierEffect const* PROPERTY(global_assimilation_rate); + ModifierEffect const* PROPERTY(global_immigrant_attract); + ModifierEffect const* PROPERTY(global_pop_consciousness_modifier); + ModifierEffect const* PROPERTY(global_pop_militancy_modifier); + ModifierEffect const* PROPERTY(global_population_growth); + ModifierEffect const* PROPERTY(goods_demand); + ModifierEffect const* PROPERTY(import_cost); + ModifierEffect const* PROPERTY(increase_research); + ModifierEffect const* PROPERTY(influence); + ModifierEffect const* PROPERTY(influence_modifier); + ModifierEffect const* PROPERTY(issue_change_speed); + ModifierEffect const* PROPERTY(land_attack_modifier); + ModifierEffect const* PROPERTY(land_attrition); + ModifierEffect const* PROPERTY(land_defense_modifier); + ModifierEffect const* PROPERTY(land_organisation); + ModifierEffect const* PROPERTY(land_unit_start_experience); + ModifierEffect const* PROPERTY(leadership); + ModifierEffect const* PROPERTY(leadership_modifier); + ModifierEffect const* PROPERTY(literacy_con_impact); + ModifierEffect const* PROPERTY(loan_interest); + ModifierEffect const* PROPERTY(max_loan_modifier); + ModifierEffect const* PROPERTY(max_military_spending); + ModifierEffect const* PROPERTY(max_national_focus); + ModifierEffect const* PROPERTY(max_social_spending); + ModifierEffect const* PROPERTY(max_tariff); + ModifierEffect const* PROPERTY(max_tax); + ModifierEffect const* PROPERTY(max_war_exhaustion); + ModifierEffect const* PROPERTY(military_tactics); + ModifierEffect const* PROPERTY(min_military_spending); + ModifierEffect const* PROPERTY(min_social_spending); + ModifierEffect const* PROPERTY(min_tariff); + ModifierEffect const* PROPERTY(min_tax); + ModifierEffect const* PROPERTY(minimum_wage); + ModifierEffect const* PROPERTY(mobilisation_economy_impact); + ModifierEffect const* PROPERTY(mobilisation_size); + ModifierEffect const* PROPERTY(mobilization_impact); + ModifierEffect const* PROPERTY(naval_attack_modifier); + ModifierEffect const* PROPERTY(naval_attrition); + ModifierEffect const* PROPERTY(naval_defense_modifier); + ModifierEffect const* PROPERTY(naval_organisation); + ModifierEffect const* PROPERTY(naval_unit_start_experience); + ModifierEffect const* PROPERTY(non_accepted_pop_consciousness_modifier); + ModifierEffect const* PROPERTY(non_accepted_pop_militancy_modifier); + ModifierEffect const* PROPERTY(org_regain); + ModifierEffect const* PROPERTY(pension_level); + ModifierEffect const* PROPERTY(permanent_prestige); + ModifierEffect const* PROPERTY(political_reform_desire); + ModifierEffect const* PROPERTY(poor_savings_modifier); + ModifierEffect const* PROPERTY(prestige); + ModifierEffect const* PROPERTY(reinforce_speed); + ModifierEffect const* PROPERTY(research_points); + ModifierEffect const* PROPERTY(research_points_modifier); + ModifierEffect const* PROPERTY(research_points_on_conquer); + ModifierEffect const* PROPERTY(rgo_output); + ModifierEffect const* PROPERTY(rgo_throughput); + ModifierEffect const* PROPERTY(ruling_party_support); + ModifierEffect const* PROPERTY(self_unciv_economic_modifier); + ModifierEffect const* PROPERTY(self_unciv_military_modifier); + ModifierEffect const* PROPERTY(social_reform_desire); + ModifierEffect const* PROPERTY(soldier_to_pop_loss); + ModifierEffect const* PROPERTY(supply_consumption); + ModifierEffect const* PROPERTY(supply_range); + ModifierEffect const* PROPERTY(suppression_points_modifier); + ModifierEffect const* PROPERTY(tariff_efficiency_modifier); + ModifierEffect const* PROPERTY(tax_efficiency); + ModifierEffect const* PROPERTY(unemployment_benefit); + ModifierEffect const* PROPERTY(unciv_economic_modifier); + ModifierEffect const* PROPERTY(unciv_military_modifier); + ModifierEffect const* PROPERTY(unit_recruitment_time); + ModifierEffect const* PROPERTY(war_exhaustion); + + /* Province Modifier Effects */ + ModifierEffect const* PROPERTY(assimilation_rate); + ModifierEffect const* PROPERTY(boost_strongest_party); + ModifierEffect const* PROPERTY(farm_rgo_eff); + ModifierEffect const* PROPERTY(farm_rgo_size); + ModifierEffect const* PROPERTY(immigrant_attract); + ModifierEffect const* PROPERTY(immigrant_push); + ModifierEffect const* PROPERTY(life_rating); + ModifierEffect const* PROPERTY(local_artisan_input); + ModifierEffect const* PROPERTY(local_artisan_output); + ModifierEffect const* PROPERTY(local_artisan_throughput); + ModifierEffect const* PROPERTY(local_factory_input); + ModifierEffect const* PROPERTY(local_factory_output); + ModifierEffect const* PROPERTY(local_factory_throughput); + ModifierEffect const* PROPERTY(local_repair); + ModifierEffect const* PROPERTY(local_rgo_output); + ModifierEffect const* PROPERTY(local_rgo_throughput); + ModifierEffect const* PROPERTY(local_ruling_party_support); + ModifierEffect const* PROPERTY(local_ship_build); + ModifierEffect const* PROPERTY(max_attrition); + ModifierEffect const* PROPERTY(mine_rgo_eff); + ModifierEffect const* PROPERTY(mine_rgo_size); + ModifierEffect const* PROPERTY(movement_cost); + ModifierEffect const* PROPERTY(number_of_voters); + ModifierEffect const* PROPERTY(pop_consciousness_modifier); + ModifierEffect const* PROPERTY(pop_militancy_modifier); + ModifierEffect const* PROPERTY(population_growth); + ModifierEffect const* PROPERTY(supply_limit); + + /* Military Modifier Effects */ + ModifierEffect const* PROPERTY(attack); + ModifierEffect const* PROPERTY(attrition); + ModifierEffect const* PROPERTY(defence); + ModifierEffect const* PROPERTY(experience); + ModifierEffect const* PROPERTY(morale); + ModifierEffect const* PROPERTY(organisation); + ModifierEffect const* PROPERTY(reconnaissance); + ModifierEffect const* PROPERTY(reliability); + ModifierEffect const* PROPERTY(speed); + + /* BuildingType Effects */ + public: + struct building_type_effects_t { + friend struct BuildingTypeManager; + + private: + ModifierEffect const* PROPERTY(min_level); + ModifierEffect const* PROPERTY(max_level); + + public: + building_type_effects_t(); + }; + + private: + IndexedMap PROPERTY(building_type_effects); + + /* GoodDefinition Effects */ + public: + struct good_effects_t { + friend struct GoodDefinitionManager; + + private: + ModifierEffect const* PROPERTY(artisan_goods_input); + ModifierEffect const* PROPERTY(artisan_goods_output); + ModifierEffect const* PROPERTY(artisan_goods_throughput); + ModifierEffect const* PROPERTY(factory_goods_input); + ModifierEffect const* PROPERTY(factory_goods_output); + ModifierEffect const* PROPERTY(factory_goods_throughput); + ModifierEffect const* PROPERTY(rgo_goods_output); + ModifierEffect const* PROPERTY(rgo_goods_throughput); + ModifierEffect const* PROPERTY(rgo_size); + + public: + good_effects_t(); + }; + + private: + IndexedMap PROPERTY(good_effects); + + /* UnitType Effects */ + public: + struct unit_type_effects_t { + friend struct UnitTypeManager; + + private: + ModifierEffect const* PROPERTY(attack); + ModifierEffect const* PROPERTY(defence); + ModifierEffect const* PROPERTY(default_organisation); + ModifierEffect const* PROPERTY(maximum_speed); + ModifierEffect const* PROPERTY(build_time); + ModifierEffect const* PROPERTY(supply_consumption); + + protected: + unit_type_effects_t(); + }; + + struct regiment_type_effects_t : unit_type_effects_t { + friend struct UnitTypeManager; + + private: + ModifierEffect const* PROPERTY(reconnaissance); + ModifierEffect const* PROPERTY(discipline); + ModifierEffect const* PROPERTY(support); + ModifierEffect const* PROPERTY(maneuver); + ModifierEffect const* PROPERTY(siege); + + public: + regiment_type_effects_t(); + }; + + struct ship_type_effects_t : unit_type_effects_t { + friend struct UnitTypeManager; + + private: + ModifierEffect const* PROPERTY(colonial_points); + ModifierEffect const* PROPERTY(supply_consumption_score); + ModifierEffect const* PROPERTY(hull); + ModifierEffect const* PROPERTY(gun_power); + ModifierEffect const* PROPERTY(fire_range); + ModifierEffect const* PROPERTY(evasion); + ModifierEffect const* PROPERTY(torpedo_attack); + + public: + ship_type_effects_t(); + }; + + private: + regiment_type_effects_t PROPERTY(army_base_effects); + IndexedMap PROPERTY(regiment_type_effects); + ship_type_effects_t PROPERTY(navy_base_effects); + IndexedMap PROPERTY(ship_type_effects); + + /* Rebel Effects */ + ModifierEffect const* PROPERTY(rebel_org_gain_all); + IndexedMap PROPERTY(rebel_org_gain_effects); + + /* Pop Effects */ + public: + struct strata_effects_t { + friend struct PopManager; + + private: + ModifierEffect const* PROPERTY(income_modifier); + ModifierEffect const* PROPERTY(vote); + ModifierEffect const* PROPERTY(life_needs); + ModifierEffect const* PROPERTY(everyday_needs); + ModifierEffect const* PROPERTY(luxury_needs); + + public: + strata_effects_t(); + }; + + private: + IndexedMap PROPERTY(strata_effects); + + /* Technology Effects */ + IndexedMap PROPERTY(research_bonus_effects); + + ModifierEffectCache(); + + public: + ModifierEffectCache(ModifierEffectCache&&) = default; + }; +} diff --git a/src/openvic-simulation/politics/Rebel.cpp b/src/openvic-simulation/politics/Rebel.cpp index ea443db..219a47b 100644 --- a/src/openvic-simulation/politics/Rebel.cpp +++ b/src/openvic-simulation/politics/Rebel.cpp @@ -187,14 +187,19 @@ bool RebelManager::generate_modifiers(ModifierManager& modifier_manager) const { ret &= modifier_manager.register_complex_modifier(identifier); ret &= modifier_manager.add_modifier_effect( - ModifierManager::get_flat_identifier(identifier, "all"), is_positive_good, PROPORTION_DECIMAL, COUNTRY, - "TECH_REBEL_ORG_GAIN" + modifier_manager.modifier_effect_cache.rebel_org_gain_all, ModifierManager::get_flat_identifier(identifier, "all"), + is_positive_good, PROPORTION_DECIMAL, COUNTRY, "TECH_REBEL_ORG_GAIN" ); + IndexedMap& rebel_org_gain_effects = + modifier_manager.modifier_effect_cache.rebel_org_gain_effects; + + rebel_org_gain_effects.set_keys(&get_rebel_types()); + for (RebelType const& rebel_type : get_rebel_types()) { ret &= modifier_manager.add_modifier_effect( - ModifierManager::get_flat_identifier(identifier, rebel_type.get_identifier()), is_positive_good, - PROPORTION_DECIMAL, COUNTRY, + rebel_org_gain_effects[rebel_type], ModifierManager::get_flat_identifier(identifier, rebel_type.get_identifier()), + is_positive_good, PROPORTION_DECIMAL, COUNTRY, StringUtils::append_string_views("$", rebel_type.get_identifier(), "_title$ $TECH_REBEL_ORG_GAIN$") ); } diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp index aeaeef5..54765d0 100644 --- a/src/openvic-simulation/pop/Pop.cpp +++ b/src/openvic-simulation/pop/Pop.cpp @@ -656,24 +656,31 @@ bool PopManager::generate_modifiers(ModifierManager& modifier_manager) const { using enum ModifierEffect::format_t; using enum ModifierEffect::target_t; + IndexedMap& strata_effects = + modifier_manager.modifier_effect_cache.strata_effects; + + strata_effects.set_keys(&get_stratas()); + bool ret = true; for (Strata const& strata : get_stratas()) { const auto strata_modifier = [&modifier_manager, &ret, &strata]( - std::string_view suffix, bool is_positive_good + ModifierEffect const*& effect_cache, std::string_view suffix, bool is_positive_good ) -> void { ret &= modifier_manager.add_modifier_effect( - StringUtils::append_string_views(strata.get_identifier(), suffix), is_positive_good, PROPORTION_DECIMAL, - COUNTRY + effect_cache, StringUtils::append_string_views(strata.get_identifier(), suffix), is_positive_good, + PROPORTION_DECIMAL, COUNTRY ); }; - strata_modifier("_income_modifier", true); // Has no effect in game - strata_modifier("_vote", true); + ModifierEffectCache::strata_effects_t& this_strata_effects = strata_effects[strata]; + + strata_modifier(this_strata_effects.income_modifier, "_income_modifier", true); // Has no effect in game + strata_modifier(this_strata_effects.vote, "_vote", true); - strata_modifier("_life_needs", false); - strata_modifier("_everyday_needs", false); - strata_modifier("_luxury_needs", false); + strata_modifier(this_strata_effects.life_needs, "_life_needs", false); + strata_modifier(this_strata_effects.everyday_needs, "_everyday_needs", false); + strata_modifier(this_strata_effects.luxury_needs, "_luxury_needs", false); } return ret; diff --git a/src/openvic-simulation/research/Technology.cpp b/src/openvic-simulation/research/Technology.cpp index 3284193..27bb4ca 100644 --- a/src/openvic-simulation/research/Technology.cpp +++ b/src/openvic-simulation/research/Technology.cpp @@ -199,13 +199,18 @@ bool TechnologyManager::generate_modifiers(ModifierManager& modifier_manager) co using enum ModifierEffect::format_t; using enum ModifierEffect::target_t; + IndexedMap& research_bonus_effects = + modifier_manager.modifier_effect_cache.research_bonus_effects; + + research_bonus_effects.set_keys(&get_technology_folders()); + bool ret = true; for (TechnologyFolder const& folder : get_technology_folders()) { const std::string modifier_identifier = StringUtils::append_string_views(folder.get_identifier(), "_research_bonus"); ret &= modifier_manager.add_modifier_effect( - modifier_identifier, true, PROPORTION_DECIMAL, COUNTRY, modifier_identifier + research_bonus_effects[folder], modifier_identifier, true, PROPORTION_DECIMAL, COUNTRY, modifier_identifier ); } -- cgit v1.2.3-56-ga3b1 From 18ab144ec4ecf1efca68a26bc79b9d54e28e54f8 Mon Sep 17 00:00:00 2001 From: hop311 Date: Fri, 18 Oct 2024 23:53:32 +0100 Subject: Move ModifierManager to its own files --- src/openvic-simulation/DefinitionManager.hpp | 2 +- src/openvic-simulation/country/CountryInstance.cpp | 2 + src/openvic-simulation/country/CountryInstance.hpp | 2 + src/openvic-simulation/economy/BuildingType.cpp | 2 + src/openvic-simulation/economy/GoodDefinition.cpp | 2 +- src/openvic-simulation/map/Crime.cpp | 2 + src/openvic-simulation/map/MapDefinition.cpp | 1 + src/openvic-simulation/map/ProvinceInstance.cpp | 1 + src/openvic-simulation/map/ProvinceInstance.hpp | 1 + src/openvic-simulation/map/TerrainType.cpp | 1 + src/openvic-simulation/military/LeaderTrait.cpp | 2 + src/openvic-simulation/military/UnitType.cpp | 1 + src/openvic-simulation/modifier/Modifier.cpp | 706 --------------------- src/openvic-simulation/modifier/Modifier.hpp | 126 +--- .../modifier/ModifierManager.cpp | 692 ++++++++++++++++++++ .../modifier/ModifierManager.hpp | 127 ++++ src/openvic-simulation/modifier/ModifierValue.cpp | 9 + .../modifier/StaticModifierCache.cpp | 2 +- src/openvic-simulation/politics/Issue.cpp | 2 + src/openvic-simulation/politics/NationalFocus.cpp | 1 + src/openvic-simulation/politics/NationalValue.cpp | 2 + src/openvic-simulation/politics/Rebel.cpp | 2 +- src/openvic-simulation/pop/Pop.cpp | 1 + src/openvic-simulation/research/Invention.cpp | 8 +- src/openvic-simulation/research/Technology.cpp | 2 + 25 files changed, 864 insertions(+), 835 deletions(-) create mode 100644 src/openvic-simulation/modifier/ModifierManager.cpp create mode 100644 src/openvic-simulation/modifier/ModifierManager.hpp (limited to 'src/openvic-simulation/pop/Pop.cpp') diff --git a/src/openvic-simulation/DefinitionManager.hpp b/src/openvic-simulation/DefinitionManager.hpp index 887cc1b..b5df507 100644 --- a/src/openvic-simulation/DefinitionManager.hpp +++ b/src/openvic-simulation/DefinitionManager.hpp @@ -14,7 +14,7 @@ #include "openvic-simulation/misc/Event.hpp" #include "openvic-simulation/misc/SongChance.hpp" #include "openvic-simulation/misc/SoundEffect.hpp" -#include "openvic-simulation/modifier/Modifier.hpp" +#include "openvic-simulation/modifier/ModifierManager.hpp" #include "openvic-simulation/politics/PoliticsManager.hpp" #include "openvic-simulation/pop/Pop.hpp" #include "openvic-simulation/research/ResearchManager.hpp" diff --git a/src/openvic-simulation/country/CountryInstance.cpp b/src/openvic-simulation/country/CountryInstance.cpp index f04dfc6..aceae11 100644 --- a/src/openvic-simulation/country/CountryInstance.cpp +++ b/src/openvic-simulation/country/CountryInstance.cpp @@ -5,6 +5,8 @@ #include "openvic-simulation/map/Crime.hpp" #include "openvic-simulation/map/MapInstance.hpp" #include "openvic-simulation/misc/Define.hpp" +#include "openvic-simulation/modifier/ModifierEffectCache.hpp" +#include "openvic-simulation/modifier/StaticModifierCache.hpp" #include "openvic-simulation/politics/Ideology.hpp" #include "openvic-simulation/research/Invention.hpp" #include "openvic-simulation/research/Technology.hpp" diff --git a/src/openvic-simulation/country/CountryInstance.hpp b/src/openvic-simulation/country/CountryInstance.hpp index 5e42f1d..ea30c0d 100644 --- a/src/openvic-simulation/country/CountryInstance.hpp +++ b/src/openvic-simulation/country/CountryInstance.hpp @@ -35,6 +35,8 @@ namespace OpenVic { struct CountryHistoryEntry; struct MapInstance; struct DefineManager; + struct ModifierEffectCache; + struct StaticModifierCache; /* Representation of a country's mutable attributes, with a CountryDefinition that is unique at any single time * but can be swapped with other CountryInstance's CountryDefinition when switching tags. */ diff --git a/src/openvic-simulation/economy/BuildingType.cpp b/src/openvic-simulation/economy/BuildingType.cpp index 3733a5f..278cde4 100644 --- a/src/openvic-simulation/economy/BuildingType.cpp +++ b/src/openvic-simulation/economy/BuildingType.cpp @@ -1,5 +1,7 @@ #include "BuildingType.hpp" +#include "openvic-simulation/modifier/ModifierManager.hpp" + using namespace OpenVic; using namespace OpenVic::NodeTools; diff --git a/src/openvic-simulation/economy/GoodDefinition.cpp b/src/openvic-simulation/economy/GoodDefinition.cpp index 25281bb..f8bd9b7 100644 --- a/src/openvic-simulation/economy/GoodDefinition.cpp +++ b/src/openvic-simulation/economy/GoodDefinition.cpp @@ -1,6 +1,6 @@ #include "GoodDefinition.hpp" -#include "openvic-simulation/modifier/Modifier.hpp" +#include "openvic-simulation/modifier/ModifierManager.hpp" using namespace OpenVic; using namespace OpenVic::NodeTools; diff --git a/src/openvic-simulation/map/Crime.cpp b/src/openvic-simulation/map/Crime.cpp index fb521ad..532be9d 100644 --- a/src/openvic-simulation/map/Crime.cpp +++ b/src/openvic-simulation/map/Crime.cpp @@ -1,5 +1,7 @@ #include "Crime.hpp" +#include "openvic-simulation/modifier/ModifierManager.hpp" + using namespace OpenVic; using namespace OpenVic::NodeTools; diff --git a/src/openvic-simulation/map/MapDefinition.cpp b/src/openvic-simulation/map/MapDefinition.cpp index 828a679..50fba7d 100644 --- a/src/openvic-simulation/map/MapDefinition.cpp +++ b/src/openvic-simulation/map/MapDefinition.cpp @@ -3,6 +3,7 @@ #include #include +#include "openvic-simulation/modifier/ModifierManager.hpp" #include "openvic-simulation/types/Colour.hpp" #include "openvic-simulation/types/OrderedContainers.hpp" #include "openvic-simulation/types/Vector.hpp" diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp index 949a2a3..57a33a4 100644 --- a/src/openvic-simulation/map/ProvinceInstance.cpp +++ b/src/openvic-simulation/map/ProvinceInstance.cpp @@ -8,6 +8,7 @@ #include "openvic-simulation/map/TerrainType.hpp" #include "openvic-simulation/military/UnitInstanceGroup.hpp" #include "openvic-simulation/misc/Define.hpp" +#include "openvic-simulation/modifier/StaticModifierCache.hpp" #include "openvic-simulation/politics/Ideology.hpp" using namespace OpenVic; diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp index 91e8ee1..e7c0326 100644 --- a/src/openvic-simulation/map/ProvinceInstance.hpp +++ b/src/openvic-simulation/map/ProvinceInstance.hpp @@ -22,6 +22,7 @@ namespace OpenVic { struct Ideology; struct Culture; struct Religion; + struct StaticModifierCache; struct BuildingTypeManager; struct ProvinceHistoryEntry; struct IssueManager; diff --git a/src/openvic-simulation/map/TerrainType.cpp b/src/openvic-simulation/map/TerrainType.cpp index b4cc430..2f8423d 100644 --- a/src/openvic-simulation/map/TerrainType.cpp +++ b/src/openvic-simulation/map/TerrainType.cpp @@ -1,5 +1,6 @@ #include "TerrainType.hpp" +#include "openvic-simulation/modifier/ModifierManager.hpp" #include "openvic-simulation/types/Colour.hpp" using namespace OpenVic; diff --git a/src/openvic-simulation/military/LeaderTrait.cpp b/src/openvic-simulation/military/LeaderTrait.cpp index da7331a..4378a67 100644 --- a/src/openvic-simulation/military/LeaderTrait.cpp +++ b/src/openvic-simulation/military/LeaderTrait.cpp @@ -1,5 +1,7 @@ #include "LeaderTrait.hpp" +#include "openvic-simulation/modifier/ModifierManager.hpp" + using namespace OpenVic; using namespace OpenVic::NodeTools; diff --git a/src/openvic-simulation/military/UnitType.cpp b/src/openvic-simulation/military/UnitType.cpp index 004f766..815025a 100644 --- a/src/openvic-simulation/military/UnitType.cpp +++ b/src/openvic-simulation/military/UnitType.cpp @@ -2,6 +2,7 @@ #include "openvic-simulation/country/CountryInstance.hpp" #include "openvic-simulation/map/TerrainType.hpp" +#include "openvic-simulation/modifier/ModifierManager.hpp" using namespace OpenVic; using namespace OpenVic::NodeTools; diff --git a/src/openvic-simulation/modifier/Modifier.cpp b/src/openvic-simulation/modifier/Modifier.cpp index 4e10c76..962d2d4 100644 --- a/src/openvic-simulation/modifier/Modifier.cpp +++ b/src/openvic-simulation/modifier/Modifier.cpp @@ -1,15 +1,6 @@ #include "Modifier.hpp" -#include - -#include - -#include - -#include "openvic-simulation/types/OrderedContainers.hpp" - using namespace OpenVic; -using namespace OpenVic::NodeTools; Modifier::Modifier(std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type) : HasIdentifier { new_identifier }, ModifierValue { std::move(new_values) }, type { new_type } {} @@ -29,700 +20,3 @@ bool TriggeredModifier::parse_scripts(DefinitionManager const& definition_manage ModifierInstance::ModifierInstance(Modifier const& new_modifier, Date new_expiry_date) : modifier { &new_modifier }, expiry_date { new_expiry_date } {} - -bool ModifierManager::add_modifier_effect( - ModifierEffect const*& effect_cache, std::string_view identifier, bool positive_good, ModifierEffect::format_t format, - ModifierEffect::target_t targets, std::string_view localisation_key -) { - if (identifier.empty()) { - Logger::error("Invalid modifier effect identifier - empty!"); - return false; - } - - if (effect_cache != nullptr) { - Logger::error( - "Cache variable for modifier effect \"", identifier, "\" is already filled with modifier effect \"", - effect_cache->get_identifier(), "\"" - ); - return false; - } - - const bool ret = modifier_effects.add_item({ std::move(identifier), positive_good, format, targets, localisation_key }); - - if (ret) { - effect_cache = &modifier_effects.get_items().back(); - } - - return ret; -} - -bool ModifierManager::setup_modifier_effects() { - bool ret = true; - - using enum ModifierEffect::format_t; - using enum ModifierEffect::target_t; - - /* Tech/inventions only */ - ret &= add_modifier_effect( - modifier_effect_cache.cb_creation_speed, "cb_creation_speed", true, PROPORTION_DECIMAL, COUNTRY, "CB_MANUFACTURE_TECH" - ); - ret &= add_modifier_effect(modifier_effect_cache.combat_width, "combat_width", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - modifier_effect_cache.plurality, "plurality", true, PERCENTAGE_DECIMAL, COUNTRY, "TECH_PLURALITY" - ); - ret &= add_modifier_effect( - modifier_effect_cache.pop_growth, "pop_growth", true, PROPORTION_DECIMAL, COUNTRY, "TECH_POP_GROWTH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.regular_experience_level, "regular_experience_level", true, RAW_DECIMAL, COUNTRY, - "REGULAR_EXP_TECH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.reinforce_rate, "reinforce_rate", true, PROPORTION_DECIMAL, COUNTRY, "REINFORCE_TECH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.separatism, "seperatism", // paradox typo - false, PROPORTION_DECIMAL, COUNTRY, "SEPARATISM_TECH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.shared_prestige, "shared_prestige", true, RAW_DECIMAL, COUNTRY, "SHARED_PRESTIGE_TECH" - ); - ret &= add_modifier_effect(modifier_effect_cache.tax_eff, "tax_eff", true, PERCENTAGE_DECIMAL, COUNTRY, "TECH_TAX_EFF"); - - /* Country Modifier Effects */ - ret &= add_modifier_effect( - modifier_effect_cache.administrative_efficiency, "administrative_efficiency", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.administrative_efficiency_modifier, "administrative_efficiency_modifier", true, - PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("administrative_efficiency") - ); - ret &= add_modifier_effect(modifier_effect_cache.artisan_input, "artisan_input", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect(modifier_effect_cache.artisan_output, "artisan_output", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - modifier_effect_cache.artisan_throughput, "artisan_throughput", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect(modifier_effect_cache.badboy, "badboy", false, RAW_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - modifier_effect_cache.cb_generation_speed_modifier, "cb_generation_speed_modifier", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.civilization_progress_modifier, "civilization_progress_modifier", true, PROPORTION_DECIMAL, - COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("civilization_progress") - ); - ret &= add_modifier_effect( - modifier_effect_cache.colonial_life_rating, "colonial_life_rating", false, INT, COUNTRY, "COLONIAL_LIFE_TECH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.colonial_migration, "colonial_migration", true, PROPORTION_DECIMAL, COUNTRY, - "COLONIAL_MIGRATION_TECH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.colonial_points, "colonial_points", true, INT, COUNTRY, "COLONIAL_POINTS_TECH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.colonial_prestige, "colonial_prestige", true, PROPORTION_DECIMAL, COUNTRY, - "COLONIAL_PRESTIGE_MODIFIER_TECH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.core_pop_consciousness_modifier, "core_pop_consciousness_modifier", false, RAW_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.core_pop_militancy_modifier, "core_pop_militancy_modifier", false, RAW_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect(modifier_effect_cache.dig_in_cap, "dig_in_cap", true, INT, COUNTRY, "DIGIN_FROM_TECH"); - ret &= add_modifier_effect( - modifier_effect_cache.diplomatic_points, "diplomatic_points", true, PROPORTION_DECIMAL, COUNTRY, - "DIPLOMATIC_POINTS_TECH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.diplomatic_points_modifier, "diplomatic_points_modifier", true, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("diplopoints_gain") - ); - ret &= add_modifier_effect( - modifier_effect_cache.education_efficiency, "education_efficiency", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.education_efficiency_modifier, "education_efficiency_modifier", true, PROPORTION_DECIMAL, - COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("education_efficiency") - ); - ret &= add_modifier_effect(modifier_effect_cache.factory_cost, "factory_cost", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect(modifier_effect_cache.factory_input, "factory_input", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - modifier_effect_cache.factory_maintenance, "factory_maintenance", false, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect(modifier_effect_cache.factory_output, "factory_output", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - modifier_effect_cache.factory_owner_cost, "factory_owner_cost", false, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.factory_throughput, "factory_throughput", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.global_assimilation_rate, "global_assimilation_rate", true, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("assimilation_rate") - ); - ret &= add_modifier_effect( - modifier_effect_cache.global_immigrant_attract, "global_immigrant_attract", true, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("immigant_attract") - ); - ret &= add_modifier_effect( - modifier_effect_cache.global_pop_consciousness_modifier, "global_pop_consciousness_modifier", false, RAW_DECIMAL, - COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.global_pop_militancy_modifier, "global_pop_militancy_modifier", false, RAW_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.global_population_growth, "global_population_growth", true, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("population_growth") - ); - ret &= add_modifier_effect(modifier_effect_cache.goods_demand, "goods_demand", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect(modifier_effect_cache.import_cost, "import_cost", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - modifier_effect_cache.increase_research, "increase_research", true, PROPORTION_DECIMAL, COUNTRY, "INC_RES_TECH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.influence, "influence", true, PROPORTION_DECIMAL, COUNTRY, "TECH_GP_INFLUENCE" - ); - ret &= add_modifier_effect( - modifier_effect_cache.influence_modifier, "influence_modifier", true, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("greatpower_influence_gain") - ); - ret &= add_modifier_effect( - modifier_effect_cache.issue_change_speed, "issue_change_speed", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.land_attack_modifier, "land_attack_modifier", true, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("land_attack") - ); - ret &= add_modifier_effect( - modifier_effect_cache.land_attrition, "land_attrition", false, PROPORTION_DECIMAL, COUNTRY, "LAND_ATTRITION_TECH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.land_defense_modifier, "land_defense_modifier", true, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("land_defense") - ); - ret &= add_modifier_effect( - modifier_effect_cache.land_organisation, "land_organisation", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.land_unit_start_experience, "land_unit_start_experience", true, RAW_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect(modifier_effect_cache.leadership, "leadership", true, RAW_DECIMAL, COUNTRY, "LEADERSHIP"); - ret &= add_modifier_effect( - modifier_effect_cache.leadership_modifier, "leadership_modifier", true, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("global_leadership_modifier") - ); - ret &= add_modifier_effect( - modifier_effect_cache.literacy_con_impact, "literacy_con_impact", false, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect(modifier_effect_cache.loan_interest, "loan_interest", false, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - modifier_effect_cache.max_loan_modifier, "max_loan_modifier", true, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("max_loan_amount") - ); - ret &= add_modifier_effect( - modifier_effect_cache.max_military_spending, "max_military_spending", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.max_national_focus, "max_national_focus", true, INT, COUNTRY, "TECH_MAX_FOCUS" - ); - ret &= add_modifier_effect( - modifier_effect_cache.max_social_spending, "max_social_spending", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect(modifier_effect_cache.max_tariff, "max_tariff", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect(modifier_effect_cache.max_tax, "max_tax", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - modifier_effect_cache.max_war_exhaustion, "max_war_exhaustion", true, PERCENTAGE_DECIMAL, COUNTRY, "MAX_WAR_EXHAUSTION" - ); - ret &= add_modifier_effect( - modifier_effect_cache.military_tactics, "military_tactics", true, PROPORTION_DECIMAL, COUNTRY, "MIL_TACTICS_TECH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.min_military_spending, "min_military_spending", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.min_social_spending, "min_social_spending", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect(modifier_effect_cache.min_tariff, "min_tariff", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect(modifier_effect_cache.min_tax, "min_tax", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - modifier_effect_cache.minimum_wage, "minimum_wage", true, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("minimun_wage") - ); - ret &= add_modifier_effect( - modifier_effect_cache.mobilisation_economy_impact, "mobilisation_economy_impact", false, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.mobilisation_size, "mobilisation_size", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.mobilization_impact, "mobilization_impact", false, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.naval_attack_modifier, "naval_attack_modifier", true, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("naval_attack") - ); - ret &= add_modifier_effect( - modifier_effect_cache.naval_attrition, "naval_attrition", false, PROPORTION_DECIMAL, COUNTRY, "NAVAL_ATTRITION_TECH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.naval_defense_modifier, "naval_defense_modifier", true, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("naval_defense") - ); - ret &= add_modifier_effect( - modifier_effect_cache.naval_organisation, "naval_organisation", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.naval_unit_start_experience, "naval_unit_start_experience", true, RAW_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.non_accepted_pop_consciousness_modifier, "non_accepted_pop_consciousness_modifier", false, - RAW_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.non_accepted_pop_militancy_modifier, "non_accepted_pop_militancy_modifier", false, RAW_DECIMAL, - COUNTRY - ); - ret &= add_modifier_effect(modifier_effect_cache.org_regain, "org_regain", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect(modifier_effect_cache.pension_level, "pension_level", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - modifier_effect_cache.permanent_prestige, "permanent_prestige", true, RAW_DECIMAL, COUNTRY, "PERMANENT_PRESTIGE_TECH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.political_reform_desire, "political_reform_desire", false, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.poor_savings_modifier, "poor_savings_modifier", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect(modifier_effect_cache.prestige, "prestige", true, RAW_DECIMAL, COUNTRY); - ret &= add_modifier_effect(modifier_effect_cache.reinforce_speed, "reinforce_speed", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect(modifier_effect_cache.research_points, "research_points", true, RAW_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - modifier_effect_cache.research_points_modifier, "research_points_modifier", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.research_points_on_conquer, "research_points_on_conquer", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect(modifier_effect_cache.rgo_output, "rgo_output", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect(modifier_effect_cache.rgo_throughput, "rgo_throughput", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - modifier_effect_cache.ruling_party_support, "ruling_party_support", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.self_unciv_economic_modifier, "self_unciv_economic_modifier", false, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("self_unciv_economic") - ); - ret &= add_modifier_effect( - modifier_effect_cache.self_unciv_military_modifier, "self_unciv_military_modifier", false, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("self_unciv_military") - ); - ret &= add_modifier_effect( - modifier_effect_cache.social_reform_desire, "social_reform_desire", false, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.soldier_to_pop_loss, "soldier_to_pop_loss", true, PROPORTION_DECIMAL, COUNTRY, - "SOLDIER_TO_POP_LOSS_TECH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.supply_consumption, "supply_consumption", false, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.supply_range, "supply_range", true, PROPORTION_DECIMAL, COUNTRY, "SUPPLY_RANGE_TECH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.suppression_points_modifier, "suppression_points_modifier", true, PROPORTION_DECIMAL, COUNTRY, - "SUPPRESSION_TECH" - ); - ret &= add_modifier_effect( - modifier_effect_cache.tariff_efficiency_modifier, "tariff_efficiency_modifier", true, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("tariff_efficiency") - ); - ret &= add_modifier_effect(modifier_effect_cache.tax_efficiency, "tax_efficiency", true, PROPORTION_DECIMAL, COUNTRY); - ret &= add_modifier_effect( - modifier_effect_cache.unemployment_benefit, "unemployment_benefit", true, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.unciv_economic_modifier, "unciv_economic_modifier", false, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("unciv_economic") - ); - ret &= add_modifier_effect( - modifier_effect_cache.unciv_military_modifier, "unciv_military_modifier", false, PROPORTION_DECIMAL, COUNTRY, - ModifierEffect::make_default_modifier_effect_localisation_key("unciv_military") - ); - ret &= add_modifier_effect( - modifier_effect_cache.unit_recruitment_time, "unit_recruitment_time", false, PROPORTION_DECIMAL, COUNTRY - ); - ret &= add_modifier_effect( - modifier_effect_cache.war_exhaustion, "war_exhaustion", false, PROPORTION_DECIMAL, COUNTRY, "WAR_EXHAUST_BATTLES" - ); - - /* Province Modifier Effects */ - ret &= add_modifier_effect( - modifier_effect_cache.assimilation_rate, "assimilation_rate", true, PROPORTION_DECIMAL, PROVINCE - ); - ret &= add_modifier_effect( - modifier_effect_cache.boost_strongest_party, "boost_strongest_party", false, PROPORTION_DECIMAL, PROVINCE - ); - ret &= add_modifier_effect( - modifier_effect_cache.farm_rgo_eff, "farm_rgo_eff", true, PROPORTION_DECIMAL, PROVINCE, "TECH_FARM_OUTPUT" - ); - ret &= add_modifier_effect( - modifier_effect_cache.farm_rgo_size, "farm_rgo_size", true, PROPORTION_DECIMAL, PROVINCE, - ModifierEffect::make_default_modifier_effect_localisation_key("farm_size") - ); - ret &= add_modifier_effect( - modifier_effect_cache.immigrant_attract, "immigrant_attract", true, PROPORTION_DECIMAL, PROVINCE, - ModifierEffect::make_default_modifier_effect_localisation_key("immigant_attract") - ); - ret &= add_modifier_effect( - modifier_effect_cache.immigrant_push, "immigrant_push", false, PROPORTION_DECIMAL, PROVINCE, - ModifierEffect::make_default_modifier_effect_localisation_key("immigant_push") - ); - ret &= add_modifier_effect(modifier_effect_cache.life_rating, "life_rating", true, PROPORTION_DECIMAL, PROVINCE); - ret &= add_modifier_effect( - modifier_effect_cache.local_artisan_input, "local_artisan_input", false, PROPORTION_DECIMAL, PROVINCE, - ModifierEffect::make_default_modifier_effect_localisation_key("artisan_input") - ); - ret &= add_modifier_effect( - modifier_effect_cache.local_artisan_output, "local_artisan_output", true, PROPORTION_DECIMAL, PROVINCE, - ModifierEffect::make_default_modifier_effect_localisation_key("artisan_output") - ); - ret &= add_modifier_effect( - modifier_effect_cache.local_artisan_throughput, "local_artisan_throughput", true, PROPORTION_DECIMAL, PROVINCE, - ModifierEffect::make_default_modifier_effect_localisation_key("artisan_throughput") - ); - ret &= add_modifier_effect( - modifier_effect_cache.local_factory_input, "local_factory_input", false, PROPORTION_DECIMAL, PROVINCE, - ModifierEffect::make_default_modifier_effect_localisation_key("factory_input") - ); - ret &= add_modifier_effect( - modifier_effect_cache.local_factory_output, "local_factory_output", true, PROPORTION_DECIMAL, PROVINCE, - ModifierEffect::make_default_modifier_effect_localisation_key("factory_output") - ); - ret &= add_modifier_effect( - modifier_effect_cache.local_factory_throughput, "local_factory_throughput", true, PROPORTION_DECIMAL, PROVINCE, - ModifierEffect::make_default_modifier_effect_localisation_key("factory_throughput") - ); - ret &= add_modifier_effect(modifier_effect_cache.local_repair, "local_repair", true, PROPORTION_DECIMAL, PROVINCE); - ret &= add_modifier_effect( - modifier_effect_cache.local_rgo_output, "local_rgo_output", true, PROPORTION_DECIMAL, PROVINCE, - ModifierEffect::make_default_modifier_effect_localisation_key("rgo_output") - ); - ret &= add_modifier_effect( - modifier_effect_cache.local_rgo_throughput, "local_rgo_throughput", true, PROPORTION_DECIMAL, PROVINCE, - ModifierEffect::make_default_modifier_effect_localisation_key("rgo_throughput") - ); - ret &= add_modifier_effect( - modifier_effect_cache.local_ruling_party_support, "local_ruling_party_support", true, PROPORTION_DECIMAL, PROVINCE, - ModifierEffect::make_default_modifier_effect_localisation_key("ruling_party_support") - ); - ret &= add_modifier_effect( - modifier_effect_cache.local_ship_build, "local_ship_build", false, PROPORTION_DECIMAL, PROVINCE - ); - ret &= add_modifier_effect(modifier_effect_cache.max_attrition, "max_attrition", false, RAW_DECIMAL, PROVINCE); - ret &= add_modifier_effect( - modifier_effect_cache.mine_rgo_eff, "mine_rgo_eff", true, PROPORTION_DECIMAL, PROVINCE, "TECH_MINE_OUTPUT" - ); - ret &= add_modifier_effect( - modifier_effect_cache.mine_rgo_size, "mine_rgo_size", true, PROPORTION_DECIMAL, PROVINCE, - ModifierEffect::make_default_modifier_effect_localisation_key("mine_size") - ); - ret &= add_modifier_effect(modifier_effect_cache.movement_cost, "movement_cost", false, PROPORTION_DECIMAL, PROVINCE); - ret &= add_modifier_effect( - modifier_effect_cache.number_of_voters, "number_of_voters", false, PROPORTION_DECIMAL, PROVINCE - ); - ret &= add_modifier_effect( - modifier_effect_cache.pop_consciousness_modifier, "pop_consciousness_modifier", false, RAW_DECIMAL, PROVINCE - ); - ret &= add_modifier_effect( - modifier_effect_cache.pop_militancy_modifier, "pop_militancy_modifier", false, RAW_DECIMAL, PROVINCE - ); - ret &= add_modifier_effect( - modifier_effect_cache.population_growth, "population_growth", true, PROPORTION_DECIMAL, PROVINCE - ); - ret &= add_modifier_effect(modifier_effect_cache.supply_limit, "supply_limit", true, RAW_DECIMAL, PROVINCE); - - /* Military Modifier Effects */ - ret &= add_modifier_effect(modifier_effect_cache.attack, "attack", true, INT, UNIT, "TRAIT_ATTACK"); - ret &= add_modifier_effect(modifier_effect_cache.attrition, "attrition", false, RAW_DECIMAL, UNIT, "ATTRITION"); - ret &= add_modifier_effect(modifier_effect_cache.defence, "defence", true, INT, UNIT, "TRAIT_DEFEND"); - ret &= add_modifier_effect( - modifier_effect_cache.experience, "experience", true, PROPORTION_DECIMAL, UNIT, "TRAIT_EXPERIENCE" - ); - ret &= add_modifier_effect(modifier_effect_cache.morale, "morale", true, PROPORTION_DECIMAL, UNIT, "TRAIT_MORALE"); - ret &= add_modifier_effect( - modifier_effect_cache.organisation, "organisation", true, PROPORTION_DECIMAL, UNIT, "TRAIT_ORGANISATION" - ); - ret &= add_modifier_effect( - modifier_effect_cache.reconnaissance, "reconnaissance", true, PROPORTION_DECIMAL, UNIT, "TRAIT_RECONAISSANCE" - ); - ret &= add_modifier_effect(modifier_effect_cache.reliability, "reliability", true, RAW_DECIMAL, UNIT, "TRAIT_RELIABILITY"); - ret &= add_modifier_effect(modifier_effect_cache.speed, "speed", true, PROPORTION_DECIMAL, UNIT, "TRAIT_SPEED"); - - return ret; -} - -bool ModifierManager::register_complex_modifier(std::string_view identifier) { - if (complex_modifiers.emplace(identifier).second) { - return true; - } else { - Logger::error("Duplicate complex modifier: ", identifier); - return false; - } -} - -std::string ModifierManager::get_flat_identifier( - std::string_view complex_modifier_identifier, std::string_view variant_identifier -) { - return StringUtils::append_string_views(complex_modifier_identifier, " ", variant_identifier); -} - -bool ModifierManager::add_event_modifier(std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon) { - if (identifier.empty()) { - Logger::error("Invalid event modifier effect identifier - empty!"); - return false; - } - - return event_modifiers.add_item( - { identifier, std::move(values), Modifier::modifier_type_t::EVENT, icon }, duplicate_warning_callback - ); -} - -bool ModifierManager::load_event_modifiers(ast::NodeCPtr root) { - const bool ret = expect_dictionary_reserve_length( - event_modifiers, - [this](std::string_view key, ast::NodeCPtr value) -> bool { - ModifierValue modifier_value; - IconModifier::icon_t icon = 0; - bool ret = expect_modifier_value_and_keys( - move_variable_callback(modifier_value), - "icon", ZERO_OR_ONE, expect_uint(assign_variable_callback(icon)) - )(value); - ret &= add_event_modifier(key, std::move(modifier_value), icon); - return ret; - } - )(root); - - lock_event_modifiers(); - - return ret; -} - -bool ModifierManager::add_static_modifier(std::string_view identifier, ModifierValue&& values) { - if (identifier.empty()) { - Logger::error("Invalid static modifier effect identifier - empty!"); - return false; - } - - return static_modifiers.add_item( - { identifier, std::move(values), Modifier::modifier_type_t::STATIC }, duplicate_warning_callback - ); -} - -bool ModifierManager::load_static_modifiers(ast::NodeCPtr root) { - bool ret = expect_dictionary_reserve_length( - static_modifiers, - [this](std::string_view key, ast::NodeCPtr value) -> bool { - ModifierValue modifier_value; - bool ret = expect_modifier_value(move_variable_callback(modifier_value))(value); - ret &= add_static_modifier(key, std::move(modifier_value)); - return ret; - } - )(root); - - lock_static_modifiers(); - - ret &= static_modifier_cache.load_static_modifiers(*this); - - return ret; -} - -bool ModifierManager::add_triggered_modifier( - std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon, ConditionScript&& trigger -) { - if (identifier.empty()) { - Logger::error("Invalid triggered modifier effect identifier - empty!"); - return false; - } - - return triggered_modifiers.add_item( - { identifier, std::move(values), Modifier::modifier_type_t::TRIGGERED, icon, std::move(trigger) }, - duplicate_warning_callback - ); -} - -bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) { - const bool ret = expect_dictionary_reserve_length( - triggered_modifiers, - [this](std::string_view key, ast::NodeCPtr value) -> bool { - ModifierValue modifier_value; - IconModifier::icon_t icon = 0; - ConditionScript trigger { scope_t::COUNTRY, scope_t::COUNTRY, scope_t::NO_SCOPE }; - - bool ret = expect_modifier_value_and_keys( - move_variable_callback(modifier_value), - "icon", ZERO_OR_ONE, expect_uint(assign_variable_callback(icon)), - "trigger", ONE_EXACTLY, trigger.expect_script() - )(value); - ret &= add_triggered_modifier(key, std::move(modifier_value), icon, std::move(trigger)); - return ret; - } - )(root); - - lock_triggered_modifiers(); - - return ret; -} - -bool ModifierManager::parse_scripts(DefinitionManager const& definition_manager) { - bool ret = true; - - for (TriggeredModifier& modifier : triggered_modifiers.get_items()) { - ret &= modifier.parse_scripts(definition_manager); - } - - return ret; -} - -key_value_callback_t ModifierManager::_modifier_effect_callback( - ModifierValue& modifier, key_value_callback_t default_callback, ModifierEffectValidator auto effect_validator -) const { - const auto add_modifier_cb = [this, &modifier, effect_validator]( - ModifierEffect const* effect, ast::NodeCPtr value - ) -> bool { - if (effect_validator(*effect)) { - static const case_insensitive_string_set_t no_effect_modifiers { - "boost_strongest_party", "poor_savings_modifier", "local_artisan_input", "local_artisan_throughput", - "local_artisan_output", "artisan_input", "artisan_throughput", "artisan_output", - "import_cost", "unciv_economic_modifier", "unciv_military_modifier" - }; - if (no_effect_modifiers.contains(effect->get_identifier())) { - Logger::warning("This modifier does nothing: ", effect->get_identifier()); - } - return expect_fixed_point(map_callback(modifier.values, effect))(value); - } else { - Logger::error("Failed to validate modifier effect: ", effect->get_identifier()); - return false; - } - }; - - const auto add_flattened_modifier_cb = [this, add_modifier_cb]( - std::string_view prefix, std::string_view key, ast::NodeCPtr value - ) -> bool { - const std::string flat_identifier = get_flat_identifier(prefix, key); - ModifierEffect const* effect = get_modifier_effect_by_identifier(flat_identifier); - if (effect != nullptr) { - return add_modifier_cb(effect, value); - } else { - Logger::error("Could not find flattened modifier: ", flat_identifier); - return false; - } - }; - - return [this, default_callback, add_modifier_cb, add_flattened_modifier_cb]( - std::string_view key, ast::NodeCPtr value - ) -> bool { - ModifierEffect const* effect = get_modifier_effect_by_identifier(key); - if (effect != nullptr && dryad::node_has_kind(value)) { - return add_modifier_cb(effect, value); - } else if (complex_modifiers.contains(key) && dryad::node_has_kind(value)) { - if (key == "rebel_org_gain") { //because of course there's a special one - std::string_view faction_identifier; - ast::NodeCPtr value_node = nullptr; - bool ret = expect_dictionary_keys( - "faction", ONE_EXACTLY, expect_identifier(assign_variable_callback(faction_identifier)), - "value", ONE_EXACTLY, assign_variable_callback(value_node) - )(value); - ret &= add_flattened_modifier_cb(key, faction_identifier, value_node); - return ret; - } else { - return expect_dictionary(std::bind_front(add_flattened_modifier_cb, key))(value); - } - } else if (key == "war_exhaustion_effect") { - Logger::warning("war_exhaustion_effect does nothing (vanilla issues have it)."); - return true; - } else { - return default_callback(key, value); - } - }; -} - -node_callback_t ModifierManager::expect_validated_modifier_value_and_default( - callback_t modifier_callback, key_value_callback_t default_callback, - ModifierEffectValidator auto effect_validator -) const { - return [this, modifier_callback, default_callback, effect_validator](ast::NodeCPtr root) -> bool { - ModifierValue modifier; - bool ret = expect_dictionary_reserve_length( - modifier.values, - _modifier_effect_callback(modifier, default_callback, effect_validator) - )(root); - ret &= modifier_callback(std::move(modifier)); - return ret; - }; -} - -node_callback_t ModifierManager::expect_validated_modifier_value( - callback_t modifier_callback, ModifierEffectValidator auto effect_validator -) const { - return expect_validated_modifier_value_and_default(modifier_callback, key_value_invalid_callback, effect_validator); -} - -node_callback_t ModifierManager::expect_modifier_value_and_default( - callback_t modifier_callback, key_value_callback_t default_callback -) const { - return expect_validated_modifier_value_and_default(modifier_callback, default_callback, [](ModifierEffect const&) -> bool { - return true; - }); -} - -node_callback_t ModifierManager::expect_modifier_value(callback_t modifier_callback) const { - return expect_modifier_value_and_default(modifier_callback, key_value_invalid_callback); -} - -node_callback_t ModifierManager::expect_whitelisted_modifier_value_and_default( - callback_t modifier_callback, string_set_t const& whitelist, key_value_callback_t default_callback -) const { - return expect_validated_modifier_value_and_default( - modifier_callback, default_callback, - [&whitelist](ModifierEffect const& effect) -> bool { - return whitelist.contains(effect.get_identifier()); - } - ); -} - -node_callback_t ModifierManager::expect_whitelisted_modifier_value( - callback_t modifier_callback, string_set_t const& whitelist -) const { - return expect_whitelisted_modifier_value_and_default(modifier_callback, whitelist, key_value_invalid_callback); -} - -node_callback_t ModifierManager::expect_modifier_value_and_key_map_and_default( - callback_t modifier_callback, key_value_callback_t default_callback, key_map_t&& key_map -) const { - return [this, modifier_callback, default_callback, key_map = std::move(key_map)](ast::NodeCPtr node) mutable -> bool { - bool ret = expect_modifier_value_and_default( - modifier_callback, - dictionary_keys_callback(key_map, default_callback) - )(node); - ret &= check_key_map_counts(key_map); - return ret; - }; -} - -node_callback_t ModifierManager::expect_modifier_value_and_key_map( - callback_t modifier_callback, key_map_t&& key_map -) const { - return expect_modifier_value_and_key_map_and_default(modifier_callback, key_value_invalid_callback, std::move(key_map)); -} - -namespace OpenVic { // so the compiler shuts up - std::ostream& operator<<(std::ostream& stream, ModifierValue const& value) { - for (ModifierValue::effect_map_t::value_type const& effect : value.values) { - stream << effect.first << ": " << effect.second << "\n"; - } - return stream; - } -} diff --git a/src/openvic-simulation/modifier/Modifier.hpp b/src/openvic-simulation/modifier/Modifier.hpp index 49194cd..16ccd21 100644 --- a/src/openvic-simulation/modifier/Modifier.hpp +++ b/src/openvic-simulation/modifier/Modifier.hpp @@ -1,11 +1,11 @@ #pragma once -#include "openvic-simulation/modifier/ModifierEffect.hpp" -#include "openvic-simulation/modifier/ModifierEffectCache.hpp" +#include + #include "openvic-simulation/modifier/ModifierValue.hpp" -#include "openvic-simulation/modifier/StaticModifierCache.hpp" #include "openvic-simulation/scripts/ConditionScript.hpp" -#include "openvic-simulation/types/IdentifierRegistry.hpp" +#include "openvic-simulation/types/Date.hpp" +#include "openvic-simulation/utility/Getters.hpp" namespace OpenVic { struct Modifier : HasIdentifier, ModifierValue { @@ -69,122 +69,4 @@ namespace OpenVic { public: ModifierInstance(Modifier const& new_modifier, Date new_expiry_date); }; - - template - concept ModifierEffectValidator = std::predicate; - - struct ModifierManager { - friend struct StaticModifierCache; - friend struct BuildingTypeManager; - friend struct GoodDefinitionManager; - friend struct UnitTypeManager; - friend struct RebelManager; - friend struct PopManager; - friend struct TechnologyManager; - - /* Some ModifierEffects are generated mid-load, such as max/min count modifiers for each building, so - * we can't lock it until loading is over. This means we can't rely on locking for pointer stability, - * so instead we store the effects in a deque which doesn't invalidate pointers on insert. - */ - private: - CaseInsensitiveIdentifierRegistry IDENTIFIER_REGISTRY(modifier_effect); - case_insensitive_string_set_t complex_modifiers; - - IdentifierRegistry IDENTIFIER_REGISTRY(event_modifier); - IdentifierRegistry IDENTIFIER_REGISTRY(static_modifier); - IdentifierRegistry IDENTIFIER_REGISTRY(triggered_modifier); - - ModifierEffectCache PROPERTY(modifier_effect_cache); - StaticModifierCache PROPERTY(static_modifier_cache); - - /* effect_validator takes in ModifierEffect const& */ - NodeTools::key_value_callback_t _modifier_effect_callback( - ModifierValue& modifier, NodeTools::key_value_callback_t default_callback, - ModifierEffectValidator auto effect_validator - ) const; - - public: - bool add_modifier_effect( - ModifierEffect const*& effect_cache, - std::string_view identifier, - bool positive_good, - ModifierEffect::format_t format, - ModifierEffect::target_t targets, - std::string_view localisation_key = {} - ); - - bool register_complex_modifier(std::string_view identifier); - static std::string get_flat_identifier( - std::string_view complex_modifier_identifier, std::string_view variant_identifier - ); - - bool setup_modifier_effects(); - - bool add_event_modifier(std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon); - bool load_event_modifiers(ast::NodeCPtr root); - - bool add_static_modifier(std::string_view identifier, ModifierValue&& values); - bool load_static_modifiers(ast::NodeCPtr root); - - bool add_triggered_modifier( - std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon, ConditionScript&& trigger - ); - bool load_triggered_modifiers(ast::NodeCPtr root); - - bool parse_scripts(DefinitionManager const& definition_manager); - - NodeTools::node_callback_t expect_validated_modifier_value_and_default( - NodeTools::callback_t modifier_callback, NodeTools::key_value_callback_t default_callback, - ModifierEffectValidator auto effect_validator - ) const; - NodeTools::node_callback_t expect_validated_modifier_value( - NodeTools::callback_t modifier_callback, ModifierEffectValidator auto effect_validator - ) const; - - NodeTools::node_callback_t expect_modifier_value_and_default( - NodeTools::callback_t modifier_callback, NodeTools::key_value_callback_t default_callback - ) const; - NodeTools::node_callback_t expect_modifier_value(NodeTools::callback_t modifier_callback) const; - - NodeTools::node_callback_t expect_whitelisted_modifier_value_and_default( - NodeTools::callback_t modifier_callback, string_set_t const& whitelist, - NodeTools::key_value_callback_t default_callback - ) const; - NodeTools::node_callback_t expect_whitelisted_modifier_value( - NodeTools::callback_t modifier_callback, string_set_t const& whitelist - ) const; - - NodeTools::node_callback_t expect_modifier_value_and_key_map_and_default( - NodeTools::callback_t modifier_callback, NodeTools::key_value_callback_t default_callback, - NodeTools::key_map_t&& key_map - ) const; - NodeTools::node_callback_t expect_modifier_value_and_key_map( - NodeTools::callback_t modifier_callback, NodeTools::key_map_t&& key_map - ) const; - - template - NodeTools::node_callback_t expect_modifier_value_and_key_map_and_default( - NodeTools::callback_t modifier_callback, NodeTools::key_value_callback_t default_callback, - NodeTools::key_map_t&& key_map, Args... args - ) const { - NodeTools::add_key_map_entries(key_map, args...); - return expect_modifier_value_and_key_map_and_default(modifier_callback, default_callback, std::move(key_map)); - } - - template - NodeTools::node_callback_t expect_modifier_value_and_keys_and_default( - NodeTools::callback_t modifier_callback, NodeTools::key_value_callback_t default_callback, - Args... args - ) const { - return expect_modifier_value_and_key_map_and_default(modifier_callback, default_callback, {}, args...); - } - template - NodeTools::node_callback_t expect_modifier_value_and_keys( - NodeTools::callback_t modifier_callback, Args... args - ) const { - return expect_modifier_value_and_key_map_and_default( - modifier_callback, NodeTools::key_value_invalid_callback, {}, args... - ); - } - }; } diff --git a/src/openvic-simulation/modifier/ModifierManager.cpp b/src/openvic-simulation/modifier/ModifierManager.cpp new file mode 100644 index 0000000..c9072c8 --- /dev/null +++ b/src/openvic-simulation/modifier/ModifierManager.cpp @@ -0,0 +1,692 @@ +#include "ModifierManager.hpp" + +using namespace OpenVic; +using namespace OpenVic::NodeTools; + +bool ModifierManager::add_modifier_effect( + ModifierEffect const*& effect_cache, std::string_view identifier, bool positive_good, ModifierEffect::format_t format, + ModifierEffect::target_t targets, std::string_view localisation_key +) { + if (identifier.empty()) { + Logger::error("Invalid modifier effect identifier - empty!"); + return false; + } + + if (effect_cache != nullptr) { + Logger::error( + "Cache variable for modifier effect \"", identifier, "\" is already filled with modifier effect \"", + effect_cache->get_identifier(), "\"" + ); + return false; + } + + const bool ret = modifier_effects.add_item({ std::move(identifier), positive_good, format, targets, localisation_key }); + + if (ret) { + effect_cache = &modifier_effects.get_items().back(); + } + + return ret; +} + +bool ModifierManager::setup_modifier_effects() { + bool ret = true; + + using enum ModifierEffect::format_t; + using enum ModifierEffect::target_t; + + /* Tech/inventions only */ + ret &= add_modifier_effect( + modifier_effect_cache.cb_creation_speed, "cb_creation_speed", true, PROPORTION_DECIMAL, COUNTRY, "CB_MANUFACTURE_TECH" + ); + ret &= add_modifier_effect(modifier_effect_cache.combat_width, "combat_width", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.plurality, "plurality", true, PERCENTAGE_DECIMAL, COUNTRY, "TECH_PLURALITY" + ); + ret &= add_modifier_effect( + modifier_effect_cache.pop_growth, "pop_growth", true, PROPORTION_DECIMAL, COUNTRY, "TECH_POP_GROWTH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.regular_experience_level, "regular_experience_level", true, RAW_DECIMAL, COUNTRY, + "REGULAR_EXP_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.reinforce_rate, "reinforce_rate", true, PROPORTION_DECIMAL, COUNTRY, "REINFORCE_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.separatism, "seperatism", // paradox typo + false, PROPORTION_DECIMAL, COUNTRY, "SEPARATISM_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.shared_prestige, "shared_prestige", true, RAW_DECIMAL, COUNTRY, "SHARED_PRESTIGE_TECH" + ); + ret &= add_modifier_effect(modifier_effect_cache.tax_eff, "tax_eff", true, PERCENTAGE_DECIMAL, COUNTRY, "TECH_TAX_EFF"); + + /* Country Modifier Effects */ + ret &= add_modifier_effect( + modifier_effect_cache.administrative_efficiency, "administrative_efficiency", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.administrative_efficiency_modifier, "administrative_efficiency_modifier", true, + PROPORTION_DECIMAL, COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("administrative_efficiency") + ); + ret &= add_modifier_effect(modifier_effect_cache.artisan_input, "artisan_input", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.artisan_output, "artisan_output", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.artisan_throughput, "artisan_throughput", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.badboy, "badboy", false, RAW_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.cb_generation_speed_modifier, "cb_generation_speed_modifier", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.civilization_progress_modifier, "civilization_progress_modifier", true, PROPORTION_DECIMAL, + COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("civilization_progress") + ); + ret &= add_modifier_effect( + modifier_effect_cache.colonial_life_rating, "colonial_life_rating", false, INT, COUNTRY, "COLONIAL_LIFE_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.colonial_migration, "colonial_migration", true, PROPORTION_DECIMAL, COUNTRY, + "COLONIAL_MIGRATION_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.colonial_points, "colonial_points", true, INT, COUNTRY, "COLONIAL_POINTS_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.colonial_prestige, "colonial_prestige", true, PROPORTION_DECIMAL, COUNTRY, + "COLONIAL_PRESTIGE_MODIFIER_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.core_pop_consciousness_modifier, "core_pop_consciousness_modifier", false, RAW_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.core_pop_militancy_modifier, "core_pop_militancy_modifier", false, RAW_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.dig_in_cap, "dig_in_cap", true, INT, COUNTRY, "DIGIN_FROM_TECH"); + ret &= add_modifier_effect( + modifier_effect_cache.diplomatic_points, "diplomatic_points", true, PROPORTION_DECIMAL, COUNTRY, + "DIPLOMATIC_POINTS_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.diplomatic_points_modifier, "diplomatic_points_modifier", true, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("diplopoints_gain") + ); + ret &= add_modifier_effect( + modifier_effect_cache.education_efficiency, "education_efficiency", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.education_efficiency_modifier, "education_efficiency_modifier", true, PROPORTION_DECIMAL, + COUNTRY, ModifierEffect::make_default_modifier_effect_localisation_key("education_efficiency") + ); + ret &= add_modifier_effect(modifier_effect_cache.factory_cost, "factory_cost", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.factory_input, "factory_input", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.factory_maintenance, "factory_maintenance", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.factory_output, "factory_output", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.factory_owner_cost, "factory_owner_cost", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.factory_throughput, "factory_throughput", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.global_assimilation_rate, "global_assimilation_rate", true, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("assimilation_rate") + ); + ret &= add_modifier_effect( + modifier_effect_cache.global_immigrant_attract, "global_immigrant_attract", true, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("immigant_attract") + ); + ret &= add_modifier_effect( + modifier_effect_cache.global_pop_consciousness_modifier, "global_pop_consciousness_modifier", false, RAW_DECIMAL, + COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.global_pop_militancy_modifier, "global_pop_militancy_modifier", false, RAW_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.global_population_growth, "global_population_growth", true, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("population_growth") + ); + ret &= add_modifier_effect(modifier_effect_cache.goods_demand, "goods_demand", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.import_cost, "import_cost", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.increase_research, "increase_research", true, PROPORTION_DECIMAL, COUNTRY, "INC_RES_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.influence, "influence", true, PROPORTION_DECIMAL, COUNTRY, "TECH_GP_INFLUENCE" + ); + ret &= add_modifier_effect( + modifier_effect_cache.influence_modifier, "influence_modifier", true, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("greatpower_influence_gain") + ); + ret &= add_modifier_effect( + modifier_effect_cache.issue_change_speed, "issue_change_speed", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.land_attack_modifier, "land_attack_modifier", true, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("land_attack") + ); + ret &= add_modifier_effect( + modifier_effect_cache.land_attrition, "land_attrition", false, PROPORTION_DECIMAL, COUNTRY, "LAND_ATTRITION_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.land_defense_modifier, "land_defense_modifier", true, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("land_defense") + ); + ret &= add_modifier_effect( + modifier_effect_cache.land_organisation, "land_organisation", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.land_unit_start_experience, "land_unit_start_experience", true, RAW_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.leadership, "leadership", true, RAW_DECIMAL, COUNTRY, "LEADERSHIP"); + ret &= add_modifier_effect( + modifier_effect_cache.leadership_modifier, "leadership_modifier", true, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("global_leadership_modifier") + ); + ret &= add_modifier_effect( + modifier_effect_cache.literacy_con_impact, "literacy_con_impact", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.loan_interest, "loan_interest", false, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.max_loan_modifier, "max_loan_modifier", true, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("max_loan_amount") + ); + ret &= add_modifier_effect( + modifier_effect_cache.max_military_spending, "max_military_spending", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.max_national_focus, "max_national_focus", true, INT, COUNTRY, "TECH_MAX_FOCUS" + ); + ret &= add_modifier_effect( + modifier_effect_cache.max_social_spending, "max_social_spending", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.max_tariff, "max_tariff", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.max_tax, "max_tax", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.max_war_exhaustion, "max_war_exhaustion", true, PERCENTAGE_DECIMAL, COUNTRY, "MAX_WAR_EXHAUSTION" + ); + ret &= add_modifier_effect( + modifier_effect_cache.military_tactics, "military_tactics", true, PROPORTION_DECIMAL, COUNTRY, "MIL_TACTICS_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.min_military_spending, "min_military_spending", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.min_social_spending, "min_social_spending", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.min_tariff, "min_tariff", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.min_tax, "min_tax", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.minimum_wage, "minimum_wage", true, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("minimun_wage") + ); + ret &= add_modifier_effect( + modifier_effect_cache.mobilisation_economy_impact, "mobilisation_economy_impact", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.mobilisation_size, "mobilisation_size", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.mobilization_impact, "mobilization_impact", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.naval_attack_modifier, "naval_attack_modifier", true, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("naval_attack") + ); + ret &= add_modifier_effect( + modifier_effect_cache.naval_attrition, "naval_attrition", false, PROPORTION_DECIMAL, COUNTRY, "NAVAL_ATTRITION_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.naval_defense_modifier, "naval_defense_modifier", true, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("naval_defense") + ); + ret &= add_modifier_effect( + modifier_effect_cache.naval_organisation, "naval_organisation", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.naval_unit_start_experience, "naval_unit_start_experience", true, RAW_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.non_accepted_pop_consciousness_modifier, "non_accepted_pop_consciousness_modifier", false, + RAW_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.non_accepted_pop_militancy_modifier, "non_accepted_pop_militancy_modifier", false, RAW_DECIMAL, + COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.org_regain, "org_regain", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.pension_level, "pension_level", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.permanent_prestige, "permanent_prestige", true, RAW_DECIMAL, COUNTRY, "PERMANENT_PRESTIGE_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.political_reform_desire, "political_reform_desire", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.poor_savings_modifier, "poor_savings_modifier", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.prestige, "prestige", true, RAW_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.reinforce_speed, "reinforce_speed", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.research_points, "research_points", true, RAW_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.research_points_modifier, "research_points_modifier", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.research_points_on_conquer, "research_points_on_conquer", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect(modifier_effect_cache.rgo_output, "rgo_output", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect(modifier_effect_cache.rgo_throughput, "rgo_throughput", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.ruling_party_support, "ruling_party_support", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.self_unciv_economic_modifier, "self_unciv_economic_modifier", false, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("self_unciv_economic") + ); + ret &= add_modifier_effect( + modifier_effect_cache.self_unciv_military_modifier, "self_unciv_military_modifier", false, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("self_unciv_military") + ); + ret &= add_modifier_effect( + modifier_effect_cache.social_reform_desire, "social_reform_desire", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.soldier_to_pop_loss, "soldier_to_pop_loss", true, PROPORTION_DECIMAL, COUNTRY, + "SOLDIER_TO_POP_LOSS_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.supply_consumption, "supply_consumption", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.supply_range, "supply_range", true, PROPORTION_DECIMAL, COUNTRY, "SUPPLY_RANGE_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.suppression_points_modifier, "suppression_points_modifier", true, PROPORTION_DECIMAL, COUNTRY, + "SUPPRESSION_TECH" + ); + ret &= add_modifier_effect( + modifier_effect_cache.tariff_efficiency_modifier, "tariff_efficiency_modifier", true, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("tariff_efficiency") + ); + ret &= add_modifier_effect(modifier_effect_cache.tax_efficiency, "tax_efficiency", true, PROPORTION_DECIMAL, COUNTRY); + ret &= add_modifier_effect( + modifier_effect_cache.unemployment_benefit, "unemployment_benefit", true, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.unciv_economic_modifier, "unciv_economic_modifier", false, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("unciv_economic") + ); + ret &= add_modifier_effect( + modifier_effect_cache.unciv_military_modifier, "unciv_military_modifier", false, PROPORTION_DECIMAL, COUNTRY, + ModifierEffect::make_default_modifier_effect_localisation_key("unciv_military") + ); + ret &= add_modifier_effect( + modifier_effect_cache.unit_recruitment_time, "unit_recruitment_time", false, PROPORTION_DECIMAL, COUNTRY + ); + ret &= add_modifier_effect( + modifier_effect_cache.war_exhaustion, "war_exhaustion", false, PROPORTION_DECIMAL, COUNTRY, "WAR_EXHAUST_BATTLES" + ); + + /* Province Modifier Effects */ + ret &= add_modifier_effect( + modifier_effect_cache.assimilation_rate, "assimilation_rate", true, PROPORTION_DECIMAL, PROVINCE + ); + ret &= add_modifier_effect( + modifier_effect_cache.boost_strongest_party, "boost_strongest_party", false, PROPORTION_DECIMAL, PROVINCE + ); + ret &= add_modifier_effect( + modifier_effect_cache.farm_rgo_eff, "farm_rgo_eff", true, PROPORTION_DECIMAL, PROVINCE, "TECH_FARM_OUTPUT" + ); + ret &= add_modifier_effect( + modifier_effect_cache.farm_rgo_size, "farm_rgo_size", true, PROPORTION_DECIMAL, PROVINCE, + ModifierEffect::make_default_modifier_effect_localisation_key("farm_size") + ); + ret &= add_modifier_effect( + modifier_effect_cache.immigrant_attract, "immigrant_attract", true, PROPORTION_DECIMAL, PROVINCE, + ModifierEffect::make_default_modifier_effect_localisation_key("immigant_attract") + ); + ret &= add_modifier_effect( + modifier_effect_cache.immigrant_push, "immigrant_push", false, PROPORTION_DECIMAL, PROVINCE, + ModifierEffect::make_default_modifier_effect_localisation_key("immigant_push") + ); + ret &= add_modifier_effect(modifier_effect_cache.life_rating, "life_rating", true, PROPORTION_DECIMAL, PROVINCE); + ret &= add_modifier_effect( + modifier_effect_cache.local_artisan_input, "local_artisan_input", false, PROPORTION_DECIMAL, PROVINCE, + ModifierEffect::make_default_modifier_effect_localisation_key("artisan_input") + ); + ret &= add_modifier_effect( + modifier_effect_cache.local_artisan_output, "local_artisan_output", true, PROPORTION_DECIMAL, PROVINCE, + ModifierEffect::make_default_modifier_effect_localisation_key("artisan_output") + ); + ret &= add_modifier_effect( + modifier_effect_cache.local_artisan_throughput, "local_artisan_throughput", true, PROPORTION_DECIMAL, PROVINCE, + ModifierEffect::make_default_modifier_effect_localisation_key("artisan_throughput") + ); + ret &= add_modifier_effect( + modifier_effect_cache.local_factory_input, "local_factory_input", false, PROPORTION_DECIMAL, PROVINCE, + ModifierEffect::make_default_modifier_effect_localisation_key("factory_input") + ); + ret &= add_modifier_effect( + modifier_effect_cache.local_factory_output, "local_factory_output", true, PROPORTION_DECIMAL, PROVINCE, + ModifierEffect::make_default_modifier_effect_localisation_key("factory_output") + ); + ret &= add_modifier_effect( + modifier_effect_cache.local_factory_throughput, "local_factory_throughput", true, PROPORTION_DECIMAL, PROVINCE, + ModifierEffect::make_default_modifier_effect_localisation_key("factory_throughput") + ); + ret &= add_modifier_effect(modifier_effect_cache.local_repair, "local_repair", true, PROPORTION_DECIMAL, PROVINCE); + ret &= add_modifier_effect( + modifier_effect_cache.local_rgo_output, "local_rgo_output", true, PROPORTION_DECIMAL, PROVINCE, + ModifierEffect::make_default_modifier_effect_localisation_key("rgo_output") + ); + ret &= add_modifier_effect( + modifier_effect_cache.local_rgo_throughput, "local_rgo_throughput", true, PROPORTION_DECIMAL, PROVINCE, + ModifierEffect::make_default_modifier_effect_localisation_key("rgo_throughput") + ); + ret &= add_modifier_effect( + modifier_effect_cache.local_ruling_party_support, "local_ruling_party_support", true, PROPORTION_DECIMAL, PROVINCE, + ModifierEffect::make_default_modifier_effect_localisation_key("ruling_party_support") + ); + ret &= add_modifier_effect( + modifier_effect_cache.local_ship_build, "local_ship_build", false, PROPORTION_DECIMAL, PROVINCE + ); + ret &= add_modifier_effect(modifier_effect_cache.max_attrition, "max_attrition", false, RAW_DECIMAL, PROVINCE); + ret &= add_modifier_effect( + modifier_effect_cache.mine_rgo_eff, "mine_rgo_eff", true, PROPORTION_DECIMAL, PROVINCE, "TECH_MINE_OUTPUT" + ); + ret &= add_modifier_effect( + modifier_effect_cache.mine_rgo_size, "mine_rgo_size", true, PROPORTION_DECIMAL, PROVINCE, + ModifierEffect::make_default_modifier_effect_localisation_key("mine_size") + ); + ret &= add_modifier_effect(modifier_effect_cache.movement_cost, "movement_cost", false, PROPORTION_DECIMAL, PROVINCE); + ret &= add_modifier_effect( + modifier_effect_cache.number_of_voters, "number_of_voters", false, PROPORTION_DECIMAL, PROVINCE + ); + ret &= add_modifier_effect( + modifier_effect_cache.pop_consciousness_modifier, "pop_consciousness_modifier", false, RAW_DECIMAL, PROVINCE + ); + ret &= add_modifier_effect( + modifier_effect_cache.pop_militancy_modifier, "pop_militancy_modifier", false, RAW_DECIMAL, PROVINCE + ); + ret &= add_modifier_effect( + modifier_effect_cache.population_growth, "population_growth", true, PROPORTION_DECIMAL, PROVINCE + ); + ret &= add_modifier_effect(modifier_effect_cache.supply_limit, "supply_limit", true, RAW_DECIMAL, PROVINCE); + + /* Military Modifier Effects */ + ret &= add_modifier_effect(modifier_effect_cache.attack, "attack", true, INT, UNIT, "TRAIT_ATTACK"); + ret &= add_modifier_effect(modifier_effect_cache.attrition, "attrition", false, RAW_DECIMAL, UNIT, "ATTRITION"); + ret &= add_modifier_effect(modifier_effect_cache.defence, "defence", true, INT, UNIT, "TRAIT_DEFEND"); + ret &= add_modifier_effect( + modifier_effect_cache.experience, "experience", true, PROPORTION_DECIMAL, UNIT, "TRAIT_EXPERIENCE" + ); + ret &= add_modifier_effect(modifier_effect_cache.morale, "morale", true, PROPORTION_DECIMAL, UNIT, "TRAIT_MORALE"); + ret &= add_modifier_effect( + modifier_effect_cache.organisation, "organisation", true, PROPORTION_DECIMAL, UNIT, "TRAIT_ORGANISATION" + ); + ret &= add_modifier_effect( + modifier_effect_cache.reconnaissance, "reconnaissance", true, PROPORTION_DECIMAL, UNIT, "TRAIT_RECONAISSANCE" + ); + ret &= add_modifier_effect(modifier_effect_cache.reliability, "reliability", true, RAW_DECIMAL, UNIT, "TRAIT_RELIABILITY"); + ret &= add_modifier_effect(modifier_effect_cache.speed, "speed", true, PROPORTION_DECIMAL, UNIT, "TRAIT_SPEED"); + + return ret; +} + +bool ModifierManager::register_complex_modifier(std::string_view identifier) { + if (complex_modifiers.emplace(identifier).second) { + return true; + } else { + Logger::error("Duplicate complex modifier: ", identifier); + return false; + } +} + +std::string ModifierManager::get_flat_identifier( + std::string_view complex_modifier_identifier, std::string_view variant_identifier +) { + return StringUtils::append_string_views(complex_modifier_identifier, " ", variant_identifier); +} + +bool ModifierManager::add_event_modifier(std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon) { + if (identifier.empty()) { + Logger::error("Invalid event modifier effect identifier - empty!"); + return false; + } + + return event_modifiers.add_item( + { identifier, std::move(values), Modifier::modifier_type_t::EVENT, icon }, duplicate_warning_callback + ); +} + +bool ModifierManager::load_event_modifiers(ast::NodeCPtr root) { + const bool ret = expect_dictionary_reserve_length( + event_modifiers, + [this](std::string_view key, ast::NodeCPtr value) -> bool { + ModifierValue modifier_value; + IconModifier::icon_t icon = 0; + bool ret = expect_modifier_value_and_keys( + move_variable_callback(modifier_value), + "icon", ZERO_OR_ONE, expect_uint(assign_variable_callback(icon)) + )(value); + ret &= add_event_modifier(key, std::move(modifier_value), icon); + return ret; + } + )(root); + + lock_event_modifiers(); + + return ret; +} + +bool ModifierManager::add_static_modifier(std::string_view identifier, ModifierValue&& values) { + if (identifier.empty()) { + Logger::error("Invalid static modifier effect identifier - empty!"); + return false; + } + + return static_modifiers.add_item( + { identifier, std::move(values), Modifier::modifier_type_t::STATIC }, duplicate_warning_callback + ); +} + +bool ModifierManager::load_static_modifiers(ast::NodeCPtr root) { + bool ret = expect_dictionary_reserve_length( + static_modifiers, + [this](std::string_view key, ast::NodeCPtr value) -> bool { + ModifierValue modifier_value; + bool ret = expect_modifier_value(move_variable_callback(modifier_value))(value); + ret &= add_static_modifier(key, std::move(modifier_value)); + return ret; + } + )(root); + + lock_static_modifiers(); + + ret &= static_modifier_cache.load_static_modifiers(*this); + + return ret; +} + +bool ModifierManager::add_triggered_modifier( + std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon, ConditionScript&& trigger +) { + if (identifier.empty()) { + Logger::error("Invalid triggered modifier effect identifier - empty!"); + return false; + } + + return triggered_modifiers.add_item( + { identifier, std::move(values), Modifier::modifier_type_t::TRIGGERED, icon, std::move(trigger) }, + duplicate_warning_callback + ); +} + +bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) { + const bool ret = expect_dictionary_reserve_length( + triggered_modifiers, + [this](std::string_view key, ast::NodeCPtr value) -> bool { + ModifierValue modifier_value; + IconModifier::icon_t icon = 0; + ConditionScript trigger { scope_t::COUNTRY, scope_t::COUNTRY, scope_t::NO_SCOPE }; + + bool ret = expect_modifier_value_and_keys( + move_variable_callback(modifier_value), + "icon", ZERO_OR_ONE, expect_uint(assign_variable_callback(icon)), + "trigger", ONE_EXACTLY, trigger.expect_script() + )(value); + ret &= add_triggered_modifier(key, std::move(modifier_value), icon, std::move(trigger)); + return ret; + } + )(root); + + lock_triggered_modifiers(); + + return ret; +} + +bool ModifierManager::parse_scripts(DefinitionManager const& definition_manager) { + bool ret = true; + + for (TriggeredModifier& modifier : triggered_modifiers.get_items()) { + ret &= modifier.parse_scripts(definition_manager); + } + + return ret; +} + +key_value_callback_t ModifierManager::_modifier_effect_callback( + ModifierValue& modifier, key_value_callback_t default_callback, ModifierEffectValidator auto effect_validator +) const { + const auto add_modifier_cb = [this, &modifier, effect_validator]( + ModifierEffect const* effect, ast::NodeCPtr value + ) -> bool { + if (effect_validator(*effect)) { + static const case_insensitive_string_set_t no_effect_modifiers { + "boost_strongest_party", "poor_savings_modifier", "local_artisan_input", "local_artisan_throughput", + "local_artisan_output", "artisan_input", "artisan_throughput", "artisan_output", + "import_cost", "unciv_economic_modifier", "unciv_military_modifier" + }; + if (no_effect_modifiers.contains(effect->get_identifier())) { + Logger::warning("This modifier does nothing: ", effect->get_identifier()); + } + return expect_fixed_point(map_callback(modifier.values, effect))(value); + } else { + Logger::error("Failed to validate modifier effect: ", effect->get_identifier()); + return false; + } + }; + + const auto add_flattened_modifier_cb = [this, add_modifier_cb]( + std::string_view prefix, std::string_view key, ast::NodeCPtr value + ) -> bool { + const std::string flat_identifier = get_flat_identifier(prefix, key); + ModifierEffect const* effect = get_modifier_effect_by_identifier(flat_identifier); + if (effect != nullptr) { + return add_modifier_cb(effect, value); + } else { + Logger::error("Could not find flattened modifier: ", flat_identifier); + return false; + } + }; + + return [this, default_callback, add_modifier_cb, add_flattened_modifier_cb]( + std::string_view key, ast::NodeCPtr value + ) -> bool { + ModifierEffect const* effect = get_modifier_effect_by_identifier(key); + if (effect != nullptr && dryad::node_has_kind(value)) { + return add_modifier_cb(effect, value); + } else if (complex_modifiers.contains(key) && dryad::node_has_kind(value)) { + if (key == "rebel_org_gain") { //because of course there's a special one + std::string_view faction_identifier; + ast::NodeCPtr value_node = nullptr; + bool ret = expect_dictionary_keys( + "faction", ONE_EXACTLY, expect_identifier(assign_variable_callback(faction_identifier)), + "value", ONE_EXACTLY, assign_variable_callback(value_node) + )(value); + ret &= add_flattened_modifier_cb(key, faction_identifier, value_node); + return ret; + } else { + return expect_dictionary(std::bind_front(add_flattened_modifier_cb, key))(value); + } + } else if (key == "war_exhaustion_effect") { + Logger::warning("war_exhaustion_effect does nothing (vanilla issues have it)."); + return true; + } else { + return default_callback(key, value); + } + }; +} + +node_callback_t ModifierManager::expect_validated_modifier_value_and_default( + callback_t modifier_callback, key_value_callback_t default_callback, + ModifierEffectValidator auto effect_validator +) const { + return [this, modifier_callback, default_callback, effect_validator](ast::NodeCPtr root) -> bool { + ModifierValue modifier; + bool ret = expect_dictionary_reserve_length( + modifier.values, + _modifier_effect_callback(modifier, default_callback, effect_validator) + )(root); + ret &= modifier_callback(std::move(modifier)); + return ret; + }; +} + +node_callback_t ModifierManager::expect_validated_modifier_value( + callback_t modifier_callback, ModifierEffectValidator auto effect_validator +) const { + return expect_validated_modifier_value_and_default(modifier_callback, key_value_invalid_callback, effect_validator); +} + +node_callback_t ModifierManager::expect_modifier_value_and_default( + callback_t modifier_callback, key_value_callback_t default_callback +) const { + return expect_validated_modifier_value_and_default(modifier_callback, default_callback, [](ModifierEffect const&) -> bool { + return true; + }); +} + +node_callback_t ModifierManager::expect_modifier_value(callback_t modifier_callback) const { + return expect_modifier_value_and_default(modifier_callback, key_value_invalid_callback); +} + +node_callback_t ModifierManager::expect_whitelisted_modifier_value_and_default( + callback_t modifier_callback, string_set_t const& whitelist, key_value_callback_t default_callback +) const { + return expect_validated_modifier_value_and_default( + modifier_callback, default_callback, + [&whitelist](ModifierEffect const& effect) -> bool { + return whitelist.contains(effect.get_identifier()); + } + ); +} + +node_callback_t ModifierManager::expect_whitelisted_modifier_value( + callback_t modifier_callback, string_set_t const& whitelist +) const { + return expect_whitelisted_modifier_value_and_default(modifier_callback, whitelist, key_value_invalid_callback); +} + +node_callback_t ModifierManager::expect_modifier_value_and_key_map_and_default( + callback_t modifier_callback, key_value_callback_t default_callback, key_map_t&& key_map +) const { + return [this, modifier_callback, default_callback, key_map = std::move(key_map)](ast::NodeCPtr node) mutable -> bool { + bool ret = expect_modifier_value_and_default( + modifier_callback, + dictionary_keys_callback(key_map, default_callback) + )(node); + ret &= check_key_map_counts(key_map); + return ret; + }; +} + +node_callback_t ModifierManager::expect_modifier_value_and_key_map( + callback_t modifier_callback, key_map_t&& key_map +) const { + return expect_modifier_value_and_key_map_and_default(modifier_callback, key_value_invalid_callback, std::move(key_map)); +} diff --git a/src/openvic-simulation/modifier/ModifierManager.hpp b/src/openvic-simulation/modifier/ModifierManager.hpp new file mode 100644 index 0000000..73d974d --- /dev/null +++ b/src/openvic-simulation/modifier/ModifierManager.hpp @@ -0,0 +1,127 @@ +#pragma once + +#include "openvic-simulation/modifier/Modifier.hpp" +#include "openvic-simulation/modifier/ModifierEffectCache.hpp" +#include "openvic-simulation/modifier/StaticModifierCache.hpp" +#include "openvic-simulation/types/IdentifierRegistry.hpp" + +namespace OpenVic { + + template + concept ModifierEffectValidator = std::predicate; + + struct ModifierManager { + friend struct StaticModifierCache; + friend struct BuildingTypeManager; + friend struct GoodDefinitionManager; + friend struct UnitTypeManager; + friend struct RebelManager; + friend struct PopManager; + friend struct TechnologyManager; + + /* Some ModifierEffects are generated mid-load, such as max/min count modifiers for each building, so + * we can't lock it until loading is over. This means we can't rely on locking for pointer stability, + * so instead we store the effects in a deque which doesn't invalidate pointers on insert. + */ + private: + CaseInsensitiveIdentifierRegistry IDENTIFIER_REGISTRY(modifier_effect); + case_insensitive_string_set_t complex_modifiers; + + IdentifierRegistry IDENTIFIER_REGISTRY(event_modifier); + IdentifierRegistry IDENTIFIER_REGISTRY(static_modifier); + IdentifierRegistry IDENTIFIER_REGISTRY(triggered_modifier); + + ModifierEffectCache PROPERTY(modifier_effect_cache); + StaticModifierCache PROPERTY(static_modifier_cache); + + /* effect_validator takes in ModifierEffect const& */ + NodeTools::key_value_callback_t _modifier_effect_callback( + ModifierValue& modifier, NodeTools::key_value_callback_t default_callback, + ModifierEffectValidator auto effect_validator + ) const; + + public: + bool add_modifier_effect( + ModifierEffect const*& effect_cache, + std::string_view identifier, + bool positive_good, + ModifierEffect::format_t format, + ModifierEffect::target_t targets, + std::string_view localisation_key = {} + ); + + bool register_complex_modifier(std::string_view identifier); + static std::string get_flat_identifier( + std::string_view complex_modifier_identifier, std::string_view variant_identifier + ); + + bool setup_modifier_effects(); + + bool add_event_modifier(std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon); + bool load_event_modifiers(ast::NodeCPtr root); + + bool add_static_modifier(std::string_view identifier, ModifierValue&& values); + bool load_static_modifiers(ast::NodeCPtr root); + + bool add_triggered_modifier( + std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon, ConditionScript&& trigger + ); + bool load_triggered_modifiers(ast::NodeCPtr root); + + bool parse_scripts(DefinitionManager const& definition_manager); + + NodeTools::node_callback_t expect_validated_modifier_value_and_default( + NodeTools::callback_t modifier_callback, NodeTools::key_value_callback_t default_callback, + ModifierEffectValidator auto effect_validator + ) const; + NodeTools::node_callback_t expect_validated_modifier_value( + NodeTools::callback_t modifier_callback, ModifierEffectValidator auto effect_validator + ) const; + + NodeTools::node_callback_t expect_modifier_value_and_default( + NodeTools::callback_t modifier_callback, NodeTools::key_value_callback_t default_callback + ) const; + NodeTools::node_callback_t expect_modifier_value(NodeTools::callback_t modifier_callback) const; + + NodeTools::node_callback_t expect_whitelisted_modifier_value_and_default( + NodeTools::callback_t modifier_callback, string_set_t const& whitelist, + NodeTools::key_value_callback_t default_callback + ) const; + NodeTools::node_callback_t expect_whitelisted_modifier_value( + NodeTools::callback_t modifier_callback, string_set_t const& whitelist + ) const; + + NodeTools::node_callback_t expect_modifier_value_and_key_map_and_default( + NodeTools::callback_t modifier_callback, NodeTools::key_value_callback_t default_callback, + NodeTools::key_map_t&& key_map + ) const; + NodeTools::node_callback_t expect_modifier_value_and_key_map( + NodeTools::callback_t modifier_callback, NodeTools::key_map_t&& key_map + ) const; + + template + NodeTools::node_callback_t expect_modifier_value_and_key_map_and_default( + NodeTools::callback_t modifier_callback, NodeTools::key_value_callback_t default_callback, + NodeTools::key_map_t&& key_map, Args... args + ) const { + NodeTools::add_key_map_entries(key_map, args...); + return expect_modifier_value_and_key_map_and_default(modifier_callback, default_callback, std::move(key_map)); + } + + template + NodeTools::node_callback_t expect_modifier_value_and_keys_and_default( + NodeTools::callback_t modifier_callback, NodeTools::key_value_callback_t default_callback, + Args... args + ) const { + return expect_modifier_value_and_key_map_and_default(modifier_callback, default_callback, {}, args...); + } + template + NodeTools::node_callback_t expect_modifier_value_and_keys( + NodeTools::callback_t modifier_callback, Args... args + ) const { + return expect_modifier_value_and_key_map_and_default( + modifier_callback, NodeTools::key_value_invalid_callback, {}, args... + ); + } + }; +} diff --git a/src/openvic-simulation/modifier/ModifierValue.cpp b/src/openvic-simulation/modifier/ModifierValue.cpp index 51d41bc..eec34bb 100644 --- a/src/openvic-simulation/modifier/ModifierValue.cpp +++ b/src/openvic-simulation/modifier/ModifierValue.cpp @@ -134,3 +134,12 @@ void ModifierValue::multiply_add_filter( } } } + +namespace OpenVic { // so the compiler shuts up + std::ostream& operator<<(std::ostream& stream, ModifierValue const& value) { + for (ModifierValue::effect_map_t::value_type const& effect : value.values) { + stream << effect.first << ": " << effect.second << "\n"; + } + return stream; + } +} diff --git a/src/openvic-simulation/modifier/StaticModifierCache.cpp b/src/openvic-simulation/modifier/StaticModifierCache.cpp index 32ef10a..b03d827 100644 --- a/src/openvic-simulation/modifier/StaticModifierCache.cpp +++ b/src/openvic-simulation/modifier/StaticModifierCache.cpp @@ -1,6 +1,6 @@ #include "StaticModifierCache.hpp" -#include "openvic-simulation/modifier/Modifier.hpp" +#include "openvic-simulation/modifier/ModifierManager.hpp" using namespace OpenVic; diff --git a/src/openvic-simulation/politics/Issue.cpp b/src/openvic-simulation/politics/Issue.cpp index 3174e23..aa7fd60 100644 --- a/src/openvic-simulation/politics/Issue.cpp +++ b/src/openvic-simulation/politics/Issue.cpp @@ -1,5 +1,7 @@ #include "Issue.hpp" +#include "openvic-simulation/modifier/ModifierManager.hpp" + using namespace OpenVic; using namespace OpenVic::NodeTools; diff --git a/src/openvic-simulation/politics/NationalFocus.cpp b/src/openvic-simulation/politics/NationalFocus.cpp index 4887ed6..81e6336 100644 --- a/src/openvic-simulation/politics/NationalFocus.cpp +++ b/src/openvic-simulation/politics/NationalFocus.cpp @@ -1,6 +1,7 @@ #include "NationalFocus.hpp" #include "openvic-simulation/economy/GoodDefinition.hpp" +#include "openvic-simulation/modifier/ModifierManager.hpp" #include "openvic-simulation/politics/Ideology.hpp" #include "openvic-simulation/pop/Pop.hpp" diff --git a/src/openvic-simulation/politics/NationalValue.cpp b/src/openvic-simulation/politics/NationalValue.cpp index e9f7f2a..6dd4678 100644 --- a/src/openvic-simulation/politics/NationalValue.cpp +++ b/src/openvic-simulation/politics/NationalValue.cpp @@ -1,5 +1,7 @@ #include "NationalValue.hpp" +#include "openvic-simulation/modifier/ModifierManager.hpp" + using namespace OpenVic; using namespace OpenVic::NodeTools; diff --git a/src/openvic-simulation/politics/Rebel.cpp b/src/openvic-simulation/politics/Rebel.cpp index 219a47b..9bba1b9 100644 --- a/src/openvic-simulation/politics/Rebel.cpp +++ b/src/openvic-simulation/politics/Rebel.cpp @@ -2,7 +2,7 @@ #include -#include "openvic-simulation/modifier/Modifier.hpp" +#include "openvic-simulation/modifier/ModifierManager.hpp" using namespace OpenVic; using namespace OpenVic::NodeTools; diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp index 54765d0..885903a 100644 --- a/src/openvic-simulation/pop/Pop.cpp +++ b/src/openvic-simulation/pop/Pop.cpp @@ -5,6 +5,7 @@ #include "openvic-simulation/map/ProvinceInstance.hpp" #include "openvic-simulation/military/UnitType.hpp" #include "openvic-simulation/misc/Define.hpp" +#include "openvic-simulation/modifier/ModifierManager.hpp" #include "openvic-simulation/politics/Ideology.hpp" #include "openvic-simulation/politics/Issue.hpp" #include "openvic-simulation/politics/Rebel.hpp" diff --git a/src/openvic-simulation/research/Invention.cpp b/src/openvic-simulation/research/Invention.cpp index 299cefb..d8696a8 100644 --- a/src/openvic-simulation/research/Invention.cpp +++ b/src/openvic-simulation/research/Invention.cpp @@ -3,6 +3,7 @@ #include "openvic-simulation/economy/BuildingType.hpp" #include "openvic-simulation/map/Crime.hpp" #include "openvic-simulation/military/UnitType.hpp" +#include "openvic-simulation/modifier/ModifierManager.hpp" using namespace OpenVic; using namespace OpenVic::NodeTools; @@ -54,8 +55,8 @@ bool InventionManager::add_invention( } bool InventionManager::load_inventions_file( - ModifierManager const& modifier_manager, UnitTypeManager const& unit_type_manager, BuildingTypeManager const& building_type_manager, - CrimeManager const& crime_manager, ast::NodeCPtr root + ModifierManager const& modifier_manager, UnitTypeManager const& unit_type_manager, + BuildingTypeManager const& building_type_manager, CrimeManager const& crime_manager, ast::NodeCPtr root ) { return expect_dictionary_reserve_length( inventions, [this, &modifier_manager, &unit_type_manager, &building_type_manager, &crime_manager]( @@ -82,7 +83,8 @@ bool InventionManager::load_inventions_file( move_variable_callback(modifiers), "gas_attack", ZERO_OR_ONE, expect_bool(assign_variable_callback(unlock_gas_attack)), "gas_defence", ZERO_OR_ONE, expect_bool(assign_variable_callback(unlock_gas_defence)), - "activate_unit", ZERO_OR_MORE, unit_type_manager.expect_unit_type_identifier(set_callback_pointer(activated_units)), + "activate_unit", ZERO_OR_MORE, + unit_type_manager.expect_unit_type_identifier(set_callback_pointer(activated_units)), "activate_building", ZERO_OR_MORE, building_type_manager.expect_building_type_identifier( set_callback_pointer(activated_buildings) ), diff --git a/src/openvic-simulation/research/Technology.cpp b/src/openvic-simulation/research/Technology.cpp index 27bb4ca..773b3c6 100644 --- a/src/openvic-simulation/research/Technology.cpp +++ b/src/openvic-simulation/research/Technology.cpp @@ -1,5 +1,7 @@ #include "Technology.hpp" +#include "openvic-simulation/modifier/ModifierManager.hpp" + using namespace OpenVic; using namespace OpenVic::NodeTools; -- cgit v1.2.3-56-ga3b1