diff options
author | hop311 <hop3114@gmail.com> | 2024-09-30 22:10:01 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-10-05 22:48:42 +0200 |
commit | f3f364f08cc8f1c80a5dfce689183c2f8f75bbd4 (patch) | |
tree | c7c206ab58440bd8d5200c4416e97a324489d018 /src/openvic-simulation/modifier/Modifier.hpp | |
parent | eb77495ba874d474bbbbc950a65e8f496b13f285 (diff) |
Move ModifierEffect and ModifierValue into their own files
Diffstat (limited to 'src/openvic-simulation/modifier/Modifier.hpp')
-rw-r--r-- | src/openvic-simulation/modifier/Modifier.hpp | 86 |
1 files changed, 2 insertions, 84 deletions
diff --git a/src/openvic-simulation/modifier/Modifier.hpp b/src/openvic-simulation/modifier/Modifier.hpp index f52f126..28e56cd 100644 --- a/src/openvic-simulation/modifier/Modifier.hpp +++ b/src/openvic-simulation/modifier/Modifier.hpp @@ -1,94 +1,12 @@ #pragma once +#include "openvic-simulation/modifier/ModifierEffect.hpp" +#include "openvic-simulation/modifier/ModifierValue.hpp" #include "openvic-simulation/modifier/StaticModifierCache.hpp" #include "openvic-simulation/scripts/ConditionScript.hpp" #include "openvic-simulation/types/IdentifierRegistry.hpp" namespace OpenVic { - struct ModifierManager; - - struct ModifierEffect : HasIdentifier { - friend struct ModifierManager; - - enum class format_t : uint8_t { - PROPORTION_DECIMAL, /* An unscaled fraction/ratio, with 1 being "full"/"whole" */ - PERCENTAGE_DECIMAL, /* A fraction/ratio scaled so that 100 is "full"/"whole" */ - RAW_DECIMAL, /* A continuous quantity, e.g. attack strength */ - INT /* A discrete quantity, e.g. building count limit */ - }; - - enum class target_t : uint8_t { - NO_TARGETS = 0, - COUNTRY = 1 << 0, - PROVINCE = 1 << 1, - UNIT = 1 << 2, - ALL_TARGETS = (1 << 3) - 1 - }; - - private: - /* If true, positive values will be green and negative values will be red. - * If false, the colours will be switced. - */ - const bool PROPERTY_CUSTOM_PREFIX(positive_good, is); - const format_t PROPERTY(format); - const target_t PROPERTY(targets); - std::string PROPERTY(localisation_key); - - // TODO - format/precision, e.g. 80% vs 0.8 vs 0.800, 2 vs 2.0 vs 200% - - ModifierEffect( - std::string_view new_identifier, bool new_positive_good, format_t new_format, target_t mew_targets, - std::string_view new_localisation_key - ); - - public: - ModifierEffect(ModifierEffect&&) = default; - }; - - template<> struct enable_bitfield<ModifierEffect::target_t> : std::true_type {}; - - struct ModifierValue { - friend struct ModifierManager; - - using effect_map_t = fixed_point_map_t<ModifierEffect const*>; - - private: - effect_map_t PROPERTY(values); - - public: - ModifierValue(); - ModifierValue(effect_map_t&& new_values); - ModifierValue(ModifierValue const&); - ModifierValue(ModifierValue&&); - - ModifierValue& operator=(ModifierValue const&); - ModifierValue& operator=(ModifierValue&&); - - /* Removes effect entries with a value of zero. */ - void trim(); - size_t get_effect_count() const; - void clear(); - bool empty() const; - - 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 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; - - void apply_target_filter(ModifierEffect::target_t targets); - void multiply_add_filter(ModifierValue const& other, fixed_point_t multiplier, ModifierEffect::target_t targets); - - friend std::ostream& operator<<(std::ostream& stream, ModifierValue const& value); - }; - struct Modifier : HasIdentifier, ModifierValue { friend struct ModifierManager; |