diff --git a/client/battle/BattleInterfaceClasses.cpp b/client/battle/BattleInterfaceClasses.cpp index 5bf689fda..6d09150d0 100644 --- a/client/battle/BattleInterfaceClasses.cpp +++ b/client/battle/BattleInterfaceClasses.cpp @@ -530,7 +530,7 @@ void StackInfoBasicPanel::initializeData(const CStack * stack) if (hasGraphics) { //FIXME: support permanent duration - int duration = stack->getBonusLocalFirst(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(effect)))->turnsRemain; + int duration = stack->getFirstBonus(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(effect)))->turnsRemain; icons.push_back(std::make_shared(AnimationPath::builtin("SpellInt"), effect + 1, 0, firstPos.x + offset.x * printed, firstPos.y + offset.y * printed)); if(settings["general"]["enableUiEnhancements"].Bool()) diff --git a/client/battle/BattleWindow.cpp b/client/battle/BattleWindow.cpp index 991f79251..85d2618d8 100644 --- a/client/battle/BattleWindow.cpp +++ b/client/battle/BattleWindow.cpp @@ -601,7 +601,7 @@ void BattleWindow::bSpellf() { //TODO: move to spell mechanics, add more information to spell cast problem //Handle Orb of Inhibition-like effects -> we want to display dialog with info, why casting is impossible - auto blockingBonus = owner.currentHero()->getBonusLocalFirst(Selector::type()(BonusType::BLOCK_ALL_MAGIC)); + auto blockingBonus = owner.currentHero()->getFirstBonus(Selector::type()(BonusType::BLOCK_ALL_MAGIC)); if (!blockingBonus) return; diff --git a/client/windows/CCreatureWindow.cpp b/client/windows/CCreatureWindow.cpp index d59c25da3..449c005bd 100644 --- a/client/windows/CCreatureWindow.cpp +++ b/client/windows/CCreatureWindow.cpp @@ -225,7 +225,7 @@ CStackWindow::ActiveSpellsSection::ActiveSpellsSection(CStackWindow * owner, int spellText = CGI->generaltexth->allTexts[610]; //"%s, duration: %d rounds." boost::replace_first(spellText, "%s", spell->getNameTranslated()); //FIXME: support permanent duration - int duration = battleStack->getBonusLocalFirst(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(effect)))->turnsRemain; + int duration = battleStack->getFirstBonus(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(effect)))->turnsRemain; boost::replace_first(spellText, "%d", std::to_string(duration)); spellIcons.push_back(std::make_shared(AnimationPath::builtin("SpellInt"), effect + 1, 0, firstPos.x + offset.x * printed, firstPos.y + offset.y * printed)); diff --git a/lib/CArtifactInstance.cpp b/lib/CArtifactInstance.cpp index a3efb5dfd..0451e2d2f 100644 --- a/lib/CArtifactInstance.cpp +++ b/lib/CArtifactInstance.cpp @@ -62,7 +62,7 @@ void CCombinedArtifactInstance::addPlacementMap(CArtifactSet::ArtPlacementMap & SpellID CScrollArtifactInstance::getScrollSpellID() const { auto artInst = static_cast(this); - const auto bonus = artInst->getBonusLocalFirst(Selector::type()(BonusType::SPELL)); + const auto bonus = artInst->getFirstBonus(Selector::type()(BonusType::SPELL)); if(!bonus) return SpellID::NONE; return bonus->subtype.as(); diff --git a/lib/bonuses/CBonusSystemNode.cpp b/lib/bonuses/CBonusSystemNode.cpp index e8760f9c0..f8f45cbbd 100644 --- a/lib/bonuses/CBonusSystemNode.cpp +++ b/lib/bonuses/CBonusSystemNode.cpp @@ -20,7 +20,7 @@ VCMI_LIB_NAMESPACE_BEGIN std::atomic CBonusSystemNode::treeChanged(1); constexpr bool CBonusSystemNode::cachingEnabled = true; -std::shared_ptr CBonusSystemNode::getBonusLocalFirst(const CSelector & selector) +std::shared_ptr CBonusSystemNode::getLocalBonus(const CSelector & selector) { auto ret = bonuses.getFirst(selector); if(ret) @@ -28,7 +28,7 @@ std::shared_ptr CBonusSystemNode::getBonusLocalFirst(const CSelector & se return nullptr; } -std::shared_ptr CBonusSystemNode::getBonusLocalFirst(const CSelector & selector) const +std::shared_ptr CBonusSystemNode::getFirstBonus(const CSelector & selector) const { auto ret = bonuses.getFirst(selector); if(ret) @@ -38,7 +38,7 @@ std::shared_ptr CBonusSystemNode::getBonusLocalFirst(const CSelecto getParents(lparents); for(const CBonusSystemNode *pname : lparents) { - ret = pname->getBonusLocalFirst(selector); + ret = pname->getFirstBonus(selector); if (ret) return ret; } diff --git a/lib/bonuses/CBonusSystemNode.h b/lib/bonuses/CBonusSystemNode.h index f8a529d65..dd00b66ce 100644 --- a/lib/bonuses/CBonusSystemNode.h +++ b/lib/bonuses/CBonusSystemNode.h @@ -88,10 +88,12 @@ public: TBonusListPtr limitBonuses(const BonusList &allBonuses) const; //same as above, returns out by val for convienence TConstBonusListPtr getAllBonuses(const CSelector &selector, const CSelector &limit, const CBonusSystemNode *root = nullptr, const std::string &cachingStr = "") const override; void getParents(TCNodes &out) const; //retrieves list of parent nodes (nodes to inherit bonuses from), - std::shared_ptr getBonusLocalFirst(const CSelector & selector) const; - //non-const interface - std::shared_ptr getBonusLocalFirst(const CSelector & selector); + /// Returns first bonus matching selector + std::shared_ptr getFirstBonus(const CSelector & selector) const; + + /// Provides write access to first bonus from this node that matches selector + std::shared_ptr getLocalBonus(const CSelector & selector); void attachTo(CBonusSystemNode & parent); void attachToSource(const CBonusSystemNode & parent); diff --git a/lib/gameState/CGameStateCampaign.cpp b/lib/gameState/CGameStateCampaign.cpp index ae6a5680f..8887c8212 100644 --- a/lib/gameState/CGameStateCampaign.cpp +++ b/lib/gameState/CGameStateCampaign.cpp @@ -91,7 +91,7 @@ void CGameStateCampaign::trimCrossoverHeroesParameters(std::vectorgetBonusLocalFirst(sel)->val = cgh->type->heroClass->primarySkillInitial[g.getNum()]; + cgh->getLocalBonus(sel)->val = cgh->type->heroClass->primarySkillInitial[g.getNum()]; } } } diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index 11b945659..dd4e8c974 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -1412,7 +1412,7 @@ void CGHeroInstance::setPrimarySkill(PrimarySkill primarySkill, si64 value, ui8 { if(primarySkill < PrimarySkill::EXPERIENCE) { - auto skill = getBonusLocalFirst(Selector::type()(BonusType::PRIMARY_SKILL) + auto skill = getLocalBonus(Selector::type()(BonusType::PRIMARY_SKILL) .And(Selector::subtype()(BonusSubtypeID(primarySkill))) .And(Selector::sourceType()(BonusSource::HERO_BASE_SKILL))); assert(skill); diff --git a/lib/mapObjects/MiscObjects.cpp b/lib/mapObjects/MiscObjects.cpp index 778e5eb52..f83fbe362 100644 --- a/lib/mapObjects/MiscObjects.cpp +++ b/lib/mapObjects/MiscObjects.cpp @@ -929,7 +929,7 @@ void CGArtifact::serializeJsonOptions(JsonSerializeFormat& handler) if(handler.saving && ID == Obj::SPELL_SCROLL) { - const std::shared_ptr b = storedArtifact->getBonusLocalFirst(Selector::type()(BonusType::SPELL)); + const auto & b = storedArtifact->getFirstBonus(Selector::type()(BonusType::SPELL)); SpellID spellId(b->subtype.as()); handler.serializeId("spell", spellId, SpellID::NONE); diff --git a/lib/networkPacks/NetPacksLib.cpp b/lib/networkPacks/NetPacksLib.cpp index b998c416a..bbe706877 100644 --- a/lib/networkPacks/NetPacksLib.cpp +++ b/lib/networkPacks/NetPacksLib.cpp @@ -2147,7 +2147,7 @@ void BattleTriggerEffect::applyGs(CGameState * gs) const } case BonusType::POISON: { - auto b = st->getBonusLocalFirst(Selector::source(BonusSource::SPELL_EFFECT, SpellID(SpellID::POISON)) + auto b = st->getLocalBonus(Selector::source(BonusSource::SPELL_EFFECT, SpellID(SpellID::POISON)) .And(Selector::type()(BonusType::STACK_HEALTH))); if (b) b->val = val; diff --git a/lib/spells/ISpellMechanics.cpp b/lib/spells/ISpellMechanics.cpp index 6d95d6bf1..6e260347f 100644 --- a/lib/spells/ISpellMechanics.cpp +++ b/lib/spells/ISpellMechanics.cpp @@ -475,7 +475,7 @@ bool BaseMechanics::adaptProblem(ESpellCastProblem source, Problem & target) con return adaptGenericProblem(target); //Recanter's Cloak or similar effect. Try to retrieve bonus - const auto b = hero->getBonusLocalFirst(Selector::type()(BonusType::BLOCK_MAGIC_ABOVE)); + const auto b = hero->getFirstBonus(Selector::type()(BonusType::BLOCK_MAGIC_ABOVE)); //TODO what about other values and non-artifact sources? if(b && b->val == 2 && b->source == BonusSource::ARTIFACT) { diff --git a/lib/spells/effects/Timed.cpp b/lib/spells/effects/Timed.cpp index 3bedc80ac..956fcf884 100644 --- a/lib/spells/effects/Timed.cpp +++ b/lib/spells/effects/Timed.cpp @@ -112,9 +112,9 @@ void Timed::apply(ServerCallback * server, const Mechanics * m, const EffectTarg const auto *casterHero = dynamic_cast(m->caster); if(casterHero) { - peculiarBonus = casterHero->getBonusLocalFirst(Selector::typeSubtype(BonusType::SPECIAL_PECULIAR_ENCHANT, BonusSubtypeID(m->getSpellId()))); - addedValueBonus = casterHero->getBonusLocalFirst(Selector::typeSubtype(BonusType::SPECIAL_ADD_VALUE_ENCHANT, BonusSubtypeID(m->getSpellId()))); - fixedValueBonus = casterHero->getBonusLocalFirst(Selector::typeSubtype(BonusType::SPECIAL_FIXED_VALUE_ENCHANT, BonusSubtypeID(m->getSpellId()))); + peculiarBonus = casterHero->getFirstBonus(Selector::typeSubtype(BonusType::SPECIAL_PECULIAR_ENCHANT, BonusSubtypeID(m->getSpellId()))); + addedValueBonus = casterHero->getFirstBonus(Selector::typeSubtype(BonusType::SPECIAL_ADD_VALUE_ENCHANT, BonusSubtypeID(m->getSpellId()))); + fixedValueBonus = casterHero->getFirstBonus(Selector::typeSubtype(BonusType::SPECIAL_FIXED_VALUE_ENCHANT, BonusSubtypeID(m->getSpellId()))); } //TODO: does hero specialty should affects his stack casting spells? diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 060ffcd80..dce051289 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -886,7 +886,7 @@ void CGameHandler::onNewTurn() { if (getPlayerStatus(player.first) == EPlayerStatus::INGAME && getPlayerRelations(player.first, t->tempOwner) == PlayerRelations::ENEMIES) - changeFogOfWar(t->visitablePos(), t->getBonusLocalFirst(Selector::type()(BonusType::DARKNESS))->val, player.first, ETileVisibility::HIDDEN); + changeFogOfWar(t->visitablePos(), t->getFirstBonus(Selector::type()(BonusType::DARKNESS))->val, player.first, ETileVisibility::HIDDEN); } } } diff --git a/server/battles/BattleActionProcessor.cpp b/server/battles/BattleActionProcessor.cpp index af8e88994..520fcdd02 100644 --- a/server/battles/BattleActionProcessor.cpp +++ b/server/battles/BattleActionProcessor.cpp @@ -404,7 +404,7 @@ bool BattleActionProcessor::doCatapultAction(const CBattleInfoCallback & battle, if (!canStackAct(battle, stack)) return false; - std::shared_ptr catapultAbility = stack->getBonusLocalFirst(Selector::type()(BonusType::CATAPULT)); + std::shared_ptr catapultAbility = stack->getFirstBonus(Selector::type()(BonusType::CATAPULT)); if(!catapultAbility || catapultAbility->subtype == BonusSubtypeID()) { gameHandler->complain("We do not know how to shoot :P"); @@ -492,7 +492,7 @@ bool BattleActionProcessor::doHealAction(const CBattleInfoCallback & battle, con } const battle::Unit * destStack = nullptr; - std::shared_ptr healerAbility = stack->getBonusLocalFirst(Selector::type()(BonusType::HEALER)); + std::shared_ptr healerAbility = stack->getFirstBonus(Selector::type()(BonusType::HEALER)); if(target.at(0).unitValue) destStack = target.at(0).unitValue; @@ -975,7 +975,7 @@ void BattleActionProcessor::makeAttack(const CBattleInfoCallback & battle, const drainedLife += applyBattleEffects(battle, bat, attackerState, fireShield, stack, distance, true); } - std::shared_ptr bonus = attacker->getBonusLocalFirst(Selector::type()(BonusType::SPELL_LIKE_ATTACK)); + std::shared_ptr bonus = attacker->getFirstBonus(Selector::type()(BonusType::SPELL_LIKE_ATTACK)); if(bonus && ranged) //TODO: make it work in melee? { //this is need for displaying hit animation diff --git a/server/battles/BattleFlowProcessor.cpp b/server/battles/BattleFlowProcessor.cpp index 975f281df..a27be3606 100644 --- a/server/battles/BattleFlowProcessor.cpp +++ b/server/battles/BattleFlowProcessor.cpp @@ -664,7 +664,7 @@ void BattleFlowProcessor::stackTurnTrigger(const CBattleInfoCallback & battle, c if (st->hasBonusOfType(BonusType::POISON)) { - std::shared_ptr b = st->getBonusLocalFirst(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(SpellID(SpellID::POISON))).And(Selector::type()(BonusType::STACK_HEALTH))); + std::shared_ptr b = st->getFirstBonus(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(SpellID(SpellID::POISON))).And(Selector::type()(BonusType::STACK_HEALTH))); if (b) //TODO: what if not?... { bte.val = std::max (b->val - 10, -(st->valOfBonuses(BonusType::POISON)));