From b91d7418dd9163deed6defc8b36f3ee67cc04eeb Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 9 Mar 2023 13:05:47 +0300 Subject: [PATCH] vcmi: remove ONLY_ENEMY_ARMY range It should be used directly instead of alias, propagation updater also can be useful for any other updaters can be added. --- config/creatures/inferno.json | 4 +-- config/creatures/necropolis.json | 4 +-- config/schemas/bonus.json | 24 +++++++++++++++ lib/HeroBonus.cpp | 40 ++---------------------- lib/HeroBonus.h | 2 -- lib/JsonNode.cpp | 51 +++++++++++++++++-------------- lib/mapObjects/CGTownInstance.cpp | 7 ----- 7 files changed, 59 insertions(+), 73 deletions(-) diff --git a/config/creatures/inferno.json b/config/creatures/inferno.json index abfcb499c..7f39cd53e 100755 --- a/config/creatures/inferno.json +++ b/config/creatures/inferno.json @@ -369,7 +369,7 @@ "val" : -1, "stacking" : "Devils", "propagator": "BATTLE_WIDE", - "updater" : "BONUS_OWNER_UPDATER", + "propagationUpdater" : "BONUS_OWNER_UPDATER", "limiters" : [ "OPPOSITE_SIDE" ] }, "blockRetaliation" : @@ -423,7 +423,7 @@ "val" : -1, "stacking" : "Devils", "propagator": "BATTLE_WIDE", - "updater" : "BONUS_OWNER_UPDATER", + "propagationUpdater" : "BONUS_OWNER_UPDATER", "limiters" : [ "OPPOSITE_SIDE" ] }, "blockRetaliation" : diff --git a/config/creatures/necropolis.json b/config/creatures/necropolis.json index 169670587..f38abe04a 100644 --- a/config/creatures/necropolis.json +++ b/config/creatures/necropolis.json @@ -345,7 +345,7 @@ "val" : -1, "stacking" : "Undead Dragons", "propagator": "BATTLE_WIDE", - "updater" : "BONUS_OWNER_UPDATER", + "propagationUpdater" : "BONUS_OWNER_UPDATER", "limiters" : [ "OPPOSITE_SIDE" ] } }, @@ -380,7 +380,7 @@ "val" : -1, "stacking" : "Undead Dragons", "propagator": "BATTLE_WIDE", - "updater" : "BONUS_OWNER_UPDATER", + "propagationUpdater" : "BONUS_OWNER_UPDATER", "limiters" : [ "OPPOSITE_SIDE" ] }, "age" : diff --git a/config/schemas/bonus.json b/config/schemas/bonus.json index 4fd8ffe99..4e297b568 100644 --- a/config/schemas/bonus.json +++ b/config/schemas/bonus.json @@ -115,6 +115,30 @@ } ] }, + "propagationUpdater" : { + "anyOf" : [ + { + "type" : "string" + }, + { + "description" : "propagationUpdater", + "type" : "object", + "required" : ["type", "parameters"], + "additionalProperties" : false, + "properties" : { + "type" : { + "type" : "string", + "description" : "type" + }, + "parameters": { + "type" : "array", + "description" : "parameters", + "additionalItems" : true + } + } + } + ] + }, "sourceID": { "type":"number", "description": "sourceID" diff --git a/lib/HeroBonus.cpp b/lib/HeroBonus.cpp index e9023281e..39136a355 100644 --- a/lib/HeroBonus.cpp +++ b/lib/HeroBonus.cpp @@ -67,7 +67,6 @@ const std::map bonusLimitEffect = BONUS_ITEM(NO_LIMIT) BONUS_ITEM(ONLY_DISTANCE_FIGHT) BONUS_ITEM(ONLY_MELEE_FIGHT) - BONUS_ITEM(ONLY_ENEMY_ARMY) }; const std::map bonusLimiterMap = @@ -95,7 +94,8 @@ const std::map bonusUpdaterMap = { {"TIMES_HERO_LEVEL", std::make_shared()}, {"TIMES_STACK_LEVEL", std::make_shared()}, - {"ARMY_MOVEMENT", std::make_shared()} + {"ARMY_MOVEMENT", std::make_shared()}, + {"BONUS_OWNER_UPDATER", std::make_shared()} }; const std::set deprecatedBonusSet = { @@ -590,7 +590,7 @@ void BonusList::getBonuses(BonusList & out, const CSelector &selector, const CSe for (auto & b : bonuses) { //add matching bonuses that matches limit predicate or have NO_LIMIT if no given predicate - auto noFightLimit = b->effectRange == Bonus::NO_LIMIT || b->effectRange == Bonus::ONLY_ENEMY_ARMY; + auto noFightLimit = b->effectRange == Bonus::NO_LIMIT; if(selector(b.get()) && ((!limit && noFightLimit) || ((bool)limit && limit(b.get())))) out.push_back(b); } @@ -2677,40 +2677,6 @@ std::shared_ptr Bonus::addUpdater(TUpdaterPtr Updater) return this->shared_from_this(); } -// Update ONLY_ENEMY_ARMY bonuses from old saves to make them workable. -// Also, we should foreseen possible errors in bonus configuration and fix them. -void Bonus::updateOppositeBonuses() -{ - if(effectRange != Bonus::ONLY_ENEMY_ARMY) - return; - - if(propagator) - { - if(propagator->getPropagatorType() != CBonusSystemNode::BATTLE) - { - logMod->error("Wrong Propagator will be ignored: The 'ONLY_ENEMY_ARMY' effectRange is only compatible with the 'BATTLE_WIDE' propagator."); - propagator.reset(new CPropagatorNodeType(CBonusSystemNode::BATTLE)); - } - } - else - { - propagator = std::make_shared(CBonusSystemNode::BATTLE); - } - if(limiter) - { - if(!dynamic_cast(limiter.get())) - { - logMod->error("Wrong Limiter will be ignored: The 'ONLY_ENEMY_ARMY' effectRange is only compatible with the 'OPPOSITE_SIDE' limiter."); - limiter.reset(new OppositeSideLimiter()); - } - } - else - { - limiter = std::make_shared(); - } - propagationUpdater = std::make_shared(); -} - IUpdater::~IUpdater() { } diff --git a/lib/HeroBonus.h b/lib/HeroBonus.h index 4effa1ca1..0bbb76ea3 100644 --- a/lib/HeroBonus.h +++ b/lib/HeroBonus.h @@ -406,7 +406,6 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this { NO_LIMIT = 0, ONLY_DISTANCE_FIGHT=1, ONLY_MELEE_FIGHT, //used to mark bonuses for attack/defense primary skills from spells like Precision (distance only) - ONLY_ENEMY_ARMY }; enum ValueType @@ -529,7 +528,6 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this std::shared_ptr addLimiter(TLimiterPtr Limiter); //returns this for convenient chain-calls std::shared_ptr addPropagator(TPropagatorPtr Propagator); //returns this for convenient chain-calls std::shared_ptr addUpdater(TUpdaterPtr Updater); //returns this for convenient chain-calls - void updateOppositeBonuses(); }; DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const Bonus &bonus); diff --git a/lib/JsonNode.cpp b/lib/JsonNode.cpp index c10800b5b..425951ba1 100644 --- a/lib/JsonNode.cpp +++ b/lib/JsonNode.cpp @@ -847,6 +847,30 @@ static BonusParams convertDeprecatedBonus(const JsonNode &ability) return ret; } +static TUpdaterPtr parseUpdater(const JsonNode & updaterJson) +{ + switch(updaterJson.getType()) + { + case JsonNode::JsonType::DATA_STRING: + return parseByMap(bonusUpdaterMap, &updaterJson, "updater type "); + break; + case JsonNode::JsonType::DATA_STRUCT: + if(updaterJson["type"].String() == "GROWS_WITH_LEVEL") + { + std::shared_ptr updater = std::make_shared(); + const JsonVector param = updaterJson["parameters"].Vector(); + updater->valPer20 = static_cast(param[0].Integer()); + if(param.size() > 1) + updater->stepSize = static_cast(param[1].Integer()); + return updater; + } + else + logMod->warn("Unknown updater type \"%s\"", updaterJson["type"].String()); + break; + } + return nullptr; +} + bool JsonUtils::parseBonus(const JsonNode &ability, Bonus *b) { const JsonNode *value; @@ -943,29 +967,10 @@ bool JsonUtils::parseBonus(const JsonNode &ability, Bonus *b) value = &ability["updater"]; if(!value->isNull()) - { - const JsonNode & updaterJson = *value; - switch(updaterJson.getType()) - { - case JsonNode::JsonType::DATA_STRING: - b->addUpdater(parseByMap(bonusUpdaterMap, &updaterJson, "updater type ")); - break; - case JsonNode::JsonType::DATA_STRUCT: - if(updaterJson["type"].String() == "GROWS_WITH_LEVEL") - { - std::shared_ptr updater = std::make_shared(); - const JsonVector param = updaterJson["parameters"].Vector(); - updater->valPer20 = static_cast(param[0].Integer()); - if(param.size() > 1) - updater->stepSize = static_cast(param[1].Integer()); - b->addUpdater(updater); - } - else - logMod->warn("Unknown updater type \"%s\"", updaterJson["type"].String()); - break; - } - } - b->updateOppositeBonuses(); + b->addUpdater(parseUpdater(*value)); + value = &ability["propagationUpdater"]; + if(!value->isNull()) + b->propagationUpdater = parseUpdater(*value); return true; } diff --git a/lib/mapObjects/CGTownInstance.cpp b/lib/mapObjects/CGTownInstance.cpp index c2e5a3d1a..336889532 100644 --- a/lib/mapObjects/CGTownInstance.cpp +++ b/lib/mapObjects/CGTownInstance.cpp @@ -1225,13 +1225,6 @@ void CGTownInstance::recreateBuildingsBonuses() for(auto & bonus : building->buildingBonuses) { - if(bonus->limiter && bonus->effectRange == Bonus::ONLY_ENEMY_ARMY) //ONLY_ENEMY_ARMY is only mark for OppositeSide limiter to avoid extra dynamic_cast. - { - auto bCopy = std::make_shared(*bonus); //just a copy of the shared_ptr has been changed and reassigned. - bCopy->limiter = std::make_shared(this->getOwner()); - addNewBonus(bCopy); - continue; - } if(bonus->propagator != nullptr && bonus->propagator->getPropagatorType() == ALL_CREATURES) VLC->creh->addBonusForAllCreatures(bonus); else