diff options
author | Hop311 <hop3114@gmail.com> | 2023-09-23 01:35:21 +0200 |
---|---|---|
committer | Hop311 <hop3114@gmail.com> | 2023-09-23 01:35:21 +0200 |
commit | 6edb54dc3f308c1e9b2ccb7bed21facb129ab963 (patch) | |
tree | c39e52312e20fa9cdf8934c21d4016364bfb3e85 /src/openvic-simulation/politics | |
parent | d7022294d43a0b173de4f060e3260e986f03853d (diff) |
Various fixes, refactors and general cleanup
Diffstat (limited to 'src/openvic-simulation/politics')
-rw-r--r-- | src/openvic-simulation/politics/Ideology.cpp | 35 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Ideology.hpp | 8 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Issue.cpp | 37 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Issue.hpp | 7 |
4 files changed, 48 insertions, 39 deletions
diff --git a/src/openvic-simulation/politics/Ideology.cpp b/src/openvic-simulation/politics/Ideology.cpp index 43adfaa..7c15c3c 100644 --- a/src/openvic-simulation/politics/Ideology.cpp +++ b/src/openvic-simulation/politics/Ideology.cpp @@ -5,9 +5,9 @@ using namespace OpenVic::NodeTools; IdeologyGroup::IdeologyGroup(const std::string_view new_identifier) : HasIdentifier { new_identifier } {} -Ideology::Ideology(const std::string_view new_identifier, colour_t new_colour, IdeologyGroup const& new_group, bool uncivilised, Date spawn_date) - : HasIdentifierAndColour { new_identifier, new_colour, true, false }, group { new_group }, uncivilised { uncivilised }, - spawn_date { spawn_date } {} +Ideology::Ideology(const 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; @@ -17,6 +17,10 @@ bool Ideology::is_uncivilised() const { return uncivilised; } +bool Ideology::get_can_reduce_militancy() const { + return can_reduce_militancy; +} + Date const& Ideology::get_spawn_date() const { return spawn_date; } @@ -32,7 +36,7 @@ bool IdeologyManager::add_ideology_group(const std::string_view identifier) { return ideology_groups.add_item({ identifier }); } -bool IdeologyManager::add_ideology(const std::string_view identifier, colour_t colour, IdeologyGroup const* group, bool uncivilised, Date spawn_date) { +bool IdeologyManager::add_ideology(const 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; @@ -48,7 +52,7 @@ bool IdeologyManager::add_ideology(const std::string_view identifier, colour_t c return false; } - return ideologies.add_item({ identifier, colour, *group, uncivilised, spawn_date }); + return ideologies.add_item({ identifier, colour, *group, uncivilised, can_reduce_militancy, spawn_date }); } /* REQUIREMENTS: @@ -59,13 +63,7 @@ bool IdeologyManager::load_ideology_file(ast::NodeCPtr root) { bool ret = expect_dictionary_reserve_length( ideology_groups, [this, &expected_ideologies](std::string_view key, ast::NodeCPtr value) -> bool { - bool ret = expect_list_and_length( - [&expected_ideologies](size_t size) -> size_t { - expected_ideologies += size; - return 0; - }, - success_callback - )(value); + bool ret = expect_length(add_variable_callback(expected_ideologies))(value); ret &= add_ideology_group(key); return ret; } @@ -80,15 +78,22 @@ bool IdeologyManager::load_ideology_file(ast::NodeCPtr root) { return expect_dictionary( [this, ideology_group](std::string_view key, ast::NodeCPtr value) -> bool { colour_t colour = NULL_COLOUR; - bool uncivilised = true; + 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)) + "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, spawn_date); + ret &= add_ideology(key, colour, ideology_group, uncivilised, can_reduce_militancy, spawn_date); return ret; } )(ideology_group_value); diff --git a/src/openvic-simulation/politics/Ideology.hpp b/src/openvic-simulation/politics/Ideology.hpp index b72c176..f5ed5f1 100644 --- a/src/openvic-simulation/politics/Ideology.hpp +++ b/src/openvic-simulation/politics/Ideology.hpp @@ -22,17 +22,19 @@ namespace OpenVic { private: IdeologyGroup const& group; - const bool uncivilised; + const bool uncivilised, can_reduce_militancy; const Date spawn_date; //TODO - willingness to repeal/pass reforms (and its modifiers) - Ideology(const std::string_view new_identifier, colour_t new_colour, IdeologyGroup const& new_group, bool uncivilised, Date spawn_date); + Ideology(const 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; + IdeologyGroup const& get_group() const; bool is_uncivilised() const; + bool get_can_reduce_militancy() const; Date const& get_spawn_date() const; }; @@ -47,7 +49,7 @@ namespace OpenVic { bool add_ideology_group(const std::string_view identifier); IDENTIFIER_REGISTRY_ACCESSORS(IdeologyGroup, ideology_group) - bool add_ideology(const std::string_view identifier, colour_t colour, IdeologyGroup const* group, bool uncivilised, Date spawn_date); + bool add_ideology(const 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, ideology, ideologies) bool load_ideology_file(ast::NodeCPtr root); diff --git a/src/openvic-simulation/politics/Issue.cpp b/src/openvic-simulation/politics/Issue.cpp index b11b8a0..8ee01ea 100644 --- a/src/openvic-simulation/politics/Issue.cpp +++ b/src/openvic-simulation/politics/Issue.cpp @@ -5,8 +5,8 @@ using namespace OpenVic::NodeTools; IssueType::IssueType(const std::string_view new_identifier) : HasIdentifier { new_identifier } {} -IssueGroup::IssueGroup(const std::string_view new_identifier, IssueType const& new_type, bool ordered) - : HasIdentifier { new_identifier }, type { new_type }, ordered { ordered } {} +IssueGroup::IssueGroup(const std::string_view new_identifier, IssueType const& new_type, bool new_ordered, bool new_administrative) + : HasIdentifier { new_identifier }, type { new_type }, ordered { new_ordered }, administrative { new_administrative } {} IssueType const& IssueGroup::get_type() const { return type; @@ -16,6 +16,10 @@ bool IssueGroup::is_ordered() const { return ordered; } +bool IssueGroup::is_administrative() const { + return administrative; +} + Issue::Issue(const std::string_view new_identifier, IssueGroup const& new_group, size_t ordinal) : HasIdentifier { new_identifier }, group { new_group }, ordinal { ordinal } {} @@ -42,7 +46,7 @@ bool IssueManager::add_issue_type(const std::string_view identifier) { return issue_types.add_item({ identifier }); } -bool IssueManager::add_issue_group(const std::string_view identifier, IssueType const* type, bool ordered) { +bool IssueManager::add_issue_group(const std::string_view identifier, IssueType const* type, bool ordered, bool administrative) { if (identifier.empty()) { Logger::error("Invalid issue group identifier - empty!"); return false; @@ -53,7 +57,7 @@ bool IssueManager::add_issue_group(const std::string_view identifier, IssueType return false; } - return issue_groups.add_item({ identifier, *type, ordered }); + return issue_groups.add_item({ identifier, *type, ordered, administrative }); } bool IssueManager::add_issue(const std::string_view identifier, IssueGroup const* group, size_t ordinal) { @@ -71,17 +75,17 @@ bool IssueManager::add_issue(const std::string_view identifier, IssueGroup const } bool IssueManager::_load_issue_group(size_t& expected_issues, const std::string_view identifier, IssueType const* type, ast::NodeCPtr node) { - bool ordered = false; - return expect_dictionary_keys_and_length( + bool ordered = false, administrative = false; + bool ret = expect_dictionary_keys_and_length( [&expected_issues](size_t size) -> size_t { expected_issues += size; return size; }, ALLOW_OTHER_KEYS, - "next_step_only", ONE_EXACTLY, [&expected_issues, &ordered](ast::NodeCPtr node) -> bool { - expected_issues--; - return expect_bool(assign_variable_callback(ordered))(node); - } - )(node) && add_issue_group(identifier, type, ordered); + "next_step_only", ZERO_OR_ONE, decrement_callback(expected_issues, expect_bool(assign_variable_callback(ordered))), + "administrative", ZERO_OR_ONE, decrement_callback(expected_issues, expect_bool(assign_variable_callback(administrative))) + )(node); + ret &= add_issue_group(identifier, type, ordered, administrative); + return ret; } bool IssueManager::_load_issue(size_t& ordinal, const std::string_view identifier, IssueGroup const* group, ast::NodeCPtr node) { @@ -102,12 +106,9 @@ bool IssueManager::load_issues_file(ast::NodeCPtr root) { size_t expected_issue_groups = 0; bool ret = expect_dictionary_reserve_length(issue_types, [this, &expected_issue_groups](std::string_view key, ast::NodeCPtr value) -> bool { - return expect_list_and_length( - [&expected_issue_groups](size_t size) -> size_t { - expected_issue_groups += size; - return 0; - }, success_callback - )(value) && add_issue_type(key); + bool ret = expect_length(add_variable_callback(expected_issue_groups))(value); + ret &= add_issue_type(key); + return ret; } )(root); lock_issue_types(); @@ -132,7 +133,7 @@ bool IssueManager::load_issues_file(ast::NodeCPtr root) { IssueGroup const* issue_group = get_issue_group_by_identifier(group_key); size_t ordinal = 0; return expect_dictionary([this, issue_group, &ordinal](std::string_view key, ast::NodeCPtr value) -> bool { - if (key == "next_step_only") return true; + if (key == "next_step_only" || key == "administrative") return true; bool ret = _load_issue(ordinal, key, issue_group, value); ordinal++; return ret; diff --git a/src/openvic-simulation/politics/Issue.hpp b/src/openvic-simulation/politics/Issue.hpp index 546b3ea..f002f45 100644 --- a/src/openvic-simulation/politics/Issue.hpp +++ b/src/openvic-simulation/politics/Issue.hpp @@ -25,14 +25,15 @@ namespace OpenVic { private: IssueType const& type; - const bool ordered; + const bool ordered, administrative; - IssueGroup(const std::string_view new_identifier, IssueType const& new_type, bool ordered); + IssueGroup(const std::string_view new_identifier, IssueType const& new_type, bool new_ordered, bool new_administrative); public: IssueGroup(IssueGroup&&) = default; IssueType const& get_type() const; bool is_ordered() const; + bool is_administrative() const; }; //Issue type (i.e. yes_slavery) @@ -70,7 +71,7 @@ namespace OpenVic { bool add_issue_type(const std::string_view identifier); IDENTIFIER_REGISTRY_ACCESSORS(IssueType, issue_type) - bool add_issue_group(const std::string_view identifier, IssueType const* type, bool ordered); + bool add_issue_group(const std::string_view identifier, IssueType const* type, bool ordered, bool administrative); IDENTIFIER_REGISTRY_ACCESSORS(IssueGroup, issue_group) bool add_issue(const std::string_view identifier, IssueGroup const* group, size_t ordinal); |