Changeset - r16380:aa3ab792f276
[Not reviewed]
master
0 4 0
michi_cc - 14 years ago 2010-11-07 13:35:07
michi_cc@openttd.org
(svn r21106) -Change: Tuned realistic acceleration to be a bit more realistic in order to make acceleration "slower", which highlights the differences between vehicle types more.
4 files changed with 40 insertions and 33 deletions:
0 comments (0 inline, 0 general)
src/ground_vehicle.cpp
Show inline comments
 
@@ -27,27 +27,24 @@ void GroundVehicle<T, Type>::PowerChange
 
	uint32 total_power = 0;
 
	uint32 max_te = 0;
 
	uint32 number_of_parts = 0;
 
	uint16 max_track_speed = v->GetDisplayMaxSpeed();
 

	
 
	for (const T *u = v; u != NULL; u = u->Next()) {
 
		uint32 current_power = u->GetPower();
 
		uint32 current_power = u->GetPower() + u->GetPoweredPartPower(u);
 
		total_power += current_power;
 

	
 
		/* Only powered parts add tractive effort. */
 
		if (current_power > 0) max_te += u->GetWeight() * u->GetTractiveEffort();
 
		total_power += u->GetPoweredPartPower(v);
 
		number_of_parts++;
 

	
 
		/* Get minimum max speed for this track. */
 
		uint16 track_speed = u->GetMaxTrackSpeed();
 
		if (track_speed > 0) max_track_speed = min(max_track_speed, track_speed);
 
	}
 

	
 
	this->acc_cache.cached_axle_resistance = 60 * number_of_parts;
 

	
 
	byte air_drag;
 
	byte air_drag_value = v->GetAirDrag();
 

	
 
	/* If air drag is set to zero (default), the resulting air drag coefficient is dependent on max speed. */
 
	if (air_drag_value == 0) {
 
		/* Simplification of the method used in TTDPatch. It uses <= 10 to change more steadily from 128 to 196. */
 
@@ -84,17 +81,20 @@ void GroundVehicle<T, Type>::CargoChange
 
	assert(this->First() == this);
 
	uint32 weight = 0;
 

	
 
	for (T *u = T::From(this); u != NULL; u = u->Next()) {
 
		uint32 current_weight = u->GetWeight();
 
		weight += current_weight;
 
		u->acc_cache.cached_slope_resistance = current_weight * u->GetSlopeSteepness();
 
		/* Slope steepness is in percent, result in N. */
 
		u->acc_cache.cached_slope_resistance = current_weight * u->GetSlopeSteepness() * 100;
 
	}
 

	
 
	/* Store consist weight in cache. */
 
	this->acc_cache.cached_weight = max<uint32>(1, weight);
 
	/* Friction in bearings and other mechanical parts is 0.1% of the weight (result in N). */
 
	this->acc_cache.cached_axle_resistance = 10 * weight;
 

	
 
	/* Now update vehicle power (tractive effort is dependent on weight). */
 
	this->PowerChanged();
 
}
 

	
 
/**
 
@@ -103,13 +103,13 @@ void GroundVehicle<T, Type>::CargoChange
 
 */
 
template <class T, VehicleType Type>
 
int GroundVehicle<T, Type>::GetAcceleration() const
 
