aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/politics
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-09-20 11:57:59 +0200
committer zaaarf <zaaarf@proton.me>2023-09-20 11:57:59 +0200
commit63e5866381234d6627174869b7a27770daef20fd (patch)
tree724c593e0f1ad4ad4c133fbbd86db36aa1475f52 /src/openvic-simulation/politics
parent33787f89686cd03a6ae7305bc51add5ac47fbde2 (diff)
feat: ideology loading
Diffstat (limited to 'src/openvic-simulation/politics')
-rw-r--r--src/openvic-simulation/politics/Ideology.cpp50
-rw-r--r--src/openvic-simulation/politics/Ideology.hpp3
2 files changed, 51 insertions, 2 deletions
diff --git a/src/openvic-simulation/politics/Ideology.cpp b/src/openvic-simulation/politics/Ideology.cpp
index be7e645..afd1de9 100644
--- a/src/openvic-simulation/politics/Ideology.cpp
+++ b/src/openvic-simulation/politics/Ideology.cpp
@@ -1,7 +1,7 @@
#include "Ideology.hpp"
-#include "types/IdentifierRegistry.hpp"
using namespace OpenVic;
+using namespace OpenVic::NodeTools;
IdeologyGroup::IdeologyGroup(const std::string_view new_identifier) : HasIdentifier { new_identifier } {}
@@ -45,4 +45,52 @@ bool IdeologyManager::add_ideology(const std::string_view identifier, colour_t c
}
return ideologies.add_item({ identifier, colour, *group, uncivilised, spawn_date });
+}
+
+/* REQUIREMENTS:
+ * POL-9, POL-10, POL-11, POL-12, POL-13, POL-14, POL-15
+*/
+bool IdeologyManager::load_ideology_file(ast::NodeCPtr root) {
+ size_t expected_ideologies = 0;
+ bool ret = expect_dictionary_reserve_length(
+ ideology_groups,
+ [this, &expected_ideologies](std::string_view key, ast::NodeCPtr value) -> bool {
+ bool ret = expect_list_and_length(
+ [&expected_ideologies](size_t size) -> size_t {
+ expected_ideologies += size;
+ return 0;
+ },
+ success_callback
+ )(value);
+ ret &= add_ideology_group(key);
+ return ret;
+ }
+ )(root);
+ lock_ideology_groups();
+
+ ideologies.reserve(ideologies.size() + expected_ideologies);
+ ret &= expect_dictionary(
+ [this](std::string_view ideology_group_key, ast::NodeCPtr ideology_group_value) -> bool {
+ IdeologyGroup const* ideology_group = get_ideology_group_by_identifier(ideology_group_key);
+
+ return expect_dictionary(
+ [this, ideology_group](std::string_view key, ast::NodeCPtr value) -> bool {
+ colour_t colour = NULL_COLOUR;
+ bool uncivilised = true;
+ Date spawn_date;
+
+ bool ret = expect_dictionary_keys(
+ "uncivilized", ZERO_OR_ONE, expect_bool(assign_variable_callback(uncivilised)),
+ "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)),
+ "date", ZERO_OR_ONE, expect_date(assign_variable_callback(spawn_date))
+ )(value);
+ ret &= add_ideology(key, colour, ideology_group, uncivilised, spawn_date);
+ return ret;
+ }
+ )(ideology_group_value);
+ }
+ )(root);
+ lock_ideologies();
+
+ return ret;
} \ No newline at end of file
diff --git a/src/openvic-simulation/politics/Ideology.hpp b/src/openvic-simulation/politics/Ideology.hpp
index b3227f7..137757f 100644
--- a/src/openvic-simulation/politics/Ideology.hpp
+++ b/src/openvic-simulation/politics/Ideology.hpp
@@ -2,6 +2,7 @@
#include "types/Date.hpp"
#include "types/IdentifierRegistry.hpp"
+#include "openvic-simulation/dataloader/NodeTools.hpp"
namespace OpenVic {
struct IdeologyManager;
@@ -48,6 +49,6 @@ namespace OpenVic {
bool add_ideology(const std::string_view identifier, colour_t colour, IdeologyGroup const* group, bool uncivilised, Date spawn_date);
IDENTIFIER_REGISTRY_ACCESSORS_CUSTOM_PLURAL(Ideology, ideology, ideologies)
- //TODO - loaders
+ bool load_ideology_file(ast::NodeCPtr root);
};
} \ No newline at end of file