diff --git a/lib/CBattleCallback.cpp b/lib/CBattleCallback.cpp index 23b566ce6..8e4180b0c 100644 --- a/lib/CBattleCallback.cpp +++ b/lib/CBattleCallback.cpp @@ -494,6 +494,15 @@ const CGHeroInstance * CBattleInfoEssentials::battleGetOwnerHero(const CStack * return getBattle()->sides.at(playerToSide(battleGetOwner(stack))).hero; } +bool CBattleInfoEssentials::battleMatchOwner(const CStack * attacker, const CStack * defender, const boost::logic::tribool positivness /* = false*/) const +{ + RETURN_IF_NOT_BATTLE(false); + if(boost::logic::indeterminate(positivness)) + return true; + else + return (battleGetOwner(attacker) == battleGetOwner(defender)) == positivness; +} + si8 CBattleInfoCallback::battleHasWallPenalty( const CStack * stack, BattleHex destHex ) const { return battleHasWallPenalty(stack, stack->position, destHex); diff --git a/lib/CBattleCallback.h b/lib/CBattleCallback.h index 6f633c327..ba0a4eabb 100644 --- a/lib/CBattleCallback.h +++ b/lib/CBattleCallback.h @@ -214,8 +214,15 @@ public: const CStack * battleGetStackByID(int ID, bool onlyAlive = true) const; //returns stack info by given ID bool battleIsObstacleVisibleForSide(const CObstacleInstance & coi, BattlePerspective::BattlePerspective side) const; - PlayerColor battleGetOwner(const CStack * stack) const; //returns player that controls given stack; mind control included - const CGHeroInstance * battleGetOwnerHero(const CStack * stack) const; //returns hero that controls given stack; nullptr if none; mind control included + ///returns player that controls given stack; mind control included + PlayerColor battleGetOwner(const CStack * stack) const; + + ///returns hero that controls given stack; nullptr if none; mind control included + const CGHeroInstance * battleGetOwnerHero(const CStack * stack) const; + + ///check that stacks are controlled by same|other player(s) depending on positiveness + ///mind control included + bool battleMatchOwner(const CStack * attacker, const CStack * defender, const boost::logic::tribool positivness = false) const; }; struct DLL_LINKAGE BattleAttackInfo diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 2ddc73de2..4f8b8be80 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -4556,7 +4556,7 @@ void CGameHandler::stackTurnTrigger(const CStack * st) bool fearsomeCreature = false; for(CStack * stack : gs->curB->stacks) { - if (stack->owner != st->owner && stack->alive() && stack->hasBonusOfType(Bonus::FEAR)) + if(battleMatchOwner(st, stack) && stack->alive() && stack->hasBonusOfType(Bonus::FEAR)) { fearsomeCreature = true; break; @@ -4614,7 +4614,7 @@ void CGameHandler::stackTurnTrigger(const CStack * st) { for (auto s : gs->curB->battleGetAllStacks()) { - if (st->owner == s->owner && s->isValidTarget()) //all allied + if(battleMatchOwner(st, s, true) && s->isValidTarget()) //all allied sse.stacks.push_back (s->ID); } }