MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ClearPathReservation

Function ClearPathReservation

src/train_cmd.cpp:2378–2413  ·  view source on GitHub ↗

* Clear the reservation of \a tile that was just left by a wagon on \a track_dir. * @param v %Train owning the reservation. * @param tile Tile with reservation to clear. * @param track_dir Track direction to clear. */

Source from the content-addressed store, hash-verified

2376 * @param track_dir Track direction to clear.
2377 */
2378static void ClearPathReservation(const Train *v, TileIndex tile, Trackdir track_dir)
2379{
2380 DiagDirection dir = TrackdirToExitdir(track_dir);
2381
2382 if (IsTileType(tile, MP_TUNNELBRIDGE)) {
2383 /* Are we just leaving a tunnel/bridge? */
2384 if (GetTunnelBridgeDirection(tile) == ReverseDiagDir(dir)) {
2385 TileIndex end = GetOtherTunnelBridgeEnd(tile);
2386
2387 if (TunnelBridgeIsFree(tile, end, v).Succeeded()) {
2388 /* Free the reservation only if no other train is on the tiles. */
2389 SetTunnelBridgeReservation(tile, false);
2390 SetTunnelBridgeReservation(end, false);
2391
2392 if (_settings_client.gui.show_track_reservation) {
2393 if (IsBridge(tile)) {
2394 MarkBridgeDirty(tile);
2395 } else {
2396 MarkTileDirtyByTile(tile);
2397 MarkTileDirtyByTile(end);
2398 }
2399 }
2400 }
2401 }
2402 } else if (IsRailStationTile(tile)) {
2403 TileIndex new_tile = TileAddByDiagDir(tile, dir);
2404 /* If the new tile is not a further tile of the same station, we
2405 * clear the reservation for the whole platform. */
2406 if (!IsCompatibleTrainStationTile(new_tile, tile)) {
2407 SetRailStationPlatformReservation(tile, ReverseDiagDir(dir), false);
2408 }
2409 } else {
2410 /* Any other tile */
2411 UnreserveRailTrack(tile, TrackdirToTrack(track_dir));
2412 }
2413}
2414
2415/**
2416 * Free the reserved path in front of a vehicle.

Callers 3

CrashMethod · 0.85
TrainControllerFunction · 0.85

Calls 15

TrackdirToExitdirFunction · 0.85
IsTileTypeFunction · 0.85
GetTunnelBridgeDirectionFunction · 0.85
ReverseDiagDirFunction · 0.85
GetOtherTunnelBridgeEndFunction · 0.85
TunnelBridgeIsFreeFunction · 0.85
IsBridgeFunction · 0.85
MarkBridgeDirtyFunction · 0.85
IsRailStationTileFunction · 0.85
TileAddByDiagDirFunction · 0.85

Tested by

no test coverage detected