mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
get rid of CPlayerBattleCallback::battleCanCastSpell
This commit is contained in:
parent
1d1519db5c
commit
4d430f6ad8
@ -186,7 +186,7 @@ void CBattleAI::attemptCastingSpell()
|
||||
if(!hero)
|
||||
return;
|
||||
|
||||
if(!cb->battleCanCastSpell())
|
||||
if(cb->battleCanCastSpell(hero, ECastingMode::HERO_CASTING) != ESpellCastProblem::OK)
|
||||
return;
|
||||
|
||||
LOGL("Casting spells sounds like fun. Let's see...");
|
||||
|
@ -871,19 +871,24 @@ void CBattleInterface::bSpellf()
|
||||
if (spellDestSelectMode) //we are casting a spell
|
||||
return;
|
||||
|
||||
CCS->curh->changeGraphic(ECursor::ADVENTURE,0);
|
||||
|
||||
if (!myTurn)
|
||||
return;
|
||||
|
||||
auto myHero = currentHero();
|
||||
ESpellCastProblem::ESpellCastProblem spellCastProblem;
|
||||
if (curInt->cb->battleCanCastSpell(&spellCastProblem))
|
||||
if(!myHero)
|
||||
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()));
|
||||
}
|
||||
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
|
||||
auto blockingBonus = currentHero()->getBonusLocalFirst(Selector::type(Bonus::BLOCK_ALL_MAGIC));
|
||||
if (!blockingBonus)
|
||||
@ -1849,11 +1854,17 @@ void CBattleInterface::showQueue()
|
||||
|
||||
void CBattleInterface::blockUI(bool on)
|
||||
{
|
||||
ESpellCastProblem::ESpellCastProblem spellcastingProblem;
|
||||
bool canCastSpells = curInt->cb->battleCanCastSpell(&spellcastingProblem);
|
||||
//if magic is blocked, we leave button active, so the message can be displayed (cf bug #97)
|
||||
if (!canCastSpells)
|
||||
canCastSpells = spellcastingProblem == ESpellCastProblem::MAGIC_IS_BLOCKED;
|
||||
bool canCastSpells = false;
|
||||
auto hero = curInt->cb->battleGetMyHero();
|
||||
|
||||
if(hero)
|
||||
{
|
||||
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;
|
||||
|
||||
bOptions->block(on);
|
||||
|
@ -191,7 +191,7 @@ void CBattleHero::clickLeft(tribool down, bool previousState)
|
||||
if(myOwner->spellDestSelectMode) //we are casting a spell
|
||||
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
|
||||
{
|
||||
|
@ -547,7 +547,7 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
|
||||
}
|
||||
|
||||
//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);
|
||||
switch (problem)
|
||||
|
@ -2153,26 +2153,6 @@ int CPlayerBattleCallback::battleGetSurrenderCost() const
|
||||
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
|
||||
{
|
||||
return CBattleInfoEssentials::battleGetFightingHero(battleGetMySide());
|
||||
|
@ -340,7 +340,6 @@ public:
|
||||
|
||||
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;
|
||||
InfoAboutHero battleGetEnemyHero() const;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user