소스 검색

More correct usage of battleGetFightingHero
* this should fix "FIXME: battleGetFightingHero wrong argument!"

AlexVinS 10 년 전
부모
커밋
6010bbe7ba
3개의 변경된 파일19개의 추가작업 그리고 11개의 파일을 삭제
  1. 12 5
      lib/CBattleCallback.cpp
  2. 2 1
      lib/CBattleCallback.h
  3. 5 5
      server/CGameHandler.cpp

+ 12 - 5
lib/CBattleCallback.cpp

@@ -335,6 +335,11 @@ int CBattleInfoEssentials::battleCastSpells(ui8 side) const
 	return getBattle()->sides[side].castSpellsCount;
 	return getBattle()->sides[side].castSpellsCount;
 }
 }
 
 
+const IBonusBearer * CBattleInfoEssentials::getBattleNode() const
+{
+	return getBattle();
+}
+
 ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastSpell(PlayerColor player, ECastingMode::ECastingMode mode) const
 ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastSpell(PlayerColor player, ECastingMode::ECastingMode mode) const
 {
 {
 	RETURN_IF_NOT_BATTLE(ESpellCastProblem::INVALID);
 	RETURN_IF_NOT_BATTLE(ESpellCastProblem::INVALID);
@@ -1645,7 +1650,7 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell
 			return ESpellCastProblem::NO_APPROPRIATE_TARGET;
 			return ESpellCastProblem::NO_APPROPRIATE_TARGET;
 	}
 	}
 
 
-	if(battleMaxSpellLevel() < spell->level) //effect like Recanter's Cloak or Orb of Inhibition
+	if(battleMaxSpellLevel(side) < spell->level) //effect like Recanter's Cloak or Orb of Inhibition
 		return ESpellCastProblem::SPELL_LEVEL_LIMIT_EXCEEDED;
 		return ESpellCastProblem::SPELL_LEVEL_LIMIT_EXCEEDED;
 
 
 	//checking if there exists an appropriate target
 	//checking if there exists an appropriate target
@@ -2060,12 +2065,14 @@ int CBattleInfoCallback::battleGetSurrenderCost(PlayerColor Player) const
 	return ret;
 	return ret;
 }
 }
 
 
-si8 CBattleInfoCallback::battleMaxSpellLevel() const
+si8 CBattleInfoCallback::battleMaxSpellLevel(ui8 side) const
 {
 {
-	const CBonusSystemNode *node = nullptr;
-	if(const CGHeroInstance *h =  battleGetFightingHero(battleGetMySide()))
+	const IBonusBearer *node = nullptr;
+	if(const CGHeroInstance * h = battleGetFightingHero(side))
 		node = h;
 		node = h;
-	//TODO else use battle node
+	else
+		node = getBattleNode();
+
 	if(!node)
 	if(!node)
 		return GameConstants::SPELL_LEVELS;
 		return GameConstants::SPELL_LEVELS;
 
 

+ 2 - 1
lib/CBattleCallback.h

@@ -158,6 +158,7 @@ class DLL_LINKAGE CBattleInfoEssentials : public virtual CCallbackBase
 {
 {
 protected:
 protected:
 	bool battleDoWeKnowAbout(ui8 side) const;
 	bool battleDoWeKnowAbout(ui8 side) const;
+	const IBonusBearer * getBattleNode() const;
 public:
 public:
 	enum EStackOwnership
 	enum EStackOwnership
 	{
 	{
@@ -276,7 +277,7 @@ public:
 	std::vector<BattleHex> getAttackableBattleHexes() const;
 	std::vector<BattleHex> getAttackableBattleHexes() const;
 
 
 	//*** MAGIC 
 	//*** MAGIC 
-	si8 battleMaxSpellLevel() const; //calculates minimum spell level possible to be cast on battlefield - takes into account artifacts of both heroes; if no effects are set, 0 is returned
+	si8 battleMaxSpellLevel(ui8 side) const; //calculates minimum spell level possible to be cast on battlefield - takes into account artifacts of both heroes; if no effects are set, 0 is returned
 	ui32 battleGetSpellCost(const CSpell * sp, const CGHeroInstance * caster) const; //returns cost of given spell
 	ui32 battleGetSpellCost(const CSpell * sp, const CGHeroInstance * caster) const; //returns cost of given spell
 	ESpellCastProblem::ESpellCastProblem battleCanCastSpell(PlayerColor player, ECastingMode::ECastingMode mode) const; //returns true if there are no general issues preventing from casting a spell
 	ESpellCastProblem::ESpellCastProblem battleCanCastSpell(PlayerColor player, ECastingMode::ECastingMode mode) const; //returns true if there are no general issues preventing from casting a spell
 	ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(PlayerColor player, const CSpell * spell, ECastingMode::ECastingMode mode) const; //checks if given player can cast given spell
 	ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(PlayerColor player, const CSpell * spell, ECastingMode::ECastingMode mode) const; //checks if given player can cast given spell

+ 5 - 5
server/CGameHandler.cpp

@@ -4183,17 +4183,17 @@ void CGameHandler::stackTurnTrigger(const CStack * st)
 		}
 		}
 		if (st->hasBonusOfType(Bonus::MANA_DRAIN) && !vstd::contains(st->state, EBattleStackState::DRAINED_MANA))
 		if (st->hasBonusOfType(Bonus::MANA_DRAIN) && !vstd::contains(st->state, EBattleStackState::DRAINED_MANA))
 		{
 		{
-			const CGHeroInstance * enemy = gs->curB->getHero(gs->curB->theOtherPlayer(st->owner));
-			//const CGHeroInstance * owner = gs->curB->getHero(st->owner);
-			if (enemy)
+			const PlayerColor opponent = gs->curB->theOtherPlayer(st->owner);
+			const CGHeroInstance * opponentHero = gs->curB->getHero(opponent);
+			if (opponentHero)
 			{
 			{
 				ui32 manaDrained = st->valOfBonuses(Bonus::MANA_DRAIN);
 				ui32 manaDrained = st->valOfBonuses(Bonus::MANA_DRAIN);
-				vstd::amin(manaDrained, gs->curB->battleGetFightingHero(0)->mana);
+				vstd::amin(manaDrained, opponentHero->mana);
 				if (manaDrained)
 				if (manaDrained)
 				{
 				{
 					bte.effect = Bonus::MANA_DRAIN;
 					bte.effect = Bonus::MANA_DRAIN;
 					bte.val = manaDrained;
 					bte.val = manaDrained;
-					bte.additionalInfo = enemy->id.getNum(); //for sanity
+					bte.additionalInfo = opponentHero->id.getNum(); //for sanity
 					sendAndApply(&bte);
 					sendAndApply(&bte);
 				}
 				}
 			}
 			}