diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/openvic-simulation/modifier/Modifier.cpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/modifier/Modifier.hpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/modifier/ModifierSum.cpp | 30 | ||||
-rw-r--r-- | src/openvic-simulation/modifier/ModifierSum.hpp | 26 |
4 files changed, 33 insertions, 29 deletions
diff --git a/src/openvic-simulation/modifier/Modifier.cpp b/src/openvic-simulation/modifier/Modifier.cpp index b26b8dd..16a4479 100644 --- a/src/openvic-simulation/modifier/Modifier.cpp +++ b/src/openvic-simulation/modifier/Modifier.cpp @@ -115,10 +115,6 @@ ModifierValue ModifierValue::operator*(fixed_point_t const& right) const { return copy *= right; } -fixed_point_t& ModifierValue::operator[](ModifierEffect const& effect) { - return values[&effect]; -} - void ModifierValue::multiply_add(ModifierValue const& other, fixed_point_t multiplier) { if (multiplier == fixed_point_t::_1()) { *this += other; diff --git a/src/openvic-simulation/modifier/Modifier.hpp b/src/openvic-simulation/modifier/Modifier.hpp index 80d2db6..f290da5 100644 --- a/src/openvic-simulation/modifier/Modifier.hpp +++ b/src/openvic-simulation/modifier/Modifier.hpp @@ -69,8 +69,6 @@ namespace OpenVic { ModifierValue& operator*=(fixed_point_t const& right); ModifierValue operator*(fixed_point_t const& right) const; - fixed_point_t& operator[](ModifierEffect const& effect); - void multiply_add(ModifierValue const& other, fixed_point_t multiplier); friend std::ostream& operator<<(std::ostream& stream, ModifierValue const& value); 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); } } diff --git a/src/openvic-simulation/modifier/ModifierSum.hpp b/src/openvic-simulation/modifier/ModifierSum.hpp index 957ffab..81ae871 100644 --- a/src/openvic-simulation/modifier/ModifierSum.hpp +++ b/src/openvic-simulation/modifier/ModifierSum.hpp @@ -1,12 +1,26 @@ #pragma once #include "openvic-simulation/modifier/Modifier.hpp" -#include "openvic-simulation/types/fixed_point/FixedPointMap.hpp" namespace OpenVic { + struct CountryInstance; + struct ProvinceInstance; + struct ModifierSum { + using modifier_source_t = std::variant<CountryInstance const*, ProvinceInstance const*>; + + struct modifier_entry_t { + Modifier const* modifier; + fixed_point_t multiplier; + modifier_source_t source; + + constexpr modifier_entry_t( + Modifier const* new_modifier, fixed_point_t new_multiplier, modifier_source_t const& new_source + ) : modifier { new_modifier }, multiplier { new_multiplier }, source { new_source } {} + }; + private: - fixed_point_map_t<Modifier const*> PROPERTY(modifiers); + std::vector<modifier_entry_t> PROPERTY(modifiers); ModifierValue PROPERTY(value_sum); public: @@ -19,12 +33,10 @@ namespace OpenVic { fixed_point_t get_effect(ModifierEffect const& effect, bool* effect_found = nullptr) const; bool has_effect(ModifierEffect const& effect) const; - void add_modifier(Modifier const& modifier, fixed_point_t multiplier = fixed_point_t::_1()); + void add_modifier(Modifier const& modifier, modifier_source_t source, fixed_point_t multiplier = fixed_point_t::_1()); void add_modifier_sum(ModifierSum const& modifier_sum); + void add_modifier_sum_exclude_source(ModifierSum const& modifier_sum, modifier_source_t const& excluded_source); - ModifierSum& operator+=(Modifier const& modifier); - ModifierSum& operator+=(ModifierSum const& modifier_sum); - - std::vector<std::pair<Modifier const*, fixed_point_t>> get_contributing_modifiers(ModifierEffect const& effect) const; + std::vector<modifier_entry_t> get_contributing_modifiers(ModifierEffect const& effect) const; }; } |