Преглед изворни кода

CPathfinder: move allowed teleport check into lambda

This also fix accidental whirlpool usage as previously I messed up code a bit.
ArseniyShestakov пре 10 година
родитељ
комит
f2a237ce6c
1 измењених фајлова са 19 додато и 6 уклоњено
  1. 19 6
      lib/CGameState.cpp

+ 19 - 6
lib/CGameState.cpp

@@ -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;
 }