aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/politics
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/politics')
-rw-r--r--src/openvic-simulation/politics/Government.hpp4
-rw-r--r--src/openvic-simulation/politics/Ideology.hpp2
-rw-r--r--src/openvic-simulation/politics/Issue.hpp4
-rw-r--r--src/openvic-simulation/politics/PoliticsManager.hpp18
-rw-r--r--src/openvic-simulation/politics/Rebel.cpp138
-rw-r--r--src/openvic-simulation/politics/Rebel.hpp81
6 files changed, 231 insertions, 16 deletions
diff --git a/src/openvic-simulation/politics/Government.hpp b/src/openvic-simulation/politics/Government.hpp
index fde7d32..0bc777a 100644
--- a/src/openvic-simulation/politics/Government.hpp
+++ b/src/openvic-simulation/politics/Government.hpp
@@ -10,8 +10,8 @@ namespace OpenVic {
private:
const std::vector<Ideology const*> PROPERTY(ideologies);
- const bool PROPERTY_CUSTOM_NAME(elections, holds_elections);
- const bool PROPERTY_CUSTOM_NAME(appoint_ruling_party, can_appoint_ruling_party);
+ const bool PROPERTY_CUSTOM_PREFIX(elections, holds);
+ const bool PROPERTY_CUSTOM_PREFIX(appoint_ruling_party, can);
const Timespan PROPERTY(term_duration);
const std::string PROPERTY_CUSTOM_NAME(flag_type_identifier, get_flag_type);
diff --git a/src/openvic-simulation/politics/Ideology.hpp b/src/openvic-simulation/politics/Ideology.hpp
index 47ae45b..dd3f07a 100644
--- a/src/openvic-simulation/politics/Ideology.hpp
+++ b/src/openvic-simulation/politics/Ideology.hpp
@@ -20,7 +20,7 @@ namespace OpenVic {
private:
IdeologyGroup const& PROPERTY(group);
- const bool PROPERTY_CUSTOM_NAME(uncivilised, is_uncivilised);
+ const bool PROPERTY_CUSTOM_PREFIX(uncivilised, is);
const bool PROPERTY(can_reduce_militancy);
const Date PROPERTY(spawn_date);
diff --git a/src/openvic-simulation/politics/Issue.hpp b/src/openvic-simulation/politics/Issue.hpp
index 0dceae9..e9d154f 100644
--- a/src/openvic-simulation/politics/Issue.hpp
+++ b/src/openvic-simulation/politics/Issue.hpp
@@ -56,8 +56,8 @@ namespace OpenVic {
private:
ReformType const& PROPERTY(type);
- const bool PROPERTY_CUSTOM_NAME(ordered, is_ordered); // next_step_only
- const bool PROPERTY_CUSTOM_NAME(administrative, is_administrative);
+ const bool PROPERTY_CUSTOM_PREFIX(ordered, is); // next_step_only
+ const bool PROPERTY_CUSTOM_PREFIX(administrative, is);
ReformGroup(std::string_view identifier, ReformType const& type, bool ordered, bool administrative);
diff --git a/src/openvic-simulation/politics/PoliticsManager.hpp b/src/openvic-simulation/politics/PoliticsManager.hpp
index b30d1c0..4f62124 100644
--- a/src/openvic-simulation/politics/PoliticsManager.hpp
+++ b/src/openvic-simulation/politics/PoliticsManager.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "Rebel.hpp"
#include "openvic-simulation/politics/Government.hpp"
#include "openvic-simulation/politics/Ideology.hpp"
#include "openvic-simulation/politics/Issue.hpp"
@@ -9,19 +10,14 @@
namespace OpenVic {
struct PoliticsManager {
private:
- GovernmentTypeManager government_type_manager;
- IdeologyManager ideology_manager;
- IssueManager issue_manager;
- NationalValueManager national_value_manager;
- NationalFocusManager national_focus_manager;
+ GovernmentTypeManager PROPERTY_REF(government_type_manager);
+ IdeologyManager PROPERTY_REF(ideology_manager);
+ IssueManager PROPERTY_REF(issue_manager);
+ NationalValueManager PROPERTY_REF(national_value_manager);
+ NationalFocusManager PROPERTY_REF(national_focus_manager);
+ RebelManager PROPERTY_REF(rebel_manager);
public:
- REF_GETTERS(government_type_manager)
- REF_GETTERS(ideology_manager)
- REF_GETTERS(issue_manager)
- REF_GETTERS(national_value_manager)
- REF_GETTERS(national_focus_manager)
-
inline bool load_government_types_file(ast::NodeCPtr root) {
return government_type_manager.load_government_types_file(ideology_manager, root);
}
diff --git a/src/openvic-simulation/politics/Rebel.cpp b/src/openvic-simulation/politics/Rebel.cpp
new file mode 100644
index 0000000..cc0514c
--- /dev/null
+++ b/src/openvic-simulation/politics/Rebel.cpp
@@ -0,0 +1,138 @@
+#include "Rebel.hpp"
+
+using namespace OpenVic;
+using namespace OpenVic::NodeTools;
+
+RebelType::RebelType(std::string_view new_identifier, RebelType::icon_t icon, RebelType::area_t area, bool break_alliance_on_win,
+ RebelType::government_map_t desired_governments, RebelType::defection_t defection, RebelType::independence_t independence, uint16_t defect_delay,
+ Ideology const* ideology, bool allow_all_cultures, bool allow_all_culture_groups, bool allow_all_religions, bool allow_all_ideologies, bool resilient,
+ bool reinforcing, bool general, bool smart, bool unit_transfer, fixed_point_t occupation_mult)
+: HasIdentifier { new_identifier }, icon { icon }, area { area }, break_alliance_on_win { break_alliance_on_win },
+ desired_governments { std::move(desired_governments) }, defection { defection }, independence { independence }, defect_delay { defect_delay },
+ ideology { ideology }, allow_all_cultures { allow_all_cultures }, allow_all_culture_groups { allow_all_culture_groups },
+ allow_all_religions { allow_all_religions }, allow_all_ideologies { allow_all_ideologies }, resilient { resilient }, reinforcing { reinforcing },
+ general { general }, smart { smart }, unit_transfer { unit_transfer }, occupation_mult { occupation_mult } {}
+
+RebelManager::RebelManager() : rebel_types { "rebel types" } {}
+
+bool RebelManager::add_rebel_type(
+ std::string_view new_identifier, RebelType::icon_t icon, RebelType::area_t area, bool break_alliance_on_win, RebelType::government_map_t desired_governments,
+ RebelType::defection_t defection, RebelType::independence_t independence, uint16_t defect_delay, Ideology const* ideology, bool allow_all_cultures,
+ bool allow_all_culture_groups, bool allow_all_religions, bool allow_all_ideologies, bool resilient, bool reinforcing, bool general, bool smart, bool unit_transfer,
+ fixed_point_t occupation_mult) {
+
+ if (new_identifier.empty()) {
+ Logger::error("Invalid rebel type identifier - empty!");
+ return false;
+ }
+
+ return rebel_types.add_item({
+ new_identifier, icon, area, break_alliance_on_win, desired_governments, defection, independence, defect_delay, ideology,
+ allow_all_cultures, allow_all_culture_groups, allow_all_religions, allow_all_ideologies, resilient, reinforcing, general,
+ smart, unit_transfer, occupation_mult
+ });
+}
+
+bool RebelManager::load_rebels_file(IdeologyManager const& ideology_manager, GovernmentTypeManager const& government_type_manager, ast::NodeCPtr root) {
+ static const string_map_t<RebelType::area_t> area_map = {
+ { "nation", RebelType::area_t::NATION },
+ { "nation_religion", RebelType::area_t::NATION_RELIGION },
+ { "nation_culture", RebelType::area_t::NATION_CULTURE },
+ { "culture", RebelType::area_t::CULTURE },
+ { "culture_group", RebelType::area_t::CULTURE_GROUP },
+ { "religion", RebelType::area_t::RELIGION },
+ { "all", RebelType::area_t::ALL }
+ };
+
+ static const string_map_t<RebelType::defection_t> defection_map = {
+ { "none", RebelType::defection_t::NONE },
+ { "culture", RebelType::defection_t::CULTURE },
+ { "culture_group", RebelType::defection_t::CULTURE_GROUP },
+ { "religion", RebelType::defection_t::RELIGION },
+ { "ideology", RebelType::defection_t::IDEOLOGY },
+ { "pan_nationalist", RebelType::defection_t::PAN_NATIONALIST },
+ { "any", RebelType::defection_t::ANY }
+ };
+
+ static const string_map_t<RebelType::independence_t> independence_map = {
+ { "none", RebelType::independence_t::NONE },
+ { "culture", RebelType::independence_t::CULTURE },
+ { "culture_group", RebelType::independence_t::CULTURE_GROUP },
+ { "religion", RebelType::independence_t::RELIGION },
+ { "colonial", RebelType::independence_t::COLONIAL },
+ { "pan_nationalist", RebelType::independence_t::PAN_NATIONALIST },
+ { "any", RebelType::independence_t::ANY }
+ };
+
+ bool ret = expect_dictionary(
+ [this, &ideology_manager, &government_type_manager](std::string_view identifier, ast::NodeCPtr node) -> bool {
+ RebelType::icon_t icon;
+ RebelType::area_t area;
+ RebelType::government_map_t desired_governments;
+ RebelType::defection_t defection;
+ RebelType::independence_t independence;
+ uint16_t defect_delay;
+ std::string_view ideology_identifier;
+ bool break_alliance_on_win, allow_all_cultures, allow_all_culture_groups, allow_all_religions, allow_all_ideologies, resilient, reinforcing, general, smart, unit_transfer;
+ fixed_point_t occupation_mult;
+
+ bool ret = expect_dictionary_keys(
+ "icon", ONE_EXACTLY, expect_uint(assign_variable_callback(icon)),
+ "area", ONE_EXACTLY, expect_identifier(expect_mapped_string(area_map, assign_variable_callback(area))),
+ "break_alliance_on_win", ZERO_OR_ONE, expect_bool(assign_variable_callback(break_alliance_on_win)),
+ "government", ONE_EXACTLY, expect_dictionary([this, &government_type_manager, &desired_governments](std::string_view key, ast::NodeCPtr value) -> bool {
+ bool ret = true;
+
+ GovernmentType const* from = government_type_manager.get_government_type_by_identifier(key);
+ ret &= from != nullptr; //invalid from
+
+ std::string_view to_identifier;
+ ret &= expect_identifier(assign_variable_callback(to_identifier))(value);
+
+ GovernmentType const* to = government_type_manager.get_government_type_by_identifier(to_identifier);
+ ret &= to != nullptr; //invalid to
+
+ if (desired_governments.contains(from)) ret = false; //duplicate
+ else if (ret) desired_governments.emplace(from, to); //only proceed if both values are valid
+
+ return ret;
+ }),
+ "defection", ONE_EXACTLY, expect_identifier(expect_mapped_string(defection_map, assign_variable_callback(defection))),
+ "independence", ONE_EXACTLY, expect_identifier(expect_mapped_string(independence_map, assign_variable_callback(independence))),
+ "defect_delay", ONE_EXACTLY, expect_uint(assign_variable_callback(defect_delay)),
+ "ideology", ZERO_OR_ONE, expect_identifier(assign_variable_callback(ideology_identifier)),
+ "allow_all_cultures", ONE_EXACTLY, expect_bool(assign_variable_callback(allow_all_cultures)),
+ "allow_all_culture_groups", ZERO_OR_ONE, expect_bool(assign_variable_callback(allow_all_culture_groups)),
+ "allow_all_religions", ONE_EXACTLY, expect_bool(assign_variable_callback(allow_all_religions)),
+ "allow_all_ideologies", ONE_EXACTLY, expect_bool(assign_variable_callback(allow_all_ideologies)),
+ "resilient", ONE_EXACTLY, expect_bool(assign_variable_callback(resilient)),
+ "reinforcing", ONE_EXACTLY, expect_bool(assign_variable_callback(reinforcing)),
+ "general", ONE_EXACTLY, expect_bool(assign_variable_callback(general)),
+ "smart", ONE_EXACTLY, expect_bool(assign_variable_callback(smart)),
+ "unit_transfer", ONE_EXACTLY, expect_bool(assign_variable_callback(unit_transfer)),
+ "occupation_mult", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(occupation_mult)),
+ "will_rise", ONE_EXACTLY, success_callback, //TODO
+ "spawn_chance", ONE_EXACTLY, success_callback, //TODO
+ "movement_evaluation", ONE_EXACTLY, success_callback, //TODO
+ "siege_won_trigger", ZERO_OR_ONE, success_callback, //TODO
+ "siege_won_effect", ZERO_OR_ONE, success_callback, //TODO
+ "demands_enforced_trigger", ZERO_OR_ONE, success_callback, //TODO
+ "demands_enforced_effect", ZERO_OR_ONE, success_callback //TODO
+ )(node);
+
+ Ideology const* ideology = ideology_manager.get_ideology_by_identifier(ideology_identifier);
+
+ ret &= add_rebel_type(
+ identifier, icon, area, break_alliance_on_win, desired_governments, defection, independence,defect_delay,
+ ideology, allow_all_cultures, allow_all_culture_groups, allow_all_religions, allow_all_ideologies, resilient, reinforcing,
+ general, smart, unit_transfer, occupation_mult
+ );
+
+ return ret;
+ }
+ )(root);
+
+ lock_rebel_types();
+
+ return ret;
+} \ No newline at end of file
diff --git a/src/openvic-simulation/politics/Rebel.hpp b/src/openvic-simulation/politics/Rebel.hpp
new file mode 100644
index 0000000..791e95b
--- /dev/null
+++ b/src/openvic-simulation/politics/Rebel.hpp
@@ -0,0 +1,81 @@
+#pragma once
+
+#include "openvic-simulation/types/IdentifierRegistry.hpp"
+#include "openvic-simulation/politics/Government.hpp"
+#include "openvic-simulation/politics/Ideology.hpp"
+#include <cstdint>
+#include <unordered_map>
+
+namespace OpenVic {
+ struct RebelManager;
+
+ struct RebelType : HasIdentifier {
+ friend struct RebelManager;
+
+ using government_map_t = std::unordered_map<GovernmentType const*, GovernmentType const*>;
+ using icon_t = uint16_t;
+
+ enum class area_t {
+ NATION, NATION_RELIGION, NATION_CULTURE,
+ CULTURE, CULTURE_GROUP, RELIGION, ALL
+ };
+
+ enum class defection_t {
+ NONE, CULTURE, CULTURE_GROUP, RELIGION,
+ IDEOLOGY, PAN_NATIONALIST, ANY
+ };
+
+ enum class independence_t {
+ NONE, CULTURE, CULTURE_GROUP, RELIGION,
+ COLONIAL, PAN_NATIONALIST, ANY
+ };
+
+ private:
+ const icon_t PROPERTY(icon);
+ const area_t PROPERTY(area);
+ const bool PROPERTY_CUSTOM_PREFIX(break_alliance_on_win, will);
+ government_map_t PROPERTY(desired_governments); //government
+ const defection_t PROPERTY_CUSTOM_NAME(defection, get_defection_type);
+ const independence_t PROPERTY_CUSTOM_NAME(independence, get_independence_type);
+ const uint16_t PROPERTY(defect_delay);
+ Ideology const* PROPERTY(ideology);
+ const bool PROPERTY_CUSTOM_PREFIX(allow_all_cultures, will);
+ const bool PROPERTY_CUSTOM_PREFIX(allow_all_culture_groups, will);
+ const bool PROPERTY_CUSTOM_PREFIX(allow_all_religions, will);
+ const bool PROPERTY_CUSTOM_PREFIX(allow_all_ideologies, will);
+ const bool PROPERTY_CUSTOM_PREFIX(resilient, is);
+ const bool PROPERTY_CUSTOM_PREFIX(reinforcing, is);
+ const bool PROPERTY_CUSTOM_PREFIX(general, can_have);
+ const bool PROPERTY_CUSTOM_PREFIX(smart, is);
+ const bool PROPERTY_CUSTOM_NAME(unit_transfer, will_transfer_units);
+ const fixed_point_t PROPERTY(occupation_mult);
+
+ RebelType(
+ std::string_view new_identifier, RebelType::icon_t icon, RebelType::area_t area, bool break_alliance_on_win,
+ RebelType::government_map_t desired_governments, RebelType::defection_t defection, RebelType::independence_t independence, uint16_t defect_delay,
+ Ideology const* ideology, bool allow_all_cultures, bool allow_all_culture_groups, bool allow_all_religions, bool allow_all_ideologies, bool resilient,
+ bool reinforcing, bool general, bool smart, bool unit_transfer, fixed_point_t occupation_mult
+ );
+
+ public:
+ RebelType(RebelType&&) = default;
+ };
+
+ struct RebelManager {
+ private:
+ IdentifierRegistry<RebelType> rebel_types;
+
+ public:
+ RebelManager();
+
+ IDENTIFIER_REGISTRY_ACCESSORS(rebel_type)
+ bool add_rebel_type(
+ std::string_view new_identifier, RebelType::icon_t icon, RebelType::area_t area, bool break_alliance_on_win,
+ RebelType::government_map_t desired_governments, RebelType::defection_t defection, RebelType::independence_t independence, uint16_t defect_delay,
+ Ideology const* ideology, bool allow_all_cultures, bool allow_all_culture_groups, bool allow_all_religions, bool allow_all_ideologies, bool resilient,
+ bool reinforcing, bool general, bool smart, bool unit_transfer, fixed_point_t occupation_mult
+ );
+
+ bool load_rebels_file(IdeologyManager const& ideology_manager, GovernmentTypeManager const& government_type_manager, ast::NodeCPtr root);
+ };
+} \ No newline at end of file