diff --git a/src/newgrf.cpp b/src/newgrf.cpp index d6d5be5d5d..403b20f31e 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -8850,7 +8850,7 @@ void ResetPersistentNewGRFData() */ static void BuildCargoTranslationMap() { - memset(_cur.grffile->cargo_map, 0xFF, sizeof(_cur.grffile->cargo_map)); + _cur.grffile->cargo_map.fill(UINT8_MAX); for (const CargoSpec *cs : CargoSpec::Iterate()) { if (!cs->IsValid()) continue; @@ -9067,20 +9067,13 @@ static void CalculateRefitMasks() * cargo type. Finally disable the vehicle, if there is still no cargo. */ if (!IsValidCargoID(ei->cargo_type) && ei->refit_mask != 0) { /* Figure out which CTT to use for the default cargo, if it is 'first refittable'. */ - const uint8_t *cargo_map_for_first_refittable = nullptr; - { - const GRFFile *file = _gted[engine].defaultcargo_grf; - if (file == nullptr) file = e->GetGRF(); - if (file != nullptr && file->grf_version >= 8 && file->cargo_list.size() != 0) { - cargo_map_for_first_refittable = file->cargo_map; - } - } - - if (cargo_map_for_first_refittable != nullptr) { + const GRFFile *file = _gted[engine].defaultcargo_grf; + if (file == nullptr) file = e->GetGRF(); + if (file != nullptr && file->grf_version >= 8 && file->cargo_list.size() != 0) { /* Use first refittable cargo from cargo translation table */ - byte best_local_slot = 0xFF; + byte best_local_slot = UINT8_MAX; for (CargoID cargo_type : SetCargoBitIterator(ei->refit_mask)) { - byte local_slot = cargo_map_for_first_refittable[cargo_type]; + byte local_slot = file->cargo_map[cargo_type]; if (local_slot < best_local_slot) { best_local_slot = local_slot; ei->cargo_type = cargo_type; diff --git a/src/newgrf.h b/src/newgrf.h index e1412e9dd1..c23f6aad55 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -127,7 +127,7 @@ struct GRFFile : ZeroedMemoryAllocator { std::vector labels; ///< List of labels std::vector cargo_list; ///< Cargo translation table (local ID -> label) - uint8_t cargo_map[NUM_CARGO]; ///< Inverse cargo translation table (CargoID -> local ID) + std::array cargo_map{}; ///< Inverse cargo translation table (CargoID -> local ID) std::vector railtype_list; ///< Railtype translation table RailType railtype_map[RAILTYPE_END];