summaryrefslogtreecommitdiff
path: root/src/autoreplace_cmd.cpp
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2008-03-25 21:58:13 +0000
committerbjarni <bjarni@openttd.org>2008-03-25 21:58:13 +0000
commit06c0e5df5a9b043ef9745e3c2cc1653847a110ab (patch)
tree2ad5b9f3e4ccd972190047d82ef084441736287e /src/autoreplace_cmd.cpp
parent97fb7fb8d9de58786722b350b6a25090baf8fb94 (diff)
downloadopenttd-06c0e5df5a9b043ef9745e3c2cc1653847a110ab.tar.xz
(svn r12421) -Feature: [autoreplace] the autoreplace button in train depots will now also replace wagons even if they aren't connected to a locomotive
fixed estimated cost in CmdDepotMassAutoReplace() (will still not estimate wagon removal profits) Made it possible to command CmdDepotMassAutoReplace() to either replace everything or nothing (the button will still happily replace just some of the vehicles if cash premits)
Diffstat (limited to 'src/autoreplace_cmd.cpp')
-rw-r--r--src/autoreplace_cmd.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index 2eafe9812..ae49128d7 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -199,12 +199,21 @@ static CommandCost ReplaceVehicle(Vehicle **w, byte flags, Money total_cost)
*/
/* Get the vehicle in front of the one we move out */
Vehicle *front = old_v->Previous();
- /* If the vehicle in front is the rear end of a dualheaded engine, then we need to use the one in front of that one */
- if (IsRearDualheaded(front)) front = front->Previous();
- /* Now we move the old one out of the train */
- DoCommand(0, (INVALID_VEHICLE << 16) | old_v->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
- /* Add the new vehicle */
- DoCommand(0, (front->index << 16) | new_v->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
+ if (front == NULL) {
+ /* It would appear that we have the front wagon of a row of wagons without engines */
+ Vehicle *next = old_v->Next();
+ if (next != NULL) {
+ /* Move the chain to the new front wagon */
+ DoCommand(0, (new_v->index << 16) | next->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
+ }
+ } else {
+ /* If the vehicle in front is the rear end of a dualheaded engine, then we need to use the one in front of that one */
+ if (IsRearDualheaded(front)) front = front->Previous();
+ /* Now we move the old one out of the train */
+ DoCommand(0, (INVALID_VEHICLE << 16) | old_v->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
+ /* Add the new vehicle */
+ DoCommand(0, (front->index << 16) | new_v->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
+ }
} else {
// copy/clone the orders
DoCommand(0, (old_v->index << 16) | new_v->index, old_v->IsOrderListShared() ? CO_SHARE : CO_COPY, DC_EXEC, CMD_CLONE_ORDER);