Browse Source

CPathfinder: move check into isBetterWay lambda

It's must be of course used for teleporters too.
ArseniyShestakov 10 years ago
parent
commit
6934c6bc95
1 changed files with 14 additions and 4 deletions
  1. 14 4
      lib/CGameState.cpp

+ 14 - 4
lib/CGameState.cpp

@@ -3428,6 +3428,18 @@ void CPathfinder::calculatePaths()
 		return cp->land ? maxMovePointsLand : maxMovePointsWater;
 		return cp->land ? maxMovePointsLand : maxMovePointsWater;
 	};
 	};
 
 
+	auto isBetterWay = [&](int remains, int turn) -> bool
+	{
+		if(dp->turns == 0xff) //we haven't been here before
+			return true;
+		else if(dp->turns > turn)
+			return true;
+		else if(dp->turns >= turn  &&  dp->moveRemains < remains) //this route is faster
+			return true;
+
+		return false;
+	};
+
 	//logGlobal->infoStream() << boost::format("Calculating paths for hero %s (adress  %d) of player %d") % hero->name % hero % hero->tempOwner;
 	//logGlobal->infoStream() << boost::format("Calculating paths for hero %s (adress  %d) of player %d") % hero->name % hero % hero->tempOwner;
 
 
 	//initial tile - set cost on 0 and add to the queue
 	//initial tile - set cost on 0 and add to the queue
@@ -3477,9 +3489,7 @@ void CPathfinder::calculatePaths()
 				remains = moveAtNextTile - cost;
 				remains = moveAtNextTile - cost;
 			}
 			}
 
 
-			if(dp->turns==0xff		//we haven't been here before
-				|| dp->turns > turnAtNextTile
-				|| (dp->turns >= turnAtNextTile  &&  dp->moveRemains < remains)) //this route is faster
+			if(isBetterWay(remains, turnAtNextTile))
 			{
 			{
 				assert(dp != cp->theNodeBefore); //two tiles can't point to each other
 				assert(dp != cp->theNodeBefore); //two tiles can't point to each other
 				dp->moveRemains = remains;
 				dp->moveRemains = remains;
@@ -3498,7 +3508,7 @@ void CPathfinder::calculatePaths()
 			for(auto & neighbour : neighbours)
 			for(auto & neighbour : neighbours)
 			{
 			{
 				dp = getNode(neighbour);
 				dp = getNode(neighbour);
-				if (dp->turns == 0xff)
+				if (isBetterWay(movement, turn))
 				{
 				{
 					dp->moveRemains = movement;
 					dp->moveRemains = movement;
 					dp->turns = turn;
 					dp->turns = turn;