Skip to content

Commit

Permalink
(svn r23144) -Change: [NewGRF v8] Consider the 'default cargotype' pr…
Browse files Browse the repository at this point in the history
…operties as indices into the cargo translation table.
  • Loading branch information
frosch123 committed Nov 8, 2011
1 parent 449d679 commit 48f75a6
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/newgrf.cpp
Expand Up @@ -1004,11 +1004,15 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop
case 0x15: { // Cargo type
uint8 ctype = buf->ReadByte();

if (ctype < NUM_CARGO && HasBit(_cargo_mask, ctype)) {
ei->cargo_type = ctype;
} else if (ctype == 0xFF) {
if (ctype == 0xFF) {
/* 0xFF is specified as 'use first refittable' */
ei->cargo_type = CT_INVALID;
} else if (_cur.grffile->grf_version >= 8) {
/* Use translated cargo. Might result in CT_INVALID (first refittable), if cargo is not defined. */
ei->cargo_type = GetCargoTranslation(ctype, _cur.grffile);
} else if (ctype < NUM_CARGO && HasBit(_cargo_mask, ctype)) {
/* Use untranslated cargo. */
ei->cargo_type = ctype;
} else {
ei->cargo_type = CT_INVALID;
grfmsg(2, "RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
Expand Down Expand Up @@ -1214,15 +1218,20 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop
break;

case 0x10: { // Cargo type
uint8 cargo = buf->ReadByte();
uint8 ctype = buf->ReadByte();

if (cargo < NUM_CARGO && HasBit(_cargo_mask, cargo)) {
ei->cargo_type = cargo;
} else if (cargo == 0xFF) {
if (ctype == 0xFF) {
/* 0xFF is specified as 'use first refittable' */
ei->cargo_type = CT_INVALID;
} else if (_cur.grffile->grf_version >= 8) {
/* Use translated cargo. Might result in CT_INVALID (first refittable), if cargo is not defined. */
ei->cargo_type = GetCargoTranslation(ctype, _cur.grffile);
} else if (ctype < NUM_CARGO && HasBit(_cargo_mask, ctype)) {
/* Use untranslated cargo. */
ei->cargo_type = ctype;
} else {
ei->cargo_type = CT_INVALID;
grfmsg(2, "RoadVehicleChangeInfo: Invalid cargo type %d, using first refittable", cargo);
grfmsg(2, "RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
}
break;
}
Expand Down Expand Up @@ -1364,15 +1373,20 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop
break;

case 0x0C: { // Cargo type
uint8 cargo = buf->ReadByte();
uint8 ctype = buf->ReadByte();

if (cargo < NUM_CARGO && HasBit(_cargo_mask, cargo)) {
ei->cargo_type = cargo;
} else if (cargo == 0xFF) {
if (ctype == 0xFF) {
/* 0xFF is specified as 'use first refittable' */
ei->cargo_type = CT_INVALID;
} else if (_cur.grffile->grf_version >= 8) {
/* Use translated cargo. Might result in CT_INVALID (first refittable), if cargo is not defined. */
ei->cargo_type = GetCargoTranslation(ctype, _cur.grffile);
} else if (ctype < NUM_CARGO && HasBit(_cargo_mask, ctype)) {
/* Use untranslated cargo. */
ei->cargo_type = ctype;
} else {
ei->cargo_type = CT_INVALID;
grfmsg(2, "ShipVehicleChangeInfo: Invalid cargo type %d, using first refittable", cargo);
grfmsg(2, "RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
}
break;
}
Expand Down

0 comments on commit 48f75a6

Please sign in to comment.