(svn r17292) -Codechange: use unified ToPercent() function to convert fract numbers to percents

pull/155/head
smatz 15 years ago
parent 3af095aa19
commit a0d0206f2d

@ -1252,7 +1252,7 @@
GetCargoType(): 255 GetCargoType(): 255
CanRefitCargo(): false CanRefitCargo(): false
GetCapacity(): -1 GetCapacity(): -1
GetReliability(): 79 GetReliability(): 80
GetMaxSpeed(): 112 GetMaxSpeed(): 112
GetPrice(): 41 GetPrice(): 41
GetMaxAge(): 7686 GetMaxAge(): 7686
@ -1270,7 +1270,7 @@
GetCargoType(): 255 GetCargoType(): 255
CanRefitCargo(): false CanRefitCargo(): false
GetCapacity(): -1 GetCapacity(): -1
GetReliability(): 83 GetReliability(): 84
GetMaxSpeed(): 128 GetMaxSpeed(): 128
GetPrice(): 61 GetPrice(): 61
GetMaxAge(): 7320 GetMaxAge(): 7320
@ -3322,7 +3322,7 @@
GetCargoType(): 1 GetCargoType(): 1
CanRefitCargo(): true CanRefitCargo(): true
GetCapacity(): 20 GetCapacity(): 20
GetReliability(): 76 GetReliability(): 77
GetMaxSpeed(): 48 GetMaxSpeed(): 48
GetPrice(): 347 GetPrice(): 347
GetMaxAge(): 5490 GetMaxAge(): 5490
@ -3376,7 +3376,7 @@
GetCargoType(): 2 GetCargoType(): 2
CanRefitCargo(): false CanRefitCargo(): false
GetCapacity(): 22 GetCapacity(): 22
GetReliability(): 91 GetReliability(): 92
GetMaxSpeed(): 48 GetMaxSpeed(): 48
GetPrice(): 370 GetPrice(): 370
GetMaxAge(): 5490 GetMaxAge(): 5490
@ -3484,7 +3484,7 @@
GetCargoType(): 3 GetCargoType(): 3
CanRefitCargo(): false CanRefitCargo(): false
GetCapacity(): 21 GetCapacity(): 21
GetReliability(): 97 GetReliability(): 98
GetMaxSpeed(): 48 GetMaxSpeed(): 48
GetPrice(): 354 GetPrice(): 354
GetMaxAge(): 5490 GetMaxAge(): 5490
@ -3538,7 +3538,7 @@
GetCargoType(): 4 GetCargoType(): 4
CanRefitCargo(): false CanRefitCargo(): false
GetCapacity(): 14 GetCapacity(): 14
GetReliability(): 96 GetReliability(): 97
GetMaxSpeed(): 48 GetMaxSpeed(): 48
GetPrice(): 337 GetPrice(): 337
GetMaxAge(): 5490 GetMaxAge(): 5490
@ -3592,7 +3592,7 @@
GetCargoType(): 5 GetCargoType(): 5
CanRefitCargo(): false CanRefitCargo(): false
GetCapacity(): 14 GetCapacity(): 14
GetReliability(): 86 GetReliability(): 87
GetMaxSpeed(): 48 GetMaxSpeed(): 48
GetPrice(): 344 GetPrice(): 344
GetMaxAge(): 5490 GetMaxAge(): 5490
@ -3646,7 +3646,7 @@
GetCargoType(): 6 GetCargoType(): 6
CanRefitCargo(): false CanRefitCargo(): false
GetCapacity(): 20 GetCapacity(): 20
GetReliability(): 96 GetReliability(): 97
GetMaxSpeed(): 48 GetMaxSpeed(): 48
GetPrice(): 366 GetPrice(): 366
GetMaxAge(): 5490 GetMaxAge(): 5490
@ -3700,7 +3700,7 @@
GetCargoType(): 7 GetCargoType(): 7
CanRefitCargo(): false CanRefitCargo(): false
GetCapacity(): 20 GetCapacity(): 20
GetReliability(): 97 GetReliability(): 98
GetMaxSpeed(): 48 GetMaxSpeed(): 48
GetPrice(): 379 GetPrice(): 379
GetMaxAge(): 5490 GetMaxAge(): 5490
@ -3754,7 +3754,7 @@
GetCargoType(): 8 GetCargoType(): 8
CanRefitCargo(): false CanRefitCargo(): false
GetCapacity(): 22 GetCapacity(): 22
GetReliability(): 96 GetReliability(): 97
GetMaxSpeed(): 48 GetMaxSpeed(): 48
GetPrice(): 389 GetPrice(): 389
GetMaxAge(): 5490 GetMaxAge(): 5490
@ -3808,7 +3808,7 @@
GetCargoType(): 9 GetCargoType(): 9
CanRefitCargo(): false CanRefitCargo(): false
GetCapacity(): 15 GetCapacity(): 15
GetReliability(): 81 GetReliability(): 82
GetMaxSpeed(): 48 GetMaxSpeed(): 48
GetPrice(): 360 GetPrice(): 360
GetMaxAge(): 5490 GetMaxAge(): 5490
@ -3862,7 +3862,7 @@
GetCargoType(): 10 GetCargoType(): 10
CanRefitCargo(): false CanRefitCargo(): false
GetCapacity(): 12 GetCapacity(): 12
GetReliability(): 75 GetReliability(): 76
GetMaxSpeed(): 48 GetMaxSpeed(): 48
GetPrice(): 466 GetPrice(): 466
GetMaxAge(): 5490 GetMaxAge(): 5490
@ -4780,7 +4780,7 @@
GetCargoType(): 3 GetCargoType(): 3
CanRefitCargo(): false CanRefitCargo(): false
GetCapacity(): 220 GetCapacity(): 220
GetReliability(): 98 GetReliability(): 99
GetMaxSpeed(): 24 GetMaxSpeed(): 24
GetPrice(): 515 GetPrice(): 515
GetMaxAge(): 10980 GetMaxAge(): 10980
@ -4816,7 +4816,7 @@
GetCargoType(): 0 GetCargoType(): 0
CanRefitCargo(): false CanRefitCargo(): false
GetCapacity(): 100 GetCapacity(): 100
GetReliability(): 87 GetReliability(): 88
GetMaxSpeed(): 32 GetMaxSpeed(): 32
GetPrice(): 309 GetPrice(): 309
GetMaxAge(): 10980 GetMaxAge(): 10980
@ -5050,7 +5050,7 @@
GetCargoType(): 0 GetCargoType(): 0
CanRefitCargo(): false CanRefitCargo(): false
GetCapacity(): 30 GetCapacity(): 30
GetReliability(): 76 GetReliability(): 77
GetMaxSpeed(): 238 GetMaxSpeed(): 238
GetPrice(): 48 GetPrice(): 48
GetMaxAge(): 10980 GetMaxAge(): 10980
@ -5757,17 +5757,17 @@
135 => 14 135 => 14
153 => 12 153 => 12
Reliability ListDump: Reliability ListDump:
144 => 97 144 => 98
132 => 97 132 => 98
147 => 96 147 => 97
141 => 96 141 => 97
135 => 96 135 => 97
126 => 91 126 => 92
138 => 86 138 => 87
150 => 81 150 => 82
116 => 78 116 => 78
123 => 76 123 => 77
153 => 75 153 => 76
MaxSpeed ListDump: MaxSpeed ListDump:
116 => 56 116 => 56
153 => 48 153 => 48
@ -7090,9 +7090,9 @@
GetBankBalance(): 805063 GetBankBalance(): 805063
--AIBuoyList-- --AIBuoyList--
Count(): 1 Count(): 1
Location ListDump: Location ListDump:
28481 28481
RemoveWaterDepot(): true RemoveWaterDepot(): true
RemoveDock(): true RemoveDock(): true

