diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 96d82325dc..f682f0cc13 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -367,16 +367,18 @@ class BuildIndustryWindow : public Window { * @param prefixstr String to use for the first item * @return A formatted raw string */ - std::string MakeCargoListString(const CargoID *cargolist, const CargoSuffix *cargo_suffix, int cargolistlen, StringID prefixstr) const + std::string MakeCargoListString(const std::span cargolist, const std::span cargo_suffix, StringID prefixstr) const { - std::string cargostring; - int numcargo = 0; - int firstcargo = -1; + assert(cargolist.size() == cargo_suffix.size()); - for (int j = 0; j < cargolistlen; j++) { + std::string cargostring; + size_t numcargo = 0; + size_t firstcargo; + + for (size_t j = 0; j < cargolist.size(); j++) { if (!IsValidCargoID(cargolist[j])) continue; numcargo++; - if (firstcargo < 0) { + if (numcargo == 1) { firstcargo = j; continue; } @@ -452,7 +454,7 @@ public: /* Measure the accepted cargoes, if any. */ GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, indtype, indsp, indsp->accepts_cargo, cargo_suffix); - std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, lengthof(indsp->accepts_cargo), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO); + std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, STR_INDUSTRY_VIEW_REQUIRES_N_CARGO); Dimension strdim = GetStringBoundingBox(cargostring); if (strdim.width > max_minwidth) { extra_lines_req = std::max(extra_lines_req, strdim.width / max_minwidth + 1); @@ -462,7 +464,7 @@ public: /* Measure the produced cargoes, if any. */ GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, indtype, indsp, indsp->produced_cargo, cargo_suffix); - cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO); + cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, STR_INDUSTRY_VIEW_PRODUCES_N_CARGO); strdim = GetStringBoundingBox(cargostring); if (strdim.width > max_minwidth) { extra_lines_prd = std::max(extra_lines_prd, strdim.width / max_minwidth + 1); @@ -568,12 +570,12 @@ public: /* Draw the accepted cargoes, if any. Otherwise, will print "Nothing". */ GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, this->selected_type, indsp, indsp->accepts_cargo, cargo_suffix); - std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, lengthof(indsp->accepts_cargo), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO); + std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, STR_INDUSTRY_VIEW_REQUIRES_N_CARGO); ir.top = DrawStringMultiLine(ir, cargostring); /* Draw the produced cargoes, if any. Otherwise, will print "Nothing". */ GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, this->selected_type, indsp, indsp->produced_cargo, cargo_suffix); - cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO); + cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, STR_INDUSTRY_VIEW_PRODUCES_N_CARGO); ir.top = DrawStringMultiLine(ir, cargostring); /* Get the additional purchase info text, if it has not already been queried. */