* Runs the pathfinder to choose a track to continue along. * * @param v Ship to navigate * @param tile Tile, the ship is about to enter * @param tracks Available track choices on \a tile * @return Track to choose, or INVALID_TRACK when to reverse. */
| 463 | * @return Track to choose, or INVALID_TRACK when to reverse. |
| 464 | */ |
| 465 | static Track ChooseShipTrack(Ship *v, TileIndex tile, TrackBits tracks) |
| 466 | { |
| 467 | bool path_found = true; |
| 468 | Track track; |
| 469 | |
| 470 | if (v->dest_tile == 0) { |
| 471 | /* No destination, don't invoke pathfinder. */ |
| 472 | track = TrackBitsToTrack(v->state); |
| 473 | if (!IsDiagonalTrack(track)) track = TrackToOppositeTrack(track); |
| 474 | if (!HasBit(tracks, track)) track = FindFirstTrack(tracks); |
| 475 | path_found = false; |
| 476 | } else { |
| 477 | /* Attempt to follow cached path. */ |
| 478 | if (!v->path.empty()) { |
| 479 | track = TrackdirToTrack(v->path.back().trackdir); |
| 480 | |
| 481 | if (HasBit(tracks, track)) { |
| 482 | v->path.pop_back(); |
| 483 | /* HandlePathfindResult() is not called here because this is not a new pathfinder result. */ |
| 484 | return track; |
| 485 | } |
| 486 | |
| 487 | /* Cached path is invalid so continue with pathfinder. */ |
| 488 | v->path.clear(); |
| 489 | } |
| 490 | |
| 491 | track = YapfShipChooseTrack(v, tile, path_found, v->path); |
| 492 | } |
| 493 | |
| 494 | v->HandlePathfindingResult(path_found); |
| 495 | return track; |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * Get the available water tracks on a tile for a ship entering a tile. |
no test coverage detected