Codechange: Add IsCargoAccepted/Produced() helpers.

This commit is contained in:
Peter Nelson
2023-05-24 00:52:44 +01:00
committed by PeterN
parent 633f19419d
commit 09408e8e46
9 changed files with 40 additions and 65 deletions

View File

@@ -67,14 +67,10 @@
Industry *i = ::Industry::Get(industry_id);
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
if (i->accepts_cargo[j] == cargo_id) {
if (IndustryTemporarilyRefusesCargo(i, cargo_id)) return CAS_TEMP_REFUSED;
return CAS_ACCEPTED;
}
}
if (!i->IsCargoAccepted(cargo_id)) return CAS_NOT_ACCEPTED;
if (IndustryTemporarilyRefusesCargo(i, cargo_id)) return CAS_TEMP_REFUSED;
return CAS_NOT_ACCEPTED;
return CAS_ACCEPTED;
}
/* static */ SQInteger ScriptIndustry::GetStockpiledCargo(IndustryID industry_id, CargoID cargo_id)

View File

@@ -23,17 +23,13 @@ ScriptIndustryList::ScriptIndustryList()
ScriptIndustryList_CargoAccepting::ScriptIndustryList_CargoAccepting(CargoID cargo_id)
{
for (const Industry *i : Industry::Iterate()) {
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
if (i->accepts_cargo[j] == cargo_id) this->AddItem(i->index);
}
if (i->IsCargoAccepted(cargo_id)) this->AddItem(i->index);
}
}
ScriptIndustryList_CargoProducing::ScriptIndustryList_CargoProducing(CargoID cargo_id)
{
for (const Industry *i : Industry::Iterate()) {
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
if (i->produced_cargo[j] == cargo_id) this->AddItem(i->index);
}
if (i->IsCargoProduced(cargo_id)) this->AddItem(i->index);
}
}

View File

@@ -83,13 +83,7 @@ ScriptTileList_IndustryAccepting::ScriptTileList_IndustryAccepting(IndustryID in
if (i->neutral_station != nullptr && !_settings_game.station.serve_neutral_industries) return;
/* Check if this industry accepts anything */
{
bool cargo_accepts = false;
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
if (::IsValidCargoID(i->accepts_cargo[j])) cargo_accepts = true;
}
if (!cargo_accepts) return;
}
if (!i->IsCargoAccepted()) return;
if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED;
@@ -123,11 +117,7 @@ ScriptTileList_IndustryProducing::ScriptTileList_IndustryProducing(IndustryID in
if (i->neutral_station != nullptr && !_settings_game.station.serve_neutral_industries) return;
/* Check if this industry produces anything */
bool cargo_produces = false;
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
if (::IsValidCargoID(i->produced_cargo[j])) cargo_produces = true;
}
if (!cargo_produces) return;
if (!i->IsCargoProduced()) return;
if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED;