1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Fix pathfinding issues when hero has expert navigation

This commit is contained in:
Andrii Danylchenko 2021-07-26 23:56:47 +03:00 committed by Andrii Danylchenko
parent 98c6215ab6
commit 11e6e0d6f7

View File

@ -209,15 +209,17 @@ void MovementCostRule::process(
int moveAtNextTile = destination.movementLeft; int moveAtNextTile = destination.movementLeft;
int cost = pathfinderHelper->getMovementCost(source, destination, moveAtNextTile); int cost = pathfinderHelper->getMovementCost(source, destination, moveAtNextTile);
int remains = moveAtNextTile - cost; int remains = moveAtNextTile - cost;
int maxMovePoints = pathfinderHelper->getMaxMovePoints(destination.node->layer); int sourceLayerMaxMovePoints = pathfinderHelper->getMaxMovePoints(source.node->layer);
if(remains < 0) if(remains < 0)
{ {
//occurs rarely, when hero with low movepoints tries to leave the road //occurs rarely, when hero with low movepoints tries to leave the road
costAtNextTile += static_cast<float>(moveAtNextTile) / maxMovePoints;//we spent all points of current turn costAtNextTile += static_cast<float>(moveAtNextTile) / sourceLayerMaxMovePoints;//we spent all points of current turn
pathfinderHelper->updateTurnInfo(++turnAtNextTile); pathfinderHelper->updateTurnInfo(++turnAtNextTile);
maxMovePoints = pathfinderHelper->getMaxMovePoints(destination.node->layer); int destinationLayerMaxMovePoints = pathfinderHelper->getMaxMovePoints(destination.node->layer);
moveAtNextTile = maxMovePoints;
moveAtNextTile = destinationLayerMaxMovePoints;
cost = pathfinderHelper->getMovementCost(source, destination, moveAtNextTile); //cost must be updated, movement points changed :( cost = pathfinderHelper->getMovementCost(source, destination, moveAtNextTile); //cost must be updated, movement points changed :(
remains = moveAtNextTile - cost; remains = moveAtNextTile - cost;
@ -231,7 +233,7 @@ void MovementCostRule::process(
cost = moveAtNextTile - remains; cost = moveAtNextTile - remains;
} }
costAtNextTile += static_cast<float>(cost) / maxMovePoints; costAtNextTile += static_cast<float>(cost) / sourceLayerMaxMovePoints;
destination.cost = costAtNextTile; destination.cost = costAtNextTile;
destination.turn = turnAtNextTile; destination.turn = turnAtNextTile;