diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -418,7 +418,7 @@ CommandCost CmdBuildSingleRail(TileIndex if (flags & DC_EXEC) { MarkTileDirtyByTile(tile); - SetSignalsOnBothDir(tile, track); + SetSignalsOnBothDir(tile, track, _current_player); YapfNotifyTrackLayoutChange(tile, track); } @@ -441,6 +441,10 @@ CommandCost CmdRemoveSingleRail(TileInde if (!ValParamTrackOrientation((Track)p2)) return CMD_ERROR; trackbit = TrackToTrackBits(track); + /* Need to read tile owner now because it may change when the rail is removed. + * Also, in case of floods, _current_player != owner */ + Owner owner = GetTileOwner(tile); + switch (GetTileType(tile)) { case MP_ROAD: { if (!IsLevelCrossing(tile) || @@ -498,12 +502,12 @@ CommandCost CmdRemoveSingleRail(TileInde * are removing one of these pieces, we'll need to update signals for * both directions explicitly, as after the track is removed it won't * 'connect' with the other piece. */ - SetSignalsOnBothDir(tile, TRACK_X); - SetSignalsOnBothDir(tile, TRACK_Y); + SetSignalsOnBothDir(tile, TRACK_X, owner); + SetSignalsOnBothDir(tile, TRACK_Y, owner); YapfNotifyTrackLayoutChange(tile, TRACK_X); YapfNotifyTrackLayoutChange(tile, TRACK_Y); } else { - SetSignalsOnBothDir(tile, track); + SetSignalsOnBothDir(tile, track, owner); YapfNotifyTrackLayoutChange(tile, track); } } @@ -741,7 +745,7 @@ CommandCost CmdBuildTrainDepot(TileIndex d->town_index = ClosestTownFromTile(tile, (uint)-1)->index; - UpdateSignalsOnSegment(tile, INVALID_DIAGDIR); + UpdateSignalsOnSegment(tile, INVALID_DIAGDIR, _current_player); YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir))); d_auto_delete.Detach(); } @@ -867,7 +871,7 @@ CommandCost CmdBuildSingleSignal(TileInd } MarkTileDirtyByTile(tile); - SetSignalsOnBothDir(tile, track); + SetSignalsOnBothDir(tile, track, _current_player); YapfNotifyTrackLayoutChange(tile, track); } @@ -1098,7 +1102,7 @@ CommandCost CmdRemoveSingleSignal(TileIn SetSignalVariant(tile, INVALID_TRACK, SIG_ELECTRIC); // remove any possible semaphores } - SetSignalsOnBothDir(tile, track); + SetSignalsOnBothDir(tile, track, GetTileOwner(tile)); YapfNotifyTrackLayoutChange(tile, track); MarkTileDirtyByTile(tile); @@ -1304,11 +1308,13 @@ static CommandCost RemoveTrainDepot(Tile return CMD_ERROR; if (flags & DC_EXEC) { + /* read variables before the depot is removed */ DiagDirection dir = GetRailDepotDirection(tile); + Owner owner = GetTileOwner(tile); DoClearSquare(tile); delete GetDepotByTile(tile); - UpdateSignalsOnSegment(tile, dir); + UpdateSignalsOnSegment(tile, dir, owner); YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir))); }