From c7eac74bb550c28be9eb75742f25d974b7742634 Mon Sep 17 00:00:00 2001 From: Joel Machens Date: Mon, 2 Oct 2023 21:27:51 -0500 Subject: Initial Government Type Loading --- src/openvic-simulation/dataloader/Dataloader.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/openvic-simulation/dataloader/Dataloader.cpp') diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index 4a98bca..b4b23aa 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -274,17 +274,19 @@ bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_di } bool Dataloader::load_defines(GameManager& game_manager) const { - static const fs::path goods_file = "common/goods.txt"; + static const fs::path map_directory = "map"; static const fs::path pop_type_directory = "poptypes"; - static const fs::path graphical_culture_type_file = "common/graphicalculturetype.txt"; + static const fs::path units_directory = "units"; + + static const fs::path buildings_file = "common/buildings.txt"; static const fs::path culture_file = "common/cultures.txt"; - static const fs::path religion_file = "common/religion.txt"; + static const fs::path goods_file = "common/goods.txt"; + static const fs::path governments_file = "common/governments.txt"; + static const fs::path graphical_culture_type_file = "common/graphicalculturetype.txt"; static const fs::path ideology_file = "common/ideologies.txt"; static const fs::path issues_file = "common/issues.txt"; static const fs::path production_types_file = "common/production_types.txt"; - static const fs::path buildings_file = "common/buildings.txt"; - static const fs::path map_directory = "map"; - static const fs::path units_directory = "units"; + static const fs::path religion_file = "common/religion.txt"; bool ret = true; @@ -316,6 +318,10 @@ bool Dataloader::load_defines(GameManager& game_manager) const { Logger::error("Failed to load ideologies!"); ret = false; } + if (!game_manager.get_government_type_manager().load_government_types_file(_parse_defines(lookup_file(governments_file)).get_file_node())) { + Logger::error("Failed to load government types!"); + ret = false; + } if (!game_manager.get_issue_manager().load_issues_file(_parse_defines(lookup_file(issues_file)).get_file_node())) { Logger::error("Failed to load issues!"); ret = false; -- cgit v1.2.3-56-ga3b1 From 3a691705be925011fac5172c5f2b374262ec2122 Mon Sep 17 00:00:00 2001 From: BrickPi <49528459+BrickPi@users.noreply.github.com> Date: Tue, 3 Oct 2023 10:17:08 -0500 Subject: Finish Government Type Loading --- src/openvic-simulation/dataloader/Dataloader.cpp | 2 +- src/openvic-simulation/politics/Government.cpp | 11 ++++++----- src/openvic-simulation/politics/Government.hpp | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src/openvic-simulation/dataloader/Dataloader.cpp') diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index b4b23aa..fffbb51 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -318,7 +318,7 @@ bool Dataloader::load_defines(GameManager& game_manager) const { Logger::error("Failed to load ideologies!"); ret = false; } - if (!game_manager.get_government_type_manager().load_government_types_file(_parse_defines(lookup_file(governments_file)).get_file_node())) { + if (!game_manager.get_government_type_manager().load_government_types_file(game_manager.get_ideology_manager(), _parse_defines(lookup_file(governments_file)).get_file_node())) { Logger::error("Failed to load government types!"); ret = false; } diff --git a/src/openvic-simulation/politics/Government.cpp b/src/openvic-simulation/politics/Government.cpp index 50f20e6..2874b42 100644 --- a/src/openvic-simulation/politics/Government.cpp +++ b/src/openvic-simulation/politics/Government.cpp @@ -52,9 +52,9 @@ bool GovernmentTypeManager::add_government_type(std::string_view identifier, std return government_types.add_item({ identifier, ideologies, elections, appoint_ruling_party, election_duration, flag_type }); } -bool GovernmentTypeManager::load_government_types_file(ast::NodeCPtr root) { +bool GovernmentTypeManager::load_government_types_file(IdeologyManager& ideology_manager, ast::NodeCPtr root) { bool ret = expect_dictionary( - [this](std::string_view government_type_identifier, ast::NodeCPtr value) -> bool { + [this, &ideology_manager](std::string_view government_type_identifier, ast::NodeCPtr value) -> bool { std::vector ideologies; bool elections = false, appoint_ruling_party = false; uint16_t election_duration = 0; @@ -70,14 +70,15 @@ bool GovernmentTypeManager::load_government_types_file(ast::NodeCPtr root) { )(value); ret &= expect_dictionary( - [this, ideologies](std::string_view key, ast::NodeCPtr value) -> bool { + [this, &ideology_manager, &ideologies](std::string_view key, ast::NodeCPtr value) -> bool { static const std::set> reserved_keys = { "election", "duration", "appoint_ruling_party", "flagType" }; if (reserved_keys.find(key) != reserved_keys.end()) return true; return expect_assign( - [this, ideologies](std::string_view ideology_key, ast::NodeCPtr value) -> bool { - // TODO: grab reference to ideology and shove in vector + [this, &ideology_manager, &ideologies](std::string_view ideology_key, ast::NodeCPtr value) -> bool { + if (ideology_manager.get_ideology_by_identifier(ideology_key) == nullptr) { return false; } + ideologies.push_back(std::string{ideology_key}); return true; } )(value); diff --git a/src/openvic-simulation/politics/Government.hpp b/src/openvic-simulation/politics/Government.hpp index a124780..a3642fb 100644 --- a/src/openvic-simulation/politics/Government.hpp +++ b/src/openvic-simulation/politics/Government.hpp @@ -10,7 +10,7 @@ namespace OpenVic { friend struct GovernmentTypeManager; private: - const std::vector ideologies; + std::vector ideologies; const bool elections, appoint_ruling_party; const uint16_t election_duration; const std::string_view flag_type_identifier; @@ -37,6 +37,6 @@ namespace OpenVic { bool add_government_type(std::string_view identifier, std::vector ideologies, bool elections, bool appoint_ruling_party, uint16_t election_duration, std::string_view flag_type); IDENTIFIER_REGISTRY_ACCESSORS(GovernmentType, government_type) - bool load_government_types_file(ast::NodeCPtr root); + bool load_government_types_file(IdeologyManager& ideology_manager, ast::NodeCPtr root); }; } // namespace OpenVic -- cgit v1.2.3-56-ga3b1