vehicle_gui.c
changeset 4408 db2afc41002a
parent 4389 18d6ccfb5335
child 4414 b7bdfeaa4631
equal deleted inserted replaced
4407:685c613f3fec 4408:db2afc41002a
   113 			break;
   113 			break;
   114 		default: break;
   114 		default: break;
   115 		}
   115 		}
   116 }
   116 }
   117 
   117 
   118 void BuildVehicleList(vehiclelist_d* vl, int type, PlayerID owner, StationID station)
   118 void BuildVehicleList(vehiclelist_d* vl, int type, PlayerID owner, StationID station, uint16 order)
   119 {
   119 {
   120 	const Vehicle** sort_list;
   120 	const Vehicle** sort_list;
   121 	uint subtype = (type != VEH_Aircraft) ? Train_Front : 2;
   121 	uint subtype = (type != VEH_Aircraft) ? Train_Front : 2;
   122 	uint n = 0;
   122 	uint n = 0;
   123 	uint i;
   123 	uint i;
   148 					}
   148 					}
   149 				}
   149 				}
   150 			}
   150 			}
   151 		}
   151 		}
   152 	} else {
   152 	} else {
   153 		const Vehicle *v;
   153 		if (order != INVALID_ORDER) {
   154 		FOR_ALL_VEHICLES(v) {
   154 			Vehicle *v;
   155 			if (v->type == type && v->owner == owner && (
   155 			FOR_ALL_VEHICLES(v) {
   156 						(type == VEH_Train && IsFrontEngine(v)) ||
   156 				/* Find a vehicle with the order in question */
   157 						(type != VEH_Train && v->subtype <= subtype)
   157 				if (v != NULL && v->orders != NULL && v->orders->index == order) break;
   158 					)) {
   158 			}
   159 				sort_list[n++] = v;
   159 
       
   160 			if (v != NULL && v->orders != NULL && v->orders->index == order) {
       
   161 				/* Only try to make the list if we found a vehicle using the order in question */
       
   162 				for (v = GetFirstVehicleFromSharedList(v); v != NULL; v = v->next_shared) {
       
   163 					sort_list[n++] = v;
       
   164 				}
       
   165 			}
       
   166 		} else {
       
   167 			const Vehicle *v;
       
   168 			FOR_ALL_VEHICLES(v) {
       
   169 				if (v->type == type && v->owner == owner && (
       
   170 				    (type == VEH_Train && IsFrontEngine(v)) ||
       
   171 				    (type != VEH_Train && v->subtype <= subtype))) {
       
   172 					sort_list[n++] = v;
       
   173 				}
   160 			}
   174 			}
   161 		}
   175 		}
   162 	}
   176 	}
   163 
   177 
   164 	free((void*)vl->sort_list);
   178 	free((void*)vl->sort_list);