diff options
author | hop311 <hop3114@gmail.com> | 2024-09-13 01:11:33 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-09-13 01:11:33 +0200 |
commit | 81e00e3291834dbae6e70224651bf66198ba154e (patch) | |
tree | 071de89f19e8fee2a51c8e5065cb25734a6ed2d1 /src | |
parent | a424969548083a977480a6be0f078760a5789bbf (diff) |
Calculate country and province modifier sums (WIP)
Diffstat (limited to 'src')
-rw-r--r-- | src/openvic-simulation/InstanceManager.cpp | 7 | ||||
-rw-r--r-- | src/openvic-simulation/country/CountryInstance.cpp | 78 | ||||
-rw-r--r-- | src/openvic-simulation/country/CountryInstance.hpp | 9 | ||||
-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 | 44 | ||||
-rw-r--r-- | src/openvic-simulation/map/ProvinceInstance.hpp | 5 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Modifier.cpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Modifier.hpp | 5 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Rule.cpp | 2 |
10 files changed, 156 insertions, 5 deletions
diff --git a/src/openvic-simulation/InstanceManager.cpp b/src/openvic-simulation/InstanceManager.cpp index c9ce24a..27ce8a4 100644 --- a/src/openvic-simulation/InstanceManager.cpp +++ b/src/openvic-simulation/InstanceManager.cpp @@ -39,6 +39,13 @@ void InstanceManager::update_gamestate() { Logger::info("Update: ", today); + map_instance.update_base_modifier_sums(today); + country_instance_manager.update_base_modifier_sums(today); + + // TODO - combine base country modifier sums + province total sums back into each individual province, + // after filtering out local province modifiers that don't apply to the country/other provinces and country + // modifiers which don't apply to provinces. + // Update gamestate... map_instance.update_gamestate(today, definition_manager.get_define_manager()); country_instance_manager.update_gamestate( 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 ) { diff --git a/src/openvic-simulation/country/CountryInstance.hpp b/src/openvic-simulation/country/CountryInstance.hpp index a7128aa..4156a39 100644 --- a/src/openvic-simulation/country/CountryInstance.hpp +++ b/src/openvic-simulation/country/CountryInstance.hpp @@ -80,6 +80,12 @@ namespace OpenVic { ordered_set<ProvinceInstance*> PROPERTY(core_provinces); ordered_set<State*> PROPERTY(states); + ModifierValue PROPERTY(base_modifier_sum); + ModifierValue PROPERTY(owned_provinces_modifier_sum); + std::vector<ModifierInstance> PROPERTY(event_modifiers); + std::vector<Modifier const*> PROPERTY(static_modifiers); + std::vector<TriggeredModifier const*> PROPERTY(triggered_modifiers); + /* Production */ fixed_point_t PROPERTY(industrial_power); std::vector<std::pair<State const*, fixed_point_t>> PROPERTY(industrial_power_from_states); @@ -174,6 +180,7 @@ namespace OpenVic { unlock_level_t PROPERTY(gas_attack_unlock_level); unlock_level_t PROPERTY(gas_defence_unlock_level); std::vector<unlock_level_t> PROPERTY(unit_variant_unlock_levels); + // TODO - stats for each unit type UNIT_BRANCHED_GETTER(get_unit_instance_groups, armies, navies); UNIT_BRANCHED_GETTER(get_leaders, generals, admirals); @@ -296,6 +303,7 @@ namespace OpenVic { public: + void update_base_modifier_sum(Date today); void update_gamestate(DefineManager const& define_manager, UnitTypeManager const& unit_type_manager); void tick(); }; @@ -341,6 +349,7 @@ namespace OpenVic { MapInstance& map_instance ); + void update_base_modifier_sums(Date today); void update_gamestate(Date today, DefineManager const& define_manager, UnitTypeManager const& unit_type_manager); void tick(); }; diff --git a/src/openvic-simulation/map/MapInstance.cpp b/src/openvic-simulation/map/MapInstance.cpp index 0ce8cea..4df755e 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_base_modifier_sums(Date today) { + for (ProvinceInstance& province : province_instances.get_items()) { + province.update_base_modifier_sum(today); + } +} + 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..f7a85fb 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_base_modifier_sums(Date today); 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..e2e4921 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,9 @@ ProvinceInstance::ProvinceInstance( owner { nullptr }, controller { nullptr }, cores {}, + base_modifier_sum {}, + event_modifiers {}, + static_modifiers {}, slave { false }, crime { nullptr }, rgo { nullptr }, @@ -185,6 +191,44 @@ void ProvinceInstance::_update_pops(DefineManager const& define_manager) { } } +void ProvinceInstance::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 + + 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 (BuildingInstance const& building : buildings.get_items()) { + base_modifier_sum += building.get_building_type(); + } + + if (crime != nullptr) { + base_modifier_sum += *crime; + } + + if (province_definition.get_continent() != nullptr) { + base_modifier_sum += *province_definition.get_continent(); + } + + if (province_definition.get_climate() != nullptr) { + base_modifier_sum += *province_definition.get_climate(); + } + + if (terrain_type != nullptr) { + base_modifier_sum += *terrain_type; + } +} + 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..8201483 100644 --- a/src/openvic-simulation/map/ProvinceInstance.hpp +++ b/src/openvic-simulation/map/ProvinceInstance.hpp @@ -68,6 +68,10 @@ namespace OpenVic { CountryInstance* PROPERTY(controller); ordered_set<CountryInstance*> PROPERTY(cores); + ModifierValue PROPERTY(base_modifier_sum); + std::vector<ModifierInstance> PROPERTY(event_modifiers); + std::vector<Modifier const*> PROPERTY(static_modifiers); + bool PROPERTY(slave); Crime const* PROPERTY_RW(crime); // TODO - change this into a factory-like structure @@ -124,6 +128,7 @@ namespace OpenVic { bool add_pop_vec(std::vector<PopBase> const& pop_vec); size_t get_pop_count() const; + void update_base_modifier_sum(Date today); void update_gamestate(Date today, DefineManager const& define_manager); void tick(Date today); diff --git a/src/openvic-simulation/misc/Modifier.cpp b/src/openvic-simulation/misc/Modifier.cpp index 9163af5..cbf6250 100644 --- a/src/openvic-simulation/misc/Modifier.cpp +++ b/src/openvic-simulation/misc/Modifier.cpp @@ -102,8 +102,8 @@ bool TriggeredModifier::parse_scripts(DefinitionManager const& definition_manage return trigger.parse_script(false, definition_manager); } -ModifierInstance::ModifierInstance(Modifier const& modifier, Date expiry_date) - : modifier { modifier }, expiry_date { expiry_date } {} +ModifierInstance::ModifierInstance(Modifier const& new_modifier, Date new_expiry_date) + : modifier { &new_modifier }, expiry_date { new_expiry_date } {} bool ModifierManager::add_modifier_effect(std::string_view identifier, bool positive_good, ModifierEffect::format_t format) { if (identifier.empty()) { diff --git a/src/openvic-simulation/misc/Modifier.hpp b/src/openvic-simulation/misc/Modifier.hpp index bd72a1e..a087d8d 100644 --- a/src/openvic-simulation/misc/Modifier.hpp +++ b/src/openvic-simulation/misc/Modifier.hpp @@ -102,10 +102,11 @@ namespace OpenVic { struct ModifierInstance { private: - Modifier const& PROPERTY(modifier); + Modifier const* PROPERTY(modifier); // We can assume this is never null Date PROPERTY(expiry_date); - ModifierInstance(Modifier const& modifier, Date expiry_date); + public: + ModifierInstance(Modifier const& new_modifier, Date new_expiry_date); }; template<typename Fn> diff --git a/src/openvic-simulation/politics/Rule.cpp b/src/openvic-simulation/politics/Rule.cpp index 1d61652..d8c8c75 100644 --- a/src/openvic-simulation/politics/Rule.cpp +++ b/src/openvic-simulation/politics/Rule.cpp @@ -159,7 +159,7 @@ bool RuleManager::setup_rules(BuildingTypeManager const& building_type_manager) "expand_factory", "open_factory", "destroy_factory", "pop_build_factory", "pop_expand_factory", "pop_open_factory", "can_subsidise", "factory_priority", "delete_factory_if_no_input", "build_factory_invest", "expand_factory_invest", "open_factory_invest", "build_railway_invest", "pop_build_factory_invest", "pop_expand_factory_invest", - "can_invest_in_pop_projects", "allow_foreign_investment" + "pop_open_factory_invest", "can_invest_in_pop_projects", "allow_foreign_investment" } }, { CITIZENSHIP, { "primary_culture_voting", "culture_voting", "all_voting" } }, { SLAVERY, { "slavery_allowed" } }, |