1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Advance REMOVE_OBSTACLE mechanics

This commit is contained in:
AlexVinS 2016-03-01 12:20:38 +03:00
parent 40e6e0c143
commit f053754653
2 changed files with 53 additions and 27 deletions

View File

@ -507,43 +507,64 @@ void RemoveObstacleMechanics::applyBattleEffects(const SpellCastEnvironment * en
{
if(auto obstacleToRemove = parameters.cb->battleGetObstacleOnPos(parameters.getFirstDestinationHex(), false))
{
ObstaclesRemoved obr;
obr.obstacles.insert(obstacleToRemove->uniqueID);
env->sendAndApply(&obr);
if(canRemove(obstacleToRemove.get(), parameters.spellLvl))
{
ObstaclesRemoved obr;
obr.obstacles.insert(obstacleToRemove->uniqueID);
env->sendAndApply(&obr);
}
else
{
env->complain("Cant remove this obstacle!");
}
}
else
env->complain("There's no obstacle to remove!");
}
ESpellCastProblem::ESpellCastProblem RemoveObstacleMechanics::canBeCast(const CBattleInfoCallback * cb, const ISpellCaster * caster) const
{
const int spellLevel = caster->getSpellSchoolLevel(owner);
for(auto obstacle : cb->battleGetAllObstacles())
if(canRemove(obstacle.get(), spellLevel))
return ESpellCastProblem::OK;
return ESpellCastProblem::NO_APPROPRIATE_TARGET;
}
ESpellCastProblem::ESpellCastProblem RemoveObstacleMechanics::canBeCast(const SpellTargetingContext & ctx) const
{
ESpellCastProblem::ESpellCastProblem res = ESpellCastProblem::NO_APPROPRIATE_TARGET;
if(auto obstacle = ctx.cb->battleGetObstacleOnPos(ctx.destination, false))
if(canRemove(obstacle.get(), ctx.schoolLvl))
return ESpellCastProblem::OK;
return ESpellCastProblem::NO_APPROPRIATE_TARGET;
}
bool RemoveObstacleMechanics::canRemove(const CObstacleInstance * obstacle, const int spellLevel) const
{
switch (obstacle->obstacleType)
{
switch (obstacle->obstacleType)
{
case CObstacleInstance::ABSOLUTE_OBSTACLE: //cliff-like obstacles can't be removed
case CObstacleInstance::MOAT:
break;
case CObstacleInstance::USUAL:
res = ESpellCastProblem::OK;
break;
case CObstacleInstance::FIRE_WALL:
if(ctx.schoolLvl >= 2)
res = ESpellCastProblem::OK;
break;
case CObstacleInstance::QUICKSAND:
case CObstacleInstance::LAND_MINE:
case CObstacleInstance::FORCE_FIELD:
if(ctx.schoolLvl >= 3)
res = ESpellCastProblem::OK;
break;
default:
break;
}
case CObstacleInstance::ABSOLUTE_OBSTACLE: //cliff-like obstacles can't be removed
case CObstacleInstance::MOAT:
return false;
case CObstacleInstance::USUAL:
return true;
case CObstacleInstance::FIRE_WALL:
if(spellLevel >= 2)
return true;
break;
case CObstacleInstance::QUICKSAND:
case CObstacleInstance::LAND_MINE:
case CObstacleInstance::FORCE_FIELD:
if(spellLevel >= 3)
return true;
break;
default:
break;
}
return res;
return false;
}
///RisingSpellMechanics

View File

@ -12,6 +12,8 @@
#include "CDefaultSpellMechanics.h"
class CObstacleInstance;
class DLL_LINKAGE HealingSpellMechanics : public DefaultSpellMechanics
{
public:
@ -110,9 +112,12 @@ class DLL_LINKAGE RemoveObstacleMechanics : public DefaultSpellMechanics
{
public:
RemoveObstacleMechanics(CSpell * s): DefaultSpellMechanics(s){};
ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const ISpellCaster * caster) const override;
ESpellCastProblem::ESpellCastProblem canBeCast(const SpellTargetingContext & ctx) const override;
protected:
void applyBattleEffects(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, SpellCastContext & ctx) const override;
private:
bool canRemove(const CObstacleInstance * obstacle, const int spellLevel) const;
};
///all rising spells