aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/country/CountryInstance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/country/CountryInstance.cpp')
-rw-r--r--src/openvic-simulation/country/CountryInstance.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/openvic-simulation/country/CountryInstance.cpp b/src/openvic-simulation/country/CountryInstance.cpp
index 183b0c8..b777cf7 100644
--- a/src/openvic-simulation/country/CountryInstance.cpp
+++ b/src/openvic-simulation/country/CountryInstance.cpp
@@ -41,6 +41,10 @@ CountryInstance::CountryInstance(
controlled_provinces {},
core_provinces {},
states {},
+ base_modifier_sum {},
+ event_modifiers {},
+ static_modifiers {},
+ triggered_modifiers {},
/* Production */
industrial_power { 0 },
@@ -923,6 +927,74 @@ bool CountryInstance::update_rule_set() {
return rule_set.trim_and_resolve_conflicts(true);
}
+void CountryInstance::update_base_modifier_sum(Date today) {
+ std::erase_if(event_modifiers, [today](ModifierInstance const& modifier) -> bool {
+ return modifier.get_expiry_date() < today;
+ });
+
+ // TODO - add/remove static modifiers
+ // TODO - add/remove triggered modifiers
+
+ // Update sum of national modifiers
+ base_modifier_sum.clear();
+
+ for (ModifierInstance const& event_modifier : event_modifiers) {
+ base_modifier_sum += *event_modifier.get_modifier();
+ }
+
+ for (Modifier const* static_modifier : static_modifiers) {
+ base_modifier_sum += *static_modifier;
+ }
+
+ for (TriggeredModifier const* triggered_modifier : triggered_modifiers) {
+ base_modifier_sum += *triggered_modifier;
+ }
+
+ if (ruling_party != nullptr) {
+ for (Issue const* issue : ruling_party->get_policies()) {
+ if (issue != nullptr) {
+ base_modifier_sum += *issue;
+ }
+ }
+ }
+
+ for (Reform const* reform : reforms) {
+ if (reform != nullptr) {
+ base_modifier_sum += *reform;
+ }
+ }
+
+ if (national_value != nullptr) {
+ base_modifier_sum += *national_value;
+ }
+
+ if (tech_school != nullptr) {
+ base_modifier_sum += *tech_school;
+ }
+
+ for (Technology const& technology : *unlocked_technologies.get_keys()) {
+ if (is_technology_unlocked(technology)) {
+ base_modifier_sum += technology;
+ }
+ }
+
+ for (Invention const& invention : *unlocked_inventions.get_keys()) {
+ if (is_invention_unlocked(invention)) {
+ base_modifier_sum += invention;
+ }
+ }
+
+ // Update sum of province base modifiers
+ owned_provinces_modifier_sum.clear();
+
+ for (ProvinceInstance const* province : owned_provinces) {
+ // TODO - filter out local province modifiers before adding them to this sum
+ owned_provinces_modifier_sum += province->get_base_modifier_sum();
+ }
+
+ // TODO - calculate stats for each unit type (locked and unlocked)
+}
+
void CountryInstance::update_gamestate(DefineManager const& define_manager, UnitTypeManager const& unit_type_manager) {
// Order of updates might need to be changed/functions split up to account for dependencies
_update_production(define_manager);
@@ -1167,6 +1239,12 @@ bool CountryInstanceManager::apply_history_to_countries(
return ret;
}
+void CountryInstanceManager::update_base_modifier_sums(Date today) {
+ for (CountryInstance& country : country_instances.get_items()) {
+ country.update_base_modifier_sum(today);
+ }
+}
+
void CountryInstanceManager::update_gamestate(
Date today, DefineManager const& define_manager, UnitTypeManager const& unit_type_manager
) {