mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-12 23:57:33 +02:00
get rid of CBattleInfoCallback::battleCanCastThisSpell
This commit is contained in:
parent
6c308956f9
commit
195e979a18
@ -194,8 +194,7 @@ void CBattleAI::attemptCastingSpell()
|
|||||||
std::vector<const CSpell*> possibleSpells;
|
std::vector<const CSpell*> possibleSpells;
|
||||||
vstd::copy_if(VLC->spellh->objects, std::back_inserter(possibleSpells), [this, hero] (const CSpell *s) -> bool
|
vstd::copy_if(VLC->spellh->objects, std::back_inserter(possibleSpells), [this, hero] (const CSpell *s) -> bool
|
||||||
{
|
{
|
||||||
auto problem = getCbc()->battleCanCastThisSpell(hero, s, ECastingMode::HERO_CASTING);
|
return s->canBeCast(getCbc().get(), ECastingMode::HERO_CASTING, hero) == ESpellCastProblem::OK;
|
||||||
return problem == ESpellCastProblem::OK;
|
|
||||||
});
|
});
|
||||||
LOGFL("I can cast %d spells.", possibleSpells.size());
|
LOGFL("I can cast %d spells.", possibleSpells.size());
|
||||||
|
|
||||||
|
@ -549,7 +549,7 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
|
|||||||
//we will cast a spell
|
//we will cast a spell
|
||||||
if(mySpell->isCombatSpell() && owner->myInt->battleInt) //if battle window is open
|
if(mySpell->isCombatSpell() && owner->myInt->battleInt) //if battle window is open
|
||||||
{
|
{
|
||||||
ESpellCastProblem::ESpellCastProblem problem = owner->myInt->cb->battleCanCastThisSpell(owner->myHero, mySpell, ECastingMode::HERO_CASTING);
|
ESpellCastProblem::ESpellCastProblem problem = mySpell->canBeCast(owner->myInt->cb.get(), ECastingMode::HERO_CASTING, owner->myHero);
|
||||||
switch (problem)
|
switch (problem)
|
||||||
{
|
{
|
||||||
case ESpellCastProblem::OK:
|
case ESpellCastProblem::OK:
|
||||||
|
@ -1708,43 +1708,6 @@ std::vector<BattleHex> CBattleInfoCallback::getAttackableBattleHexes() const
|
|||||||
return attackableBattleHexes;
|
return attackableBattleHexes;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell(const ISpellCaster * caster, const CSpell * spell, ECastingMode::ECastingMode mode) const
|
|
||||||
{
|
|
||||||
RETURN_IF_NOT_BATTLE(ESpellCastProblem::INVALID);
|
|
||||||
if(caster == nullptr)
|
|
||||||
{
|
|
||||||
logGlobal->errorStream() << "CBattleInfoCallback::battleCanCastThisSpell: no spellcaster.";
|
|
||||||
return ESpellCastProblem::INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
ESpellCastProblem::ESpellCastProblem genProblem = battleCanCastSpell(caster, mode);
|
|
||||||
if(genProblem != ESpellCastProblem::OK)
|
|
||||||
return genProblem;
|
|
||||||
|
|
||||||
switch(mode)
|
|
||||||
{
|
|
||||||
case ECastingMode::HERO_CASTING:
|
|
||||||
{
|
|
||||||
const CGHeroInstance * castingHero = dynamic_cast<const CGHeroInstance *>(caster);//todo: unify hero|creature spell cost
|
|
||||||
if(!castingHero)
|
|
||||||
{
|
|
||||||
logGlobal->error("battleCanCastThisSpell: invalid caster");
|
|
||||||
return ESpellCastProblem::INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!castingHero->getArt(ArtifactPosition::SPELLBOOK))
|
|
||||||
return ESpellCastProblem::NO_SPELLBOOK;
|
|
||||||
if(!castingHero->canCastThisSpell(spell))
|
|
||||||
return ESpellCastProblem::HERO_DOESNT_KNOW_SPELL;
|
|
||||||
if(castingHero->mana < battleGetSpellCost(spell, castingHero)) //not enough mana
|
|
||||||
return ESpellCastProblem::NOT_ENOUGH_MANA;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return spell->canBeCast(this, mode, caster);
|
|
||||||
}
|
|
||||||
|
|
||||||
ui32 CBattleInfoCallback::battleGetSpellCost(const CSpell * sp, const CGHeroInstance * caster) const
|
ui32 CBattleInfoCallback::battleGetSpellCost(const CSpell * sp, const CGHeroInstance * caster) const
|
||||||
{
|
{
|
||||||
RETURN_IF_NOT_BATTLE(-1);
|
RETURN_IF_NOT_BATTLE(-1);
|
||||||
|
@ -293,7 +293,6 @@ public:
|
|||||||
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
|
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(const ISpellCaster * caster, 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
|
|
||||||
|
|
||||||
SpellID battleGetRandomStackSpell(CRandomGenerator & rand, const CStack * stack, ERandomSpell mode) const;
|
SpellID battleGetRandomStackSpell(CRandomGenerator & rand, const CStack * stack, ERandomSpell mode) const;
|
||||||
SpellID getRandomBeneficialSpell(CRandomGenerator & rand, const CStack * subject) const;
|
SpellID getRandomBeneficialSpell(CRandomGenerator & rand, const CStack * subject) const;
|
||||||
|
@ -157,6 +157,31 @@ ui32 CSpell::calculateDamage(const ISpellCaster * caster, const CStack * affecte
|
|||||||
|
|
||||||
ESpellCastProblem::ESpellCastProblem CSpell::canBeCast(const CBattleInfoCallback * cb, ECastingMode::ECastingMode mode, const ISpellCaster * caster) const
|
ESpellCastProblem::ESpellCastProblem CSpell::canBeCast(const CBattleInfoCallback * cb, ECastingMode::ECastingMode mode, const ISpellCaster * caster) const
|
||||||
{
|
{
|
||||||
|
ESpellCastProblem::ESpellCastProblem genProblem = cb->battleCanCastSpell(caster, mode);
|
||||||
|
if(genProblem != ESpellCastProblem::OK)
|
||||||
|
return genProblem;
|
||||||
|
|
||||||
|
switch(mode)
|
||||||
|
{
|
||||||
|
case ECastingMode::HERO_CASTING:
|
||||||
|
{
|
||||||
|
const CGHeroInstance * castingHero = dynamic_cast<const CGHeroInstance *>(caster);//todo: unify hero|creature spell cost
|
||||||
|
if(!castingHero)
|
||||||
|
{
|
||||||
|
logGlobal->debug("CSpell::canBeCast: invalid caster");
|
||||||
|
return ESpellCastProblem::NO_HERO_TO_CAST_SPELL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!castingHero->getArt(ArtifactPosition::SPELLBOOK))
|
||||||
|
return ESpellCastProblem::NO_SPELLBOOK;
|
||||||
|
if(!castingHero->canCastThisSpell(this))
|
||||||
|
return ESpellCastProblem::HERO_DOESNT_KNOW_SPELL;
|
||||||
|
if(castingHero->mana < cb->battleGetSpellCost(this, castingHero)) //not enough mana
|
||||||
|
return ESpellCastProblem::NOT_ENOUGH_MANA;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if(!isCombatSpell())
|
if(!isCombatSpell())
|
||||||
return ESpellCastProblem::ADVMAP_SPELL_INSTEAD_OF_BATTLE_SPELL;
|
return ESpellCastProblem::ADVMAP_SPELL_INSTEAD_OF_BATTLE_SPELL;
|
||||||
|
|
||||||
@ -383,7 +408,7 @@ void CSpell::getEffects(std::vector<Bonus> & lst, const int level) const
|
|||||||
|
|
||||||
ESpellCastProblem::ESpellCastProblem CSpell::canBeCastAt(const CBattleInfoCallback * cb, const ISpellCaster * caster, ECastingMode::ECastingMode mode, BattleHex destination) const
|
ESpellCastProblem::ESpellCastProblem CSpell::canBeCastAt(const CBattleInfoCallback * cb, const ISpellCaster * caster, ECastingMode::ECastingMode mode, BattleHex destination) const
|
||||||
{
|
{
|
||||||
ESpellCastProblem::ESpellCastProblem problem = cb->battleCanCastThisSpell(caster, this, mode);
|
ESpellCastProblem::ESpellCastProblem problem = canBeCast(cb, mode, caster);
|
||||||
if(problem != ESpellCastProblem::OK)
|
if(problem != ESpellCastProblem::OK)
|
||||||
return problem;
|
return problem;
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ void BattleSpellCastParameters::cast(const SpellCastEnvironment * env)
|
|||||||
|
|
||||||
bool BattleSpellCastParameters::castIfPossible(const SpellCastEnvironment * env)
|
bool BattleSpellCastParameters::castIfPossible(const SpellCastEnvironment * env)
|
||||||
{
|
{
|
||||||
if(ESpellCastProblem::OK == cb->battleCanCastThisSpell(caster, spell, mode))
|
if(ESpellCastProblem::OK == spell->canBeCast(cb, mode, caster))
|
||||||
{
|
{
|
||||||
cast(env);
|
cast(env);
|
||||||
return true;
|
return true;
|
||||||
|
@ -4458,7 +4458,7 @@ bool CGameHandler::makeCustomAction(BattleAction &ba)
|
|||||||
if (ba.selectedStack >= 0)
|
if (ba.selectedStack >= 0)
|
||||||
parameters.aimToStack(gs->curB->battleGetStackByID(ba.selectedStack, false));
|
parameters.aimToStack(gs->curB->battleGetStackByID(ba.selectedStack, false));
|
||||||
|
|
||||||
ESpellCastProblem::ESpellCastProblem escp = gs->curB->battleCanCastThisSpell(h, s, ECastingMode::HERO_CASTING);//todo: should we check aimed cast?
|
ESpellCastProblem::ESpellCastProblem escp = s->canBeCast(gs->curB, ECastingMode::HERO_CASTING, h);//todo: should we check aimed cast?
|
||||||
if (escp != ESpellCastProblem::OK)
|
if (escp != ESpellCastProblem::OK)
|
||||||
{
|
{
|
||||||
logGlobal->warn("Spell cannot be cast! Problem: %d", escp);
|
logGlobal->warn("Spell cannot be cast! Problem: %d", escp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user