* 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. */
| 2376 | * @param track_dir Track direction to clear. |
| 2377 | */ |
| 2378 | static 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. |
no test coverage detected