MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / BuildStationsList

Method BuildStationsList

src/station_gui.cpp:303–342  ·  view source on GitHub ↗

* (Re)Build station list * * @param owner company whose stations are to be in list */

Source from the content-addressed store, hash-verified

301 * @param owner company whose stations are to be in list
302 */
303 void BuildStationsList(const Owner owner)
304 {
305 if (!this->stations.NeedRebuild()) return;
306
307 Debug(misc, 3, "Building station list for company {}", owner);
308
309 this->stations.clear();
310 this->stations_per_cargo_type.fill(0);
311 this->stations_per_cargo_type_no_rating = 0;
312
313 for (const Station *st : Station::Iterate()) {
314 if (this->filter.facilities.Any(st->facilities)) { // only stations with selected facilities
315 if (st->owner == owner || (st->owner == OWNER_NONE && HasStationInUse(st->index, true, owner))) {
316 bool has_rating = false;
317 /* Add to the station/cargo counts. */
318 for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
319 if (st->goods[cargo].HasRating()) this->stations_per_cargo_type[cargo]++;
320 }
321 for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
322 if (st->goods[cargo].HasRating()) {
323 has_rating = true;
324 if (HasBit(this->filter.cargoes, cargo)) {
325 this->stations.push_back(st);
326 break;
327 }
328 }
329 }
330 /* Stations with no cargo rating. */
331 if (!has_rating) {
332 if (this->filter.include_no_rating) this->stations.push_back(st);
333 this->stations_per_cargo_type_no_rating++;
334 }
335 }
336 }
337 }
338
339 this->stations.RebuildDone();
340
341 this->vscroll->SetCount(this->stations.size()); // Update the scrollbar
342 }
343
344 /** Sort stations by their name */
345 static bool StationNameSorter(const Station * const &a, const Station * const &b, const CargoTypes &)

Callers 1

OnPaintMethod · 0.95

Calls 11

HasStationInUseFunction · 0.85
HasBitFunction · 0.85
NeedRebuildMethod · 0.80
fillMethod · 0.80
AnyMethod · 0.80
HasRatingMethod · 0.80
push_backMethod · 0.80
RebuildDoneMethod · 0.80
clearMethod · 0.45
SetCountMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected