From fa2ca50905f327713207069cf9a2e66cf6c00076 Mon Sep 17 00:00:00 2001 From: zaaarf Date: Tue, 5 Dec 2023 10:16:27 +0100 Subject: feat: implemented invention dataloading --- src/openvic-simulation/misc/Modifier.cpp | 49 +++++++++++++++++++++++--------- src/openvic-simulation/misc/Modifier.hpp | 2 +- 2 files changed, 36 insertions(+), 15 deletions(-) (limited to 'src/openvic-simulation/misc') diff --git a/src/openvic-simulation/misc/Modifier.cpp b/src/openvic-simulation/misc/Modifier.cpp index 6ad14aa..87a6b65 100644 --- a/src/openvic-simulation/misc/Modifier.cpp +++ b/src/openvic-simulation/misc/Modifier.cpp @@ -1,4 +1,5 @@ #include "Modifier.hpp" +#include using namespace OpenVic; using namespace OpenVic::NodeTools; @@ -196,6 +197,17 @@ bool ModifierManager::setup_modifier_effects() { ret &= add_modifier_effect("dig_in_cap", true, INT); ret &= add_modifier_effect("max_national_focus", true, INT); ret &= add_modifier_effect("regular_experience_level", true, RAW_DECIMAL); + ret &= add_modifier_effect("land_attrition", false); + ret &= add_modifier_effect("naval_attrition", false); + ret &= add_modifier_effect("permanent_prestige", true, RAW_DECIMAL); + ret &= add_modifier_effect("shared_prestige", true, RAW_DECIMAL); + ret &= add_modifier_effect("colonial_prestige", true); + ret &= add_modifier_effect("soldier_to_pop_loss", true); + ret &= add_modifier_effect("pop_growth", true); + ret &= add_modifier_effect("plurality", true, PERCENTAGE_DECIMAL); + ret &= add_modifier_effect("suppression_points_modifier", true); + ret &= add_modifier_effect("colonial_life_rating", false, INT); + ret &= add_modifier_effect("seperatism", false); //paradox typo /* Province Modifier Effects */ ret &= add_modifier_effect("assimilation_rate", true); @@ -359,7 +371,7 @@ bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) { key_value_callback_t ModifierManager::_modifier_effect_callback( ModifierValue& modifier, key_value_callback_t default_callback, ModifierEffectValidator auto effect_validator ) const { - std::function add_modifier_cb = [this, &modifier, effect_validator](ModifierEffect const* effect, ast::NodeCPtr value) -> bool { + const auto add_modifier_cb = [this, &modifier, effect_validator](ModifierEffect const* effect, ast::NodeCPtr value) -> bool { if (effect_validator(*effect)) { if (!modifier.values.contains(effect)) { return expect_fixed_point(assign_variable_callback(modifier.values[effect]))(value); @@ -373,23 +385,32 @@ key_value_callback_t ModifierManager::_modifier_effect_callback( } }; - return [this, &modifier, default_callback, effect_validator, add_modifier_cb](std::string_view key, ast::NodeCPtr value) -> bool { + const auto add_flattened_modifier_cb = [this, add_modifier_cb](std::string_view prefix, std::string_view key, ast::NodeCPtr value) -> bool { + const std::string flat_identifier = StringUtils::append_string_views(prefix, "_", key); + ModifierEffect const* effect = get_modifier_effect_by_identifier(flat_identifier); + if (effect != nullptr) { + return add_modifier_cb(effect, value); + } else { + Logger::error("Could not find flattened modifier: ", flat_identifier); + return false; + } + }; + + return [this, default_callback, add_modifier_cb, add_flattened_modifier_cb](std::string_view key, ast::NodeCPtr value) -> bool { ModifierEffect const* effect = get_modifier_effect_by_identifier(key); if (effect != nullptr && value->is_type()) { return add_modifier_cb(effect, value); } else if (complex_modifiers.contains(key) && value->is_derived_from()) { - return expect_dictionary([this, &key, &add_modifier_cb, &default_callback](std::string_view identifier, ast::NodeCPtr node) -> bool { - std::string flat_identifier = std::string(key); - flat_identifier += "_"; - flat_identifier += identifier; - ModifierEffect const* effect = get_modifier_effect_by_identifier(flat_identifier); - if(effect != nullptr) { - return add_modifier_cb(effect, node); - } else { - Logger::error("Could not find flattened modifier: ", flat_identifier); - return false; - } - })(value); + if (key == "rebel_org_gain") { //because of course there's a special one + std::string_view faction_identifier; + ast::NodeCPtr value_node = nullptr; + bool ret = expect_dictionary_keys( + "faction", ONE_EXACTLY, expect_identifier(assign_variable_callback(faction_identifier)), + "value", ONE_EXACTLY, assign_variable_callback(value_node) + )(value); + ret &= add_flattened_modifier_cb(key, faction_identifier, value_node); + return ret; + } else return expect_dictionary(std::bind(add_flattened_modifier_cb, key, std::placeholders::_1, std::placeholders::_2))(value); } else return default_callback(key, value); }; } diff --git a/src/openvic-simulation/misc/Modifier.hpp b/src/openvic-simulation/misc/Modifier.hpp index 9665e07..f3678d9 100644 --- a/src/openvic-simulation/misc/Modifier.hpp +++ b/src/openvic-simulation/misc/Modifier.hpp @@ -11,7 +11,7 @@ namespace OpenVic { PROPORTION_DECIMAL, /* An unscaled fraction/ratio, with 1 being "full"/"whole" */ PERCENTAGE_DECIMAL, /* A fraction/ratio scaled so that 100 is "full"/"whole" */ RAW_DECIMAL, /* A continuous quantity, e.g. attack strength */ - INT /* A discrete quantity, e.g. building count limit */ + INT /* A discrete quantity, e.g. building count limit */ }; friend std::unique_ptr std::make_unique(std::string_view&&, bool&&, format_t&&); -- cgit v1.2.3-56-ga3b1