(svn r19790) -Change: use the typed FOR_EACH_SET_BIT for CargoIDs (adf88)

This commit is contained in:
rubidium 2010-05-11 21:01:01 +00:00
parent 115a4ee734
commit fa7c8be0b8
2 changed files with 19 additions and 17 deletions

View File

@ -150,6 +150,8 @@ static inline bool IsCargoInClass(CargoID c, CargoClass cc)
if ((var = CargoSpec::Get(cargospec_index))->IsValid()) if ((var = CargoSpec::Get(cargospec_index))->IsValid())
#define FOR_ALL_CARGOSPECS(var) FOR_ALL_CARGOSPECS_FROM(var, 0) #define FOR_ALL_CARGOSPECS(var) FOR_ALL_CARGOSPECS_FROM(var, 0)
#define FOR_EACH_SET_CARGO_ID(var, cargo_bits) FOR_EACH_SET_BIT_EX(CargoID, var, uint, cargo_bits)
#define FOR_ALL_SORTED_CARGOSPECS(var) for (uint8 index = 0; var = _sorted_cargo_specs[index], index < _sorted_cargo_specs_size; index++) #define FOR_ALL_SORTED_CARGOSPECS(var) for (uint8 index = 0; var = _sorted_cargo_specs[index], index < _sorted_cargo_specs_size; index++)
#define FOR_ALL_SORTED_STANDARD_CARGOSPECS(var) for (uint8 index = 0; var = _sorted_cargo_specs[index], index < _sorted_standard_cargo_specs_size; index++) #define FOR_ALL_SORTED_STANDARD_CARGOSPECS(var) for (uint8 index = 0; var = _sorted_cargo_specs[index], index < _sorted_standard_cargo_specs_size; index++)

View File

@ -45,18 +45,18 @@ static int DrawCargoListText(uint32 cargo_mask, const Rect &r, StringID prefix)
char string[512]; char string[512];
char *b = string; char *b = string;
for (CargoID i = 0; i < NUM_CARGO; i++) { CargoID i;
FOR_EACH_SET_CARGO_ID(i, cargo_mask) {
if (b >= lastof(string) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode() if (b >= lastof(string) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode()
if (HasBit(cargo_mask, i)) {
if (first) { if (first) {
first = false; first = false;
} else { } else {
/* Add a comma if this is not the first item */ /* Add a comma if this is not the first item */
*b++ = ','; *b++ = ',';
*b++ = ' '; *b++ = ' ';
}
b = InlineString(b, CargoSpec::Get(i)->name);
} }
b = InlineString(b, CargoSpec::Get(i)->name);
} }
/* If first is still true then no cargo is accepted */ /* If first is still true then no cargo is accepted */
@ -288,8 +288,8 @@ protected:
{ {
Money diff = 0; Money diff = 0;
for (CargoID j = 0; j < NUM_CARGO; j++) { CargoID j;
if (!HasBit(cargo_filter, j)) continue; FOR_EACH_SET_CARGO_ID(j, cargo_filter) {
if (!(*a)->goods[j].cargo.Empty()) diff += GetTransportedGoodsIncome((*a)->goods[j].cargo.Count(), 20, 50, j); if (!(*a)->goods[j].cargo.Empty()) diff += GetTransportedGoodsIncome((*a)->goods[j].cargo.Count(), 20, 50, j);
if (!(*b)->goods[j].cargo.Empty()) diff -= GetTransportedGoodsIncome((*b)->goods[j].cargo.Count(), 20, 50, j); if (!(*b)->goods[j].cargo.Empty()) diff -= GetTransportedGoodsIncome((*b)->goods[j].cargo.Count(), 20, 50, j);
} }
@ -303,8 +303,8 @@ protected:
byte maxr1 = 0; byte maxr1 = 0;
byte maxr2 = 0; byte maxr2 = 0;
for (CargoID j = 0; j < NUM_CARGO; j++) { CargoID j;
if (!HasBit(cargo_filter, j)) continue; FOR_EACH_SET_CARGO_ID(j, cargo_filter) {
if (HasBit((*a)->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr1 = max(maxr1, (*a)->goods[j].rating); if (HasBit((*a)->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr1 = max(maxr1, (*a)->goods[j].rating);
if (HasBit((*b)->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr2 = max(maxr2, (*b)->goods[j].rating); if (HasBit((*b)->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr2 = max(maxr2, (*b)->goods[j].rating);
} }
@ -351,9 +351,9 @@ public:
this->InitNested(desc, window_number); this->InitNested(desc, window_number);
this->owner = (Owner)this->window_number; this->owner = (Owner)this->window_number;
for (uint i = 0; i < NUM_CARGO; i++) { CargoID cid;
const CargoSpec *cs = CargoSpec::Get(i); FOR_EACH_SET_CARGO_ID(cid, this->cargo_filter) {
if (cs->IsValid() && HasBit(this->cargo_filter, i)) this->LowerWidget(SLW_CARGOSTART + i); if (CargoSpec::Get(cid)->IsValid()) this->LowerWidget(SLW_CARGOSTART + cid);
} }
if (this->cargo_filter == this->cargo_filter_max) this->cargo_filter = _cargo_mask; if (this->cargo_filter == this->cargo_filter_max) this->cargo_filter = _cargo_mask;