aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/modifier/ModifierSum.hpp
blob: 0ca8caa1e2f6ce7281692494305193203b0fed54 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once

#include <variant>

#include "openvic-simulation/modifier/ModifierValue.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"

namespace OpenVic {
   struct CountryInstance;
   struct ProvinceInstance;
   struct Modifier;

   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;
         ModifierEffect::target_t targets;

         constexpr modifier_entry_t(
            Modifier const* new_modifier, fixed_point_t new_multiplier, modifier_source_t const& new_source,
            ModifierEffect::target_t new_targets
         ) : modifier { new_modifier }, multiplier { new_multiplier }, source { new_source }, targets { new_targets } {}
      };

   private:
      std::vector<modifier_entry_t> PROPERTY(modifiers);
      ModifierValue PROPERTY(value_sum);

   public:
      ModifierSum() = default;
      ModifierSum(ModifierSum const&) = default;
      ModifierSum(ModifierSum&&) = default;
      ModifierSum& operator=(ModifierSum const&) = default;
      ModifierSum& operator=(ModifierSum&&) = default;

      void clear();
      bool empty();

      fixed_point_t get_effect(ModifierEffect const& effect, bool* effect_found = nullptr) const;
      fixed_point_t get_effect_nullcheck(ModifierEffect const* effect, bool* effect_found = nullptr) const;
      bool has_effect(ModifierEffect const& effect) const;

      void add_modifier(
         Modifier const& modifier, modifier_source_t const& source, fixed_point_t multiplier = fixed_point_t::_1(),
         ModifierEffect::target_t targets = ModifierEffect::target_t::ALL_TARGETS
      );
      void add_modifier_nullcheck(
         Modifier const* modifier, modifier_source_t const& source, fixed_point_t multiplier = fixed_point_t::_1(),
         ModifierEffect::target_t targets = ModifierEffect::target_t::ALL_TARGETS
      );
      void add_modifier_sum(ModifierSum const& modifier_sum);
      void add_modifier_sum_filter_targets(ModifierSum const& modifier_sum, ModifierEffect::target_t targets);
      void add_modifier_sum_exclude_source(ModifierSum const& modifier_sum, modifier_source_t const& excluded_source);

      std::vector<modifier_entry_t> get_contributing_modifiers(ModifierEffect const& effect) const;
   };
}