summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-02-23 09:56:20 +0000
committerpeter1138 <peter1138@openttd.org>2007-02-23 09:56:20 +0000
commit7e73413709b3f830d83338421298af5dc20581db (patch)
tree2fa52d1955fc03be8152cb9d7b298bfce4b80664 /src
parent0ed4b64e649349f695a1942e0fa09b8b564e1774 (diff)
downloadopenttd-7e73413709b3f830d83338421298af5dc20581db.tar.xz
(svn r8858) -Codechange: Replace magic number test with class method for determining if a cargo is valid/active.
Diffstat (limited to 'src')
-rw-r--r--src/cargotype.cpp6
-rw-r--r--src/cargotype.h2
-rw-r--r--src/newgrf_engine.cpp6
-rw-r--r--src/newgrf_station.cpp2
-rw-r--r--src/station_gui.cpp4
5 files changed, 15 insertions, 5 deletions
diff --git a/src/cargotype.cpp b/src/cargotype.cpp
index 0cfd7e2e9..28fbce38b 100644
--- a/src/cargotype.cpp
+++ b/src/cargotype.cpp
@@ -67,3 +67,9 @@ CargoID GetCargoIDByBitnum(byte bitnum)
assert(_cargo_bitnum_map[bitnum] != CT_INVALID);
return _cargo_bitnum_map[bitnum];
}
+
+
+bool CargoSpec::IsValid() const
+{
+ return bitnum != INVALID_CARGO;
+}
diff --git a/src/cargotype.h b/src/cargotype.h
index 65a5797cf..684e463ab 100644
--- a/src/cargotype.h
+++ b/src/cargotype.h
@@ -31,6 +31,8 @@ typedef struct CargoSpec {
SpriteID sprite;
uint16 classes;
+
+ bool IsValid() const;
} CargoSpec;
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 7e21cc8ec..1d21eb252 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -820,8 +820,10 @@ static const SpriteGroup *GetVehicleSpriteGroup(EngineID engine, const Vehicle *
if (v == NULL) {
cargo = GC_PURCHASE;
} else {
- cargo = GetCargo(v->cargo_type)->bitnum;
- assert(cargo != GC_INVALID);
+ const CargoSpec *cs = GetCargo(v->cargo_type);
+ assert(cs->IsValid());
+
+ cargo = cs->bitnum;
if (v->type == VEH_Train) {
group = GetWagonOverrideSpriteSet(engine, cargo, v->u.rail.first_engine);
diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp
index 2d4f69790..ce9846d68 100644
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -515,7 +515,7 @@ static const SpriteGroup *ResolveStation(ResolverObject *object)
/* Pick the first cargo that we have waiting */
for (CargoID cargo = 0; cargo < NUM_CARGO; 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) {
ctype = cs->bitnum;
break;
diff --git a/src/station_gui.cpp b/src/station_gui.cpp
index cc9bcb65b..7b7a2c341 100644
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -59,7 +59,7 @@ static StationSortListingTypeFunction StationRatingMaxSorter;
static void StationsWndShowStationRating(int x, int y, CargoID type, uint amount, byte rating)
{
const CargoSpec *cs = GetCargo(type);
- if (cs->bitnum == 0xFF) return;
+ if (!cs->IsValid()) return;
int colour = cs->rating_colour;
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;
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);
DrawStringCentered(x + 6 + cg_ofst, y + cg_ofst, cs->abbrev, 0x10);
}