mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
More correct usage of battleGetFightingHero
* this should fix "FIXME: battleGetFightingHero wrong argument!"
This commit is contained in:
parent
92990c887c
commit
6010bbe7ba
@ -335,6 +335,11 @@ int CBattleInfoEssentials::battleCastSpells(ui8 side) const
|
||||
return getBattle()->sides[side].castSpellsCount;
|
||||
}
|
||||
|
||||
const IBonusBearer * CBattleInfoEssentials::getBattleNode() const
|
||||
{
|
||||
return getBattle();
|
||||
}
|
||||
|
||||
ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastSpell(PlayerColor player, ECastingMode::ECastingMode mode) const
|
||||
{
|
||||
RETURN_IF_NOT_BATTLE(ESpellCastProblem::INVALID);
|
||||
@ -1645,7 +1650,7 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell
|
||||
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;
|
||||
|
||||
//checking if there exists an appropriate target
|
||||
@ -2060,12 +2065,14 @@ int CBattleInfoCallback::battleGetSurrenderCost(PlayerColor Player) const
|
||||
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;
|
||||
//TODO else use battle node
|
||||
else
|
||||
node = getBattleNode();
|
||||
|
||||
if(!node)
|
||||
return GameConstants::SPELL_LEVELS;
|
||||
|
||||
|
@ -158,6 +158,7 @@ class DLL_LINKAGE CBattleInfoEssentials : public virtual CCallbackBase
|
||||
{
|
||||
protected:
|
||||
bool battleDoWeKnowAbout(ui8 side) const;
|
||||
const IBonusBearer * getBattleNode() const;
|
||||
public:
|
||||
enum EStackOwnership
|
||||
{
|
||||
@ -276,7 +277,7 @@ public:
|
||||
std::vector<BattleHex> getAttackableBattleHexes() const;
|
||||
|
||||
//*** 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
|
||||
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
|
||||
|
@ -4183,17 +4183,17 @@ void CGameHandler::stackTurnTrigger(const CStack * st)
|
||||
}
|
||||
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);
|
||||
vstd::amin(manaDrained, gs->curB->battleGetFightingHero(0)->mana);
|
||||
vstd::amin(manaDrained, opponentHero->mana);
|
||||
if (manaDrained)
|
||||
{
|
||||
bte.effect = Bonus::MANA_DRAIN;
|
||||
bte.val = manaDrained;
|
||||
bte.additionalInfo = enemy->id.getNum(); //for sanity
|
||||
bte.additionalInfo = opponentHero->id.getNum(); //for sanity
|
||||
sendAndApply(&bte);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user