Mercurial > hg > openttd
diff src/station_gui.cpp @ 12418:0d8340a4c70e draft
(svn r16852) -Codechange: use FOR_ALL_CARGOSPECS for iterating over all valid CargoSpecs
author | smatz <smatz@openttd.org> |
---|---|
date | Thu, 16 Jul 2009 20:40:06 +0000 (2009-07-16) |
parents | 6a77d1df56e2 |
children | 499dee1c27b6 |
line wrap: on
line diff
--- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -257,8 +257,9 @@ /* 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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);