Codechange: Use iterators and/or range-for on cargo related loops.

This commit is contained in:
Peter Nelson 2023-10-18 20:49:01 +01:00 committed by Peter Nelson
parent 2a88e0fab3
commit 9602de474d
16 changed files with 79 additions and 89 deletions

View File

@ -1370,9 +1370,9 @@ static void MaybeCrashAirplane(Aircraft *v)
if (GB(Random(), 0, 22) > prob) return; if (GB(Random(), 0, 22) > prob) return;
/* Crash the airplane. Remove all goods stored at the station. */ /* Crash the airplane. Remove all goods stored at the station. */
for (CargoID i = 0; i < NUM_CARGO; i++) { for (GoodsEntry &ge : st->goods) {
st->goods[i].rating = 1; ge.rating = 1;
st->goods[i].cargo.Truncate(); ge.cargo.Truncate();
} }
CrashAirplane(v); CrashAirplane(v);

View File

@ -2440,8 +2440,7 @@ static void ConDumpCargoTypes()
IConsolePrint(CC_DEFAULT, " S = special"); IConsolePrint(CC_DEFAULT, " S = special");
std::map<uint32_t, const GRFFile *> grfs; std::map<uint32_t, const GRFFile *> grfs;
for (CargoID i = 0; i < NUM_CARGO; i++) { for (const CargoSpec *spec : CargoSpec::Iterate()) {
const CargoSpec *spec = CargoSpec::Get(i);
if (!spec->IsValid()) continue; if (!spec->IsValid()) continue;
uint32_t grfid = 0; uint32_t grfid = 0;
const GRFFile *grf = spec->grffile; const GRFFile *grf = spec->grffile;
@ -2450,7 +2449,7 @@ static void ConDumpCargoTypes()
grfs.emplace(grfid, grf); grfs.emplace(grfid, grf);
} }
IConsolePrint(CC_DEFAULT, " {:02d} Bit: {:2d}, Label: {:c}{:c}{:c}{:c}, Callback mask: 0x{:02X}, Cargo class: {}{}{}{}{}{}{}{}{}{}{}, GRF: {:08X}, {}", IConsolePrint(CC_DEFAULT, " {:02d} Bit: {:2d}, Label: {:c}{:c}{:c}{:c}, Callback mask: 0x{:02X}, Cargo class: {}{}{}{}{}{}{}{}{}{}{}, GRF: {:08X}, {}",
(uint)i, spec->Index(),
spec->bitnum, spec->bitnum,
spec->label >> 24, spec->label >> 16, spec->label >> 8, spec->label, spec->label >> 24, spec->label >> 16, spec->label >> 8, spec->label,
spec->callback_mask, spec->callback_mask,

View File

@ -2566,8 +2566,7 @@ struct IndustryCargoesWindow : public Window {
/* Compute max size of the cargo texts. */ /* Compute max size of the cargo texts. */
this->cargo_textsize.width = 0; this->cargo_textsize.width = 0;
this->cargo_textsize.height = 0; this->cargo_textsize.height = 0;
for (uint i = 0; i < NUM_CARGO; i++) { for (const CargoSpec *csp : CargoSpec::Iterate()) {
const CargoSpec *csp = CargoSpec::Get(i);
if (!csp->IsValid()) continue; if (!csp->IsValid()) continue;
this->cargo_textsize = maxdim(this->cargo_textsize, GetStringBoundingBox(csp->name)); this->cargo_textsize = maxdim(this->cargo_textsize, GetStringBoundingBox(csp->name));
} }

View File

@ -8852,17 +8852,16 @@ static void BuildCargoTranslationMap()
{ {
memset(_cur.grffile->cargo_map, 0xFF, sizeof(_cur.grffile->cargo_map)); memset(_cur.grffile->cargo_map, 0xFF, sizeof(_cur.grffile->cargo_map));
for (CargoID c = 0; c < NUM_CARGO; c++) { for (const CargoSpec *cs : CargoSpec::Iterate()) {
const CargoSpec *cs = CargoSpec::Get(c);
if (!cs->IsValid()) continue; if (!cs->IsValid()) continue;
if (_cur.grffile->cargo_list.size() == 0) { if (_cur.grffile->cargo_list.size() == 0) {
/* Default translation table, so just a straight mapping to bitnum */ /* Default translation table, so just a straight mapping to bitnum */
_cur.grffile->cargo_map[c] = cs->bitnum; _cur.grffile->cargo_map[cs->Index()] = cs->bitnum;
} else { } else {
/* Check the translation table for this cargo's label */ /* Check the translation table for this cargo's label */
int idx = find_index(_cur.grffile->cargo_list, {cs->label}); int idx = find_index(_cur.grffile->cargo_list, {cs->label});
if (idx >= 0) _cur.grffile->cargo_map[c] = idx; if (idx >= 0) _cur.grffile->cargo_map[cs->Index()] = idx;
} }
} }
} }
@ -9184,8 +9183,7 @@ static void FinaliseEngineArray()
/** Check for invalid cargoes */ /** Check for invalid cargoes */
static void FinaliseCargoArray() static void FinaliseCargoArray()
{ {
for (CargoID c = 0; c < NUM_CARGO; c++) { for (CargoSpec *cs : CargoSpec::Iterate()) {
CargoSpec *cs = CargoSpec::Get(c);
if (!cs->IsValid()) { if (!cs->IsValid()) {
cs->name = cs->name_single = cs->units_volume = STR_NEWGRF_INVALID_CARGO; cs->name = cs->name_single = cs->units_volume = STR_NEWGRF_INVALID_CARGO;
cs->quantifier = STR_NEWGRF_INVALID_CARGO_QUANTITY; cs->quantifier = STR_NEWGRF_INVALID_CARGO_QUANTITY;

View File

@ -502,8 +502,8 @@ uint32_t Waypoint::GetNewGRFVariable(const ResolverObject &, byte variable, [[ma
break; break;
case CT_DEFAULT: case CT_DEFAULT:
for (CargoID cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) { for (const GoodsEntry &ge : st->goods) {
cargo += st->goods[cargo_type].cargo.TotalCount(); cargo += ge.cargo.TotalCount();
} }
break; break;

View File

@ -1300,11 +1300,11 @@ static void CheckCaches()
for (Industry *ind : Industry::Iterate()) old_industry_stations_near.push_back(ind->stations_near); for (Industry *ind : Industry::Iterate()) old_industry_stations_near.push_back(ind->stations_near);
for (Station *st : Station::Iterate()) { for (Station *st : Station::Iterate()) {
for (CargoID c = 0; c < NUM_CARGO; c++) { for (GoodsEntry &ge : st->goods) {
byte buff[sizeof(StationCargoList)]; byte buff[sizeof(StationCargoList)];
memcpy(buff, &st->goods[c].cargo, sizeof(StationCargoList)); memcpy(buff, &ge.cargo, sizeof(StationCargoList));
st->goods[c].cargo.InvalidateCache(); ge.cargo.InvalidateCache();
assert(memcmp(&st->goods[c].cargo, buff, sizeof(StationCargoList)) == 0); assert(memcmp(&ge.cargo, buff, sizeof(StationCargoList)) == 0);
} }
/* Check docking tiles */ /* Check docking tiles */

View File

@ -1690,9 +1690,9 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_74)) { if (IsSavegameVersionBefore(SLV_74)) {
for (Station *st : Station::Iterate()) { for (Station *st : Station::Iterate()) {
for (CargoID c = 0; c < NUM_CARGO; c++) { for (GoodsEntry &ge : st->goods) {
st->goods[c].last_speed = 0; ge.last_speed = 0;
if (st->goods[c].cargo.AvailableCount() != 0) SetBit(st->goods[c].status, GoodsEntry::GES_RATING); if (ge.cargo.AvailableCount() != 0) SetBit(ge.status, GoodsEntry::GES_RATING);
} }
} }
} }

View File

@ -43,10 +43,8 @@
* information is lost. In that case we set it to the position of this * information is lost. In that case we set it to the position of this
* station */ * station */
for (Station *st : Station::Iterate()) { for (Station *st : Station::Iterate()) {
for (CargoID c = 0; c < NUM_CARGO; c++) { for (GoodsEntry &ge : st->goods) {
GoodsEntry *ge = &st->goods[c]; const StationCargoPacketMap *packets = ge.cargo.Packets();
const StationCargoPacketMap *packets = ge->cargo.Packets();
for (StationCargoList::ConstIterator it(packets->begin()); it != packets->end(); it++) { for (StationCargoList::ConstIterator it(packets->begin()); it != packets->end(); it++) {
CargoPacket *cp = *it; CargoPacket *cp = *it;
cp->source_xy = Station::IsValidID(cp->first_station) ? Station::Get(cp->first_station)->xy : st->xy; cp->source_xy = Station::IsValidID(cp->first_station) ? Station::Get(cp->first_station)->xy : st->xy;
@ -69,7 +67,7 @@
for (Vehicle *v : Vehicle::Iterate()) v->cargo.InvalidateCache(); for (Vehicle *v : Vehicle::Iterate()) v->cargo.InvalidateCache();
for (Station *st : Station::Iterate()) { for (Station *st : Station::Iterate()) {
for (CargoID c = 0; c < NUM_CARGO; c++) st->goods[c].cargo.InvalidateCache(); for (GoodsEntry &ge : st->goods) ge.cargo.InvalidateCache();
} }
} }
@ -81,9 +79,8 @@
if (IsSavegameVersionBefore(SLV_CARGO_TRAVELLED)) { if (IsSavegameVersionBefore(SLV_CARGO_TRAVELLED)) {
/* Update the cargo-traveled in stations as if they arrived from the source tile. */ /* Update the cargo-traveled in stations as if they arrived from the source tile. */
for (Station *st : Station::Iterate()) { for (Station *st : Station::Iterate()) {
for (size_t i = 0; i < NUM_CARGO; i++) { for (GoodsEntry &ge : st->goods) {
GoodsEntry *ge = &st->goods[i]; for (auto it = ge.cargo.Packets()->begin(); it != ge.cargo.Packets()->end(); ++it) {
for (auto it = ge->cargo.Packets()->begin(); it != ge->cargo.Packets()->end(); it++) {
for (CargoPacket *cp : it->second) { for (CargoPacket *cp : it->second) {
if (cp->source_xy != INVALID_TILE && cp->source_xy != st->xy) { if (cp->source_xy != INVALID_TILE && cp->source_xy != st->xy) {
cp->travelled.x = TileX(cp->source_xy) - TileX(st->xy); cp->travelled.x = TileX(cp->source_xy) - TileX(st->xy);

View File

@ -412,8 +412,8 @@ public:
SlSetStructListLength(NUM_CARGO); SlSetStructListLength(NUM_CARGO);
for (CargoID i = 0; i < NUM_CARGO; i++) { for (GoodsEntry &ge : st->goods) {
SlObject(&st->goods[i], this->GetDescription()); SlObject(&ge, this->GetDescription());
} }
} }
@ -429,15 +429,15 @@ public:
std::copy(std::begin(_old_st_persistent_storage.storage), std::end(_old_st_persistent_storage.storage), std::begin(st->airport.psa->storage)); std::copy(std::begin(_old_st_persistent_storage.storage), std::end(_old_st_persistent_storage.storage), std::begin(st->airport.psa->storage));
} }
size_t num_cargo = this->GetNumCargo(); auto end = std::next(std::begin(st->goods), std::min(this->GetNumCargo(), std::size(st->goods)));
for (size_t i = 0; i < num_cargo; i++) { for (auto it = std::begin(st->goods); it != end; ++it) {
GoodsEntry *ge = &st->goods[i]; GoodsEntry &ge = *it;
SlObject(ge, this->GetLoadDescription()); SlObject(&ge, this->GetLoadDescription());
if (IsSavegameVersionBefore(SLV_183)) { if (IsSavegameVersionBefore(SLV_183)) {
SwapPackets(ge); SwapPackets(&ge);
} }
if (IsSavegameVersionBefore(SLV_68)) { if (IsSavegameVersionBefore(SLV_68)) {
SB(ge->status, GoodsEntry::GES_ACCEPTANCE, 1, HasBit(_waiting_acceptance, 15)); SB(ge.status, GoodsEntry::GES_ACCEPTANCE, 1, HasBit(_waiting_acceptance, 15));
if (GB(_waiting_acceptance, 0, 12) != 0) { if (GB(_waiting_acceptance, 0, 12) != 0) {
/* In old versions, enroute_from used 0xFF as INVALID_STATION */ /* In old versions, enroute_from used 0xFF as INVALID_STATION */
StationID source = (IsSavegameVersionBefore(SLV_7) && _cargo_source == 0xFF) ? INVALID_STATION : _cargo_source; StationID source = (IsSavegameVersionBefore(SLV_7) && _cargo_source == 0xFF) ? INVALID_STATION : _cargo_source;
@ -450,8 +450,8 @@ public:
/* Don't construct the packet with station here, because that'll fail with old savegames */ /* Don't construct the packet with station here, because that'll fail with old savegames */
CargoPacket *cp = new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_periods, source, _cargo_source_xy, _cargo_feeder_share); CargoPacket *cp = new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_periods, source, _cargo_source_xy, _cargo_feeder_share);
ge->cargo.Append(cp, INVALID_STATION); ge.cargo.Append(cp, INVALID_STATION);
SB(ge->status, GoodsEntry::GES_RATING, 1, 1); SB(ge.status, GoodsEntry::GES_RATING, 1, 1);
} }
} }
} }
@ -461,15 +461,16 @@ public:
{ {
Station *st = Station::From(bst); Station *st = Station::From(bst);
uint num_cargo = IsSavegameVersionBefore(SLV_55) ? 12 : IsSavegameVersionBefore(SLV_EXTEND_CARGOTYPES) ? 32 : NUM_CARGO; size_t num_cargo = IsSavegameVersionBefore(SLV_55) ? 12 : IsSavegameVersionBefore(SLV_EXTEND_CARGOTYPES) ? 32 : NUM_CARGO;
for (CargoID i = 0; i < num_cargo; i++) { auto end = std::next(std::begin(st->goods), std::min(num_cargo, std::size(st->goods)));
GoodsEntry *ge = &st->goods[i]; for (auto it = std::begin(st->goods); it != end; ++it) {
GoodsEntry &ge = *it;
if (IsSavegameVersionBefore(SLV_183)) { if (IsSavegameVersionBefore(SLV_183)) {
SwapPackets(ge); // We have to swap back again to be in the format pre-183 expects. SwapPackets(&ge); // We have to swap back again to be in the format pre-183 expects.
SlObject(ge, this->GetDescription()); SlObject(&ge, this->GetDescription());
SwapPackets(ge); SwapPackets(&ge);
} else { } else {
SlObject(ge, this->GetDescription()); SlObject(&ge, this->GetDescription());
} }
} }
} }

View File

@ -139,9 +139,9 @@ public:
void Save(Town *t) const override void Save(Town *t) const override
{ {
SlSetStructListLength(NUM_CARGO); SlSetStructListLength(std::size(t->supplied));
for (CargoID i = 0; i < NUM_CARGO; i++) { for (auto &supplied : t->supplied) {
SlObject(&t->supplied[i], this->GetDescription()); SlObject(&supplied, this->GetDescription());
} }
} }
@ -166,9 +166,9 @@ public:
void Save(Town *t) const override void Save(Town *t) const override
{ {
SlSetStructListLength(NUM_TE); SlSetStructListLength(std::size(t->received));
for (size_t i = TE_BEGIN; i < TE_END; i++) { for (auto &received : t->received) {
SlObject(&t->received[i], this->GetDescription()); SlObject(&received, this->GetDescription());
} }
} }

View File

@ -71,8 +71,8 @@
const IndustrySpec *ins = ::GetIndustrySpec(industry_type); const IndustrySpec *ins = ::GetIndustrySpec(industry_type);
ScriptList *list = new ScriptList(); ScriptList *list = new ScriptList();
for (size_t i = 0; i < lengthof(ins->produced_cargo); i++) { for (const CargoID &c : ins->produced_cargo) {
if (::IsValidCargoID(ins->produced_cargo[i])) list->AddItem(ins->produced_cargo[i]); if (::IsValidCargoID(c)) list->AddItem(c);
} }
return list; return list;
@ -85,8 +85,8 @@
const IndustrySpec *ins = ::GetIndustrySpec(industry_type); const IndustrySpec *ins = ::GetIndustrySpec(industry_type);
ScriptList *list = new ScriptList(); ScriptList *list = new ScriptList();
for (size_t i = 0; i < lengthof(ins->accepts_cargo); i++) { for (const CargoID &c : ins->accepts_cargo) {
if (::IsValidCargoID(ins->accepts_cargo[i])) list->AddItem(ins->accepts_cargo[i]); if (::IsValidCargoID(c)) list->AddItem(c);
} }
return list; return list;

View File

@ -83,8 +83,8 @@ Station::Station(TileIndex tile) :
Station::~Station() Station::~Station()
{ {
if (CleaningPool()) { if (CleaningPool()) {
for (CargoID c = 0; c < NUM_CARGO; c++) { for (GoodsEntry &ge : this->goods) {
this->goods[c].cargo.OnCleanPool(); ge.cargo.OnCleanPool();
} }
return; return;
} }
@ -148,8 +148,8 @@ Station::~Station()
/* Remove all news items */ /* Remove all news items */
DeleteStationNews(this->index); DeleteStationNews(this->index);
for (CargoID c = 0; c < NUM_CARGO; c++) { for (GoodsEntry &ge : this->goods) {
this->goods[c].cargo.Truncate(); ge.cargo.Truncate();
} }
CargoPacket::InvalidateAllFrom(this->index); CargoPacket::InvalidateAllFrom(this->index);

View File

@ -496,8 +496,8 @@ CargoTypes GetAcceptanceMask(const Station *st)
{ {
CargoTypes mask = 0; CargoTypes mask = 0;
for (CargoID i = 0; i < NUM_CARGO; i++) { for (auto it = std::begin(st->goods); it != std::end(st->goods); ++it) {
if (HasBit(st->goods[i].status, GoodsEntry::GES_ACCEPTANCE)) SetBit(mask, i); if (HasBit(it->status, GoodsEntry::GES_ACCEPTANCE)) SetBit(mask, std::distance(std::begin(st->goods), it));
} }
return mask; return mask;
} }
@ -511,8 +511,8 @@ CargoTypes GetEmptyMask(const Station *st)
{ {
CargoTypes mask = 0; CargoTypes mask = 0;
for (CargoID i = 0; i < NUM_CARGO; i++) { for (auto it = std::begin(st->goods); it != std::end(st->goods); ++it) {
if (st->goods[i].cargo.TotalCount() == 0) SetBit(mask, i); if (it->cargo.TotalCount() == 0) SetBit(mask, std::distance(std::begin(st->goods), it));
} }
return mask; return mask;
} }
@ -704,10 +704,10 @@ static void UpdateStationSignCoord(BaseStation *st)
if (!Station::IsExpected(st)) return; if (!Station::IsExpected(st)) return;
Station *full_station = Station::From(st); Station *full_station = Station::From(st);
for (CargoID c = 0; c < NUM_CARGO; ++c) { for (const GoodsEntry &ge : full_station->goods) {
LinkGraphID lg = full_station->goods[c].link_graph; LinkGraphID lg = ge.link_graph;
if (!LinkGraph::IsValidID(lg)) continue; if (!LinkGraph::IsValidID(lg)) continue;
(*LinkGraph::Get(lg))[full_station->goods[c].node].UpdateLocation(st->xy); (*LinkGraph::Get(lg))[ge.node].UpdateLocation(st->xy);
} }
} }
@ -3595,8 +3595,8 @@ static bool StationHandleBigTick(BaseStation *st)
if (Station::IsExpected(st)) { if (Station::IsExpected(st)) {
TriggerWatchedCargoCallbacks(Station::From(st)); TriggerWatchedCargoCallbacks(Station::From(st));
for (CargoID i = 0; i < NUM_CARGO; i++) { for (GoodsEntry &ge : Station::From(st)->goods) {
ClrBit(Station::From(st)->goods[i].status, GoodsEntry::GES_ACCEPTED_BIGTICK); ClrBit(ge.status, GoodsEntry::GES_ACCEPTED_BIGTICK);
} }
} }
@ -4027,10 +4027,9 @@ void OnTick_Station()
static IntervalTimer<TimerGameCalendar> _stations_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::STATION}, [](auto) static IntervalTimer<TimerGameCalendar> _stations_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::STATION}, [](auto)
{ {
for (Station *st : Station::Iterate()) { for (Station *st : Station::Iterate()) {
for (CargoID i = 0; i < NUM_CARGO; i++) { for (GoodsEntry &ge : st->goods) {
GoodsEntry *ge = &st->goods[i]; SB(ge.status, GoodsEntry::GES_LAST_MONTH, 1, GB(ge.status, GoodsEntry::GES_CURRENT_MONTH, 1));
SB(ge->status, GoodsEntry::GES_LAST_MONTH, 1, GB(ge->status, GoodsEntry::GES_CURRENT_MONTH, 1)); ClrBit(ge.status, GoodsEntry::GES_CURRENT_MONTH);
ClrBit(ge->status, GoodsEntry::GES_CURRENT_MONTH);
} }
} }
}); });
@ -4039,11 +4038,9 @@ void ModifyStationRatingAround(TileIndex tile, Owner owner, int amount, uint rad
{ {
ForAllStationsRadius(tile, radius, [&](Station *st) { ForAllStationsRadius(tile, radius, [&](Station *st) {
if (st->owner == owner && DistanceManhattan(tile, st->xy) <= radius) { if (st->owner == owner && DistanceManhattan(tile, st->xy) <= radius) {
for (CargoID i = 0; i < NUM_CARGO; i++) { for (GoodsEntry &ge : st->goods) {
GoodsEntry *ge = &st->goods[i]; if (ge.status != 0) {
ge.rating = ClampTo<uint8_t>(ge.rating + amount);
if (ge->status != 0) {
ge->rating = ClampTo<uint8_t>(ge->rating + amount);
} }
} }
} }

View File

@ -330,8 +330,7 @@ protected:
byte minr1 = 255; byte minr1 = 255;
byte minr2 = 255; byte minr2 = 255;
for (CargoID j = 0; j < NUM_CARGO; j++) { for (CargoID j : SetCargoBitIterator(cargo_filter)) {
if (!HasBit(cargo_filter, j)) continue;
if (a->goods[j].HasRating()) minr1 = std::min(minr1, a->goods[j].rating); if (a->goods[j].HasRating()) minr1 = std::min(minr1, a->goods[j].rating);
if (b->goods[j].HasRating()) minr2 = std::min(minr2, b->goods[j].rating); if (b->goods[j].HasRating()) minr2 = std::min(minr2, b->goods[j].rating);
} }

View File

@ -3277,7 +3277,7 @@ static CommandCost TownActionBribe(Town *t, DoCommandFlag flags)
/* set all close by station ratings to 0 */ /* set all close by station ratings to 0 */
for (Station *st : Station::Iterate()) { for (Station *st : Station::Iterate()) {
if (st->town == t && st->owner == _current_company) { if (st->town == t && st->owner == _current_company) {
for (CargoID i = 0; i < NUM_CARGO; i++) st->goods[i].rating = 0; for (GoodsEntry &ge : st->goods) ge.rating = 0;
} }
} }
@ -3554,8 +3554,8 @@ static void UpdateTownGrowth(Town *t)
static void UpdateTownAmounts(Town *t) static void UpdateTownAmounts(Town *t)
{ {
for (CargoID i = 0; i < NUM_CARGO; i++) t->supplied[i].NewMonth(); for (auto &supplied : t->supplied) supplied.NewMonth();
for (int i = TE_BEGIN; i < TE_END; i++) t->received[i].NewMonth(); for (auto &received : t->received) received.NewMonth();
if (t->fund_buildings_months != 0) t->fund_buildings_months--; if (t->fund_buildings_months != 0) t->fund_buildings_months--;
SetWindowDirty(WC_TOWN_VIEW, t->index); SetWindowDirty(WC_TOWN_VIEW, t->index);

View File

@ -47,16 +47,16 @@ void CcStartStopVehicle(Commands cmd, const CommandCost &result, VehicleID veh_i
template <typename Tcont, typename Titer> template <typename Tcont, typename Titer>
inline EndianBufferWriter<Tcont, Titer> &operator <<(EndianBufferWriter<Tcont, Titer> &buffer, const CargoArray &cargo_array) inline EndianBufferWriter<Tcont, Titer> &operator <<(EndianBufferWriter<Tcont, Titer> &buffer, const CargoArray &cargo_array)
{ {
for (CargoID c = 0; c < NUM_CARGO; c++) { for (const uint &amt : cargo_array) {
buffer << cargo_array[c]; buffer << amt;
} }
return buffer; return buffer;
} }
inline EndianBufferReader &operator >>(EndianBufferReader &buffer, CargoArray &cargo_array) inline EndianBufferReader &operator >>(EndianBufferReader &buffer, CargoArray &cargo_array)
{ {
for (CargoID c = 0; c < NUM_CARGO; c++) { for (uint &amt : cargo_array) {
buffer >> cargo_array[c]; buffer >> amt;
} }
return buffer; return buffer;
} }