src/order_cmd.cpp
branchgamebalance
changeset 9906 6f41b8713b65
parent 9895 7bd07f43b0e3
child 9907 3b068c3a1c74
equal deleted inserted replaced
9905:91eca6fdee8d 9906:6f41b8713b65
     1 /* $Id$ */
     1 /* $Id$ */
       
     2 
       
     3 /** @file order_cmd.cpp */
     2 
     4 
     3 #include "stdafx.h"
     5 #include "stdafx.h"
     4 #include "openttd.h"
     6 #include "openttd.h"
     5 #include "order.h"
     7 #include "order.h"
     6 #include "airport.h"
     8 #include "airport.h"
   453 		RebuildVehicleLists();
   455 		RebuildVehicleLists();
   454 	}
   456 	}
   455 	return 0;
   457 	return 0;
   456 }
   458 }
   457 
   459 
       
   460 /**
       
   461  * Remove the VehicleList that shows all the vehicles with the same shared
       
   462  *  orders.
       
   463  */
       
   464 static void RemoveSharedOrderVehicleList(Vehicle *v)
       
   465 {
       
   466 	WindowClass window_class = WC_NONE;
       
   467 
       
   468 	switch (v->type) {
       
   469 		default: NOT_REACHED();
       
   470 		case VEH_TRAIN:    window_class = WC_TRAINS_LIST;   break;
       
   471 		case VEH_ROAD:     window_class = WC_ROADVEH_LIST;  break;
       
   472 		case VEH_SHIP:     window_class = WC_SHIPS_LIST;    break;
       
   473 		case VEH_AIRCRAFT: window_class = WC_AIRCRAFT_LIST; break;
       
   474 	}
       
   475 	DeleteWindowById(window_class, (v->orders->index << 16) | (v->type << 11) | VLW_SHARED_ORDERS | v->owner);
       
   476 }
       
   477 
   458 /** Delete an order from the orderlist of a vehicle.
   478 /** Delete an order from the orderlist of a vehicle.
   459  * @param tile unused
   479  * @param tile unused
   460  * @param p1 the ID of the vehicle
   480  * @param p1 the ID of the vehicle
   461  * @param p2 the order to delete (max 255)
   481  * @param p2 the order to delete (max 255)
   462  */
   482  */
   487 				    Because we can have shared order, we copy the data
   507 				    Because we can have shared order, we copy the data
   488 				    from the next item over the deleted */
   508 				    from the next item over the deleted */
   489 				order = GetVehicleOrder(v, sel_ord + 1);
   509 				order = GetVehicleOrder(v, sel_ord + 1);
   490 				SwapOrders(v->orders, order);
   510 				SwapOrders(v->orders, order);
   491 			} else {
   511 			} else {
       
   512 				/* XXX -- The system currently can't handle a shared-order vehicle list
       
   513 				 *  open when there aren't any orders in the list, so close the window
       
   514 				 *  in this case. Of course it needs a better fix later */
       
   515 				RemoveSharedOrderVehicleList(v);
   492 				/* Last item, so clean the list */
   516 				/* Last item, so clean the list */
   493 				v->orders = NULL;
   517 				v->orders = NULL;
   494 			}
   518 			}
   495 		} else {
   519 		} else {
   496 			GetVehicleOrder(v, sel_ord - 1)->next = order->next;
   520 			GetVehicleOrder(v, sel_ord - 1)->next = order->next;
  1114 	DeleteOrderWarnings(v);
  1138 	DeleteOrderWarnings(v);
  1115 
  1139 
  1116 	/* If we have a shared order-list, don't delete the list, but just
  1140 	/* If we have a shared order-list, don't delete the list, but just
  1117 	    remove our pointer */
  1141 	    remove our pointer */
  1118 	if (IsOrderListShared(v)) {
  1142 	if (IsOrderListShared(v)) {
  1119 		const Vehicle *u = v;
  1143 		Vehicle *u = v;
  1120 
  1144 
  1121 		v->orders = NULL;
  1145 		v->orders = NULL;
  1122 		v->num_orders = 0;
  1146 		v->num_orders = 0;
  1123 
  1147 
  1124 		/* Unlink ourself */
  1148 		/* Unlink ourself */
  1130 			v->next_shared->prev_shared = v->prev_shared;
  1154 			v->next_shared->prev_shared = v->prev_shared;
  1131 			u = v->next_shared;
  1155 			u = v->next_shared;
  1132 		}
  1156 		}
  1133 		v->prev_shared = NULL;
  1157 		v->prev_shared = NULL;
  1134 		v->next_shared = NULL;
  1158 		v->next_shared = NULL;
       
  1159 
       
  1160 		/* If we are the only one left in the Shared Order Vehicle List,
       
  1161 		 *  remove it, as we are no longer a Shared Order Vehicle */
       
  1162 		if (u->prev_shared == NULL && u->next_shared == NULL) RemoveSharedOrderVehicleList(u);
  1135 
  1163 
  1136 		/* We only need to update this-one, because if there is a third
  1164 		/* We only need to update this-one, because if there is a third
  1137 		 *  vehicle which shares the same order-list, nothing will change. If
  1165 		 *  vehicle which shares the same order-list, nothing will change. If
  1138 		 *  this is the last vehicle, the last line of the order-window
  1166 		 *  this is the last vehicle, the last line of the order-window
  1139 		 *  will change from Shared order list, to Order list, so it needs
  1167 		 *  will change from Shared order list, to Order list, so it needs
  1142 		return;
  1170 		return;
  1143 	}
  1171 	}
  1144 
  1172 
  1145 	/* Remove the orders */
  1173 	/* Remove the orders */
  1146 	Order *cur = v->orders;
  1174 	Order *cur = v->orders;
       
  1175 	/* Delete the vehicle list of shared orders, if any */
       
  1176 	if (cur != NULL) RemoveSharedOrderVehicleList(v);
  1147 	v->orders = NULL;
  1177 	v->orders = NULL;
  1148 	v->num_orders = 0;
  1178 	v->num_orders = 0;
  1149 
  1179 
  1150 	if (cur != NULL) {
  1180 	if (cur != NULL) {
  1151 		/* Delete the vehicle list of shared orders, if any */
       
  1152 		WindowClass window_class = WC_NONE;
       
  1153 
       
  1154 		switch (v->type) {
       
  1155 			default: NOT_REACHED();
       
  1156 			case VEH_TRAIN:    window_class = WC_TRAINS_LIST;   break;
       
  1157 			case VEH_ROAD:     window_class = WC_ROADVEH_LIST;  break;
       
  1158 			case VEH_SHIP:     window_class = WC_SHIPS_LIST;    break;
       
  1159 			case VEH_AIRCRAFT: window_class = WC_AIRCRAFT_LIST; break;
       
  1160 		}
       
  1161 		DeleteWindowById(window_class, (cur->index << 16) | (v->type << 11) | VLW_SHARED_ORDERS | v->owner);
       
  1162 
       
  1163 		cur->FreeChain(); // Free the orders.
  1181 		cur->FreeChain(); // Free the orders.
  1164 	}
  1182 	}
  1165 }
  1183 }
  1166 
  1184 
  1167 /**
  1185 /**