aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent33787f89686cd03a6ae7305bc51add5ac47fbde2 (diff)
feat: ideology loading
Diffstat (limited to 'src')
-rw-r--r--src/openvic-simulation/GameManager.hpp8
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp5
-rw-r--r--src/openvic-simulation/politics/Ideology.cpp50
-rw-r--r--src/openvic-simulation/politics/Ideology.hpp3
4 files changed, 61 insertions, 5 deletions
diff --git a/src/openvic-simulation/GameManager.hpp b/src/openvic-simulation/GameManager.hpp
index d221a99..c932523 100644
--- a/src/openvic-simulation/GameManager.hpp
+++ b/src/openvic-simulation/GameManager.hpp
@@ -1,8 +1,9 @@
#pragma once
-#include "openvic-simulation/GameAdvancementHook.hpp"
-#include "openvic-simulation/economy/Good.hpp"
-#include "openvic-simulation/map/Map.hpp"
+#include "GameAdvancementHook.hpp"
+#include "economy/Good.hpp"
+#include "map/Map.hpp"
+#include "politics/Ideology.hpp"
namespace OpenVic {
struct GameManager {
@@ -12,6 +13,7 @@ namespace OpenVic {
BuildingManager building_manager;
GoodManager good_manager;
PopManager pop_manager;
+ IdeologyManager ideology_manager;
GameAdvancementHook clock;
private:
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index a30983b..45efaec 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -257,6 +257,7 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
static const fs::path graphical_culture_type_file = "common/graphicalculturetype.txt";
static const fs::path culture_file = "common/cultures.txt";
static const fs::path religion_file = "common/religion.txt";
+ static const fs::path ideology_file = "common/ideologies.txt";
static const fs::path map_directory = "map";
bool ret = true;
@@ -281,6 +282,10 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
Logger::error("Failed to load religions!");
ret = false;
}
+ if (!game_manager.ideology_manager.load_ideology_file(_parse_defines(lookup_file(ideology_file)).get_file_node())) {
+ Logger::error("Failed to load ideologies!");
+ ret = false;
+ }
if (!_load_map_dir(game_manager, map_directory)) {
Logger::error("Failed to load map!");
ret = false;
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