changeset 15639:c3f5c85493f7 draft

(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.
author terkhen <terkhen@openttd.org>
date Mon, 02 Aug 2010 14:54:47 +0000
parents ac0992c935b9
children a659b7cadd64
files src/ground_vehicle.cpp src/table/engines.h
diffstat 2 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/ground_vehicle.cpp
+++ b/src/ground_vehicle.cpp
@@ -46,7 +46,20 @@
 	}
 
 	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.
--- a/src/table/engines.h
+++ b/src/table/engines.h
@@ -362,6 +362,7 @@
  * @param j railtype
  * @param k engclass
  * Tractive effort coefficient by default is the same as TTDPatch, 0.30*256=76
+ * Air drag value depends on the top speed of the vehicle.
  */
 #define RVI(a, b, c, d, e, f, g, h, i, j, k) { a, b, c, {j}, d, e, f, g, h, k, i, 0, 0, 0, 0, 0, 76, 0, 0 }
 #define M RAILVEH_MULTIHEAD
@@ -642,6 +643,7 @@
  * @param g weight (1/4 ton)
  * @param h power (10 hp)
  * Tractive effort coefficient by default is the same as TTDPatch, 0.30*256=76
+ * Air drag value depends on the top speed of the vehicle.
  */
 #define ROV(a, b, c, d, e, f, g, h) { a, b, c, PR_RUNNING_ROADVEH, d, e, f, g, h, 76, 0 }
 static const RoadVehicleInfo _orig_road_vehicle_info[] = {