164 |
164 |
165 while (chunk->type != OC_END) { |
165 while (chunk->type != OC_END) { |
166 ptr = chunk->ptr; |
166 ptr = chunk->ptr; |
167 |
167 |
168 for (i = 0; i < chunk->amount; i++) { |
168 for (i = 0; i < chunk->amount; i++) { |
169 if (ls->failed) |
169 if (ls->failed) return false; |
170 return false; |
|
171 |
170 |
172 /* Handle simple types */ |
171 /* Handle simple types */ |
173 if ((chunk->type & 0xFF) != 0) { |
172 if ((chunk->type & 0xFF) != 0) { |
174 switch (chunk->type & 0xFF) { |
173 switch (chunk->type & 0xFF) { |
175 case OC_NULL: |
174 /* Just read the byte and forget about it */ |
176 /* Just read the byte and forget about it */ |
175 case OC_NULL: ReadByte(ls); break; |
177 ReadByte(ls); |
|
178 break; |
|
179 |
176 |
180 case OC_CHUNK: |
177 case OC_CHUNK: |
181 /* Call function, with 'i' as parameter to tell which item we |
178 /* Call function, with 'i' as parameter to tell which item we |
182 * are going to read */ |
179 * are going to read */ |
183 if (!chunk->proc(ls, i)) return false; |
180 if (!chunk->proc(ls, i)) return false; |
184 break; |
181 break; |
185 |
182 |
186 case OC_ASSERT: |
183 case OC_ASSERT: |
187 DEBUG(oldloader, 4)("[OldLoader] Assert point: %x / %x", ls->total_read, chunk->offset + _bump_assert_value); |
184 DEBUG(oldloader, 4)("[OldLoader] Assert point: %x / %x", ls->total_read, chunk->offset + _bump_assert_value); |
188 if (ls->total_read != chunk->offset + _bump_assert_value) { |
185 if (ls->total_read != chunk->offset + _bump_assert_value) ls->failed = true; |
189 ls->failed = true; |
|
190 } |
|
191 break; |
|
192 |
|
193 } |
186 } |
194 } else { |
187 } else { |
195 uint32 res = 0; |
188 uint32 res = 0; |
196 |
189 |
197 /* Reading from the file: bit 16 to 23 have the FILE */ |
190 /* Reading from the file: bit 16 to 23 have the FILE */ |
443 |
436 |
444 extern TileIndex _animated_tile_list[256]; |
437 extern TileIndex _animated_tile_list[256]; |
445 extern char _name_array[512][32]; |
438 extern char _name_array[512][32]; |
446 extern uint16 _custom_sprites_base; |
439 extern uint16 _custom_sprites_base; |
447 |
440 |
448 static byte _old_vehicle_multipler; |
441 static byte _old_vehicle_multiplier; |
449 static uint8 _old_map3[OLD_MAP_SIZE * 2]; |
442 static uint8 _old_map3[OLD_MAP_SIZE * 2]; |
450 static bool _new_ttdpatch_format; |
443 static bool _new_ttdpatch_format; |
451 static uint32 _old_town_index; |
444 static uint32 _old_town_index; |
452 static uint16 _old_string_id; |
445 static uint16 _old_string_id; |
453 static uint16 _old_string_id_2; |
446 static uint16 _old_string_id_2; |
459 if (_read_ttdpatch_flags) return; |
452 if (_read_ttdpatch_flags) return; |
460 |
453 |
461 _read_ttdpatch_flags = true; |
454 _read_ttdpatch_flags = true; |
462 |
455 |
463 /* TTDPatch misuses _old_map3 for flags.. read them! */ |
456 /* TTDPatch misuses _old_map3 for flags.. read them! */ |
464 _old_vehicle_multipler = _old_map3[0]; |
457 _old_vehicle_multiplier = _old_map3[0]; |
465 /* Somehow.... there was an error in some savegames, so 0 becomes 1 |
458 /* Somehow.... there was an error in some savegames, so 0 becomes 1 |
466 and 1 becomes 2. The rest of the values are okay */ |
459 and 1 becomes 2. The rest of the values are okay */ |
467 if (_old_vehicle_multipler < 2) _old_vehicle_multipler++; |
460 if (_old_vehicle_multiplier < 2) _old_vehicle_multiplier++; |
468 |
461 |
469 /* TTDPatch incraeses the Vehicle-part in the middle of the game, |
462 /* TTDPatch incraeses the Vehicle-part in the middle of the game, |
470 so if the multipler is anything else but 1, the assert fails.. |
463 so if the multipler is anything else but 1, the assert fails.. |
471 bump the assert value so it doesn't! |
464 bump the assert value so it doesn't! |
472 (1 multipler == 850 vehicles |
465 (1 multipler == 850 vehicles |
473 1 vehicle == 128 bytes */ |
466 1 vehicle == 128 bytes */ |
474 _bump_assert_value = (_old_vehicle_multipler - 1) * 850 * 128; |
467 _bump_assert_value = (_old_vehicle_multiplier - 1) * 850 * 128; |
475 |
468 |
476 /* Check if we have a modern TTDPatch savegame (has extra data all around) */ |
469 /* Check if we have a modern TTDPatch savegame (has extra data all around) */ |
477 _new_ttdpatch_format = (memcmp(&_old_map3[0x1FFFA], "TTDp", 4) == 0); |
470 _new_ttdpatch_format = (memcmp(&_old_map3[0x1FFFA], "TTDp", 4) == 0); |
478 |
471 |
479 /* Clean the misused places */ |
472 /* Clean the misused places */ |
481 for (i = 0x1FE00; i < 0x20000; i++) _old_map3[i] = 0; |
474 for (i = 0x1FE00; i < 0x20000; i++) _old_map3[i] = 0; |
482 |
475 |
483 if (_new_ttdpatch_format) |
476 if (_new_ttdpatch_format) |
484 DEBUG(oldloader, 1)("[OldLoader] Found TTDPatch game"); |
477 DEBUG(oldloader, 1)("[OldLoader] Found TTDPatch game"); |
485 |
478 |
486 DEBUG(oldloader, 1)("[OldLoader] Vehicle-multipler is set to %d (%d vehicles)", _old_vehicle_multipler, _old_vehicle_multipler * 850); |
479 DEBUG(oldloader, 1)("[OldLoader] Vehicle-multiplier is set to %d (%d vehicles)", _old_vehicle_multiplier, _old_vehicle_multiplier * 850); |
487 } |
480 } |
488 |
481 |
489 static const OldChunks town_chunk[] = { |
482 static const OldChunks town_chunk[] = { |
490 OCL_SVAR( OC_TILE, Town, xy ), |
483 OCL_SVAR( OC_TILE, Town, xy ), |
491 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Town, population ), |
484 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Town, population ), |
550 static uint16 _old_order; |
543 static uint16 _old_order; |
551 static const OldChunks order_chunk[] = { |
544 static const OldChunks order_chunk[] = { |
552 OCL_VAR ( OC_UINT16, 1, &_old_order ), |
545 OCL_VAR ( OC_UINT16, 1, &_old_order ), |
553 OCL_END() |
546 OCL_END() |
554 }; |
547 }; |
|
548 |
555 static bool LoadOldOrder(LoadgameState *ls, int num) |
549 static bool LoadOldOrder(LoadgameState *ls, int num) |
556 { |
550 { |
557 if (!AddBlockIfNeeded(&_order_pool, num)) |
551 if (!AddBlockIfNeeded(&_order_pool, num)) |
558 error("Orders: failed loading savegame: too many orders"); |
552 error("Orders: failed loading savegame: too many orders"); |
559 |
553 |
560 if (!LoadChunk(ls, NULL, order_chunk)) |
554 if (!LoadChunk(ls, NULL, order_chunk)) return false; |
561 return false; |
|
562 |
555 |
563 AssignOrder(GetOrder(num), UnpackOldOrder(_old_order)); |
556 AssignOrder(GetOrder(num), UnpackOldOrder(_old_order)); |
564 |
557 |
565 /* Relink the orders to eachother (in TTD(Patch) the orders for one |
558 /* Relink the orders to eachother (in TTD(Patch) the orders for one |
566 vehicle are behind eachother, with OT_NOTHING as indication that |
559 vehicle are behind eachother, with OT_NOTHING as indication that |
574 static const OldChunks depot_chunk[] = { |
567 static const OldChunks depot_chunk[] = { |
575 OCL_SVAR( OC_TILE, Depot, xy ), |
568 OCL_SVAR( OC_TILE, Depot, xy ), |
576 OCL_VAR ( OC_UINT32, 1, &_old_town_index ), |
569 OCL_VAR ( OC_UINT32, 1, &_old_town_index ), |
577 OCL_END() |
570 OCL_END() |
578 }; |
571 }; |
|
572 |
579 static bool LoadOldDepot(LoadgameState *ls, int num) |
573 static bool LoadOldDepot(LoadgameState *ls, int num) |
580 { |
574 { |
581 if (!AddBlockIfNeeded(&_depot_pool, num)) |
575 if (!AddBlockIfNeeded(&_depot_pool, num)) |
582 error("Depots: failed loading savegame: too many depots"); |
576 error("Depots: failed loading savegame: too many depots"); |
583 |
577 |
584 if (!LoadChunk(ls, GetDepot(num), depot_chunk)) |
578 if (!LoadChunk(ls, GetDepot(num), depot_chunk)) return false; |
585 return false; |
|
586 |
579 |
587 if (GetDepot(num)->xy != 0) { |
580 if (GetDepot(num)->xy != 0) { |
588 GetDepot(num)->town_index = REMAP_TOWN_IDX(_old_town_index); |
581 GetDepot(num)->town_index = REMAP_TOWN_IDX(_old_town_index); |
589 } |
582 } |
590 |
583 |
596 static const OldChunks price_chunk[] = { |
589 static const OldChunks price_chunk[] = { |
597 OCL_VAR ( OC_INT32, 1, &_old_price ), |
590 OCL_VAR ( OC_INT32, 1, &_old_price ), |
598 OCL_VAR ( OC_UINT16, 1, &_old_price_frac ), |
591 OCL_VAR ( OC_UINT16, 1, &_old_price_frac ), |
599 OCL_END() |
592 OCL_END() |
600 }; |
593 }; |
|
594 |
601 static bool LoadOldPrice(LoadgameState *ls, int num) |
595 static bool LoadOldPrice(LoadgameState *ls, int num) |
602 { |
596 { |
603 if (!LoadChunk(ls, NULL, price_chunk)) |
597 if (!LoadChunk(ls, NULL, price_chunk)) return false; |
604 return false; |
|
605 |
598 |
606 /* We use a struct to store the prices, but they are ints in a row.. |
599 /* We use a struct to store the prices, but they are ints in a row.. |
607 so just access the struct as an array of int32's */ |
600 so just access the struct as an array of int32's */ |
608 ((int32*)&_price)[num] = _old_price; |
601 ((int32*)&_price)[num] = _old_price; |
609 _price_frac[num] = _old_price_frac; |
602 _price_frac[num] = _old_price_frac; |
616 OCL_VAR ( OC_UINT16, 1, &_old_price_frac ), |
609 OCL_VAR ( OC_UINT16, 1, &_old_price_frac ), |
617 |
610 |
618 OCL_NULL( 2 ), // Junk |
611 OCL_NULL( 2 ), // Junk |
619 OCL_END() |
612 OCL_END() |
620 }; |
613 }; |
|
614 |
621 static bool LoadOldCargoPaymentRate(LoadgameState *ls, int num) |
615 static bool LoadOldCargoPaymentRate(LoadgameState *ls, int num) |
622 { |
616 { |
623 if (!LoadChunk(ls, NULL, cargo_payment_rate_chunk)) |
617 if (!LoadChunk(ls, NULL, cargo_payment_rate_chunk)) return false; |
624 return false; |
|
625 |
618 |
626 _cargo_payment_rates[num] = -_old_price; |
619 _cargo_payment_rates[num] = -_old_price; |
627 _cargo_payment_rates_frac[num] = _old_price_frac; |
620 _cargo_payment_rates_frac[num] = _old_price_frac; |
628 |
621 |
629 return true; |
622 return true; |
641 OCL_SVAR( OC_UINT8, GoodsEntry, last_speed ), |
634 OCL_SVAR( OC_UINT8, GoodsEntry, last_speed ), |
642 OCL_SVAR( OC_UINT8, GoodsEntry, last_age ), |
635 OCL_SVAR( OC_UINT8, GoodsEntry, last_age ), |
643 |
636 |
644 OCL_END() |
637 OCL_END() |
645 }; |
638 }; |
|
639 |
646 static bool LoadOldGood(LoadgameState *ls, int num) |
640 static bool LoadOldGood(LoadgameState *ls, int num) |
647 { |
641 { |
648 Station *st = GetStation(_current_station_id); |
642 Station *st = GetStation(_current_station_id); |
649 return LoadChunk(ls, &st->goods[num], goods_chunk); |
643 return LoadChunk(ls, &st->goods[num], goods_chunk); |
650 } |
644 } |
759 |
753 |
760 OCL_NULL( 9 ), // Random junk at the end of this chunk |
754 OCL_NULL( 9 ), // Random junk at the end of this chunk |
761 |
755 |
762 OCL_END() |
756 OCL_END() |
763 }; |
757 }; |
|
758 |
764 static bool LoadOldIndustry(LoadgameState *ls, int num) |
759 static bool LoadOldIndustry(LoadgameState *ls, int num) |
765 { |
760 { |
766 Industry *i; |
761 Industry *i; |
767 |
762 |
768 if (!AddBlockIfNeeded(&_industry_pool, num)) |
763 if (!AddBlockIfNeeded(&_industry_pool, num)) |
769 error("Industries: failed loading savegame: too many industries"); |
764 error("Industries: failed loading savegame: too many industries"); |
770 |
765 |
771 i = GetIndustry(num); |
766 i = GetIndustry(num); |
772 if (!LoadChunk(ls, i, industry_chunk)) |
767 if (!LoadChunk(ls, i, industry_chunk)) return false; |
773 return false; |
|
774 |
768 |
775 if (i->xy != 0) { |
769 if (i->xy != 0) { |
776 i->town = GetTown(REMAP_TOWN_IDX(_old_town_index)); |
770 i->town = GetTown(REMAP_TOWN_IDX(_old_town_index)); |
777 } |
771 } |
778 |
772 |
785 |
779 |
786 static const OldChunks player_yearly_chunk[] = { |
780 static const OldChunks player_yearly_chunk[] = { |
787 OCL_VAR( OC_INT32, 1, &_old_yearly ), |
781 OCL_VAR( OC_INT32, 1, &_old_yearly ), |
788 OCL_END() |
782 OCL_END() |
789 }; |
783 }; |
|
784 |
790 static bool OldPlayerYearly(LoadgameState *ls, int num) |
785 static bool OldPlayerYearly(LoadgameState *ls, int num) |
791 { |
786 { |
792 int i; |
787 int i; |
793 Player *p = GetPlayer(_current_player_id); |
788 Player *p = GetPlayer(_current_player_id); |
794 |
789 |
795 for (i = 0; i < 13; i++) { |
790 for (i = 0; i < 13; i++) { |
796 if (!LoadChunk(ls, NULL, player_yearly_chunk)) |
791 if (!LoadChunk(ls, NULL, player_yearly_chunk)) return false; |
797 return false; |
|
798 |
792 |
799 p->yearly_expenses[num][i] = _old_yearly; |
793 p->yearly_expenses[num][i] = _old_yearly; |
800 } |
794 } |
801 |
795 |
802 return true; |
796 return true; |
809 OCL_SVAR( OC_INT32, PlayerEconomyEntry, performance_history ), |
803 OCL_SVAR( OC_INT32, PlayerEconomyEntry, performance_history ), |
810 OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, PlayerEconomyEntry, company_value ), |
804 OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, PlayerEconomyEntry, company_value ), |
811 |
805 |
812 OCL_END() |
806 OCL_END() |
813 }; |
807 }; |
|
808 |
814 static bool OldPlayerEconomy(LoadgameState *ls, int num) |
809 static bool OldPlayerEconomy(LoadgameState *ls, int num) |
815 { |
810 { |
816 int i; |
811 int i; |
817 Player *p = GetPlayer(_current_player_id); |
812 Player *p = GetPlayer(_current_player_id); |
818 |
813 |
819 if (!LoadChunk(ls, &p->cur_economy, player_economy_chunk)) |
814 if (!LoadChunk(ls, &p->cur_economy, player_economy_chunk)) return false; |
820 return false; |
|
821 |
815 |
822 /* Don't ask, but the number in TTD(Patch) are inversed to OpenTTD */ |
816 /* Don't ask, but the number in TTD(Patch) are inversed to OpenTTD */ |
823 p->cur_economy.income = -p->cur_economy.income; |
817 p->cur_economy.income = -p->cur_economy.income; |
824 p->cur_economy.expenses = -p->cur_economy.expenses; |
818 p->cur_economy.expenses = -p->cur_economy.expenses; |
825 |
819 |
826 for (i = 0; i < 24; i++) { |
820 for (i = 0; i < 24; i++) { |
827 if (!LoadChunk(ls, &p->old_economy[i], player_economy_chunk)) |
821 if (!LoadChunk(ls, &p->old_economy[i], player_economy_chunk)) return false; |
828 return false; |
|
829 |
822 |
830 p->old_economy[i].income = -p->old_economy[i].income; |
823 p->old_economy[i].income = -p->old_economy[i].income; |
831 p->old_economy[i].expenses = -p->old_economy[i].expenses; |
824 p->old_economy[i].expenses = -p->old_economy[i].expenses; |
832 } |
825 } |
833 |
826 |
963 OCL_SVAR( OC_UINT8, PlayerAI, railtype_to_use ), |
957 OCL_SVAR( OC_UINT8, PlayerAI, railtype_to_use ), |
964 OCL_SVAR( OC_UINT8, PlayerAI, route_type_mask ), |
958 OCL_SVAR( OC_UINT8, PlayerAI, route_type_mask ), |
965 |
959 |
966 OCL_END() |
960 OCL_END() |
967 }; |
961 }; |
|
962 |
968 static bool OldPlayerAI(LoadgameState *ls, int num) |
963 static bool OldPlayerAI(LoadgameState *ls, int num) |
969 { |
964 { |
970 Player *p = GetPlayer(_current_player_id); |
965 Player *p = GetPlayer(_current_player_id); |
971 |
966 |
972 return LoadChunk(ls, &p->ai, player_ai_chunk); |
967 return LoadChunk(ls, &p->ai, player_ai_chunk); |
1074 |
1068 |
1075 OCL_NULL( 5 ), // Junk |
1069 OCL_NULL( 5 ), // Junk |
1076 |
1070 |
1077 OCL_END() |
1071 OCL_END() |
1078 }; |
1072 }; |
|
1073 |
1079 static const OldChunks vehicle_road_chunk[] = { |
1074 static const OldChunks vehicle_road_chunk[] = { |
1080 OCL_SVAR( OC_UINT8, VehicleRoad, state ), |
1075 OCL_SVAR( OC_UINT8, VehicleRoad, state ), |
1081 OCL_SVAR( OC_UINT8, VehicleRoad, frame ), |
1076 OCL_SVAR( OC_UINT8, VehicleRoad, frame ), |
1082 OCL_SVAR( OC_UINT16, VehicleRoad, blocked_ctr ), |
1077 OCL_SVAR( OC_UINT16, VehicleRoad, blocked_ctr ), |
1083 OCL_SVAR( OC_UINT8, VehicleRoad, overtaking ), |
1078 OCL_SVAR( OC_UINT8, VehicleRoad, overtaking ), |
1087 |
1082 |
1088 OCL_NULL( 1 ), // Junk |
1083 OCL_NULL( 1 ), // Junk |
1089 |
1084 |
1090 OCL_END() |
1085 OCL_END() |
1091 }; |
1086 }; |
|
1087 |
1092 static const OldChunks vehicle_ship_chunk[] = { |
1088 static const OldChunks vehicle_ship_chunk[] = { |
1093 OCL_SVAR( OC_UINT8, VehicleShip, state ), |
1089 OCL_SVAR( OC_UINT8, VehicleShip, state ), |
1094 |
1090 |
1095 OCL_NULL( 9 ), // Junk |
1091 OCL_NULL( 9 ), // Junk |
1096 |
1092 |
1097 OCL_END() |
1093 OCL_END() |
1098 }; |
1094 }; |
|
1095 |
1099 static const OldChunks vehicle_air_chunk[] = { |
1096 static const OldChunks vehicle_air_chunk[] = { |
1100 OCL_SVAR( OC_UINT8, VehicleAir, pos ), |
1097 OCL_SVAR( OC_UINT8, VehicleAir, pos ), |
1101 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, VehicleAir, targetairport ), |
1098 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, VehicleAir, targetairport ), |
1102 OCL_SVAR( OC_UINT16, VehicleAir, crashed_counter ), |
1099 OCL_SVAR( OC_UINT16, VehicleAir, crashed_counter ), |
1103 OCL_SVAR( OC_UINT8, VehicleAir, state ), |
1100 OCL_SVAR( OC_UINT8, VehicleAir, state ), |
1104 |
1101 |
1105 OCL_NULL( 5 ), // Junk |
1102 OCL_NULL( 5 ), // Junk |
1106 |
1103 |
1107 OCL_END() |
1104 OCL_END() |
1108 }; |
1105 }; |
|
1106 |
1109 static const OldChunks vehicle_special_chunk[] = { |
1107 static const OldChunks vehicle_special_chunk[] = { |
1110 OCL_SVAR( OC_UINT16, VehicleSpecial, unk0 ), |
1108 OCL_SVAR( OC_UINT16, VehicleSpecial, unk0 ), |
1111 OCL_SVAR( OC_UINT8, VehicleSpecial, unk2 ), |
1109 OCL_SVAR( OC_UINT8, VehicleSpecial, unk2 ), |
1112 |
1110 |
1113 OCL_NULL( 7 ), // Junk |
1111 OCL_NULL( 7 ), // Junk |
1114 |
1112 |
1115 OCL_END() |
1113 OCL_END() |
1116 }; |
1114 }; |
|
1115 |
1117 static const OldChunks vehicle_disaster_chunk[] = { |
1116 static const OldChunks vehicle_disaster_chunk[] = { |
1118 OCL_SVAR( OC_UINT16, VehicleDisaster, image_override ), |
1117 OCL_SVAR( OC_UINT16, VehicleDisaster, image_override ), |
1119 OCL_SVAR( OC_UINT16, VehicleDisaster, unk2 ), |
1118 OCL_SVAR( OC_UINT16, VehicleDisaster, unk2 ), |
1120 |
1119 |
1121 OCL_NULL( 6 ), // Junk |
1120 OCL_NULL( 6 ), // Junk |
1122 |
1121 |
1123 OCL_END() |
1122 OCL_END() |
1124 }; |
1123 }; |
|
1124 |
1125 static const OldChunks vehicle_empty_chunk[] = { |
1125 static const OldChunks vehicle_empty_chunk[] = { |
1126 OCL_NULL( 10 ), // Junk |
1126 OCL_NULL( 10 ), // Junk |
1127 |
1127 |
1128 OCL_END() |
1128 OCL_END() |
1129 }; |
1129 }; |
|
1130 |
1130 static bool LoadOldVehicleUnion(LoadgameState *ls, int num) |
1131 static bool LoadOldVehicleUnion(LoadgameState *ls, int num) |
1131 { |
1132 { |
1132 Vehicle *v = GetVehicle(_current_vehicle_id); |
1133 Vehicle *v = GetVehicle(_current_vehicle_id); |
1133 uint temp = ls->total_read; |
1134 uint temp = ls->total_read; |
1134 bool res; |
1135 bool res; |
1231 |
1232 |
1232 OCL_NULL( 20 ), // Junk at end of struct (TTDPatch has some data in it) |
1233 OCL_NULL( 20 ), // Junk at end of struct (TTDPatch has some data in it) |
1233 |
1234 |
1234 OCL_END() |
1235 OCL_END() |
1235 }; |
1236 }; |
|
1237 |
1236 static bool LoadOldVehicle(LoadgameState *ls, int num) |
1238 static bool LoadOldVehicle(LoadgameState *ls, int num) |
1237 { |
1239 { |
1238 uint i; |
1240 uint i; |
1239 |
1241 |
1240 /* Read the TTDPatch flags, because we need some info from it */ |
1242 /* Read the TTDPatch flags, because we need some info from it */ |
1241 ReadTTDPatchFlags(); |
1243 ReadTTDPatchFlags(); |
1242 |
1244 |
1243 for (i = 0; i < _old_vehicle_multipler; i++) { |
1245 for (i = 0; i < _old_vehicle_multiplier; i++) { |
1244 Vehicle *v; |
1246 Vehicle *v; |
1245 |
1247 |
1246 _current_vehicle_id = num * _old_vehicle_multipler + i; |
1248 _current_vehicle_id = num * _old_vehicle_multiplier + i; |
1247 |
1249 |
1248 if (!AddBlockIfNeeded(&_vehicle_pool, _current_vehicle_id)) |
1250 if (!AddBlockIfNeeded(&_vehicle_pool, _current_vehicle_id)) |
1249 error("Vehicles: failed loading savegame: too many vehicles"); |
1251 error("Vehicles: failed loading savegame: too many vehicles"); |
1250 |
1252 |
1251 v = GetVehicle(_current_vehicle_id); |
1253 v = GetVehicle(_current_vehicle_id); |
1252 if (!LoadChunk(ls, v, vehicle_chunk)) |
1254 if (!LoadChunk(ls, v, vehicle_chunk)) return false; |
1253 return false; |
|
1254 |
1255 |
1255 /* This should be consistent, else we have a big problem... */ |
1256 /* This should be consistent, else we have a big problem... */ |
1256 if (v->index != _current_vehicle_id) { |
1257 if (v->index != _current_vehicle_id) { |
1257 DEBUG(oldloader, 0)("[OldLoader] -- Loading failed - vehicle-array is invalid"); |
1258 DEBUG(oldloader, 0)("[OldLoader] -- Loading failed - vehicle-array is invalid"); |
1258 return false; |
1259 return false; |
1344 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Subsidy, from ), |
1346 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Subsidy, from ), |
1345 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Subsidy, to ), |
1347 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Subsidy, to ), |
1346 |
1348 |
1347 OCL_END() |
1349 OCL_END() |
1348 }; |
1350 }; |
1349 static bool LoadOldSubsidy(LoadgameState *ls, int num) |
1351 |
|
1352 static inline bool LoadOldSubsidy(LoadgameState *ls, int num) |
1350 { |
1353 { |
1351 return LoadChunk(ls, &_subsidies[num], subsidy_chunk); |
1354 return LoadChunk(ls, &_subsidies[num], subsidy_chunk); |
1352 } |
1355 } |
1353 |
1356 |
1354 static const OldChunks game_difficulty_chunk[] = { |
1357 static const OldChunks game_difficulty_chunk[] = { |
1369 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, economy ), |
1372 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, economy ), |
1370 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, line_reverse_mode ), |
1373 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, line_reverse_mode ), |
1371 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, disasters ), |
1374 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, disasters ), |
1372 OCL_END() |
1375 OCL_END() |
1373 }; |
1376 }; |
1374 static bool LoadOldGameDifficulty(LoadgameState *ls, int num) |
1377 |
|
1378 static inline bool LoadOldGameDifficulty(LoadgameState *ls, int num) |
1375 { |
1379 { |
1376 return LoadChunk(ls, &_opt.diff, game_difficulty_chunk); |
1380 return LoadChunk(ls, &_opt.diff, game_difficulty_chunk); |
1377 } |
1381 } |
1378 |
1382 |
1379 |
1383 |
1615 return true; |
1620 return true; |
1616 } |
1621 } |
1617 |
1622 |
1618 void GetOldSaveGameName(char *title, const char *file) |
1623 void GetOldSaveGameName(char *title, const char *file) |
1619 { |
1624 { |
1620 FILE *f; |
1625 FILE *f = fopen(file, "rb"); |
1621 |
|
1622 f = fopen(file, "rb"); |
|
1623 title[0] = 0; |
1626 title[0] = 0; |
1624 title[48] = 0; |
1627 title[48] = 0; |
1625 |
1628 |
1626 if (f == NULL) |
1629 if (f == NULL) return; |
1627 return; |
1630 |
1628 |
1631 if (fread(title, 1, 48, f) != 48) snprintf(title, 48, "Corrupt file"); |
1629 if (fread(title, 1, 48, f) != 48) |
|
1630 snprintf(title, 48, "Corrupt file"); |
|
1631 |
1632 |
1632 fclose(f); |
1633 fclose(f); |
1633 } |
1634 } |
1634 |
1635 |
1635 void GetOldScenarioGameName(char *title, const char *file) |
1636 void GetOldScenarioGameName(char *title, const char *file) |