src/station_gui.cpp
changeset 5609 dc6a58930ba4
parent 5608 0b0aff054402
child 5668 36b39f4a9032
equal deleted inserted replaced
5608:0b0aff054402 5609:dc6a58930ba4
   196 
   196 
   197 static void BuildStationsList(plstations_d* sl, PlayerID owner, byte facilities, uint16 cargo_filter)
   197 static void BuildStationsList(plstations_d* sl, PlayerID owner, byte facilities, uint16 cargo_filter)
   198 {
   198 {
   199 	uint n = 0;
   199 	uint n = 0;
   200 	uint i, j;
   200 	uint i, j;
   201 	const Station** station_sort;
       
   202 	const Station *st;
   201 	const Station *st;
   203 
   202 
   204 	if (!(sl->flags & SL_REBUILD)) return;
   203 	if (!(sl->flags & SL_REBUILD)) return;
   205 
   204 
   206 	/* Create array for sorting */
   205 	/* Create array for sorting */
   207 	MallocT(&station_sort, GetMaxStationIndex() + 1);
   206 	const Station** station_sort = MallocT<const Station*>(GetMaxStationIndex() + 1);
   208 	if (station_sort == NULL) error("Could not allocate memory for the station-sorting-list");
   207 	if (station_sort == NULL) error("Could not allocate memory for the station-sorting-list");
   209 
   208 
   210 	DEBUG(misc, 3, "Building station list for player %d", owner);
   209 	DEBUG(misc, 3, "Building station list for player %d", owner);
   211 
   210 
   212 	FOR_ALL_STATIONS(st) {
   211 	FOR_ALL_STATIONS(st) {
   229 			}
   228 			}
   230 		}
   229 		}
   231 	}
   230 	}
   232 
   231 
   233 	free((void*)sl->sort_list);
   232 	free((void*)sl->sort_list);
   234 	MallocT(&sl->sort_list, n);
   233 	sl->sort_list = MallocT<const Station*>(n);
   235 	if (n != 0 && sl->sort_list == NULL) error("Could not allocate memory for the station-sorting-list");
   234 	if (n != 0 && sl->sort_list == NULL) error("Could not allocate memory for the station-sorting-list");
   236 	sl->list_length = n;
   235 	sl->list_length = n;
   237 
   236 
   238 	for (i = 0; i < n; ++i) sl->sort_list[i] = station_sort[i];
   237 	for (i = 0; i < n; ++i) sl->sort_list[i] = station_sort[i];
   239 
   238