From bf9caa425b9ef1152c8d45245e99be4dd732c1a6 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 8 May 2023 23:10:14 +0100 Subject: [PATCH] Change: Units-system can convert from N to kN, don't preconvert. This allows force to passed as is and avoid premature rounding. The AI function "GetMaxTractiveEffort" still needs to return kN to avoid breaking the API. --- src/engine.cpp | 4 ++-- src/script/api/script_engine.cpp | 2 +- src/strings.cpp | 6 +++--- src/vehicle_gui.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/engine.cpp b/src/engine.cpp index 0cc6e9cf52..591710905e 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -423,9 +423,9 @@ uint Engine::GetDisplayMaxTractiveEffort() const /* Only trains and road vehicles have 'tractive effort'. */ switch (this->type) { case VEH_TRAIN: - return (GROUND_ACCELERATION * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_TRAIN_TRACTIVE_EFFORT, this->u.rail.tractive_effort)) / 256 / 1000; + return (GROUND_ACCELERATION * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_TRAIN_TRACTIVE_EFFORT, this->u.rail.tractive_effort)) / 256; case VEH_ROAD: - return (GROUND_ACCELERATION * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_ROADVEH_TRACTIVE_EFFORT, this->u.road.tractive_effort)) / 256 / 1000; + return (GROUND_ACCELERATION * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_ROADVEH_TRACTIVE_EFFORT, this->u.road.tractive_effort)) / 256; default: NOT_REACHED(); } diff --git a/src/script/api/script_engine.cpp b/src/script/api/script_engine.cpp index 17845ae4fe..db16861212 100644 --- a/src/script/api/script_engine.cpp +++ b/src/script/api/script_engine.cpp @@ -172,7 +172,7 @@ if (GetVehicleType(engine_id) != ScriptVehicle::VT_RAIL && GetVehicleType(engine_id) != ScriptVehicle::VT_ROAD) return -1; if (IsWagon(engine_id)) return -1; - return ::Engine::Get(engine_id)->GetDisplayMaxTractiveEffort(); + return ::Engine::Get(engine_id)->GetDisplayMaxTractiveEffort() / 1000; } /* static */ ScriptDate::Date ScriptEngine::GetDesignDate(EngineID engine_id) diff --git a/src/strings.cpp b/src/strings.cpp index 468977196c..0e13ef13bc 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -748,9 +748,9 @@ static const UnitsLong _units_volume[] = { /** Unit conversions for force. */ static const Units _units_force[] = { - { { 224.809 }, STR_UNITS_FORCE_IMPERIAL, 0 }, - { { 101.972 }, STR_UNITS_FORCE_METRIC, 0 }, - { { 1.0 }, STR_UNITS_FORCE_SI, 0 }, + { { 0.224809 }, STR_UNITS_FORCE_IMPERIAL, 0 }, + { { 0.101972 }, STR_UNITS_FORCE_METRIC, 0 }, + { { 0.001 }, STR_UNITS_FORCE_SI, 0 }, }; /** Unit conversions for height. */ diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 50c5267ea9..9bd28e8e43 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -2498,7 +2498,7 @@ struct VehicleDetailsWindow : Window { SetDParam(2, PackVelocity(v->GetDisplayMaxSpeed(), v->type)); SetDParam(1, gcache->cached_power); SetDParam(0, gcache->cached_weight); - SetDParam(3, gcache->cached_max_te / 1000); + SetDParam(3, gcache->cached_max_te); if (v->type == VEH_TRAIN && (_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL || GetRailTypeInfo(Train::From(v)->railtype)->acceleration_type == 2)) { string = STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED;