Skip to content

Commit

Permalink
Fix OpenTTD#7226: Don't call ship pathfinders if there is no availabl…
Browse files Browse the repository at this point in the history
…e track due to "forbid 90 deg turns".
  • Loading branch information
J0anJosep authored and michicc committed Feb 18, 2019
1 parent 349cbee commit 6ca637b
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/ship_cmd.cpp
Expand Up @@ -510,9 +510,20 @@ static Track ChooseShipTrack(Ship *v, TileIndex tile, DiagDirection enterdir, Tr
return track;
}

static inline TrackBits GetAvailShipTracks(TileIndex tile, DiagDirection dir)
/**
* Get the available water tracks on a tile for a ship entering a tile.
* @param tile The tile about to enter.
* @param dir The entry direction.
* @param trackdir The trackdir the ship has on the old tile.
* @return The available trackbits on the next tile.
*/
static inline TrackBits GetAvailShipTracks(TileIndex tile, DiagDirection dir, Trackdir trackdir)
{
return GetTileShipTrackStatus(tile) & DiagdirReachesTracks(dir);
TrackBits tracks = GetTileShipTrackStatus(tile) & DiagdirReachesTracks(dir);

if (_settings_game.pf.forbid_90_deg) tracks &= ~TrackCrossesTracks(TrackdirToTrack(trackdir));

return tracks;
}

static const byte _ship_subcoord[4][6][3] = {
Expand Down Expand Up @@ -699,7 +710,7 @@ static void ShipController(Ship *v)

DiagDirection diagdir = DiagdirBetweenTiles(gp.old_tile, gp.new_tile);
assert(diagdir != INVALID_DIAGDIR);
tracks = GetAvailShipTracks(gp.new_tile, diagdir);
tracks = GetAvailShipTracks(gp.new_tile, diagdir, v->GetVehicleTrackdir());
if (tracks == TRACK_BIT_NONE) goto reverse_direction;

/* Choose a direction, and continue if we find one */
Expand Down

0 comments on commit 6ca637b

Please sign in to comment.