aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/politics
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-12-02 16:48:08 +0100
committer hop311 <hop3114@gmail.com>2023-12-02 20:14:29 +0100
commit4a899c1a9e83ab9476b85522751081be434caa35 (patch)
treef1f6276c91beceecdfd9b09083d1c91ea8b41b60 /src/openvic-simulation/politics
parentcd6875d5e0ca5e2545fd0e1647678cd18a6c81c2 (diff)
Crime+event modifier loading + misc UI backend
Diffstat (limited to 'src/openvic-simulation/politics')
-rw-r--r--src/openvic-simulation/politics/Government.cpp11
-rw-r--r--src/openvic-simulation/politics/Government.hpp1
-rw-r--r--src/openvic-simulation/politics/PoliticsManager.hpp3
-rw-r--r--src/openvic-simulation/politics/Rebel.cpp109
-rw-r--r--src/openvic-simulation/politics/Rebel.hpp16
5 files changed, 81 insertions, 59 deletions
diff --git a/src/openvic-simulation/politics/Government.cpp b/src/openvic-simulation/politics/Government.cpp
index 0d1d063..609e75f 100644
--- a/src/openvic-simulation/politics/Government.cpp
+++ b/src/openvic-simulation/politics/Government.cpp
@@ -37,9 +37,16 @@ bool GovernmentTypeManager::add_government_type(
return false;
}
- return government_types.add_item({
+ const bool ret = government_types.add_item({
identifier, std::move(ideologies), elections, appoint_ruling_party, term_duration, flag_type
});
+
+ /* flag_type can be empty here for default/non-ideological flag */
+ if (ret && std::find(flag_types.begin(), flag_types.end(), flag_type) == flag_types.end()) {
+ flag_types.emplace_back(flag_type);
+ }
+
+ return ret;
}
/* REQUIREMENTS: FS-525, SIM-27 */
@@ -49,7 +56,7 @@ bool GovernmentTypeManager::load_government_types_file(IdeologyManager const& id
std::vector<Ideology const*> ideologies;
bool elections = false, appoint_ruling_party = false;
Timespan term_duration = 0;
- std::string_view flag_type_identifier = "republic";
+ std::string_view flag_type_identifier;
size_t total_expected_ideologies = 0;
bool ret = expect_dictionary_keys_and_default(
diff --git a/src/openvic-simulation/politics/Government.hpp b/src/openvic-simulation/politics/Government.hpp
index 0bc777a..025e238 100644
--- a/src/openvic-simulation/politics/Government.hpp
+++ b/src/openvic-simulation/politics/Government.hpp
@@ -29,6 +29,7 @@ namespace OpenVic {
struct GovernmentTypeManager {
private:
IdentifierRegistry<GovernmentType> government_types;
+ std::vector<std::string> PROPERTY(flag_types);
public:
GovernmentTypeManager();
diff --git a/src/openvic-simulation/politics/PoliticsManager.hpp b/src/openvic-simulation/politics/PoliticsManager.hpp
index 4f62124..0afe002 100644
--- a/src/openvic-simulation/politics/PoliticsManager.hpp
+++ b/src/openvic-simulation/politics/PoliticsManager.hpp
@@ -24,5 +24,8 @@ namespace OpenVic {
inline bool load_national_foci_file(PopManager const& pop_manager, GoodManager const& good_manager, ModifierManager const& modifier_manager, ast::NodeCPtr root) {
return national_focus_manager.load_national_foci_file(pop_manager, ideology_manager, good_manager, modifier_manager, root);
}
+ inline bool load_rebels_file(ast::NodeCPtr root) {
+ return rebel_manager.load_rebels_file(ideology_manager, government_type_manager, root);
+ }
};
}
diff --git a/src/openvic-simulation/politics/Rebel.cpp b/src/openvic-simulation/politics/Rebel.cpp
index cc0514c..e58b3de 100644
--- a/src/openvic-simulation/politics/Rebel.cpp
+++ b/src/openvic-simulation/politics/Rebel.cpp
@@ -3,37 +3,43 @@
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 } {}
+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) {
-
+ 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
+ new_identifier, icon, area, break_alliance_on_win, std::move(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) {
+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 },
@@ -66,41 +72,44 @@ bool RebelManager::load_rebels_file(IdeologyManager const& ideology_manager, Gov
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::icon_t icon = 0;
+ RebelType::area_t area = RebelType::area_t::ALL;
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;
+ RebelType::defection_t defection = RebelType::defection_t::ANY;
+ RebelType::independence_t independence = RebelType::independence_t::ANY;
+ uint16_t defect_delay = 0;
+ Ideology const* ideology = nullptr;
+ bool break_alliance_on_win = false, allow_all_cultures = true, allow_all_culture_groups = true,
+ allow_all_religions = true, allow_all_ideologies = true, resilient = true, reinforcing = true, general = true,
+ smart = true, unit_transfer = false;
+ fixed_point_t occupation_mult = 0;
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))),
+ "government", ONE_EXACTLY, government_type_manager.expect_government_type_dictionary(
+ [this, &government_type_manager, &desired_governments](GovernmentType const& from,
+ ast::NodeCPtr value) -> bool {
+ if (desired_governments.contains(&from)) {
+ Logger::error("Duplicate \"from\" government type in rebel type: ", from.get_identifier());
+ return false;
+ }
+ return government_type_manager.expect_government_type_identifier(
+ [&desired_governments, &from](GovernmentType const& to) -> bool {
+ desired_governments.emplace(&from, &to);
+ return true;
+ }
+ )(value);
+ }
+ ),
+ "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)),
+ "ideology", ZERO_OR_ONE,
+ ideology_manager.expect_ideology_identifier(assign_variable_callback_pointer(ideology)),
"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)),
@@ -120,12 +129,10 @@ bool RebelManager::load_rebels_file(IdeologyManager const& ideology_manager, Gov
"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
+ identifier, icon, area, break_alliance_on_win, std::move(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;
diff --git a/src/openvic-simulation/politics/Rebel.hpp b/src/openvic-simulation/politics/Rebel.hpp
index 791e95b..f012829 100644
--- a/src/openvic-simulation/politics/Rebel.hpp
+++ b/src/openvic-simulation/politics/Rebel.hpp
@@ -52,13 +52,14 @@ namespace OpenVic {
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,
+ 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;
+ RebelType(RebelType&&) = default;
};
struct RebelManager {
@@ -71,11 +72,14 @@ namespace OpenVic {
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,
+ 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);
+ bool load_rebels_file(
+ IdeologyManager const& ideology_manager, GovernmentTypeManager const& government_type_manager, ast::NodeCPtr root
+ );
};
} \ No newline at end of file