Change: Reorganise industry accept/produce arrays. (#10853)

Use a array of struct for each cargo instead of an array for each statistic.
This makes iterating for acceptance and production much simpler.
pct_transported is now calculated when needed.
This commit is contained in:
PeterN
2023-05-25 21:25:46 +01:00
committed by GitHub
parent db3b086a52
commit 584faaf064
16 changed files with 527 additions and 355 deletions

View File

@@ -29,10 +29,9 @@ ScriptCargoList_IndustryAccepting::ScriptCargoList_IndustryAccepting(IndustryID
if (!ScriptIndustry::IsValidIndustry(industry_id)) return;
Industry *ind = ::Industry::Get(industry_id);
for (uint i = 0; i < lengthof(ind->accepts_cargo); i++) {
CargoID cargo_id = ind->accepts_cargo[i];
if (::IsValidCargoID(cargo_id)) {
this->AddItem(cargo_id);
for (const auto &a : ind->accepted) {
if (::IsValidCargoID(a.cargo)) {
this->AddItem(a.cargo);
}
}
}
@@ -42,10 +41,9 @@ ScriptCargoList_IndustryProducing::ScriptCargoList_IndustryProducing(IndustryID
if (!ScriptIndustry::IsValidIndustry(industry_id)) return;
Industry *ind = ::Industry::Get(industry_id);
for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
CargoID cargo_id = ind->produced_cargo[i];
if (::IsValidCargoID(cargo_id)) {
this->AddItem(cargo_id);
for (const auto &p : ind->produced) {
if (::IsValidCargoID(p.cargo)) {
this->AddItem(p.cargo);
}
}
}