summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2013-02-03 10:03:38 +0000
committerrubidium <rubidium@openttd.org>2013-02-03 10:03:38 +0000
commitc7168f09c315795a88b70d5486b2ced6356f0cd4 (patch)
treea6f93809edbd93ffe43837672f347b004060e673
parente65a7109865ba418ce6ae64181b4333c33f17c32 (diff)
downloadopenttd-c7168f09c315795a88b70d5486b2ced6356f0cd4.tar.xz
(svn r24961) -Fix [FS#5362] (r23564): making occupied platforms larger would make train reserve onto the newly unreserved bit and cause crashes. Now if a platform is enlarged and there is a reservation, reserve the whole platform
-rw-r--r--src/station_cmd.cpp34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 8b08cc2a9..dc898d9bc 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1236,8 +1236,9 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
numtracks_orig = numtracks;
Company *c = Company::Get(st->owner);
+ TileIndex tile_track = tile_org;
do {
- TileIndex tile = tile_org;
+ TileIndex tile = tile_track;
int w = plat_len;
do {
byte layout = *layout_ptr++;
@@ -1293,9 +1294,9 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
tile += tile_delta;
} while (--w);
- AddTrackToSignalBuffer(tile_org, track, _current_company);
- YapfNotifyTrackLayoutChange(tile_org, track);
- tile_org += tile_delta ^ TileDiffXY(1, 1); // perpendicular to tile_delta
+ AddTrackToSignalBuffer(tile_track, track, _current_company);
+ YapfNotifyTrackLayoutChange(tile_track, track);
+ tile_track += tile_delta ^ TileDiffXY(1, 1); // perpendicular to tile_delta
} while (--numtracks);
for (uint i = 0; i < affected_vehicles.Length(); ++i) {
@@ -1307,6 +1308,31 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(ReverseTrackdir(v->GetVehicleTrackdir())), true);
}
+ /* Check whether we need to expand the reservation of trains already on the station. */
+ TileArea update_reservation_area;
+ if (axis == AXIS_X) {
+ update_reservation_area = TileArea(tile_org, 1, numtracks_orig);
+ } else {
+ update_reservation_area = TileArea(tile_org, numtracks_orig, 1);
+ }
+
+ TILE_AREA_LOOP(tile, update_reservation_area) {
+ DiagDirection dir = AxisToDiagDir(axis);
+ TileIndexDiff tile_offset = TileOffsByDiagDir(dir);
+ TileIndex platform_begin = tile - tile_offset * (st->GetPlatformLength(tile, ReverseDiagDir(dir)) - 1);
+ TileIndex platform_end = tile + tile_offset * (st->GetPlatformLength(tile, dir) - 1);
+
+ /* If there is at least on reservation on the platform, we reserve the whole platform. */
+ bool reservation = false;
+ for (TileIndex t = platform_begin; !reservation && t <= platform_end; t += tile_offset) {
+ reservation = HasStationReservation(t);
+ }
+
+ if (reservation) {
+ SetRailStationPlatformReservation(platform_begin, dir, true);
+ }
+ }
+
st->MarkTilesDirty(false);
st->UpdateVirtCoord();
UpdateStationAcceptance(st, false);