summaryrefslogtreecommitdiff
path: root/src/vehicle.cpp
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2007-06-09 18:31:04 +0000
committerbjarni <bjarni@openttd.org>2007-06-09 18:31:04 +0000
commit160aa21f31407065b6052da8bc844821801e35ab (patch)
treef225dff6a8923d03219dfa8e2bc46478e862ea72 /src/vehicle.cpp
parent8686e247acbde679fc498cdfd7901f3a84eb7b4d (diff)
downloadopenttd-160aa21f31407065b6052da8bc844821801e35ab.tar.xz
(svn r10077) -Fix: FS#845 Cloning Trains Longer Than 8 Units Causes Crash
The problem was that if adding units to the clone (wagon by wagon) failed, then cloning wouldn't notice it and it made two half trains Now it detects this case and it will make cloning fail. The string with the explanation for the failed move will be used in the error message so the user will know why it failed.
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r--src/vehicle.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index d813414d4..47b8b7c5c 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1825,7 +1825,14 @@ int32 CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (v->type == VEH_TRAIN && !IsFrontEngine(v)) {
/* this s a train car
* add this unit to the end of the train */
- DoCommand(0, (w_rear->index << 16) | w->index, 1, flags, CMD_MOVE_RAIL_VEHICLE);
+ int32 result = DoCommand(0, (w_rear->index << 16) | w->index, 1, flags, CMD_MOVE_RAIL_VEHICLE);
+ if (CmdFailed(result)) {
+ /* The train can't be joined to make the same consist as the original.
+ * Sell what we already made (clean up) and return an error. */
+ DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front));
+ DoCommand(w_front->tile, w->index, 1, flags, GetCmdSellVeh(w));
+ return result; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE
+ }
} else {
/* this is a front engine or not a train. It need orders */
w_front = w;