1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-25 21:38:59 +02:00

CPathfinder: move check into isBetterWay lambda

It's must be of course used for teleporters too.
This commit is contained in:
ArseniyShestakov 2015-10-24 14:54:15 +03:00
parent 5a04f05b9b
commit 6934c6bc95

View File

@ -3428,6 +3428,18 @@ void CPathfinder::calculatePaths()
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;
//initial tile - set cost on 0 and add to the queue
@ -3477,9 +3489,7 @@ void CPathfinder::calculatePaths()
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
dp->moveRemains = remains;
@ -3498,7 +3508,7 @@ void CPathfinder::calculatePaths()
for(auto & neighbour : neighbours)
{
dp = getNode(neighbour);
if (dp->turns == 0xff)
if (isBetterWay(movement, turn))
{
dp->moveRemains = movement;
dp->turns = turn;