@ -1142,6 +1142,30 @@ CommandCost FindJoiningWaypoint(StationID existing_waypoint, StationID waypoint_
return FindJoiningBaseStation < Waypoint , STR_ERROR_MUST_REMOVE_RAILWAYPOINT_FIRST > ( existing_waypoint , waypoint_to_join , adjacent , ta , wp ) ;
}
/**
* Clear platform reservation during station building / removing .
* @ param v vehicle which holds reservation
*/
static void FreeTrainReservation ( Train * v )
{
FreeTrainTrackReservation ( v ) ;
if ( IsRailStationTile ( v - > tile ) ) SetRailStationPlatformReservation ( v - > tile , TrackdirToExitdir ( v - > GetVehicleTrackdir ( ) ) , false ) ;
v = v - > Last ( ) ;
if ( IsRailStationTile ( v - > tile ) ) SetRailStationPlatformReservation ( v - > tile , TrackdirToExitdir ( ReverseTrackdir ( v - > GetVehicleTrackdir ( ) ) ) , false ) ;
}
/**
* Restore platform reservation during station building / removing .
* @ param v vehicle which held reservation
*/
static void RestoreTrainReservation ( Train * v )
{
if ( IsRailStationTile ( v - > tile ) ) SetRailStationPlatformReservation ( v - > tile , TrackdirToExitdir ( v - > GetVehicleTrackdir ( ) ) , true ) ;
TryPathReserve ( v , true , true ) ;
v = v - > Last ( ) ;
if ( IsRailStationTile ( v - > tile ) ) SetRailStationPlatformReservation ( v - > tile , TrackdirToExitdir ( ReverseTrackdir ( v - > GetVehicleTrackdir ( ) ) ) , true ) ;
}
/**
* Build rail station
* @ param tile_org northern most position of station dragging / placement
@ -1281,11 +1305,8 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
/* Check for trains having a reservation for this tile. */
Train * v = GetTrainForReservation ( tile , AxisToTrack ( GetRailStationAxis ( tile ) ) ) ;
if ( v ! = NULL ) {
FreeTrainTrackReservation ( v ) ;
* affected_vehicles . Append ( ) = v ;
if ( IsRailStationTile ( v - > tile ) ) SetRailStationPlatformReservation ( v - > tile , TrackdirToExitdir ( v - > GetVehicleTrackdir ( ) ) , false ) ;
for ( ; v - > Next ( ) ! = NULL ; v = v - > Next ( ) ) { }
if ( IsRailStationTile ( v - > tile ) ) SetRailStationPlatformReservation ( v - > tile , TrackdirToExitdir ( ReverseTrackdir ( v - > GetVehicleTrackdir ( ) ) ) , false ) ;
FreeTrainReservation ( v ) ;
}
}
@ -1336,11 +1357,7 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
for ( uint i = 0 ; i < affected_vehicles . Length ( ) ; + + i ) {
/* Restore reservations of trains. */
Train * v = affected_vehicles [ i ] ;
if ( IsRailStationTile ( v - > tile ) ) SetRailStationPlatformReservation ( v - > tile , TrackdirToExitdir ( v - > GetVehicleTrackdir ( ) ) , true ) ;
TryPathReserve ( v , true , true ) ;
for ( ; v - > Next ( ) ! = NULL ; v = v - > Next ( ) ) { }
if ( IsRailStationTile ( v - > tile ) ) SetRailStationPlatformReservation ( v - > tile , TrackdirToExitdir ( ReverseTrackdir ( v - > GetVehicleTrackdir ( ) ) ) , true ) ;
RestoreTrainReservation ( affected_vehicles [ i ] ) ;
}
/* Check whether we need to expand the reservation of trains already on the station. */
@ -1504,14 +1521,7 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, SmallVector<T *, 4> &affected
if ( HasStationReservation ( tile ) ) {
v = GetTrainForReservation ( tile , track ) ;
if ( v ! = NULL ) {
/* Free train reservation. */
FreeTrainTrackReservation ( v ) ;
if ( IsRailStationTile ( v - > tile ) ) SetRailStationPlatformReservation ( v - > tile , TrackdirToExitdir ( v - > GetVehicleTrackdir ( ) ) , false ) ;
Vehicle * temp = v ;
for ( ; temp - > Next ( ) ! = NULL ; temp = temp - > Next ( ) ) { }
if ( IsRailStationTile ( temp - > tile ) ) SetRailStationPlatformReservation ( temp - > tile , TrackdirToExitdir ( ReverseTrackdir ( temp - > GetVehicleTrackdir ( ) ) ) , false ) ;
}
if ( v ! = NULL ) FreeTrainReservation ( v ) ;
}
bool build_rail = keep_rail & & ! IsStationTileBlocked ( tile ) ;
@ -1531,13 +1541,7 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, SmallVector<T *, 4> &affected
affected_stations . Include ( st ) ;
if ( v ! = NULL ) {
/* Restore station reservation. */
if ( IsRailStationTile ( v - > tile ) ) SetRailStationPlatformReservation ( v - > tile , TrackdirToExitdir ( v - > GetVehicleTrackdir ( ) ) , true ) ;
TryPathReserve ( v , true , true ) ;
for ( ; v - > Next ( ) ! = NULL ; v = v - > Next ( ) ) { }
if ( IsRailStationTile ( v - > tile ) ) SetRailStationPlatformReservation ( v - > tile , TrackdirToExitdir ( ReverseTrackdir ( v - > GetVehicleTrackdir ( ) ) ) , true ) ;
}
if ( v ! = NULL ) RestoreTrainReservation ( v ) ;
}
}