aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/politics
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-10-29 15:11:10 +0100
committer hop311 <hop3114@gmail.com>2023-10-29 21:08:08 +0100
commit1b5e43fa7750cc4025d32f18390593cbce3ba842 (patch)
treed37fcb69766ec029ea4e3e2816c419f9d7e05f7c /src/openvic-simulation/politics
parent164264b047921dbe1567d2af183e1cffb200a8cb (diff)
Clang-format formatting (with manual cleanup)
Diffstat (limited to 'src/openvic-simulation/politics')
-rw-r--r--src/openvic-simulation/politics/Government.cpp46
-rw-r--r--src/openvic-simulation/politics/Government.hpp12
-rw-r--r--src/openvic-simulation/politics/Ideology.cpp73
-rw-r--r--src/openvic-simulation/politics/Ideology.hpp16
-rw-r--r--src/openvic-simulation/politics/Issue.cpp33
-rw-r--r--src/openvic-simulation/politics/Issue.hpp37
6 files changed, 122 insertions, 95 deletions
diff --git a/src/openvic-simulation/politics/Government.cpp b/src/openvic-simulation/politics/Government.cpp
index 97b1d68..823284a 100644
--- a/src/openvic-simulation/politics/Government.cpp
+++ b/src/openvic-simulation/politics/Government.cpp
@@ -38,8 +38,10 @@ std::string_view GovernmentType::get_flag_type() const {
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 term_duration, std::string_view flag_type) {
+bool GovernmentTypeManager::add_government_type(
+ std::string_view identifier, std::vector<Ideology const*>&& ideologies, bool elections, bool appoint_ruling_party,
+ Timespan term_duration, std::string_view flag_type
+) {
if (identifier.empty()) {
Logger::error("Invalid government type identifier - empty!");
return false;
@@ -55,13 +57,14 @@ bool GovernmentTypeManager::add_government_type(std::string_view identifier, std
return false;
}
- return government_types.add_item({ identifier, std::move(ideologies), elections, appoint_ruling_party, term_duration, flag_type });
+ return government_types.add_item({
+ identifier, std::move(ideologies), elections, appoint_ruling_party, term_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_reserve_length(
- government_types,
+ bool ret = expect_dictionary_reserve_length(government_types,
[this, &ideology_manager](std::string_view government_type_identifier, ast::NodeCPtr government_type_value) -> bool {
std::vector<Ideology const*> ideologies;
bool elections = false, appoint_ruling_party = false;
@@ -79,14 +82,18 @@ bool GovernmentTypeManager::load_government_types_file(IdeologyManager const& id
ideologies.reserve(total_expected_ideologies);
ret &= expect_dictionary(
- [this, &ideology_manager, &ideologies, government_type_identifier](std::string_view key, ast::NodeCPtr value) -> bool {
- static const string_set_t reserved_keys = {
- "election", "duration", "appoint_ruling_party", "flagType"
- };
- if (reserved_keys.find(key) != reserved_keys.end()) return true;
+ [this, &ideology_manager, &ideologies, government_type_identifier](
+ std::string_view key, ast::NodeCPtr value) -> bool {
+ static const string_set_t 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!");
+ Logger::error(
+ "When loading government type ", government_type_identifier, ", specified ideology ", key,
+ " is invalid!"
+ );
return false;
}
return expect_bool([&ideologies, ideology, government_type_identifier](bool val) -> bool {
@@ -95,20 +102,29 @@ bool GovernmentTypeManager::load_government_types_file(IdeologyManager const& id
ideologies.push_back(ideology);
return true;
}
- Logger::error("Government type ", government_type_identifier, " marked as supporting ideology ", ideology->get_identifier());
+ Logger::error(
+ "Government type ", government_type_identifier, " marked as supporting ideology ",
+ ideology->get_identifier()
+ );
return false;
}
- Logger::error("Government type ", government_type_identifier, " redundantly marked as not supporting ideology ", ideology->get_identifier(), " multiple times");
+ Logger::error(
+ "Government type ", government_type_identifier, " redundantly marked as not supporting ideology ",
+ ideology->get_identifier(), " multiple times"
+ );
return false;
})(value);
}
)(government_type_value);
- ret &= add_government_type(government_type_identifier, std::move(ideologies), elections, appoint_ruling_party, term_duration, flag_type_identifier);
+ ret &= add_government_type(
+ government_type_identifier, std::move(ideologies), elections, appoint_ruling_party, term_duration,
+ 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
index 455b822..9fff111 100644
--- a/src/openvic-simulation/politics/Government.hpp
+++ b/src/openvic-simulation/politics/Government.hpp
@@ -14,8 +14,10 @@ namespace OpenVic {
const Timespan term_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_term_duration, std::string_view new_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_term_duration, std::string_view new_flag_type_identifier
+ );
public:
GovernmentType(GovernmentType&&) = default;
@@ -35,8 +37,10 @@ namespace OpenVic {
public:
GovernmentTypeManager();
- bool add_government_type(std::string_view identifier, std::vector<Ideology const*>&& ideologies, bool elections,
- bool appoint_ruling_party, Timespan term_duration, std::string_view flag_type);
+ bool add_government_type(
+ std::string_view identifier, std::vector<Ideology const*>&& ideologies, bool elections, bool appoint_ruling_party,
+ Timespan term_duration, std::string_view flag_type
+ );
IDENTIFIER_REGISTRY_ACCESSORS(government_type)
bool load_government_types_file(IdeologyManager const& ideology_manager, ast::NodeCPtr root);
diff --git a/src/openvic-simulation/politics/Ideology.cpp b/src/openvic-simulation/politics/Ideology.cpp
index c52d8b1..acbd82f 100644
--- a/src/openvic-simulation/politics/Ideology.cpp
+++ b/src/openvic-simulation/politics/Ideology.cpp
@@ -6,10 +6,10 @@ using namespace OpenVic::NodeTools;
IdeologyGroup::IdeologyGroup(std::string_view new_identifier) : HasIdentifier { new_identifier } {}
Ideology::Ideology(
- std::string_view new_identifier, colour_t new_colour, IdeologyGroup const& new_group,
- bool new_uncivilised, bool new_can_reduce_militancy, Date new_spawn_date
-) : HasIdentifierAndColour { new_identifier, new_colour, true, false }, group { new_group },
- uncivilised { new_uncivilised }, can_reduce_militancy { new_can_reduce_militancy }, spawn_date { new_spawn_date } {}
+ std::string_view new_identifier, colour_t new_colour, IdeologyGroup const& new_group, bool new_uncivilised,
+ bool new_can_reduce_militancy, Date new_spawn_date
+) : HasIdentifierAndColour { new_identifier, new_colour, true, false }, group { new_group }, uncivilised { new_uncivilised },
+ can_reduce_militancy { new_can_reduce_militancy }, spawn_date { new_spawn_date } {}
IdeologyGroup const& Ideology::get_group() const {
return group;
@@ -38,8 +38,10 @@ bool IdeologyManager::add_ideology_group(std::string_view identifier) {
return ideology_groups.add_item({ identifier });
}
-bool IdeologyManager::add_ideology(std::string_view identifier, colour_t colour, IdeologyGroup const* group,
- bool uncivilised, bool can_reduce_militancy, Date spawn_date) {
+bool IdeologyManager::add_ideology(
+ std::string_view identifier, colour_t colour, IdeologyGroup const* group, bool uncivilised, bool can_reduce_militancy,
+ Date spawn_date
+) {
if (identifier.empty()) {
Logger::error("Invalid ideology identifier - empty!");
return false;
@@ -60,11 +62,10 @@ bool IdeologyManager::add_ideology(std::string_view identifier, colour_t colour,
/* REQUIREMENTS:
* POL-9, POL-10, POL-11, POL-12, POL-13, POL-14, POL-15
-*/
+ */
bool IdeologyManager::load_ideology_file(ast::NodeCPtr root) {
size_t expected_ideologies = 0;
- bool ret = expect_dictionary_reserve_length(
- ideology_groups,
+ bool ret = expect_dictionary_reserve_length(ideology_groups,
[this, &expected_ideologies](std::string_view key, ast::NodeCPtr value) -> bool {
bool ret = expect_length(add_variable_callback(expected_ideologies))(value);
ret &= add_ideology_group(key);
@@ -74,35 +75,31 @@ bool IdeologyManager::load_ideology_file(ast::NodeCPtr root) {
lock_ideology_groups();
ideologies.reserve(ideologies.size() + expected_ideologies);
- ret &= expect_dictionary(
- [this](std::string_view ideology_group_key, ast::NodeCPtr ideology_group_value) -> bool {
- IdeologyGroup const* ideology_group = get_ideology_group_by_identifier(ideology_group_key);
-
- return expect_dictionary(
- [this, ideology_group](std::string_view key, ast::NodeCPtr value) -> bool {
- colour_t colour = NULL_COLOUR;
- bool uncivilised = true, can_reduce_militancy = false;
- Date spawn_date;
-
- bool ret = expect_dictionary_keys(
- "uncivilized", ZERO_OR_ONE, expect_bool(assign_variable_callback(uncivilised)),
- "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)),
- "date", ZERO_OR_ONE, expect_date(assign_variable_callback(spawn_date)),
- "can_reduce_militancy", ZERO_OR_ONE, expect_bool(assign_variable_callback(can_reduce_militancy)),
- "add_political_reform", ONE_EXACTLY, success_callback,
- "remove_political_reform", ONE_EXACTLY, success_callback,
- "add_social_reform", ONE_EXACTLY, success_callback,
- "remove_social_reform", ONE_EXACTLY, success_callback,
- "add_military_reform", ZERO_OR_ONE, success_callback,
- "add_economic_reform", ZERO_OR_ONE, success_callback
- )(value);
- ret &= add_ideology(key, colour, ideology_group, uncivilised, can_reduce_militancy, spawn_date);
- return ret;
- }
- )(ideology_group_value);
- }
- )(root);
+ ret &= expect_dictionary([this](std::string_view ideology_group_key, ast::NodeCPtr ideology_group_value) -> bool {
+ IdeologyGroup const* ideology_group = get_ideology_group_by_identifier(ideology_group_key);
+
+ return expect_dictionary([this, ideology_group](std::string_view key, ast::NodeCPtr value) -> bool {
+ colour_t colour = NULL_COLOUR;
+ bool uncivilised = true, can_reduce_militancy = false;
+ Date spawn_date;
+
+ bool ret = expect_dictionary_keys(
+ "uncivilized", ZERO_OR_ONE, expect_bool(assign_variable_callback(uncivilised)),
+ "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)),
+ "date", ZERO_OR_ONE, expect_date(assign_variable_callback(spawn_date)),
+ "can_reduce_militancy", ZERO_OR_ONE, expect_bool(assign_variable_callback(can_reduce_militancy)),
+ "add_political_reform", ONE_EXACTLY, success_callback,
+ "remove_political_reform", ONE_EXACTLY, success_callback,
+ "add_social_reform", ONE_EXACTLY, success_callback,
+ "remove_social_reform", ONE_EXACTLY, success_callback,
+ "add_military_reform", ZERO_OR_ONE, success_callback,
+ "add_economic_reform", ZERO_OR_ONE, success_callback
+ )(value);
+ ret &= add_ideology(key, colour, ideology_group, uncivilised, can_reduce_militancy, spawn_date);
+ return ret;
+ })(ideology_group_value);
+ })(root);
lock_ideologies();
return ret;
-} \ No newline at end of file
+}
diff --git a/src/openvic-simulation/politics/Ideology.hpp b/src/openvic-simulation/politics/Ideology.hpp
index 3cd72f4..046dbc9 100644
--- a/src/openvic-simulation/politics/Ideology.hpp
+++ b/src/openvic-simulation/politics/Ideology.hpp
@@ -23,10 +23,12 @@ namespace OpenVic {
const bool uncivilised, can_reduce_militancy;
const Date spawn_date;
- //TODO - willingness to repeal/pass reforms (and its modifiers)
+ // TODO - willingness to repeal/pass reforms (and its modifiers)
- Ideology(std::string_view new_identifier, colour_t new_colour, IdeologyGroup const& new_group,
- bool new_uncivilised, bool new_can_reduce_militancy, Date new_spawn_date);
+ Ideology(
+ std::string_view new_identifier, colour_t new_colour, IdeologyGroup const& new_group, bool new_uncivilised,
+ bool new_can_reduce_militancy, Date new_spawn_date
+ );
public:
Ideology(Ideology&&) = default;
@@ -48,10 +50,12 @@ namespace OpenVic {
bool add_ideology_group(std::string_view identifier);
IDENTIFIER_REGISTRY_ACCESSORS(ideology_group)
- bool add_ideology(std::string_view identifier, colour_t colour, IdeologyGroup const* group,
- bool uncivilised, bool can_reduce_militancy, Date spawn_date);
+ bool add_ideology(
+ std::string_view identifier, colour_t colour, IdeologyGroup const* group, bool uncivilised,
+ bool can_reduce_militancy, Date spawn_date
+ );
IDENTIFIER_REGISTRY_ACCESSORS_CUSTOM_PLURAL(ideology, ideologies)
bool load_ideology_file(ast::NodeCPtr root);
};
-} \ No newline at end of file
+}
diff --git a/src/openvic-simulation/politics/Issue.cpp b/src/openvic-simulation/politics/Issue.cpp
index 4f05a99..cc3c12b 100644
--- a/src/openvic-simulation/politics/Issue.cpp
+++ b/src/openvic-simulation/politics/Issue.cpp
@@ -5,8 +5,7 @@ using namespace OpenVic::NodeTools;
IssueGroup::IssueGroup(std::string_view new_identifier) : HasIdentifier { new_identifier } {}
-Issue::Issue(std::string_view identifier, IssueGroup const& group)
- : HasIdentifier { identifier }, group { group } {}
+Issue::Issue(std::string_view identifier, IssueGroup const& group) : HasIdentifier { identifier }, group { group } {}
IssueGroup const& Issue::get_group() const {
return group;
@@ -45,8 +44,9 @@ size_t Reform::get_ordinal() const {
return ordinal;
}
-IssueManager::IssueManager() : issue_groups { "issue groups" }, issues { "issues" },
- reform_types { "reform types" }, reform_groups { "reform groups" }, reforms { "reforms" } {}
+IssueManager::IssueManager()
+ : issue_groups { "issue groups" }, issues { "issues" }, reform_types { "reform types" }, reform_groups { "reform groups" },
+ reforms { "reforms" } {}
bool IssueManager::add_issue_group(std::string_view identifier) {
if (identifier.empty()) {
@@ -116,12 +116,13 @@ bool IssueManager::_load_issue_group(size_t& expected_issues, std::string_view i
}
bool IssueManager::_load_issue(std::string_view identifier, IssueGroup const* group, ast::NodeCPtr node) {
- //TODO: policy modifiers, policy rule changes
+ // TODO: policy modifiers, policy rule changes
return add_issue(identifier, group);
}
-bool IssueManager::_load_reform_group(size_t& expected_reforms, std::string_view identifier,
- ReformType const* type, ast::NodeCPtr node) {
+bool IssueManager::_load_reform_group(
+ size_t& expected_reforms, std::string_view identifier, ReformType const* type, ast::NodeCPtr node
+) {
bool ordered = false, administrative = false;
bool ret = expect_dictionary_keys_and_default(
increment_callback(expected_reforms),
@@ -133,7 +134,7 @@ bool IssueManager::_load_reform_group(size_t& expected_reforms, std::string_view
}
bool IssueManager::_load_reform(size_t& ordinal, std::string_view identifier, ReformGroup const* group, ast::NodeCPtr node) {
- //TODO: conditions to allow, policy modifiers, policy rule changes
+ // TODO: conditions to allow, policy modifiers, policy rule changes
return add_reform(identifier, group, ordinal);
}
@@ -145,16 +146,18 @@ bool IssueManager::_load_reform(size_t& ordinal, std::string_view identifier, Re
* POL-84, POL-85, POL-86, POL-87, POL-89, POL-90, POL-91, POL-92, POL-93, POL-95, POL-96, POL-97, POL-98,
* POL-99, POL-101, POL-102, POL-103, POL-104, POL-105, POL-107, POL-108, POL-109, POL-110, POL-111, POL-113,
* POL-113, POL-114, POL-115, POL-116
-*/
+ */
bool IssueManager::load_issues_file(ast::NodeCPtr root) {
size_t expected_issue_groups = 0;
size_t expected_reform_groups = 0;
bool ret = expect_dictionary_reserve_length(reform_types,
[this, &expected_issue_groups, &expected_reform_groups](std::string_view key, ast::NodeCPtr value) -> bool {
- if (key == "party_issues")
+ if (key == "party_issues") {
return expect_length(add_variable_callback(expected_issue_groups))(value);
- else return expect_length(add_variable_callback(expected_reform_groups))(value) & add_reform_type(
- key, key == "economic_reforms" || "education_reforms" || "military_reforms");
+ } else {
+ return expect_length(add_variable_callback(expected_reform_groups))(value) &
+ add_reform_type(key, key == "economic_reforms" || "education_reforms" || "military_reforms");
+ }
}
)(root);
lock_reform_types();
@@ -198,7 +201,9 @@ bool IssueManager::load_issues_file(ast::NodeCPtr root) {
ReformGroup const* reform_group = get_reform_group_by_identifier(group_key);
size_t ordinal = 0;
return expect_dictionary([this, reform_group, &ordinal](std::string_view key, ast::NodeCPtr value) -> bool {
- if (key == "next_step_only" || key == "administrative") return true;
+ if (key == "next_step_only" || key == "administrative") {
+ return true;
+ }
bool ret = _load_reform(ordinal, key, reform_group, value);
ordinal++;
return ret;
@@ -210,4 +215,4 @@ bool IssueManager::load_issues_file(ast::NodeCPtr root) {
lock_reforms();
return ret;
-} \ No newline at end of file
+}
diff --git a/src/openvic-simulation/politics/Issue.hpp b/src/openvic-simulation/politics/Issue.hpp
index 9d72334..84aa886 100644
--- a/src/openvic-simulation/politics/Issue.hpp
+++ b/src/openvic-simulation/politics/Issue.hpp
@@ -2,14 +2,14 @@
#include <cstddef>
#include <string_view>
-#include "openvic-simulation/types/IdentifierRegistry.hpp"
+
#include "openvic-simulation/dataloader/NodeTools.hpp"
-#include "openvic-dataloader/v2script/AbstractSyntaxTree.hpp"
+#include "openvic-simulation/types/IdentifierRegistry.hpp"
namespace OpenVic {
struct IssueManager;
- //Issue group (i.e. trade_policy)
+ // Issue group (i.e. trade_policy)
struct IssueGroup : HasIdentifier {
friend struct IssueManager;
@@ -20,14 +20,14 @@ namespace OpenVic {
IssueGroup(IssueGroup&&) = default;
};
- //Issue (i.e. protectionism)
+ // Issue (i.e. protectionism)
struct Issue : HasIdentifier {
friend struct IssueManager;
private:
IssueGroup const& group;
- //TODO: policy modifiers, policy rule changes
+ // TODO: policy modifiers, policy rule changes
protected:
Issue(std::string_view identifier, IssueGroup const& group);
@@ -37,13 +37,13 @@ namespace OpenVic {
IssueGroup const& get_group() const;
};
- //Reform type (i.e. political_issues)
+ // Reform type (i.e. political_issues)
struct ReformType : HasIdentifier {
friend struct IssueManager;
private:
- bool uncivilised; //whether this group is available to non-westernised countries
- //in vanilla education, military and economic reforms are hardcoded to true and the rest to false
+ bool uncivilised; // whether this group is available to non-westernised countries
+ // in vanilla education, military and economic reforms are hardcoded to true and the rest to false
ReformType(std::string_view new_identifier, bool uncivilised);
@@ -51,13 +51,13 @@ namespace OpenVic {
ReformType(ReformType&&) = default;
};
- //Reform group (i.e. slavery)
+ // Reform group (i.e. slavery)
struct ReformGroup : IssueGroup {
friend struct IssueManager;
private:
ReformType const& type;
- const bool ordered; //next_step_only
+ const bool ordered; // next_step_only
const bool administrative;
ReformGroup(std::string_view identifier, ReformType const& type, bool ordered, bool administrative);
@@ -69,17 +69,17 @@ namespace OpenVic {
bool is_administrative() const;
};
- //Reform (i.e. yes_slavery)
+ // Reform (i.e. yes_slavery)
struct Reform : Issue {
friend struct IssueManager;
private:
- ReformGroup const& reform_group; //stores an already casted reference
- const size_t ordinal; //assigned by the parser to allow policy sorting
+ ReformGroup const& reform_group; // stores an already casted reference
+ const size_t ordinal; // assigned by the parser to allow policy sorting
Reform(std::string_view new_identifier, ReformGroup const& group, size_t ordinal);
- //TODO: conditions to allow,
+ // TODO: conditions to allow,
public:
Reform(Reform&&) = default;
@@ -88,7 +88,7 @@ namespace OpenVic {
size_t get_ordinal() const;
};
- //Issue manager - holds the registries
+ // Issue manager - holds the registries
struct IssueManager {
private:
IdentifierRegistry<IssueGroup> issue_groups;
@@ -99,8 +99,9 @@ namespace OpenVic {
bool _load_issue_group(size_t& expected_issues, std::string_view identifier, ast::NodeCPtr node);
bool _load_issue(std::string_view identifier, IssueGroup const* group, ast::NodeCPtr node);
- bool _load_reform_group(size_t& expected_reforms, std::string_view identifier, ReformType const* type,
- ast::NodeCPtr node);
+ bool _load_reform_group(
+ size_t& expected_reforms, std::string_view identifier, ReformType const* type, ast::NodeCPtr node
+ );
bool _load_reform(size_t& ordinal, std::string_view identifier, ReformGroup const* group, ast::NodeCPtr node);
public:
@@ -123,4 +124,4 @@ namespace OpenVic {
bool load_issues_file(ast::NodeCPtr root);
};
-} \ No newline at end of file
+}