diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index bbe6034f60..94015c8cba 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -574,11 +574,12 @@ static uint GetCargoWeight(const CargoArray &cap, VehicleType vtype) static int DrawCargoCapacityInfo(int left, int right, int y, TestedEngineDetails &te, bool refittable) { - for (CargoID c = 0; c < NUM_CARGO; c++) { - if (te.all_capacities[c] == 0) continue; + for (const CargoSpec *cs : _sorted_cargo_specs) { + CargoID cid = cs->Index(); + if (te.all_capacities[cid] == 0) continue; - SetDParam(0, c); - SetDParam(1, te.all_capacities[c]); + SetDParam(0, cid); + SetDParam(1, te.all_capacities[cid]); SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY); DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY); y += FONT_HEIGHT_NORMAL; diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 97f34fba0b..5e9913ace4 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -876,7 +876,8 @@ struct DepotWindow : Window { static std::string details; details.clear(); - for (CargoID cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) { + for (const CargoSpec *cs : _sorted_cargo_specs) { + CargoID cargo_type = cs->Index(); if (capacity[cargo_type] == 0) continue; SetDParam(0, cargo_type); // {CARGO} #1 diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index ad129cee8c..d3cc1df0db 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -306,19 +306,20 @@ public: line << GetString(STR_LAND_AREA_INFORMATION_CARGO_ACCEPTED); bool found = false; - for (CargoID i = 0; i < NUM_CARGO; ++i) { - if (acceptance[i] > 0) { + for (const CargoSpec *cs : _sorted_cargo_specs) { + CargoID cid = cs->Index(); + if (acceptance[cid] > 0) { /* Add a comma between each item. */ if (found) line << ", "; found = true; /* If the accepted value is less than 8, show it in 1/8:ths */ - if (acceptance[i] < 8) { - SetDParam(0, acceptance[i]); - SetDParam(1, CargoSpec::Get(i)->name); + if (acceptance[cid] < 8) { + SetDParam(0, acceptance[cid]); + SetDParam(1, cs->name); line << GetString(STR_LAND_AREA_INFORMATION_CARGO_EIGHTS); } else { - line << GetString(CargoSpec::Get(i)->name); + line << GetString(cs->name); } } } diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp index 301b0c90a7..99654c6c7f 100644 --- a/src/roadveh_gui.cpp +++ b/src/roadveh_gui.cpp @@ -40,9 +40,7 @@ void DrawRoadVehDetails(const Vehicle *v, const Rect &r) if (v->HasArticulatedPart()) { CargoArray max_cargo{}; - StringID subtype_text[NUM_CARGO]; - - memset(subtype_text, 0, sizeof(subtype_text)); + std::array subtype_text{}; for (const Vehicle *u = v; u != nullptr; u = u->Next()) { max_cargo[u->cargo_type] += u->cargo_cap; @@ -55,16 +53,17 @@ void DrawRoadVehDetails(const Vehicle *v, const Rect &r) std::string capacity = GetString(STR_VEHICLE_DETAILS_TRAIN_ARTICULATED_RV_CAPACITY); bool first = true; - for (CargoID i = 0; i < NUM_CARGO; i++) { - if (max_cargo[i] > 0) { + for (const CargoSpec *cs : _sorted_cargo_specs) { + CargoID cid = cs->Index(); + if (max_cargo[cid] > 0) { if (!first) capacity += ", "; - SetDParam(0, i); - SetDParam(1, max_cargo[i]); + SetDParam(0, cid); + SetDParam(1, max_cargo[cid]); capacity += GetString(STR_JUST_CARGO); - if (subtype_text[i] != 0) { - capacity += GetString(subtype_text[i]); + if (subtype_text[cid] != STR_NULL) { + capacity += GetString(subtype_text[cid]); } first = false; diff --git a/src/train_gui.cpp b/src/train_gui.cpp index f8829688fd..34a6f6d370 100644 --- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -447,14 +447,15 @@ void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16_t v /* Indent the total cargo capacity details */ Rect ir = r.Indent(WidgetDimensions::scaled.hsep_indent, rtl); - for (CargoID i = 0; i < NUM_CARGO; i++) { - if (max_cargo[i] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) { - SetDParam(0, i); // {CARGO} #1 - SetDParam(1, act_cargo[i]); // {CARGO} #2 - SetDParam(2, i); // {SHORTCARGO} #1 - SetDParam(3, max_cargo[i]); // {SHORTCARGO} #2 + for (const CargoSpec *cs : _sorted_cargo_specs) { + CargoID cid = cs->Index(); + if (max_cargo[cid] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) { + SetDParam(0, cid); // {CARGO} #1 + SetDParam(1, act_cargo[cid]); // {CARGO} #2 + SetDParam(2, cid); // {SHORTCARGO} #1 + SetDParam(3, max_cargo[cid]); // {SHORTCARGO} #2 SetDParam(4, _settings_game.vehicle.freight_trains); - DrawString(ir.left, ir.right, y + text_y_offset, FreightWagonMult(i) > 1 ? STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_MULT : STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY); + DrawString(ir.left, ir.right, y + text_y_offset, FreightWagonMult(cid) > 1 ? STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_MULT : STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY); y += line_height; } }