Browse Source

Fixed http://bugs.vcmi.eu/view.php?id=2268

AlexVinS 9 years ago
parent
commit
72461c5c2e
4 changed files with 20 additions and 4 deletions
  1. 4 3
      lib/CBattleCallback.cpp
  2. 13 0
      lib/spells/CSpellHandler.cpp
  3. 2 0
      lib/spells/CSpellHandler.h
  4. 1 1
      server/CGameHandler.cpp

+ 4 - 3
lib/CBattleCallback.cpp

@@ -478,7 +478,6 @@ EGateState CBattleInfoEssentials::battleGetGateState() const
 	return getBattle()->si.gateState;
 }
 
-
 PlayerColor CBattleInfoEssentials::battleGetOwner(const CStack * stack) const
 {
 	RETURN_IF_NOT_BATTLE(PlayerColor::CANNOT_DETERMINE);
@@ -499,6 +498,8 @@ bool CBattleInfoEssentials::battleMatchOwner(const CStack * attacker, const CSta
 	RETURN_IF_NOT_BATTLE(false);
 	if(boost::logic::indeterminate(positivness))
 		return true;
+	else if(defender->owner != battleGetOwner(defender))
+		return true;//mind controlled unit is attackable for both sides
 	else
 		return (battleGetOwner(attacker) == battleGetOwner(defender)) == positivness;
 }
@@ -856,7 +857,7 @@ bool CBattleInfoCallback::battleCanAttack(const CStack * stack, const CStack * t
 	if (!stack || !target)
 		return false;
 
-	if (stack->owner == target->owner)
+	if(!battleMatchOwner(stack, target))
 		return false;
 
 	auto &id = stack->getCreature()->idNumber;
@@ -888,7 +889,7 @@ bool CBattleInfoCallback::battleCanShoot(const CStack * stack, BattleHex dest) c
 		return false;
 
 	if(stack->hasBonusOfType(Bonus::SHOOTER)//it's shooter
-		&& stack->owner != dst->owner
+		&& battleMatchOwner(stack, dst)
 		&& dst->alive()
 		&& (!battleIsStackBlocked(stack)  ||  stack->hasBonusOfType(Bonus::FREE_SHOOTING))
 		&& stack->shots

+ 13 - 0
lib/spells/CSpellHandler.cpp

@@ -267,6 +267,19 @@ bool CSpell::isNeutral() const
 	return positiveness == NEUTRAL;
 }
 
+boost::logic::tribool CSpell::getPositiveness() const
+{
+	switch (positiveness)
+	{
+	case CSpell::POSITIVE:
+		return true;
+	case CSpell::NEGATIVE:
+		return false;
+	default:
+		return boost::logic::indeterminate;
+	}
+}
+
 bool CSpell::isRisingSpell() const
 {
 	return isRising;

+ 2 - 0
lib/spells/CSpellHandler.h

@@ -204,6 +204,8 @@ public:
 	bool isNegative() const;
 	bool isNeutral() const;
 
+	boost::logic::tribool getPositiveness() const;
+
 	bool isDamageSpell() const;
 	bool isRisingSpell() const;
 	bool isOffensiveSpell() const;

+ 1 - 1
server/CGameHandler.cpp

@@ -5726,7 +5726,7 @@ void CGameHandler::runBattle()
 				continue;
 			}
 
-			const CGHeroInstance * curOwner = gs->curB->battleGetOwnerHero(next);
+			const CGHeroInstance * curOwner = battleGetOwnerHero(next);
 
 			if( (next->position < 0 || next->getCreature()->idNumber == CreatureID::BALLISTA)	//arrow turret or ballista
 				&& (!curOwner || curOwner->getSecSkillLevel(SecondarySkill::ARTILLERY) == 0)) //hero has no artillery