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:
parent
01390e0c2c
commit
f2a237ce6c
@ -3349,13 +3349,26 @@ void CPathfinder::calculatePaths()
|
||||
//add accessible neighbouring nodes to the queue
|
||||
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 cObj = dynamic_cast<const CGTeleport *>(sObj);
|
||||
if(gs->isTeleportEntrancePassable(cObj, hero->tempOwner)
|
||||
&& (addTeleportWhirlpool(dynamic_cast<const CGWhirlpool *>(cObj))
|
||||
|| addTeleportTwoWay(cObj)
|
||||
|| addTeleportOneWay(cObj)
|
||||
|| addTeleportOneWayRandom(cObj)))
|
||||
if(isAllowedTeleportEntrance(cObj))
|
||||
{
|
||||
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
|
||||
{
|
||||
return allowTeleportWhirlpool && obj && !gs->isTeleportChannelImpassable(obj->channel, hero->tempOwner);
|
||||
return allowTeleportWhirlpool && obj;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user