diff options
author | hop311 <hop3114@gmail.com> | 2023-12-06 23:10:53 +0100 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2023-12-07 21:38:17 +0100 |
commit | 398377011cb3d3c970451dcd215f3610159f1ae2 (patch) | |
tree | 2a73255f595eabb1441419a08bd0d5e5407213e7 /src/openvic-simulation/misc | |
parent | 48a3f1729d709847d7cad33f594c77cac414e802 (diff) |
Vec/set callbacks + crime file + prov building pos
Diffstat (limited to 'src/openvic-simulation/misc')
-rw-r--r-- | src/openvic-simulation/misc/Define.cpp | 1 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Modifier.cpp | 48 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Modifier.hpp | 19 |
3 files changed, 8 insertions, 60 deletions
diff --git a/src/openvic-simulation/misc/Define.cpp b/src/openvic-simulation/misc/Define.cpp index cfd96a6..9e468d9 100644 --- a/src/openvic-simulation/misc/Define.cpp +++ b/src/openvic-simulation/misc/Define.cpp @@ -1,4 +1,3 @@ - #include "Define.hpp" #include <cassert> diff --git a/src/openvic-simulation/misc/Modifier.cpp b/src/openvic-simulation/misc/Modifier.cpp index 87a6b65..1b3e551 100644 --- a/src/openvic-simulation/misc/Modifier.cpp +++ b/src/openvic-simulation/misc/Modifier.cpp @@ -84,13 +84,9 @@ TriggeredModifier::TriggeredModifier(std::string_view new_identifier, ModifierVa ModifierInstance::ModifierInstance(Modifier const& modifier, Date expiry_date) : modifier { modifier }, expiry_date { expiry_date } {} -Crime::Crime(std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon, bool new_default_active) - : TriggeredModifier { new_identifier, std::move(new_values), new_icon }, default_active { new_default_active }, - active { new_default_active } {} - ModifierManager::ModifierManager() - : modifier_effects { "modifier effects" }, crime_modifiers { "crime modifiers" }, event_modifiers { "event modifiers" }, - static_modifiers { "static modifiers" }, triggered_modifiers { "triggered modifiers" } {} + : modifier_effects { "modifier effects" }, event_modifiers { "event modifiers" }, static_modifiers { "static modifiers" }, + triggered_modifiers { "triggered modifiers" } {} bool ModifierManager::add_modifier_effect(std::string_view identifier, bool positive_good, ModifierEffect::format_t format) { if (identifier.empty()) { @@ -261,38 +257,6 @@ void ModifierManager::register_complex_modifier(std::string_view identifier) { complex_modifiers.emplace(identifier); } -bool ModifierManager::add_crime_modifier( - std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, bool active -) { - if (identifier.empty()) { - Logger::error("Invalid crime modifier effect identifier - empty!"); - return false; - } - return crime_modifiers.add_item({ identifier, std::move(values), icon, active }, duplicate_warning_callback); -} - -bool ModifierManager::load_crime_modifiers(ast::NodeCPtr root) { - const bool ret = expect_dictionary_reserve_length( - crime_modifiers, - [this](std::string_view key, ast::NodeCPtr value) -> bool { - ModifierValue modifier_value; - Modifier::icon_t icon = 0; - bool active = false; - bool ret = expect_modifier_value_and_keys( - move_variable_callback(modifier_value), - "icon", ZERO_OR_ONE, expect_uint(assign_variable_callback(icon)), - "trigger", ONE_EXACTLY, success_callback, // TODO - load condition - "active", ZERO_OR_ONE, expect_bool(assign_variable_callback(active)) - )(value); - ret &= add_crime_modifier(key, std::move(modifier_value), icon, active); - return ret; - } - )(root); - lock_crime_modifiers(); - return ret; - return true; -} - bool ModifierManager::add_event_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon) { if (identifier.empty()) { Logger::error("Invalid event modifier effect identifier - empty!"); @@ -410,8 +374,12 @@ key_value_callback_t ModifierManager::_modifier_effect_callback( )(value); ret &= add_flattened_modifier_cb(key, faction_identifier, value_node); return ret; - } else return expect_dictionary(std::bind(add_flattened_modifier_cb, key, std::placeholders::_1, std::placeholders::_2))(value); - } else return default_callback(key, value); + } else { + return expect_dictionary(std::bind_front(add_flattened_modifier_cb, key))(value); + } + } else { + return default_callback(key, value); + } }; } diff --git a/src/openvic-simulation/misc/Modifier.hpp b/src/openvic-simulation/misc/Modifier.hpp index f3678d9..617159a 100644 --- a/src/openvic-simulation/misc/Modifier.hpp +++ b/src/openvic-simulation/misc/Modifier.hpp @@ -1,7 +1,6 @@ #pragma once #include "openvic-simulation/types/IdentifierRegistry.hpp" -#include <unordered_set> namespace OpenVic { struct ModifierManager; @@ -93,19 +92,6 @@ namespace OpenVic { TriggeredModifier(TriggeredModifier&&) = default; }; - struct Crime final : TriggeredModifier { - friend struct ModifierManager; - - private: - const bool PROPERTY(default_active); - bool PROPERTY_RW(active); - - Crime(std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon, bool new_default_active); - - public: - Crime(Crime&&) = default; - }; - struct ModifierInstance { private: @@ -127,7 +113,6 @@ namespace OpenVic { IdentifierInstanceRegistry<ModifierEffect> modifier_effects; string_set_t complex_modifiers; - IdentifierRegistry<Crime> crime_modifiers; IdentifierRegistry<Modifier> event_modifiers; IdentifierRegistry<Modifier> static_modifiers; IdentifierRegistry<TriggeredModifier> triggered_modifiers; @@ -151,10 +136,6 @@ namespace OpenVic { bool setup_modifier_effects(); - bool add_crime_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, bool active); - IDENTIFIER_REGISTRY_ACCESSORS(crime_modifier) - bool load_crime_modifiers(ast::NodeCPtr root); - bool add_event_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon); IDENTIFIER_REGISTRY_ACCESSORS(event_modifier) bool load_event_modifiers(ast::NodeCPtr root); |