Fix #6920: Make 9.8m/s^2 a common constant for TE-calculation

pull/73/head
Johannes E. Krause 6 years ago committed by Michael Lutz
parent 060248a422
commit 662dcc3c31

@ -1292,7 +1292,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRunningCost(): 820 GetRunningCost(): 820
GetPower(): 300 GetPower(): 300
GetWeight(): 47 GetWeight(): 47
GetMaxTractiveEffort(): 139 GetMaxTractiveEffort(): 136
GetVehicleType(): 0 GetVehicleType(): 0
GetRailType(): 0 GetRailType(): 0
GetRoadType(): -1 GetRoadType(): -1
@ -1436,7 +1436,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRunningCost(): 1968 GetRunningCost(): 1968
GetPower(): 1000 GetPower(): 1000
GetWeight(): 131 GetWeight(): 131
GetMaxTractiveEffort(): 388 GetMaxTractiveEffort(): 381
GetVehicleType(): 0 GetVehicleType(): 0
GetRailType(): 0 GetRailType(): 0
GetRoadType(): -1 GetRoadType(): -1
@ -1454,7 +1454,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRunningCost(): 2296 GetRunningCost(): 2296
GetPower(): 1200 GetPower(): 1200
GetWeight(): 162 GetWeight(): 162
GetMaxTractiveEffort(): 480 GetMaxTractiveEffort(): 471
GetVehicleType(): 0 GetVehicleType(): 0
GetRailType(): 0 GetRailType(): 0
GetRoadType(): -1 GetRoadType(): -1

@ -431,9 +431,9 @@ uint Engine::GetDisplayMaxTractiveEffort() const
/* Only trains and road vehicles have 'tractive effort'. */ /* Only trains and road vehicles have 'tractive effort'. */
switch (this->type) { switch (this->type) {
case VEH_TRAIN: case VEH_TRAIN:
return (10 * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_TRAIN_TRACTIVE_EFFORT, this->u.rail.tractive_effort)) / 256; return (GROUND_ACCELERATION * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_TRAIN_TRACTIVE_EFFORT, this->u.rail.tractive_effort)) / 256 / 1000;
case VEH_ROAD: case VEH_ROAD:
return (10 * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_ROADVEH_TRACTIVE_EFFORT, this->u.road.tractive_effort)) / 256; return (GROUND_ACCELERATION * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_ROADVEH_TRACTIVE_EFFORT, this->u.road.tractive_effort)) / 256 / 1000;
default: NOT_REACHED(); default: NOT_REACHED();
} }

@ -58,7 +58,7 @@ void GroundVehicle<T, Type>::PowerChanged()
this->gcache.cached_air_drag = air_drag + 3 * air_drag * number_of_parts / 20; this->gcache.cached_air_drag = air_drag + 3 * air_drag * number_of_parts / 20;
max_te *= 9800; // Tractive effort in (tonnes * 1000 * 9.8 =) N. max_te *= GROUND_ACCELERATION; // Tractive effort in (tonnes * 1000 * 9.8 =) N.
max_te /= 256; // Tractive effort is a [0-255] coefficient. max_te /= 256; // Tractive effort is a [0-255] coefficient.
if (this->gcache.cached_power != total_power || this->gcache.cached_max_te != max_te) { if (this->gcache.cached_power != total_power || this->gcache.cached_max_te != max_te) {
/* Stop the vehicle if it has no power. */ /* Stop the vehicle if it has no power. */

@ -17,6 +17,8 @@
/** The type all our vehicle IDs have. */ /** The type all our vehicle IDs have. */
typedef uint32 VehicleID; typedef uint32 VehicleID;
static const int GROUND_ACCELERATION = 9800; ///< Acceleration due to gravity, 9.8 m/s^2
/** Available vehicle types. */ /** Available vehicle types. */
enum VehicleType { enum VehicleType {
VEH_BEGIN, VEH_BEGIN,

Loading…
Cancel
Save