aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/misc/Modifier.hpp
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-09-19 00:37:35 +0200
committer hop311 <hop3114@gmail.com>2024-09-19 00:37:35 +0200
commiteac76ba7c8dc714535c67b8febef3168b1670caf (patch)
treebbba559afe6047e89dca5e923ccdd7e07e6d55f2 /src/openvic-simulation/misc/Modifier.hpp
parent00a3121dd43a3b6e8f5a6efa2d3b6560ef78c370 (diff)
Add ModifierSum and improve ModifierValue
Diffstat (limited to 'src/openvic-simulation/misc/Modifier.hpp')
-rw-r--r--src/openvic-simulation/misc/Modifier.hpp38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/openvic-simulation/misc/Modifier.hpp b/src/openvic-simulation/misc/Modifier.hpp
index f3cc0f6..c36585f 100644
--- a/src/openvic-simulation/misc/Modifier.hpp
+++ b/src/openvic-simulation/misc/Modifier.hpp
@@ -57,14 +57,21 @@ namespace OpenVic {
void clear();
bool empty() const;
- fixed_point_t get_effect(ModifierEffect const* effect, bool* successful = nullptr);
+ fixed_point_t get_effect(ModifierEffect const* effect, bool* successful = nullptr) const;
bool has_effect(ModifierEffect const* effect) const;
+ void set_effect(ModifierEffect const* effect, fixed_point_t value);
ModifierValue& operator+=(ModifierValue const& right);
ModifierValue operator+(ModifierValue const& right) const;
ModifierValue operator-() const;
ModifierValue& operator-=(ModifierValue const& right);
ModifierValue operator-(ModifierValue const& right) const;
+ 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);
};
@@ -105,10 +112,35 @@ namespace OpenVic {
struct ModifierInstance {
private:
- Modifier const& PROPERTY(modifier);
+ Modifier const* PROPERTY(modifier); // We can assume this is never null
Date PROPERTY(expiry_date);
- ModifierInstance(Modifier const& modifier, Date expiry_date);
+ public:
+ ModifierInstance(Modifier const& new_modifier, Date new_expiry_date);
+ };
+
+ struct ModifierSum {
+ private:
+ fixed_point_map_t<Modifier const*> PROPERTY(modifiers);
+ ModifierValue PROPERTY(value_sum);
+
+ public:
+ ModifierSum() = default;
+ ModifierSum(ModifierSum&&) = default;
+
+ void clear();
+ bool empty();
+
+ fixed_point_t get_effect(ModifierEffect const* effect, bool* successful = 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_sum(ModifierSum const& modifier_sum);
+
+ 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;
};
template<typename Fn>