From fc1a616d9faacdd2ef4ca65104d7fbf995efbd41 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 5 Aug 2024 18:55:28 +0100 Subject: [PATCH] Change: Sort cargo list in build industry window. --- src/industry_gui.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index e32a8dc2d9..e51c377c22 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -377,8 +377,15 @@ class BuildIndustryWindow : public Window { size_t numcargo = 0; size_t firstcargo = 0; - for (size_t j = 0; j < cargolist.size(); j++) { - if (!IsValidCargoID(cargolist[j])) continue; + /* Use map to sort cargo list. The data is in two separate spans, so keep the index of each entry. */ + std::map positions; + for (auto it = std::begin(cargolist); it != std::end(cargolist); ++it) { + if (!IsValidCargoID(*it)) continue; + positions.emplace(*it, std::distance(std::begin(cargolist), it)); + } + + for (const auto &pair : positions) { + size_t j = pair.second; numcargo++; if (numcargo == 1) { firstcargo = j;