1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

fixed patch obstacle placement inside walls

This commit is contained in:
AlexVinS
2016-09-23 20:27:55 +03:00
parent bac0b026e5
commit cffc4b2ab5
2 changed files with 32 additions and 23 deletions

View File

@@ -405,14 +405,26 @@ ESpellCastProblem::ESpellCastProblem ObstacleMechanics::canBeCast(const CBattleI
auto tilesThatMustBeClear = owner->rangeInHexes(ctx.destination, ctx.schoolLvl, side, &hexesOutsideBattlefield); auto tilesThatMustBeClear = owner->rangeInHexes(ctx.destination, ctx.schoolLvl, side, &hexesOutsideBattlefield);
if(ctx.ti.clearAffected) for(const BattleHex & hex : tilesThatMustBeClear)
{ if(!isHexAviable(cb, hex, ctx.ti.clearAffected))
for(BattleHex hex : tilesThatMustBeClear)
{
if(cb->battleGetStackByPos(hex, true) || !!cb->battleGetObstacleOnPos(hex, false) || !hex.isAvailable())
{
return ESpellCastProblem::NO_APPROPRIATE_TARGET; return ESpellCastProblem::NO_APPROPRIATE_TARGET;
}
if(hexesOutsideBattlefield)
return ESpellCastProblem::NO_APPROPRIATE_TARGET;
return ESpellCastProblem::OK;
}
bool ObstacleMechanics::isHexAviable(const CBattleInfoCallback * cb, const BattleHex & hex, const bool mustBeClear)
{
if(!hex.isAvailable())
return false;
if(!mustBeClear)
return true;
if(cb->battleGetStackByPos(hex, true) || !!cb->battleGetObstacleOnPos(hex, false))
return false;
if(nullptr != cb->battleGetDefendedTown() && CGTownInstance::NONE != cb->battleGetDefendedTown()->fortLevel()) if(nullptr != cb->battleGetDefendedTown() && CGTownInstance::NONE != cb->battleGetDefendedTown()->fortLevel())
{ {
@@ -420,19 +432,15 @@ ESpellCastProblem::ESpellCastProblem ObstacleMechanics::canBeCast(const CBattleI
if(part != EWallPart::INVALID) if(part != EWallPart::INVALID)
{ {
if(static_cast<int>(part) < 0)
return false;//indestuctible part, cant be checked by battleGetWallState
if(cb->battleGetWallState(part) != EWallState::DESTROYED && cb->battleGetWallState(part) != EWallState::NONE) if(cb->battleGetWallState(part) != EWallState::DESTROYED && cb->battleGetWallState(part) != EWallState::NONE)
return ESpellCastProblem::NO_APPROPRIATE_TARGET; return false;
}
}
} }
} }
if(hexesOutsideBattlefield) return true;
{
return ESpellCastProblem::NO_APPROPRIATE_TARGET;
}
return ESpellCastProblem::OK;
} }
void ObstacleMechanics::placeObstacle(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, const BattleHex & pos) const void ObstacleMechanics::placeObstacle(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, const BattleHex & pos) const
@@ -461,7 +469,7 @@ void PatchObstacleMechanics::applyBattleEffects(const SpellCastEnvironment * env
for(int i = 0; i < GameConstants::BFIELD_SIZE; i += 1) for(int i = 0; i < GameConstants::BFIELD_SIZE; i += 1)
{ {
BattleHex hex = i; BattleHex hex = i;
if(hex.getX() > 0 && hex.getX() < 16 && !(parameters.cb->battleGetStackByPos(hex, false)) && !(parameters.cb->battleGetObstacleOnPos(hex, false))) if(isHexAviable(parameters.cb, hex, true))
availableTiles.push_back(hex); availableTiles.push_back(hex);
} }
RandomGeneratorUtil::randomShuffle(availableTiles, env->getRandomGenerator()); RandomGeneratorUtil::randomShuffle(availableTiles, env->getRandomGenerator());

View File

@@ -104,6 +104,7 @@ public:
ObstacleMechanics(CSpell * s): SpecialSpellMechanics(s){}; ObstacleMechanics(CSpell * s): SpecialSpellMechanics(s){};
ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const override; ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const override;
protected: protected:
static bool isHexAviable(const CBattleInfoCallback * cb, const BattleHex & hex, const bool mustBeClear);
void placeObstacle(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, const BattleHex & pos) const; void placeObstacle(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, const BattleHex & pos) const;
virtual void setupObstacle(SpellCreatedObstacle * obstacle) const = 0; virtual void setupObstacle(SpellCreatedObstacle * obstacle) const = 0;
}; };