{
 
	/* Templated class used for function calls for performance reasons. */
 
	const T *v = T::From(this);
 
	int32 speed = v->GetCurrentSpeed();
 
	int32 speed = v->GetCurrentSpeed(); // [km/h-ish]
 

	
 
	/* Weight is stored in tonnes. */
 
	int32 mass = this->acc_cache.cached_weight;
 

	
 
	/* Power is stored in HP, we need it in watts. */
 
	int32 power = this->acc_cache.cached_power * 746;
 
@@ -117,33 +117,31 @@ int GroundVehicle<T, Type>::GetAccelerat
 
	int32 resistance = 0;
 

	
 
	bool maglev = v->GetAccelerationType() == 2;
 

	
 
	const int area = v->GetAirDragArea();
 
	if (!maglev) {
 
		resistance = (13 * mass) / 10;
 
		resistance += this->acc_cache.cached_axle_resistance;
 
		resistance += (v->GetRollingFriction() * mass * speed) / 1000;
 
		resistance += (area * this->acc_cache.cached_air_drag * speed * speed) / 10000;
 
	} else {
 
		resistance += (area * this->acc_cache.cached_air_drag * speed * speed) / 20000;
 
		/* Static resistance plus rolling friction. */
 
		resistance = this->acc_cache.cached_axle_resistance;
 
		resistance += mass * v->GetRollingFriction();
 
	}
 
	/* Air drag; the air drag coefficient is in an arbitrary NewGRF-unit,
 
	 * so we need some magic conversion factor. */
 
	resistance += (area * this->acc_cache.cached_air_drag * speed * speed) / 500;
 

	
 
	resistance += this->GetSlopeResistance();
 
	resistance *= 4; //[N]
 

	
 
	/* This value allows to know if the vehicle is accelerating or braking. */
 
	AccelStatus mode = v->GetAccelerationStatus();
 

	
 
	const int max_te = this->acc_cache.cached_max_te; // [N]
 
	int force;
 
	if (speed > 0) {
 
		if (!maglev) {
 
			force = power / speed; //[N]
 
			force *= 22;
 
			force /= 10;
 
			/* Conversion factor from km/h to m/s is 5/18 to get [N] in the end. */
 
			force = power * 18 / (speed * 5);
 
			if (mode == AS_ACCEL && force > max_te) force = max_te;
 
		} else {
 
			force = power / 25;
 
		}
 
	} else {
 
		/* "Kickoff" acceleration. */
src/ground_vehicle.hpp
Show inline comments
 
@@ -27,18 +27,18 @@ enum AccelStatus {
 
 */
 
struct AccelerationCache {
 
	/* Cached values, recalculated when the cargo on a vehicle changes (in addition to the conditions below) */
 
	uint32 cached_weight;           ///< Total weight of the consist.
 
	uint32 cached_slope_resistance; ///< Resistance caused by weight when this vehicle part is at a slope.
 
	uint32 cached_max_te;           ///< Maximum tractive effort of consist.
 
	uint16 cached_axle_resistance;  ///< Resistance caused by the axles of the vehicle.
 

	
 
	/* Cached values, recalculated on load and each time a vehicle is added to/removed from the consist. */
 
	uint16 cached_max_track_speed;  ///< Maximum consist speed limited by track type.
 
	uint32 cached_power;            ///< Total power of the consist.
 
	uint32 cached_air_drag;         ///< Air drag coefficient of the vehicle.
 
	uint16 cached_axle_resistance;  ///< Resistance caused by the axles of the vehicle.
 
	uint16 cached_max_track_speed;  ///< Maximum consist speed limited by track type.
 
};
 

	
 
/** Ground vehicle flags. */
 
enum GroundVehicleFlags {
 
	GVF_GOINGUP_BIT       = 0,
 
	GVF_GOINGDOWN_BIT     = 1,
src/roadveh.h
Show inline comments
 
@@ -214,17 +214,17 @@ protected: // These functions should not
 
		/* The tractive effort coefficient is in units of 1/256.  */
 
		return GetVehicleProperty(this, PROP_ROADVEH_TRACTIVE_EFFORT, RoadVehInfo(this->engine_type)->tractive_effort);
 
	}
 

	
 
	/**
 
	 * Gets the area used for calculating air drag.
 
	 * @return Area of the engine.
 
	 * @return Area of the engine in m^2.
 
	 */
 
	FORCEINLINE byte GetAirDragArea() const
 
	{
 
		return 60;
 
		return 6;
 
	}
 

	
 
	/**
 
	 * Gets the air drag coefficient of this vehicle.
 
	 * @return Air drag value from the engine.
 
	 */
 
@@ -241,27 +241,31 @@ protected: // These functions should not
 
	{
 
		return (this->vehstatus & VS_STOPPED) ? AS_BRAKE : AS_ACCEL;
 
	}
 

	
 
	/**
 
	 * Calculates the current speed of this vehicle.
 
	 * @return Current speed in mph.
 
	 * @return Current speed in km/h-ish.
 
	 */
 
	FORCEINLINE uint16 GetCurrentSpeed() const
 
	{
 
		return this->cur_speed * 10 / 32;
 
		return this->cur_speed / 2;
 
	}
 

	
 
	/**
 
	 * Returns the rolling friction coefficient of this vehicle.
 
	 * @return Rolling friction coefficient in [1e-3].
 
	 * @return Rolling friction coefficient in [1e-4].
 
	 */
 
	FORCEINLINE uint32 GetRollingFriction() const
 
	{
 
		/* Trams have a slightly greater friction coefficient than trains. The rest of road vehicles have bigger values. */
 
		return (this->roadtype == ROADTYPE_TRAM) ? 50 : 75;
 
		/* Trams have a slightly greater friction coefficient than trains.
 
		 * The rest of road vehicles have bigger values. */
 
		uint32 coeff = (this->roadtype == ROADTYPE_TRAM) ? 40 : 75;
 
		/* The friction coefficient increases with speed in a way that
 
		 * it doubles at 128 km/h, triples at 256 km/h and so on. */
 
		return coeff * (128 + this->GetCurrentSpeed()) / 128;
 
	}
 

	
 
	/**
 
	 * Allows to know the acceleration type of a vehicle.
 
	 * @return Zero, road vehicles always use a normal acceleration method.
 
	 */
 
@@ -273,13 +277,13 @@ protected: // These functions should not
 
	/**
 
	 * Returns the slope steepness used by this vehicle.
 
	 * @return Slope steepness used by the vehicle.
 
	 */
 
	FORCEINLINE uint32 GetSlopeSteepness() const
 
	{
 
		return 20 * _settings_game.vehicle.roadveh_slope_steepness; // 1% slope * slope steepness
 
		return _settings_game.vehicle.roadveh_slope_steepness;
 
	}
 

	
 
	/**
 
	 * Gets the maximum speed allowed by the track for this vehicle.
 
	 * @return Since roads don't limit road vehicle speed, it returns always zero.
 
	 */
src/train.h
Show inline comments
 
@@ -435,17 +435,18 @@ protected: // These functions should not
 
	{
 
		return GetVehicleProperty(this, PROP_TRAIN_TRACTIVE_EFFORT, RailVehInfo(this->engine_type)->tractive_effort);
 
	}
 

	
 
	/**
 
	 * Gets the area used for calculating air drag.
 
	 * @return Area of the engine.
 
	 * @return Area of the engine in m^2.
 
	 */
 
	FORCEINLINE byte GetAirDragArea() const
 
	{
 
		return 120;
 
		/* Air drag is higher in tunnels due to the limited cross-section. */
 
		return (this->track == TRACK_BIT_WORMHOLE && this->vehstatus & VS_HIDDEN) ? 28 : 14;
 
	}
 

	
 
	/**
 
	 * Gets the air drag coefficient of this vehicle.
 
	 * @return Air drag value from the engine.
 
	 */
 
@@ -462,26 +463,30 @@ protected: // These functions should not
 
	{
 
		return (this->vehstatus & VS_STOPPED) || HasBit(this->flags, VRF_REVERSING) || HasBit(this->flags, VRF_TRAIN_STUCK) ? AS_BRAKE : AS_ACCEL;
 
	}
 

	
 
	/**
 
	 * Calculates the current speed of this vehicle.
 
	 * @return Current speed in mph.
 
	 * @return Current speed in km/h-ish.
 
	 */
 
	FORCEINLINE uint16 GetCurrentSpeed() const
 
	{
 
		return this->cur_speed * 10 / 16;
 
		return this->cur_speed;
 
	}
 

	
 
	/**
 
	 * Returns the rolling friction coefficient of this vehicle.
 
	 * @return Rolling friction coefficient in [1e-3].
 
	 * @return Rolling friction coefficient in [1e-4].
 
	 */
 
	FORCEINLINE uint32 GetRollingFriction() const
 
	{
 
		return 35;
 
		/* Rolling friction for steel on steel is between 0.1% and 0.2%,
 
		 * but we use a higher value here to get better game-play results.
 
		 * The friction coefficient increases with speed in a way that
 
		 * it doubles at 512 km/h, triples at 1024 km/h and so on. */
 
		return 30 * (512 + this->GetCurrentSpeed()) / 512;
 
	}
 

	
 
	/**
 
	 * Allows to know the acceleration type of a vehicle.
 
	 * @return Acceleration type of the vehicle.
 
	 */
 
@@ -493,13 +498,13 @@ protected: // These functions should not
 
	/**
 
	 * Returns the slope steepness used by this vehicle.
 
	 * @return Slope steepness used by the vehicle.
 
	 */
 
	FORCEINLINE uint32 GetSlopeSteepness() const
 
	{
 
		return 20 * _settings_game.vehicle.train_slope_steepness; // 1% slope * slope steepness
 
		return _settings_game.vehicle.train_slope_steepness;
 
	}
 

	
 
	/**
 
	 * Gets the maximum speed allowed by the track for this vehicle.
 
	 * @return Maximum speed allowed.
 
	 */
0 comments (0 inline, 0 general)