From 6edb54dc3f308c1e9b2ccb7bed21facb129ab963 Mon Sep 17 00:00:00 2001 From: Hop311 Date: Sat, 23 Sep 2023 00:35:21 +0100 Subject: Various fixes, refactors and general cleanup --- src/openvic-simulation/politics/Ideology.cpp | 35 ++++++++++++++++------------ 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'src/openvic-simulation/politics/Ideology.cpp') 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); -- cgit v1.2.3-56-ga3b1