diff options
author | hop311 <hop3114@gmail.com> | 2024-09-20 22:44:48 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-09-20 22:44:48 +0200 |
commit | 118570dc7cf9ae9daf324c2aaba5a5d86fb2c330 (patch) | |
tree | 71bf13dad720ad8adb90a9824e7cf0fe08d4e3af /src | |
parent | b68a21c773af4d53343ad8c2b732943a7d13608f (diff) |
Store national focus encouragement in specific variables rather than modifier effects
Diffstat (limited to 'src')
-rw-r--r-- | src/openvic-simulation/economy/GoodDefinition.cpp | 7 | ||||
-rw-r--r-- | src/openvic-simulation/modifier/Modifier.cpp | 7 | ||||
-rw-r--r-- | src/openvic-simulation/politics/NationalFocus.cpp | 49 | ||||
-rw-r--r-- | src/openvic-simulation/politics/NationalFocus.hpp | 14 | ||||
-rw-r--r-- | src/openvic-simulation/pop/Pop.cpp | 7 |
5 files changed, 57 insertions, 27 deletions
diff --git a/src/openvic-simulation/economy/GoodDefinition.cpp b/src/openvic-simulation/economy/GoodDefinition.cpp index 82d3719..ed24549 100644 --- a/src/openvic-simulation/economy/GoodDefinition.cpp +++ b/src/openvic-simulation/economy/GoodDefinition.cpp @@ -123,12 +123,5 @@ bool GoodDefinitionManager::generate_modifiers(ModifierManager& modifier_manager return StringUtils::append_string_views(good_identifier, "_RGO_SIZE"); }); - for (GoodDefinition const& good : get_good_definitions()) { - ret &= modifier_manager.add_modifier_effect( - good.get_identifier(), true, PERCENTAGE_DECIMAL, - StringUtils::append_string_views("$ENCOURAGEMENT_FOR$$", good.get_identifier(), "$") - ); - } - return ret; } diff --git a/src/openvic-simulation/modifier/Modifier.cpp b/src/openvic-simulation/modifier/Modifier.cpp index 28aa777..6d0f42a 100644 --- a/src/openvic-simulation/modifier/Modifier.cpp +++ b/src/openvic-simulation/modifier/Modifier.cpp @@ -317,13 +317,6 @@ bool ModifierManager::setup_modifier_effects() { ret &= add_modifier_effect("unit_recruitment_time", false); ret &= add_modifier_effect("war_exhaustion", false, PROPORTION_DECIMAL, "WAR_EXHAUST_BATTLES"); - /* State only */ - // replace $VAL$ with effect value * 30 (as proportion decimal, only used in national foci) - ret &= add_modifier_effect("flashpoint_tension", true, PROPORTION_DECIMAL, "increase_tension_focus_desc"); - // capitalist likelihood for railroads vs factories - // replace $VAL$ with effect value (as proportion decimal, only used in national foci) - ret &= add_modifier_effect("railroads", true, PROPORTION_DECIMAL, "railroad_build_desc"); - /* Province Modifier Effects */ ret &= add_modifier_effect("assimilation_rate", true); ret &= add_modifier_effect("boost_strongest_party", false); diff --git a/src/openvic-simulation/politics/NationalFocus.cpp b/src/openvic-simulation/politics/NationalFocus.cpp index 3132c3e..bf5d728 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) }, 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) { @@ -45,11 +55,15 @@ 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()) { @@ -67,8 +81,9 @@ inline bool NationalFocusManager::add_national_focus( ); } 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) }); } @@ -97,29 +112,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; diff --git a/src/openvic-simulation/politics/NationalFocus.hpp b/src/openvic-simulation/politics/NationalFocus.hpp index 327b25b..e046c7a 100644 --- a/src/openvic-simulation/politics/NationalFocus.hpp +++ b/src/openvic-simulation/politics/NationalFocus.hpp @@ -16,6 +16,8 @@ namespace OpenVic { }; struct Ideology; + struct GoodDefinition; + struct PopType; struct NationalFocus : Modifier { friend struct NationalFocusManager; @@ -24,10 +26,14 @@ namespace OpenVic { NationalFocusGroup const& PROPERTY(group); uint8_t PROPERTY(icon); bool PROPERTY(has_flashpoint); + fixed_point_t PROPERTY(flashpoint_tension); bool PROPERTY(own_provinces); bool PROPERTY(outliner_show_as_percent); Ideology const* PROPERTY(loyalty_ideology); fixed_point_t PROPERTY(loyalty_value); + fixed_point_t PROPERTY(encourage_railroads); + fixed_point_map_t<GoodDefinition const*> PROPERTY(encourage_goods); + fixed_point_map_t<PopType const*> PROPERTY(encourage_pop_types); ConditionScript PROPERTY(limit); NationalFocus( @@ -35,11 +41,15 @@ namespace OpenVic { 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 ); @@ -66,11 +76,15 @@ namespace OpenVic { 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 ); diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp index d534fed..dd829d9 100644 --- a/src/openvic-simulation/pop/Pop.cpp +++ b/src/openvic-simulation/pop/Pop.cpp @@ -674,13 +674,6 @@ bool PopManager::generate_modifiers(ModifierManager& modifier_manager) const { strata_modifier("_luxury_needs", false); } - for (PopType const& pop_type : get_pop_types()) { - ret &= modifier_manager.add_modifier_effect( - pop_type.get_identifier(), true, PROPORTION_DECIMAL, - StringUtils::append_string_views("$ENCOURAGEMENT_FOR$$", pop_type.get_identifier(), "$") - ); - } - return ret; } |