aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/modifier/ModifierEffect.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/ModifierEffect.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/ModifierEffect.cpp')
-rw-r--r--src/openvic-simulation/modifier/ModifierEffect.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/openvic-simulation/modifier/ModifierEffect.cpp b/src/openvic-simulation/modifier/ModifierEffect.cpp
new file mode 100644
index 0000000..2ffb9a5
--- /dev/null
+++ b/src/openvic-simulation/modifier/ModifierEffect.cpp
@@ -0,0 +1,49 @@
+#include "ModifierEffect.hpp"
+
+#include "openvic-simulation/utility/StringUtils.hpp"
+
+using namespace OpenVic;
+
+std::string ModifierEffect::target_to_string(target_t target) {
+ using enum target_t;
+
+ if (target == NO_TARGETS) {
+ return "NO TARGETS";
+ }
+
+ if (target == ALL_TARGETS) {
+ return "ALL TARGETS";
+ }
+
+ static constexpr std::string_view SEPARATOR = " | ";
+
+ std::string ret;
+
+ const auto append_target = [target, &ret](target_t check_target, std::string_view target_str) -> void {
+ if (!ModifierEffect::excludes_targets(target, check_target)) {
+ if (!ret.empty()) {
+ ret += SEPARATOR;
+ }
+ ret += target_str;
+ }
+ };
+
+ append_target(COUNTRY, "COUNTRY");
+ append_target(PROVINCE, "PROVINCE");
+ append_target(UNIT, "UNIT");
+ append_target(~ALL_TARGETS, "INVALID TARGET");
+
+ return ret;
+}
+
+std::string ModifierEffect::make_default_modifier_effect_localisation_key(std::string_view identifier) {
+ return "MODIFIER_" + StringUtils::string_toupper(identifier);
+}
+
+ModifierEffect::ModifierEffect(
+ std::string_view new_identifier, bool new_positive_good, format_t new_format, target_t new_targets,
+ std::string_view new_localisation_key
+) : HasIdentifier { new_identifier }, positive_good { new_positive_good }, format { new_format }, targets { new_targets },
+ localisation_key {
+ new_localisation_key.empty() ? make_default_modifier_effect_localisation_key(new_identifier) : new_localisation_key
+ } {}