mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Make more use of GetCargoAccepted/ProducedIndex().
This commit is contained in:
parent
29b20718ba
commit
633f19419d
|
@ -1017,12 +1017,9 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
|
|||
Industry *ind = i.industry;
|
||||
if (ind->index == source) continue;
|
||||
|
||||
uint cargo_index;
|
||||
for (cargo_index = 0; cargo_index < lengthof(ind->accepts_cargo); cargo_index++) {
|
||||
if (cargo_type == ind->accepts_cargo[cargo_index]) break;
|
||||
}
|
||||
int cargo_index = ind->GetCargoAcceptedIndex(cargo_type);
|
||||
/* Check if matching cargo has been found */
|
||||
if (cargo_index >= lengthof(ind->accepts_cargo)) continue;
|
||||
if (cargo_index < 0) continue;
|
||||
|
||||
/* Check if industry temporarily refuses acceptance */
|
||||
if (IndustryTemporarilyRefusesCargo(ind, cargo_type)) continue;
|
||||
|
|
|
@ -82,15 +82,12 @@
|
|||
if (!IsValidIndustry(industry_id)) return -1;
|
||||
if (!ScriptCargo::IsValidCargo(cargo_id)) return -1;
|
||||
|
||||
Industry *ind = ::Industry::Get(industry_id);
|
||||
for (uint i = 0; i < lengthof(ind->accepts_cargo); i++) {
|
||||
CargoID cid = ind->accepts_cargo[i];
|
||||
if (cid == cargo_id) {
|
||||
return ind->incoming_cargo_waiting[i];
|
||||
}
|
||||
}
|
||||
Industry *i = ::Industry::Get(industry_id);
|
||||
|
||||
return -1;
|
||||
int j = i->GetCargoAcceptedIndex(cargo_id);
|
||||
if (j < 0) return -1;
|
||||
|
||||
return i->incoming_cargo_waiting[j];
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptIndustry::GetLastMonthProduction(IndustryID industry_id, CargoID cargo_id)
|
||||
|
@ -100,11 +97,10 @@
|
|||
|
||||
const Industry *i = ::Industry::Get(industry_id);
|
||||
|
||||
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||
if (i->produced_cargo[j] == cargo_id) return i->last_month_production[j];
|
||||
}
|
||||
int j = i->GetCargoProducedIndex(cargo_id);
|
||||
if (j < 0) return -1;
|
||||
|
||||
return -1;
|
||||
return i->last_month_production[j];
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptIndustry::GetLastMonthTransported(IndustryID industry_id, CargoID cargo_id)
|
||||
|
@ -114,11 +110,10 @@
|
|||
|
||||
const Industry *i = ::Industry::Get(industry_id);
|
||||
|
||||
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||
if (i->produced_cargo[j] == cargo_id) return i->last_month_transported[j];
|
||||
}
|
||||
int j = i->GetCargoProducedIndex(cargo_id);
|
||||
if (j < 0) return -1;
|
||||
|
||||
return -1;
|
||||
return i->last_month_transported[j];
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptIndustry::GetLastMonthTransportedPercentage(IndustryID industry_id, CargoID cargo_id)
|
||||
|
@ -128,11 +123,10 @@
|
|||
|
||||
const Industry *i = ::Industry::Get(industry_id);
|
||||
|
||||
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||
if (i->produced_cargo[j] == cargo_id) return ::ToPercent8(i->last_month_pct_transported[j]);
|
||||
}
|
||||
int j = i->GetCargoProducedIndex(cargo_id);
|
||||
if (j < 0) return -1;
|
||||
|
||||
return -1;
|
||||
return ::ToPercent8(i->last_month_pct_transported[j]);
|
||||
}
|
||||
|
||||
/* static */ TileIndex ScriptIndustry::GetLocation(IndustryID industry_id)
|
||||
|
|
Loading…
Reference in New Issue