1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

Moved all affected stacks calculations to mechanics

This commit is contained in:
AlexVinS
2016-09-06 07:05:55 +03:00
parent 18fc94d709
commit f1d0bede11
5 changed files with 29 additions and 17 deletions

View File

@@ -638,6 +638,13 @@ std::vector<BattleHex> DefaultSpellMechanics::rangeInHexes(BattleHex centralHex,
}
std::vector<const CStack *> DefaultSpellMechanics::getAffectedStacks(const CBattleInfoCallback * cb, SpellTargetingContext & ctx) const
{
std::vector<const CStack *> attackedCres = calculateAffectedStacks(cb, ctx);
handleImmunities(cb, ctx, attackedCres);
return attackedCres;
}
std::vector<const CStack *> DefaultSpellMechanics::calculateAffectedStacks(const CBattleInfoCallback* cb, const SpellTargetingContext& ctx) const
{
std::set<const CStack* > attackedCres;//std::set to exclude multiple occurrences of two hex creatures
@@ -751,6 +758,19 @@ void DefaultSpellMechanics::doDispell(BattleInfo * battle, const BattleSpellCast
}
}
void DefaultSpellMechanics::handleImmunities(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx, std::vector<const CStack*> & stacks) const
{
//now handle immunities
auto predicate = [&, this](const CStack * s)->bool
{
bool hitDirectly = ctx.ti.alwaysHitDirectly && s->coversPos(ctx.destination);
bool notImmune = (ESpellCastProblem::OK == owner->isImmuneByStack(ctx.caster, s));
return !(hitDirectly || notImmune);
};
vstd::erase_if(stacks, predicate);
}
void DefaultSpellMechanics::handleResistance(const SpellCastEnvironment * env, std::vector<const CStack* >& attackedCres, BattleSpellCast& sc) const
{
//checking if creatures resist