aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/politics
diff options
context:
space:
mode:
author Joel Machens <ajmach6@gmail.com>2023-10-15 23:09:21 +0200
committer hop311 <hop3114@gmail.com>2023-10-17 00:33:22 +0200
commitf4f41b6c51ce7a1d719759128b2af92604df5182 (patch)
treebe293fe4b4597b74c9d35143a551a8fb33f80290 /src/openvic-simulation/politics
parentfe319098e49c9841219a9e118a30ebef05eb2c51 (diff)
Add National Values Loading
Diffstat (limited to 'src/openvic-simulation/politics')
-rw-r--r--src/openvic-simulation/politics/NationalValue.cpp38
-rw-r--r--src/openvic-simulation/politics/NationalValue.hpp35
-rw-r--r--src/openvic-simulation/politics/PoliticsManager.hpp4
3 files changed, 77 insertions, 0 deletions
diff --git a/src/openvic-simulation/politics/NationalValue.cpp b/src/openvic-simulation/politics/NationalValue.cpp
new file mode 100644
index 0000000..f1d8a3b
--- /dev/null
+++ b/src/openvic-simulation/politics/NationalValue.cpp
@@ -0,0 +1,38 @@
+#include "NationalValue.hpp"
+
+using namespace OpenVic;
+using namespace OpenVic::NodeTools;
+
+NationalValue::NationalValue(std::string_view new_identifier, ModifierValue&& new_modifiers)
+ : HasIdentifier { new_identifier }, modifiers { std::move(new_modifiers) } {}
+
+ModifierValue const& NationalValue::get_modifiers() const {
+ return modifiers;
+}
+
+NationalValueManager::NationalValueManager() : national_values { "national values" } {}
+
+bool NationalValueManager::add_national_value(std::string_view identifier, ModifierValue&& modifiers) {
+ if (identifier.empty()) {
+ Logger::error("Invalid national value identifier - empty!");
+ return false;
+ }
+
+ return national_values.add_item({ identifier, std::move(modifiers) });
+}
+
+bool NationalValueManager::load_national_values_file(ModifierManager const& modifier_manager, ast::NodeCPtr root) {
+ bool ret = expect_dictionary(
+ [this, &modifier_manager](std::string_view national_value_identifier, ast::NodeCPtr value) -> bool {
+ ModifierValue modifiers;
+
+ bool ret = modifier_manager.expect_modifier_value(move_variable_callback(modifiers))(value);
+
+ ret &= add_national_value(national_value_identifier, std::move(modifiers));
+ return ret;
+ }
+ )(root);
+ lock_national_values();
+
+ return ret;
+}
diff --git a/src/openvic-simulation/politics/NationalValue.hpp b/src/openvic-simulation/politics/NationalValue.hpp
new file mode 100644
index 0000000..09ef85e
--- /dev/null
+++ b/src/openvic-simulation/politics/NationalValue.hpp
@@ -0,0 +1,35 @@
+#pragma once
+
+#include "openvic-simulation/Modifier.hpp"
+#include "openvic-simulation/types/IdentifierRegistry.hpp"
+
+namespace OpenVic {
+ struct NationalValueManager;
+
+ struct NationalValue : HasIdentifier {
+ friend struct NationalValueManager;
+
+ private:
+ const ModifierValue modifiers;
+
+ NationalValue(std::string_view new_identifier, ModifierValue&& new_modifiers);
+
+ public:
+ NationalValue(NationalValue&&) = default;
+
+ ModifierValue const& get_modifiers() const;
+ };
+
+ struct NationalValueManager {
+ private:
+ IdentifierRegistry<NationalValue> national_values;
+
+ public:
+ NationalValueManager();
+
+ bool add_national_value(std::string_view identifier, ModifierValue&& modifiers);
+ IDENTIFIER_REGISTRY_ACCESSORS(national_value)
+
+ bool load_national_values_file(ModifierManager const& modifier_manager, ast::NodeCPtr root);
+ };
+} // namespace OpenVic
diff --git a/src/openvic-simulation/politics/PoliticsManager.hpp b/src/openvic-simulation/politics/PoliticsManager.hpp
index 9072d72..1423cf7 100644
--- a/src/openvic-simulation/politics/PoliticsManager.hpp
+++ b/src/openvic-simulation/politics/PoliticsManager.hpp
@@ -3,6 +3,7 @@
#include "openvic-simulation/politics/Government.hpp"
#include "openvic-simulation/politics/Ideology.hpp"
#include "openvic-simulation/politics/Issue.hpp"
+#include "openvic-simulation/politics/NationalValue.hpp"
namespace OpenVic {
struct PoliticsManager {
@@ -10,10 +11,13 @@ namespace OpenVic {
GovernmentTypeManager government_type_manager;
IdeologyManager ideology_manager;
IssueManager issue_manager;
+ NationalValueManager national_value_manager;
+
public:
REF_GETTERS(government_type_manager)
REF_GETTERS(ideology_manager)
REF_GETTERS(issue_manager)
+ REF_GETTERS(national_value_manager)
inline bool load_government_types_file(ast::NodeCPtr root) {
return government_type_manager.load_government_types_file(ideology_manager, root);