diff options
author | KUDr <KUDr@openttd.org> | 2006-06-07 18:41:58 +0000 |
---|---|---|
committer | KUDr <KUDr@openttd.org> | 2006-06-07 18:41:58 +0000 |
commit | 8992f9cb2bf20a1615f99735d13ade6b2535cbcf (patch) | |
tree | 886f4442bbecca8e23f40e5353b6ac5f72de7778 /yapf | |
parent | b1ef3b117eb04f1dd7675f4a796f390aedfadba9 (diff) | |
download | openttd-8992f9cb2bf20a1615f99735d13ade6b2535cbcf.tar.xz |
(svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
Diffstat (limited to 'yapf')
-rw-r--r-- | yapf/follow_track.hpp | 35 | ||||
-rw-r--r-- | yapf/yapf_road.cpp | 8 |
2 files changed, 35 insertions, 8 deletions
diff --git a/yapf/follow_track.hpp b/yapf/follow_track.hpp index 394130932..8cc5f7451 100644 --- a/yapf/follow_track.hpp +++ b/yapf/follow_track.hpp @@ -45,10 +45,10 @@ struct CFollowTrackT : public FollowTrack_t m_old_td = old_td; assert((GetTileTrackStatus(m_old_tile, TT()) & TrackdirToTrackdirBits(m_old_td)) != 0); m_exitdir = TrackdirToExitdir(m_old_td); - if (EnteredRailDepot()) return true; + if (EnteredDepot()) return true; if (!CanExitOldTile()) return false; FollowTileExit(); - if (!QueryNewTileTrackStatus()) return false; + if (!QueryNewTileTrackStatus()) return TryReverse(); if (!CanEnterNewTile()) return false; m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir); if (!Allow90degTurns()) @@ -198,23 +198,44 @@ protected: return true; } - FORCEINLINE bool EnteredRailDepot() + /** return true if we entered depot and reversed inside */ + FORCEINLINE bool EnteredDepot() { - // rail depots cause reversing - if (IsRailTT() && IsTileDepotType(m_old_tile, TT())) { - DiagDirection exitdir = GetRailDepotDirection(m_old_tile); + // rail and road depots cause reversing + if (!IsWaterTT() && IsTileDepotType(m_old_tile, TT())) { + DiagDirection exitdir = IsRailTT() ? GetRailDepotDirection(m_old_tile) : GetRoadDepotDirection(m_old_tile); if (exitdir != m_exitdir) { // reverse m_new_tile = m_old_tile; m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td)); m_exitdir = exitdir; m_tiles_skipped = 0; - m_is_tunnel = false; + m_is_tunnel = m_is_bridge = m_is_station = false; return true; } } return false; } + + /** return true if we successfully reversed at end of road/track */ + FORCEINLINE bool TryReverse() + { + if (IsRoadTT()) { + // if we reached the end of road, we can reverse the RV and continue moving + m_exitdir = ReverseDiagDir(m_exitdir); + // new tile will be the same as old one + m_new_tile = m_old_tile; + // set new trackdir bits to all reachable trackdirs + QueryNewTileTrackStatus(); + m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir); + if (m_new_td_bits != TRACKDIR_BIT_NONE) { + // we have some trackdirs reachable after reversal + return true; + } + } + return false; + } + public: /** Helper for pathfinders - get min/max speed on the m_old_tile/m_old_td */ int GetSpeedLimit(int *pmin_speed = NULL) diff --git a/yapf/yapf_road.cpp b/yapf/yapf_road.cpp index 6fbff3ecb..d0a06c0f4 100644 --- a/yapf/yapf_road.cpp +++ b/yapf/yapf_road.cpp @@ -76,7 +76,13 @@ public: // base tile cost depending on distance between edges segment_cost += Yapf().OneTileCost(tile, trackdir); - // if there are no reachable trackdirs n new tile, we have end of road + // stop if we have just entered the depot + if (IsTileDepotType(tile, TRANSPORT_ROAD) && trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) { + // next time we will reverse and leave the depot + break; + } + + // if there are no reachable trackdirs on new tile, we have end of road TrackFollower F; if (!F.Follow(tile, trackdir)) break; |