aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation
diff options
context:
space:
mode:
author BrickPi <49528459+BrickPi@users.noreply.github.com>2023-10-03 17:17:08 +0200
committer Joel Machens <ajmach6@gmail.com>2023-10-03 23:55:53 +0200
commit3a691705be925011fac5172c5f2b374262ec2122 (patch)
tree16a62a1f34b1fca3614985119aee87bce93de5dc /src/openvic-simulation
parentc7eac74bb550c28be9eb75742f25d974b7742634 (diff)
Finish Government Type Loading
Diffstat (limited to 'src/openvic-simulation')
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp2
-rw-r--r--src/openvic-simulation/politics/Government.cpp11
-rw-r--r--src/openvic-simulation/politics/Government.hpp4
3 files changed, 9 insertions, 8 deletions
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<std::string> 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<std::string, std::less<void>> 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<std::string> ideologies;
+ std::vector<std::string> 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<std::string> 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