changeset 16347:8c9974e20b1c draft

(svn r21058) -Feature [NewGRF]: Add CB36 support for road vehicle properties 0x13 (Power), 0x14 (Weight) and 0x18 (Tractive effort).
author terkhen <terkhen@openttd.org>
date Sat, 30 Oct 2010 14:31:49 +0000
parents f98b6c94ef7f
children 47fa3333e773
files src/engine.cpp src/newgrf.cpp src/newgrf_properties.h src/roadveh.h
diffstat 4 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -319,7 +319,7 @@
 		case VEH_TRAIN:
 			return GetEngineProperty(this->index, PROP_TRAIN_POWER, this->u.rail.power);
 		case VEH_ROAD:
-			return this->u.road.power * 10;
+			return GetEngineProperty(this->index, PROP_ROADVEH_POWER, this->u.road.power) * 10;
 
 		default: NOT_REACHED();
 	}
@@ -337,7 +337,7 @@
 		case VEH_TRAIN:
 			return GetEngineProperty(this->index, PROP_TRAIN_WEIGHT, this->u.rail.weight) << (this->u.rail.railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
 		case VEH_ROAD:
-			return this->u.road.weight / 4;
+			return GetEngineProperty(this->index, PROP_ROADVEH_WEIGHT, this->u.road.weight) / 4;
 
 		default: NOT_REACHED();
 	}
@@ -355,7 +355,7 @@
 		case VEH_TRAIN:
 			return (10 * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_TRAIN_TRACTIVE_EFFORT, this->u.rail.tractive_effort)) / 256;
 		case VEH_ROAD:
-			return (10 * this->GetDisplayWeight() * this->u.road.tractive_effort) / 256;
+			return (10 * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_ROADVEH_TRACTIVE_EFFORT, this->u.road.tractive_effort)) / 256;
 
 		default: NOT_REACHED();
 	}
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -824,11 +824,11 @@
 				rvi->sfx = buf->ReadByte();
 				break;
 
-			case 0x13: // Power in 10hp
+			case PROP_ROADVEH_POWER: // Power in units of 10 HP.
 				rvi->power = buf->ReadByte();
 				break;
 
-			case 0x14: // Weight in 1/4 tons
+			case PROP_ROADVEH_WEIGHT: // Weight in units of 1/4 tons.
 				rvi->weight = buf->ReadByte();
 				break;
 
@@ -845,7 +845,7 @@
 				ei->callback_mask = buf->ReadByte();
 				break;
 
-			case 0x18: // Tractive effort
+			case PROP_ROADVEH_TRACTIVE_EFFORT: // Tractive effort coefficient in 1/256.
 				rvi->tractive_effort = buf->ReadByte();
 				break;
 
--- a/src/newgrf_properties.h
+++ b/src/newgrf_properties.h
@@ -30,6 +30,9 @@
 	PROP_ROADVEH_RUNNING_COST_FACTOR            = 0x09, ///< Yearly runningcost
 	PROP_ROADVEH_CARGO_CAPACITY                 = 0x0F, ///< Capacity
 	PROP_ROADVEH_COST_FACTOR                    = 0x11, ///< Purchase cost
+	PROP_ROADVEH_POWER                          = 0x13, ///< Power in 10 HP
+	PROP_ROADVEH_WEIGHT                         = 0x14, ///< Weight in 1/4 t
+	PROP_ROADVEH_TRACTIVE_EFFORT                = 0x18, ///< Tractive effort coefficient in 1/256
 
 	PROP_SHIP_COST_FACTOR                       = 0x0A, ///< Purchase cost
 	PROP_SHIP_SPEED                             = 0x0B, ///< Max. speed: 1 unit = 1/3.2 mph = 0.5 km-ish/h
--- a/src/roadveh.h
+++ b/src/roadveh.h
@@ -17,6 +17,8 @@
 #include "cargotype.h"
 #include "track_func.h"
 #include "road_type.h"
+#include "newgrf_properties.h"
+#include "newgrf_engine.h"
 
 struct RoadVehicle;
 
@@ -171,7 +173,8 @@
 	{
 		/* Power is not added for articulated parts */
 		if (!this->IsArticulatedPart()) {
-			return 10 * RoadVehInfo(this->engine_type)->power; // Road vehicle power is in units of 10 HP.
+			/* Road vehicle power is in units of 10 HP. */
+			return 10 * GetVehicleProperty(this, PROP_ROADVEH_POWER, RoadVehInfo(this->engine_type)->power);
 		}
 		return 0;
 	}
@@ -195,7 +198,8 @@
 
 		/* Vehicle weight is not added for articulated parts. */
 		if (!this->IsArticulatedPart()) {
-			weight += RoadVehInfo(this->engine_type)->weight / 4; // Road vehicle weight is in units of 1/4 t.
+			/* Road vehicle weight is in units of 1/4 t. */
+			weight += GetVehicleProperty(this, PROP_ROADVEH_WEIGHT, RoadVehInfo(this->engine_type)->weight) / 4;
 		}
 
 		return weight;
@@ -207,7 +211,8 @@
 	 */
 	FORCEINLINE byte GetTractiveEffort() const
 	{
-		return RoadVehInfo(this->engine_type)->tractive_effort;
+		/* The tractive effort coefficient is in units of 1/256.  */
+		return GetVehicleProperty(this, PROP_ROADVEH_TRACTIVE_EFFORT, RoadVehInfo(this->engine_type)->tractive_effort);
 	}
 
 	/**