summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsignde <signde@openttd.org>2004-09-14 08:13:15 +0000
committersignde <signde@openttd.org>2004-09-14 08:13:15 +0000
commit5e699ca65d58722d0e0daebdfc61fbc8913b56bc (patch)
tree8c56e1da458107ca71064202a71bfd4ef058daa0
parentbf703a0e825c16d07cf64f62ace41ff8b9bd69c0 (diff)
downloadopenttd-5e699ca65d58722d0e0daebdfc61fbc8913b56bc.tar.xz
(svn r243) -Fix: [1022689] When destroying a part of a train with a 2 side engine the second engine was also deleted [Celestar]
-rw-r--r--train_cmd.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/train_cmd.c b/train_cmd.c
index 909294b79..aeb2079dd 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -773,7 +773,17 @@ int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2)
first = v;
if (first->subtype != 0) {
first = GetFirstVehicleInChain(first);
- last = NULL;
+ last = GetLastVehicleInChain(first);
+ //now if:
+ // 1) we delete a whole a chain, and
+ // 2) the first and the last vehicle of that train are of the same type, and
+ // 3) the first and the last vehicle of the chain are not identical, and
+ // 4) and of "engine" type (i.e. not a carriage)
+ // then let the last vehicle live
+ if ( (p2 == 1) && ( last->engine_type == first->engine_type ) && (last != first) && (first->subtype == 0) )
+ last = GetPrevVehicleInChain(last);
+ else
+ last = NULL;
} else {
if (p2 != 1) {
// sell last part of multiheaded?
@@ -825,7 +835,7 @@ int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2)
tmp = v;
v = v->next;
DeleteVehicle(tmp);
- if (v == NULL || p2 != 1) break;
+ if (v == last || p2 != 1) break;
}
// delete last vehicle of multiheaded train?
@@ -844,7 +854,7 @@ int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2)
cost = 0;
for(;;) {
cost -= v->value;
- if ((v=v->next) == NULL || p2 != 1) break;
+ if ((v=v->next) == last || p2 != 1) break;
}
if (last) cost -= last->value;
}