Browse Source

Handle HYPNOTIZE effect in case of FEAR and ENCHANTED effects

AlexVinS 9 năm trước cách đây
mục cha
commit
9097ffbd8a

+ 9 - 0
lib/CBattleCallback.cpp

@@ -494,6 +494,15 @@ const CGHeroInstance * CBattleInfoEssentials::battleGetOwnerHero(const CStack *
 	return getBattle()->sides.at(playerToSide(battleGetOwner(stack))).hero;
 	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
 si8 CBattleInfoCallback::battleHasWallPenalty( const CStack * stack, BattleHex destHex ) const
 {
 {
 	return battleHasWallPenalty(stack, stack->position, destHex);
 	return battleHasWallPenalty(stack, stack->position, destHex);

+ 9 - 2
lib/CBattleCallback.h

@@ -214,8 +214,15 @@ public:
 	const CStack * battleGetStackByID(int ID, bool onlyAlive = true) const; //returns stack info by given ID
 	const CStack * battleGetStackByID(int ID, bool onlyAlive = true) const; //returns stack info by given ID
 	bool battleIsObstacleVisibleForSide(const CObstacleInstance & coi, BattlePerspective::BattlePerspective side) const;
 	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
 struct DLL_LINKAGE BattleAttackInfo

+ 2 - 2
server/CGameHandler.cpp

@@ -4556,7 +4556,7 @@ void CGameHandler::stackTurnTrigger(const CStack * st)
 			bool fearsomeCreature = false;
 			bool fearsomeCreature = false;
 			for(CStack * stack : gs->curB->stacks)
 			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;
 					fearsomeCreature = true;
 					break;
 					break;
@@ -4614,7 +4614,7 @@ void CGameHandler::stackTurnTrigger(const CStack * st)
 			{
 			{
 				for (auto s : gs->curB->battleGetAllStacks())
 				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);
 						sse.stacks.push_back (s->ID);
 				}
 				}
 			}
 			}