diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 6c42240ba3..ebbc316dba 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -415,22 +415,20 @@ static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, Ca const Industry *ind = Industry::GetByTile(tile); /* Starting point for acceptance */ - CargoID accepts_cargo[lengthof(itspec->accepts_cargo)]; - int8_t cargo_acceptance[lengthof(itspec->acceptance)]; - MemCpyT(accepts_cargo, itspec->accepts_cargo, lengthof(accepts_cargo)); - MemCpyT(cargo_acceptance, itspec->acceptance, lengthof(cargo_acceptance)); + auto accepts_cargo = itspec->accepts_cargo; + auto cargo_acceptance = itspec->acceptance; if (itspec->special_flags & INDTILE_SPECIAL_ACCEPTS_ALL_CARGO) { /* Copy all accepted cargoes from industry itself */ for (const auto &a : ind->accepted) { - CargoID *pos = std::find(accepts_cargo, endof(accepts_cargo), a.cargo); - if (pos == endof(accepts_cargo)) { + auto pos = std::find(std::begin(accepts_cargo), std::end(accepts_cargo), a.cargo); + if (pos == std::end(accepts_cargo)) { /* Not found, insert */ - pos = std::find(accepts_cargo, endof(accepts_cargo), CT_INVALID); - if (pos == endof(accepts_cargo)) continue; // nowhere to place, give up on this one + pos = std::find(std::begin(accepts_cargo), std::end(accepts_cargo), CT_INVALID); + if (pos == std::end(accepts_cargo)) continue; // nowhere to place, give up on this one *pos = a.cargo; } - cargo_acceptance[pos - accepts_cargo] += 8; + cargo_acceptance[std::distance(std::begin(accepts_cargo), pos)] += 8; } } @@ -438,7 +436,7 @@ static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, Ca /* Try callback for accepts list, if success override all existing accepts */ uint16_t res = GetIndustryTileCallback(CBID_INDTILE_ACCEPT_CARGO, 0, 0, gfx, Industry::GetByTile(tile), tile); if (res != CALLBACK_FAILED) { - MemSetT(accepts_cargo, CT_INVALID, lengthof(accepts_cargo)); + accepts_cargo.fill(CT_INVALID); for (uint i = 0; i < 3; i++) accepts_cargo[i] = GetCargoTranslation(GB(res, i * 5, 5), itspec->grf_prop.grffile); } } @@ -447,12 +445,12 @@ static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, Ca /* Try callback for acceptance list, if success override all existing acceptance */ uint16_t res = GetIndustryTileCallback(CBID_INDTILE_CARGO_ACCEPTANCE, 0, 0, gfx, Industry::GetByTile(tile), tile); if (res != CALLBACK_FAILED) { - MemSetT(cargo_acceptance, 0, lengthof(cargo_acceptance)); + cargo_acceptance.fill(0); for (uint i = 0; i < 3; i++) cargo_acceptance[i] = GB(res, i * 4, 4); } } - for (byte i = 0; i < lengthof(itspec->accepts_cargo); i++) { + for (byte i = 0; i < std::size(itspec->accepts_cargo); i++) { CargoID a = accepts_cargo[i]; if (!IsValidCargoID(a) || cargo_acceptance[i] <= 0) continue; // work only with valid cargoes diff --git a/src/industrytype.h b/src/industrytype.h index 153e4a0ff1..df2b5e6e51 100644 --- a/src/industrytype.h +++ b/src/industrytype.h @@ -152,8 +152,8 @@ struct IndustrySpec { * @note A tile can at most accept 3 types of cargo, even if an industry as a whole can accept more types. */ struct IndustryTileSpec { - CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]; ///< Cargo accepted by this tile - int8_t acceptance[INDUSTRY_NUM_INPUTS]; ///< Level of acceptance per cargo type (signed, may be negative!) + std::array accepts_cargo; ///< Cargo accepted by this tile + std::array acceptance; ///< Level of acceptance per cargo type (signed, may be negative!) Slope slopes_refused; ///< slope pattern on which this tile cannot be built byte anim_production; ///< Animation frame to start when goods are produced byte anim_next; ///< Next frame in an animation diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 8c76a04d0b..72687655ca 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -3295,12 +3295,12 @@ static ChangeInfoResult IndustrytilesChangeInfo(uint indtid, int numinfo, int pr case 0x13: { // variable length cargo acceptance byte num_cargoes = buf->ReadByte(); - if (num_cargoes > lengthof(tsp->acceptance)) { + if (num_cargoes > std::size(tsp->acceptance)) { GRFError *error = DisableGrf(STR_NEWGRF_ERROR_LIST_PROPERTY_TOO_LONG); error->param_value[1] = prop; return CIR_DISABLED; } - for (uint i = 0; i < lengthof(tsp->acceptance); i++) { + for (uint i = 0; i < std::size(tsp->acceptance); i++) { if (i < num_cargoes) { tsp->accepts_cargo[i] = GetCargoTranslation(buf->ReadByte(), _cur.grffile); /* Tile acceptance can be negative to counteract the INDTILE_SPECIAL_ACCEPTS_ALL_CARGO flag */