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

Method SelectFirstAvailableAirport

src/airport_gui.cpp:541–567  ·  view source on GitHub ↗

* Select the first available airport. * @param change_class If true, change the class if no airport in the current * class is available. */

Source from the content-addressed store, hash-verified

539 * class is available.
540 */
541 void SelectFirstAvailableAirport(bool change_class)
542 {
543 /* First try to select an airport in the selected class. */
544 AirportClass *sel_apclass = AirportClass::Get(_selected_airport_class);
545 for (const AirportSpec *as : sel_apclass->Specs()) {
546 if (as->IsAvailable()) {
547 this->SelectOtherAirport(as->index);
548 return;
549 }
550 }
551 if (change_class) {
552 /* If that fails, select the first available airport
553 * from the first class where airports are available. */
554 for (const auto &cls : AirportClass::Classes()) {
555 for (const auto &as : cls.Specs()) {
556 if (as->IsAvailable()) {
557 _selected_airport_class = cls.Index();
558 this->vscroll->SetCount(cls.GetSpecCount());
559 this->SelectOtherAirport(as->index);
560 return;
561 }
562 }
563 }
564 }
565 /* If all airports are unavailable, select nothing. */
566 this->SelectOtherAirport(-1);
567 }
568
569 void OnDropdownSelect(WidgetID widget, int index, int) override
570 {

Callers 2

BuildAirportWindowMethod · 0.95
OnDropdownSelectMethod · 0.95

Calls 6

SelectOtherAirportMethod · 0.95
SpecsMethod · 0.80
GetSpecCountMethod · 0.80
IsAvailableMethod · 0.45
IndexMethod · 0.45
SetCountMethod · 0.45

Tested by

no test coverage detected