aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/misc/Modifier.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-12-02 01:41:15 +0100
committer GitHub <noreply@github.com>2023-12-02 01:41:15 +0100
commitcd6875d5e0ca5e2545fd0e1647678cd18a6c81c2 (patch)
tree49016457c09ef3583b200a8bd016dc702b6e298e /src/openvic-simulation/misc/Modifier.cpp
parent0de3d5849cfb9faad0e3c8ce10a8152a916bba21 (diff)
parentc935e471782764dcc10a3175741a02ab3ffffa8e (diff)
Merge pull request #51 from OpenVicProject/dataloading-tech
Dataloading tech
Diffstat (limited to 'src/openvic-simulation/misc/Modifier.cpp')
-rw-r--r--src/openvic-simulation/misc/Modifier.cpp71
1 files changed, 49 insertions, 22 deletions
diff --git a/src/openvic-simulation/misc/Modifier.cpp b/src/openvic-simulation/misc/Modifier.cpp
index 89a411c..86c659b 100644
--- a/src/openvic-simulation/misc/Modifier.cpp
+++ b/src/openvic-simulation/misc/Modifier.cpp
@@ -132,7 +132,7 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("influence_modifier", true);
ret &= add_modifier_effect("issue_change_speed", true);
ret &= add_modifier_effect("land_organisation", true);
- ret &= add_modifier_effect("land_unit_start_experience", true, PERCENTAGE_DECIMAL);
+ ret &= add_modifier_effect("land_unit_start_experience", true, RAW_DECIMAL);
ret &= add_modifier_effect("leadership_modifier", true);
ret &= add_modifier_effect("loan_interest", false);
ret &= add_modifier_effect("max_loan_modifier", true);
@@ -153,7 +153,7 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("mobilisation_impact", false);
ret &= add_modifier_effect("mobilisation_size", true);
ret &= add_modifier_effect("naval_organisation", true);
- ret &= add_modifier_effect("naval_unit_start_experience", true, PERCENTAGE_DECIMAL);
+ ret &= add_modifier_effect("naval_unit_start_experience", true, RAW_DECIMAL);
ret &= add_modifier_effect("non_accepted_pop_consciousness_modifier", false, RAW_DECIMAL);
ret &= add_modifier_effect("non_accepted_pop_militancy_modifier", false, RAW_DECIMAL);
ret &= add_modifier_effect("org_regain", true);
@@ -180,15 +180,23 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("social_reform_desire", false);
ret &= add_modifier_effect("supply_consumption", false);
ret &= add_modifier_effect("tax_efficiency", true);
- ret &= add_modifier_effect("unit_start_experience", true, PERCENTAGE_DECIMAL);
+ ret &= add_modifier_effect("unit_start_experience", true, RAW_DECIMAL);
ret &= add_modifier_effect("war_exhaustion", false);
-
- // TODO: make technology group modifiers dynamic
- ret &= add_modifier_effect("army_tech_research_bonus", true);
- ret &= add_modifier_effect("commerce_tech_research_bonus", true);
- ret &= add_modifier_effect("culture_tech_research_bonus", true);
- ret &= add_modifier_effect("industry_tech_research_bonus", true);
- ret &= add_modifier_effect("navy_tech_research_bonus", true);
+ ret &= add_modifier_effect("reinforce_rate", true);
+ ret &= add_modifier_effect("colonial_migration", true);
+ ret &= add_modifier_effect("supply_range", true);
+ ret &= add_modifier_effect("colonial_points", true, INT);
+ ret &= add_modifier_effect("diplomatic_points", true);
+ ret &= add_modifier_effect("cb_creation_speed", true); //seemingly works the same way as cb_generation_speed_modifier
+ ret &= add_modifier_effect("education_efficiency", true);
+ ret &= add_modifier_effect("increase_research", true);
+ ret &= add_modifier_effect("influence", true);
+ ret &= add_modifier_effect("administrative_efficiency", true);
+ ret &= add_modifier_effect("tax_eff", true);
+ ret &= add_modifier_effect("military_tactics", true);
+ 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);
/* Province Modifier Effects */
ret &= add_modifier_effect("assimilation_rate", true);
@@ -235,6 +243,10 @@ bool ModifierManager::setup_modifier_effects() {
return ret;
}
+void ModifierManager::register_complex_modifier(std::string_view identifier) {
+ complex_modifiers.emplace(identifier);
+}
+
bool ModifierManager::load_crime_modifiers(ast::NodeCPtr root) {
// TODO - DEV TASK: read crime modifiers
return true;
@@ -271,23 +283,38 @@ 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<bool(ModifierEffect const*, ast::NodeCPtr)> 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);
+ } else {
+ Logger::error("Duplicate modifier effect: ", effect->get_identifier());
+ return false;
+ }
+ } else {
+ Logger::error("Failed to validate modifier effect: ", effect->get_identifier());
+ return false;
+ }
+ };
- return [this, &modifier, default_callback, effect_validator](std::string_view key, ast::NodeCPtr value) -> bool {
+ return [this, &modifier, default_callback, effect_validator, add_modifier_cb](std::string_view key, ast::NodeCPtr value) -> bool {
ModifierEffect const* effect = get_modifier_effect_by_identifier(key);
- if (effect != nullptr) {
- if (effect_validator(*effect)) {
- if (!modifier.values.contains(effect)) {
- return expect_fixed_point(assign_variable_callback(modifier.values[effect]))(value);
+ if (effect != nullptr && value->is_type<ast::IdentifierNode>()) {
+ return add_modifier_cb(effect, value);
+ } else if (complex_modifiers.contains(key) && value->is_derived_from<ast::AbstractListNode>()) {
+ 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("Duplicate modifier effect: ", key);
+ Logger::error("Could not find flattened modifier: ", flat_identifier);
return false;
}
- } else {
- Logger::error("Failed to validate modifier effect: ", key);
- return false;
- }
- }
- return default_callback(key, value);
+ })(value);
+ } else return default_callback(key, value);
};
}