From 6181851281876730d7db4bed18791fdbbe3cfbbc Mon Sep 17 00:00:00 2001 From: hop311 Date: Sun, 6 Oct 2024 00:08:44 +0100 Subject: Add alternative modifier calculation (keeping country modifiers out of their owned provinces' modifier sums) --- src/openvic-simulation/country/CountryInstance.cpp | 39 ++++++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'src/openvic-simulation/country/CountryInstance.cpp') diff --git a/src/openvic-simulation/country/CountryInstance.cpp b/src/openvic-simulation/country/CountryInstance.cpp index be62fda..f04dfc6 100644 --- a/src/openvic-simulation/country/CountryInstance.cpp +++ b/src/openvic-simulation/country/CountryInstance.cpp @@ -1007,23 +1007,30 @@ void CountryInstance::update_modifier_sum(Date today, StaticModifierCache const& } } - // Add province base modifiers (with local province modifier effects removed) - using enum ModifierEffect::target_t; - static constexpr ModifierEffect::target_t NOT_PROVINCE = ALL_TARGETS & ~PROVINCE; - - for (ProvinceInstance const* province : owned_provinces) { - modifier_sum.add_modifier_sum_filter_targets(province->get_modifier_sum(), NOT_PROVINCE); - } + if constexpr (ProvinceInstance::ADD_OWNER_CONTRIBUTION) { + // Add province base modifiers (with local province modifier effects removed) + for (ProvinceInstance const* province : owned_provinces) { + contribute_province_modifier_sum(province->get_modifier_sum()); + } - // This has to be done after adding all province modifiers to the country's sum, otherwise provinces earlier in the list - // wouldn't be affected by modifiers from provinces later in the list. - for (ProvinceInstance* province : owned_provinces) { - province->contribute_country_modifier_sum(modifier_sum); + // This has to be done after adding all province modifiers to the country's sum, otherwise provinces + // earlier in the list wouldn't be affected by modifiers from provinces later in the list. + for (ProvinceInstance* province : owned_provinces) { + province->contribute_country_modifier_sum(modifier_sum); + } } // TODO - calculate stats for each unit type (locked and unlocked) } +void CountryInstance::contribute_province_modifier_sum(ModifierSum const& province_modifier_sum) { + using enum ModifierEffect::target_t; + + static constexpr ModifierEffect::target_t NOT_PROVINCE = ALL_TARGETS & ~PROVINCE; + + modifier_sum.add_modifier_sum_filter_targets(province_modifier_sum, NOT_PROVINCE); +} + fixed_point_t CountryInstance::get_modifier_effect_value(ModifierEffect const& effect) const { return modifier_sum.get_effect(effect); } @@ -1032,6 +1039,16 @@ fixed_point_t CountryInstance::get_modifier_effect_value_nullcheck(ModifierEffec return modifier_sum.get_effect_nullcheck(effect); } +void CountryInstance::push_contributing_modifiers( + ModifierEffect const& effect, std::vector& contributions +) const { + modifier_sum.push_contributing_modifiers(effect, contributions); +} + +std::vector CountryInstance::get_contributing_modifiers(ModifierEffect const& effect) const { + return modifier_sum.get_contributing_modifiers(effect); +} + void CountryInstance::update_gamestate( DefineManager const& define_manager, UnitTypeManager const& unit_type_manager, ModifierEffectCache const& modifier_effect_cache -- cgit v1.2.3-56-ga3b1