1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

get rid of CPlayerBattleCallback::battleCanCastSpell

This commit is contained in:
AlexVinS
2017-06-05 22:16:12 +03:00
parent 1d1519db5c
commit 4d430f6ad8
6 changed files with 23 additions and 33 deletions

View File

@ -186,7 +186,7 @@ void CBattleAI::attemptCastingSpell()
if(!hero) if(!hero)
return; return;
if(!cb->battleCanCastSpell()) if(cb->battleCanCastSpell(hero, ECastingMode::HERO_CASTING) != ESpellCastProblem::OK)
return; return;
LOGL("Casting spells sounds like fun. Let's see..."); LOGL("Casting spells sounds like fun. Let's see...");

View File

@ -871,19 +871,24 @@ void CBattleInterface::bSpellf()
if (spellDestSelectMode) //we are casting a spell if (spellDestSelectMode) //we are casting a spell
return; return;
CCS->curh->changeGraphic(ECursor::ADVENTURE,0);
if (!myTurn) if (!myTurn)
return; return;
auto myHero = currentHero(); auto myHero = currentHero();
ESpellCastProblem::ESpellCastProblem spellCastProblem; if(!myHero)
if (curInt->cb->battleCanCastSpell(&spellCastProblem)) return;
CCS->curh->changeGraphic(ECursor::ADVENTURE,0);
ESpellCastProblem::ESpellCastProblem spellCastProblem = curInt->cb->battleCanCastSpell(myHero, ECastingMode::HERO_CASTING);
if(spellCastProblem == ESpellCastProblem::OK)
{ {
GH.pushInt(new CSpellWindow(myHero, curInt.get())); GH.pushInt(new CSpellWindow(myHero, curInt.get()));
} }
else if (spellCastProblem == ESpellCastProblem::MAGIC_IS_BLOCKED) else if (spellCastProblem == ESpellCastProblem::MAGIC_IS_BLOCKED)
{ {
//TODO: move to spell mechanics, add more information to spell cast problem
//Handle Orb of Inhibition-like effects -> we want to display dialog with info, why casting is impossible //Handle Orb of Inhibition-like effects -> we want to display dialog with info, why casting is impossible
auto blockingBonus = currentHero()->getBonusLocalFirst(Selector::type(Bonus::BLOCK_ALL_MAGIC)); auto blockingBonus = currentHero()->getBonusLocalFirst(Selector::type(Bonus::BLOCK_ALL_MAGIC));
if (!blockingBonus) if (!blockingBonus)
@ -1849,11 +1854,17 @@ void CBattleInterface::showQueue()
void CBattleInterface::blockUI(bool on) void CBattleInterface::blockUI(bool on)
{ {
ESpellCastProblem::ESpellCastProblem spellcastingProblem; bool canCastSpells = false;
bool canCastSpells = curInt->cb->battleCanCastSpell(&spellcastingProblem); auto hero = curInt->cb->battleGetMyHero();
//if magic is blocked, we leave button active, so the message can be displayed (cf bug #97)
if (!canCastSpells) if(hero)
canCastSpells = spellcastingProblem == ESpellCastProblem::MAGIC_IS_BLOCKED; {
ESpellCastProblem::ESpellCastProblem spellcastingProblem = curInt->cb->battleCanCastSpell(hero, ECastingMode::HERO_CASTING);
//if magic is blocked, we leave button active, so the message can be displayed after button click
canCastSpells = spellcastingProblem == ESpellCastProblem::OK || spellcastingProblem == ESpellCastProblem::MAGIC_IS_BLOCKED;
}
bool canWait = activeStack ? !activeStack->waited() : false; bool canWait = activeStack ? !activeStack->waited() : false;
bOptions->block(on); bOptions->block(on);

View File

@ -191,7 +191,7 @@ void CBattleHero::clickLeft(tribool down, bool previousState)
if(myOwner->spellDestSelectMode) //we are casting a spell if(myOwner->spellDestSelectMode) //we are casting a spell
return; return;
if(myHero != nullptr && !down && myOwner->myTurn && myOwner->getCurrentPlayerInterface()->cb->battleCanCastSpell()) //check conditions if(myHero != nullptr && !down && myOwner->myTurn && myOwner->getCurrentPlayerInterface()->cb->battleCanCastSpell(myHero, ECastingMode::HERO_CASTING) == ESpellCastProblem::OK) //check conditions
{ {
for(int it=0; it<GameConstants::BFIELD_SIZE; ++it) //do nothing when any hex is hovered - hero's animation overlaps battlefield for(int it=0; it<GameConstants::BFIELD_SIZE; ++it) //do nothing when any hex is hovered - hero's animation overlaps battlefield
{ {

View File

@ -547,7 +547,7 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
} }
//we will cast a spell //we will cast a spell
if(mySpell->combatSpell && owner->myInt->battleInt && owner->myInt->cb->battleCanCastSpell()) //if battle window is open if(mySpell->combatSpell && owner->myInt->battleInt) //if battle window is open
{ {
ESpellCastProblem::ESpellCastProblem problem = owner->myInt->cb->battleCanCastThisSpell(mySpell); ESpellCastProblem::ESpellCastProblem problem = owner->myInt->cb->battleCanCastThisSpell(mySpell);
switch (problem) switch (problem)

View File

@ -2153,26 +2153,6 @@ int CPlayerBattleCallback::battleGetSurrenderCost() const
return CBattleInfoCallback::battleGetSurrenderCost(*player); return CBattleInfoCallback::battleGetSurrenderCost(*player);
} }
bool CPlayerBattleCallback::battleCanCastSpell(ESpellCastProblem::ESpellCastProblem *outProblem /*= nullptr*/) const
{
RETURN_IF_NOT_BATTLE(false);
ASSERT_IF_CALLED_WITH_PLAYER
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;
return problem == ESpellCastProblem::OK;
}
const CGHeroInstance * CPlayerBattleCallback::battleGetMyHero() const const CGHeroInstance * CPlayerBattleCallback::battleGetMyHero() const
{ {
return CBattleInfoEssentials::battleGetFightingHero(battleGetMySide()); return CBattleInfoEssentials::battleGetFightingHero(battleGetMySide());

View File

@ -340,7 +340,6 @@ public:
int battleGetSurrenderCost() const; //returns cost of surrendering battle, -1 if surrendering is not possible int battleGetSurrenderCost() const; //returns cost of surrendering battle, -1 if surrendering is not possible
bool battleCanCastSpell(ESpellCastProblem::ESpellCastProblem *outProblem = nullptr) const; //returns true, if caller can cast a spell. If not, if pointer is given via arg, the reason will be written.
const CGHeroInstance * battleGetMyHero() const; const CGHeroInstance * battleGetMyHero() const;
InfoAboutHero battleGetEnemyHero() const; InfoAboutHero battleGetEnemyHero() const;
}; };