@ -99,7 +99,7 @@
if (!IsValidEngine(engine_id)) return -1; if (!IsValidEngine(engine_id)) return -1;
if (GetVehicleType(engine_id) == AIVehicle::VT_RAIL && IsWagon(engine_id)) return -1; if (GetVehicleType(engine_id) == AIVehicle::VT_RAIL && IsWagon(engine_id)) return -1;
return (::Engine::Get(engine_id)->reliability * 100 >> 16); return ::ToPercent16(::Engine::Get(engine_id)->reliability);
} }
/* static */ int32 AIEngine::GetMaxSpeed(EngineID engine_id) /* static */ int32 AIEngine::GetMaxSpeed(EngineID engine_id)

@ -438,5 +438,5 @@
if (!IsValidVehicle(vehicle_id)) return -1; if (!IsValidVehicle(vehicle_id)) return -1;
const Vehicle *v = ::Vehicle::Get(vehicle_id); const Vehicle *v = ::Vehicle::Get(vehicle_id);
return v->reliability * 100 >> 16; return ::ToPercent16(v->reliability);
} }

@ -691,7 +691,7 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number)
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;
/* Reliability */ /* Reliability */
SetDParam(0, e->reliability * 100 >> 16); SetDParam(0, ToPercent16(e->reliability));
DrawString(left, right, y, STR_PURCHASE_INFO_RELIABILITY); DrawString(left, right, y, STR_PURCHASE_INFO_RELIABILITY);
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;
} }

@ -269,6 +269,28 @@ static FORCEINLINE void Swap(T &a, T &b)
b = t; b = t;
} }
/**
* Converts a "fract" value 0..255 to "percent" value 0..100
* @param i value to convert, range 0..255
* @return value in range 0..100
*/
static FORCEINLINE uint ToPercent8(uint i)
{
assert(i < 256);
return i * 101 >> 8;
}
/**
* Converts a "fract" value 0..65535 to "percent" value 0..100
* @param i value to convert, range 0..65535
* @return value in range 0..100
*/
static FORCEINLINE uint ToPercent16(uint i)
{
assert(i < 65536);
return i * 101 >> 16;
}
int LeastCommonMultiple(int a, int b); int LeastCommonMultiple(int a, int b);
int GreatestCommonDivisor(int a, int b); int GreatestCommonDivisor(int a, int b);

