From 0a623bc333a54dba04271399b5d73a09498df8b2 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Sun, 4 Jun 2006 17:49:16 +0000 Subject: [PATCH] (svn r5104) - When refitting a vehicle to its existing cargo type, don't lose the cargo onboard (useful when adding wagons to a train) --- aircraft_cmd.c | 8 +++++++- ship_cmd.c | 2 +- train_cmd.c | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/aircraft_cmd.c b/aircraft_cmd.c index dc736e491c..94411d3b26 100644 --- a/aircraft_cmd.c +++ b/aircraft_cmd.c @@ -538,7 +538,13 @@ int32 CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) u = v->next; mail = (new_cid != CT_PASSENGERS) ? 0 : avi->mail_capacity; u->cargo_cap = mail; - v->cargo_count = u->cargo_count = 0; + if (v->cargo_type == new_cid) { + v->cargo_count = min(pass, v->cargo_count); + u->cargo_count = min(mail, u->cargo_count); + } else { + v->cargo_count = 0; + u->cargo_count = 0; + } v->cargo_type = new_cid; v->cargo_subtype = new_subtype; InvalidateWindow(WC_VEHICLE_DETAILS, v->index); diff --git a/ship_cmd.c b/ship_cmd.c index 424d484fbe..b193f954cd 100644 --- a/ship_cmd.c +++ b/ship_cmd.c @@ -1061,7 +1061,7 @@ int32 CmdRefitShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) } if (flags & DC_EXEC) { - v->cargo_count = 0; + v->cargo_count = (v->cargo_type == new_cid) ? min(v->cargo_cap, v->cargo_count) : 0; v->cargo_type = new_cid; v->cargo_subtype = new_subtype; InvalidateWindow(WC_VEHICLE_DETAILS, v->index); diff --git a/train_cmd.c b/train_cmd.c index a189a9d9ab..ad0aa8965a 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -1789,7 +1789,7 @@ int32 CmdRefitRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) if (new_cid != v->cargo_type) cost += _price.build_railvehicle >> 8; num += amount; if (flags & DC_EXEC) { - v->cargo_count = 0; + v->cargo_count = (v->cargo_type == new_cid) ? min(amount, v->cargo_count) : 0; v->cargo_type = new_cid; v->cargo_cap = amount; v->cargo_subtype = new_subtype;