(svn r23914) -Fix (r11252, r13855): Don't test validity of cargobits using a mask of cargoslots.

This commit is contained in:
frosch 2012-02-07 22:46:26 +00:00
parent 1c84468b5d
commit b1a3a31a83
1 changed files with 11 additions and 3 deletions

View File

@ -100,14 +100,22 @@ uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const
return group->GetCallbackResult();
}
/**
* Translate a GRF-local cargo slot/bitnum into a CargoID.
* @param cargo GRF-local cargo slot/bitnum.
* @param grffile Originating GRF file.
* @param usebit Defines the meaning of \a cargo for GRF version < 7.
* If true, then \a cargo is a bitnum. If false, then \a cargo is a cargoslot.
* For GRF version >= 7 \a cargo is always a translated cargo bit.
* @return CargoID or CT_INVALID if the cargo is not available.
*/
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
{
/* Pre-version 7 uses the 'climate dependent' ID, i.e. cargo is the cargo ID */
if (grffile->grf_version < 7) {
if (!usebit) return cargo;
/* Else the cargo value is a 'climate independent' 'bitnum' */
if (HasBit(_cargo_mask, cargo)) return GetCargoIDByBitnum(cargo);
return GetCargoIDByBitnum(cargo);
} else {
/* If the GRF contains a translation table... */
if (grffile->cargo_max > 0) {
@ -116,7 +124,7 @@ CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
if (cargo < grffile->cargo_max) return GetCargoIDByLabel(grffile->cargo_list[cargo]);
} else {
/* Else the cargo value is a 'climate independent' 'bitnum' */
if (HasBit(_cargo_mask, cargo)) return GetCargoIDByBitnum(cargo);
return GetCargoIDByBitnum(cargo);
}
}
return CT_INVALID;