mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-23 04:04:09 +01:00
Add convenience helpers to correctly retrieve goods entry cargo available/totals. Avoids having to check if cargo data is available before accessing it, which was missing for autorefit.
This commit is contained in:
@@ -506,7 +506,7 @@ CargoTypes GetEmptyMask(const Station *st)
|
||||
CargoTypes mask = 0;
|
||||
|
||||
for (auto it = std::begin(st->goods); it != std::end(st->goods); ++it) {
|
||||
if (!it->HasData() || it->GetData().cargo.TotalCount() == 0) SetBit(mask, std::distance(std::begin(st->goods), it));
|
||||
if (it->TotalCount() == 0) SetBit(mask, std::distance(std::begin(st->goods), it));
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
@@ -3990,7 +3990,7 @@ static void UpdateStationRating(Station *st)
|
||||
|
||||
bool skip = false;
|
||||
int rating = 0;
|
||||
uint waiting = ge->HasData() ? ge->GetData().cargo.AvailableCount() : 0;
|
||||
uint waiting = ge->AvailableCount();
|
||||
|
||||
/* num_dests is at least 1 if there is any cargo as
|
||||
* StationID::Invalid() is also a destination.
|
||||
@@ -4098,12 +4098,12 @@ static void UpdateStationRating(Station *st)
|
||||
|
||||
/* We can't truncate cargo that's already reserved for loading.
|
||||
* Thus StoredCount() here. */
|
||||
if (waiting_changed && waiting < (ge->HasData() ? ge->GetData().cargo.AvailableCount() : 0)) {
|
||||
if (waiting_changed && waiting < ge->AvailableCount()) {
|
||||
/* Feed back the exact own waiting cargo at this station for the
|
||||
* next rating calculation. */
|
||||
ge->max_waiting_cargo = 0;
|
||||
|
||||
TruncateCargo(cs, ge, ge->GetData().cargo.AvailableCount() - waiting);
|
||||
TruncateCargo(cs, ge, ge->AvailableCount() - waiting);
|
||||
} else {
|
||||
/* If the average number per next hop is low, be more forgiving. */
|
||||
ge->max_waiting_cargo = waiting_avg;
|
||||
|
||||
Reference in New Issue
Block a user