diff options
author | Hop311 <Hop3114@gmail.com> | 2024-09-21 15:34:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-21 15:34:22 +0200 |
commit | 4b69a91a6db50f86efec503b56b07573c692df9f (patch) | |
tree | 68fca0f77f6b20f3e1fe98d32a5a79311cfd3edc /src/openvic-simulation/politics/NationalFocus.cpp | |
parent | 85da7fb84197d617d1b3cde6969bf7bcfbb93d1d (diff) | |
parent | e35ff8ed703b0b6a5496a21a29e0b274c6a36874 (diff) |
Merge pull request #204 from OpenVicProject/fix-modifiers
Fix modifiers
Diffstat (limited to 'src/openvic-simulation/politics/NationalFocus.cpp')
-rw-r--r-- | src/openvic-simulation/politics/NationalFocus.cpp | 60 |
1 files changed, 53 insertions, 7 deletions
diff --git a/src/openvic-simulation/politics/NationalFocus.cpp b/src/openvic-simulation/politics/NationalFocus.cpp index 3132c3e..4887ed6 100644 --- a/src/openvic-simulation/politics/NationalFocus.cpp +++ b/src/openvic-simulation/politics/NationalFocus.cpp @@ -1,6 +1,8 @@ #include "NationalFocus.hpp" +#include "openvic-simulation/economy/GoodDefinition.hpp" #include "openvic-simulation/politics/Ideology.hpp" +#include "openvic-simulation/pop/Pop.hpp" using namespace OpenVic; using namespace OpenVic::NodeTools; @@ -12,20 +14,28 @@ NationalFocus::NationalFocus( NationalFocusGroup const& new_group, uint8_t new_icon, bool new_has_flashpoint, + fixed_point_t new_flashpoint_tension, bool new_own_provinces, bool new_outliner_show_as_percent, ModifierValue&& new_modifiers, Ideology const* new_loyalty_ideology, fixed_point_t new_loyalty_value, + fixed_point_t new_encourage_railroads, + fixed_point_map_t<GoodDefinition const*>&& new_encourage_goods, + fixed_point_map_t<PopType const*>&& new_encourage_pop_types, ConditionScript&& new_limit -) : Modifier { new_identifier, std::move(new_modifiers) }, +) : Modifier { new_identifier, std::move(new_modifiers), modifier_type_t::NATIONAL_FOCUS }, group { new_group }, icon { new_icon }, has_flashpoint { new_has_flashpoint }, + flashpoint_tension { new_flashpoint_tension }, own_provinces { new_own_provinces }, outliner_show_as_percent { new_outliner_show_as_percent }, loyalty_ideology { new_loyalty_ideology }, loyalty_value { new_loyalty_value }, + encourage_railroads { new_encourage_railroads }, + encourage_goods { std::move(new_encourage_goods) }, + encourage_pop_types { std::move(new_encourage_pop_types) }, limit { std::move(new_limit) } {} bool NationalFocus::parse_scripts(DefinitionManager const& definition_manager) { @@ -37,6 +47,7 @@ inline bool NationalFocusManager::add_national_focus_group(std::string_view iden Logger::error("No identifier for national focus group!"); return false; } + return national_focus_groups.add_item({ identifier }); } @@ -45,30 +56,38 @@ inline bool NationalFocusManager::add_national_focus( NationalFocusGroup const& group, uint8_t icon, bool has_flashpoint, + fixed_point_t flashpoint_tension, bool own_provinces, bool outliner_show_as_percent, ModifierValue&& modifiers, Ideology const* loyalty_ideology, fixed_point_t loyalty_value, + fixed_point_t encourage_railroads, + fixed_point_map_t<GoodDefinition const*>&& encourage_goods, + fixed_point_map_t<PopType const*>&& encourage_pop_types, ConditionScript&& limit ) { if (identifier.empty()) { Logger::error("No identifier for national focus!"); return false; } + if (icon < 1) { Logger::error("Invalid icon ", icon, " for national focus ", identifier); return false; } + if ((loyalty_ideology == nullptr) != (loyalty_value == 0)) { Logger::warning( "Party loyalty incorrectly defined for national focus ", identifier, ": ideology = ", loyalty_ideology, ", value = ", loyalty_value ); } + return national_foci.add_item({ - identifier, group, icon, has_flashpoint, own_provinces, outliner_show_as_percent, std::move(modifiers), - loyalty_ideology, loyalty_value, std::move(limit) + identifier, group, icon, has_flashpoint, flashpoint_tension, own_provinces, outliner_show_as_percent, + std::move(modifiers), loyalty_ideology, loyalty_value, encourage_railroads, std::move(encourage_goods), + std::move(encourage_pop_types), std::move(limit) }); } @@ -77,12 +96,14 @@ bool NationalFocusManager::load_national_foci_file( GoodDefinitionManager const& good_definition_manager, ModifierManager const& modifier_manager, ast::NodeCPtr root ) { size_t expected_national_foci = 0; + bool ret = expect_dictionary_reserve_length( national_focus_groups, [this, &expected_national_foci](std::string_view identifier, ast::NodeCPtr node) -> bool { return expect_length(add_variable_callback(expected_national_foci))(node) & add_national_focus_group(identifier); } )(root); + lock_national_focus_groups(); reserve_more_national_foci(expected_national_foci); @@ -97,29 +118,51 @@ bool NationalFocusManager::load_national_foci_file( ) -> bool { uint8_t icon = 0; bool has_flashpoint = false, own_provinces = true, outliner_show_as_percent = false; + fixed_point_t flashpoint_tension = 0; ModifierValue modifiers; Ideology const* loyalty_ideology = nullptr; fixed_point_t loyalty_value = 0; + fixed_point_t encourage_railroads = 0; + fixed_point_map_t<GoodDefinition const*> encourage_goods; + fixed_point_map_t<PopType const*> encourage_pop_types; ConditionScript limit { scope_t::PROVINCE | scope_t::COUNTRY, scope_t::PROVINCE | scope_t::COUNTRY, scope_t::NO_SCOPE }; - bool ret = modifier_manager.expect_modifier_value_and_keys( + bool ret = modifier_manager.expect_modifier_value_and_keys_and_default( move_variable_callback(modifiers), + [&good_definition_manager, &encourage_goods, &pop_manager, &encourage_pop_types]( + std::string_view key, ast::NodeCPtr value + ) -> bool { + GoodDefinition const* good = good_definition_manager.get_good_definition_by_identifier(key); + if (good != nullptr) { + return expect_fixed_point(map_callback(encourage_goods, good))(value); + } + + PopType const* pop_type = pop_manager.get_pop_type_by_identifier(key); + if (pop_type != nullptr) { + return expect_fixed_point(map_callback(encourage_pop_types, pop_type))(value); + } + + return key_value_invalid_callback(key, value); + }, "icon", ONE_EXACTLY, expect_uint(assign_variable_callback(icon)), "ideology", ZERO_OR_ONE, ideology_manager.expect_ideology_identifier(assign_variable_callback_pointer(loyalty_ideology)), "loyalty_value", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(loyalty_value)), "limit", ZERO_OR_ONE, limit.expect_script(), "has_flashpoint", ZERO_OR_ONE, expect_bool(assign_variable_callback(has_flashpoint)), + "flashpoint_tension", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(flashpoint_tension)), "own_provinces", ZERO_OR_ONE, expect_bool(assign_variable_callback(own_provinces)), "outliner_show_as_percent", ZERO_OR_ONE, - expect_bool(assign_variable_callback(outliner_show_as_percent)) + expect_bool(assign_variable_callback(outliner_show_as_percent)), + "railroads", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(encourage_railroads)) )(node); ret &= add_national_focus( - identifier, group, icon, has_flashpoint, own_provinces, outliner_show_as_percent, std::move(modifiers), - loyalty_ideology, loyalty_value, std::move(limit) + identifier, group, icon, has_flashpoint, flashpoint_tension, own_provinces, outliner_show_as_percent, + std::move(modifiers), loyalty_ideology, loyalty_value, encourage_railroads, + std::move(encourage_goods), std::move(encourage_pop_types), std::move(limit) ); return ret; @@ -127,6 +170,7 @@ bool NationalFocusManager::load_national_foci_file( )(group_node); } )(root); + lock_national_foci(); return ret; @@ -134,8 +178,10 @@ bool NationalFocusManager::load_national_foci_file( bool NationalFocusManager::parse_scripts(DefinitionManager const& definition_manager) { bool ret = true; + for (NationalFocus& national_focus : national_foci.get_items()) { ret &= national_focus.parse_scripts(definition_manager); } + return ret; } |