10 #include "../stdafx.h"
12 #include "../industry.h"
13 #include "../company_func.h"
14 #include "../aircraft.h"
15 #include "../roadveh.h"
18 #include "../signs_base.h"
19 #include "../station_base.h"
20 #include "../subsidy_base.h"
22 #include "../depot_base.h"
23 #include "../timer/timer_game_calendar.h"
24 #include "../timer/timer_game_calendar.h"
25 #include "../vehicle_func.h"
26 #include "../effectvehicle_base.h"
27 #include "../engine_func.h"
28 #include "../company_base.h"
29 #include "../disaster_vehicle.h"
30 #include "../timer/timer.h"
31 #include "../timer/timer_game_tick.h"
32 #include "../timer/timer_game_calendar.h"
36 #include "table/strings.h"
37 #include "../table/engines.h"
38 #include "../table/townname.h"
40 #include "../safeguards.h"
53 static void FixTTDMapArray()
61 case 0x53:
case 0x54: tile.m5() += 170 - 0x53;
break;
62 case 0x57:
case 0x58: tile.m5() += 168 - 0x57;
break;
63 case 0x55:
case 0x56: tile.m5() += 170 - 0x55;
break;
64 case 0x59:
case 0x5A: tile.m5() += 168 - 0x59;
break;
71 if (
GB(tile.m5(), 6, 2) == 1) {
74 tile.m4() = (tile.m4() >> 1) & 7;
84 if (
GB(tile.m3(), 0, 2) == 3) {
112 #define FIXNUM(x, y, z) (((((x) << 16) / (y)) + 1) << z)
114 static uint32_t RemapOldTownName(uint32_t townnameparts,
byte old_town_name_type)
116 switch (old_town_name_type) {
119 return townnameparts;
124 return FIXNUM(townnameparts - 86,
lengthof(_name_french_real), 0);
127 Debug(misc, 0,
"German Townnames are buggy ({})", townnameparts);
128 return townnameparts;
132 return FIXNUM(townnameparts,
lengthof(_name_spanish_real), 0);
138 return FIXNUM(townnameparts,
lengthof(_name_silly_1), 0) | FIXNUM(
GB(townnameparts, 16, 8),
lengthof(_name_silly_2), 16);
145 static void FixOldTowns()
149 if (
IsInsideMM(town->townnametype, 0x20C1, 0x20C3)) {
156 static StringID *_old_vehicle_names;
166 if ((
size_t)v->next == 0xFFFF) {
173 switch (v->spritenum) {
175 case 0xff: v->spritenum = 0xfe;
break;
176 default: v->spritenum >>= 1;
break;
180 if (v->type ==
VEH_EFFECT) v->subtype = v->subtype >> 1;
205 (v->IsPrimaryVehicle() && v->current_order.IsType(OT_NOTHING))) {
206 v->current_order.MakeDummy();
213 static bool FixTTOMapArray()
231 switch (
GB(tile.m5(), 6, 2)) {
235 tile.m4() = (~tile.m5() & 1) << 2;
236 SB(tile.m2(), 6, 2,
GB(tile.m5(), 3, 2));
238 tile.m5() =
HasBit(tile.m5(), 5) ? 2 : 1;
250 switch (
GB(tile.m5(), 4, 4)) {
252 if (tile.m2() == 4) tile.m2() = 5;
255 tile.m3() = tile.m1();
265 tile.m3() = tile.m2() & 0xC0;
267 if (tile.m2() >= 5) tile.m2()++;
271 tile.m3() =
GB(tile.m5(), 3, 3);
276 tile.m3() = (tile.m5() >= 0x08 && tile.m5() <= 0x0F) ? 1 : 0;
277 if (tile.m5() >= 8) tile.m5() -= 8;
278 if (tile.m5() >= 0x42) tile.m5()++;
282 tile.m3() = tile.m2() = 0;
286 tile.m2() = tile.m3() = tile.m5() = 0;
295 case 0x25:
case 0x27:
296 case 0x28:
case 0x29:
case 0x2A:
case 0x2B:
300 if (tile.m5() >= 0x2C) tile.m5() += 3;
306 if (
HasBit(tile.m5(), 7)) {
308 tile.m5() = m5 & 0xE1;
309 if (
GB(m5, 1, 2) == 1) tile.m5() |= 0x02;
310 if (
GB(m5, 1, 2) == 3) tile.m2() |= 0xA0;
312 tile.m3() = (
GB(m5, 1, 2) == 3) ? 1 : 0;
314 tile.m3() =
HasBit(m5, 2) ? 0x10 : 0;
315 if (
GB(m5, 3, 2) == 3) tile.m3() |= 1;
316 if (
GB(m5, 3, 2) == 1) tile.m5() |= 0x08;
320 tile.m3() =
HasBit(tile.m5(), 3);
321 tile.m5() &=
HasBit(tile.m5(), 3) ? 0x03 : 0x07 ;
341 static Engine *_old_engines;
346 static const EngineID ttd_to_tto[] = {
347 0, 255, 255, 255, 255, 255, 255, 255, 5, 7, 8, 9, 10, 11, 12, 13,
348 255, 255, 255, 255, 255, 255, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
349 25, 26, 27, 29, 28, 30, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
350 255, 255, 255, 255, 255, 255, 255, 31, 255, 32, 33, 34, 35, 36, 37, 38,
351 39, 40, 41, 42, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
352 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
353 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
354 255, 255, 255, 255, 44, 45, 46, 255, 255, 255, 255, 47, 48, 255, 49, 50,
355 255, 255, 255, 255, 51, 52, 255, 53, 54, 255, 55, 56, 255, 57, 59, 255,
356 58, 60, 255, 61, 62, 255, 63, 64, 255, 65, 66, 255, 255, 255, 255, 255,
357 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
358 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
359 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 67, 68, 69, 70,
360 71, 255, 255, 76, 77, 255, 255, 78, 79, 80, 81, 82, 83, 84, 85, 86,
361 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 255,
362 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 102, 255, 255
366 static const EngineID tto_to_ttd[] = {
367 0, 0, 8, 8, 8, 8, 8, 9, 10, 11, 12, 13, 14, 15, 15, 22,
368 23, 24, 25, 26, 27, 29, 28, 30, 31, 32, 33, 34, 35, 36, 37, 55,
369 57, 59, 58, 60, 61, 62, 63, 64, 65, 66, 67, 116, 116, 117, 118, 123,
370 124, 126, 127, 132, 133, 135, 136, 138, 139, 141, 142, 144, 145, 147, 148, 150,
371 151, 153, 154, 204, 205, 206, 207, 208, 211, 212, 211, 212, 211, 212, 215, 216,
372 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
373 233, 234, 235, 236, 237, 238, 253
377 if (v->engine_type >=
lengthof(tto_to_ttd))
return false;
378 v->engine_type = tto_to_ttd[v->engine_type];
384 for (uint i = 0; i <
lengthof(_orig_rail_vehicle_info); i++, j++)
new (GetTempDataEngine(j))
Engine(
VEH_TRAIN, i);
385 for (uint i = 0; i <
lengthof(_orig_road_vehicle_info); i++, j++)
new (GetTempDataEngine(j))
Engine(
VEH_ROAD, i);
386 for (uint i = 0; i <
lengthof(_orig_ship_vehicle_info); i++, j++)
new (GetTempDataEngine(j))
Engine(
VEH_SHIP, i);
393 for (
EngineID i = 0; i < 256; i++) {
394 int oi = ttd_to_tto[i];
395 Engine *e = GetTempDataEngine(i);
413 Engine *oe = &_old_engines[oi];
431 for (uint j = 0; j <
lengthof(tto_to_ttd); j++) {
432 if (tto_to_ttd[j] == i && _old_engines[j].company_avail != 0) {
445 e->
name = std::string{};
451 static void FixTTOCompanies()
461 static const Colours tto_colour_remap[] = {
462 COLOUR_DARK_BLUE, COLOUR_GREY, COLOUR_YELLOW, COLOUR_RED,
463 COLOUR_PURPLE, COLOUR_DARK_GREEN, COLOUR_ORANGE, COLOUR_PALE_GREEN,
464 COLOUR_BLUE, COLOUR_GREEN, COLOUR_CREAM, COLOUR_BROWN,
465 COLOUR_WHITE, COLOUR_LIGHT_BLUE, COLOUR_MAUVE, COLOUR_PINK
468 if ((
size_t)tto >=
lengthof(tto_colour_remap))
return COLOUR_GREY;
470 return tto_colour_remap[tto];
473 static inline uint RemapTownIndex(uint x)
478 static inline uint RemapOrderIndex(uint x)
487 static uint32_t _old_town_index;
488 static uint16_t _old_string_id;
489 static uint16_t _old_string_id_2;
511 static void ReadTTDPatchFlags()
521 _bump_assert_value = 0;
549 if (ttdp2_header_first.m3() ==
'T' && ttdp2_header_first.m4() ==
'T' &&
550 ttdp2_header_second.m3() ==
'D' && ttdp2_header_second.m4() ==
'p') {
558 for (
TileIndex i = 0; i < 9; i++) ClearOldMap3(i);
567 OCL_SVAR( OC_TILE,
Town, xy ),
569 OCL_SVAR( OC_UINT16,
Town, townnametype ),
570 OCL_SVAR( OC_UINT32,
Town, townnameparts ),
571 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Town, grow_counter ),
575 OCL_SVAR( OC_FILE_U16 | OC_VAR_U8,
Town, flags ),
578 OCL_SVAR( OC_INT16,
Town, ratings[0] ),
579 OCL_SVAR( OC_INT16,
Town, ratings[1] ),
580 OCL_SVAR( OC_INT16,
Town, ratings[2] ),
581 OCL_SVAR( OC_INT16,
Town, ratings[3] ),
582 OCL_SVAR( OC_INT16,
Town, ratings[4] ),
583 OCL_SVAR( OC_INT16,
Town, ratings[5] ),
584 OCL_SVAR( OC_INT16,
Town, ratings[6] ),
585 OCL_SVAR( OC_INT16,
Town, ratings[7] ),
587 OCL_SVAR( OC_FILE_U32 | OC_VAR_U16,
Town, have_ratings ),
588 OCL_SVAR( OC_FILE_U32 | OC_VAR_U16,
Town, statues ),
590 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Town, time_until_rebuild ),
591 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Town, growth_rate ),
594 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Town, supplied[0].new_max ),
595 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Town, supplied[2].new_max ),
596 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Town, supplied[0].new_act ),
597 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Town, supplied[2].new_act ),
598 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Town, supplied[0].old_max ),
599 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Town, supplied[2].old_max ),
600 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Town, supplied[0].old_act ),
601 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Town, supplied[2].old_act ),
610 OCL_SVAR( OC_UINT8,
Town, road_build_months ),
611 OCL_SVAR( OC_UINT8,
Town, fund_buildings_months ),
621 if (!
LoadChunk(ls, t, town_chunk))
return false;
626 t->townnametype = t->townnametype == 0x10B6 ? 0x20C1 : t->townnametype + 0x2A00;
635 static uint16_t _old_order;
637 OCL_VAR ( OC_UINT16, 1, &_old_order ),
643 if (!
LoadChunk(ls,
nullptr, order_chunk))
return false;
648 if (o->
IsType(OT_NOTHING)) {
654 if (prev !=
nullptr) prev->
next = o;
664 OCL_VAR ( OC_TILE, 256, anim_list ),
668 if (!
LoadChunk(ls,
nullptr, anim_chunk))
return false;
671 for (
int i = 0; i < 256; i++) {
672 if (anim_list[i] == 0)
break;
680 OCL_SVAR( OC_TILE,
Depot, xy ),
681 OCL_VAR ( OC_UINT32, 1, &_old_town_index ),
688 if (!
LoadChunk(ls, d, depot_chunk))
return false;
691 d->town = RemapTown(d->xy);
699 static StationID _current_station_id;
700 static uint16_t _waiting_acceptance;
701 static uint8_t _cargo_source;
702 static uint8_t _cargo_periods;
705 OCL_VAR ( OC_UINT16, 1, &_waiting_acceptance ),
706 OCL_SVAR( OC_UINT8,
GoodsEntry, time_since_pickup ),
708 OCL_VAR ( OC_UINT8, 1, &_cargo_source ),
709 OCL_VAR ( OC_UINT8, 1, &_cargo_periods ),
724 if (!
LoadChunk(ls, ge, goods_chunk))
return false;
736 static const OldChunks station_chunk[] = {
737 OCL_SVAR( OC_TILE,
Station, xy ),
738 OCL_VAR ( OC_UINT32, 1, &_old_town_index ),
741 OCL_SVAR( OC_TILE,
Station, train_station.tile ),
742 OCL_SVAR( OC_TILE,
Station, airport.tile ),
744 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Station, train_station.w ),
749 OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
753 OCL_SVAR( OC_FILE_U16 | OC_VAR_U8,
Station, had_vehicle_of_type ),
755 OCL_CHUNK( 12, LoadOldGood ),
757 OCL_SVAR( OC_UINT8,
Station, time_since_load ),
758 OCL_SVAR( OC_UINT8,
Station, time_since_unload ),
759 OCL_SVAR( OC_UINT8,
Station, delete_ctr ),
760 OCL_SVAR( OC_UINT8,
Station, owner ),
761 OCL_SVAR( OC_UINT8,
Station, facilities ),
763 OCL_SVAR(
OC_TTO | OC_FILE_U16 | OC_VAR_U64,
Station, airport.flags ),
766 OCL_SVAR(
OC_TTD | OC_FILE_U16 | OC_VAR_U64,
Station, airport.flags ),
776 _current_station_id = num;
778 if (!
LoadChunk(ls, st, station_chunk))
return false;
781 st->
town = RemapTown(st->
xy);
785 st->
string_id = STR_SV_STNAME + (_old_string_id - 0x180F);
807 static const OldChunks industry_chunk[] = {
808 OCL_SVAR( OC_TILE,
Industry, location.tile ),
809 OCL_VAR ( OC_UINT32, 1, &_old_town_index ),
810 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Industry, location.w ),
811 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Industry, location.h ),
816 OCL_SVAR(
OC_TTO | OC_FILE_U8 | OC_VAR_U16,
Industry, produced[0].waiting ),
817 OCL_SVAR(
OC_TTO | OC_FILE_U8 | OC_VAR_U16,
Industry, produced[1].waiting ),
819 OCL_SVAR( OC_UINT8,
Industry, produced[0].rate ),
820 OCL_SVAR( OC_UINT8,
Industry, produced[1].rate ),
824 OCL_SVAR( OC_UINT8,
Industry, prod_level ),
826 OCL_SVAR( OC_UINT16,
Industry, produced[0].history[THIS_MONTH].production ),
827 OCL_SVAR( OC_UINT16,
Industry, produced[1].history[THIS_MONTH].production ),
828 OCL_SVAR( OC_UINT16,
Industry, produced[0].history[THIS_MONTH].transported ),
829 OCL_SVAR( OC_UINT16,
Industry, produced[1].history[THIS_MONTH].transported ),
833 OCL_SVAR( OC_UINT16,
Industry, produced[0].history[LAST_MONTH].production ),
834 OCL_SVAR( OC_UINT16,
Industry, produced[1].history[LAST_MONTH].production ),
835 OCL_SVAR( OC_UINT16,
Industry, produced[0].history[LAST_MONTH].transported ),
836 OCL_SVAR( OC_UINT16,
Industry, produced[1].history[LAST_MONTH].transported ),
838 OCL_SVAR( OC_UINT8,
Industry, type ),
840 OCL_SVAR( OC_UINT8,
Industry, owner ),
841 OCL_SVAR( OC_UINT8,
Industry, random_colour ),
842 OCL_SVAR(
OC_TTD | OC_FILE_U8 | OC_VAR_I32,
Industry, last_prod_year ),
854 if (!
LoadChunk(ls, i, industry_chunk))
return false;
861 if (i->
type == 0x0A) i->
type = 0x12;
878 static int32_t _old_yearly;
880 static const OldChunks _company_yearly_chunk[] = {
881 OCL_VAR( OC_INT32, 1, &_old_yearly ),
889 for (uint i = 0; i < 13; i++) {
893 if (!
LoadChunk(ls,
nullptr, _company_yearly_chunk))
return false;
902 static const OldChunks _company_economy_chunk[] = {
922 for (uint i = 0; i < 24; i++) {
932 static const OldChunks _company_chunk[] = {
933 OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
934 OCL_SVAR( OC_UINT32,
Company, name_2 ),
935 OCL_SVAR( OC_UINT32,
Company, face ),
936 OCL_VAR ( OC_UINT16, 1, &_old_string_id_2 ),
937 OCL_SVAR( OC_UINT32,
Company, president_name_2 ),
939 OCL_SVAR( OC_FILE_I32 | OC_VAR_I64,
Company, money ),
940 OCL_SVAR( OC_FILE_I32 | OC_VAR_I64,
Company, current_loan ),
942 OCL_SVAR( OC_UINT8,
Company, colour ),
943 OCL_SVAR( OC_UINT8,
Company, money_fraction ),
944 OCL_SVAR( OC_UINT8,
Company, months_of_bankruptcy ),
945 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Company, bankrupt_asked ),
946 OCL_SVAR( OC_FILE_U32 | OC_VAR_I64,
Company, bankrupt_value ),
947 OCL_SVAR( OC_UINT16,
Company, bankrupt_timeout ),
952 OCL_CHUNK( 3, LoadOldCompanyYearly ),
953 OCL_CHUNK( 1, LoadOldCompanyEconomy ),
955 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32,
Company, inaugurated_year),
956 OCL_SVAR( OC_TILE,
Company, last_build_coordinate ),
957 OCL_SVAR( OC_UINT8,
Company, num_valid_stat_ent ),
961 OCL_SVAR( OC_UINT8,
Company, block_preview ),
964 OCL_SVAR( OC_TILE,
Company, location_of_HQ ),
979 if (!
LoadChunk(ls, c, _company_chunk))
return false;
981 if (_old_string_id == 0) {
994 if (_old_string_id == 0 || _old_string_id == 0x4C00) {
995 _old_string_id = STR_SV_UNNAMED;
996 }
else if (
GB(_old_string_id, 8, 8) == 0x52) {
997 _old_string_id += 0x2A00;
1001 c->
name_1 = _old_string_id;
1004 switch (_old_string_id_2) {
1005 case 0x4CDA: _old_string_id_2 = SPECSTR_PRESIDENT_NAME;
break;
1006 case 0x0006: _old_string_id_2 = STR_SV_EMPTY;
break;
1007 default: _old_string_id_2 = _old_string_id_2 + 0x2A00;
break;
1013 if (num != 0) c->
is_ai =
true;
1021 c->
name_1 = STR_SV_UNNAMED;
1043 static uint32_t _old_order_ptr;
1044 static uint16_t _old_next_ptr;
1047 static const OldChunks vehicle_train_chunk[] = {
1048 OCL_SVAR( OC_UINT8,
Train, track ),
1049 OCL_SVAR( OC_UINT8,
Train, force_proceed ),
1050 OCL_SVAR( OC_UINT16,
Train, crash_anim_pos ),
1051 OCL_SVAR( OC_UINT8,
Train, railtype ),
1058 static const OldChunks vehicle_road_chunk[] = {
1063 OCL_SVAR( OC_UINT8,
RoadVehicle, overtaking_ctr ),
1072 static const OldChunks vehicle_ship_chunk[] = {
1073 OCL_SVAR( OC_UINT8,
Ship, state ),
1080 static const OldChunks vehicle_air_chunk[] = {
1081 OCL_SVAR( OC_UINT8,
Aircraft, pos ),
1082 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Aircraft, targetairport ),
1083 OCL_SVAR( OC_UINT16,
Aircraft, crashed_counter ),
1084 OCL_SVAR( OC_UINT8,
Aircraft, state ),
1091 static const OldChunks vehicle_effect_chunk[] = {
1100 static const OldChunks vehicle_disaster_chunk[] = {
1109 static const OldChunks vehicle_empty_chunk[] = {
1118 uint temp = ls->total_read;
1122 res =
LoadChunk(ls,
nullptr, vehicle_empty_chunk);
1136 if (ls->total_read - temp != 10) {
1137 Debug(oldloader, 0,
"Assert failed in VehicleUnion: invalid chunk size");
1144 static uint16_t _cargo_count;
1146 static const OldChunks vehicle_chunk[] = {
1147 OCL_SVAR( OC_UINT8,
Vehicle, subtype ),
1152 OCL_VAR ( OC_UINT32, 1, &_old_order_ptr ),
1153 OCL_VAR ( OC_UINT16, 1, &_old_order ),
1156 OCL_SVAR( OC_UINT8,
Vehicle, cur_implicit_order_index ),
1157 OCL_SVAR( OC_TILE,
Vehicle, dest_tile ),
1158 OCL_SVAR( OC_UINT16,
Vehicle, load_unload_ticks ),
1159 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Vehicle, date_of_last_service ),
1160 OCL_SVAR( OC_UINT16,
Vehicle, service_interval ),
1161 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Vehicle, last_station_visited ),
1166 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32,
Vehicle, x_pos ),
1167 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32,
Vehicle, y_pos ),
1168 OCL_SVAR( OC_FILE_U8 | OC_VAR_I32,
Vehicle, z_pos ),
1169 OCL_SVAR( OC_UINT8,
Vehicle, direction ),
1174 OCL_SVAR( OC_UINT8,
Vehicle, owner ),
1175 OCL_SVAR( OC_TILE,
Vehicle, tile ),
1176 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Vehicle, sprite_cache.sprite_seq.seq[0].sprite ),
1180 OCL_SVAR( OC_FILE_U16 | OC_VAR_U8,
Vehicle, vehstatus ),
1182 OCL_SVAR(
OC_TTO | OC_FILE_U8 | OC_VAR_U16,
Vehicle, cur_speed ),
1183 OCL_SVAR( OC_UINT8,
Vehicle, subspeed ),
1184 OCL_SVAR( OC_UINT8,
Vehicle, acceleration ),
1185 OCL_SVAR( OC_UINT8,
Vehicle, progress ),
1187 OCL_SVAR( OC_UINT8,
Vehicle, cargo_type ),
1189 OCL_SVAR(
OC_TTO | OC_FILE_U8 | OC_VAR_U16,
Vehicle, cargo_cap ),
1190 OCL_VAR (
OC_TTD | OC_UINT16, 1, &_cargo_count ),
1191 OCL_VAR (
OC_TTO | OC_FILE_U8 | OC_VAR_U16, 1, &_cargo_count ),
1192 OCL_VAR ( OC_UINT8, 1, &_cargo_source ),
1193 OCL_VAR ( OC_UINT8, 1, &_cargo_periods ),
1197 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Vehicle, age ),
1198 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Vehicle, max_age ),
1199 OCL_SVAR( OC_FILE_U8 | OC_VAR_I32,
Vehicle, build_year ),
1200 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Vehicle, unitnumber ),
1203 OCL_SVAR(
OC_TTO | OC_FILE_U8 | OC_VAR_U16,
Vehicle, engine_type ),
1205 OCL_SVAR( OC_UINT8,
Vehicle, spritenum ),
1206 OCL_SVAR( OC_UINT8,
Vehicle, day_counter ),
1208 OCL_SVAR( OC_UINT8,
Vehicle, breakdowns_since_last_service ),
1209 OCL_SVAR( OC_UINT8,
Vehicle, breakdown_ctr ),
1210 OCL_SVAR( OC_UINT8,
Vehicle, breakdown_delay ),
1211 OCL_SVAR( OC_UINT8,
Vehicle, breakdown_chance ),
1215 OCL_SVAR( OC_UINT16,
Vehicle, reliability ),
1216 OCL_SVAR( OC_UINT16,
Vehicle, reliability_spd_dec ),
1218 OCL_SVAR( OC_FILE_I32 | OC_VAR_I64,
Vehicle, profit_this_year ),
1219 OCL_SVAR( OC_FILE_I32 | OC_VAR_I64,
Vehicle, profit_last_year ),
1221 OCL_VAR ( OC_UINT16, 1, &_old_next_ptr ),
1223 OCL_SVAR( OC_FILE_U32 | OC_VAR_I64,
Vehicle, value ),
1225 OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
1227 OCL_CHUNK( 1, LoadOldVehicleUnion ),
1244 ReadTTDPatchFlags();
1254 default:
return false;
1255 case 0x00 : v =
nullptr;
break;
1257 case 0x20 : v =
new (_current_vehicle_id)
Train();
break;
1258 case 0x21 : v =
new (_current_vehicle_id)
RoadVehicle();
break;
1259 case 0x22 : v =
new (_current_vehicle_id)
Ship();
break;
1260 case 0x23 : v =
new (_current_vehicle_id)
Aircraft();
break;
1261 case 0x24 : v =
new (_current_vehicle_id)
EffectVehicle();
break;
1265 if (!
LoadChunk(ls, v, vehicle_chunk))
return false;
1266 if (v ==
nullptr)
continue;
1284 static const byte spriteset_rail[] = {
1285 0, 2, 4, 4, 8, 10, 12, 14, 16, 18, 20, 22, 40, 42, 44, 46,
1286 48, 52, 54, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 120, 122,
1287 124, 126, 128, 130, 132, 134, 136, 138, 140
1319 switch (_old_string_id) {
1321 case 0x0006: _old_string_id = STR_SV_EMPTY;
break;
1322 case 0x8495: _old_string_id = STR_SV_TRAIN_NAME;
break;
1323 case 0x8842: _old_string_id = STR_SV_ROAD_VEHICLE_NAME;
break;
1324 case 0x8C3B: _old_string_id = STR_SV_SHIP_NAME;
break;
1325 case 0x9047: _old_string_id = STR_SV_AIRCRAFT_NAME;
break;
1326 default: _old_string_id += 0x2A00;
break;
1329 _old_vehicle_names[_current_vehicle_id] = _old_string_id;
1334 case 0x00 : v =
nullptr;
break;
1335 case 0x10 : v =
new (_current_vehicle_id)
Train();
break;
1336 case 0x11 : v =
new (_current_vehicle_id)
RoadVehicle();
break;
1337 case 0x12 : v =
new (_current_vehicle_id)
Ship();
break;
1338 case 0x13 : v =
new (_current_vehicle_id)
Aircraft();
break;
1339 case 0x14 : v =
new (_current_vehicle_id)
EffectVehicle();
break;
1343 if (!
LoadChunk(ls, v, vehicle_chunk))
return false;
1344 if (v ==
nullptr)
continue;
1346 _old_vehicle_names[_current_vehicle_id] =
RemapOldStringID(_old_string_id);
1349 if (v->
index != _current_vehicle_id) {
1350 Debug(oldloader, 0,
"Loading failed - vehicle-array is invalid");
1355 if (_old_order_ptr != 0 && _old_order_ptr != 0xFFFFFFFF) {
1357 uint old_id = RemapOrderIndex(_old_order_ptr);
1369 StationID source = (_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source;
1379 OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
1380 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32,
Sign, x ),
1381 OCL_SVAR( OC_FILE_U16 | OC_VAR_I32,
Sign, y ),
1382 OCL_SVAR( OC_FILE_U16 | OC_VAR_I8,
Sign, z ),
1392 if (!
LoadChunk(ls, si, sign_chunk))
return false;
1394 if (_old_string_id != 0) {
1396 if (_old_string_id != 0x140A) si->name =
CopyFromOldName(_old_string_id + 0x2A00);
1408 static const OldChunks engine_chunk[] = {
1409 OCL_SVAR( OC_UINT16,
Engine, company_avail ),
1410 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Engine, intro_date ),
1411 OCL_SVAR( OC_FILE_U16 | OC_VAR_U32,
Engine, age ),
1412 OCL_SVAR( OC_UINT16,
Engine, reliability ),
1413 OCL_SVAR( OC_UINT16,
Engine, reliability_spd_dec ),
1414 OCL_SVAR( OC_UINT16,
Engine, reliability_start ),
1415 OCL_SVAR( OC_UINT16,
Engine, reliability_max ),
1416 OCL_SVAR( OC_UINT16,
Engine, reliability_final ),
1417 OCL_SVAR( OC_UINT16,
Engine, duration_phase_1 ),
1418 OCL_SVAR( OC_UINT16,
Engine, duration_phase_2 ),
1419 OCL_SVAR( OC_UINT16,
Engine, duration_phase_3 ),
1422 OCL_SVAR( OC_UINT8,
Engine, flags ),
1424 OCL_SVAR( OC_UINT8,
Engine, preview_wait ),
1439 Engine *e = GetTempDataEngine(num);
1444 static const OldChunks subsidy_chunk[] = {
1445 OCL_SVAR( OC_UINT8,
Subsidy, cargo_type ),
1446 OCL_SVAR( OC_UINT8,
Subsidy, remaining ),
1447 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Subsidy, src ),
1448 OCL_SVAR( OC_FILE_U8 | OC_VAR_U16,
Subsidy, dst ),
1456 bool ret =
LoadChunk(ls, s, subsidy_chunk);
1461 static const OldChunks game_difficulty_chunk[] = {
1510 for (
auto it = range.begin(); it != range.end(); ) {
1512 for (
int i = 0; i < 8; i += 2, ++it) (*it).m6() =
GB(b, i, 2);
1533 ReadTTDPatchFlags();
1538 uint16_t
id = ReadUint16(ls);
1539 uint32_t len = ReadUint32(ls);
1547 ReadUint32(ls);
ReadByte(ls); len -= 5;
1551 uint32_t grfid = ReadUint32(ls);
1571 Debug(oldloader, 3,
"Game saved with TTDPatch version {}.{}.{} r{}",
1572 GB(
_ttdp_version, 24, 8),
GB(
_ttdp_version, 20, 4),
GB(
_ttdp_version, 16, 4),
GB(
_ttdp_version, 0, 16));
1578 Debug(oldloader, 4,
"Skipping unknown extra chunk {}",
id);
1591 extern uint8_t _old_diff_level;
1592 extern uint8_t _old_units;
1601 OCL_ASSERT(
OC_TTD, 0x264 ),
1602 OCL_ASSERT(
OC_TTO, 0x264 ),
1604 OCL_CCHUNK(
OC_TTD, 70, LoadOldTown ),
1605 OCL_CCHUNK(
OC_TTO, 80, LoadOldTown ),
1607 OCL_ASSERT(
OC_TTD, 0x1C18 ),
1608 OCL_ASSERT(
OC_TTO, 0x1AC4 ),
1610 OCL_CCHUNK(
OC_TTD, 5000, LoadOldOrder ),
1611 OCL_CCHUNK(
OC_TTO, 3000, LoadOldOrder ),
1613 OCL_ASSERT(
OC_TTD, 0x4328 ),
1614 OCL_ASSERT(
OC_TTO, 0x3234 ),
1616 OCL_CHUNK( 1, LoadOldAnimTileList ),
1619 OCL_ASSERT(
OC_TTO, 0x3438 ),
1621 OCL_CCHUNK(
OC_TTD, 255, LoadOldDepot ),
1622 OCL_CCHUNK(
OC_TTO, 252, LoadOldDepot ),
1624 OCL_ASSERT(
OC_TTD, 0x4B26 ),
1625 OCL_ASSERT(
OC_TTO, 0x3A20 ),
1633 OCL_VAR ( OC_TILE, 1, &_cur_tileloop_tile ),
1635 OCL_ASSERT(
OC_TTO, 0x3A2E ),
1637 OCL_CNULL(
OC_TTO, 48 * 6 ),
1638 OCL_CNULL(
OC_TTD, 49 * 6 ),
1640 OCL_ASSERT(
OC_TTO, 0x3B4E ),
1642 OCL_CNULL(
OC_TTO, 11 * 8 ),
1643 OCL_CNULL(
OC_TTD, 12 * 8 ),
1645 OCL_ASSERT(
OC_TTD, 0x4CBA ),
1646 OCL_ASSERT(
OC_TTO, 0x3BA6 ),
1648 OCL_CHUNK( 1, LoadOldMapPart1 ),
1650 OCL_ASSERT(
OC_TTD, 0x48CBA ),
1651 OCL_ASSERT(
OC_TTO, 0x23BA6 ),
1653 OCL_CCHUNK(
OC_TTD, 250, LoadOldStation ),
1654 OCL_CCHUNK(
OC_TTO, 200, LoadOldStation ),
1656 OCL_ASSERT(
OC_TTO, 0x29E16 ),
1658 OCL_CCHUNK(
OC_TTD, 90, LoadOldIndustry ),
1659 OCL_CCHUNK(
OC_TTO, 100, LoadOldIndustry ),
1661 OCL_ASSERT(
OC_TTO, 0x2ADB6 ),
1663 OCL_CHUNK( 8, LoadOldCompany ),
1665 OCL_ASSERT(
OC_TTD, 0x547F2 ),
1666 OCL_ASSERT(
OC_TTO, 0x2C746 ),
1671 OCL_ASSERT(
OC_TTD, 0x6F0F2 ),
1672 OCL_ASSERT(
OC_TTO, 0x45746 ),
1677 OCL_ASSERT(
OC_TTO, 0x46A06 ),
1681 OCL_CHUNK( 40, LoadOldSign ),
1683 OCL_ASSERT(
OC_TTO, 0x48C36 ),
1685 OCL_CCHUNK(
OC_TTD, 256, LoadOldEngine ),
1686 OCL_CCHUNK(
OC_TTO, 103, LoadOldEngine ),
1688 OCL_ASSERT(
OC_TTO, 0x496AC ),
1692 OCL_CHUNK( 8, LoadOldSubsidy ),
1694 OCL_ASSERT(
OC_TTO, 0x496CE ),
1700 OCL_VAR ( OC_FILE_I16 | OC_VAR_I32, 1, &_saved_scrollpos_x ),
1701 OCL_VAR ( OC_FILE_I16 | OC_VAR_I32, 1, &_saved_scrollpos_y ),
1702 OCL_VAR ( OC_FILE_U16 | OC_VAR_U8, 1, &_saved_scrollpos_zoom ),
1706 OCL_VAR ( OC_INT16, 1, &_economy.
fluct ),
1710 OCL_ASSERT(
OC_TTO, 0x496E4 ),
1712 OCL_CNULL(
OC_TTD, 144 ),
1714 OCL_CCHUNK(
OC_TTD, 256, LoadOldEngineName ),
1716 OCL_CNULL(
OC_TTD, 144 ),
1721 OCL_VAR ( OC_UINT8, 1, &_old_units ),
1734 OCL_CHUNK( 1, LoadOldGameDifficulty ),
1736 OCL_ASSERT(
OC_TTD, 0x77130 ),
1738 OCL_VAR ( OC_UINT8, 1, &_old_diff_level ),
1749 OCL_ASSERT(
OC_TTD, 0x77179 ),
1750 OCL_ASSERT(
OC_TTO, 0x4971D ),
1752 OCL_CHUNK( 1, LoadOldMapPart2 ),
1754 OCL_ASSERT(
OC_TTD, 0x97179 ),
1755 OCL_ASSERT(
OC_TTO, 0x6971D ),
1758 OCL_CHUNK(1, LoadTTDPatchExtraChunks),
1765 Debug(oldloader, 3,
"Reading main chunk...");
1770 _old_vehicle_names =
nullptr;
1772 if (!
LoadChunk(ls,
nullptr, main_chunk)) {
1773 Debug(oldloader, 0,
"Loading failed");
1774 free(_old_vehicle_names);
1778 free(_old_vehicle_names);
1782 Debug(oldloader, 3,
"Done, converting game data...");
1797 Debug(oldloader, 3,
"Finished converting game data");
1798 Debug(oldloader, 1,
"TTD(Patch) savegame successfully converted");
1800 free(_old_vehicle_names);
1807 Debug(oldloader, 3,
"Reading main chunk...");
1811 std::array<byte, 103 *
sizeof(
Engine)> engines;
1812 _old_engines = (
Engine *)engines.data();
1813 std::array<StringID, 800> vehnames;
1814 _old_vehicle_names = vehnames.data();
1817 if (!
LoadChunk(ls,
nullptr, main_chunk)) {
1818 Debug(oldloader, 0,
"Loading failed");
1821 Debug(oldloader, 3,
"Done, converting game data...");
1829 Debug(oldloader, 0,
"Conversion failed");
1846 Debug(oldloader, 3,
"Finished converting game data");
1847 Debug(oldloader, 1,
"TTO savegame successfully converted");