From 2179faf5c82c2eca3aeeaf7f08fa0f18ad4772c1 Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 28 Aug 2007 06:46:33 +0000 Subject: [PATCH] (svn r10995) -Codechange: unify the way to get the displayed maxium speed of a vehicle. Patch by nycom. --- src/aircraft.h | 1 + src/aircraft_gui.cpp | 2 +- src/roadveh.h | 1 + src/roadveh_gui.cpp | 2 +- src/ship.h | 1 + src/ship_gui.cpp | 2 +- src/train.h | 1 + src/train_gui.cpp | 2 +- src/vehicle.h | 6 ++++++ 9 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/aircraft.h b/src/aircraft.h index 1af9942ad3..0a32703e22 100644 --- a/src/aircraft.h +++ b/src/aircraft.h @@ -129,6 +129,7 @@ struct Aircraft : public Vehicle { bool IsPrimaryVehicle() const { return IsNormalAircraft(this); } int GetImage(Direction direction) const; int GetDisplaySpeed() const { return this->cur_speed * 10 / 16; } + int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 16; } void Tick(); }; diff --git a/src/aircraft_gui.cpp b/src/aircraft_gui.cpp index b90ddb3f1d..ee8d396103 100644 --- a/src/aircraft_gui.cpp +++ b/src/aircraft_gui.cpp @@ -86,7 +86,7 @@ static void AircraftDetailsWndProc(Window *w, WindowEvent *e) /* Draw max speed */ { - SetDParam(0, v->max_speed * 10 / 16); + SetDParam(0, v->GetDisplayMaxSpeed()); DrawString(2, 25, STR_A00E_MAX_SPEED, 0); } diff --git a/src/roadveh.h b/src/roadveh.h index 8547a2610a..24b64424d9 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -82,6 +82,7 @@ struct RoadVehicle : public Vehicle { bool HasFront() const { return true; } int GetImage(Direction direction) const; int GetDisplaySpeed() const { return this->cur_speed * 10 / 32; } + int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 32; } void Tick(); }; diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp index d301a482ef..73d314b0f3 100644 --- a/src/roadveh_gui.cpp +++ b/src/roadveh_gui.cpp @@ -97,7 +97,7 @@ static void RoadVehDetailsWndProc(Window *w, WindowEvent *e) /* Draw max speed */ { - SetDParam(0, v->max_speed * 10 / 32); + SetDParam(0, v->GetDisplayMaxSpeed()); DrawString(2, 25, STR_900E_MAX_SPEED, 0); } diff --git a/src/ship.h b/src/ship.h index cd7b4c3c14..ac86c907a2 100644 --- a/src/ship.h +++ b/src/ship.h @@ -47,6 +47,7 @@ struct Ship: public Vehicle { bool IsPrimaryVehicle() const { return true; } int GetImage(Direction direction) const; int GetDisplaySpeed() const { return this->cur_speed * 10 / 32; } + int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 32; } void Tick(); }; diff --git a/src/ship_gui.cpp b/src/ship_gui.cpp index d1e64d39a9..fd4456c3b0 100644 --- a/src/ship_gui.cpp +++ b/src/ship_gui.cpp @@ -56,7 +56,7 @@ static void ShipDetailsWndProc(Window *w, WindowEvent *e) /* Draw max speed */ { - SetDParam(0, v->max_speed * 10 / 32); + SetDParam(0, v->GetDisplayMaxSpeed()); DrawString(2, 25, STR_9813_MAX_SPEED, 0); } diff --git a/src/train.h b/src/train.h index db9aa5b2d4..a64048fb8e 100644 --- a/src/train.h +++ b/src/train.h @@ -273,6 +273,7 @@ struct Train : public Vehicle { bool HasFront() const { return true; } int GetImage(Direction direction) const; int GetDisplaySpeed() const { return this->cur_speed * 10 / 16; } + int GetDisplayMaxSpeed() const { return this->u.rail.cached_max_speed * 10 / 16; } void Tick(); }; diff --git a/src/train_gui.cpp b/src/train_gui.cpp index 378d874adf..ba3ad30461 100644 --- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -421,7 +421,7 @@ static void DrawTrainDetailsWindow(Window *w) SetDParam(3, GetTrainRunningCost(v) >> 8); DrawString(x, 15, STR_885D_AGE_RUNNING_COST_YR, 0); - SetDParam(2, v->u.rail.cached_max_speed * 10 / 16); + SetDParam(2, v->GetDisplayMaxSpeed()); SetDParam(1, v->u.rail.cached_power); SetDParam(0, v->u.rail.cached_weight); SetDParam(3, v->u.rail.cached_max_te / 1000); diff --git a/src/vehicle.h b/src/vehicle.h index f036a2e8d0..02ed8e51ef 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -420,6 +420,12 @@ struct Vehicle : PoolItem { */ virtual int GetDisplaySpeed() const { return 0; } + /** + * Gets the maximum speed in mph that can be sent into SetDParam for string processing. + * @return the vehicle's maximum speed + */ + virtual int GetDisplayMaxSpeed() const { return 0; } + /** * Calls the tick handler of the vehicle */