diff options
author | Hop311 <Hop3114@gmail.com> | 2024-10-20 20:44:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-20 20:44:51 +0200 |
commit | 6527f832a5e14a28fc1f5b85628541038eb90141 (patch) | |
tree | aca829171be7b1144cb3ca29510593fa8a84af24 /src/openvic-simulation/modifier/ModifierEffect.hpp | |
parent | 9a84e7af70f2528578b00879e568bca285563e9b (diff) | |
parent | 5194a3d043db66b81470111a94f3b1cdf8d42176 (diff) |
Merge pull request #198 from OpenVicProject/resultant-modifier
Calculate country and province modifier sums
Diffstat (limited to 'src/openvic-simulation/modifier/ModifierEffect.hpp')
-rw-r--r-- | src/openvic-simulation/modifier/ModifierEffect.hpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/openvic-simulation/modifier/ModifierEffect.hpp b/src/openvic-simulation/modifier/ModifierEffect.hpp new file mode 100644 index 0000000..ff82acf --- /dev/null +++ b/src/openvic-simulation/modifier/ModifierEffect.hpp @@ -0,0 +1,63 @@ +#pragma once + +#include <string> +#include <string_view> + +#include "openvic-simulation/types/EnumBitfield.hpp" +#include "openvic-simulation/types/HasIdentifier.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 + }; + + static constexpr bool excludes_targets(target_t targets, target_t excluded_target); + + static std::string target_to_string(target_t target); + + static std::string make_default_modifier_effect_localisation_key(std::string_view identifier); + + 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 {}; + + constexpr bool ModifierEffect::excludes_targets(target_t targets, target_t excluded_targets) { + using enum target_t; + + return (targets & excluded_targets) == NO_TARGETS; + } +} |