aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/Modifier.hpp
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-10-13 18:34:25 +0200
committer hop311 <hop3114@gmail.com>2023-10-13 19:14:01 +0200
commitce6e70d079f4ab18cdfa082032dc3580ab233b0e (patch)
tree0e2d1e13c35c0ea97acc5474c41adb69207277d4 /src/openvic-simulation/Modifier.hpp
parent17847e16e14ec52eb48a6fd0d9dc36ee93e457db (diff)
TGC compatibility fixes + other cleanup
Diffstat (limited to 'src/openvic-simulation/Modifier.hpp')
-rw-r--r--src/openvic-simulation/Modifier.hpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/openvic-simulation/Modifier.hpp b/src/openvic-simulation/Modifier.hpp
index 2e1b03a..663d359 100644
--- a/src/openvic-simulation/Modifier.hpp
+++ b/src/openvic-simulation/Modifier.hpp
@@ -8,26 +8,32 @@ namespace OpenVic {
struct ModifierEffect : HasIdentifier {
friend struct ModifierManager;
+ enum class format_t {
+ RAW_DECIMAL, PERCENTAGE_DECIMAL, INT
+ };
+
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;
+ const format_t format;
// 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);
+ ModifierEffect(std::string_view new_identifier, bool new_positive_good, format_t new_format);
public:
ModifierEffect(ModifierEffect&&) = default;
bool get_positive_good() const;
+ format_t get_format() const;
};
struct ModifierValue {
friend struct ModifierManager;
- using effect_map_t = std::map<ModifierEffect const*, fixed_point_t>;
+ using effect_map_t = decimal_map_t<ModifierEffect const*>;
private:
effect_map_t values;
@@ -95,7 +101,7 @@ namespace OpenVic {
public:
ModifierManager();
- bool add_modifier_effect(std::string_view identifier, bool province_good);
+ bool add_modifier_effect(std::string_view identifier, bool province_good, ModifierEffect::format_t format = ModifierEffect::format_t::PERCENTAGE_DECIMAL);
IDENTIFIER_REGISTRY_ACCESSORS(modifier_effect)
bool add_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon);
@@ -110,12 +116,10 @@ namespace OpenVic {
NodeTools::node_callback_t expect_modifier_value_and_key_map(NodeTools::callback_t<ModifierValue&&> modifier_callback, NodeTools::key_map_t&& key_map) const;
template<typename... Args>
- NodeTools::node_callback_t expect_modifier_value_and_key_map_and_default(
- NodeTools::callback_t<ModifierValue&&> modifier_callback, NodeTools::key_value_callback_t default_callback, NodeTools::key_map_t&& key_map,
- std::string_view key, NodeTools::dictionary_entry_t::expected_count_t expected_count, NodeTools::node_callback_t callback,
- Args... args) const {
- NodeTools::add_key_map_entry(key_map, key, expected_count, callback);
- return expect_modifier_value_and_key_map_and_default(modifier_callback, default_callback, std::move(key_map), args...);
+ NodeTools::node_callback_t expect_modifier_value_and_key_map_and_default(NodeTools::callback_t<ModifierValue&&> modifier_callback,
+ NodeTools::key_value_callback_t default_callback, NodeTools::key_map_t&& key_map, Args... args) const {
+ NodeTools::add_key_map_entries(key_map, args...);
+ return expect_modifier_value_and_key_map_and_default(modifier_callback, default_callback, std::move(key_map));
}
template<typename... Args>