From d17ec934f55f5000cf30aa752437cc48cff19645 Mon Sep 17 00:00:00 2001 From: frosch Date: Sat, 18 Aug 2012 11:37:47 +0000 Subject: (svn r24481) -Feature [FS#5127]: Make the pathfinder decide whether ships shall leave depots towards north or south. --- src/pathfinder/npf/npf.cpp | 17 +++++++++++++++++ src/pathfinder/npf/npf_func.h | 7 +++++++ 2 files changed, 24 insertions(+) (limited to 'src/pathfinder/npf') diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp index 976767319..1b8d2f17f 100644 --- a/src/pathfinder/npf/npf.cpp +++ b/src/pathfinder/npf/npf.cpp @@ -1178,6 +1178,23 @@ Track NPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, return TrackdirToTrack(ftd.best_trackdir); } +bool NPFShipCheckReverse(const Ship *v) +{ + NPFFindStationOrTileData fstd; + NPFFoundTargetData ftd; + + NPFFillWithOrderData(&fstd, v); + + Trackdir trackdir = v->GetVehicleTrackdir(); + Trackdir trackdir_rev = ReverseTrackdir(trackdir); + assert(trackdir != INVALID_TRACKDIR); + assert(trackdir_rev != INVALID_TRACKDIR); + + ftd = NPFRouteToStationOrTileTwoWay(v->tile, trackdir, false, v->tile, trackdir_rev, false, &fstd, TRANSPORT_WATER, 0, v->owner, INVALID_RAILTYPES); + /* If we didn't find anything, just keep on going straight ahead, otherwise take the reverse flag */ + return ftd.best_bird_dist == 0 && NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE); +} + /*** Trains ***/ FindDepotData NPFTrainFindNearestDepot(const Train *v, int max_penalty) diff --git a/src/pathfinder/npf/npf_func.h b/src/pathfinder/npf/npf_func.h index f83c06f13..6507f4ec5 100644 --- a/src/pathfinder/npf/npf_func.h +++ b/src/pathfinder/npf/npf_func.h @@ -49,6 +49,13 @@ Trackdir NPFRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDir */ Track NPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found); +/** + * Returns true if it is better to reverse the ship before leaving depot using NPF. + * @param v the ship leaving the depot + * @return true if reversing is better + */ +bool NPFShipCheckReverse(const Ship *v); + /** * Used when user sends train to the nearest depot or if train needs servicing using NPF * @param v train that needs to go to some depot -- cgit v1.2.3-70-g09d2