summaryrefslogtreecommitdiff
path: root/vehicle.c
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-01-08 12:20:13 +0000
committerbjarni <bjarni@openttd.org>2006-01-08 12:20:13 +0000
commit4bf1741783226e9b3ec5f54647a26651c6f08cda (patch)
tree5960bec54c1e2a43b84d1d87d627862d69f03db0 /vehicle.c
parentde34ab97a2f91740815d9657f785b71194742552 (diff)
downloadopenttd-4bf1741783226e9b3ec5f54647a26651c6f08cda.tar.xz
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
and the front engine was multiheaded and the first vehicle after it was the rear part of that engine
Diffstat (limited to 'vehicle.c')
-rw-r--r--vehicle.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/vehicle.c b/vehicle.c
index 444bfaa10..45f7c6ee8 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -1654,10 +1654,17 @@ static int32 ReplaceVehicle(Vehicle **w, byte flags)
new_front = true;
new_v->current_order = old_v->current_order;
- if (old_v->type == VEH_Train){
- // move the entire train to the new engine, including the old engine. It will be sold in a moment anyway
- if (GetNextVehicle(old_v) != NULL) {
- DoCommand(0, 0, (new_v->index << 16) | GetNextVehicle(old_v)->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
+ if (old_v->type == VEH_Train && GetNextVehicle(old_v) != NULL){
+ Vehicle *temp_v = GetNextVehicle(old_v);
+
+ // move the entire train to the new engine, excluding the old engine
+ if (IsMultiheaded(old_v) && temp_v == old_v->u.rail.other_multiheaded_part) {
+ // we got front and rear of a multiheaded engine right after each other. We should work with the next in line instead
+ temp_v = GetNextVehicle(temp_v);
+ }
+
+ if (temp_v != NULL) {
+ DoCommand(0, 0, (new_v->index << 16) | temp_v->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
}
}
}