mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
(svn r23502) -Fix (r23143): Vehicle var 42 used a cargo translation table of the wrong GRF.
This commit is contained in:
parent
89854e0ab1
commit
44dc83b73f
@ -481,7 +481,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const ResolverObject *object, byte
|
||||
}
|
||||
return v->grf_cache.position_same_id_length;
|
||||
|
||||
case 0x42: // Consist cargo information
|
||||
case 0x42: { // Consist cargo information
|
||||
if (!HasBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION)) {
|
||||
const Vehicle *u;
|
||||
byte cargo_classes = 0;
|
||||
@ -531,14 +531,22 @@ static uint32 VehicleGetVariable(Vehicle *v, const ResolverObject *object, byte
|
||||
}
|
||||
}
|
||||
|
||||
/* Unlike everywhere else the cargo translation table is only used since grf version 8, not 7. */
|
||||
const GRFFile *grffile = v->GetGRF();
|
||||
uint8 common_bitnum = (common_cargo_type == CT_INVALID) ? 0xFF :
|
||||
(grffile->grf_version < 8) ? CargoSpec::Get(common_cargo_type)->bitnum : grffile->cargo_map[common_cargo_type];
|
||||
v->grf_cache.consist_cargo_information = cargo_classes | (common_bitnum << 8) | (common_subtype << 16) | (user_def_data << 24);
|
||||
/* Note: We have to store the untranslated cargotype in the cache as the cache can be read by different NewGRFs,
|
||||
* which will need different translations */
|
||||
v->grf_cache.consist_cargo_information = cargo_classes | (common_cargo_type << 8) | (common_subtype << 16) | (user_def_data << 24);
|
||||
SetBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION);
|
||||
}
|
||||
return v->grf_cache.consist_cargo_information;
|
||||
|
||||
/* The cargo translation is specific to the accessing GRF, and thus cannot be cached. */
|
||||
CargoID common_cargo_type = (v->grf_cache.consist_cargo_information >> 8) & 0xFF;
|
||||
|
||||
/* Unlike everywhere else the cargo translation table is only used since grf version 8, not 7. */
|
||||
const GRFFile *grffile = object->grffile;
|
||||
uint8 common_bitnum = (common_cargo_type == CT_INVALID) ? 0xFF :
|
||||
(grffile->grf_version < 8) ? CargoSpec::Get(common_cargo_type)->bitnum : grffile->cargo_map[common_cargo_type];
|
||||
|
||||
return (v->grf_cache.consist_cargo_information & 0xFFFF00FF) | common_bitnum << 8;
|
||||
}
|
||||
|
||||
case 0x43: // Company information
|
||||
if (!HasBit(v->grf_cache.cache_valid, NCVV_COMPANY_INFORMATION)) {
|
||||
|
@ -60,7 +60,7 @@ struct NewGRFCache {
|
||||
/* Values calculated when they are requested for the first time after invalidating the NewGRF cache. */
|
||||
uint32 position_consist_length; ///< Cache for NewGRF var 40.
|
||||
uint32 position_same_id_length; ///< Cache for NewGRF var 41.
|
||||
uint32 consist_cargo_information; ///< Cache for NewGRF var 42.
|
||||
uint32 consist_cargo_information; ///< Cache for NewGRF var 42. (Note: The cargotype is untranslated in the cache because the accessing GRF is yet unknown.)
|
||||
uint32 company_information; ///< Cache for NewGRF var 43.
|
||||
uint8 cache_valid; ///< Bitset that indicates which cache values are valid.
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user