diff options
author | bjarni <bjarni@openttd.org> | 2008-03-25 21:58:13 +0000 |
---|---|---|
committer | bjarni <bjarni@openttd.org> | 2008-03-25 21:58:13 +0000 |
commit | b05919cc5a07ef01e18db2a22f339fb8a5665526 (patch) | |
tree | 2ad5b9f3e4ccd972190047d82ef084441736287e /src/autoreplace_cmd.cpp | |
parent | 691e9e1b5c860c8190f30f8bb8e34c45888a894f (diff) | |
download | openttd-b05919cc5a07ef01e18db2a22f339fb8a5665526.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.cpp | 21 |
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); |