src/oldloader.cpp
changeset 8725 82b411efffdc
parent 8724 9a3f2c2116fd
child 8785 871586967963
equal deleted inserted replaced
8724:9a3f2c2116fd 8725:82b411efffdc
  1109 {
  1109 {
  1110 	Vehicle *v = GetVehicle(_current_vehicle_id);
  1110 	Vehicle *v = GetVehicle(_current_vehicle_id);
  1111 	uint temp = ls->total_read;
  1111 	uint temp = ls->total_read;
  1112 	bool res;
  1112 	bool res;
  1113 
  1113 
  1114 	/* We changed the offset of the vehicle types, so fix it
       
  1115 	 * Basically v->type -= 0x10; would suffice, but play safely */
       
  1116 	switch (v->type) {
  1114 	switch (v->type) {
  1117 		default: NOT_REACHED();
  1115 		default: NOT_REACHED();
  1118 		case 0x00 /*VEH_INVALID */: v = new (v) InvalidVehicle();  res = LoadChunk(ls, NULL,           vehicle_empty_chunk);    break;
  1116 		case VEH_INVALID : res = LoadChunk(ls, NULL,           vehicle_empty_chunk);    break;
  1119 		case 0x10 /*VEH_TRAIN   */: v = new (v) Train();           res = LoadChunk(ls, &v->u.rail,     vehicle_train_chunk);    break;
  1117 		case VEH_TRAIN   : res = LoadChunk(ls, &v->u.rail,     vehicle_train_chunk);    break;
  1120 		case 0x11 /*VEH_ROAD    */: v = new (v) RoadVehicle();     res = LoadChunk(ls, &v->u.road,     vehicle_road_chunk);     break;
  1118 		case VEH_ROAD    : res = LoadChunk(ls, &v->u.road,     vehicle_road_chunk);     break;
  1121 		case 0x12 /*VEH_SHIP    */: v = new (v) Ship();            res = LoadChunk(ls, &v->u.ship,     vehicle_ship_chunk);     break;
  1119 		case VEH_SHIP    : res = LoadChunk(ls, &v->u.ship,     vehicle_ship_chunk);     break;
  1122 		case 0x13 /*VEH_AIRCRAFT*/: v = new (v) Aircraft();        res = LoadChunk(ls, &v->u.air,      vehicle_air_chunk);      break;
  1120 		case VEH_AIRCRAFT: res = LoadChunk(ls, &v->u.air,      vehicle_air_chunk);      break;
  1123 		case 0x14 /*VEH_SPECIAL */: v = new (v) SpecialVehicle();  res = LoadChunk(ls, &v->u.special,  vehicle_special_chunk);  break;
  1121 		case VEH_SPECIAL : res = LoadChunk(ls, &v->u.special,  vehicle_special_chunk);  break;
  1124 		case 0x15 /*VEH_DISASTER*/: v = new (v) DisasterVehicle(); res = LoadChunk(ls, &v->u.disaster, vehicle_disaster_chunk); break;
  1122 		case VEH_DISASTER: res = LoadChunk(ls, &v->u.disaster, vehicle_disaster_chunk); break;
  1125 	}
  1123 	}
  1126 
  1124 
  1127 	/* This chunk size should always be 10 bytes */
  1125 	/* This chunk size should always be 10 bytes */
  1128 	if (ls->total_read - temp != 10) {
  1126 	if (ls->total_read - temp != 10) {
  1129 		DEBUG(oldloader, 0, "Assert failed in VehicleUnion: invalid chunk size");
  1127 		DEBUG(oldloader, 0, "Assert failed in VehicleUnion: invalid chunk size");
  1134 }
  1132 }
  1135 
  1133 
  1136 static uint16 _cargo_count;
  1134 static uint16 _cargo_count;
  1137 
  1135 
  1138 static const OldChunks vehicle_chunk[] = {
  1136 static const OldChunks vehicle_chunk[] = {
  1139 	OCL_SVAR(  OC_UINT8, Vehicle, type ),
       
  1140 	OCL_SVAR(  OC_UINT8, Vehicle, subtype ),
  1137 	OCL_SVAR(  OC_UINT8, Vehicle, subtype ),
  1141 
  1138 
  1142 	OCL_NULL( 2 ),         ///< Hash, calculated automatically
  1139 	OCL_NULL( 2 ),         ///< Hash, calculated automatically
  1143 	OCL_NULL( 2 ),         ///< Index, calculated automatically
  1140 	OCL_NULL( 2 ),         ///< Index, calculated automatically
  1144 
  1141 
  1223 	ReadTTDPatchFlags();
  1220 	ReadTTDPatchFlags();
  1224 
  1221 
  1225 	for (i = 0; i < _old_vehicle_multiplier; i++) {
  1222 	for (i = 0; i < _old_vehicle_multiplier; i++) {
  1226 		_current_vehicle_id = num * _old_vehicle_multiplier + i;
  1223 		_current_vehicle_id = num * _old_vehicle_multiplier + i;
  1227 
  1224 
  1228 		Vehicle *v = new (_current_vehicle_id) InvalidVehicle();
  1225 		/* Read the vehicle type and allocate the right vehicle */
       
  1226 		Vehicle *v;
       
  1227 		switch (ReadByte(ls)) {
       
  1228 			default: NOT_REACHED();
       
  1229 			case 0x00 /*VEH_INVALID */: v = new (_current_vehicle_id) InvalidVehicle();  break;
       
  1230 			case 0x10 /*VEH_TRAIN   */: v = new (_current_vehicle_id) Train();           break;
       
  1231 			case 0x11 /*VEH_ROAD    */: v = new (_current_vehicle_id) RoadVehicle();     break;
       
  1232 			case 0x12 /*VEH_SHIP    */: v = new (_current_vehicle_id) Ship();            break;
       
  1233 			case 0x13 /*VEH_AIRCRAFT*/: v = new (_current_vehicle_id) Aircraft();        break;
       
  1234 			case 0x14 /*VEH_SPECIAL */: v = new (_current_vehicle_id) SpecialVehicle();  break;
       
  1235 			case 0x15 /*VEH_DISASTER*/: v = new (_current_vehicle_id) DisasterVehicle(); break;
       
  1236 		}
  1229 		if (!LoadChunk(ls, v, vehicle_chunk)) return false;
  1237 		if (!LoadChunk(ls, v, vehicle_chunk)) return false;
  1230 
  1238 
  1231 		/* This should be consistent, else we have a big problem... */
  1239 		/* This should be consistent, else we have a big problem... */
  1232 		if (v->index != _current_vehicle_id) {
  1240 		if (v->index != _current_vehicle_id) {
  1233 			DEBUG(oldloader, 0, "Loading failed - vehicle-array is invalid");
  1241 			DEBUG(oldloader, 0, "Loading failed - vehicle-array is invalid");