vehicle_gui.c
changeset 2951 2de6d3a59743
parent 2848 8f57563f8ddf
child 2962 f0a49b646c48
equal deleted inserted replaced
2950:30eee9c93028 2951:2de6d3a59743
   112 	uint i;
   112 	uint i;
   113 
   113 
   114 	if (!(vl->flags & VL_REBUILD)) return;
   114 	if (!(vl->flags & VL_REBUILD)) return;
   115 
   115 
   116 	sort_list = malloc(GetVehiclePoolSize() * sizeof(sort_list[0]));
   116 	sort_list = malloc(GetVehiclePoolSize() * sizeof(sort_list[0]));
   117 	if (sort_list == NULL)
   117 	if (sort_list == NULL) {
   118 		error("Could not allocate memory for the vehicle-sorting-list");
   118 		error("Could not allocate memory for the vehicle-sorting-list");
       
   119 	}
   119 
   120 
   120 	DEBUG(misc, 1) ("Building vehicle list for player %d station %d...",
   121 	DEBUG(misc, 1) ("Building vehicle list for player %d station %d...",
   121 		owner, station);
   122 		owner, station);
   122 
   123 
   123 	if (station != INVALID_STATION) {
   124 	if (station != INVALID_STATION) {
   124 		const Vehicle *v;
   125 		const Vehicle *v;
   125 		FOR_ALL_VEHICLES(v) {
   126 		FOR_ALL_VEHICLES(v) {
   126 			if (v->type == type && (
   127 			if (v->type == type && (
   127 				(type == VEH_Train && IsFrontEngine(v)) ||
   128 						(type == VEH_Train && IsFrontEngine(v)) ||
   128 				(type != VEH_Train && v->subtype <= subtype))) {
   129 						(type != VEH_Train && v->subtype <= subtype)
       
   130 					)) {
   129 				const Order *order;
   131 				const Order *order;
   130 
   132 
   131 				FOR_VEHICLE_ORDERS(v, order) {
   133 				FOR_VEHICLE_ORDERS(v, order) {
   132 					if (order->type == OT_GOTO_STATION && order->station == station) {
   134 					if (order->type == OT_GOTO_STATION && order->station == station) {
   133 						sort_list[n].index = v->index;
   135 						sort_list[n].index = v->index;
   140 		}
   142 		}
   141 	} else {
   143 	} else {
   142 		const Vehicle *v;
   144 		const Vehicle *v;
   143 		FOR_ALL_VEHICLES(v) {
   145 		FOR_ALL_VEHICLES(v) {
   144 			if (v->type == type && v->owner == owner && (
   146 			if (v->type == type && v->owner == owner && (
   145 				(type == VEH_Train && IsFrontEngine(v)) ||
   147 						(type == VEH_Train && IsFrontEngine(v)) ||
   146 				(type != VEH_Train && v->subtype <= subtype))) {
   148 						(type != VEH_Train && v->subtype <= subtype)
       
   149 					)) {
   147 				sort_list[n].index = v->index;
   150 				sort_list[n].index = v->index;
   148 				sort_list[n].owner = v->owner;
   151 				sort_list[n].owner = v->owner;
   149 				++n;
   152 				++n;
   150 			}
   153 			}
   151 		}
   154 		}
   152 	}
   155 	}
   153 
   156 
   154 	free(vl->sort_list);
   157 	free(vl->sort_list);
   155 	vl->sort_list = malloc(n * sizeof(vl->sort_list[0]));
   158 	vl->sort_list = malloc(n * sizeof(vl->sort_list[0]));
   156 	if (n != 0 && vl->sort_list == NULL)
   159 	if (n != 0 && vl->sort_list == NULL) {
   157 		error("Could not allocate memory for the vehicle-sorting-list");
   160 		error("Could not allocate memory for the vehicle-sorting-list");
       
   161 	}
   158 	vl->list_length = n;
   162 	vl->list_length = n;
   159 
   163 
   160 	for (i = 0; i < n; ++i) vl->sort_list[i] = sort_list[i];
   164 	for (i = 0; i < n; ++i) vl->sort_list[i] = sort_list[i];
   161 	free(sort_list);
   165 	free(sort_list);
   162 
   166