1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Do not place obstacles on wall parts

This commit is contained in:
AlexVinS 2016-09-23 13:14:12 +03:00
parent 44753866ec
commit bac0b026e5

View File

@ -398,8 +398,6 @@ ESpellCastProblem::ESpellCastProblem HypnotizeMechanics::isImmuneByStack(const I
///ObstacleMechanics
ESpellCastProblem::ESpellCastProblem ObstacleMechanics::canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const
{
if(ctx.ti.clearAffected)
{
ui8 side = cb->playerToSide(ctx.caster->getOwner());
@ -407,19 +405,32 @@ ESpellCastProblem::ESpellCastProblem ObstacleMechanics::canBeCast(const CBattleI
auto tilesThatMustBeClear = owner->rangeInHexes(ctx.destination, ctx.schoolLvl, side, &hexesOutsideBattlefield);
if(ctx.ti.clearAffected)
{
for(BattleHex hex : tilesThatMustBeClear)
{
if(cb->battleGetStackByPos(hex, true) || !!cb->battleGetObstacleOnPos(hex, false) || !hex.isAvailable())
{
return ESpellCastProblem::NO_APPROPRIATE_TARGET;
}
if(nullptr != cb->battleGetDefendedTown() && CGTownInstance::NONE != cb->battleGetDefendedTown()->fortLevel())
{
EWallPart::EWallPart part = cb->battleHexToWallPart(hex);
if(part != EWallPart::INVALID)
{
if(cb->battleGetWallState(part) != EWallState::DESTROYED && cb->battleGetWallState(part) != EWallState::NONE)
return ESpellCastProblem::NO_APPROPRIATE_TARGET;
}
}
}
}
if(hexesOutsideBattlefield)
{
return ESpellCastProblem::NO_APPROPRIATE_TARGET;
}
}
return ESpellCastProblem::OK;
}