diff options
author | hop311 <hop3114@gmail.com> | 2023-12-31 01:47:31 +0100 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-01-02 14:41:28 +0100 |
commit | 5f64f983d0cead266a28791be42162c443fd2a75 (patch) | |
tree | da5fbb48d6c01d6faedd16b46ff846c65fdb4c33 /src/openvic-simulation/politics/Ideology.cpp | |
parent | 9988b21278dc1c8df044631bd2935a7e450a7bff (diff) |
Added framework for loading all Conditions and Effects
Diffstat (limited to 'src/openvic-simulation/politics/Ideology.cpp')
-rw-r--r-- | src/openvic-simulation/politics/Ideology.cpp | 60 |
1 files changed, 49 insertions, 11 deletions
diff --git a/src/openvic-simulation/politics/Ideology.cpp b/src/openvic-simulation/politics/Ideology.cpp index 577ab79..2678bee 100644 --- a/src/openvic-simulation/politics/Ideology.cpp +++ b/src/openvic-simulation/politics/Ideology.cpp @@ -9,9 +9,27 @@ IdeologyGroup::IdeologyGroup(std::string_view new_identifier) : HasIdentifier { 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 + bool new_can_reduce_militancy, Date new_spawn_date, ConditionalWeight&& new_add_political_reform, + ConditionalWeight&& new_remove_political_reform, ConditionalWeight&& new_add_social_reform, + ConditionalWeight&& new_remove_social_reform, ConditionalWeight&& new_add_military_reform, + ConditionalWeight&& new_add_economic_reform ) : HasIdentifierAndColour { new_identifier, new_colour, false }, group { new_group }, uncivilised { new_uncivilised }, - can_reduce_militancy { new_can_reduce_militancy }, spawn_date { new_spawn_date } {} + can_reduce_militancy { new_can_reduce_militancy }, spawn_date { new_spawn_date }, + add_political_reform { std::move(new_add_political_reform) }, + remove_political_reform { std::move(new_remove_political_reform) }, + add_social_reform { std::move(new_add_social_reform) }, remove_social_reform { std::move(new_remove_social_reform) }, + add_military_reform { std::move(new_add_military_reform) }, add_economic_reform { std::move(new_add_economic_reform) } {} + +bool Ideology::parse_scripts(GameManager const& game_manager) { + bool ret = true; + ret &= add_political_reform.parse_scripts(game_manager); + ret &= remove_political_reform.parse_scripts(game_manager); + ret &= add_social_reform.parse_scripts(game_manager); + ret &= remove_social_reform.parse_scripts(game_manager); + ret &= add_military_reform.parse_scripts(game_manager); + ret &= add_economic_reform.parse_scripts(game_manager); + return ret; +} bool IdeologyManager::add_ideology_group(std::string_view identifier) { if (identifier.empty()) { @@ -24,7 +42,9 @@ bool IdeologyManager::add_ideology_group(std::string_view identifier) { bool IdeologyManager::add_ideology( std::string_view identifier, colour_t colour, IdeologyGroup const* group, bool uncivilised, bool can_reduce_militancy, - Date spawn_date + Date spawn_date, ConditionalWeight&& add_political_reform, ConditionalWeight&& remove_political_reform, + ConditionalWeight&& add_social_reform, ConditionalWeight&& remove_social_reform, ConditionalWeight&& add_military_reform, + ConditionalWeight&& add_economic_reform ) { if (identifier.empty()) { Logger::error("Invalid ideology identifier - empty!"); @@ -36,7 +56,11 @@ bool IdeologyManager::add_ideology( return false; } - return ideologies.add_item({ identifier, colour, *group, uncivilised, can_reduce_militancy, spawn_date }); + return ideologies.add_item({ + identifier, colour, *group, uncivilised, can_reduce_militancy, spawn_date, std::move(add_political_reform), + std::move(remove_political_reform), std::move(add_social_reform), std::move(remove_social_reform), + std::move(add_military_reform), std::move(add_economic_reform) + }); } /* REQUIREMENTS: @@ -61,20 +85,26 @@ bool IdeologyManager::load_ideology_file(ast::NodeCPtr root) { colour_t colour = colour_t::null(); bool uncivilised = true, can_reduce_militancy = false; Date spawn_date; + ConditionalWeight add_political_reform, remove_political_reform, add_social_reform, remove_social_reform, + add_military_reform, add_economic_reform; 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 + "add_political_reform", ONE_EXACTLY, add_political_reform.expect_conditional_weight(ConditionalWeight::BASE), + "remove_political_reform", ONE_EXACTLY, remove_political_reform.expect_conditional_weight(ConditionalWeight::BASE), + "add_social_reform", ONE_EXACTLY, add_social_reform.expect_conditional_weight(ConditionalWeight::BASE), + "remove_social_reform", ONE_EXACTLY, remove_social_reform.expect_conditional_weight(ConditionalWeight::BASE), + "add_military_reform", ZERO_OR_ONE, add_military_reform.expect_conditional_weight(ConditionalWeight::BASE), + "add_economic_reform", ZERO_OR_ONE, add_economic_reform.expect_conditional_weight(ConditionalWeight::BASE) )(value); - ret &= add_ideology(key, colour, ideology_group, uncivilised, can_reduce_militancy, spawn_date); + ret &= add_ideology( + key, colour, ideology_group, uncivilised, can_reduce_militancy, spawn_date, std::move(add_political_reform), + std::move(remove_political_reform), std::move(add_social_reform), std::move(remove_social_reform), + std::move(add_military_reform), std::move(add_economic_reform) + ); return ret; })(ideology_group_value); })(root); @@ -82,3 +112,11 @@ bool IdeologyManager::load_ideology_file(ast::NodeCPtr root) { return ret; } + +bool IdeologyManager::parse_scripts(GameManager const& game_manager) { + bool ret = true; + for (Ideology& ideology : ideologies.get_items()) { + ideology.parse_scripts(game_manager); + } + return ret; +} |