aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/openvic-simulation/GameManager.cpp8
-rw-r--r--src/openvic-simulation/GameManager.hpp4
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp18
-rw-r--r--src/openvic-simulation/politics/Government.cpp99
-rw-r--r--src/openvic-simulation/politics/Government.hpp43
5 files changed, 166 insertions, 6 deletions
diff --git a/src/openvic-simulation/GameManager.cpp b/src/openvic-simulation/GameManager.cpp
index 6eeecac..69adaac 100644
--- a/src/openvic-simulation/GameManager.cpp
+++ b/src/openvic-simulation/GameManager.cpp
@@ -30,6 +30,14 @@ GoodManager const& GameManager::get_good_manager() const {
return good_manager;
}
+GovernmentTypeManager& GameManager::get_government_type_manager() {
+ return government_type_manager;
+}
+
+GovernmentTypeManager const& GameManager::get_government_type_manager() const {
+ return government_type_manager;
+}
+
PopManager& GameManager::get_pop_manager() {
return pop_manager;
}
diff --git a/src/openvic-simulation/GameManager.hpp b/src/openvic-simulation/GameManager.hpp
index 99e2fd1..8982e21 100644
--- a/src/openvic-simulation/GameManager.hpp
+++ b/src/openvic-simulation/GameManager.hpp
@@ -2,6 +2,7 @@
#include "openvic-simulation/GameAdvancementHook.hpp"
#include "openvic-simulation/economy/Good.hpp"
+#include "openvic-simulation/politics/Government.hpp"
#include "openvic-simulation/economy/ProductionType.hpp"
#include "openvic-simulation/map/Map.hpp"
#include "openvic-simulation/politics/Ideology.hpp"
@@ -16,6 +17,7 @@ namespace OpenVic {
Map map;
BuildingManager building_manager;
GoodManager good_manager;
+ GovernmentTypeManager government_type_manager;
PopManager pop_manager;
IdeologyManager ideology_manager;
IssueManager issue_manager;
@@ -42,6 +44,8 @@ namespace OpenVic {
BuildingManager const& get_building_manager() const;
GoodManager& get_good_manager();
GoodManager const& get_good_manager() const;
+ GovernmentTypeManager& get_government_type_manager();
+ GovernmentTypeManager const& get_government_type_manager() const;
PopManager& get_pop_manager();
PopManager const& get_pop_manager() const;
IdeologyManager& get_ideology_manager();
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index 4a98bca..fffbb51 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(game_manager.get_ideology_manager(), _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;
diff --git a/src/openvic-simulation/politics/Government.cpp b/src/openvic-simulation/politics/Government.cpp
new file mode 100644
index 0000000..869ac3d
--- /dev/null
+++ b/src/openvic-simulation/politics/Government.cpp
@@ -0,0 +1,99 @@
+#include "Government.hpp"
+
+#include <set>
+
+#include "openvic-simulation/dataloader/NodeTools.hpp"
+#include "openvic-simulation/GameManager.hpp"
+
+using namespace OpenVic;
+using namespace OpenVic::NodeTools;
+
+GovernmentType::GovernmentType(std::string_view new_identifier, std::vector<Ideology const*> new_ideologies, bool new_elections, bool new_appoint_ruling_party, Timespan new_election_duration, std::string_view new_flag_type_identifier)
+ : HasIdentifier { new_identifier }, ideologies { new_ideologies }, elections { new_elections }, appoint_ruling_party { new_appoint_ruling_party }, election_duration { new_election_duration }, flag_type_identifier { new_flag_type_identifier } {}
+
+bool GovernmentType::is_ideology_compatible(Ideology const* ideology) const {
+ return std::find(ideologies.begin(), ideologies.end(), ideology) != ideologies.end();
+}
+
+std::vector<Ideology const*> const& GovernmentType::get_ideologies() const {
+ return ideologies;
+}
+
+bool GovernmentType::holds_elections() const {
+ return elections;
+}
+
+bool GovernmentType::can_appoint_ruling_party() const {
+ return appoint_ruling_party;
+}
+
+Timespan GovernmentType::get_election_duration() const {
+ return election_duration;
+}
+
+std::string_view GovernmentType::get_flag_type() const {
+ return flag_type_identifier;
+}
+
+GovernmentTypeManager::GovernmentTypeManager() : government_types { "government types" } {}
+
+bool GovernmentTypeManager::add_government_type(std::string_view identifier, std::vector<Ideology const*> ideologies, bool elections, bool appoint_ruling_party, Timespan election_duration, std::string_view flag_type) {
+ if (identifier.empty()) {
+ Logger::error("Invalid government type identifier - empty!");
+ return false;
+ }
+
+ if (ideologies.empty()) {
+ Logger::error("No compatible ideologies defined for government type ", identifier);
+ return false;
+ }
+
+ if (elections && election_duration == 0) {
+ Logger::error("No or invalid election duration for government type ", identifier);
+ return false;
+ }
+
+ return government_types.add_item({ identifier, ideologies, elections, appoint_ruling_party, election_duration, flag_type });
+}
+
+/* REQUIREMENTS: FS-525, SIM-27 */
+bool GovernmentTypeManager::load_government_types_file(IdeologyManager const& ideology_manager, ast::NodeCPtr root) {
+ bool ret = expect_dictionary(
+ [this, &ideology_manager](std::string_view government_type_identifier, ast::NodeCPtr value) -> bool {
+ std::vector<Ideology const*> ideologies;
+ bool elections = false, appoint_ruling_party = false;
+ uint16_t election_duration = 0; /* in months */
+ std::string_view flag_type_identifier = "republic";
+
+ bool ret = expect_dictionary_keys(
+ ALLOW_OTHER_KEYS,
+ "election", ONE_EXACTLY, expect_bool(assign_variable_callback(elections)),
+ "duration", ZERO_OR_ONE, expect_uint(assign_variable_callback_uint(election_duration)),
+ "appoint_ruling_party", ONE_EXACTLY, expect_bool(assign_variable_callback(appoint_ruling_party)),
+ "flagType", ZERO_OR_ONE, expect_identifier(assign_variable_callback(flag_type_identifier))
+ )(value);
+
+ ret &= expect_dictionary(
+ [this, &ideology_manager, &ideologies, government_type_identifier](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;
+ Ideology const* ideology = ideology_manager.get_ideology_by_identifier(key);
+ if (ideology == nullptr) {
+ Logger::error("When loading government type ", government_type_identifier, ", specified ideology ", key, " is invalid!");
+ return false;
+ }
+ ideologies.push_back(ideology);
+ return true;
+ }
+ )(value);
+
+ ret &= add_government_type(government_type_identifier, ideologies, elections, appoint_ruling_party, Timespan(election_duration * 30), flag_type_identifier);
+ return ret;
+ }
+ )(root);
+ lock_government_types();
+
+ return ret;
+} \ No newline at end of file
diff --git a/src/openvic-simulation/politics/Government.hpp b/src/openvic-simulation/politics/Government.hpp
new file mode 100644
index 0000000..a8fc00f
--- /dev/null
+++ b/src/openvic-simulation/politics/Government.hpp
@@ -0,0 +1,43 @@
+#pragma once
+
+#include "openvic-simulation/types/IdentifierRegistry.hpp"
+#include "openvic-simulation/politics/Ideology.hpp"
+
+namespace OpenVic {
+ struct GovernmentTypeManager;
+
+ struct GovernmentType : HasIdentifier {
+ friend struct GovernmentTypeManager;
+
+ private:
+ std::vector<Ideology const*> ideologies;
+ const bool elections, appoint_ruling_party;
+ const Timespan election_duration;
+ const std::string flag_type_identifier;
+
+ GovernmentType(std::string_view new_identifier, std::vector<Ideology const*> new_ideologies, bool new_elections, bool new_appoint_ruling_party, Timespan new_election_duration, std::string_view new_flag_type_identifier);
+
+ public:
+ GovernmentType(GovernmentType&&) = default;
+
+ bool is_ideology_compatible(Ideology const* ideology) const;
+ std::vector<Ideology const*> const& get_ideologies() const;
+ bool holds_elections() const;
+ bool can_appoint_ruling_party() const;
+ Timespan get_election_duration() const;
+ std::string_view get_flag_type() const;
+ };
+
+ struct GovernmentTypeManager {
+ private:
+ IdentifierRegistry<GovernmentType> government_types;
+
+ public:
+ GovernmentTypeManager();
+
+ bool add_government_type(std::string_view identifier, std::vector<Ideology const*> ideologies, bool elections, bool appoint_ruling_party, Timespan election_duration, std::string_view flag_type);
+ IDENTIFIER_REGISTRY_ACCESSORS(GovernmentType, government_type)
+
+ bool load_government_types_file(IdeologyManager const& ideology_manager, ast::NodeCPtr root);
+ };
+} // namespace OpenVic