aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/modifier/ModifierSum.cpp
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-09-21 15:23:58 +0200
committer hop311 <hop3114@gmail.com>2024-10-05 21:33:01 +0200
commit2bfd651778bff970991f3bd320a78a4008959b4a (patch)
tree1d3020efbcd14ddd2580fe492f0d5521af4ac33e /src/openvic-simulation/modifier/ModifierSum.cpp
parent9a84e7af70f2528578b00879e568bca285563e9b (diff)
Store sources in ModifierSum
Diffstat (limited to 'src/openvic-simulation/modifier/ModifierSum.cpp')
-rw-r--r--src/openvic-simulation/modifier/ModifierSum.cpp30
1 files changed, 14 insertions, 16 deletions
diff --git a/src/openvic-simulation/modifier/ModifierSum.cpp b/src/openvic-simulation/modifier/ModifierSum.cpp
index 8e5ce48..f603a5b 100644
--- a/src/openvic-simulation/modifier/ModifierSum.cpp
+++ b/src/openvic-simulation/modifier/ModifierSum.cpp
@@ -19,38 +19,36 @@ bool ModifierSum::has_effect(ModifierEffect const& effect) const {
return value_sum.has_effect(effect);
}
-void ModifierSum::add_modifier(Modifier const& modifier, fixed_point_t multiplier) {
- modifiers[&modifier] += multiplier;
+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_sum(ModifierSum const& modifier_sum) {
- modifiers += modifier_sum.modifiers;
+ modifiers.insert(modifiers.end(), modifier_sum.modifiers.begin(), modifier_sum.modifiers.end());
value_sum += modifier_sum.value_sum;
}
-ModifierSum& ModifierSum::operator+=(Modifier const& modifier) {
- add_modifier(modifier);
- return *this;
-}
-
-ModifierSum& ModifierSum::operator+=(ModifierSum const& modifier_sum) {
- add_modifier_sum(modifier_sum);
- return *this;
+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);
+ }
+ }
}
// TODO - include value_sum[effect] in result? Early return if lookup in value_sum fails?
-std::vector<std::pair<Modifier const*, fixed_point_t>> ModifierSum::get_contributing_modifiers(
+std::vector<ModifierSum::modifier_entry_t> ModifierSum::get_contributing_modifiers(
ModifierEffect const& effect
) const {
- std::vector<std::pair<Modifier const*, fixed_point_t>> ret;
+ std::vector<modifier_entry_t> ret;
- for (auto const& [modifier, multiplier] : modifiers) {
+ for (modifier_entry_t const& modifier_entry : modifiers) {
bool effect_found = false;
- const fixed_point_t value = modifier->get_effect(effect, &effect_found);
+ const fixed_point_t value = modifier_entry.modifier->get_effect(effect, &effect_found);
if (effect_found) {
- ret.emplace_back(modifier, value * multiplier);
+ ret.push_back(modifier_entry);
}
}