summaryrefslogtreecommitdiff
path: root/src/station_gui.cpp
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-07-16 20:40:06 +0000
committersmatz <smatz@openttd.org>2009-07-16 20:40:06 +0000
commit77d13eae6194387ca6ce2b0eb835b7f97f67d085 (patch)
treea15b28b9384b9590cf11866a877097709db4d89d /src/station_gui.cpp
parent665fa7f9c170774f6a640ecf381f714b50b6b174 (diff)
downloadopenttd-77d13eae6194387ca6ce2b0eb835b7f97f67d085.tar.xz
(svn r16852) -Codechange: use FOR_ALL_CARGOSPECS for iterating over all valid CargoSpecs
Diffstat (limited to 'src/station_gui.cpp')
-rw-r--r--src/station_gui.cpp40
1 files changed, 17 insertions, 23 deletions
diff --git a/src/station_gui.cpp b/src/station_gui.cpp
index 310e2b0dd..f1cfb5b49 100644
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -257,8 +257,9 @@ public:
/* Add cargo filter buttons */
uint num_active = 0;
- for (CargoID c = 0; c < NUM_CARGO; c++) {
- if (CargoSpec::Get(c)->IsValid()) num_active++;
+ const CargoSpec *cs;
+ FOR_ALL_CARGOSPECS(cs) {
+ num_active++;
}
this->widget_count += num_active;
@@ -266,9 +267,7 @@ public:
this->widget[this->widget_count].type = WWT_LAST;
uint i = 0;
- for (CargoID c = 0; c < NUM_CARGO; c++) {
- if (!CargoSpec::Get(c)->IsValid()) continue;
-
+ FOR_ALL_CARGOSPECS(cs) {
Widget *wi = &this->widget[SLW_CARGOSTART + i];
wi->type = WWT_PANEL;
wi->display_flags = RESIZE_NONE;
@@ -280,7 +279,7 @@ public:
wi->data = 0;
wi->tooltips = STR_USE_CTRL_TO_SELECT_MORE;
- if (HasBit(this->cargo_filter, c)) this->LowerWidget(SLW_CARGOSTART + i);
+ if (HasBit(this->cargo_filter, cs->Index())) this->LowerWidget(SLW_CARGOSTART + i);
i++;
}
@@ -345,11 +344,9 @@ public:
int xb = 2; ///< offset from left of widget
uint i = 0;
- for (CargoID c = 0; c < NUM_CARGO; c++) {
- const CargoSpec *cs = CargoSpec::Get(c);
- if (!cs->IsValid()) continue;
-
- cg_ofst = HasBit(this->cargo_filter, c) ? 2 : 1;
+ const CargoSpec *cs;
+ FOR_ALL_CARGOSPECS(cs) {
+ cg_ofst = HasBit(this->cargo_filter, cs->Index()) ? 2 : 1;
GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, cs->rating_colour);
DrawString(x + cg_ofst, x + 12 + cg_ofst, y + cg_ofst, cs->abbrev, TC_BLACK, SA_CENTER);
x += 14;
@@ -456,8 +453,8 @@ public:
case SLW_CARGOALL: {
uint i = 0;
- for (CargoID c = 0; c < NUM_CARGO; c++) {
- if (!CargoSpec::Get(c)->IsValid()) continue;
+ const CargoSpec *cs;
+ FOR_ALL_CARGOSPECS(cs) {
this->LowerWidget(i + SLW_CARGOSTART);
i++;
}
@@ -504,16 +501,15 @@ public:
default:
if (widget >= SLW_CARGOSTART) { // change cargo_filter
/* Determine the selected cargo type */
- CargoID c;
int i = 0;
- for (c = 0; c < NUM_CARGO; c++) {
- if (!CargoSpec::Get(c)->IsValid()) continue;
+ const CargoSpec *cs;
+ FOR_ALL_CARGOSPECS(cs) {
if (widget - SLW_CARGOSTART == i) break;
i++;
}
if (_ctrl_pressed) {
- ToggleBit(this->cargo_filter, c);
+ ToggleBit(this->cargo_filter, cs->Index());
this->ToggleWidgetLoweredState(widget);
} else {
for (uint i = SLW_CARGOSTART; i < this->widget_count; i++) {
@@ -524,7 +520,7 @@ public:
this->cargo_filter = 0;
this->include_empty = false;
- SetBit(this->cargo_filter, c);
+ SetBit(this->cargo_filter, cs->Index());
this->LowerWidget(widget);
}
this->SetWidgetLoweredState(SLW_CARGOALL, this->cargo_filter == _cargo_mask && this->include_empty);
@@ -944,11 +940,9 @@ struct StationViewWindow : public Window {
DrawString(this->widget[SVW_ACCEPTLIST].left + 2, this->widget[SVW_ACCEPTLIST].right - 2, y, STR_STATION_VIEW_CARGO_RATINGS_TITLE);
y += 10;
- for (CargoID i = 0; i < NUM_CARGO; i++) {
- const CargoSpec *cs = CargoSpec::Get(i);
- if (!cs->IsValid()) continue;
-
- const GoodsEntry *ge = &st->goods[i];
+ const CargoSpec *cs;
+ FOR_ALL_CARGOSPECS(cs) {
+ const GoodsEntry *ge = &st->goods[cs->Index()];
if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue;
SetDParam(0, cs->name);