Fix: Iterate ProducedCargo correctly

This commit is contained in:
2025-07-16 18:08:16 +01:00
parent 465a84553c
commit 8b8341f402

View File

@@ -247,14 +247,15 @@ bool is_cached_industry(const Industry *ind) {
} }
MinimapIndustryKdtreeEntry get_industry_entry(const Industry *ind) { MinimapIndustryKdtreeEntry get_industry_entry(const Industry *ind) {
auto x = TileX(ind->location.tile) * TILE_SIZE + ind->location.w * TILE_SIZE / 2; auto x = TileX(ind->location.tile) * TILE_SIZE + ind->location.w * TILE_SIZE / 2;
auto y = TileY(ind->location.tile) * TILE_SIZE + ind->location.h * TILE_SIZE / 2; auto y = TileY(ind->location.tile) * TILE_SIZE + ind->location.h * TILE_SIZE / 2;
uint num_outputs = 0; uint num_outputs = std::ranges::count_if(
for (auto i = 0; i < INDUSTRY_NUM_OUTPUTS; i++) ind->produced, [](const Industry::ProducedCargo &p) {
if (ind->produced[i].cargo != INVALID_CARGO) return p.cargo != INVALID_CARGO;
num_outputs++; });
_max_industry_outputs = std::max(_max_industry_outputs, num_outputs);
return {(int16)((y - x) / 8), (int16)((y + x) / 8), ind->index}; _max_industry_outputs = std::max(_max_industry_outputs, num_outputs);
return {(int16)((y - x) / 8), (int16)((y + x) / 8), ind->index};
} }
void minimap_add_industry(const Industry *ind) { void minimap_add_industry(const Industry *ind) {
@@ -1034,18 +1035,18 @@ void SmallMapWindow::DrawIndustryProduction(const DrawPixelInfo *dpi) const
); );
IconTextSizeHelper its{SPR_CARGO_COAL, WidgetDimensions::scaled.framerect}; IconTextSizeHelper its{SPR_CARGO_COAL, WidgetDimensions::scaled.framerect};
for (auto i = 0; i < INDUSTRY_NUM_OUTPUTS; i++) { for (const auto& p : ind->produced) {
if (ind->produced[i].cargo == INVALID_CARGO) continue; if (p.cargo == INVALID_CARGO) continue;
its.add(GetString(STR_JUST_INT, ind->produced[i].history[LAST_MONTH].production), FS_SMALL); its.add(GetString(STR_JUST_INT, p.history[LAST_MONTH].production), FS_SMALL);
} }
its.calculate(); its.calculate();
this->industry_max_sign = maxdim(this->industry_max_sign, its.size); this->industry_max_sign = maxdim(this->industry_max_sign, its.size);
auto [r, ir] = its.make_rects(pt.x, pt.y); auto [r, ir] = its.make_rects(pt.x, pt.y);
GfxFillRect(r, PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOUR); GfxFillRect(r, PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOUR);
for (auto i = 0; i < INDUSTRY_NUM_OUTPUTS; i++) { for (const auto& p : ind->produced) {
if (ind->produced[i].cargo == INVALID_CARGO) continue; if (p.cargo == INVALID_CARGO) continue;
DrawSprite(CargoSpec::Get(ind->produced[i].cargo)->GetCargoIcon(), PAL_NONE, ir.left, ir.top + its.icon_ofs_y); DrawSprite(CargoSpec::Get(p.cargo)->GetCargoIcon(), PAL_NONE, ir.left, ir.top + its.icon_ofs_y);
auto str = GetString(STR_JUST_INT, ind->produced[i].history[LAST_MONTH].production); auto str = GetString(STR_JUST_INT, p.history[LAST_MONTH].production);
DrawString(ir.left + its.text_ofs_x, ir.right, ir.top + its.text_ofs_y, str, TC_WHITE, SA_LEFT, false, FS_SMALL); DrawString(ir.left + its.text_ofs_x, ir.right, ir.top + its.text_ofs_y, str, TC_WHITE, SA_LEFT, false, FS_SMALL);
ir.top += its.line_height; ir.top += its.line_height;
} }