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

CPathfinder: move allowed teleport check into lambda

This also fix accidental whirlpool usage as previously I messed up code a bit.
This commit is contained in:
ArseniyShestakov 2015-03-11 23:53:35 +03:00
parent 01390e0c2c
commit f2a237ce6c

View File

@ -3349,13 +3349,26 @@ void CPathfinder::calculatePaths()
//add accessible neighbouring nodes to the queue //add accessible neighbouring nodes to the queue
neighbours.clear(); neighbours.clear();
auto isAllowedTeleportEntrance = [&](const CGTeleport * obj) -> bool
{
if(!gs->isTeleportEntrancePassable(obj, hero->tempOwner))
return false;
auto whirlpool = dynamic_cast<const CGWhirlpool *>(obj);
if(whirlpool)
{
if(addTeleportWhirlpool(whirlpool))
return true;
}
else if(addTeleportTwoWay(obj) || addTeleportOneWay(obj) || addTeleportOneWayRandom(obj))
return true;
return false;
};
auto sObj = ct->topVisitableObj(cp->coord == CGHeroInstance::convertPosition(hero->pos, false)); auto sObj = ct->topVisitableObj(cp->coord == CGHeroInstance::convertPosition(hero->pos, false));
auto cObj = dynamic_cast<const CGTeleport *>(sObj); auto cObj = dynamic_cast<const CGTeleport *>(sObj);
if(gs->isTeleportEntrancePassable(cObj, hero->tempOwner) if(isAllowedTeleportEntrance(cObj))
&& (addTeleportWhirlpool(dynamic_cast<const CGWhirlpool *>(cObj))
|| addTeleportTwoWay(cObj)
|| addTeleportOneWay(cObj)
|| addTeleportOneWayRandom(cObj)))
{ {
for(auto objId : gs->getTeleportChannelExits(cObj->channel, hero->tempOwner)) for(auto objId : gs->getTeleportChannelExits(cObj->channel, hero->tempOwner))
{ {
@ -3595,5 +3608,5 @@ bool CPathfinder::addTeleportOneWayRandom(const CGTeleport * obj) const
bool CPathfinder::addTeleportWhirlpool(const CGWhirlpool * obj) const bool CPathfinder::addTeleportWhirlpool(const CGWhirlpool * obj) const
{ {
return allowTeleportWhirlpool && obj && !gs->isTeleportChannelImpassable(obj->channel, hero->tempOwner); return allowTeleportWhirlpool && obj;
} }