1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-23 21:29:13 +02:00

Fixed error handling in TownPortalMechanics::applyAdventureEffects

This commit is contained in:
AlexVinS 2019-02-23 20:51:03 +03:00
parent 9311966706
commit 1855af9ed3

View File

@ -367,17 +367,30 @@ ESpellCastResult TownPortalMechanics::applyAdventureEffects(const SpellCastEnvir
else if(env->getMap()->isInTheMap(parameters.pos)) else if(env->getMap()->isInTheMap(parameters.pos))
{ {
const TerrainTile & tile = env->getMap()->getTile(parameters.pos); const TerrainTile & tile = env->getMap()->getTile(parameters.pos);
if(tile.visitableObjects.empty() || tile.visitableObjects.back()->ID != Obj::TOWN)
const auto topObj = tile.topVisitableObj(false);
if(!topObj)
{ {
env->complain("No town at destination tile"); env->complain("Destination tile is not visitable" + parameters.pos.toString());
return ESpellCastResult::ERROR;
}
else if(topObj->ID == Obj::HERO)
{
env->complain("Can't teleport to occupied town at " + parameters.pos.toString());
return ESpellCastResult::ERROR;
}
else if(topObj->ID != Obj::TOWN)
{
env->complain("No town at destination tile " + parameters.pos.toString());
return ESpellCastResult::ERROR; return ESpellCastResult::ERROR;
} }
destination = dynamic_cast<CGTownInstance*>(tile.visitableObjects.back()); destination = dynamic_cast<const CGTownInstance*>(topObj);
if(nullptr == destination) if(nullptr == destination)
{ {
env->complain("[Internal error] invalid town object"); env->complain("[Internal error] invalid town object at " + parameters.pos.toString());
return ESpellCastResult::ERROR; return ESpellCastResult::ERROR;
} }
@ -397,7 +410,7 @@ ESpellCastResult TownPortalMechanics::applyAdventureEffects(const SpellCastEnvir
if(destination->visitingHero) if(destination->visitingHero)
{ {
env->complain("Can't teleport to occupied town!"); env->complain("[Internal error] Can't teleport to occupied town");
return ESpellCastResult::ERROR; return ESpellCastResult::ERROR;
} }
} }