diff -r 91eca6fdee8d -r 6f41b8713b65 src/order_cmd.cpp --- a/src/order_cmd.cpp Sun Apr 01 09:38:43 2007 +0000 +++ b/src/order_cmd.cpp Thu Apr 19 14:43:25 2007 +0000 @@ -1,5 +1,7 @@ /* $Id$ */ +/** @file order_cmd.cpp */ + #include "stdafx.h" #include "openttd.h" #include "order.h" @@ -455,6 +457,24 @@ return 0; } +/** + * Remove the VehicleList that shows all the vehicles with the same shared + * orders. + */ +static void RemoveSharedOrderVehicleList(Vehicle *v) +{ + WindowClass window_class = WC_NONE; + + switch (v->type) { + default: NOT_REACHED(); + case VEH_TRAIN: window_class = WC_TRAINS_LIST; break; + case VEH_ROAD: window_class = WC_ROADVEH_LIST; break; + case VEH_SHIP: window_class = WC_SHIPS_LIST; break; + case VEH_AIRCRAFT: window_class = WC_AIRCRAFT_LIST; break; + } + DeleteWindowById(window_class, (v->orders->index << 16) | (v->type << 11) | VLW_SHARED_ORDERS | v->owner); +} + /** Delete an order from the orderlist of a vehicle. * @param tile unused * @param p1 the ID of the vehicle @@ -489,6 +509,10 @@ order = GetVehicleOrder(v, sel_ord + 1); SwapOrders(v->orders, order); } else { + /* XXX -- The system currently can't handle a shared-order vehicle list + * open when there aren't any orders in the list, so close the window + * in this case. Of course it needs a better fix later */ + RemoveSharedOrderVehicleList(v); /* Last item, so clean the list */ v->orders = NULL; } @@ -1116,7 +1140,7 @@ /* If we have a shared order-list, don't delete the list, but just remove our pointer */ if (IsOrderListShared(v)) { - const Vehicle *u = v; + Vehicle *u = v; v->orders = NULL; v->num_orders = 0; @@ -1133,6 +1157,10 @@ v->prev_shared = NULL; v->next_shared = NULL; + /* If we are the only one left in the Shared Order Vehicle List, + * remove it, as we are no longer a Shared Order Vehicle */ + if (u->prev_shared == NULL && u->next_shared == NULL) RemoveSharedOrderVehicleList(u); + /* We only need to update this-one, because if there is a third * vehicle which shares the same order-list, nothing will change. If * this is the last vehicle, the last line of the order-window @@ -1144,22 +1172,12 @@ /* Remove the orders */ Order *cur = v->orders; + /* Delete the vehicle list of shared orders, if any */ + if (cur != NULL) RemoveSharedOrderVehicleList(v); v->orders = NULL; v->num_orders = 0; if (cur != NULL) { - /* Delete the vehicle list of shared orders, if any */ - WindowClass window_class = WC_NONE; - - switch (v->type) { - default: NOT_REACHED(); - case VEH_TRAIN: window_class = WC_TRAINS_LIST; break; - case VEH_ROAD: window_class = WC_ROADVEH_LIST; break; - case VEH_SHIP: window_class = WC_SHIPS_LIST; break; - case VEH_AIRCRAFT: window_class = WC_AIRCRAFT_LIST; break; - } - DeleteWindowById(window_class, (cur->index << 16) | (v->type << 11) | VLW_SHARED_ORDERS | v->owner); - cur->FreeChain(); // Free the orders. } }