Mercurial > hg > openttd
changeset 9899:dd90dcb4082f draft
(svn r14048) -Fix (r14019) [FS#2222]: Redo the check for reserved tracks properly this time. (michi_cc)
author | rubidium <rubidium@openttd.org> |
---|---|
date | Mon, 11 Aug 2008 22:58:30 +0000 |
parents | ffa87f0a2f8b |
children | 8ac644b5a2ef |
files | src/yapf/follow_track.hpp src/yapf/yapf_costrail.hpp src/yapf/yapf_node_rail.hpp src/yapf/yapf_rail.cpp |
diffstat | 4 files changed, 34 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/src/yapf/follow_track.hpp +++ b/src/yapf/follow_track.hpp @@ -14,8 +14,6 @@ template <TransportType Ttr_type_, bool T90deg_turns_allowed_ = true, bool Tmask_reserved_tracks = false> struct CFollowTrackT { - typedef CFollowTrackT<Ttr_type_, T90deg_turns_allowed_, false> BaseNoMask; - enum ErrorCode { EC_NONE, EC_OWNER, @@ -79,7 +77,7 @@ FORCEINLINE bool IsTram() {return IsRoadTT() && HasBit(m_veh->u.road.compatible_roadtypes, ROADTYPE_TRAM);} FORCEINLINE static bool IsRoadTT() {return TT() == TRANSPORT_ROAD;} FORCEINLINE static bool Allow90degTurns() {return T90deg_turns_allowed_;} - FORCEINLINE static bool MaskReservedTracks() {return IsRailTT() && Tmask_reserved_tracks;} + FORCEINLINE static bool DoTrackMasking() {return IsRailTT() && Tmask_reserved_tracks;} /** Tests if a tile is a road tile with a single tramtrack (tram can reverse) */ FORCEINLINE DiagDirection GetSingleTramBit(TileIndex tile) @@ -124,32 +122,37 @@ return false; } } - if (MaskReservedTracks()) { - if (m_is_station) { - /* Check skipped station tiles as well. */ - TileIndexDiff diff = TileOffsByDiagDir(m_exitdir); - for (TileIndex tile = m_new_tile - diff * m_tiles_skipped; tile != m_new_tile; tile += diff) { - if (GetRailwayStationReservation(tile)) { - m_new_td_bits = TRACKDIR_BIT_NONE; - m_err = EC_RESERVED; - return false; - } + return true; + } + + inline bool MaskReservedTracks() + { + if (!DoTrackMasking()) return true; + + if (m_is_station) { + /* Check skipped station tiles as well. */ + TileIndexDiff diff = TileOffsByDiagDir(m_exitdir); + for (TileIndex tile = m_new_tile - diff * m_tiles_skipped; tile != m_new_tile; tile += diff) { + if (GetRailwayStationReservation(tile)) { + m_new_td_bits = TRACKDIR_BIT_NONE; + m_err = EC_RESERVED; + return false; } } + } - TrackBits reserved = GetReservedTrackbits(m_new_tile); - /* Mask already reserved trackdirs. */ - m_new_td_bits &= ~TrackBitsToTrackdirBits(reserved); - /* Mask out all trackdirs that conflict with the reservation. */ - uint bits = (uint)TrackdirBitsToTrackBits(m_new_td_bits); - int i; - FOR_EACH_SET_BIT(i, bits) { - if (TracksOverlap(reserved | TrackToTrackBits((Track)i))) m_new_td_bits &= ~TrackToTrackdirBits((Track)i); - } - if (m_new_td_bits == TRACKDIR_BIT_NONE) { - m_err = EC_RESERVED; - return false; - } + TrackBits reserved = GetReservedTrackbits(m_new_tile); + /* Mask already reserved trackdirs. */ + m_new_td_bits &= ~TrackBitsToTrackdirBits(reserved); + /* Mask out all trackdirs that conflict with the reservation. */ + uint bits = (uint)TrackdirBitsToTrackBits(m_new_td_bits); + int i; + FOR_EACH_SET_BIT(i, bits) { + if (TracksOverlap(reserved | TrackToTrackBits((Track)i))) m_new_td_bits &= ~TrackToTrackdirBits((Track)i); + } + if (m_new_td_bits == TRACKDIR_BIT_NONE) { + m_err = EC_RESERVED; + return false; } return true; }
--- a/src/yapf/yapf_costrail.hpp +++ b/src/yapf/yapf_costrail.hpp @@ -399,7 +399,7 @@ } else if (cur.tile_type == MP_RAILWAY && IsRailWaypoint(cur.tile)) { /* Waypoint is also a good reason to finish. */ end_segment_reason |= ESRB_WAYPOINT; - } else if (TrackFollower::MaskReservedTracks() && cur.tile_type == MP_RAILWAY) { + } else if (TrackFollower::DoTrackMasking() && cur.tile_type == MP_RAILWAY) { /* Searching for a safe tile? */ if (HasSignalOnTrackdir(cur.tile, cur.td) && !IsPbsSignal(GetSignalType(cur.tile, TrackdirToTrack(cur.td)))) { end_segment_reason |= ESRB_SAFE_TILE; @@ -437,7 +437,7 @@ end_segment_reason |= ESRB_DEAD_END; } - if (TrackFollower::MaskReservedTracks() && tf_local.m_err != TrackFollower::EC_90DEG) { + if (TrackFollower::DoTrackMasking() && tf_local.m_err != TrackFollower::EC_90DEG) { if (!HasOnewaySignalBlockingTrackdir(cur.tile, cur.td)) end_segment_reason |= ESRB_SAFE_TILE; } break; @@ -453,7 +453,7 @@ /* Gather the next tile/trackdir/tile_type/rail_type. */ TILE next(tf_local.m_new_tile, (Trackdir)FindFirstBit2x64(tf_local.m_new_td_bits)); - if (TrackFollower::MaskReservedTracks() && HasPbsSignalOnTrackdir(next.tile, next.td)) { + if (TrackFollower::DoTrackMasking() && HasPbsSignalOnTrackdir(next.tile, next.td)) { /* Possible safe tile. */ end_segment_reason |= ESRB_SAFE_TILE; }
--- a/src/yapf/yapf_node_rail.hpp +++ b/src/yapf/yapf_node_rail.hpp @@ -182,8 +182,7 @@ template <class Tbase, class Tfunc, class Tpf> bool IterateTiles(const Vehicle *v, Tpf &yapf, Tbase &obj, bool (Tfunc::*func)(TileIndex, Trackdir)) const { - typedef typename Tbase::TrackFollower TrackFollower; - typename TrackFollower::BaseNoMask ft(v, yapf.GetCompatibleRailTypes()); + typename Tbase::TrackFollower ft(v, yapf.GetCompatibleRailTypes()); TileIndex cur = base::GetTile(); Trackdir cur_td = base::GetTrackdir();
--- a/src/yapf/yapf_rail.cpp +++ b/src/yapf/yapf_rail.cpp @@ -223,7 +223,7 @@ inline void PfFollowNode(Node& old_node) { TrackFollower F(Yapf().GetVehicle(), Yapf().GetCompatibleRailTypes()); - if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) + if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir()) && F.MaskReservedTracks()) Yapf().AddMultipleNodes(&old_node, F); }