summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2008-05-07 22:08:20 +0000
committerbjarni <bjarni@openttd.org>2008-05-07 22:08:20 +0000
commit02709df7e3313c630afab63c922afe2d9156f947 (patch)
tree30fbdc49b7e1694d63868e14bfddeaa26a028230 /src
parent6e6102e20d3b8bb5dbe0b8129c9ab7b37ab666d6 (diff)
downloadopenttd-02709df7e3313c630afab63c922afe2d9156f947.tar.xz
(svn r13001) -Fix [FS#1994](r12913): [autoreplace] we should stop working on vehicles right away if we fail to replace them and certainly not presume their data is valid
Diffstat (limited to 'src')
-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 4499a2d04..8b9ce5d46 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -244,11 +244,13 @@ static CommandCost ReplaceVehicle(Vehicle **w, byte flags, Money total_cost, con
}
}
}
- /* We are done setting up the new vehicle. Now we move the cargo from the old one to the new one */
- MoveVehicleCargo(new_v->type == VEH_TRAIN ? new_v->First() : new_v, old_v);
+ if (CmdSucceeded(cost)) {
+ /* We are done setting up the new vehicle. Now we move the cargo from the old one to the new one */
+ MoveVehicleCargo(new_v->type == VEH_TRAIN ? new_v->First() : new_v, old_v);
- // Get the name of the old vehicle if it has a custom name.
- if (old_v->name != NULL) vehicle_name = strdup(old_v->name);
+ /* Get the name of the old vehicle if it has a custom name. */
+ if (old_v->name != NULL) vehicle_name = strdup(old_v->name);
+ }
} else { // flags & DC_EXEC not set
CommandCost tmp_move;
@@ -282,6 +284,8 @@ static CommandCost ReplaceVehicle(Vehicle **w, byte flags, Money total_cost, con
/* sell the engine/ find out how much you get for the old engine (income is returned as negative cost) */
cost.AddCost(DoCommand(0, old_v->index, 0, flags, GetCmdSellVeh(old_v)));
+ if (CmdFailed(cost)) return cost;
+
if (new_front) {
/* now we assign the old unitnumber to the new vehicle */
new_v->unitnumber = cached_unitnumber;
@@ -426,16 +430,16 @@ CommandCost MaybeReplaceVehicle(Vehicle *v, uint32 flags, bool display_costs)
/* Now replace the vehicle */
cost.AddCost(ReplaceVehicle(&w, DC_EXEC, cost.GetCost(), p, new_engine));
- if (w->type != VEH_TRAIN || w->u.rail.first_engine == INVALID_ENGINE) {
+ if (CmdSucceeded(cost) && (w->type != VEH_TRAIN || w->u.rail.first_engine == INVALID_ENGINE)) {
/* now we bought a new engine and sold the old one. We need to fix the
* pointers in order to avoid pointing to the old one for trains: these
* pointers should point to the front engine and not the cars
*/
v = w;
}
- } while (w->type == VEH_TRAIN && (w = GetNextVehicle(w)) != NULL);
+ } while (CmdSucceeded(cost) && w->type == VEH_TRAIN && (w = GetNextVehicle(w)) != NULL);
- if (v->type == VEH_TRAIN && p->renew_keep_length) {
+ if (CmdSucceeded(cost) && v->type == VEH_TRAIN && p->renew_keep_length) {
/* Remove wagons until the wanted length is reached */
cost.AddCost(WagonRemoval(v, old_total_length));
}