aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/country
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-09-13 01:11:33 +0200
committer hop311 <hop3114@gmail.com>2024-09-13 01:11:33 +0200
commit81e00e3291834dbae6e70224651bf66198ba154e (patch)
tree071de89f19e8fee2a51c8e5065cb25734a6ed2d1 /src/openvic-simulation/country
parenta424969548083a977480a6be0f078760a5789bbf (diff)
Calculate country and province modifier sums (WIP)
Diffstat (limited to 'src/openvic-simulation/country')
-rw-r--r--src/openvic-simulation/country/CountryInstance.cpp78
-rw-r--r--src/openvic-simulation/country/CountryInstance.hpp9
2 files changed, 87 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
) {
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();
};