changeset 14415:f58a9eed2663 draft

(svn r18972) -Add: [NewGRF] Per-rail type speed limits.
author peter1138 <peter1138@openttd.org>
date Sun, 31 Jan 2010 13:17:29 +0000
parents 3c6a7fa40269
children 4ab0cc96d96e
files src/newgrf.cpp src/rail.h src/table/railtypes.h src/train.h src/train_cmd.cpp
diffstat 5 files changed, 28 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -2569,7 +2569,7 @@
 				break;
 
 			case 0x14: // Speed limit
-				buf->ReadWord();
+				rti->max_speed = buf->ReadWord();
 				break;
 
 			case 0x15: // Acceleration model
--- a/src/rail.h
+++ b/src/rail.h
@@ -146,6 +146,11 @@
 	uint8 acceleration_type;
 
 	/**
+	 * Maximum speed for vehicles travelling on this rail type
+	 */
+	uint16 max_speed;
+
+	/**
 	 * Unique 32 bit rail type identifier
 	 */
 	RailTypeLabel label;
--- a/src/table/railtypes.h
+++ b/src/table/railtypes.h
@@ -84,6 +84,9 @@
 		/* acceleration type */
 		0,
 
+		/* max speed */
+		0,
+
 		/* rail type label */
 		'RAIL',
 	},
@@ -159,6 +162,9 @@
 		/* acceleration type */
 		0,
 
+		/* max speed */
+		0,
+
 		/* rail type label */
 		'ELRL',
 	},
@@ -230,6 +236,9 @@
 		/* acceleration type */
 		1,
 
+		/* max speed */
+		0,
+
 		/* rail type label */
 		'MONO',
 	},
@@ -301,6 +310,9 @@
 		/* acceleration type */
 		2,
 
+		/* max speed */
+		0,
+
 		/* rail type label */
 		'MGLV',
 	},
--- a/src/train.h
+++ b/src/train.h
@@ -86,6 +86,7 @@
 
 	/* cached max. speed / acceleration data */
 	uint16 cached_max_speed;    ///< max speed of the consist. (minimum of the max speed of all vehicles in the consist)
+	uint16 cached_max_rail_speed; ///< max consist speed limited by rail type
 	int cached_max_curve_speed; ///< max consist speed limited by curves
 
 	/**
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -99,6 +99,7 @@
 	uint32 total_power = 0;
 	uint32 max_te = 0;
 	uint32 number_of_parts = 0;
+	uint16 max_rail_speed = this->tcache.cached_max_speed;
 
 	for (const Train *u = this; u != NULL; u = u->Next()) {
 		uint32 current_power = u->GetPower();
@@ -108,6 +109,10 @@
 		if (current_power > 0) max_te += u->GetWeight() * u->GetTractiveEffort();
 		total_power += u->GetPoweredPartPower(this);
 		number_of_parts++;
+
+		/* Get minimum max speed for rail */
+		uint16 rail_speed = GetRailTypeInfo(GetRailType(u->tile))->max_speed;
+		if (rail_speed > 0) max_rail_speed = min(max_rail_speed, rail_speed);
 	}
 
 	this->tcache.cached_axle_resistance = 60 * number_of_parts;
@@ -124,6 +129,8 @@
 		SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
 		SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
 	}
+
+	this->tcache.cached_max_rail_speed = max_rail_speed;
 }
 
 
@@ -491,7 +498,7 @@
 		}
 	}
 
-	return min(max_speed, this->tcache.cached_max_speed);
+	return min(max_speed, this->tcache.cached_max_rail_speed);
 }
 
 /**
@@ -557,7 +564,7 @@
 {
 	assert(this->IsFrontEngine());
 
-	this->max_speed = this->tcache.cached_max_speed;
+	this->max_speed = this->tcache.cached_max_rail_speed;
 
 	uint power = this->tcache.cached_power;
 	uint weight = this->tcache.cached_weight;