diff options
author | hop311 <hop3114@gmail.com> | 2024-09-29 22:37:11 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-10-05 22:48:42 +0200 |
commit | eb77495ba874d474bbbbc950a65e8f496b13f285 (patch) | |
tree | fdbbc50f20d607cf66cff407415a7b89a14c78b8 /src/openvic-simulation/map | |
parent | 6c23b7ff2e8bc733699ef9b29aee80719001acf2 (diff) |
Calculate country and province resultant modifier sums
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r-- | src/openvic-simulation/map/MapInstance.cpp | 6 | ||||
-rw-r--r-- | src/openvic-simulation/map/MapInstance.hpp | 1 | ||||
-rw-r--r-- | src/openvic-simulation/map/ProvinceInstance.cpp | 64 | ||||
-rw-r--r-- | src/openvic-simulation/map/ProvinceInstance.hpp | 10 |
4 files changed, 81 insertions, 0 deletions
diff --git a/src/openvic-simulation/map/MapInstance.cpp b/src/openvic-simulation/map/MapInstance.cpp index 0ce8cea..d8ec2fb 100644 --- a/src/openvic-simulation/map/MapInstance.cpp +++ b/src/openvic-simulation/map/MapInstance.cpp @@ -118,6 +118,12 @@ bool MapInstance::apply_history_to_provinces( return ret; } +void MapInstance::update_modifier_sums(Date today, StaticModifierCache const& static_modifier_cache) { + for (ProvinceInstance& province : province_instances.get_items()) { + province.update_modifier_sum(today, static_modifier_cache); + } +} + void MapInstance::update_gamestate(Date today, DefineManager const& define_manager) { for (ProvinceInstance& province : province_instances.get_items()) { province.update_gamestate(today, define_manager); diff --git a/src/openvic-simulation/map/MapInstance.hpp b/src/openvic-simulation/map/MapInstance.hpp index 99c13d3..e7c623e 100644 --- a/src/openvic-simulation/map/MapInstance.hpp +++ b/src/openvic-simulation/map/MapInstance.hpp @@ -52,6 +52,7 @@ namespace OpenVic { IssueManager const& issue_manager ); + void update_modifier_sums(Date today, StaticModifierCache const& static_modifier_cache); void update_gamestate(Date today, DefineManager const& define_manager); void tick(Date today); }; diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp index 06b3f1e..e85c576 100644 --- a/src/openvic-simulation/map/ProvinceInstance.cpp +++ b/src/openvic-simulation/map/ProvinceInstance.cpp @@ -2,7 +2,10 @@ #include "openvic-simulation/country/CountryInstance.hpp" #include "openvic-simulation/history/ProvinceHistory.hpp" +#include "openvic-simulation/map/Crime.hpp" #include "openvic-simulation/map/ProvinceDefinition.hpp" +#include "openvic-simulation/map/Region.hpp" +#include "openvic-simulation/map/TerrainType.hpp" #include "openvic-simulation/military/UnitInstanceGroup.hpp" #include "openvic-simulation/misc/Define.hpp" #include "openvic-simulation/politics/Ideology.hpp" @@ -21,6 +24,8 @@ ProvinceInstance::ProvinceInstance( owner { nullptr }, controller { nullptr }, cores {}, + modifier_sum {}, + event_modifiers {}, slave { false }, crime { nullptr }, rgo { nullptr }, @@ -185,6 +190,65 @@ void ProvinceInstance::_update_pops(DefineManager const& define_manager) { } } +void ProvinceInstance::update_modifier_sum(Date today, StaticModifierCache const& static_modifier_cache) { + // Update sum of direct province modifiers + modifier_sum.clear(); + + const ModifierSum::modifier_source_t province_source { this }; + + // Erase expired event modifiers and add non-expired ones to the sum + std::erase_if(event_modifiers, [this, today, &province_source](ModifierInstance const& modifier) -> bool { + if (today <= modifier.get_expiry_date()) { + modifier_sum.add_modifier(*modifier.get_modifier(), province_source); + return false; + } else { + return true; + } + }); + + // Add static modifiers + if (is_owner_core()) { + modifier_sum.add_modifier_nullcheck(static_modifier_cache.get_core(), province_source); + } + if (province_definition.is_water()) { + modifier_sum.add_modifier_nullcheck(static_modifier_cache.get_sea_zone(), province_source); + } else { + modifier_sum.add_modifier_nullcheck(static_modifier_cache.get_land_province(), province_source); + + if (province_definition.is_coastal()) { + modifier_sum.add_modifier_nullcheck(static_modifier_cache.get_coastal(), province_source); + } else { + modifier_sum.add_modifier_nullcheck(static_modifier_cache.get_non_coastal(), province_source); + } + + // TODO - overseas, blockaded, no_adjacent_controlled, has_siege, occupied, nationalism, infrastructure + } + + for (BuildingInstance const& building : buildings.get_items()) { + modifier_sum.add_modifier(building.get_building_type(), province_source); + } + + modifier_sum.add_modifier_nullcheck(crime, province_source); + + modifier_sum.add_modifier_nullcheck(province_definition.get_continent(), province_source); + + modifier_sum.add_modifier_nullcheck(province_definition.get_climate(), province_source); + + modifier_sum.add_modifier_nullcheck(terrain_type, province_source); +} + +void ProvinceInstance::contribute_country_modifier_sum(ModifierSum const& owner_modifier_sum) { + modifier_sum.add_modifier_sum_exclude_source(owner_modifier_sum, this); +} + +fixed_point_t ProvinceInstance::get_modifier_effect_value(ModifierEffect const& effect) const { + return modifier_sum.get_effect(effect); +} + +fixed_point_t ProvinceInstance::get_modifier_effect_value_nullcheck(ModifierEffect const* effect) const { + return modifier_sum.get_effect_nullcheck(effect); +} + void ProvinceInstance::update_gamestate(Date today, DefineManager const& define_manager) { for (BuildingInstance& building : buildings.get_items()) { building.update_gamestate(today); diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp index fa0be98..0b02c41 100644 --- a/src/openvic-simulation/map/ProvinceInstance.hpp +++ b/src/openvic-simulation/map/ProvinceInstance.hpp @@ -5,6 +5,7 @@ #include "openvic-simulation/economy/BuildingInstance.hpp" #include "openvic-simulation/military/UnitInstance.hpp" #include "openvic-simulation/military/UnitType.hpp" +#include "openvic-simulation/modifier/ModifierSum.hpp" #include "openvic-simulation/pop/Pop.hpp" #include "openvic-simulation/types/fixed_point/FixedPointMap.hpp" #include "openvic-simulation/types/HasIdentifier.hpp" @@ -68,6 +69,10 @@ namespace OpenVic { CountryInstance* PROPERTY(controller); ordered_set<CountryInstance*> PROPERTY(cores); + // The total/resultant modifier affecting this province, including owner country contributions. + ModifierSum PROPERTY(modifier_sum); + std::vector<ModifierInstance> PROPERTY(event_modifiers); + bool PROPERTY(slave); Crime const* PROPERTY_RW(crime); // TODO - change this into a factory-like structure @@ -124,6 +129,11 @@ namespace OpenVic { bool add_pop_vec(std::vector<PopBase> const& pop_vec); size_t get_pop_count() const; + void update_modifier_sum(Date today, StaticModifierCache const& static_modifier_cache); + void contribute_country_modifier_sum(ModifierSum const& owner_modifier_sum); + fixed_point_t get_modifier_effect_value(ModifierEffect const& effect) const; + fixed_point_t get_modifier_effect_value_nullcheck(ModifierEffect const* effect) const; + void update_gamestate(Date today, DefineManager const& define_manager); void tick(Date today); |