MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ChooseShipTrack

Function ChooseShipTrack

src/ship_cmd.cpp:465–496  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

463 * @return Track to choose, or INVALID_TRACK when to reverse.
464 */
465static 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.

Callers 3

ShipControllerFunction · 0.85
CheckShipReverseMethod · 0.85
YapfShipChooseTrackFunction · 0.85

Calls 11

TrackBitsToTrackFunction · 0.85
IsDiagonalTrackFunction · 0.85
TrackToOppositeTrackFunction · 0.85
HasBitFunction · 0.85
FindFirstTrackFunction · 0.85
TrackdirToTrackFunction · 0.85
YapfShipChooseTrackFunction · 0.85
pop_backMethod · 0.80
emptyMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected