(svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
KUDr 19 years ago
parent f2f4ca1dc4
commit ace071529e

@ -45,10 +45,10 @@ struct CFollowTrackT : public FollowTrack_t
m_old_td = old_td; m_old_td = old_td;
assert((GetTileTrackStatus(m_old_tile, TT()) & TrackdirToTrackdirBits(m_old_td)) != 0); assert((GetTileTrackStatus(m_old_tile, TT()) & TrackdirToTrackdirBits(m_old_td)) != 0);
m_exitdir = TrackdirToExitdir(m_old_td); m_exitdir = TrackdirToExitdir(m_old_td);
if (EnteredRailDepot()) return true; if (EnteredDepot()) return true;
if (!CanExitOldTile()) return false; if (!CanExitOldTile()) return false;
FollowTileExit(); FollowTileExit();
if (!QueryNewTileTrackStatus()) return false; if (!QueryNewTileTrackStatus()) return TryReverse();
if (!CanEnterNewTile()) return false; if (!CanEnterNewTile()) return false;
m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir); m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir);
if (!Allow90degTurns()) if (!Allow90degTurns())
@ -198,23 +198,44 @@ protected:
return true; return true;
} }
FORCEINLINE bool EnteredRailDepot() /** return true if we entered depot and reversed inside */
FORCEINLINE bool EnteredDepot()
{ {
// rail depots cause reversing // rail and road depots cause reversing
if (IsRailTT() && IsTileDepotType(m_old_tile, TT())) { if (!IsWaterTT() && IsTileDepotType(m_old_tile, TT())) {
DiagDirection exitdir = GetRailDepotDirection(m_old_tile); DiagDirection exitdir = IsRailTT() ? GetRailDepotDirection(m_old_tile) : GetRoadDepotDirection(m_old_tile);
if (exitdir != m_exitdir) { if (exitdir != m_exitdir) {
// reverse // reverse
m_new_tile = m_old_tile; m_new_tile = m_old_tile;
m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td)); m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td));
m_exitdir = exitdir; m_exitdir = exitdir;
m_tiles_skipped = 0; m_tiles_skipped = 0;
m_is_tunnel = false; m_is_tunnel = m_is_bridge = m_is_station = false;
return true; return true;
} }
} }
return false; 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: public:
/** Helper for pathfinders - get min/max speed on the m_old_tile/m_old_td */ /** Helper for pathfinders - get min/max speed on the m_old_tile/m_old_td */
int GetSpeedLimit(int *pmin_speed = NULL) int GetSpeedLimit(int *pmin_speed = NULL)

@ -76,7 +76,13 @@ public:
// base tile cost depending on distance between edges // base tile cost depending on distance between edges
segment_cost += Yapf().OneTileCost(tile, trackdir); 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; TrackFollower F;
if (!F.Follow(tile, trackdir)) break; if (!F.Follow(tile, trackdir)) break;

Loading…
Cancel
Save