changeset 2587:a5aed0411e80 draft

(svn r3124) Alter train loading/unloading time to use the actual length of the train instead of the number of wagons. The actual length is cached in the first vehicle of the train.
author peter1138 <peter1138@openttd.org>
date Thu, 03 Nov 2005 09:22:24 +0000
parents 50c492a95d08
children 62b5cb6aa71f
files economy.c train_cmd.c vehicle.h
diffstat 3 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/economy.c
+++ b/economy.c
@@ -1463,13 +1463,12 @@
 		ShowFeederIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, v_profit_total);
 
 	if (v->type == VEH_Train) {
-		int num = - (int)GetStationPlatforms(st, v->tile) * 2;
-		do num++; while ( (v=v->next) != NULL);
-		if (num > 0) {
-			unloading_time <<=1;
-			unloading_time += num * unloading_time;
+		// Each platform tile is worth 2 rail vehicles.
+		int overhang = v->u.rail.cached_total_length - GetStationPlatforms(st, v->tile) * 16;
+		if (overhang > 0) {
+			unloading_time <<= 1;
+			unloading_time += (overhang * unloading_time) / 8;
 		}
-		v = u;
 	}
 
 	v->load_unload_time_rem = unloading_time;
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -83,6 +83,7 @@
 
 	rvi_v = RailVehInfo(v->engine_type);
 	first_engine = (v->subtype == TS_Front_Engine) ? v->engine_type : INVALID_VEHICLE;
+	v->u.rail.cached_total_length = 0;
 
 	for (u = v; u != NULL; u = u->next) {
 		const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type);
@@ -125,6 +126,7 @@
 			veh_len = rvi_u->shorten_factor;
 		veh_len = clamp(veh_len, 0, u->next == NULL ? 7 : 5); // the clamp on vehicles not the last in chain is stricter, as too short wagons can break the 'follow next vehicle' code
 		u->u.rail.cached_veh_length = 8 - veh_len;
+		v->u.rail.cached_total_length += u->u.rail.cached_veh_length;
 
 	};
 
--- a/vehicle.h
+++ b/vehicle.h
@@ -57,6 +57,8 @@
 	uint16 cached_max_speed;  // max speed of the consist. (minimum of the max speed of all vehicles in the consist)
 	uint32 cached_power;      // total power of the consist.
 	uint8 cached_veh_length;  // length of this vehicle in units of 1/8 of normal length, cached because this can be set by a callback
+	uint16 cached_total_length; ///< Length of the whole train, valid only for first engine.
+
 	// cached values, recalculated when the cargo on a train changes (in addition to the conditions above)
 	uint16 cached_weight;     // total weight of the consist.
 	uint16 cached_veh_weight; // weight of the vehicle.