summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2008-03-24 00:52:28 +0000
committerglx <glx@openttd.org>2008-03-24 00:52:28 +0000
commit3f3598bd762f7994141998e968c833050f068186 (patch)
tree7f6efc93e8af51ff47ce92a453445285c1e54a04 /src
parent83fec1b29769a2a87bc10cc5ec43fc5592b4b0c4 (diff)
downloadopenttd-3f3598bd762f7994141998e968c833050f068186.tar.xz
(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.
Diffstat (limited to 'src')
-rw-r--r--src/oldloader.cpp30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/oldloader.cpp b/src/oldloader.cpp
index 7a7173660..0c985c375 100644
--- a/src/oldloader.cpp
+++ b/src/oldloader.cpp
@@ -1111,17 +1111,15 @@ static bool LoadOldVehicleUnion(LoadgameState *ls, int num)
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 bool LoadOldVehicleUnion(LoadgameState *ls, int num)
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 @@ bool LoadOldVehicle(LoadgameState *ls, int num)
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... */