diff --git a/src/aircraft.h b/src/aircraft.h index f47febd62d..b6c847812f 100644 --- a/src/aircraft.h +++ b/src/aircraft.h @@ -76,6 +76,7 @@ struct Aircraft FINAL : public SpecializedVehicle { 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 3c1a93ac02..f4e120aee9 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 6096ae0554..e471e7fb10 100644 --- a/src/ship.h +++ b/src/ship.h @@ -37,6 +37,7 @@ struct Ship FINAL : public SpecializedVehicle { 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 2de9dd5e87..3379bec2a0 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 a605e64ece..7b2f371fa9 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -398,6 +398,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