diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index aaf5792fd5..3b5d81f900 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -589,6 +589,19 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object, return v->grf_cache.position_same_id_length; case 0x42: { // Consist cargo information + if ((extra->mask & 0x00FFFFFF) == 0) { + if (!HasBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION_UD)) { + byte user_def_data = 0; + if (v->type == VEH_TRAIN) { + for (const Vehicle *u = v; u != nullptr; u = u->Next()) { + user_def_data |= Train::From(u)->tcache.user_def_data; + } + } + SB(v->grf_cache.consist_cargo_information, 24, 8, user_def_data); + SetBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION_UD); + } + return (v->grf_cache.consist_cargo_information & 0xFF000000); + } if (!HasBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION)) { const Vehicle *u; byte cargo_classes = 0; @@ -642,6 +655,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object, * 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); + SetBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION_UD); } /* The cargo translation is specific to the accessing GRF, and thus cannot be cached. */ @@ -1569,7 +1583,10 @@ void FillNewGRFVehicleCache(const Vehicle *v) { 0x43, NCVV_COMPANY_INFORMATION }, { 0x4D, NCVV_POSITION_IN_VEHICLE }, }; - static_assert(NCVV_END == lengthof(cache_entries)); + static const int partial_cache_entries[] = { + NCVV_CONSIST_CARGO_INFORMATION_UD, + }; + static_assert(NCVV_END == lengthof(cache_entries) + lengthof(partial_cache_entries)); /* Resolve all the variables, so their caches are set. */ for (size_t i = 0; i < lengthof(cache_entries); i++) { diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 63c4df32aa..226c1a0df2 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -73,6 +73,7 @@ enum NewGRFCacheValidValues { NCVV_CONSIST_CARGO_INFORMATION = 2, ///< This bit will be set if the NewGRF var 42 currently stored is valid. NCVV_COMPANY_INFORMATION = 3, ///< This bit will be set if the NewGRF var 43 currently stored is valid. NCVV_POSITION_IN_VEHICLE = 4, ///< This bit will be set if the NewGRF var 4D currently stored is valid. + NCVV_CONSIST_CARGO_INFORMATION_UD = 5, ///< This bit will be set if the uppermost byte of NewGRF var 42 currently stored is valid. NCVV_END, ///< End of the bits. };