aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/Modifier.hpp
diff options
context:
space:
mode:
author Steve Frampton <40193522+FarmingtonS9@users.noreply.github.com>2023-09-16 01:15:33 +0200
committer GitHub <noreply@github.com>2023-09-16 01:15:33 +0200
commit879b9debfb97c48ed46d777b2a99d71757658cc6 (patch)
tree87974e84563d08c2f2762b75da0cfb2b4e28eab2 /src/openvic-simulation/Modifier.hpp
parent6278a35f4704574933464700026d8deb997da5c1 (diff)
parent8cf93b6523dc380ef0c7215e15e327a78bf4578e (diff)
Merge pull request #15 from OpenVicProject/more-dataloading
More dataloading
Diffstat (limited to 'src/openvic-simulation/Modifier.hpp')
-rw-r--r--src/openvic-simulation/Modifier.hpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/openvic-simulation/Modifier.hpp b/src/openvic-simulation/Modifier.hpp
new file mode 100644
index 0000000..eb63788
--- /dev/null
+++ b/src/openvic-simulation/Modifier.hpp
@@ -0,0 +1,96 @@
+#pragma once
+
+#include "openvic-simulation/types/IdentifierRegistry.hpp"
+
+namespace OpenVic {
+ struct ModifierManager;
+
+ struct ModifierEffect : HasIdentifier {
+ friend struct ModifierManager;
+
+ private:
+ /* If true, positive values will be green and negative values will be red.
+ * If false, the colours will be switced.
+ */
+ const bool positive_good;
+
+ // TODO - format/precision, e.g. 80% vs 0.8 vs 0.800, 2 vs 2.0 vs 200%
+
+ ModifierEffect(const std::string_view new_identifier, bool new_positive_good);
+
+ public:
+ ModifierEffect(ModifierEffect&&) = default;
+
+ bool get_positive_good() const;
+ };
+
+ struct ModifierValue {
+ using effect_map_t = std::map<ModifierEffect const*, fixed_point_t>;
+ private:
+ effect_map_t values;
+
+ public:
+ ModifierValue();
+ ModifierValue(effect_map_t&& new_values);
+ ModifierValue(ModifierValue const&);
+ ModifierValue(ModifierValue&&);
+
+ /* Removes effect entries with a value of zero. */
+ void trim();
+ size_t get_effect_count() const;
+
+ fixed_point_t get_effect(ModifierEffect const* effect, bool* successful = nullptr);
+ bool has_effect(ModifierEffect const* effect) const;
+
+ 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;
+
+ friend std::ostream& operator<<(std::ostream& stream, ModifierValue const& value);
+ };
+
+ struct Modifier : HasIdentifier, ModifierValue {
+ friend struct ModifierManager;
+
+ using icon_t = uint8_t;
+
+ private:
+ const icon_t icon;
+
+ Modifier(const std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon);
+
+ public:
+ Modifier(Modifier&&) = default;
+
+ icon_t get_icon() const;
+ };
+
+ struct ModifierInstance {
+
+ private:
+ Modifier const& modifier;
+ Date expiry_date;
+
+ public:
+ Modifier const& get_modifier() const;
+ Date const& get_expiry_date() const;
+ };
+
+ struct ModifierManager {
+
+ private:
+ IdentifierRegistry<ModifierEffect> modifier_effects;
+ IdentifierRegistry<Modifier> modifiers;
+
+ public:
+ ModifierManager();
+
+ bool add_modifier_effect(const std::string_view identifier, bool province_good);
+ IDENTIFIER_REGISTRY_ACCESSORS(ModifierEffect, modifier_effect)
+
+ bool add_modifier(const std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon);
+ IDENTIFIER_REGISTRY_ACCESSORS(Modifier, modifier)
+ };
+}