475 |
475 |
476 OCL_END() |
476 OCL_END() |
477 }; |
477 }; |
478 static bool LoadOldTown(LoadgameState *ls, int num) |
478 static bool LoadOldTown(LoadgameState *ls, int num) |
479 { |
479 { |
480 if (!AddBlockIfNeeded(&_Town_pool, num)) |
480 return LoadChunk(ls, new (num) Town(), town_chunk); |
481 error("Towns: failed loading savegame: too many towns"); |
|
482 |
|
483 return LoadChunk(ls, GetTown(num), town_chunk); |
|
484 } |
481 } |
485 |
482 |
486 static uint16 _old_order; |
483 static uint16 _old_order; |
487 static const OldChunks order_chunk[] = { |
484 static const OldChunks order_chunk[] = { |
488 OCL_VAR ( OC_UINT16, 1, &_old_order ), |
485 OCL_VAR ( OC_UINT16, 1, &_old_order ), |
489 OCL_END() |
486 OCL_END() |
490 }; |
487 }; |
491 |
488 |
492 static bool LoadOldOrder(LoadgameState *ls, int num) |
489 static bool LoadOldOrder(LoadgameState *ls, int num) |
493 { |
490 { |
494 if (!AddBlockIfNeeded(&_Order_pool, num)) |
|
495 error("Orders: failed loading savegame: too many orders"); |
|
496 |
|
497 if (!LoadChunk(ls, NULL, order_chunk)) return false; |
491 if (!LoadChunk(ls, NULL, order_chunk)) return false; |
498 |
492 |
499 AssignOrder(GetOrder(num), UnpackOldOrder(_old_order)); |
493 AssignOrder(new (num) Order(), UnpackOldOrder(_old_order)); |
500 |
494 |
501 /* Relink the orders to eachother (in TTD(Patch) the orders for one |
495 /* Relink the orders to eachother (in TTD(Patch) the orders for one |
502 vehicle are behind eachother, with an invalid order (OT_NOTHING) as indication that |
496 vehicle are behind eachother, with an invalid order (OT_NOTHING) as indication that |
503 it is the last order */ |
497 it is the last order */ |
504 if (num > 0 && GetOrder(num)->IsValid()) |
498 if (num > 0 && GetOrder(num)->IsValid()) |
513 OCL_END() |
507 OCL_END() |
514 }; |
508 }; |
515 |
509 |
516 static bool LoadOldDepot(LoadgameState *ls, int num) |
510 static bool LoadOldDepot(LoadgameState *ls, int num) |
517 { |
511 { |
518 if (!AddBlockIfNeeded(&_Depot_pool, num)) |
512 if (!LoadChunk(ls, new (num) Depot(), depot_chunk)) return false; |
519 error("Depots: failed loading savegame: too many depots"); |
513 |
520 |
514 if (IsValidDepotID(num)) { |
521 if (!LoadChunk(ls, GetDepot(num), depot_chunk)) return false; |
|
522 |
|
523 if (IsValidDepot(GetDepot(num))) { |
|
524 GetDepot(num)->town_index = REMAP_TOWN_IDX(_old_town_index); |
515 GetDepot(num)->town_index = REMAP_TOWN_IDX(_old_town_index); |
525 } |
516 } |
526 |
517 |
527 return true; |
518 return true; |
528 } |
519 } |
705 OCL_END() |
696 OCL_END() |
706 }; |
697 }; |
707 |
698 |
708 static bool LoadOldIndustry(LoadgameState *ls, int num) |
699 static bool LoadOldIndustry(LoadgameState *ls, int num) |
709 { |
700 { |
710 Industry *i; |
701 Industry *i = new (num) Industry(); |
711 |
|
712 if (!AddBlockIfNeeded(&_Industry_pool, num)) |
|
713 error("Industries: failed loading savegame: too many industries"); |
|
714 |
|
715 i = GetIndustry(num); |
|
716 if (!LoadChunk(ls, i, industry_chunk)) return false; |
702 if (!LoadChunk(ls, i, industry_chunk)) return false; |
717 |
703 |
718 if (IsValidIndustry(i)) { |
704 if (i->IsValid()) { |
719 i->town = GetTown(REMAP_TOWN_IDX(_old_town_index)); |
705 i->town = GetTown(REMAP_TOWN_IDX(_old_town_index)); |
720 } |
706 } |
721 |
707 |
722 return true; |
708 return true; |
723 } |
709 } |
904 |
890 |
905 OCL_END() |
891 OCL_END() |
906 }; |
892 }; |
907 |
893 |
908 static const OldChunks vehicle_special_chunk[] = { |
894 static const OldChunks vehicle_special_chunk[] = { |
909 OCL_SVAR( OC_UINT16, VehicleSpecial, unk0 ), |
895 OCL_SVAR( OC_UINT16, VehicleSpecial, animation_state ), |
910 OCL_SVAR( OC_UINT8, VehicleSpecial, unk2 ), |
896 OCL_SVAR( OC_UINT8, VehicleSpecial, animation_substate ), |
911 |
897 |
912 OCL_NULL( 7 ), // Junk |
898 OCL_NULL( 7 ), // Junk |
913 |
899 |
914 OCL_END() |
900 OCL_END() |
915 }; |
901 }; |
916 |
902 |
917 static const OldChunks vehicle_disaster_chunk[] = { |
903 static const OldChunks vehicle_disaster_chunk[] = { |
918 OCL_SVAR( OC_UINT16, VehicleDisaster, image_override ), |
904 OCL_SVAR( OC_UINT16, VehicleDisaster, image_override ), |
919 OCL_SVAR( OC_UINT16, VehicleDisaster, unk2 ), |
905 OCL_SVAR( OC_UINT16, VehicleDisaster, big_ufo_destroyer_target ), |
920 |
906 |
921 OCL_NULL( 6 ), ///< Junk |
907 OCL_NULL( 6 ), ///< Junk |
922 |
908 |
923 OCL_END() |
909 OCL_END() |
924 }; |
910 }; |
1045 |
1031 |
1046 /* Read the TTDPatch flags, because we need some info from it */ |
1032 /* Read the TTDPatch flags, because we need some info from it */ |
1047 ReadTTDPatchFlags(); |
1033 ReadTTDPatchFlags(); |
1048 |
1034 |
1049 for (i = 0; i < _old_vehicle_multiplier; i++) { |
1035 for (i = 0; i < _old_vehicle_multiplier; i++) { |
1050 Vehicle *v; |
|
1051 |
|
1052 _current_vehicle_id = num * _old_vehicle_multiplier + i; |
1036 _current_vehicle_id = num * _old_vehicle_multiplier + i; |
1053 |
1037 |
1054 if (!AddBlockIfNeeded(&_Vehicle_pool, _current_vehicle_id)) |
1038 Vehicle *v = new (_current_vehicle_id) InvalidVehicle(); |
1055 error("Vehicles: failed loading savegame: too many vehicles"); |
|
1056 |
|
1057 v = GetVehicle(_current_vehicle_id); |
|
1058 if (!LoadChunk(ls, v, vehicle_chunk)) return false; |
1039 if (!LoadChunk(ls, v, vehicle_chunk)) return false; |
1059 |
1040 |
1060 /* This should be consistent, else we have a big problem... */ |
1041 /* This should be consistent, else we have a big problem... */ |
1061 if (v->index != _current_vehicle_id) { |
1042 if (v->index != _current_vehicle_id) { |
1062 DEBUG(oldloader, 0, "Loading failed - vehicle-array is invalid"); |
1043 DEBUG(oldloader, 0, "Loading failed - vehicle-array is invalid"); |
1103 OCL_END() |
1084 OCL_END() |
1104 }; |
1085 }; |
1105 |
1086 |
1106 static bool LoadOldSign(LoadgameState *ls, int num) |
1087 static bool LoadOldSign(LoadgameState *ls, int num) |
1107 { |
1088 { |
1108 if (!AddBlockIfNeeded(&_Sign_pool, num)) |
1089 return LoadChunk(ls, new (num) Sign(), sign_chunk); |
1109 error("Signs: failed loading savegame: too many signs"); |
|
1110 |
|
1111 return LoadChunk(ls, GetSign(num), sign_chunk); |
|
1112 } |
1090 } |
1113 |
1091 |
1114 static const OldChunks engine_chunk[] = { |
1092 static const OldChunks engine_chunk[] = { |
1115 OCL_SVAR( OC_UINT16, Engine, player_avail ), |
1093 OCL_SVAR( OC_UINT16, Engine, player_avail ), |
1116 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, intro_date ), |
1094 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, intro_date ), |