mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-15 15:19:52 +00:00
Codechange: Deduplicate test for "block signal on trackdir" into a function. (#15526)
Co-authored-by: Michael Lutz <michi@icosahedron.de>
This commit is contained in:
committed by
GitHub
parent
a0ce1f94ed
commit
4a69cafe9a
+4
-6
@@ -254,7 +254,7 @@ static PBSTileInfo FollowReservation(Owner o, RailTypes rts, TileIndex tile, Tra
|
||||
/* Depot tile? Can't continue. */
|
||||
if (IsRailDepotTile(tile)) break;
|
||||
/* Non-pbs signal? Reservation can't continue. */
|
||||
if (IsTileType(tile, TileType::Railway) && HasSignalOnTrackdir(tile, trackdir) && !IsPbsSignal(GetSignalType(tile, TrackdirToTrack(trackdir)))) break;
|
||||
if (HasBlockSignalOnTrackdir(tile, trackdir)) break;
|
||||
}
|
||||
|
||||
return PBSTileInfo(tile, trackdir, false);
|
||||
@@ -396,10 +396,8 @@ bool IsSafeWaitingPosition(const Train *v, TileIndex tile, Trackdir trackdir, bo
|
||||
{
|
||||
if (IsRailDepotTile(tile)) return true;
|
||||
|
||||
if (IsTileType(tile, TileType::Railway)) {
|
||||
/* For non-pbs signals, stop on the signal tile. */
|
||||
if (HasSignalOnTrackdir(tile, trackdir) && !IsPbsSignal(GetSignalType(tile, TrackdirToTrack(trackdir)))) return true;
|
||||
}
|
||||
/* For non-pbs signals, stop on the signal tile. */
|
||||
if (HasBlockSignalOnTrackdir(tile, trackdir)) return true;
|
||||
|
||||
/* Check next tile. For performance reasons, we check for 90 degree turns ourself. */
|
||||
CFollowTrackRail ft(v, GetAllCompatibleRailTypes(v->railtypes));
|
||||
@@ -448,7 +446,7 @@ bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bo
|
||||
|
||||
/* Not reserved and depot or not a pbs signal -> free. */
|
||||
if (IsRailDepotTile(tile)) return true;
|
||||
if (IsTileType(tile, TileType::Railway) && HasSignalOnTrackdir(tile, trackdir) && !IsPbsSignal(GetSignalType(tile, track))) return true;
|
||||
if (HasBlockSignalOnTrackdir(tile, trackdir)) return true;
|
||||
|
||||
/* Check the next tile, it has to be free as well. Do not filter for compatible railtypes
|
||||
* to make sure we never accidentally join up reservations. */
|
||||
|
||||
@@ -551,6 +551,17 @@ inline bool HasOnewaySignalBlockingTrackdir(Tile tile, Trackdir td)
|
||||
!HasSignalOnTrackdir(tile, td) && IsOnewaySignal(tile, TrackdirToTrack(td));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a block signal is present along the trackdir.
|
||||
* @param tile The tile to check.
|
||||
* @param td The trackdir to check.
|
||||
* @return \c true iff a block signal present along the trackdir.
|
||||
*/
|
||||
inline bool HasBlockSignalOnTrackdir(Tile tile, Trackdir td)
|
||||
{
|
||||
return IsTileType(tile, TileType::Railway) && HasSignalOnTrackdir(tile, td) &&
|
||||
!IsPbsSignal(GetSignalType(tile, TrackdirToTrack(td)));
|
||||
}
|
||||
|
||||
RailType GetTileRailType(Tile tile);
|
||||
|
||||
|
||||
+2
-6
@@ -2091,9 +2091,7 @@ static void ReverseTrainDirection(Train *consist)
|
||||
if (UpdateSignalsOnSegment(moving_front->tile, dir, consist->owner) == SIGSEG_PBS || _settings_game.pf.reserve_paths) {
|
||||
/* If we are currently on a tile with conventional signals, we can't treat the
|
||||
* current tile as a safe tile or we would enter a PBS block without a reservation. */
|
||||
bool first_tile_okay = !(IsTileType(moving_front->tile, TileType::Railway) &&
|
||||
HasSignalOnTrackdir(moving_front->tile, moving_front->GetVehicleTrackdir()) &&
|
||||
!IsPbsSignal(GetSignalType(moving_front->tile, FindFirstTrack(moving_front->track))));
|
||||
bool first_tile_okay = !HasBlockSignalOnTrackdir(moving_front->tile, moving_front->GetVehicleTrackdir());
|
||||
|
||||
/* If we are on a depot tile facing outwards, do not treat the current tile as safe. */
|
||||
if (IsRailDepotTile(moving_front->tile) && TrackdirToExitdir(moving_front->GetVehicleTrackdir()) == GetRailDepotDirection(moving_front->tile)) first_tile_okay = false;
|
||||
@@ -2314,9 +2312,7 @@ static void CheckNextTrainTile(Train *consist)
|
||||
Trackdir td = moving_front->GetVehicleTrackdir();
|
||||
|
||||
/* On a tile with a red non-pbs signal, don't look ahead. */
|
||||
if (IsTileType(moving_front->tile, TileType::Railway) && HasSignalOnTrackdir(moving_front->tile, td) &&
|
||||
!IsPbsSignal(GetSignalType(moving_front->tile, TrackdirToTrack(td))) &&
|
||||
GetSignalStateByTrackdir(moving_front->tile, td) == SIGNAL_STATE_RED) return;
|
||||
if (HasBlockSignalOnTrackdir(moving_front->tile, td) && GetSignalStateByTrackdir(moving_front->tile, td) == SIGNAL_STATE_RED) return;
|
||||
|
||||
CFollowTrackRail ft(consist);
|
||||
if (!ft.Follow(moving_front->tile, td)) return;
|
||||
|
||||
Reference in New Issue
Block a user