summaryrefslogtreecommitdiff
path: root/src/autoreplace_cmd.cpp
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2007-09-04 19:58:18 +0000
committerbjarni <bjarni@openttd.org>2007-09-04 19:58:18 +0000
commit75bc407c461dd6b13e239f3b3d04d29d87f91e2e (patch)
tree6ddd9157ecf0802b85c84cc5e7fd18a8bb7979ae /src/autoreplace_cmd.cpp
parentc5cfb281ad92397784e81204f4679942e5463c45 (diff)
downloadopenttd-75bc407c461dd6b13e239f3b3d04d29d87f91e2e.tar.xz
(svn r11043) -Fix (r10039) [FS#1185]: Autorenew/autoreplace fails silently with multiple multi-headed engines
Diffstat (limited to 'src/autoreplace_cmd.cpp')
-rw-r--r--src/autoreplace_cmd.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index 08638a903..3d939eaee 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -247,13 +247,17 @@ static CommandCost ReplaceVehicle(Vehicle **w, byte flags, Money total_cost)
}
} else { // flags & DC_EXEC not set
CommandCost tmp_move;
- if (old_v->type == VEH_TRAIN && IsFrontEngine(old_v) && old_v->Next() != NULL) {
- /* Verify that the wagons can be placed on the engine in question.
- * This is done by building an engine, test if the wagons can be added and then sell the test engine. */
- DoCommand(old_v->tile, new_engine_type, 3, DC_EXEC, GetCmdBuildVeh(old_v));
- Vehicle *temp = GetVehicle(_new_vehicle_id);
- tmp_move = DoCommand(0, (temp->index << 16) | old_v->Next()->index, 1, 0, CMD_MOVE_RAIL_VEHICLE);
- DoCommand(0, temp->index, 0, DC_EXEC, GetCmdSellVeh(old_v));
+
+ if (old_v->type == VEH_TRAIN && IsFrontEngine(old_v)) {
+ Vehicle *next_veh = IsMultiheaded(old_v) ? old_v->Next()->Next() : old_v->Next();
+ if (next_veh != NULL) {
+ /* Verify that the wagons can be placed on the engine in question.
+ * This is done by building an engine, test if the wagons can be added and then sell the test engine. */
+ DoCommand(old_v->tile, new_engine_type, 3, DC_EXEC, GetCmdBuildVeh(old_v));
+ Vehicle *temp = GetVehicle(_new_vehicle_id);
+ tmp_move = DoCommand(0, (temp->index << 16) | next_veh->index, 1, 0, CMD_MOVE_RAIL_VEHICLE);
+ DoCommand(0, temp->index, 0, DC_EXEC, GetCmdSellVeh(old_v));
+ }
}
/* Ensure that the player will not end up having negative money while autoreplacing