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

@ -399,28 +399,39 @@ ESpellCastProblem::ESpellCastProblem HypnotizeMechanics::isImmuneByStack(const I
///ObstacleMechanics ///ObstacleMechanics
ESpellCastProblem::ESpellCastProblem ObstacleMechanics::canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const ESpellCastProblem::ESpellCastProblem ObstacleMechanics::canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const
{ {
ui8 side = cb->playerToSide(ctx.caster->getOwner());
bool hexesOutsideBattlefield = false;
auto tilesThatMustBeClear = owner->rangeInHexes(ctx.destination, ctx.schoolLvl, side, &hexesOutsideBattlefield);
if(ctx.ti.clearAffected) if(ctx.ti.clearAffected)
{ {
ui8 side = cb->playerToSide(ctx.caster->getOwner());
bool hexesOutsideBattlefield = false;
auto tilesThatMustBeClear = owner->rangeInHexes(ctx.destination, ctx.schoolLvl, side, &hexesOutsideBattlefield);
for(BattleHex hex : tilesThatMustBeClear) for(BattleHex hex : tilesThatMustBeClear)
{ {
if(cb->battleGetStackByPos(hex, true) || !!cb->battleGetObstacleOnPos(hex, false) || !hex.isAvailable()) if(cb->battleGetStackByPos(hex, true) || !!cb->battleGetObstacleOnPos(hex, false) || !hex.isAvailable())
{ {
return ESpellCastProblem::NO_APPROPRIATE_TARGET; return ESpellCastProblem::NO_APPROPRIATE_TARGET;
} }
}
if(hexesOutsideBattlefield) if(nullptr != cb->battleGetDefendedTown() && CGTownInstance::NONE != cb->battleGetDefendedTown()->fortLevel())
{ {
return ESpellCastProblem::NO_APPROPRIATE_TARGET; 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; return ESpellCastProblem::OK;
} }