summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2008-05-07 23:00:11 +0000
committerbjarni <bjarni@openttd.org>2008-05-07 23:00:11 +0000
commit5a7fcf9aa3ce17e9f8602a682171b30cc8b1a786 (patch)
treef54be9b0353e707e891da8c1c12652ba7eed65b2 /src
parentaddcd2bb2ec897d1396f727e6668c70472574223 (diff)
downloadopenttd-5a7fcf9aa3ce17e9f8602a682171b30cc8b1a786.tar.xz
(svn r13002) -Fix (r13001): [autoreplace] previous fix broke updating of a pointer to the front vehicle in certain cases
Now it's updated when it's the front vehicle and it's every time it's the front vehicle and only if it's the front vehicle (nomatter if the replacement works or not)
Diffstat (limited to 'src')
-rw-r--r--src/autoreplace_cmd.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index 8b9ce5d46..fb5ad11f9 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -427,10 +427,14 @@ CommandCost MaybeReplaceVehicle(Vehicle *v, uint32 flags, bool display_costs)
/* We are going to try to replace a vehicle but we don't have any backup so we will make one. */
backup.Backup(v, p);
}
- /* Now replace the vehicle */
+ /* Now replace the vehicle.
+ * First we need to cache if it's the front vehicle as we need to update the v pointer if it is.
+ * If the replacement fails then we can't trust the data in the vehicle hence the reason to cache the result. */
+ bool IsFront = w->type != VEH_TRAIN || w->u.rail.first_engine == INVALID_ENGINE;
+
cost.AddCost(ReplaceVehicle(&w, DC_EXEC, cost.GetCost(), p, new_engine));
- if (CmdSucceeded(cost) && (w->type != VEH_TRAIN || w->u.rail.first_engine == INVALID_ENGINE)) {
+ if (IsFront) {
/* 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