summaryrefslogtreecommitdiff
path: root/src/ground_vehicle.cpp
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2010-08-02 14:54:47 +0000
committerterkhen <terkhen@openttd.org>2010-08-02 14:54:47 +0000
commitcded122da519b72a00c0432a7129a5a9f8ee97e7 (patch)
tree87e542bc3a5a2428b81aa39b0ebe5d057c1b7f36 /src/ground_vehicle.cpp
parent7d0297f96710d658e09c7494637030921c1bc4a5 (diff)
downloadopenttd-cded122da519b72a00c0432a7129a5a9f8ee97e7.tar.xz
(svn r20303) -Feature: [NewGRF] Air drag property support for trains and road vehicles. Air drag for vehicles with air drag not set or set to zero will use a default value depending on their max speed.
Diffstat (limited to 'src/ground_vehicle.cpp')
-rw-r--r--src/ground_vehicle.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/ground_vehicle.cpp b/src/ground_vehicle.cpp
index 6ccba6aa7..0ea7cef8b 100644
--- a/src/ground_vehicle.cpp
+++ b/src/ground_vehicle.cpp
@@ -46,7 +46,20 @@ void GroundVehicle<T, Type>::PowerChanged()
}
this->acc_cache.cached_axle_resistance = 60 * number_of_parts;
- this->acc_cache.cached_air_drag = 20 + 3 * 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. */
+ air_drag = (max_track_speed <= 10) ? 192 : max(2048 / max_track_speed, 1);
+ } else {
+ /* According to the specs, a value of 0x01 in the air drag property means "no air drag". */
+ air_drag = (air_drag_value == 1) ? 0 : air_drag_value;
+ }
+
+ this->acc_cache.cached_air_drag = air_drag + 3 * air_drag * number_of_parts / 20;
max_te *= 10000; // Tractive effort in (tonnes * 1000 * 10 =) N.
max_te /= 256; // Tractive effort is a [0-255] coefficient.