(svn r13681) -Revert (r13678, r13677): the fixes didn't work in all cases (assertions on savegame loads).
authorrubidium
Tue, 08 Jul 2008 15:10:23 +0000
changeset 11123 a3752bbcc23b
parent 11122 ef4f97adc383
child 11124 cc6f23e84ef4
(svn r13681) -Revert (r13678, r13677): the fixes didn't work in all cases (assertions on savegame loads).
-Fix [FS#2102]: but now in a hopefully beter way.
src/elrail.cpp
src/openttd.cpp
src/vehicle.cpp
src/vehicle_base.h
--- a/src/elrail.cpp	Mon Jul 07 16:04:38 2008 +0000
+++ b/src/elrail.cpp	Tue Jul 08 15:10:23 2008 +0000
@@ -495,10 +495,13 @@
 		}
 	}
 
-	/* setup total power for trains */
+	/* Fix the total power and acceleration for trains */
 	FOR_ALL_VEHICLES(v) {
-		/* power is cached only for front engines */
-		if (v->type == VEH_TRAIN && IsFrontEngine(v)) TrainPowerChanged(v);
+		/* power and acceleration is cached only for front engines */
+		if (v->type == VEH_TRAIN && IsFrontEngine(v)) {
+			TrainPowerChanged(v);
+			UpdateTrainAcceleration(v);
+		}
 	}
 
 	FOR_ALL_PLAYERS(p) p->avail_railtypes = GetPlayerRailtypes(p->index);
--- a/src/openttd.cpp	Mon Jul 07 16:04:38 2008 +0000
+++ b/src/openttd.cpp	Tue Jul 08 15:10:23 2008 +0000
@@ -1265,8 +1265,6 @@
 		}
 	}
 
-	InitializeVehicleCaches();
-
 	SetCachedEngineCounts();
 
 	/* Towns have a noise controlled number of airports system
--- a/src/vehicle.cpp	Mon Jul 07 16:04:38 2008 +0000
+++ b/src/vehicle.cpp	Tue Jul 08 15:10:23 2008 +0000
@@ -275,8 +275,17 @@
 	}
 
 	FOR_ALL_VEHICLES(v) {
-		assert(v->First() != NULL);
-
+		assert(v->first != NULL);
+
+		if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) {
+			if (IsFrontEngine(v)) v->u.rail.last_speed = v->cur_speed; // update displayed train speed
+			TrainConsistChanged(v);
+		} else if (v->type == VEH_ROAD && IsRoadVehFront(v)) {
+			RoadVehUpdateCache(v);
+		}
+	}
+
+	FOR_ALL_VEHICLES(v) {
 		switch (v->type) {
 			case VEH_ROAD:
 				v->u.road.roadtype = HasBit(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD;
@@ -312,19 +321,6 @@
 	}
 }
 
-void InitializeVehicleCaches()
-{
-	Vehicle *v;
-	FOR_ALL_VEHICLES(v) {
-		if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) {
-			if (IsFrontEngine(v)) v->u.rail.last_speed = v->cur_speed; // update displayed train speed
-			TrainConsistChanged(v);
-		} else if (v->type == VEH_ROAD && IsRoadVehFront(v)) {
-			RoadVehUpdateCache(v);
-		}
-	}
-}
-
 Vehicle::Vehicle()
 {
 	this->type               = VEH_INVALID;
--- a/src/vehicle_base.h	Mon Jul 07 16:04:38 2008 +0000
+++ b/src/vehicle_base.h	Tue Jul 08 15:10:23 2008 +0000
@@ -191,7 +191,6 @@
 struct SaveLoad;
 extern const SaveLoad *GetVehicleDescription(VehicleType vt);
 extern void AfterLoadVehicles(bool clear_te_id);
-extern void InitializeVehicleCaches();
 struct LoadgameState;
 extern bool LoadOldVehicle(LoadgameState *ls, int num);