mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-10 08:00:05 +00:00
Codechange: Simplify usage of GRFFile cargo_map. (#11349)
This commit is contained in:
parent
69e20e79ab
commit
bc8e26f4e7
@ -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;
|
||||
|
@ -127,7 +127,7 @@ struct GRFFile : ZeroedMemoryAllocator {
|
||||
std::vector<GRFLabel> labels; ///< List of labels
|
||||
|
||||
std::vector<CargoLabel> cargo_list; ///< Cargo translation table (local ID -> label)
|
||||
uint8_t cargo_map[NUM_CARGO]; ///< Inverse cargo translation table (CargoID -> local ID)
|
||||
std::array<uint8_t, NUM_CARGO> cargo_map{}; ///< Inverse cargo translation table (CargoID -> local ID)
|
||||
|
||||
std::vector<RailTypeLabel> railtype_list; ///< Railtype translation table
|
||||
RailType railtype_map[RAILTYPE_END];
|
||||
|
Loading…
Reference in New Issue
Block a user