summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-08-27 13:31:26 +0000
committersmatz <smatz@openttd.org>2009-08-27 13:31:26 +0000
commit100ae8efcc592ec44f0cc161e0045fb84b67c45e (patch)
tree79e23872457025fcbbc5f0a92e071c53d687ec7b
parent984efae368da7a7a7e5090820ef31c9c3a678670 (diff)
downloadopenttd-100ae8efcc592ec44f0cc161e0045fb84b67c45e.tar.xz
(svn r17292) -Codechange: use unified ToPercent() function to convert fract numbers to percents
-rw-r--r--bin/ai/regression/regression.txt54
-rw-r--r--src/ai/api/ai_engine.cpp2
-rw-r--r--src/ai/api/ai_vehicle.cpp2
-rw-r--r--src/build_vehicle_gui.cpp2
-rw-r--r--src/core/math_func.hpp22
-rw-r--r--src/industry_gui.cpp6
-rw-r--r--src/order_cmd.cpp2
-rw-r--r--src/station_gui.cpp2
-rw-r--r--src/vehicle_gui.cpp2
9 files changed, 58 insertions, 36 deletions
diff --git a/bin/ai/regression/regression.txt b/bin/ai/regression/regression.txt
index 31bc3a417..8c569376f 100644
--- a/bin/ai/regression/regression.txt
+++ b/bin/ai/regression/regression.txt
@@ -1252,7 +1252,7 @@
GetCargoType(): 255
CanRefitCargo(): false
GetCapacity(): -1
- GetReliability(): 79
+ GetReliability(): 80
GetMaxSpeed(): 112
GetPrice(): 41
GetMaxAge(): 7686
@@ -1270,7 +1270,7 @@
GetCargoType(): 255
CanRefitCargo(): false
GetCapacity(): -1
- GetReliability(): 83
+ GetReliability(): 84
GetMaxSpeed(): 128
GetPrice(): 61
GetMaxAge(): 7320
@@ -3322,7 +3322,7 @@
GetCargoType(): 1
CanRefitCargo(): true
GetCapacity(): 20
- GetReliability(): 76
+ GetReliability(): 77
GetMaxSpeed(): 48
GetPrice(): 347
GetMaxAge(): 5490
@@ -3376,7 +3376,7 @@
GetCargoType(): 2
CanRefitCargo(): false
GetCapacity(): 22
- GetReliability(): 91
+ GetReliability(): 92
GetMaxSpeed(): 48
GetPrice(): 370
GetMaxAge(): 5490
@@ -3484,7 +3484,7 @@
GetCargoType(): 3
CanRefitCargo(): false
GetCapacity(): 21
- GetReliability(): 97
+ GetReliability(): 98
GetMaxSpeed(): 48
GetPrice(): 354
GetMaxAge(): 5490
@@ -3538,7 +3538,7 @@
GetCargoType(): 4
CanRefitCargo(): false
GetCapacity(): 14
- GetReliability(): 96
+ GetReliability(): 97
GetMaxSpeed(): 48
GetPrice(): 337
GetMaxAge(): 5490
@@ -3592,7 +3592,7 @@
GetCargoType(): 5
CanRefitCargo(): false
GetCapacity(): 14
- GetReliability(): 86
+ GetReliability(): 87
GetMaxSpeed(): 48
GetPrice(): 344
GetMaxAge(): 5490
@@ -3646,7 +3646,7 @@
GetCargoType(): 6
CanRefitCargo(): false
GetCapacity(): 20
- GetReliability(): 96
+ GetReliability(): 97
GetMaxSpeed(): 48
GetPrice(): 366
GetMaxAge(): 5490
@@ -3700,7 +3700,7 @@
GetCargoType(): 7
CanRefitCargo(): false
GetCapacity(): 20
- GetReliability(): 97
+ GetReliability(): 98
GetMaxSpeed(): 48
GetPrice(): 379
GetMaxAge(): 5490
@@ -3754,7 +3754,7 @@
GetCargoType(): 8
CanRefitCargo(): false
GetCapacity(): 22
- GetReliability(): 96
+ GetReliability(): 97
GetMaxSpeed(): 48
GetPrice(): 389
GetMaxAge(): 5490
@@ -3808,7 +3808,7 @@
GetCargoType(): 9
CanRefitCargo(): false
GetCapacity(): 15
- GetReliability(): 81
+ GetReliability(): 82
GetMaxSpeed(): 48
GetPrice(): 360
GetMaxAge(): 5490
@@ -3862,7 +3862,7 @@
GetCargoType(): 10
CanRefitCargo(): false
GetCapacity(): 12
- GetReliability(): 75
+ GetReliability(): 76
GetMaxSpeed(): 48
GetPrice(): 466
GetMaxAge(): 5490
@@ -4780,7 +4780,7 @@
GetCargoType(): 3
CanRefitCargo(): false
GetCapacity(): 220
- GetReliability(): 98
+ GetReliability(): 99
GetMaxSpeed(): 24
GetPrice(): 515
GetMaxAge(): 10980
@@ -4816,7 +4816,7 @@
GetCargoType(): 0
CanRefitCargo(): false
GetCapacity(): 100
- GetReliability(): 87
+ GetReliability(): 88
GetMaxSpeed(): 32
GetPrice(): 309
GetMaxAge(): 10980
@@ -5050,7 +5050,7 @@
GetCargoType(): 0
CanRefitCargo(): false
GetCapacity(): 30
- GetReliability(): 76
+ GetReliability(): 77
GetMaxSpeed(): 238
GetPrice(): 48
GetMaxAge(): 10980
@@ -5757,17 +5757,17 @@
135 => 14
153 => 12
Reliability ListDump:
- 144 => 97
- 132 => 97
- 147 => 96
- 141 => 96
- 135 => 96
- 126 => 91
- 138 => 86
- 150 => 81
+ 144 => 98
+ 132 => 98
+ 147 => 97
+ 141 => 97
+ 135 => 97
+ 126 => 92
+ 138 => 87
+ 150 => 82
116 => 78
- 123 => 76
- 153 => 75
+ 123 => 77
+ 153 => 76
MaxSpeed ListDump:
116 => 56
153 => 48
@@ -7090,9 +7090,9 @@
GetBankBalance(): 805063
--AIBuoyList--
- Count(): 1
+ Count(): 1
Location ListDump:
- 28481
+ 28481
RemoveWaterDepot(): true
RemoveDock(): true
diff --git a/src/ai/api/ai_engine.cpp b/src/ai/api/ai_engine.cpp
index d25f522e1..a3f5c39cd 100644
--- a/src/ai/api/ai_engine.cpp
+++ b/src/ai/api/ai_engine.cpp
@@ -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)
diff --git a/src/ai/api/ai_vehicle.cpp b/src/ai/api/ai_vehicle.cpp
index e15062daa..acf1a3bd8 100644
--- a/src/ai/api/ai_vehicle.cpp
+++ b/src/ai/api/ai_vehicle.cpp
@@ -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);
}
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index 8b377047d..1d67a221f 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -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;
}
diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp
index 39ed16c98..b27fe9a01 100644
--- a/src/core/math_func.hpp
+++ b/src/core/math_func.hpp
@@ -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);
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 9cc76a5ef..6276d9411 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -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 */
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index 35ba61bd9..0b344b08d 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -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;
diff --git a/src/station_gui.cpp b/src/station_gui.cpp
index cd6a3df53..424e8e7c7 100644
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -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;
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 381fe01a5..f4b9eacbb 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -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);