mirror of https://github.com/OpenTTD/OpenTTD
(svn r8858) -Codechange: Replace magic number test with class method for determining if a cargo is valid/active.
parent
0ed4b64e64
commit
7e73413709
|
@ -67,3 +67,9 @@ CargoID GetCargoIDByBitnum(byte bitnum)
|
||||||
assert(_cargo_bitnum_map[bitnum] != CT_INVALID);
|
assert(_cargo_bitnum_map[bitnum] != CT_INVALID);
|
||||||
return _cargo_bitnum_map[bitnum];
|
return _cargo_bitnum_map[bitnum];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool CargoSpec::IsValid() const
|
||||||
|
{
|
||||||
|
return bitnum != INVALID_CARGO;
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@ typedef struct CargoSpec {
|
||||||
SpriteID sprite;
|
SpriteID sprite;
|
||||||
|
|
||||||
uint16 classes;
|
uint16 classes;
|
||||||
|
|
||||||
|
bool IsValid() const;
|
||||||
} CargoSpec;
|
} CargoSpec;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -820,8 +820,10 @@ static const SpriteGroup *GetVehicleSpriteGroup(EngineID engine, const Vehicle *
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
cargo = GC_PURCHASE;
|
cargo = GC_PURCHASE;
|
||||||
} else {
|
} else {
|
||||||
cargo = GetCargo(v->cargo_type)->bitnum;
|
const CargoSpec *cs = GetCargo(v->cargo_type);
|
||||||
assert(cargo != GC_INVALID);
|
assert(cs->IsValid());
|
||||||
|
|
||||||
|
cargo = cs->bitnum;
|
||||||
|
|
||||||
if (v->type == VEH_Train) {
|
if (v->type == VEH_Train) {
|
||||||
group = GetWagonOverrideSpriteSet(engine, cargo, v->u.rail.first_engine);
|
group = GetWagonOverrideSpriteSet(engine, cargo, v->u.rail.first_engine);
|
||||||
|
|
|
@ -515,7 +515,7 @@ static const SpriteGroup *ResolveStation(ResolverObject *object)
|
||||||
/* Pick the first cargo that we have waiting */
|
/* Pick the first cargo that we have waiting */
|
||||||
for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
|
for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
|
||||||
const CargoSpec *cs = GetCargo(cargo);
|
const CargoSpec *cs = GetCargo(cargo);
|
||||||
if (cs->bitnum != 0xFF && object->u.station.statspec->spritegroup[cs->bitnum] != NULL &&
|
if (cs->IsValid() && object->u.station.statspec->spritegroup[cs->bitnum] != NULL &&
|
||||||
GB(object->u.station.st->goods[cargo].waiting_acceptance, 0, 12) != 0) {
|
GB(object->u.station.st->goods[cargo].waiting_acceptance, 0, 12) != 0) {
|
||||||
ctype = cs->bitnum;
|
ctype = cs->bitnum;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -59,7 +59,7 @@ static StationSortListingTypeFunction StationRatingMaxSorter;
|
||||||
static void StationsWndShowStationRating(int x, int y, CargoID type, uint amount, byte rating)
|
static void StationsWndShowStationRating(int x, int y, CargoID type, uint amount, byte rating)
|
||||||
{
|
{
|
||||||
const CargoSpec *cs = GetCargo(type);
|
const CargoSpec *cs = GetCargo(type);
|
||||||
if (cs->bitnum == 0xFF) return;
|
if (!cs->IsValid()) return;
|
||||||
|
|
||||||
int colour = cs->rating_colour;
|
int colour = cs->rating_colour;
|
||||||
uint w = (minu(amount, 576) + 5) / 36;
|
uint w = (minu(amount, 576) + 5) / 36;
|
||||||
|
@ -328,7 +328,7 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e)
|
||||||
cg_ofst = IsWindowWidgetLowered(w, i + STATIONLIST_WIDGET_CARGOSTART) ? 2 : 1;
|
cg_ofst = IsWindowWidgetLowered(w, i + STATIONLIST_WIDGET_CARGOSTART) ? 2 : 1;
|
||||||
|
|
||||||
const CargoSpec *cs = GetCargo(i);
|
const CargoSpec *cs = GetCargo(i);
|
||||||
if (cs->bitnum != 0xFF) {
|
if (cs->IsValid()) {
|
||||||
GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, cs->rating_colour);
|
GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, cs->rating_colour);
|
||||||
DrawStringCentered(x + 6 + cg_ofst, y + cg_ofst, cs->abbrev, 0x10);
|
DrawStringCentered(x + 6 + cg_ofst, y + cg_ofst, cs->abbrev, 0x10);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue