summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2010-11-06 12:47:12 +0000
committerterkhen <terkhen@openttd.org>2010-11-06 12:47:12 +0000
commitcfac2ced69f072a3881e990837f82a884e27cd40 (patch)
tree3bd21023bbe8e4776f1625f81fabdd7baf7c248a /src
parent609e6dae3fbdace3c753456268eec6dbd0df2db2 (diff)
downloadopenttd-cfac2ced69f072a3881e990837f82a884e27cd40.tar.xz
(svn r21095) -Codechange: Use a function to convert aircraft speed to old units.
Diffstat (limited to 'src')
-rw-r--r--src/aircraft.h1
-rw-r--r--src/economy.cpp2
-rw-r--r--src/newgrf_engine.cpp16
3 files changed, 16 insertions, 3 deletions
diff --git a/src/aircraft.h b/src/aircraft.h
index a7d7761a1..cc9dd8641 100644
--- a/src/aircraft.h
+++ b/src/aircraft.h
@@ -91,6 +91,7 @@ struct Aircraft : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
SpriteID GetImage(Direction direction) const;
int GetDisplaySpeed() const { return this->cur_speed; }
int GetDisplayMaxSpeed() const { return this->max_speed; }
+ int GetSpeedOldUnits() const { return this->max_speed * 10 / 128; }
Money GetRunningCost() const;
bool IsInDepot() const { return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile); }
bool Tick();
diff --git a/src/economy.cpp b/src/economy.cpp
index f0530c3da..810e99701 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1231,7 +1231,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
case VEH_TRAIN: t = Train::From(u)->tcache.cached_max_speed; break;
case VEH_ROAD: t = u->max_speed / 2; break;
case VEH_SHIP: t = u->max_speed; break;
- case VEH_AIRCRAFT: t = u->max_speed * 10 / 128; break; // convert to old units
+ case VEH_AIRCRAFT: t = Aircraft::From(u)->GetSpeedOldUnits(); break; // Convert to old units.
default: NOT_REACHED();
}
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 33479cabd..1d683430c 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -715,8 +715,20 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
case 0x17: return v->tick_counter;
case 0x18:
case 0x19: {
- uint max_speed = v->type == VEH_TRAIN ? Train::From(v)->tcache.cached_max_speed : v->max_speed;
- if (v->type == VEH_AIRCRAFT) max_speed = max_speed * 10 / 128;
+ uint max_speed;
+ switch (v->type) {
+ case VEH_TRAIN:
+ max_speed = Train::From(v)->tcache.cached_max_speed;
+ break;
+
+ case VEH_AIRCRAFT:
+ max_speed = Aircraft::From(v)->GetSpeedOldUnits(); // Convert to old units.
+ break;
+
+ default:
+ max_speed = v->max_speed;
+ break;
+ }
return (variable - 0x80) == 0x18 ? max_speed : GB(max_speed, 8, 8);
}
case 0x1A: return v->x_pos;