From 4757c0bf8c92fa5215c5dfeea0f72daeaae96834 Mon Sep 17 00:00:00 2001 From: darkvater Date: Tue, 14 Sep 2004 14:26:12 +0000 Subject: (svn r245) -Fix: [1022689] Bug when dragging a part of a multiheaded engine to 'sell-whole-train'. The rear-head of the multiheaded train will now not be sold automatically. You have to drag it manually (Celestar) --- train_cmd.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'train_cmd.c') diff --git a/train_cmd.c b/train_cmd.c index aeb2079dd..2efd3e03d 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -776,11 +776,12 @@ int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2) 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) + // 2) we don't actually try to delete the last engine + // 3) the first and the last vehicle of that train are of the same type, and + // 4) the first and the last vehicle of the chain are not identical + // 5) 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) ) + if ( (p2 == 1) && (v != last) && ( last->engine_type == first->engine_type ) && (last != first) && (first->subtype == 0) ) last = GetPrevVehicleInChain(last); else last = NULL; @@ -833,9 +834,12 @@ int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2) first = UnlinkWagon(v, first); cost -= v->value; tmp = v; - v = v->next; DeleteVehicle(tmp); - if (v == last || p2 != 1) break; + if ( v == last ) { + last = NULL; + break; + } + if ( (v=v->next) == last || p2 != 1) break; } // delete last vehicle of multiheaded train? @@ -854,7 +858,11 @@ int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2) cost = 0; for(;;) { cost -= v->value; - if ((v=v->next) == last || p2 != 1) break; + if ( v == last ) { + last = NULL; + break; + } + if ( (v=v->next) == last || p2 != 1) break; } if (last) cost -= last->value; } -- cgit v1.2.3-54-g00ecf