changeset 11094:6a6a59f20daf draft

(svn r15439) -Fix [FS#2626]: call Vehicle::LeaveStation() before reversing overlength loading train (station triggers were missed, PBS reservation could cause crash)
author smatz <smatz@openttd.org>
date Tue, 10 Feb 2009 12:49:12 +0000
parents 1d2655421ce9
children c126c8718572
files src/train_cmd.cpp
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1936,6 +1936,17 @@
 		if (v->vehstatus & VS_CRASHED || v->breakdown_ctr != 0) return CMD_ERROR;
 
 		if (flags & DC_EXEC) {
+			/* Properly leave the station if we are loading and won't be loading anymore */
+			if (v->current_order.IsType(OT_LOADING)) {
+				const Vehicle *last = v;
+				while (last->Next() != NULL) last = last->Next();
+
+				/* not a station || different station --> leave the station */
+				if (!IsTileType(last->tile, MP_STATION) || GetStationIndex(last->tile) != GetStationIndex(v->tile)) {
+					v->LeaveStation();
+				}
+			}
+
 			if (_settings_game.vehicle.train_acceleration_model != TAM_ORIGINAL && v->cur_speed != 0) {
 				ToggleBit(v->u.rail.flags, VRF_REVERSING);
 			} else {