(svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
authorglx
Mon, 24 Mar 2008 00:52:28 +0000
changeset 8725 82b411efffdc
parent 8724 9a3f2c2116fd
child 8726 0d8a2fdb5bbb
(svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
src/oldloader.cpp
--- a/src/oldloader.cpp	Sun Mar 23 21:31:43 2008 +0000
+++ b/src/oldloader.cpp	Mon Mar 24 00:52:28 2008 +0000
@@ -1111,17 +1111,15 @@
 	uint temp = ls->total_read;
 	bool res;
 
-	/* We changed the offset of the vehicle types, so fix it
-	 * Basically v->type -= 0x10; would suffice, but play safely */
 	switch (v->type) {
 		default: NOT_REACHED();
-		case 0x00 /*VEH_INVALID */: v = new (v) InvalidVehicle();  res = LoadChunk(ls, NULL,           vehicle_empty_chunk);    break;
-		case 0x10 /*VEH_TRAIN   */: v = new (v) Train();           res = LoadChunk(ls, &v->u.rail,     vehicle_train_chunk);    break;
-		case 0x11 /*VEH_ROAD    */: v = new (v) RoadVehicle();     res = LoadChunk(ls, &v->u.road,     vehicle_road_chunk);     break;
-		case 0x12 /*VEH_SHIP    */: v = new (v) Ship();            res = LoadChunk(ls, &v->u.ship,     vehicle_ship_chunk);     break;
-		case 0x13 /*VEH_AIRCRAFT*/: v = new (v) Aircraft();        res = LoadChunk(ls, &v->u.air,      vehicle_air_chunk);      break;
-		case 0x14 /*VEH_SPECIAL */: v = new (v) SpecialVehicle();  res = LoadChunk(ls, &v->u.special,  vehicle_special_chunk);  break;
-		case 0x15 /*VEH_DISASTER*/: v = new (v) DisasterVehicle(); res = LoadChunk(ls, &v->u.disaster, vehicle_disaster_chunk); break;
+		case VEH_INVALID : res = LoadChunk(ls, NULL,           vehicle_empty_chunk);    break;
+		case VEH_TRAIN   : res = LoadChunk(ls, &v->u.rail,     vehicle_train_chunk);    break;
+		case VEH_ROAD    : res = LoadChunk(ls, &v->u.road,     vehicle_road_chunk);     break;
+		case VEH_SHIP    : res = LoadChunk(ls, &v->u.ship,     vehicle_ship_chunk);     break;
+		case VEH_AIRCRAFT: res = LoadChunk(ls, &v->u.air,      vehicle_air_chunk);      break;
+		case VEH_SPECIAL : res = LoadChunk(ls, &v->u.special,  vehicle_special_chunk);  break;
+		case VEH_DISASTER: res = LoadChunk(ls, &v->u.disaster, vehicle_disaster_chunk); break;
 	}
 
 	/* This chunk size should always be 10 bytes */
@@ -1136,7 +1134,6 @@
 static uint16 _cargo_count;
 
 static const OldChunks vehicle_chunk[] = {
-	OCL_SVAR(  OC_UINT8, Vehicle, type ),
 	OCL_SVAR(  OC_UINT8, Vehicle, subtype ),
 
 	OCL_NULL( 2 ),         ///< Hash, calculated automatically
@@ -1225,7 +1222,18 @@
 	for (i = 0; i < _old_vehicle_multiplier; i++) {
 		_current_vehicle_id = num * _old_vehicle_multiplier + i;
 
-		Vehicle *v = new (_current_vehicle_id) InvalidVehicle();
+		/* Read the vehicle type and allocate the right vehicle */
+		Vehicle *v;
+		switch (ReadByte(ls)) {
+			default: NOT_REACHED();
+			case 0x00 /*VEH_INVALID */: v = new (_current_vehicle_id) InvalidVehicle();  break;
+			case 0x10 /*VEH_TRAIN   */: v = new (_current_vehicle_id) Train();           break;
+			case 0x11 /*VEH_ROAD    */: v = new (_current_vehicle_id) RoadVehicle();     break;
+			case 0x12 /*VEH_SHIP    */: v = new (_current_vehicle_id) Ship();            break;
+			case 0x13 /*VEH_AIRCRAFT*/: v = new (_current_vehicle_id) Aircraft();        break;
+			case 0x14 /*VEH_SPECIAL */: v = new (_current_vehicle_id) SpecialVehicle();  break;
+			case 0x15 /*VEH_DISASTER*/: v = new (_current_vehicle_id) DisasterVehicle(); break;
+		}
 		if (!LoadChunk(ls, v, vehicle_chunk)) return false;
 
 		/* This should be consistent, else we have a big problem... */