Mercurial > hg > openttd
changeset 13847:701d8d247a50 draft
(svn r18376) -Codechange: simplify setting the destination
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 02 Dec 2009 14:44:32 +0000 |
parents | 8f65fa432770 |
children | a47ef53cafb4 |
files | src/pathfinder/yapf/yapf_road.cpp |
diffstat | 1 files changed, 7 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/pathfinder/yapf/yapf_road.cpp +++ b/src/pathfinder/yapf/yapf_road.cpp @@ -271,10 +271,10 @@ TrackdirBits m_destTrackdirs; public: - void SetDestination(TileIndex tile, TrackdirBits trackdirs) + void SetDestination(const RoadVehicle *v) { - m_destTile = tile; - m_destTrackdirs = trackdirs; + m_destTile = v->dest_tile; + m_destTrackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_ROAD, v->compatible_roadtypes)); } protected: @@ -288,8 +288,7 @@ /** Called by YAPF to detect if node ends in the desired destination */ FORCEINLINE bool PfDetectDestination(Node& n) { - bool bDest = (n.m_segment_last_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.m_segment_last_td)) != TRACKDIR_BIT_NONE); - return bDest; + return PfDetectDestinationTile(n.m_segment_last_tile, n.m_segment_last_td); } FORCEINLINE bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir) @@ -382,13 +381,9 @@ /* select reachable trackdirs only */ src_trackdirs &= DiagdirReachesTrackdirs(enterdir); - /* get available trackdirs on the destination tile */ - TileIndex dest_tile = v->dest_tile; - TrackdirBits dest_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(dest_tile, TRANSPORT_ROAD, v->compatible_roadtypes)); - /* set origin and destination nodes */ Yapf().SetOrigin(src_tile, src_trackdirs); - Yapf().SetDestination(dest_tile, dest_trackdirs); + Yapf().SetDestination(v); /* find the best path */ Yapf().FindPath(v); @@ -426,10 +421,8 @@ if (!SetOriginFromVehiclePos(v)) return UINT_MAX; - /* set destination tile, trackdir - * get available trackdirs on the destination tile */ - TrackdirBits dst_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(dst_tile, TRANSPORT_ROAD, v->compatible_roadtypes)); - Yapf().SetDestination(dst_tile, dst_td_bits); + /* get available trackdirs on the destination tile */ + Yapf().SetDestination(v); /* if path not found - return distance = UINT_MAX */ uint dist = UINT_MAX;