mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Unify battleCanCastSpell parameters
This commit is contained in:
parent
ef34d21941
commit
7e85154946
@ -345,9 +345,15 @@ const IBonusBearer * CBattleInfoEssentials::getBattleNode() const
|
||||
return getBattle();
|
||||
}
|
||||
|
||||
ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastSpell(PlayerColor player, ECastingMode::ECastingMode mode) const
|
||||
ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastSpell(const ISpellCaster * caster, ECastingMode::ECastingMode mode) const
|
||||
{
|
||||
RETURN_IF_NOT_BATTLE(ESpellCastProblem::INVALID);
|
||||
if(caster == nullptr)
|
||||
{
|
||||
logGlobal->errorStream() << "CBattleInfoCallback::battleCanCastSpell: no spellcaster.";
|
||||
return ESpellCastProblem::INVALID;
|
||||
}
|
||||
const PlayerColor player = caster->getOwner();
|
||||
const ui8 side = playerToSide(player);
|
||||
if(!battleDoWeKnowAbout(side))
|
||||
{
|
||||
@ -355,16 +361,17 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastSpell(Pla
|
||||
return ESpellCastProblem::INVALID;
|
||||
}
|
||||
|
||||
if(battleTacticDist())
|
||||
return ESpellCastProblem::ONGOING_TACTIC_PHASE;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case ECastingMode::HERO_CASTING:
|
||||
{
|
||||
if(battleTacticDist())
|
||||
return ESpellCastProblem::ONGOING_TACTIC_PHASE;
|
||||
if(battleCastSpells(side) > 0)
|
||||
return ESpellCastProblem::ALREADY_CASTED_THIS_TURN;
|
||||
|
||||
auto hero = battleGetFightingHero(side);
|
||||
auto hero = dynamic_cast<const CGHeroInstance *>(caster);
|
||||
|
||||
if(!hero)
|
||||
return ESpellCastProblem::NO_HERO_TO_CAST_SPELL;
|
||||
@ -1640,7 +1647,7 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell
|
||||
if(!battleDoWeKnowAbout(side))
|
||||
return ESpellCastProblem::INVALID;
|
||||
|
||||
ESpellCastProblem::ESpellCastProblem genProblem = battleCanCastSpell(player, mode);
|
||||
ESpellCastProblem::ESpellCastProblem genProblem = battleCanCastSpell(caster, mode);
|
||||
if(genProblem != ESpellCastProblem::OK)
|
||||
return genProblem;
|
||||
|
||||
@ -2079,7 +2086,16 @@ bool CPlayerBattleCallback::battleCanCastSpell(ESpellCastProblem::ESpellCastProb
|
||||
{
|
||||
RETURN_IF_NOT_BATTLE(false);
|
||||
ASSERT_IF_CALLED_WITH_PLAYER
|
||||
auto problem = CBattleInfoCallback::battleCanCastSpell(*player, ECastingMode::HERO_CASTING);
|
||||
|
||||
const CGHeroInstance * hero = battleGetMyHero();
|
||||
if(!hero)
|
||||
{
|
||||
if(outProblem)
|
||||
*outProblem = ESpellCastProblem::NO_HERO_TO_CAST_SPELL;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto problem = CBattleInfoCallback::battleCanCastSpell(hero, ECastingMode::HERO_CASTING);
|
||||
if(outProblem)
|
||||
*outProblem = problem;
|
||||
|
||||
|
@ -212,7 +212,6 @@ public:
|
||||
TStacks battleAliveStacks(ui8 side) const;
|
||||
const CStack * battleGetStackByID(int ID, bool onlyAlive = true) const; //returns stack info by given ID
|
||||
bool battleIsObstacleVisibleForSide(const CObstacleInstance & coi, BattlePerspective::BattlePerspective side) const;
|
||||
//ESpellCastProblem::ESpellCastProblem battleCanCastSpell(int player, ECastingMode::ECastingMode mode) const; //Checks if player is able to cast spells (at all) at the moment
|
||||
};
|
||||
|
||||
struct DLL_LINKAGE BattleAttackInfo
|
||||
@ -282,7 +281,7 @@ public:
|
||||
//*** MAGIC
|
||||
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 battleCanCastSpell(const ISpellCaster * caster, ECastingMode::ECastingMode mode) const; //returns true if there are no general issues preventing from casting a spell
|
||||
ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(const ISpellCaster * caster, const CSpell * spell, ECastingMode::ECastingMode mode) const; //checks if given player can cast given spell
|
||||
ESpellCastProblem::ESpellCastProblem battleCanCastThisSpellHere(const ISpellCaster * caster, const CSpell * spell, ECastingMode::ECastingMode mode, BattleHex dest) const; //checks if given player can cast given spell at given tile in given mode
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user