MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / LoadOldVehicle

Function LoadOldVehicle

src/saveload/oldloader_sl.cpp:1258–1391  ·  view source on GitHub ↗

* Load the vehicles of an old style savegame. * @param ls State (buffer) of the currently loaded game. * @param num The number of vehicles to load. * @return True iff loading went without problems. */

Source from the content-addressed store, hash-verified

1256 * @return True iff loading went without problems.
1257 */
1258bool LoadOldVehicle(LoadgameState &ls, int num)
1259{
1260 /* Read the TTDPatch flags, because we need some info from it */
1261 ReadTTDPatchFlags(ls);
1262
1263 for (uint i = 0; i < ls.vehicle_multiplier; i++) {
1264 _current_vehicle_id = num * ls.vehicle_multiplier + i;
1265
1266 Vehicle *v;
1267
1268 if (_savegame_type == SGT_TTO) {
1269 uint type = ReadByte(ls);
1270 switch (type) {
1271 default: return false;
1272 case 0x00 /* VEH_INVALID */: v = nullptr; break;
1273 case 0x25 /* MONORAIL */:
1274 case 0x20 /* VEH_TRAIN */: v = new (VehicleID(_current_vehicle_id)) Train(); break;
1275 case 0x21 /* VEH_ROAD */: v = new (VehicleID(_current_vehicle_id)) RoadVehicle(); break;
1276 case 0x22 /* VEH_SHIP */: v = new (VehicleID(_current_vehicle_id)) Ship(); break;
1277 case 0x23 /* VEH_AIRCRAFT */: v = new (VehicleID(_current_vehicle_id)) Aircraft(); break;
1278 case 0x24 /* VEH_EFFECT */: v = new (VehicleID(_current_vehicle_id)) EffectVehicle(); break;
1279 case 0x26 /* VEH_DISASTER */: v = new (VehicleID(_current_vehicle_id)) DisasterVehicle(); break;
1280 }
1281
1282 if (!LoadChunk(ls, v, vehicle_chunk)) return false;
1283 if (v == nullptr) continue;
1284 v->refit_cap = v->cargo_cap;
1285
1286 SpriteID sprite = v->sprite_cache.sprite_seq.seq[0].sprite;
1287 /* no need to override other sprites */
1288 if (IsInsideMM(sprite, 1460, 1465)) {
1289 sprite += 580; // aircraft smoke puff
1290 } else if (IsInsideMM(sprite, 2096, 2115)) {
1291 sprite += 977; // special effects part 1
1292 } else if (IsInsideMM(sprite, 2396, 2436)) {
1293 sprite += 1305; // special effects part 2
1294 } else if (IsInsideMM(sprite, 2516, 2539)) {
1295 sprite += 1385; // rotor or disaster-related vehicles
1296 }
1297 v->sprite_cache.sprite_seq.seq[0].sprite = sprite;
1298
1299 switch (v->type) {
1300 case VEH_TRAIN: {
1301 static const uint8_t spriteset_rail[] = {
1302 0, 2, 4, 4, 8, 10, 12, 14, 16, 18, 20, 22, 40, 42, 44, 46,
1303 48, 52, 54, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 120, 122,
1304 124, 126, 128, 130, 132, 134, 136, 138, 140
1305 };
1306 if (v->spritenum / 2 >= lengthof(spriteset_rail)) return false;
1307 v->spritenum = spriteset_rail[v->spritenum / 2]; // adjust railway sprite set offset
1308 break;
1309 }
1310
1311 case VEH_ROAD:
1312 if (v->spritenum >= 22) v->spritenum += 12;
1313 break;
1314
1315 case VEH_SHIP:

Callers

nothing calls this directly

Calls 12

ReadTTDPatchFlagsFunction · 0.85
ReadByteFunction · 0.85
LoadChunkFunction · 0.85
IsInsideMMFunction · 0.85
SlErrorCorruptFunction · 0.85
RemapOldStringIDFunction · 0.85
RemapOrderIndexFunction · 0.85
UnpackOldOrderFunction · 0.85
InvalidFunction · 0.85
AssignOrderMethod · 0.80
GetDestinationMethod · 0.80
AppendMethod · 0.45

Tested by

no test coverage detected