Changeset - r27233:ee72fbff3328
[Not reviewed]
master
0 1 0
Jonathan G Rennison - 16 months ago 2023-05-04 20:45:13
j.g.rennison@gmail.com
Fix #10741: Rail platforms left partially reserved after train crash (#10751)
1 file changed with 21 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/train_cmd.cpp
Show inline comments
 
@@ -3550,6 +3550,20 @@ static Vehicle *CollectTrackbitsFromCras
 
	return nullptr;
 
}
 

	
 
static bool IsRailStationPlatformOccupied(TileIndex tile)
 
{
 
	TileIndexDiff delta = (GetRailStationAxis(tile) == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
 

	
 
	for (TileIndex t = tile; IsCompatibleTrainStationTile(t, tile); t -= delta) {
 
		if (HasVehicleOnPos(t, nullptr, &TrainOnTileEnum)) return true;
 
	}
 
	for (TileIndex t = tile + delta; IsCompatibleTrainStationTile(t, tile); t += delta) {
 
		if (HasVehicleOnPos(t, nullptr, &TrainOnTileEnum)) return true;
 
	}
 

	
 
	return false;
 
}
 

	
 
/**
 
 * Deletes/Clears the last wagon of a crashed train. It takes the engine of the
 
 * train, then goes to the last wagon and deletes that. Each call to this function
 
@@ -3608,6 +3622,13 @@ static void DeleteLastWagon(Train *v)
 
	/* check if the wagon was on a road/rail-crossing */
 
	if (IsLevelCrossingTile(tile)) UpdateLevelCrossing(tile);
 

	
 
	if (IsRailStationTile(tile)) {
 
		bool occupied = IsRailStationPlatformOccupied(tile);
 
		DiagDirection dir = AxisToDiagDir(GetRailStationAxis(tile));
 
		SetRailStationPlatformReservation(tile, dir, occupied);
 
		SetRailStationPlatformReservation(tile, ReverseDiagDir(dir), occupied);
 
	}
 

	
 
	/* Update signals */
 
	if (IsTileType(tile, MP_TUNNELBRIDGE) || IsRailDepotTile(tile)) {
 
		UpdateSignalsOnSegment(tile, INVALID_DIAGDIR, owner);
0 comments (0 inline, 0 general)