summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2012-05-14 19:56:49 +0000
committermichi_cc <michi_cc@openttd.org>2012-05-14 19:56:49 +0000
commitce5c936b07517955ffa29a134907346b6cd4c148 (patch)
tree204c818783cda0baf6104f72e7897f5c311f0e3b /src
parent58d474797e90fbc551a455000cfbda16f15ad4a5 (diff)
downloadopenttd-ce5c936b07517955ffa29a134907346b6cd4c148.tar.xz
(svn r24246) -Add [FS#5052-ish]: [NewGRF] Variable with the current max speed for vehicles.
Diffstat (limited to 'src')
-rw-r--r--src/aircraft.h1
-rw-r--r--src/newgrf_engine.cpp4
-rw-r--r--src/ship.h1
-rw-r--r--src/train_cmd.cpp2
-rw-r--r--src/vehicle_base.h6
5 files changed, 14 insertions, 0 deletions
diff --git a/src/aircraft.h b/src/aircraft.h
index f47febd62..b6c847812 100644
--- a/src/aircraft.h
+++ b/src/aircraft.h
@@ -76,6 +76,7 @@ struct Aircraft FINAL : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
int GetDisplaySpeed() const { return this->cur_speed; }
int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed; }
int GetSpeedOldUnits() const { return this->vcache.cached_max_speed * 10 / 128; }
+ int GetCurrentMaxSpeed() const { return this->GetSpeedOldUnits(); }
Money GetRunningCost() const;
bool IsInDepot() const { return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile); }
bool Tick();
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 3c1a93ac0..f4e120aee 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -619,6 +619,10 @@ static uint32 VehicleGetVariable(Vehicle *v, const ResolverObject *object, byte
case 0x4B: // Long date of last service
return v->date_of_last_service;
+ case 0x4C: // Current maximum speed in NewGRF units
+ if (!v->IsPrimaryVehicle()) return 0;
+ return v->GetCurrentMaxSpeed();
+
/* Variables which use the parameter */
case 0x60: // Count consist's engine ID occurance
if (v->type != VEH_TRAIN) return v->GetEngine()->grf_prop.local_id == parameter ? 1 : 0;
diff --git a/src/ship.h b/src/ship.h
index 6096ae055..e471e7fb1 100644
--- a/src/ship.h
+++ b/src/ship.h
@@ -37,6 +37,7 @@ struct Ship FINAL : public SpecializedVehicle<Ship, VEH_SHIP> {
SpriteID GetImage(Direction direction, EngineImageType image_type) const;
int GetDisplaySpeed() const { return this->cur_speed / 2; }
int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed / 2; }
+ int GetCurrentMaxSpeed() const { return min(this->vcache.cached_max_speed, this->current_order.max_speed * 2); }
Money GetRunningCost() const;
bool IsInDepot() const { return this->state == TRACK_BIT_DEPOT; }
bool Tick();
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 2de9dd5e8..3379bec2a 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -369,6 +369,8 @@ int Train::GetCurveSpeedLimit() const
*/
int Train::GetCurrentMaxSpeed() const
{
+ if (_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL) return min(this->gcache.cached_max_track_speed, this->current_order.max_speed);
+
int max_speed = this->tcache.cached_max_curve_speed;
assert(max_speed == this->GetCurveSpeedLimit());
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index a605e64ec..7b2f371fa 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -399,6 +399,12 @@ public:
virtual int GetDisplayMaxSpeed() const { return 0; }
/**
+ * Calculates the maximum speed of the vehicle under its current conditions.
+ * @return Current maximum speed in native units.
+ */
+ virtual int GetCurrentMaxSpeed() const { return 0; }
+
+ /**
* Gets the running cost of a vehicle
* @return the vehicle's running cost
*/