src/vehicle.cpp
changeset 7269 c7f39d91255e
parent 7223 485af472c2f0
child 7278 f297b439fe6e
equal deleted inserted replaced
7268:9c77f6baef3b 7269:c7f39d91255e
   588 	if (IsEngineCountable(v)) {
   588 	if (IsEngineCountable(v)) {
   589 		GetPlayer(v->owner)->num_engines[v->engine_type]--;
   589 		GetPlayer(v->owner)->num_engines[v->engine_type]--;
   590 		if (v->owner == _local_player) InvalidateAutoreplaceWindow(v->engine_type);
   590 		if (v->owner == _local_player) InvalidateAutoreplaceWindow(v->engine_type);
   591 
   591 
   592 		if (IsValidGroupID(v->group_id)) GetGroup(v->group_id)->num_engines[v->engine_type]--;
   592 		if (IsValidGroupID(v->group_id)) GetGroup(v->group_id)->num_engines[v->engine_type]--;
   593 		if (v->type != VEH_TRAIN || IsFrontEngine(v)) DecreaseGroupNumVehicle(v->group_id);
   593 		if (v->IsPrimaryVehicle()) DecreaseGroupNumVehicle(v->group_id);
   594 	}
   594 	}
   595 
   595 
   596 	DeleteVehicleNews(v->index, INVALID_STRING_ID);
   596 	DeleteVehicleNews(v->index, INVALID_STRING_ID);
   597 
   597 
   598 	DeleteName(v->string_id);
   598 	DeleteName(v->string_id);
  1995 * @param window_type tells what kind of window the list is for. Use the VLW flags in vehicle_gui.h
  1995 * @param window_type tells what kind of window the list is for. Use the VLW flags in vehicle_gui.h
  1996 * @return the number of vehicles added to the list
  1996 * @return the number of vehicles added to the list
  1997 */
  1997 */
  1998 uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type)
  1998 uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type)
  1999 {
  1999 {
  2000 	const byte subtype = (type != VEH_AIRCRAFT) ? (byte)Train_Front : (byte)AIR_AIRCRAFT;
       
  2001 	uint n = 0;
  2000 	uint n = 0;
  2002 	const Vehicle *v;
  2001 	const Vehicle *v;
  2003 
  2002 
  2004 	switch (window_type) {
  2003 	switch (window_type) {
  2005 		case VLW_STATION_LIST: {
  2004 		case VLW_STATION_LIST: {
  2006 			FOR_ALL_VEHICLES(v) {
  2005 			FOR_ALL_VEHICLES(v) {
  2007 				if (v->type == type && (
  2006 				if (v->type == type && v->IsPrimaryVehicle()) {
  2008 					(type == VEH_TRAIN && IsFrontEngine(v)) ||
       
  2009 					(type != VEH_TRAIN && v->subtype <= subtype))) {
       
  2010 					const Order *order;
  2007 					const Order *order;
  2011 
  2008 
  2012 					FOR_VEHICLE_ORDERS(v, order) {
  2009 					FOR_VEHICLE_ORDERS(v, order) {
  2013 						if (order->type == OT_GOTO_STATION && order->dest == index) {
  2010 						if (order->type == OT_GOTO_STATION && order->dest == index) {
  2014 							if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 50);
  2011 							if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 50);
  2037 			break;
  2034 			break;
  2038 		}
  2035 		}
  2039 
  2036 
  2040 		case VLW_STANDARD: {
  2037 		case VLW_STANDARD: {
  2041 			FOR_ALL_VEHICLES(v) {
  2038 			FOR_ALL_VEHICLES(v) {
  2042 				if (v->type == type && v->owner == owner && (
  2039 				if (v->type == type && v->owner == owner && v->IsPrimaryVehicle()) {
  2043 					(type == VEH_TRAIN && IsFrontEngine(v)) ||
       
  2044 					(type != VEH_TRAIN && v->subtype <= subtype))) {
       
  2045 					/* TODO find a better estimate on the total number of vehicles for current player */
  2040 					/* TODO find a better estimate on the total number of vehicles for current player */
  2046 					if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, GetNumVehicles()/4);
  2041 					if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, GetNumVehicles()/4);
  2047 					(*sort_list)[n++] = v;
  2042 					(*sort_list)[n++] = v;
  2048 				}
  2043 				}
  2049 			}
  2044 			}
  2050 			break;
  2045 			break;
  2051 		}
  2046 		}
  2052 
  2047 
  2053 		case VLW_DEPOT_LIST: {
  2048 		case VLW_DEPOT_LIST: {
  2054 			FOR_ALL_VEHICLES(v) {
  2049 			FOR_ALL_VEHICLES(v) {
  2055 				if (v->type == type && (
  2050 				if (v->type == type && v->IsPrimaryVehicle()) {
  2056 					(type == VEH_TRAIN && IsFrontEngine(v)) ||
       
  2057 					(type != VEH_TRAIN && v->subtype <= subtype))) {
       
  2058 					const Order *order;
  2051 					const Order *order;
  2059 
  2052 
  2060 					FOR_VEHICLE_ORDERS(v, order) {
  2053 					FOR_VEHICLE_ORDERS(v, order) {
  2061 						if (order->type == OT_GOTO_DEPOT && order->dest == index) {
  2054 						if (order->type == OT_GOTO_DEPOT && order->dest == index) {
  2062 							if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 25);
  2055 							if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 25);
  2069 			break;
  2062 			break;
  2070 		}
  2063 		}
  2071 
  2064 
  2072  		case VLW_GROUP_LIST:
  2065  		case VLW_GROUP_LIST:
  2073 			FOR_ALL_VEHICLES(v) {
  2066 			FOR_ALL_VEHICLES(v) {
  2074 				if (v->type == type && (
  2067 				if (v->type == type && v->IsPrimaryVehicle() &&
  2075 							(type == VEH_TRAIN && IsFrontEngine(v)) ||
  2068 						v->owner == owner && v->group_id == index) {
  2076 							(type != VEH_TRAIN && v->subtype <= subtype)
       
  2077 						) && v->owner == owner && v->group_id == index) {
       
  2078 					if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, GetNumVehicles() / 4);
  2069 					if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, GetNumVehicles() / 4);
  2079 
  2070 
  2080 					(*sort_list)[n++] = v;
  2071 					(*sort_list)[n++] = v;
  2081 				}
  2072 				}
  2082 			}
  2073 			}