aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/modifier/StaticModifierCache.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-10-20 20:44:51 +0200
committer GitHub <noreply@github.com>2024-10-20 20:44:51 +0200
commit6527f832a5e14a28fc1f5b85628541038eb90141 (patch)
treeaca829171be7b1144cb3ca29510593fa8a84af24 /src/openvic-simulation/modifier/StaticModifierCache.cpp
parent9a84e7af70f2528578b00879e568bca285563e9b (diff)
parent5194a3d043db66b81470111a94f3b1cdf8d42176 (diff)
Merge pull request #198 from OpenVicProject/resultant-modifier
Calculate country and province modifier sums
Diffstat (limited to 'src/openvic-simulation/modifier/StaticModifierCache.cpp')
-rw-r--r--src/openvic-simulation/modifier/StaticModifierCache.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/openvic-simulation/modifier/StaticModifierCache.cpp b/src/openvic-simulation/modifier/StaticModifierCache.cpp
new file mode 100644
index 0000000..b03d827
--- /dev/null
+++ b/src/openvic-simulation/modifier/StaticModifierCache.cpp
@@ -0,0 +1,115 @@
+#include "StaticModifierCache.hpp"
+
+#include "openvic-simulation/modifier/ModifierManager.hpp"
+
+using namespace OpenVic;
+
+StaticModifierCache::StaticModifierCache()
+ : // Country modifiers
+ very_easy_player { nullptr },
+ easy_player { nullptr },
+ hard_player { nullptr },
+ very_hard_player { nullptr },
+ very_easy_ai { nullptr },
+ easy_ai { nullptr },
+ hard_ai { nullptr },
+ very_hard_ai { nullptr },
+ base_modifier { nullptr },
+ war { nullptr },
+ peace { nullptr },
+ disarming { nullptr },
+ war_exhaustion { nullptr },
+ infamy { nullptr },
+ debt_default_to { nullptr },
+ bad_debter { nullptr },
+ great_power { nullptr },
+ secondary_power { nullptr },
+ civilised { nullptr },
+ uncivilised { nullptr },
+ literacy { nullptr },
+ plurality { nullptr },
+ generalised_debt_default { nullptr },
+ total_occupation { nullptr },
+ total_blockaded { nullptr },
+ in_bankruptcy { nullptr },
+ // Province modifiers
+ overseas { nullptr },
+ coastal { nullptr },
+ non_coastal { nullptr },
+ coastal_sea { nullptr },
+ sea_zone { nullptr },
+ land_province { nullptr },
+ blockaded { nullptr },
+ no_adjacent_controlled { nullptr },
+ core { nullptr },
+ has_siege { nullptr },
+ occupied { nullptr },
+ nationalism { nullptr },
+ infrastructure { nullptr } {}
+
+bool StaticModifierCache::load_static_modifiers(ModifierManager& modifier_manager) {
+ bool ret = true;
+
+ const auto set_static_modifier = [&modifier_manager, &ret](
+ Modifier const*& modifier, std::string_view name, fixed_point_t multiplier = 1
+ ) -> void {
+ Modifier* mutable_modifier = modifier_manager.static_modifiers.get_item_by_identifier(name);
+
+ if (mutable_modifier != nullptr) {
+ if (multiplier != fixed_point_t::_1()) {
+ *mutable_modifier *= multiplier;
+ }
+
+ modifier = mutable_modifier;
+ } else {
+ Logger::error("Failed to set static modifier: ", name);
+ ret = false;
+ }
+ };
+
+ // Country modifiers
+ set_static_modifier(very_easy_player, "very_easy_player");
+ set_static_modifier(easy_player, "easy_player");
+ set_static_modifier(hard_player, "hard_player");
+ set_static_modifier(very_hard_player, "very_hard_player");
+ set_static_modifier(very_easy_ai, "very_easy_ai");
+ set_static_modifier(easy_ai, "easy_ai");
+ set_static_modifier(hard_ai, "hard_ai");
+ set_static_modifier(very_hard_ai, "very_hard_ai");
+
+ set_static_modifier(base_modifier, "base_values");
+ set_static_modifier(war, "war");
+ set_static_modifier(peace, "peace");
+ set_static_modifier(disarming, "disarming");
+ set_static_modifier(war_exhaustion, "war_exhaustion");
+ set_static_modifier(infamy, "badboy");
+ set_static_modifier(debt_default_to, "debt_default_to");
+ set_static_modifier(bad_debter, "bad_debter");
+ set_static_modifier(great_power, "great_power");
+ set_static_modifier(secondary_power, "second_power");
+ set_static_modifier(civilised, "civ_nation");
+ set_static_modifier(uncivilised, "unciv_nation");
+ set_static_modifier(literacy, "average_literacy");
+ set_static_modifier(plurality, "plurality");
+ set_static_modifier(generalised_debt_default, "generalised_debt_default");
+ set_static_modifier(total_occupation, "total_occupation", 100);
+ set_static_modifier(total_blockaded, "total_blockaded");
+ set_static_modifier(in_bankruptcy, "in_bankrupcy");
+
+ // Province modifiers
+ set_static_modifier(overseas, "overseas");
+ set_static_modifier(coastal, "coastal");
+ set_static_modifier(non_coastal, "non_coastal");
+ set_static_modifier(coastal_sea, "coastal_sea");
+ set_static_modifier(sea_zone, "sea_zone");
+ set_static_modifier(land_province, "land_province");
+ set_static_modifier(blockaded, "blockaded");
+ set_static_modifier(no_adjacent_controlled, "no_adjacent_controlled");
+ set_static_modifier(core, "core");
+ set_static_modifier(has_siege, "has_siege");
+ set_static_modifier(occupied, "occupied");
+ set_static_modifier(nationalism, "nationalism");
+ set_static_modifier(infrastructure, "infrastructure");
+
+ return ret;
+}