Codechange: [YAPF] Allow to retrieve the final tile of the calculated path

This commit is contained in:
Nicolas Chappe
2022-07-27 18:34:01 +02:00
committed by Michael Lutz
parent 227626b0b7
commit 7e7d943526
3 changed files with 22 additions and 14 deletions

View File

@@ -2318,13 +2318,16 @@ static const byte _initial_tile_subcoord[6][4][3] = {
* @param[out] path_found Whether a path has been found or not.
* @param do_track_reservation Path reservation is requested
* @param[out] dest State and destination of the requested path
* @param[out] final_dest Final tile of the best path found
* @return The best track the train should follow
*/
static Track DoTrainPathfind(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool do_track_reservation, PBSTileInfo *dest)
static Track DoTrainPathfind(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool do_track_reservation, PBSTileInfo *dest, TileIndex *final_dest)
{
if (final_dest != nullptr) *final_dest = INVALID_TILE;
switch (_settings_game.pf.pathfinder_for_trains) {
case VPF_NPF: return NPFTrainChooseTrack(v, path_found, do_track_reservation, dest);
case VPF_YAPF: return YapfTrainChooseTrack(v, tile, enterdir, tracks, path_found, do_track_reservation, dest);
case VPF_YAPF: return YapfTrainChooseTrack(v, tile, enterdir, tracks, path_found, do_track_reservation, dest, final_dest);
default: NOT_REACHED();
}
@@ -2596,7 +2599,7 @@ static Track ChooseTrainTrack(Train *v, TileIndex tile, DiagDirection enterdir,
bool path_found = true;
TileIndex new_tile = res_dest.tile;
Track next_track = DoTrainPathfind(v, new_tile, dest_enterdir, tracks, path_found, do_track_reservation, &res_dest);
Track next_track = DoTrainPathfind(v, new_tile, dest_enterdir, tracks, path_found, do_track_reservation, &res_dest, nullptr);
if (new_tile == tile) best_track = next_track;
v->HandlePathfindingResult(path_found);
}
@@ -2644,7 +2647,7 @@ static Track ChooseTrainTrack(Train *v, TileIndex tile, DiagDirection enterdir,
if (orders.SwitchToNextOrder(true)) {
PBSTileInfo cur_dest;
bool path_found;
DoTrainPathfind(v, next_tile, exitdir, reachable, path_found, true, &cur_dest);
DoTrainPathfind(v, next_tile, exitdir, reachable, path_found, true, &cur_dest, nullptr);
if (cur_dest.tile != INVALID_TILE) {
res_dest = cur_dest;
if (res_dest.okay) continue;