diff options
Diffstat (limited to 'src/openvic-simulation/misc/Modifier.cpp')
-rw-r--r-- | src/openvic-simulation/misc/Modifier.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/openvic-simulation/misc/Modifier.cpp b/src/openvic-simulation/misc/Modifier.cpp index 94d38e0..bbc8f59 100644 --- a/src/openvic-simulation/misc/Modifier.cpp +++ b/src/openvic-simulation/misc/Modifier.cpp @@ -82,8 +82,13 @@ ModifierValue ModifierValue::operator-(ModifierValue const& right) const { Modifier::Modifier(std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon) : HasIdentifier { new_identifier }, ModifierValue { std::move(new_values) }, icon { new_icon } {} -TriggeredModifier::TriggeredModifier(std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon) - : Modifier { new_identifier, std::move(new_values), new_icon } {} +TriggeredModifier::TriggeredModifier( + std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon, ConditionScript&& new_trigger +) : Modifier { new_identifier, std::move(new_values), new_icon }, trigger { std::move(new_trigger) } {} + +bool TriggeredModifier::parse_scripts(GameManager const& game_manager) { + return trigger.parse_script(false, game_manager); +} ModifierInstance::ModifierInstance(Modifier const& modifier, Date expiry_date) : modifier { modifier }, expiry_date { expiry_date } {} @@ -319,12 +324,14 @@ bool ModifierManager::load_static_modifiers(ast::NodeCPtr root) { return ret; } -bool ModifierManager::add_triggered_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon) { +bool ModifierManager::add_triggered_modifier( + std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, ConditionScript&& trigger +) { if (identifier.empty()) { Logger::error("Invalid triggered modifier effect identifier - empty!"); return false; } - return triggered_modifiers.add_item({ identifier, std::move(values), icon }, duplicate_warning_callback); + return triggered_modifiers.add_item({ identifier, std::move(values), icon, std::move(trigger) }, duplicate_warning_callback); } bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) { @@ -333,12 +340,14 @@ bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) { [this](std::string_view key, ast::NodeCPtr value) -> bool { ModifierValue modifier_value; Modifier::icon_t icon = 0; + ConditionScript trigger; + bool ret = expect_modifier_value_and_keys( move_variable_callback(modifier_value), "icon", ZERO_OR_ONE, expect_uint(assign_variable_callback(icon)), - "trigger", ONE_EXACTLY, success_callback // TODO - load condition + "trigger", ONE_EXACTLY, trigger.expect_script() )(value); - ret &= add_triggered_modifier(key, std::move(modifier_value), icon); + ret &= add_triggered_modifier(key, std::move(modifier_value), icon, std::move(trigger)); return ret; } )(root); @@ -346,6 +355,14 @@ bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) { return ret; } +bool ModifierManager::parse_scripts(GameManager const& game_manager) { + bool ret = true; + for (TriggeredModifier& modifier : triggered_modifiers.get_items()) { + ret &= modifier.parse_scripts(game_manager); + } + return ret; +} + key_value_callback_t ModifierManager::_modifier_effect_callback( ModifierValue& modifier, key_value_callback_t default_callback, ModifierEffectValidator auto effect_validator ) const { |