From 8488abaf2fac9783d66264c776163936cc763c0e Mon Sep 17 00:00:00 2001 From: Juanjo Date: Tue, 23 Sep 2014 18:22:18 +0200 Subject: [PATCH] Add: Add IsStandard and IsExtendedRailDepotTile map functions. --- src/pathfinder/follow_track.hpp | 2 +- src/pathfinder/yapf/yapf_costrail.hpp | 5 ++- src/pbs.cpp | 8 ++--- src/rail_cmd.cpp | 1 + src/rail_map.h | 44 +++++++++++++++++++++++++++ src/train_cmd.cpp | 16 +++++++--- 6 files changed, 63 insertions(+), 13 deletions(-) diff --git a/src/pathfinder/follow_track.hpp b/src/pathfinder/follow_track.hpp index d384568b62..9a16bcba93 100644 --- a/src/pathfinder/follow_track.hpp +++ b/src/pathfinder/follow_track.hpp @@ -311,7 +311,7 @@ protected: return false; } } - if (IsRailTT() && IsDepotTypeTile(m_new_tile, TT())) { + if (IsRailTT() && IsStandardRailDepotTile(m_new_tile)) { DiagDirection exitdir = GetRailDepotDirection(m_new_tile); if (ReverseDiagDir(exitdir) != m_exitdir) { m_err = EC_NO_WAY; diff --git a/src/pathfinder/yapf/yapf_costrail.hpp b/src/pathfinder/yapf/yapf_costrail.hpp index f6217d2b24..d50bb24377 100644 --- a/src/pathfinder/yapf/yapf_costrail.hpp +++ b/src/pathfinder/yapf/yapf_costrail.hpp @@ -389,13 +389,12 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th /* Tests for 'potential target' reasons to close the segment. */ if (cur.tile == prev.tile) { /* Penalty for reversing in a depot. */ - assert(IsRailDepot(cur.tile)); + assert(IsStandardRailDepot(cur.tile)); segment_cost += Yapf().PfGetSettings().rail_depot_reverse_penalty; - } else if (IsRailDepotTile(cur.tile)) { + } else if (IsStandardRailDepotTile(cur.tile)) { /* We will end in this pass (depot is possible target) */ end_segment_reason |= ESRB_DEPOT; - } else if (cur.tile_type == MP_STATION && IsRailWaypoint(cur.tile)) { if (v->current_order.IsType(OT_GOTO_WAYPOINT) && GetStationIndex(cur.tile) == v->current_order.GetDestination() && diff --git a/src/pbs.cpp b/src/pbs.cpp index 363404330c..03b5311f89 100644 --- a/src/pbs.cpp +++ b/src/pbs.cpp @@ -240,7 +240,7 @@ static PBSTileInfo FollowReservation(Owner o, RailTypes rts, TileIndex tile, Tra if (tile == start_tile && trackdir == start_trackdir) break; } /* Depot tile? Can't continue. */ - if (IsRailDepotTile(tile)) break; + if (IsStandardRailDepotTile(tile)) break; /* Non-pbs signal? Reservation can't continue. */ if (IsTileType(tile, MP_RAILWAY) && HasSignalOnTrackdir(tile, trackdir) && !IsPbsSignal(GetSignalType(tile, TrackdirToTrack(trackdir)))) break; } @@ -292,7 +292,7 @@ PBSTileInfo FollowTrainReservation(const Train *v, Vehicle **train_on_res) TileIndex tile = v->tile; Trackdir trackdir = v->GetVehicleTrackdir(); - if (IsRailDepotTile(tile) && !GetDepotReservationTrackBits(tile)) return PBSTileInfo(tile, trackdir, false); + if (IsStandardRailDepotTile(tile) && !GetDepotReservationTrackBits(tile)) return PBSTileInfo(tile, trackdir, false); FindTrainOnTrackInfo ftoti; ftoti.res = FollowReservation(v->owner, GetRailTypeInfo(v->railtype)->compatible_railtypes, tile, trackdir); @@ -379,7 +379,7 @@ Train *GetTrainForReservation(TileIndex tile, Track track) */ bool IsSafeWaitingPosition(const Train *v, TileIndex tile, Trackdir trackdir, bool include_line_end, bool forbid_90deg) { - if (IsRailDepotTile(tile)) return true; + if (IsStandardRailDepotTile(tile)) return true; if (IsTileType(tile, MP_RAILWAY)) { /* For non-pbs signals, stop on the signal tile. */ @@ -432,7 +432,7 @@ bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bo if (TrackOverlapsTracks(reserved, track)) return false; /* Not reserved and depot or not a pbs signal -> free. */ - if (IsRailDepotTile(tile)) return true; + if (IsStandardRailDepotTile(tile)) return true; if (IsTileType(tile, MP_RAILWAY) && HasSignalOnTrackdir(tile, trackdir) && !IsPbsSignal(GetSignalType(tile, track))) return true; /* Check the next tile, if it's a PBS signal, it has to be free as well. */ diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 2e02d8eb24..b2840174a4 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -2960,6 +2960,7 @@ static const int8_t _deltacoord_leaveoffset[8] = { */ int TicksToLeaveDepot(const Train *v) { + assert(IsStandardRailDepotTile(v->tile)); DiagDirection dir = GetRailDepotDirection(v->tile); int length = v->CalcNextVehicleOffset(); diff --git a/src/rail_map.h b/src/rail_map.h index 03bca7e6e3..a715fc67fe 100644 --- a/src/rail_map.h +++ b/src/rail_map.h @@ -107,6 +107,50 @@ debug_inline static bool IsRailDepotTile(Tile t) return IsTileType(t, MP_RAILWAY) && IsRailDepot(t); } +/** + * Is this rail depot tile an extended depot? + * @param t the tile to get the information from + * @pre IsRailDepotTile(t) + * @return true if and only if the tile is an extended rail depot + */ +static inline bool IsExtendedRailDepot(Tile t) +{ + assert(IsRailDepotTile(t)); + return HasBit(t.m5(), 5); +} + +/** + * Is this rail tile a standard rail depot? + * @param t the tile to get the information from + * @pre IsTileType(t, MP_RAILWAY) + * @return true if and only if the tile is a standard rail depot + */ +static inline bool IsStandardRailDepot(Tile t) +{ + assert(IsTileType(t, MP_RAILWAY)); + return IsRailDepot(t) && !IsExtendedRailDepot(t); +} + +/** + * Is this tile a standard rail depot? + * @param t the tile to get the information from + * @return true if and only if the tile is a standard rail depot + */ +static inline bool IsStandardRailDepotTile(TileIndex t) +{ + return IsTileType(t, MP_RAILWAY) && IsStandardRailDepot(t); +} + +/** + * Is this tile rail tile and an extended rail depot? + * @param t the tile to get the information from + * @return true if and only if the tile is an extended rail depot + */ +static inline bool IsExtendedRailDepotTile(TileIndex t) +{ + return IsTileType(t, MP_RAILWAY) && IsRailDepotTile(t) && IsExtendedRailDepot(t); +} + /** * Gets the rail type of the given tile * @param t the tile to get the rail type from diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index a94fb911c0..8f8dc12eb9 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2181,7 +2181,7 @@ void ReverseTrainDirection(Train *v) !IsPbsSignal(GetSignalType(v->tile, FindFirstTrack(v->track)))); /* If we are on a depot tile facing outwards, do not treat the current tile as safe. */ - if (IsRailDepotTile(v->tile) && TrackdirToExitdir(v->GetVehicleTrackdir()) == GetRailDepotDirection(v->tile)) first_tile_okay = false; + if (IsStandardRailDepotTile(v->tile) && TrackdirToExitdir(v->GetVehicleTrackdir()) == GetRailDepotDirection(v->tile)) first_tile_okay = false; if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), true); if (TryPathReserve(v, false, first_tile_okay)) { @@ -2549,7 +2549,7 @@ void FreeTrainTrackReservation(const Train *v) StationID station_id = IsRailStationTile(v->tile) ? GetStationIndex(v->tile) : INVALID_STATION; /* Can't be holding a reservation if we enter a depot. */ - if (IsRailDepotTile(tile) && TrackdirToExitdir(td) != GetRailDepotDirection(tile)) return; + if (IsStandardRailDepotTile(tile) && TrackdirToExitdir(td) != GetRailDepotDirection(tile)) return; if (v->track == TRACK_BIT_DEPOT) { /* Front engine is in a depot. We enter if some part is not in the depot. */ for (const Train *u = v; u != nullptr; u = u->Next()) { @@ -3005,6 +3005,7 @@ bool TryPathReserve(Train *v, bool mark_as_stuck, bool first_tile_okay) if (mark_as_stuck) MarkTrainAsStuck(v); return false; } else { + assert(IsStandardRailDepotTile(v->tile)); /* Depot not reserved, but the next tile might be. */ TileIndex next_tile = TileAddByDiagDir(v->tile, GetRailDepotDirection(v->tile)); if (HasReservedTracks(next_tile, DiagdirReachesTracks(GetRailDepotDirection(v->tile)))) return false; @@ -3823,7 +3824,7 @@ static void DeleteLastWagon(Train *v) } /* Update signals */ - if (IsTileType(tile, MP_TUNNELBRIDGE) || IsRailDepotTile(tile)) { + if (IsTileType(tile, MP_TUNNELBRIDGE) || IsStandardRailDepotTile(tile)) { UpdateSignalsOnSegment(tile, INVALID_DIAGDIR, owner); } else { SetSignalsOnBothDir(tile, track, owner); @@ -3974,8 +3975,13 @@ static bool TrainCanLeaveTile(const Train *v) /* entering a depot? */ if (IsRailDepotTile(tile)) { - DiagDirection dir = ReverseDiagDir(GetRailDepotDirection(tile)); - if (DiagDirToDir(dir) == v->direction) return false; + if (IsExtendedRailDepot(tile)) { + Direction dir = DiagDirToDir(GetRailDepotDirection(tile)); + if (dir == v->direction || ReverseDir(dir) == v->direction) return false; + } else { + DiagDirection dir = ReverseDiagDir(GetRailDepotDirection(tile)); + if (DiagDirToDir(dir) == v->direction) return false; + } } return true;