mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
CPathfinder: move check into isBetterWay lambda
It's must be of course used for teleporters too.
This commit is contained in:
@@ -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
|
if(isBetterWay(remains, turnAtNextTile))
|
||||||
|| dp->turns > turnAtNextTile
|
|
||||||
|| (dp->turns >= turnAtNextTile && dp->moveRemains < remains)) //this route is faster
|
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user