diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 351941838d..3b26449563 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -854,7 +854,7 @@ struct BuildVehicleWindow : Window { /* Collect available cargo types for filtering. */ const CargoSpec *cs; - FOR_ALL_SORTED_CARGOSPECS(cs) { + FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { this->cargo_filter[filter_items] = cs->Index(); this->cargo_filter_texts[filter_items] = cs->name; filter_items++; diff --git a/src/cargotype.cpp b/src/cargotype.cpp index 01b5f425f8..ecad2308ed 100644 --- a/src/cargotype.cpp +++ b/src/cargotype.cpp @@ -116,7 +116,9 @@ SpriteID CargoSpec::GetCargoIcon() const } const CargoSpec *_sorted_cargo_specs[NUM_CARGO]; ///< Cargo specifications sorted alphabetically by name. -uint8 _sorted_cargo_specs_size; ///< Number of cargo specifications stored at the _sorted_cargo_specs array. +uint8 _sorted_cargo_specs_size; ///< Number of cargo specifications stored at the _sorted_cargo_specs array (including special cargos). +uint8 _sorted_standard_cargo_specs_size; ///< Number of standard cargo specifications stored at the _sorted_cargo_specs array. + /** Sort cargo specifications by their name. */ static int CDECL CargoSpecNameSorter(const CargoSpec * const *a, const CargoSpec * const *b) @@ -140,7 +142,10 @@ static int CDECL CargoSpecClassSorter(const CargoSpec * const *a, const CargoSpe if (res == 0) { res = ((*b)->classes & CC_MAIL) - ((*a)->classes & CC_MAIL); if (res == 0) { - return CargoSpecNameSorter(a, b); + res = ((*a)->classes & CC_SPECIAL) - ((*b)->classes & CC_SPECIAL); + if (res == 0) { + return CargoSpecNameSorter(a, b); + } } } @@ -151,15 +156,20 @@ static int CDECL CargoSpecClassSorter(const CargoSpec * const *a, const CargoSpe void InitializeSortedCargoSpecs() { _sorted_cargo_specs_size = 0; - CargoSpec *cargo; + const CargoSpec *cargo; /* Add each cargo spec to the list. */ FOR_ALL_CARGOSPECS(cargo) { - if ((cargo->classes & CC_SPECIAL) != 0) continue; // Exclude fake cargo types. _sorted_cargo_specs[_sorted_cargo_specs_size] = cargo; _sorted_cargo_specs_size++; } /* Sort cargo specifications by cargo class and name. */ QSortT(_sorted_cargo_specs, _sorted_cargo_specs_size, &CargoSpecClassSorter); + + _sorted_standard_cargo_specs_size = 0; + FOR_ALL_SORTED_CARGOSPECS(cargo) { + if (cargo->classes & CC_SPECIAL) break; + _sorted_standard_cargo_specs_size++; + } } diff --git a/src/cargotype.h b/src/cargotype.h index 4ce5e60f60..e9e3f6385e 100644 --- a/src/cargotype.h +++ b/src/cargotype.h @@ -134,6 +134,7 @@ CargoID GetCargoIDByBitnum(uint8 bitnum); void InitializeSortedCargoSpecs(); extern const CargoSpec *_sorted_cargo_specs[NUM_CARGO]; extern uint8 _sorted_cargo_specs_size; +extern uint8 _sorted_standard_cargo_specs_size; /** Does cargo \a c have cargo class \a cc? * @param c Cargo type. @@ -151,4 +152,6 @@ static inline bool IsCargoInClass(CargoID c, CargoClass cc) #define FOR_ALL_SORTED_CARGOSPECS(var) for (uint8 index = 0; var = _sorted_cargo_specs[index], index < _sorted_cargo_specs_size; index++) +#define FOR_ALL_SORTED_STANDARD_CARGOSPECS(var) for (uint8 index = 0; var = _sorted_cargo_specs[index], index < _sorted_standard_cargo_specs_size; index++) + #endif /* CARGOTYPE_H */ diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index 501c752c43..186b3bf8a0 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -851,7 +851,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow { int i = 0; const CargoSpec *cs; - FOR_ALL_SORTED_CARGOSPECS(cs) { + FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { if (HasBit(_legend_excluded_cargo, cs->Index())) SetBit(this->excluded_data, i); i++; } @@ -859,7 +859,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow { void UpdateLoweredWidgets() { - for (int i = 0; i < _sorted_cargo_specs_size; i++) { + for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) { this->SetWidgetLoweredState(CPW_CARGO_FIRST + i, !HasBit(this->excluded_data, i)); } } @@ -924,7 +924,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow { /* Add all cargos to the excluded lists. */ int i = 0; const CargoSpec *cs; - FOR_ALL_SORTED_CARGOSPECS(cs) { + FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { SetBit(_legend_excluded_cargo, cs->Index()); SetBit(this->excluded_data, i); i++; @@ -962,7 +962,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow { int i = 0; const CargoSpec *cs; - FOR_ALL_SORTED_CARGOSPECS(cs) { + FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { this->colours[i] = cs->legend_colour; for (uint j = 0; j != 20; j++) { this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->Index()); @@ -978,14 +978,14 @@ static NWidgetBase *MakeCargoButtons(int *biggest_index) { NWidgetVertical *ver = new NWidgetVertical; - for (int i = 0; i < _sorted_cargo_specs_size; i++) { + for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) { NWidgetBackground *leaf = new NWidgetBackground(WWT_PANEL, COLOUR_ORANGE, CPW_CARGO_FIRST + i, NULL); leaf->tool_tip = STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO; leaf->SetFill(1, 0); leaf->SetLowered(true); ver->Add(leaf); } - *biggest_index = CPW_CARGO_FIRST + _sorted_cargo_specs_size - 1; + *biggest_index = CPW_CARGO_FIRST + _sorted_standard_cargo_specs_size - 1; return ver; } diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 3fbe9c4653..f81bbceecf 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -1128,7 +1128,7 @@ struct StationViewWindow : public Window { y += FONT_HEIGHT_NORMAL; const CargoSpec *cs; - FOR_ALL_SORTED_CARGOSPECS(cs) { + FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { const GoodsEntry *ge = &st->goods[cs->Index()]; if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue;