12 #include "../stdafx.h"
14 #include "../industry.h"
15 #include "../company_func.h"
16 #include "../aircraft.h"
17 #include "../roadveh.h"
20 #include "../signs_base.h"
21 #include "../station_base.h"
22 #include "../subsidy_base.h"
24 #include "../depot_base.h"
25 #include "../date_func.h"
26 #include "../vehicle_func.h"
27 #include "../effectvehicle_base.h"
28 #include "../engine_func.h"
29 #include "../company_base.h"
30 #include "../disaster_vehicle.h"
34 #include "table/strings.h"
35 #include "../table/engines.h"
36 #include "../table/townname.h"
38 #include "../safeguards.h"
44 static uint8 *_old_map3;
55 static void FixTTDMapArray()
58 for (
TileIndex t = 0; t < OLD_MAP_SIZE; t++) {
59 _m[t].
m3 = _old_map3[t * 2];
60 _m[t].
m4 = _old_map3[t * 2 + 1];
63 for (
TileIndex t = 0; t < OLD_MAP_SIZE; t++) {
69 case 0x53:
case 0x54:
_m[t].
m5 += 170 - 0x53;
break;
70 case 0x57:
case 0x58:
_m[t].
m5 += 168 - 0x57;
break;
71 case 0x55:
case 0x56:
_m[t].
m5 += 170 - 0x55;
break;
72 case 0x59:
case 0x5A:
_m[t].
m5 += 168 - 0x59;
break;
79 if (
GB(
_m[t].m5, 6, 2) == 1) {
92 if (
GB(
_m[t].m3, 0, 2) == 3) {
113 FOR_ALL_DEPOTS_FROM(d, 252) {
121 #define FIXNUM(x, y, z) (((((x) << 16) / (y)) + 1) << z)
123 static uint32 RemapOldTownName(uint32 townnameparts, byte old_town_name_type)
125 switch (old_town_name_type) {
128 return townnameparts;
133 return FIXNUM(townnameparts - 86,
lengthof(_name_french_real), 0);
136 DEBUG(misc, 0,
"German Townnames are buggy (%d)", townnameparts);
137 return townnameparts;
141 return FIXNUM(townnameparts,
lengthof(_name_spanish_real), 0);
147 return FIXNUM(townnameparts,
lengthof(_name_silly_1), 0) | FIXNUM(
GB(townnameparts, 16, 8),
lengthof(_name_silly_2), 16);
154 static void FixOldTowns()
159 FOR_ALL_TOWNS(town) {
160 if (
IsInsideMM(town->townnametype, 0x20C1, 0x20C3)) {
167 static StringID *_old_vehicle_names;
179 if ((
size_t)v->
next == 0xFFFF) {
225 static bool FixTTOMapArray()
227 for (
TileIndex t = 0; t < OLD_MAP_SIZE; t++) {
243 switch (
GB(
_m[t].m5, 6, 2)) {
248 SB(
_m[t].m2, 6, 2,
GB(
_m[t].m5, 3, 2));
262 switch (
GB(
_m[t].m5, 4, 4)) {
264 if (
_m[t].m2 == 4)
_m[t].
m2 = 5;
279 if (
_m[t].m2 >= 5)
_m[t].
m2++;
288 _m[t].
m3 = (
_m[t].
m5 >= 0x08 &&
_m[t].
m5 <= 0x0F) ? 1 : 0;
289 if (
_m[t].m5 >= 8)
_m[t].
m5 -= 8;
290 if (
_m[t].m5 >= 0x42)
_m[t].
m5++;
307 case 0x25:
case 0x27:
308 case 0x28:
case 0x29:
case 0x2A:
case 0x2B:
312 if (
_m[t].m5 >= 0x2C)
_m[t].
m5 += 3;
320 _m[t].
m5 = m5 & 0xE1;
321 if (
GB(m5, 1, 2) == 1)
_m[t].m5 |= 0x02;
322 if (
GB(m5, 1, 2) == 3)
_m[t].m2 |= 0xA0;
324 _m[t].
m3 = (
GB(m5, 1, 2) == 3) ? 1 : 0;
327 if (
GB(m5, 3, 2) == 3)
_m[t].
m3 |= 1;
328 if (
GB(m5, 3, 2) == 1)
_m[t].
m5 |= 0x08;
353 static Engine *_old_engines;
358 static const EngineID ttd_to_tto[] = {
359 0, 255, 255, 255, 255, 255, 255, 255, 5, 7, 8, 9, 10, 11, 12, 13,
360 255, 255, 255, 255, 255, 255, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
361 25, 26, 27, 29, 28, 30, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
362 255, 255, 255, 255, 255, 255, 255, 31, 255, 32, 33, 34, 35, 36, 37, 38,
363 39, 40, 41, 42, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
364 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
365 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
366 255, 255, 255, 255, 44, 45, 46, 255, 255, 255, 255, 47, 48, 255, 49, 50,
367 255, 255, 255, 255, 51, 52, 255, 53, 54, 255, 55, 56, 255, 57, 59, 255,
368 58, 60, 255, 61, 62, 255, 63, 64, 255, 65, 66, 255, 255, 255, 255, 255,
369 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
370 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
371 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 67, 68, 69, 70,
372 71, 255, 255, 76, 77, 255, 255, 78, 79, 80, 81, 82, 83, 84, 85, 86,
373 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 255,
374 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 102, 255, 255
378 static const EngineID tto_to_ttd[] = {
379 0, 0, 8, 8, 8, 8, 8, 9, 10, 11, 12, 13, 14, 15, 15, 22,
380 23, 24, 25, 26, 27, 29, 28, 30, 31, 32, 33, 34, 35, 36, 37, 55,
381 57, 59, 58, 60, 61, 62, 63, 64, 65, 66, 67, 116, 116, 117, 118, 123,
382 124, 126, 127, 132, 133, 135, 136, 138, 139, 141, 142, 144, 145, 147, 148, 150,
383 151, 153, 154, 204, 205, 206, 207, 208, 211, 212, 211, 212, 211, 212, 215, 216,
384 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
385 233, 234, 235, 236, 237, 238, 253
396 for (uint i = 0; i <
lengthof(_orig_rail_vehicle_info); i++, j++)
new (GetTempDataEngine(j))
Engine(
VEH_TRAIN, i);
397 for (uint i = 0; i <
lengthof(_orig_road_vehicle_info); i++, j++)
new (GetTempDataEngine(j))
Engine(
VEH_ROAD, i);
398 for (uint i = 0; i <
lengthof(_orig_ship_vehicle_info); i++, j++)
new (GetTempDataEngine(j))
Engine(
VEH_SHIP, i);
403 for (
EngineID i = 0; i < 256; i++) {
404 int oi = ttd_to_tto[i];
405 Engine *e = GetTempDataEngine(i);
422 Engine *oe = &_old_engines[oi];
440 for (uint j = 0; j <
lengthof(tto_to_ttd); j++) {
441 if (tto_to_ttd[j] == i && _old_engines[j].company_avail != 0) {
460 static void FixTTOCompanies()
463 FOR_ALL_COMPANIES(c) {
471 static const byte tto_colour_remap[] = {
472 COLOUR_DARK_BLUE, COLOUR_GREY, COLOUR_YELLOW, COLOUR_RED,
473 COLOUR_PURPLE, COLOUR_DARK_GREEN, COLOUR_ORANGE, COLOUR_PALE_GREEN,
474 COLOUR_BLUE, COLOUR_GREEN, COLOUR_CREAM, COLOUR_BROWN,
475 COLOUR_WHITE, COLOUR_LIGHT_BLUE, COLOUR_MAUVE, COLOUR_PINK
478 if ((
size_t)tto >=
lengthof(tto_colour_remap))
return COLOUR_GREY;
480 return tto_colour_remap[tto];
483 static inline uint RemapTownIndex(uint x)
488 static inline uint RemapOrderIndex(uint x)
497 static uint32 _old_town_index;
498 static uint16 _old_string_id;
499 static uint16 _old_string_id_2;
501 static void ReadTTDPatchFlags()
511 _bump_assert_value = 0;
530 for (uint i = 0; i < 17; i++) {
540 for (uint i = 0; i < 17; i++) _old_map3[i] = 0;
541 for (uint i = 0x1FE00; i < 0x20000; i++) _old_map3[i] = 0;
543 if (_savegame_type ==
SGT_TTDP2)
DEBUG(oldloader, 2,
"Found TTDPatch game");
549 OCL_SVAR( OC_TILE,
Town, xy ),
551 OCL_SVAR( OC_UINT16,
Town, townnametype ),
552 OCL_SVAR( OC_UINT32,
Town, townnameparts ),
553 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Town, grow_counter ),
557 OCL_SVAR( OC_FILE_U16 | OC_VAR_U8,
Town, flags ),
560 OCL_SVAR( OC_INT16,
Town, ratings[0] ),
561 OCL_SVAR( OC_INT16,
Town, ratings[1] ),
562 OCL_SVAR( OC_INT16,
Town, ratings[2] ),
563 OCL_SVAR( OC_INT16,
Town, ratings[3] ),
564 OCL_SVAR( OC_INT16,
Town, ratings[4] ),
565 OCL_SVAR( OC_INT16,
Town, ratings[5] ),
566 OCL_SVAR( OC_INT16,
Town, ratings[6] ),
567 OCL_SVAR( OC_INT16,
Town, ratings[7] ),
569 OCL_SVAR( OC_FILE_U32 | OC_VAR_U16,
Town, have_ratings ),
570 OCL_SVAR( OC_FILE_U32 | OC_VAR_U16,
Town, statues ),
572 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Town, time_until_rebuild ),
573 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Town, growth_rate ),
575 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Town, supplied[CT_PASSENGERS].new_max ),
576 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Town, supplied[CT_MAIL].new_max ),
577 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Town, supplied[CT_PASSENGERS].new_act ),
578 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Town, supplied[CT_MAIL].new_act ),
579 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Town, supplied[CT_PASSENGERS].old_max ),
580 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Town, supplied[CT_MAIL].old_max ),
581 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Town, supplied[CT_PASSENGERS].old_act ),
582 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Town, supplied[CT_MAIL].old_act ),
591 OCL_SVAR( OC_UINT8,
Town, road_build_months ),
592 OCL_SVAR( OC_UINT8,
Town, fund_buildings_months ),
602 if (!
LoadChunk(ls, t, town_chunk))
return false;
605 if (_savegame_type ==
SGT_TTO) {
607 t->townnametype = t->townnametype == 0x10B6 ? 0x20C1 : t->townnametype + 0x2A00;
616 static uint16 _old_order;
618 OCL_VAR ( OC_UINT16, 1, &_old_order ),
624 if (!
LoadChunk(ls, NULL, order_chunk))
return false;
629 if (o->
IsType(OT_NOTHING)) {
635 if (prev != NULL) prev->
next = o;
650 OCL_VAR ( OC_TILE, 256, _animated_tile_list ),
654 if (!
LoadChunk(ls, NULL, anim_chunk))
return false;
657 for (_animated_tile_count = 0; _animated_tile_count < 256; _animated_tile_count++) {
658 if (_animated_tile_list[_animated_tile_count] == 0)
break;
665 OCL_SVAR( OC_TILE,
Depot, xy ),
666 OCL_VAR ( OC_UINT32, 1, &_old_town_index ),
673 if (!
LoadChunk(ls, d, depot_chunk))
return false;
687 static StationID _current_station_id;
688 static uint16 _waiting_acceptance;
689 static uint8 _cargo_source;
690 static uint8 _cargo_days;
693 OCL_VAR ( OC_UINT16, 1, &_waiting_acceptance ),
694 OCL_SVAR( OC_UINT8,
GoodsEntry, time_since_pickup ),
696 OCL_VAR ( OC_UINT8, 1, &_cargo_source ),
697 OCL_VAR ( OC_UINT8, 1, &_cargo_days ),
707 if (_savegame_type ==
SGT_TTO && num == 11)
return true;
712 if (!
LoadChunk(ls, ge, goods_chunk))
return false;
717 ge->
cargo.
Append(
new CargoPacket(
GB(_waiting_acceptance, 0, 12), _cargo_days, (_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source, 0, 0),
724 static const OldChunks station_chunk[] = {
725 OCL_SVAR( OC_TILE,
Station, xy ),
726 OCL_VAR ( OC_UINT32, 1, &_old_town_index ),
729 OCL_SVAR( OC_TILE,
Station, train_station.tile ),
730 OCL_SVAR( OC_TILE,
Station, airport.tile ),
731 OCL_SVAR( OC_TILE,
Station, dock_tile ),
732 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Station, train_station.w ),
737 OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
741 OCL_SVAR( OC_FILE_U16 | OC_VAR_U8,
Station, had_vehicle_of_type ),
743 OCL_CHUNK( 12, LoadOldGood ),
745 OCL_SVAR( OC_UINT8,
Station, time_since_load ),
746 OCL_SVAR( OC_UINT8,
Station, time_since_unload ),
747 OCL_SVAR( OC_UINT8,
Station, delete_ctr ),
748 OCL_SVAR( OC_UINT8,
Station, owner ),
749 OCL_SVAR( OC_UINT8,
Station, facilities ),
751 OCL_SVAR(
OC_TTO | OC_FILE_U16 | OC_VAR_U64,
Station, airport.flags ),
754 OCL_SVAR(
OC_TTD | OC_FILE_U16 | OC_VAR_U64,
Station, airport.flags ),
764 _current_station_id = num;
766 if (!
LoadChunk(ls, st, station_chunk))
return false;
771 if (_savegame_type ==
SGT_TTO) {
773 st->
string_id = STR_SV_STNAME + (_old_string_id - 0x180F);
795 static const OldChunks industry_chunk[] = {
796 OCL_SVAR( OC_TILE,
Industry, location.tile ),
797 OCL_VAR ( OC_UINT32, 1, &_old_town_index ),
798 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Industry, location.w ),
799 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Industry, location.h ),
802 OCL_SVAR(
OC_TTD | OC_UINT16,
Industry, produced_cargo_waiting[0] ),
803 OCL_SVAR(
OC_TTD | OC_UINT16,
Industry, produced_cargo_waiting[1] ),
804 OCL_SVAR(
OC_TTO | OC_FILE_U8 | OC_VAR_U16,
Industry, produced_cargo_waiting[0] ),
805 OCL_SVAR(
OC_TTO | OC_FILE_U8 | OC_VAR_U16,
Industry, produced_cargo_waiting[1] ),
807 OCL_SVAR( OC_UINT8,
Industry, production_rate[0] ),
808 OCL_SVAR( OC_UINT8,
Industry, production_rate[1] ),
812 OCL_SVAR( OC_UINT8,
Industry, prod_level ),
814 OCL_SVAR( OC_UINT16,
Industry, this_month_production[0] ),
815 OCL_SVAR( OC_UINT16,
Industry, this_month_production[1] ),
816 OCL_SVAR( OC_UINT16,
Industry, this_month_transported[0] ),
817 OCL_SVAR( OC_UINT16,
Industry, this_month_transported[1] ),
819 OCL_SVAR( OC_UINT8,
Industry, last_month_pct_transported[0] ),
820 OCL_SVAR( OC_UINT8,
Industry, last_month_pct_transported[1] ),
822 OCL_SVAR( OC_UINT16,
Industry, last_month_production[0] ),
823 OCL_SVAR( OC_UINT16,
Industry, last_month_production[1] ),
824 OCL_SVAR( OC_UINT16,
Industry, last_month_transported[0] ),
825 OCL_SVAR( OC_UINT16,
Industry, last_month_transported[1] ),
827 OCL_SVAR( OC_UINT8,
Industry, type ),
829 OCL_SVAR( OC_UINT8,
Industry, owner ),
830 OCL_SVAR( OC_UINT8,
Industry, random_colour ),
831 OCL_SVAR(
OC_TTD | OC_FILE_U8 | OC_VAR_I32,
Industry, last_prod_year ),
843 if (!
LoadChunk(ls, i, industry_chunk))
return false;
848 if (_savegame_type ==
SGT_TTO) {
850 if (i->
type == 0x0A) i->
type = 0x12;
868 static int32 _old_yearly;
870 static const OldChunks _company_yearly_chunk[] = {
871 OCL_VAR( OC_INT32, 1, &_old_yearly ),
879 for (uint i = 0; i < 13; i++) {
880 if (_savegame_type ==
SGT_TTO && i == 6) {
883 if (!
LoadChunk(ls, NULL, _company_yearly_chunk))
return false;
892 static const OldChunks _company_economy_chunk[] = {
902 static bool LoadOldCompanyEconomy(
LoadgameState *ls,
int num)
912 for (uint i = 0; i < 24; i++) {
922 static const OldChunks _company_chunk[] = {
923 OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
924 OCL_SVAR( OC_UINT32,
Company, name_2 ),
925 OCL_SVAR( OC_UINT32,
Company, face ),
926 OCL_VAR ( OC_UINT16, 1, &_old_string_id_2 ),
927 OCL_SVAR( OC_UINT32,
Company, president_name_2 ),
929 OCL_SVAR( OC_FILE_I32 | OC_VAR_I64,
Company, money ),
930 OCL_SVAR( OC_FILE_I32 | OC_VAR_I64,
Company, current_loan ),
932 OCL_SVAR( OC_UINT8,
Company, colour ),
933 OCL_SVAR( OC_UINT8,
Company, money_fraction ),
934 OCL_SVAR( OC_UINT8,
Company, months_of_bankruptcy ),
935 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Company, bankrupt_asked ),
936 OCL_SVAR( OC_FILE_U32 | OC_VAR_I64,
Company, bankrupt_value ),
937 OCL_SVAR( OC_UINT16,
Company, bankrupt_timeout ),
942 OCL_CHUNK( 3, LoadOldCompanyYearly ),
943 OCL_CHUNK( 1, LoadOldCompanyEconomy ),
945 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32,
Company, inaugurated_year),
946 OCL_SVAR( OC_TILE,
Company, last_build_coordinate ),
947 OCL_SVAR( OC_UINT8,
Company, num_valid_stat_ent ),
951 OCL_SVAR( OC_UINT8,
Company, block_preview ),
954 OCL_SVAR( OC_TILE,
Company, location_of_HQ ),
971 if (!
LoadChunk(ls, c, _company_chunk))
return false;
973 if (_old_string_id == 0) {
978 if (_savegame_type ==
SGT_TTO) {
986 if (_old_string_id == 0 || _old_string_id == 0x4C00) {
987 _old_string_id = STR_SV_UNNAMED;
988 }
else if (
GB(_old_string_id, 8, 8) == 0x52) {
989 _old_string_id += 0x2A00;
993 c->
name_1 = _old_string_id;
996 switch (_old_string_id_2) {
997 case 0x4CDA: _old_string_id_2 = SPECSTR_PRESIDENT_NAME;
break;
998 case 0x0006: _old_string_id_2 = STR_SV_EMPTY;
break;
999 default: _old_string_id_2 = _old_string_id_2 + 0x2A00;
break;
1005 if (num != 0) c->
is_ai =
true;
1013 c->
name_1 = STR_SV_UNNAMED;
1035 static uint32 _old_order_ptr;
1036 static uint16 _old_next_ptr;
1039 static const OldChunks vehicle_train_chunk[] = {
1040 OCL_SVAR( OC_UINT8,
Train, track ),
1041 OCL_SVAR( OC_UINT8,
Train, force_proceed ),
1042 OCL_SVAR( OC_UINT16,
Train, crash_anim_pos ),
1043 OCL_SVAR( OC_UINT8,
Train, railtype ),
1050 static const OldChunks vehicle_road_chunk[] = {
1055 OCL_SVAR( OC_UINT8,
RoadVehicle, overtaking_ctr ),
1064 static const OldChunks vehicle_ship_chunk[] = {
1065 OCL_SVAR( OC_UINT8,
Ship, state ),
1072 static const OldChunks vehicle_air_chunk[] = {
1073 OCL_SVAR( OC_UINT8,
Aircraft, pos ),
1074 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Aircraft, targetairport ),
1075 OCL_SVAR( OC_UINT16,
Aircraft, crashed_counter ),
1076 OCL_SVAR( OC_UINT8,
Aircraft, state ),
1083 static const OldChunks vehicle_effect_chunk[] = {
1092 static const OldChunks vehicle_disaster_chunk[] = {
1101 static const OldChunks vehicle_empty_chunk[] = {
1110 uint temp = ls->total_read;
1114 res =
LoadChunk(ls, NULL, vehicle_empty_chunk);
1128 if (ls->total_read - temp != 10) {
1129 DEBUG(oldloader, 0,
"Assert failed in VehicleUnion: invalid chunk size");
1136 static uint16 _cargo_count;
1138 static const OldChunks vehicle_chunk[] = {
1139 OCL_SVAR( OC_UINT8,
Vehicle, subtype ),
1144 OCL_VAR ( OC_UINT32, 1, &_old_order_ptr ),
1145 OCL_VAR ( OC_UINT16, 1, &_old_order ),
1148 OCL_SVAR( OC_UINT8,
Vehicle, cur_implicit_order_index ),
1149 OCL_SVAR( OC_TILE,
Vehicle, dest_tile ),
1150 OCL_SVAR( OC_UINT16,
Vehicle, load_unload_ticks ),
1151 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Vehicle, date_of_last_service ),
1152 OCL_SVAR( OC_UINT16,
Vehicle, service_interval ),
1153 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Vehicle, last_station_visited ),
1158 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32,
Vehicle, x_pos ),
1159 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32,
Vehicle, y_pos ),
1160 OCL_SVAR( OC_FILE_U8 | OC_VAR_I32,
Vehicle, z_pos ),
1161 OCL_SVAR( OC_UINT8,
Vehicle, direction ),
1166 OCL_SVAR( OC_UINT8,
Vehicle, owner ),
1167 OCL_SVAR( OC_TILE,
Vehicle, tile ),
1168 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Vehicle, sprite_seq.seq[0].sprite ),
1172 OCL_SVAR( OC_FILE_U16 | OC_VAR_U8,
Vehicle, vehstatus ),
1174 OCL_SVAR(
OC_TTO | OC_FILE_U8 | OC_VAR_U16,
Vehicle, cur_speed ),
1175 OCL_SVAR( OC_UINT8,
Vehicle, subspeed ),
1176 OCL_SVAR( OC_UINT8,
Vehicle, acceleration ),
1177 OCL_SVAR( OC_UINT8,
Vehicle, progress ),
1179 OCL_SVAR( OC_UINT8,
Vehicle, cargo_type ),
1181 OCL_SVAR(
OC_TTO | OC_FILE_U8 | OC_VAR_U16,
Vehicle, cargo_cap ),
1182 OCL_VAR (
OC_TTD | OC_UINT16, 1, &_cargo_count ),
1183 OCL_VAR (
OC_TTO | OC_FILE_U8 | OC_VAR_U16, 1, &_cargo_count ),
1184 OCL_VAR ( OC_UINT8, 1, &_cargo_source ),
1185 OCL_VAR ( OC_UINT8, 1, &_cargo_days ),
1189 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Vehicle, age ),
1190 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Vehicle, max_age ),
1191 OCL_SVAR( OC_FILE_U8 | OC_VAR_I32,
Vehicle, build_year ),
1192 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Vehicle, unitnumber ),
1195 OCL_SVAR(
OC_TTO | OC_FILE_U8 | OC_VAR_U16,
Vehicle, engine_type ),
1197 OCL_SVAR( OC_UINT8,
Vehicle, spritenum ),
1198 OCL_SVAR( OC_UINT8,
Vehicle, day_counter ),
1200 OCL_SVAR( OC_UINT8,
Vehicle, breakdowns_since_last_service ),
1201 OCL_SVAR( OC_UINT8,
Vehicle, breakdown_ctr ),
1202 OCL_SVAR( OC_UINT8,
Vehicle, breakdown_delay ),
1203 OCL_SVAR( OC_UINT8,
Vehicle, breakdown_chance ),
1207 OCL_SVAR( OC_UINT16,
Vehicle, reliability ),
1208 OCL_SVAR( OC_UINT16,
Vehicle, reliability_spd_dec ),
1210 OCL_SVAR( OC_FILE_I32 | OC_VAR_I64,
Vehicle, profit_this_year ),
1211 OCL_SVAR( OC_FILE_I32 | OC_VAR_I64,
Vehicle, profit_last_year ),
1213 OCL_VAR ( OC_UINT16, 1, &_old_next_ptr ),
1215 OCL_SVAR( OC_FILE_U32 | OC_VAR_I64,
Vehicle, value ),
1217 OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
1219 OCL_CHUNK( 1, LoadOldVehicleUnion ),
1236 ReadTTDPatchFlags();
1239 _current_vehicle_id = num * _old_vehicle_multiplier + i;
1243 if (_savegame_type ==
SGT_TTO) {
1246 default:
return false;
1247 case 0x00 : v = NULL;
break;
1249 case 0x20 : v =
new (_current_vehicle_id)
Train();
break;
1250 case 0x21 : v =
new (_current_vehicle_id)
RoadVehicle();
break;
1251 case 0x22 : v =
new (_current_vehicle_id)
Ship();
break;
1252 case 0x23 : v =
new (_current_vehicle_id)
Aircraft();
break;
1253 case 0x24 : v =
new (_current_vehicle_id)
EffectVehicle();
break;
1257 if (!
LoadChunk(ls, v, vehicle_chunk))
return false;
1258 if (v == NULL)
continue;
1276 static const byte spriteset_rail[] = {
1277 0, 2, 4, 4, 8, 10, 12, 14, 16, 18, 20, 22, 40, 42, 44, 46,
1278 48, 52, 54, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 120, 122,
1279 124, 126, 128, 130, 132, 134, 136, 138, 140
1310 switch (_old_string_id) {
1312 case 0x0006: _old_string_id = STR_SV_EMPTY;
break;
1313 case 0x8495: _old_string_id = STR_SV_TRAIN_NAME;
break;
1314 case 0x8842: _old_string_id = STR_SV_ROAD_VEHICLE_NAME;
break;
1315 case 0x8C3B: _old_string_id = STR_SV_SHIP_NAME;
break;
1316 case 0x9047: _old_string_id = STR_SV_AIRCRAFT_NAME;
break;
1317 default: _old_string_id += 0x2A00;
break;
1320 _old_vehicle_names[_current_vehicle_id] = _old_string_id;
1325 case 0x00 : v = NULL;
break;
1326 case 0x10 : v =
new (_current_vehicle_id)
Train();
break;
1327 case 0x11 : v =
new (_current_vehicle_id)
RoadVehicle();
break;
1328 case 0x12 : v =
new (_current_vehicle_id)
Ship();
break;
1329 case 0x13 : v =
new (_current_vehicle_id)
Aircraft();
break;
1330 case 0x14 : v =
new (_current_vehicle_id)
EffectVehicle();
break;
1334 if (!
LoadChunk(ls, v, vehicle_chunk))
return false;
1335 if (v == NULL)
continue;
1337 _old_vehicle_names[_current_vehicle_id] =
RemapOldStringID(_old_string_id);
1340 if (v->
index != _current_vehicle_id) {
1341 DEBUG(oldloader, 0,
"Loading failed - vehicle-array is invalid");
1346 if (_old_order_ptr != 0 && _old_order_ptr != 0xFFFFFFFF) {
1347 uint
max = _savegame_type ==
SGT_TTO ? 3000 : 5000;
1348 uint old_id = RemapOrderIndex(_old_order_ptr);
1356 StationID source = (_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source;
1366 OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
1367 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32,
Sign, x ),
1368 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32,
Sign, y ),
1369 OCL_SVAR( OC_FILE_U16 | OC_VAR_I8,
Sign, z ),
1379 if (!
LoadChunk(ls, si, sign_chunk))
return false;
1381 if (_old_string_id != 0) {
1382 if (_savegame_type ==
SGT_TTO) {
1383 if (_old_string_id != 0x140A) si->name =
CopyFromOldName(_old_string_id + 0x2A00);
1395 static const OldChunks engine_chunk[] = {
1396 OCL_SVAR( OC_UINT16,
Engine, company_avail ),
1397 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Engine, intro_date ),
1398 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Engine, age ),
1399 OCL_SVAR( OC_UINT16,
Engine, reliability ),
1400 OCL_SVAR( OC_UINT16,
Engine, reliability_spd_dec ),
1401 OCL_SVAR( OC_UINT16,
Engine, reliability_start ),
1402 OCL_SVAR( OC_UINT16,
Engine, reliability_max ),
1403 OCL_SVAR( OC_UINT16,
Engine, reliability_final ),
1404 OCL_SVAR( OC_UINT16,
Engine, duration_phase_1 ),
1405 OCL_SVAR( OC_UINT16,
Engine, duration_phase_2 ),
1406 OCL_SVAR( OC_UINT16,
Engine, duration_phase_3 ),
1409 OCL_SVAR( OC_UINT8,
Engine, flags ),
1411 OCL_SVAR( OC_UINT8,
Engine, preview_wait ),
1420 Engine *e = _savegame_type ==
SGT_TTO ? &_old_engines[num] : GetTempDataEngine(num);
1426 Engine *e = GetTempDataEngine(num);
1431 static const OldChunks subsidy_chunk[] = {
1432 OCL_SVAR( OC_UINT8,
Subsidy, cargo_type ),
1433 OCL_SVAR( OC_UINT8,
Subsidy, remaining ),
1434 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Subsidy, src ),
1435 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Subsidy, dst ),
1443 bool ret =
LoadChunk(ls, s, subsidy_chunk);
1448 static const OldChunks game_difficulty_chunk[] = {
1469 static bool LoadOldGameDifficulty(
LoadgameState *ls,
int num)
1479 if (_savegame_type ==
SGT_TTO) {
1484 for (uint i = 0; i < OLD_MAP_SIZE; i++) {
1487 for (uint i = 0; i < OLD_MAP_SIZE; i++) {
1491 if (_savegame_type !=
SGT_TTO) {
1492 for (uint i = 0; i < OLD_MAP_SIZE; i++) {
1494 _old_map3[i * 2 + 1] =
ReadByte(ls);
1496 for (uint i = 0; i < OLD_MAP_SIZE / 4; i++) {
1498 _me[i * 4 + 0].
m6 =
GB(b, 0, 2);
1499 _me[i * 4 + 1].
m6 =
GB(b, 2, 2);
1500 _me[i * 4 + 2].
m6 =
GB(b, 4, 2);
1501 _me[i * 4 + 3].
m6 =
GB(b, 6, 2);
1512 for (i = 0; i < OLD_MAP_SIZE; i++) {
1515 for (i = 0; i < OLD_MAP_SIZE; i++) {
1522 static bool LoadTTDPatchExtraChunks(
LoadgameState *ls,
int num)
1524 ReadTTDPatchFlags();
1529 uint16
id = ReadUint16(ls);
1530 uint32 len = ReadUint32(ls);
1538 ReadUint32(ls);
ReadByte(ls); len -= 5;
1542 uint32 grfid = ReadUint32(ls);
1562 DEBUG(oldloader, 3,
"Game saved with TTDPatch version %d.%d.%d r%d",
1563 GB(
_ttdp_version, 24, 8),
GB(
_ttdp_version, 20, 4),
GB(
_ttdp_version, 16, 4),
GB(
_ttdp_version, 0, 16));
1569 DEBUG(oldloader, 4,
"Skipping unknown extra chunk %X",
id);
1582 extern uint8 _old_diff_level;
1583 extern uint8 _old_units;
1587 OCL_VAR ( OC_FILE_U16 | OC_VAR_U32, 1, &
_date ),
1592 OCL_ASSERT(
OC_TTD, 0x264 ),
1593 OCL_ASSERT(
OC_TTO, 0x264 ),
1595 OCL_CCHUNK(
OC_TTD, 70, LoadOldTown ),
1596 OCL_CCHUNK(
OC_TTO, 80, LoadOldTown ),
1598 OCL_ASSERT(
OC_TTD, 0x1C18 ),
1599 OCL_ASSERT(
OC_TTO, 0x1AC4 ),
1601 OCL_CCHUNK(
OC_TTD, 5000, LoadOldOrder ),
1602 OCL_CCHUNK(
OC_TTO, 3000, LoadOldOrder ),
1604 OCL_ASSERT(
OC_TTD, 0x4328 ),
1605 OCL_ASSERT(
OC_TTO, 0x3234 ),
1607 OCL_CHUNK( 1, LoadOldAnimTileList ),
1610 OCL_ASSERT(
OC_TTO, 0x3438 ),
1612 OCL_CCHUNK(
OC_TTD, 255, LoadOldDepot ),
1613 OCL_CCHUNK(
OC_TTO, 252, LoadOldDepot ),
1615 OCL_ASSERT(
OC_TTD, 0x4B26 ),
1616 OCL_ASSERT(
OC_TTO, 0x3A20 ),
1622 OCL_VAR ( OC_FILE_U16 | OC_VAR_U8, 1, &_age_cargo_skip_counter ),
1624 OCL_VAR ( OC_TILE, 1, &_cur_tileloop_tile ),
1626 OCL_ASSERT(
OC_TTO, 0x3A2E ),
1628 OCL_CNULL(
OC_TTO, 48 * 6 ),
1629 OCL_CNULL(
OC_TTD, 49 * 6 ),
1631 OCL_ASSERT(
OC_TTO, 0x3B4E ),
1633 OCL_CNULL(
OC_TTO, 11 * 8 ),
1634 OCL_CNULL(
OC_TTD, 12 * 8 ),
1636 OCL_ASSERT(
OC_TTD, 0x4CBA ),
1637 OCL_ASSERT(
OC_TTO, 0x3BA6 ),
1639 OCL_CHUNK( 1, LoadOldMapPart1 ),
1641 OCL_ASSERT(
OC_TTD, 0x48CBA ),
1642 OCL_ASSERT(
OC_TTO, 0x23BA6 ),
1644 OCL_CCHUNK(
OC_TTD, 250, LoadOldStation ),
1645 OCL_CCHUNK(
OC_TTO, 200, LoadOldStation ),
1647 OCL_ASSERT(
OC_TTO, 0x29E16 ),
1649 OCL_CCHUNK(
OC_TTD, 90, LoadOldIndustry ),
1650 OCL_CCHUNK(
OC_TTO, 100, LoadOldIndustry ),
1652 OCL_ASSERT(
OC_TTO, 0x2ADB6 ),
1654 OCL_CHUNK( 8, LoadOldCompany ),
1656 OCL_ASSERT(
OC_TTD, 0x547F2 ),
1657 OCL_ASSERT(
OC_TTO, 0x2C746 ),
1662 OCL_ASSERT(
OC_TTD, 0x6F0F2 ),
1663 OCL_ASSERT(
OC_TTO, 0x45746 ),
1668 OCL_ASSERT(
OC_TTO, 0x46A06 ),
1672 OCL_CHUNK( 40, LoadOldSign ),
1674 OCL_ASSERT(
OC_TTO, 0x48C36 ),
1676 OCL_CCHUNK(
OC_TTD, 256, LoadOldEngine ),
1677 OCL_CCHUNK(
OC_TTO, 103, LoadOldEngine ),
1679 OCL_ASSERT(
OC_TTO, 0x496AC ),
1683 OCL_CHUNK( 8, LoadOldSubsidy ),
1685 OCL_ASSERT(
OC_TTO, 0x496CE ),
1691 OCL_VAR ( OC_FILE_I16 | OC_VAR_I32, 1, &_saved_scrollpos_x ),
1692 OCL_VAR ( OC_FILE_I16 | OC_VAR_I32, 1, &_saved_scrollpos_y ),
1693 OCL_VAR ( OC_FILE_U16 | OC_VAR_U8, 1, &_saved_scrollpos_zoom ),
1697 OCL_VAR ( OC_INT16, 1, &_economy.
fluct ),
1699 OCL_VAR ( OC_UINT16, 1, &_disaster_delay ),
1701 OCL_ASSERT(
OC_TTO, 0x496E4 ),
1703 OCL_CNULL(
OC_TTD, 144 ),
1705 OCL_CCHUNK(
OC_TTD, 256, LoadOldEngineName ),
1707 OCL_CNULL(
OC_TTD, 144 ),
1712 OCL_VAR ( OC_UINT8, 1, &_old_units ),
1725 OCL_CHUNK( 1, LoadOldGameDifficulty ),
1727 OCL_ASSERT(
OC_TTD, 0x77130 ),
1729 OCL_VAR ( OC_UINT8, 1, &_old_diff_level ),
1732 OCL_VAR (
OC_TTD | OC_UINT8, 1, &_trees_tick_ctr ),
1740 OCL_ASSERT(
OC_TTD, 0x77179 ),
1741 OCL_ASSERT(
OC_TTO, 0x4971D ),
1743 OCL_CHUNK( 1, LoadOldMapPart2 ),
1745 OCL_ASSERT(
OC_TTD, 0x97179 ),
1746 OCL_ASSERT(
OC_TTO, 0x6971D ),
1749 OCL_CHUNK(1, LoadTTDPatchExtraChunks),
1756 DEBUG(oldloader, 3,
"Reading main chunk...");
1762 _old_map3 = map3.
data;
1763 _old_vehicle_names = NULL;
1766 DEBUG(oldloader, 0,
"Loading failed");
1767 free(_old_vehicle_names);
1771 free(_old_vehicle_names);
1775 DEBUG(oldloader, 3,
"Done, converting game data...");
1790 DEBUG(oldloader, 3,
"Finished converting game data");
1791 DEBUG(oldloader, 1,
"TTD(Patch) savegame successfully converted");
1793 free(_old_vehicle_names);
1800 DEBUG(oldloader, 3,
"Reading main chunk...");
1807 _old_vehicle_names = vehnames.
data;
1811 DEBUG(oldloader, 0,
"Loading failed");
1814 DEBUG(oldloader, 3,
"Done, converting game data...");
1819 _trees_tick_ctr = 0xFF;
1822 DEBUG(oldloader, 0,
"Conversion failed");
1839 DEBUG(oldloader, 3,
"Finished converting game data");
1840 DEBUG(oldloader, 1,
"TTO savegame successfully converted");