(svn r17292) -Codechange: use unified ToPercent() function to convert fract numbers to percents
This commit is contained in:
@@ -99,7 +99,7 @@
|
||||
if (!IsValidEngine(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)
|
||||
|
@@ -438,5 +438,5 @@
|
||||
if (!IsValidVehicle(vehicle_id)) return -1;
|
||||
|
||||
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;
|
||||
|
||||
/* Reliability */
|
||||
SetDParam(0, e->reliability * 100 >> 16);
|
||||
SetDParam(0, ToPercent16(e->reliability));
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_RELIABILITY);
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
}
|
||||
|
@@ -269,6 +269,28 @@ static FORCEINLINE void Swap(T &a, T &b)
|
||||
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 GreatestCommonDivisor(int a, int b);
|
||||
|
||||
|
@@ -554,7 +554,7 @@ public:
|
||||
SetDParam(1, i->last_month_production[j]);
|
||||
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);
|
||||
DrawString(x, this->widget[IVW_INFO].right, y, STR_INDUSTRY_VIEW_TRANSPORTED);
|
||||
/* Let's put out those buttons.. */
|
||||
@@ -833,7 +833,7 @@ protected:
|
||||
assert(id < lengthof(i->produced_cargo));
|
||||
|
||||
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 */
|
||||
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||
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 */
|
||||
|
@@ -1630,7 +1630,7 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v)
|
||||
|
||||
switch (order->GetConditionVariable()) {
|
||||
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_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;
|
||||
|
@@ -954,7 +954,7 @@ struct StationViewWindow : public Window {
|
||||
if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue;
|
||||
|
||||
SetDParam(0, cs->name);
|
||||
SetDParam(2, ge->rating * 101 >> 8);
|
||||
SetDParam(2, ToPercent8(ge->rating));
|
||||
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);
|
||||
y += 10;
|
||||
|
@@ -1424,7 +1424,7 @@ struct VehicleDetailsWindow : Window {
|
||||
DrawString(2, this->width - 2, 35, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR);
|
||||
|
||||
/* Draw breakdown & reliability */
|
||||
SetDParam(0, v->reliability * 100 >> 16);
|
||||
SetDParam(0, ToPercent16(v->reliability));
|
||||
SetDParam(1, v->breakdowns_since_last_service);
|
||||
DrawString(2, this->width - 2, 45, STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS);
|
||||
|
||||
|
Reference in New Issue
Block a user