diff options
author | hop311 <hop3114@gmail.com> | 2024-09-25 23:10:21 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-10-05 22:48:41 +0200 |
commit | 4f9fd8a327b6de5fb32792a07453e9a2e245dc84 (patch) | |
tree | dc92397c8d16df21d612ad5159b8fd9b19353eb7 /src/openvic-simulation/modifier/ModifierSum.cpp | |
parent | fb6b9439c219239691eb0201ec3f431b5dfe4893 (diff) |
Add ModifierEffect targets
Diffstat (limited to 'src/openvic-simulation/modifier/ModifierSum.cpp')
-rw-r--r-- | src/openvic-simulation/modifier/ModifierSum.cpp | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/openvic-simulation/modifier/ModifierSum.cpp b/src/openvic-simulation/modifier/ModifierSum.cpp index f603a5b..312432a 100644 --- a/src/openvic-simulation/modifier/ModifierSum.cpp +++ b/src/openvic-simulation/modifier/ModifierSum.cpp @@ -19,9 +19,15 @@ bool ModifierSum::has_effect(ModifierEffect const& effect) const { return value_sum.has_effect(effect); } -void ModifierSum::add_modifier(Modifier const& modifier, modifier_source_t source, fixed_point_t multiplier) { - modifiers.emplace_back(&modifier, multiplier, source); - value_sum.multiply_add(modifier, multiplier); +void ModifierSum::add_modifier( + Modifier const& modifier, modifier_source_t const& source, fixed_point_t multiplier, ModifierEffect::target_t targets +) { + using enum ModifierEffect::target_t; + + if (multiplier != fixed_point_t::_0() && targets != NO_TARGETS) { + modifiers.emplace_back(&modifier, multiplier, source, targets); + value_sum.multiply_add_filter(modifier, multiplier, targets); + } } void ModifierSum::add_modifier_sum(ModifierSum const& modifier_sum) { @@ -29,10 +35,22 @@ void ModifierSum::add_modifier_sum(ModifierSum const& modifier_sum) { value_sum += modifier_sum.value_sum; } +void ModifierSum::add_modifier_sum_filter_targets(ModifierSum const& modifier_sum, ModifierEffect::target_t targets) { + using enum ModifierEffect::target_t; + + for (modifier_entry_t const& modifier_entry : modifier_sum.modifiers) { + ModifierEffect::target_t new_targets = modifier_entry.targets & targets; + + if (new_targets != NO_TARGETS) { + add_modifier(*modifier_entry.modifier, modifier_entry.source, modifier_entry.multiplier, new_targets); + } + } +} + void ModifierSum::add_modifier_sum_exclude_source(ModifierSum const& modifier_sum, modifier_source_t const& excluded_source) { for (modifier_entry_t const& modifier_entry : modifier_sum.modifiers) { if (modifier_entry.source != excluded_source) { - add_modifier(*modifier_entry.modifier, modifier_entry.source, modifier_entry.multiplier); + add_modifier(*modifier_entry.modifier, modifier_entry.source, modifier_entry.multiplier, modifier_entry.targets); } } } @@ -41,14 +59,18 @@ void ModifierSum::add_modifier_sum_exclude_source(ModifierSum const& modifier_su std::vector<ModifierSum::modifier_entry_t> ModifierSum::get_contributing_modifiers( ModifierEffect const& effect ) const { + using enum ModifierEffect::target_t; + std::vector<modifier_entry_t> ret; for (modifier_entry_t const& modifier_entry : modifiers) { - bool effect_found = false; - const fixed_point_t value = modifier_entry.modifier->get_effect(effect, &effect_found); + if ((modifier_entry.targets & effect.get_targets()) != NO_TARGETS) { + bool effect_found = false; + const fixed_point_t value = modifier_entry.modifier->get_effect(effect, &effect_found); - if (effect_found) { - ret.push_back(modifier_entry); + if (effect_found) { + ret.push_back(modifier_entry); + } } } |