@ -554,7 +554,7 @@ public:
SetDParam(1, i->last_month_production[j]); SetDParam(1, i->last_month_production[j]);
SetDParam(2, GetCargoSuffix(j + 3, CST_VIEW, i, i->type, ind)); SetDParam(2, GetCargoSuffix(j + 3, CST_VIEW, i, i->type, ind));
SetDParam(3, i->last_month_pct_transported[j] * 100 >> 8); SetDParam(3, ToPercent8(i->last_month_pct_transported[j]));
uint x = 4 + (IsProductionAlterable(i) ? 30 : 0); uint x = 4 + (IsProductionAlterable(i) ? 30 : 0);
DrawString(x, this->widget[IVW_INFO].right, y, STR_INDUSTRY_VIEW_TRANSPORTED); DrawString(x, this->widget[IVW_INFO].right, y, STR_INDUSTRY_VIEW_TRANSPORTED);
/* Let's put out those buttons.. */ /* Let's put out those buttons.. */
@ -833,7 +833,7 @@ protected:
assert(id < lengthof(i->produced_cargo)); assert(id < lengthof(i->produced_cargo));
if (i->produced_cargo[id] == CT_INVALID) return 101; if (i->produced_cargo[id] == CT_INVALID) return 101;
return i->last_month_pct_transported[id] * 100 >> 8; return ToPercent8(i->last_month_pct_transported[id]);
} }
/** /**
@ -968,7 +968,7 @@ public:
/* Transported productions */ /* Transported productions */
for (byte j = 0; j < lengthof(i->produced_cargo); j++) { for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
if (i->produced_cargo[j] == CT_INVALID) continue; if (i->produced_cargo[j] == CT_INVALID) continue;
SetDParam(p++, i->last_month_pct_transported[j] * 100 >> 8); SetDParam(p++, ToPercent8(i->last_month_pct_transported[j]));
} }
/* Drawing the right string */ /* Drawing the right string */

@ -1630,7 +1630,7 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v)
switch (order->GetConditionVariable()) { switch (order->GetConditionVariable()) {
case OCV_LOAD_PERCENTAGE: skip_order = OrderConditionCompare(occ, CalcPercentVehicleFilled(v, NULL), value); break; case OCV_LOAD_PERCENTAGE: skip_order = OrderConditionCompare(occ, CalcPercentVehicleFilled(v, NULL), value); break;
case OCV_RELIABILITY: skip_order = OrderConditionCompare(occ, v->reliability * 100 >> 16, value); break; case OCV_RELIABILITY: skip_order = OrderConditionCompare(occ, ToPercent16(v->reliability), value); break;
case OCV_MAX_SPEED: skip_order = OrderConditionCompare(occ, v->GetDisplayMaxSpeed() * 10 / 16, value); break; case OCV_MAX_SPEED: skip_order = OrderConditionCompare(occ, v->GetDisplayMaxSpeed() * 10 / 16, value); break;
case OCV_AGE: skip_order = OrderConditionCompare(occ, v->age / DAYS_IN_LEAP_YEAR, value); break; case OCV_AGE: skip_order = OrderConditionCompare(occ, v->age / DAYS_IN_LEAP_YEAR, value); break;
case OCV_REQUIRES_SERVICE: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break; case OCV_REQUIRES_SERVICE: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break;

@ -954,7 +954,7 @@ struct StationViewWindow : public Window {
if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue; if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue;
SetDParam(0, cs->name); SetDParam(0, cs->name);
SetDParam(2, ge->rating * 101 >> 8); SetDParam(2, ToPercent8(ge->rating));
SetDParam(1, STR_CARGO_RATING_APPALLING + (ge->rating >> 5)); SetDParam(1, STR_CARGO_RATING_APPALLING + (ge->rating >> 5));
DrawString(this->widget[SVW_ACCEPTLIST].left + 8, this->widget[SVW_ACCEPTLIST].right - 2, y, STR_STATION_VIEW_CARGO_RATING); DrawString(this->widget[SVW_ACCEPTLIST].left + 8, this->widget[SVW_ACCEPTLIST].right - 2, y, STR_STATION_VIEW_CARGO_RATING);
y += 10; y += 10;

@ -1424,7 +1424,7 @@ struct VehicleDetailsWindow : Window {
DrawString(2, this->width - 2, 35, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR); DrawString(2, this->width - 2, 35, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR);
/* Draw breakdown & reliability */ /* Draw breakdown & reliability */
SetDParam(0, v->reliability * 100 >> 16); SetDParam(0, ToPercent16(v->reliability));
SetDParam(1, v->breakdowns_since_last_service); SetDParam(1, v->breakdowns_since_last_service);
DrawString(2, this->width - 2, 45, STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS); DrawString(2, this->width - 2, 45, STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS);

Loading…
Cancel
Save