1
0
Fork 0

(svn r27075) -Fix [FS#6182]: Variable 47 used the carge translation table of the wrong GRF in case of callback 1D.

release/1.5
frosch 2014-12-07 14:13:21 +00:00
parent 3a8990995e
commit c97d3c322f
1 changed files with 15 additions and 5 deletions

View File

@ -540,9 +540,14 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
/* The cargo translation is specific to the accessing GRF, and thus cannot be cached. */ /* 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; 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. /* Note:
* Note: The grffile == NULL case only happens if this function is called for default vehicles. * - Unlike everywhere else the cargo translation table is only used since grf version 8, not 7.
* And this is only done by CheckCaches(). */ * - For translating the cargo type we need to use the GRF which is resolving the variable, which
* is object->ro.grffile.
* In case of CBID_TRAIN_ALLOW_WAGON_ATTACH this is not the same as v->GetGRF().
* - The grffile == NULL case only happens if this function is called for default vehicles.
* And this is only done by CheckCaches().
*/
const GRFFile *grffile = object->ro.grffile; const GRFFile *grffile = object->ro.grffile;
uint8 common_bitnum = (common_cargo_type == CT_INVALID) ? 0xFF : uint8 common_bitnum = (common_cargo_type == CT_INVALID) ? 0xFF :
(grffile == NULL || grffile->grf_version < 8) ? CargoSpec::Get(common_cargo_type)->bitnum : grffile->cargo_map[common_cargo_type]; (grffile == NULL || grffile->grf_version < 8) ? CargoSpec::Get(common_cargo_type)->bitnum : grffile->cargo_map[common_cargo_type];
@ -605,7 +610,12 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
*/ */
const CargoSpec *cs = CargoSpec::Get(v->cargo_type); const CargoSpec *cs = CargoSpec::Get(v->cargo_type);
return (cs->classes << 16) | (cs->weight << 8) | v->GetGRF()->cargo_map[v->cargo_type]; /* Note:
* For translating the cargo type we need to use the GRF which is resolving the variable, which
* is object->ro.grffile.
* In case of CBID_TRAIN_ALLOW_WAGON_ATTACH this is not the same as v->GetGRF().
*/
return (cs->classes << 16) | (cs->weight << 8) | object->ro.grffile->cargo_map[v->cargo_type];
} }
case 0x48: return v->GetEngine()->flags; // Vehicle Type Info case 0x48: return v->GetEngine()->flags; // Vehicle Type Info
@ -897,7 +907,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
CargoID cargo_type = e->GetDefaultCargoType(); CargoID cargo_type = e->GetDefaultCargoType();
if (cargo_type != CT_INVALID) { if (cargo_type != CT_INVALID) {
const CargoSpec *cs = CargoSpec::Get(cargo_type); const CargoSpec *cs = CargoSpec::Get(cargo_type);
return (cs->classes << 16) | (cs->weight << 8) | e->GetGRF()->cargo_map[cargo_type]; return (cs->classes << 16) | (cs->weight << 8) | this->ro.grffile->cargo_map[cargo_type];
} else { } else {
return 0x000000FF; return 0x000000FF;
} }