(svn r14097) -Fix [FS#2085]: one couldn't get a list of vehicles sharing an order when the number of orders was 0; you could see that the vehicles had a shared order though.
authorrubidium
Sun, 17 Aug 2008 21:07:09 +0000
changeset 9942 c3677fa5563f
parent 9941 8549448b55fa
child 9943 ccea23aec951
(svn r14097) -Fix [FS#2085]: one couldn't get a list of vehicles sharing an order when the number of orders was 0; you could see that the vehicles had a shared order though.
src/order_cmd.cpp
src/order_gui.cpp
src/vehicle.cpp
src/vehicle_gui.cpp
src/vehiclelist.cpp
--- a/src/order_cmd.cpp	Sun Aug 17 19:56:17 2008 +0000
+++ b/src/order_cmd.cpp	Sun Aug 17 21:07:09 2008 +0000
@@ -596,25 +596,6 @@
 	return CommandCost();
 }
 
-/**
- * Remove the VehicleList that shows all the vehicles with the same shared
- *  orders.
- */
-void RemoveSharedOrderVehicleList(Vehicle *v)
-{
-	assert(v->orders != NULL);
-	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 flags operation to perform
@@ -650,10 +631,6 @@
 				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;
 			}
--- a/src/order_gui.cpp	Sun Aug 17 19:56:17 2008 +0000
+++ b/src/order_gui.cpp	Sun Aug 17 21:07:09 2008 +0000
@@ -654,7 +654,7 @@
 			this->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD,    order == NULL || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload
 			this->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD_DROPDOWN, this->IsWidgetDisabled(ORDER_WIDGET_UNLOAD));
 			/* Disable list of vehicles with the same shared orders if there is no list */
-			this->SetWidgetDisabledState(ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders || this->vehicle->orders == NULL);
+			this->SetWidgetDisabledState(ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders);
 			this->SetWidgetDisabledState(ORDER_WIDGET_REFIT,     order == NULL); // Refit
 			this->SetWidgetDisabledState(ORDER_WIDGET_SERVICE,   order == NULL); // Refit
 			this->HideWidget(ORDER_WIDGET_REFIT); // Refit
--- a/src/vehicle.cpp	Sun Aug 17 19:56:17 2008 +0000
+++ b/src/vehicle.cpp	Sun Aug 17 21:07:09 2008 +0000
@@ -2614,11 +2614,15 @@
 
 	if (this->next_shared != NULL) this->next_shared->previous_shared = this->previous_shared;
 
+	uint32 old_window_number = (this->FirstShared()->index << 16) | (this->type << 11) | VLW_SHARED_ORDERS | this->owner;
+
 	if (new_first->NextShared() == NULL) {
 		/* When there is only one vehicle, remove the shared order list window. */
-		extern void RemoveSharedOrderVehicleList(Vehicle *v);
-		if (new_first->orders != NULL) RemoveSharedOrderVehicleList(new_first);
+		DeleteWindowById(GetWindowClassForVehicleType(this->type), old_window_number);
 		InvalidateVehicleOrder(new_first);
+	} else if (this->FirstShared() == this) {
+		/* If we were the first one, update to the new first one. */
+		InvalidateWindowData(GetWindowClassForVehicleType(this->type), old_window_number, (new_first->index << 16) | (1 << 15));
 	}
 
 	this->first_shared    = this;
--- a/src/vehicle_gui.cpp	Sun Aug 17 19:56:17 2008 +0000
+++ b/src/vehicle_gui.cpp	Sun Aug 17 21:07:09 2008 +0000
@@ -1074,6 +1074,12 @@
 
 	virtual void OnInvalidateData(int data)
 	{
+		if (HasBit(data, 15) && (this->window_number & VLW_MASK) == VLW_SHARED_ORDERS) {
+			SB(this->window_number, 16, 16, GB(data, 16, 16));
+			this->vehicles.ForceRebuild();
+			return;
+		}
+
 		if (data == 0) {
 			this->vehicles.ForceRebuild();
 		} else {
@@ -1163,8 +1169,7 @@
 
 void ShowVehicleListWindow(const Vehicle *v)
 {
-	if (v->orders == NULL) return; // no shared list to show
-	ShowVehicleListWindowLocal(v->owner, VLW_SHARED_ORDERS, v->type, v->orders->index);
+	ShowVehicleListWindowLocal(v->owner, VLW_SHARED_ORDERS, v->type, v->FirstShared()->index);
 }
 
 void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, StationID station)
--- a/src/vehiclelist.cpp	Sun Aug 17 19:56:17 2008 +0000
+++ b/src/vehiclelist.cpp	Sun Aug 17 21:07:09 2008 +0000
@@ -93,15 +93,9 @@
 			break;
 
 		case VLW_SHARED_ORDERS:
-			FOR_ALL_VEHICLES(v) {
-				/* Find a vehicle with the order in question */
-				if (v->orders != NULL && v->orders->index == index) {
-					/* Add all vehicles from this vehicle's shared order list */
-					for (v = v->FirstShared(); v != NULL; v = v->NextShared()) {
-						*list->Append() = v;
-					}
-					break;
-				}
+			/* Add all vehicles from this vehicle's shared order list */
+			for (v = GetVehicle(index); v != NULL; v = v->NextShared()) {
+				*list->Append() = v;
 			}
 			break;