summaryrefslogtreecommitdiff
path: root/src/ship_cmd.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-08-18 11:37:47 +0000
committerfrosch <frosch@openttd.org>2012-08-18 11:37:47 +0000
commitd17ec934f55f5000cf30aa752437cc48cff19645 (patch)
tree68d5895b8ad40d12189102617bc8a15a0db3a3f6 /src/ship_cmd.cpp
parent0f0f027379181bf35b3e0b9ae6900cd3b0d82574 (diff)
downloadopenttd-d17ec934f55f5000cf30aa752437cc48cff19645.tar.xz
(svn r24481) -Feature [FS#5127]: Make the pathfinder decide whether ships shall leave depots towards north or south.
Diffstat (limited to 'src/ship_cmd.cpp')
-rw-r--r--src/ship_cmd.cpp33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 06a4b7390..ae2c819db 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -310,13 +310,34 @@ static bool CheckShipLeaveDepot(Ship *v)
TileIndex tile = v->tile;
Axis axis = GetShipDepotAxis(tile);
- /* Check first (north) side */
- if (DiagdirReachesTracks((DiagDirection)axis) & GetTileShipTrackStatus(TILE_ADD(tile, ToTileIndexDiff(_ship_leave_depot_offs[axis])))) {
- v->direction = ReverseDir(AxisToDirection(axis));
- /* Check second (south) side */
- } else if (DiagdirReachesTracks((DiagDirection)(axis + 2)) & GetTileShipTrackStatus(TILE_ADD(tile, -2 * ToTileIndexDiff(_ship_leave_depot_offs[axis])))) {
- v->direction = AxisToDirection(axis);
+ DiagDirection north_dir = ReverseDiagDir(AxisToDiagDir(axis));
+ TileIndex north_neighbour = TILE_ADD(tile, ToTileIndexDiff(_ship_leave_depot_offs[axis]));
+ DiagDirection south_dir = AxisToDiagDir(axis);
+ TileIndex south_neighbour = TILE_ADD(tile, -2 * ToTileIndexDiff(_ship_leave_depot_offs[axis]));
+
+ TrackBits north_tracks = DiagdirReachesTracks(north_dir) & GetTileShipTrackStatus(north_neighbour);
+ TrackBits south_tracks = DiagdirReachesTracks(south_dir) & GetTileShipTrackStatus(south_neighbour);
+ if (north_tracks && south_tracks) {
+ /* Ask pathfinder for best direction */
+ bool reverse = false;
+ bool path_found;
+ switch (_settings_game.pf.pathfinder_for_ships) {
+ case VPF_OPF: reverse = OPFShipChooseTrack(v, north_neighbour, north_dir, north_tracks, path_found) == INVALID_TRACK; break; // OPF always allows reversing
+ case VPF_NPF: reverse = NPFShipCheckReverse(v); break;
+ case VPF_YAPF: reverse = YapfShipCheckReverse(v); break;
+ default: NOT_REACHED();
+ }
+ if (reverse) north_tracks = TRACK_BIT_NONE;
+ }
+
+ if (north_tracks) {
+ /* Leave towards north */
+ v->direction = DiagDirToDir(north_dir);
+ } else if (south_tracks) {
+ /* Leave towards south */
+ v->direction = DiagDirToDir(south_dir);
} else {
+ /* Both ways blocked */
return false;
}