(svn r25149) -Codechange: replace 'magic' 'has rating' bitcheck by descriptive function

This commit is contained in:
rubidium 2013-04-06 12:10:16 +00:00
parent 70454b8d64
commit b2292122b6
5 changed files with 20 additions and 11 deletions

View File

@ -423,7 +423,7 @@ uint32 Station::GetNewGRFVariable(const ResolverObject *object, byte variable, b
switch (variable) { switch (variable) {
case 0x60: return min(ge->cargo.Count(), 4095); case 0x60: return min(ge->cargo.Count(), 4095);
case 0x61: return ge->HasVehicleEverTriedLoading() ? ge->time_since_pickup : 0; case 0x61: return ge->HasVehicleEverTriedLoading() ? ge->time_since_pickup : 0;
case 0x62: return HasBit(ge->acceptance_pickup, GoodsEntry::GES_PICKUP) ? ge->rating : 0xFFFFFFFF; case 0x62: return ge->HasRating() ? ge->rating : 0xFFFFFFFF;
case 0x63: return ge->cargo.DaysInTransit(); case 0x63: return ge->cargo.DaysInTransit();
case 0x64: return ge->HasVehicleEverTriedLoading() ? ge->last_speed | (ge->last_age << 8) : 0xFF00; case 0x64: return ge->HasVehicleEverTriedLoading() ? ge->last_speed | (ge->last_age << 8) : 0xFF00;
case 0x65: return GB(ge->acceptance_pickup, GoodsEntry::GES_ACCEPTANCE, 1) << 3; case 0x65: return GB(ge->acceptance_pickup, GoodsEntry::GES_ACCEPTANCE, 1) << 3;

View File

@ -114,6 +114,15 @@ struct GoodsEntry {
* @return true if vehicle tried to load. * @return true if vehicle tried to load.
*/ */
bool HasVehicleEverTriedLoading() const { return this->last_speed != 0; } bool HasVehicleEverTriedLoading() const { return this->last_speed != 0; }
/**
* Does this cargo have a rating at this station?
* @return true if the cargo has a rating, i.e. pickup has been attempted.
*/
inline bool HasRating() const
{
return HasBit(this->acceptance_pickup, GES_PICKUP);
}
}; };
/** All airport-related information. Only valid if tile != INVALID_TILE. */ /** All airport-related information. Only valid if tile != INVALID_TILE. */

View File

@ -3215,12 +3215,12 @@ static void UpdateStationRating(Station *st)
/* Slowly increase the rating back to his original level in the case we /* Slowly increase the rating back to his original level in the case we
* didn't deliver cargo yet to this station. This happens when a bribe * didn't deliver cargo yet to this station. This happens when a bribe
* failed while you didn't moved that cargo yet to a station. */ * failed while you didn't moved that cargo yet to a station. */
if (!HasBit(ge->acceptance_pickup, GoodsEntry::GES_PICKUP) && ge->rating < INITIAL_STATION_RATING) { if (!ge->HasRating() && ge->rating < INITIAL_STATION_RATING) {
ge->rating++; ge->rating++;
} }
/* Only change the rating if we are moving this cargo */ /* Only change the rating if we are moving this cargo */
if (HasBit(ge->acceptance_pickup, GoodsEntry::GES_PICKUP)) { if (ge->HasRating()) {
byte_inc_sat(&ge->time_since_pickup); byte_inc_sat(&ge->time_since_pickup);
bool skip = false; bool skip = false;
@ -3411,7 +3411,7 @@ static uint UpdateStationWaiting(Station *st, CargoID type, uint amount, SourceT
ge.cargo.Append(new CargoPacket(st->index, st->xy, amount, source_type, source_id)); ge.cargo.Append(new CargoPacket(st->index, st->xy, amount, source_type, source_id));
if (!HasBit(ge.acceptance_pickup, GoodsEntry::GES_PICKUP)) { if (!ge.HasRating()) {
InvalidateWindowData(WC_STATION_LIST, st->index); InvalidateWindowData(WC_STATION_LIST, st->index);
SetBit(ge.acceptance_pickup, GoodsEntry::GES_PICKUP); SetBit(ge.acceptance_pickup, GoodsEntry::GES_PICKUP);
} }

View File

@ -178,7 +178,7 @@ protected:
if (this->facilities & st->facilities) { // only stations with selected facilities if (this->facilities & st->facilities) { // only stations with selected facilities
int num_waiting_cargo = 0; int num_waiting_cargo = 0;
for (CargoID j = 0; j < NUM_CARGO; j++) { for (CargoID j = 0; j < NUM_CARGO; j++) {
if (HasBit(st->goods[j].acceptance_pickup, GoodsEntry::GES_PICKUP)) { if (st->goods[j].HasRating()) {
num_waiting_cargo++; // count number of waiting cargo num_waiting_cargo++; // count number of waiting cargo
if (HasBit(this->cargo_filter, j)) { if (HasBit(this->cargo_filter, j)) {
*this->stations.Append() = st; *this->stations.Append() = st;
@ -246,8 +246,8 @@ protected:
CargoID j; CargoID j;
FOR_EACH_SET_CARGO_ID(j, cargo_filter) { FOR_EACH_SET_CARGO_ID(j, cargo_filter) {
if (HasBit((*a)->goods[j].acceptance_pickup, GoodsEntry::GES_PICKUP)) maxr1 = max(maxr1, (*a)->goods[j].rating); if ((*a)->goods[j].HasRating()) maxr1 = max(maxr1, (*a)->goods[j].rating);
if (HasBit((*b)->goods[j].acceptance_pickup, GoodsEntry::GES_PICKUP)) maxr2 = max(maxr2, (*b)->goods[j].rating); if ((*b)->goods[j].HasRating()) maxr2 = max(maxr2, (*b)->goods[j].rating);
} }
return maxr1 - maxr2; return maxr1 - maxr2;
@ -261,8 +261,8 @@ protected:
for (CargoID j = 0; j < NUM_CARGO; j++) { for (CargoID j = 0; j < NUM_CARGO; j++) {
if (!HasBit(cargo_filter, j)) continue; if (!HasBit(cargo_filter, j)) continue;
if (HasBit((*a)->goods[j].acceptance_pickup, GoodsEntry::GES_PICKUP)) minr1 = min(minr1, (*a)->goods[j].rating); if ((*a)->goods[j].HasRating()) minr1 = min(minr1, (*a)->goods[j].rating);
if (HasBit((*b)->goods[j].acceptance_pickup, GoodsEntry::GES_PICKUP)) minr2 = min(minr2, (*b)->goods[j].rating); if ((*b)->goods[j].HasRating()) minr2 = min(minr2, (*b)->goods[j].rating);
} }
return -(minr1 - minr2); return -(minr1 - minr2);
@ -1081,7 +1081,7 @@ struct StationViewWindow : public Window {
const CargoSpec *cs; const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
const GoodsEntry *ge = &st->goods[cs->Index()]; const GoodsEntry *ge = &st->goods[cs->Index()];
if (!HasBit(ge->acceptance_pickup, GoodsEntry::GES_PICKUP)) continue; if (!ge->HasRating()) continue;
SetDParam(0, cs->name); SetDParam(0, cs->name);
SetDParam(2, ToPercent8(ge->rating)); SetDParam(2, ToPercent8(ge->rating));

View File

@ -1261,7 +1261,7 @@ uint8 CalcPercentVehicleFilled(const Vehicle *front, StringID *colour)
if (v->cargo_cap != 0 && colour != NULL) { if (v->cargo_cap != 0 && colour != NULL) {
unloading += HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0; unloading += HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0;
loading |= !order_no_load && loading |= !order_no_load &&
(order_full_load || HasBit(st->goods[v->cargo_type].acceptance_pickup, GoodsEntry::GES_PICKUP)) && (order_full_load || st->goods[v->cargo_type].HasRating()) &&
!HasBit(v->vehicle_flags, VF_LOADING_FINISHED) && !HasBit(v->vehicle_flags, VF_STOP_LOADING); !HasBit(v->vehicle_flags, VF_LOADING_FINISHED) && !HasBit(v->vehicle_flags, VF_STOP_LOADING);
cars++; cars++;
} }