From 28081085a8bbebe978e2d3d79b5cf664a447b9a6 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Tue, 28 May 2024 16:43:28 +0000 Subject: [PATCH] Create separate instance of updater for every bonus --- lib/bonuses/Updaters.cpp | 8 -------- lib/bonuses/Updaters.h | 4 +--- lib/json/JsonBonus.cpp | 18 ++++++++++++++++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/bonuses/Updaters.cpp b/lib/bonuses/Updaters.cpp index 5a41aa047..fd9d94cd6 100644 --- a/lib/bonuses/Updaters.cpp +++ b/lib/bonuses/Updaters.cpp @@ -19,14 +19,6 @@ VCMI_LIB_NAMESPACE_BEGIN -const std::map bonusUpdaterMap = -{ - {"TIMES_HERO_LEVEL", std::make_shared()}, - {"TIMES_STACK_LEVEL", std::make_shared()}, - {"ARMY_MOVEMENT", std::make_shared()}, - {"BONUS_OWNER_UPDATER", std::make_shared()} -}; - std::shared_ptr IUpdater::createUpdatedBonus(const std::shared_ptr & b, const CBonusSystemNode & context) const { return b; diff --git a/lib/bonuses/Updaters.h b/lib/bonuses/Updaters.h index 8e3a7ed49..551304f4c 100644 --- a/lib/bonuses/Updaters.h +++ b/lib/bonuses/Updaters.h @@ -13,8 +13,6 @@ VCMI_LIB_NAMESPACE_BEGIN -extern DLL_LINKAGE const std::map bonusUpdaterMap; - // observers for updating bonuses based on certain events (e.g. hero gaining level) class DLL_LINKAGE IUpdater @@ -114,4 +112,4 @@ public: JsonNode toJsonNode() const override; }; -VCMI_LIB_NAMESPACE_END \ No newline at end of file +VCMI_LIB_NAMESPACE_END diff --git a/lib/json/JsonBonus.cpp b/lib/json/JsonBonus.cpp index 5eb43642b..dbf023c47 100644 --- a/lib/json/JsonBonus.cpp +++ b/lib/json/JsonBonus.cpp @@ -325,11 +325,25 @@ static BonusParams convertDeprecatedBonus(const JsonNode &ability) static TUpdaterPtr parseUpdater(const JsonNode & updaterJson) { + const std::map> bonusUpdaterMap = + { + {"TIMES_HERO_LEVEL", std::make_shared}, + {"TIMES_STACK_LEVEL", std::make_shared}, + {"ARMY_MOVEMENT", std::make_shared}, + {"BONUS_OWNER_UPDATER", std::make_shared} + }; + switch(updaterJson.getType()) { case JsonNode::JsonType::DATA_STRING: - return parseByMap(bonusUpdaterMap, &updaterJson, "updater type "); - break; + { + auto it = bonusUpdaterMap.find(updaterJson.String()); + if (it != bonusUpdaterMap.end()) + return it->second(); + + logGlobal->error("Unknown bonus updater type '%s'", updaterJson.String()); + return nullptr; + } case JsonNode::JsonType::DATA_STRUCT: if(updaterJson["type"].String() == "GROWS_WITH_LEVEL") {