OpenTTD Source  14.0-beta1
oldloader_sl.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "../stdafx.h"
11 #include "../town.h"
12 #include "../industry.h"
13 #include "../company_func.h"
14 #include "../aircraft.h"
15 #include "../roadveh.h"
16 #include "../ship.h"
17 #include "../train.h"
18 #include "../signs_base.h"
19 #include "../station_base.h"
20 #include "../subsidy_base.h"
21 #include "../debug.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"
33 #include "saveload_internal.h"
34 #include "oldloader.h"
35 
36 #include "table/strings.h"
37 #include "../table/engines.h"
38 #include "../table/townname.h"
39 
40 #include "../safeguards.h"
41 
42 static bool _read_ttdpatch_flags;
43 static uint16_t _old_extra_chunk_nums;
45 
46 void FixOldMapArray()
47 {
48  /* TTO/TTD/TTDP savegames could have buoys at tile 0
49  * (without assigned station struct) */
50  MakeSea(0);
51 }
52 
53 static void FixTTDMapArray()
54 {
55  for (auto tile : Map::Iterate()) {
56  switch (GetTileType(tile)) {
57  case MP_STATION:
58  tile.m4() = 0; // We do not understand this TTDP station mapping (yet)
59  switch (tile.m5()) {
60  /* We have drive through stops at a totally different place */
61  case 0x53: case 0x54: tile.m5() += 170 - 0x53; break; // Bus drive through
62  case 0x57: case 0x58: tile.m5() += 168 - 0x57; break; // Truck drive through
63  case 0x55: case 0x56: tile.m5() += 170 - 0x55; break; // Bus tram stop
64  case 0x59: case 0x5A: tile.m5() += 168 - 0x59; break; // Truck tram stop
65  default: break;
66  }
67  break;
68 
69  case MP_RAILWAY:
70  /* We save presignals different from TTDPatch, convert them */
71  if (GB(tile.m5(), 6, 2) == 1) { // RAIL_TILE_SIGNALS
72  /* This byte is always zero in TTD for this type of tile */
73  if (tile.m4()) { // Convert the presignals to our own format
74  tile.m4() = (tile.m4() >> 1) & 7;
75  }
76  }
77  /* TTDPatch stores PBS things in L6 and all elsewhere; so we'll just
78  * clear it for ourselves and let OTTD's rebuild PBS itself */
79  tile.m4() &= 0xF; // Only keep the lower four bits; upper four is PBS
80  break;
81 
82  case MP_WATER:
83  /* if water class == 3, make river there */
84  if (GB(tile.m3(), 0, 2) == 3) {
85  SetTileType(tile, MP_WATER);
87  tile.m2() = 0;
88  tile.m3() = 2; // WATER_CLASS_RIVER
89  tile.m4() = Random();
90  tile.m5() = 0;
91  }
92  break;
93 
94  default:
95  break;
96  }
97  }
98 
99  FixOldMapArray();
100 }
101 
102 static void FixTTDDepots()
103 {
104  for (const Depot *d : Depot::Iterate(252)) {
105  if (!IsDepotTile(d->xy) || GetDepotIndex(d->xy) != d->index) {
107  delete d;
108  }
109  }
110 }
111 
112 #define FIXNUM(x, y, z) (((((x) << 16) / (y)) + 1) << z)
113 
114 static uint32_t RemapOldTownName(uint32_t townnameparts, byte old_town_name_type)
115 {
116  switch (old_town_name_type) {
117  case 0: case 3: // English, American
118  /* Already OK */
119  return townnameparts;
120 
121  case 1: // French
122  /* For some reason 86 needs to be subtracted from townnameparts
123  * 0000 0000 0000 0000 0000 0000 1111 1111 */
124  return FIXNUM(townnameparts - 86, lengthof(_name_french_real), 0);
125 
126  case 2: // German
127  Debug(misc, 0, "German Townnames are buggy ({})", townnameparts);
128  return townnameparts;
129 
130  case 4: // Latin-American
131  /* 0000 0000 0000 0000 0000 0000 1111 1111 */
132  return FIXNUM(townnameparts, lengthof(_name_spanish_real), 0);
133 
134  case 5: // Silly
135  /* NUM_SILLY_1 - lower 16 bits
136  * NUM_SILLY_2 - upper 16 bits without leading 1 (first 8 bytes)
137  * 1000 0000 2222 2222 0000 0000 1111 1111 */
138  return FIXNUM(townnameparts, lengthof(_name_silly_1), 0) | FIXNUM(GB(townnameparts, 16, 8), lengthof(_name_silly_2), 16);
139  }
140  return 0;
141 }
142 
143 #undef FIXNUM
144 
145 static void FixOldTowns()
146 {
147  /* Convert town-names if needed */
148  for (Town *town : Town::Iterate()) {
149  if (IsInsideMM(town->townnametype, 0x20C1, 0x20C3)) {
150  town->townnametype = SPECSTR_TOWNNAME_ENGLISH + _settings_game.game_creation.town_name;
151  town->townnameparts = RemapOldTownName(town->townnameparts, _settings_game.game_creation.town_name);
152  }
153  }
154 }
155 
156 static StringID *_old_vehicle_names;
157 
164 {
165  for (Vehicle *v : Vehicle::Iterate()) {
166  if ((size_t)v->next == 0xFFFF) {
167  v->next = nullptr;
168  } else {
169  v->next = Vehicle::GetIfValid((size_t)v->next);
170  }
171 
172  /* For some reason we need to correct for this */
173  switch (v->spritenum) {
174  case 0xfd: break;
175  case 0xff: v->spritenum = 0xfe; break;
176  default: v->spritenum >>= 1; break;
177  }
178 
179  /* Vehicle-subtype is different in TTD(Patch) */
180  if (v->type == VEH_EFFECT) v->subtype = v->subtype >> 1;
181 
182  v->name = CopyFromOldName(_old_vehicle_names[v->index]);
183 
184  /* We haven't used this bit for stations for ages */
185  if (v->type == VEH_ROAD) {
187  if (rv->state != RVSB_IN_DEPOT && rv->state != RVSB_WORMHOLE) {
188  ClrBit(rv->state, 2);
189  Tile tile(rv->tile);
190  if (IsTileType(tile, MP_STATION) && tile.m5() >= 168) {
191  /* Update the vehicle's road state to show we're in a drive through road stop. */
193  }
194  }
195  }
196 
197  /* The subtype should be 0, but it sometimes isn't :( */
198  if (v->type == VEH_ROAD || v->type == VEH_SHIP) v->subtype = 0;
199 
200  /* Sometimes primary vehicles would have a nothing (invalid) order
201  * or vehicles that could not have an order would still have a
202  * (loading) order which causes assertions and the like later on.
203  */
205  (v->IsPrimaryVehicle() && v->current_order.IsType(OT_NOTHING))) {
206  v->current_order.MakeDummy();
207  }
208 
209  /* Shared orders are fixed in AfterLoadVehicles now */
210  }
211 }
212 
213 static bool FixTTOMapArray()
214 {
215  for (auto tile : Map::Iterate()) {
216  TileType tt = GetTileType(tile);
217  if (tt == 11) {
218  /* TTO has a different way of storing monorail.
219  * Instead of using bits in m3 it uses a different tile type. */
220  tile.m3() = 1; // rail type = monorail (in TTD)
221  SetTileType(tile, MP_RAILWAY);
222  tile.m2() = 1; // set monorail ground to RAIL_GROUND_GRASS
223  tt = MP_RAILWAY;
224  }
225 
226  switch (tt) {
227  case MP_CLEAR:
228  break;
229 
230  case MP_RAILWAY:
231  switch (GB(tile.m5(), 6, 2)) {
232  case 0: // RAIL_TILE_NORMAL
233  break;
234  case 1: // RAIL_TILE_SIGNALS
235  tile.m4() = (~tile.m5() & 1) << 2; // signal variant (present only in OTTD)
236  SB(tile.m2(), 6, 2, GB(tile.m5(), 3, 2)); // signal status
237  tile.m3() |= 0xC0; // both signals are present
238  tile.m5() = HasBit(tile.m5(), 5) ? 2 : 1; // track direction (only X or Y)
239  tile.m5() |= 0x40; // RAIL_TILE_SIGNALS
240  break;
241  case 3: // RAIL_TILE_DEPOT
242  tile.m2() = 0;
243  break;
244  default:
245  return false;
246  }
247  break;
248 
249  case MP_ROAD: // road (depot) or level crossing
250  switch (GB(tile.m5(), 4, 4)) {
251  case 0: // ROAD_TILE_NORMAL
252  if (tile.m2() == 4) tile.m2() = 5; // 'small trees' -> ROADSIDE_TREES
253  break;
254  case 1: // ROAD_TILE_CROSSING (there aren't monorail crossings in TTO)
255  tile.m3() = tile.m1(); // set owner of road = owner of rail
256  break;
257  case 2: // ROAD_TILE_DEPOT
258  break;
259  default:
260  return false;
261  }
262  break;
263 
264  case MP_HOUSE:
265  tile.m3() = tile.m2() & 0xC0; // construction stage
266  tile.m2() &= 0x3F; // building type
267  if (tile.m2() >= 5) tile.m2()++; // skip "large office block on snow"
268  break;
269 
270  case MP_TREES:
271  tile.m3() = GB(tile.m5(), 3, 3); // type of trees
272  tile.m5() &= 0xC7; // number of trees and growth status
273  break;
274 
275  case MP_STATION:
276  tile.m3() = (tile.m5() >= 0x08 && tile.m5() <= 0x0F) ? 1 : 0; // monorail -> 1, others 0 (rail, road, airport, dock)
277  if (tile.m5() >= 8) tile.m5() -= 8; // shift for monorail
278  if (tile.m5() >= 0x42) tile.m5()++; // skip heliport
279  break;
280 
281  case MP_WATER:
282  tile.m3() = tile.m2() = 0;
283  break;
284 
285  case MP_VOID:
286  tile.m2() = tile.m3() = tile.m5() = 0;
287  break;
288 
289  case MP_INDUSTRY:
290  tile.m3() = 0;
291  switch (tile.m5()) {
292  case 0x24: // farm silo
293  tile.m5() = 0x25;
294  break;
295  case 0x25: case 0x27: // farm
296  case 0x28: case 0x29: case 0x2A: case 0x2B: // factory
297  tile.m5()--;
298  break;
299  default:
300  if (tile.m5() >= 0x2C) tile.m5() += 3; // iron ore mine, steel mill or bank
301  break;
302  }
303  break;
304 
305  case MP_TUNNELBRIDGE:
306  if (HasBit(tile.m5(), 7)) { // bridge
307  byte m5 = tile.m5();
308  tile.m5() = m5 & 0xE1; // copy bits 7..5, 1
309  if (GB(m5, 1, 2) == 1) tile.m5() |= 0x02; // road bridge
310  if (GB(m5, 1, 2) == 3) tile.m2() |= 0xA0; // monorail bridge -> tubular, steel bridge
311  if (!HasBit(m5, 6)) { // bridge head
312  tile.m3() = (GB(m5, 1, 2) == 3) ? 1 : 0; // track subtype (1 for monorail, 0 for others)
313  } else { // middle bridge part
314  tile.m3() = HasBit(m5, 2) ? 0x10 : 0; // track subtype on bridge
315  if (GB(m5, 3, 2) == 3) tile.m3() |= 1; // track subtype under bridge
316  if (GB(m5, 3, 2) == 1) tile.m5() |= 0x08; // set for road/water under (0 for rail/clear)
317  }
318  } else { // tunnel entrance/exit
319  tile.m2() = 0;
320  tile.m3() = HasBit(tile.m5(), 3); // monorail
321  tile.m5() &= HasBit(tile.m5(), 3) ? 0x03 : 0x07 ; // direction, transport type (== 0 for rail)
322  }
323  break;
324 
325  case MP_OBJECT:
326  tile.m2() = 0;
327  tile.m3() = 0;
328  break;
329 
330  default:
331  return false;
332 
333  }
334  }
335 
336  FixOldMapArray();
337 
338  return true;
339 }
340 
341 static Engine *_old_engines;
342 
343 static bool FixTTOEngines()
344 {
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
363  };
364 
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
374  };
375 
376  for (Vehicle *v : Vehicle::Iterate()) {
377  if (v->engine_type >= lengthof(tto_to_ttd)) return false;
378  v->engine_type = tto_to_ttd[v->engine_type];
379  }
380 
381  /* Load the default engine set. Many of them will be overridden later */
382  {
383  uint j = 0;
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);
387  for (uint i = 0; i < lengthof(_orig_aircraft_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_AIRCRAFT, i);
388  }
389 
390  TimerGameCalendar::Date aging_date = std::min(TimerGameCalendar::date + CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR, TimerGameCalendar::ConvertYMDToDate(2050, 0, 1));
391  TimerGameCalendar::YearMonthDay aging_ymd = TimerGameCalendar::ConvertDateToYMD(aging_date);
392 
393  for (EngineID i = 0; i < 256; i++) {
394  int oi = ttd_to_tto[i];
395  Engine *e = GetTempDataEngine(i);
396 
397  if (oi == 255) {
398  /* Default engine is used */
400  StartupOneEngine(e, aging_ymd, 0);
401  CalcEngineReliability(e, false);
404 
405  /* Make sure for example monorail and maglev are available when they should be */
406  if (TimerGameCalendar::date >= e->intro_date && HasBit(e->info.climates, 0)) {
407  e->flags |= ENGINE_AVAILABLE;
408  e->company_avail = MAX_UVALUE(CompanyMask);
409  e->age = TimerGameCalendar::date > e->intro_date ? (TimerGameCalendar::date - e->intro_date).base() / 30 : 0;
410  }
411  } else {
412  /* Using data from TTO savegame */
413  Engine *oe = &_old_engines[oi];
414 
415  e->intro_date = oe->intro_date;
416  e->age = oe->age;
417  e->reliability = oe->reliability;
425  e->flags = oe->flags;
426 
427  e->company_avail = 0;
428 
429  /* One or more engines were remapped to this one. Make this engine available
430  * if at least one of them was available. */
431  for (uint j = 0; j < lengthof(tto_to_ttd); j++) {
432  if (tto_to_ttd[j] == i && _old_engines[j].company_avail != 0) {
433  e->company_avail = MAX_UVALUE(CompanyMask);
434  e->flags |= ENGINE_AVAILABLE;
435  break;
436  }
437  }
438 
439  e->info.climates = 1;
440  }
441 
443  e->preview_asked = MAX_UVALUE(CompanyMask);
444  e->preview_wait = 0;
445  e->name = std::string{};
446  }
447 
448  return true;
449 }
450 
451 static void FixTTOCompanies()
452 {
453  for (Company *c : Company::Iterate()) {
454  c->cur_economy.company_value = CalculateCompanyValue(c); // company value history is zeroed
455  }
456 }
457 
458 static inline Colours RemapTTOColour(Colours tto)
459 {
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
466  };
467 
468  if ((size_t)tto >= lengthof(tto_colour_remap)) return COLOUR_GREY; // this shouldn't happen
469 
470  return tto_colour_remap[tto];
471 }
472 
473 static inline uint RemapTownIndex(uint x)
474 {
475  return _savegame_type == SGT_TTO ? (x - 0x264) / 78 : (x - 0x264) / 94;
476 }
477 
478 static inline uint RemapOrderIndex(uint x)
479 {
480  return _savegame_type == SGT_TTO ? (x - 0x1AC4) / 2 : (x - 0x1C18) / 2;
481 }
482 
483 extern std::vector<TileIndex> _animated_tiles;
485 extern char *_old_name_array;
486 
487 static uint32_t _old_town_index;
488 static uint16_t _old_string_id;
489 static uint16_t _old_string_id_2;
490 
491 static void ClearOldMap3(TileIndex t)
492 {
493  Tile tile(t);
494  tile.m3() = 0;
495  tile.m4() = 0;
496 }
497 
498 static Town *RemapTown(TileIndex fallback)
499 {
500  /* In some cases depots, industries and stations could refer to a missing town. */
501  Town *t = Town::GetIfValid(RemapTownIndex(_old_town_index));
502  if (t == nullptr) {
503  /* In case the town that was refered to does not exist, find the closest.
504  * However, this needs the kd-tree to be present. */
505  RebuildTownKdtree();
506  t = CalcClosestTownFromTile(fallback);
507  }
508  return t;
509 }
510 
511 static void ReadTTDPatchFlags()
512 {
513  if (_read_ttdpatch_flags) return;
514 
515  _read_ttdpatch_flags = true;
516 
517  /* Set default values */
519  _ttdp_version = 0;
521  _bump_assert_value = 0;
522 
523  if (_savegame_type == SGT_TTO) return;
524 
525  /* TTDPatch misuses old map3 (now m3/m4) for flags.. read them! */
527  /* Somehow.... there was an error in some savegames, so 0 becomes 1
528  * and 1 becomes 2. The rest of the values are okay */
530 
531  _old_vehicle_names = MallocT<StringID>(_old_vehicle_multiplier * 850);
532 
533  /* TTDPatch increases the Vehicle-part in the middle of the game,
534  * so if the multiplier is anything else but 1, the assert fails..
535  * bump the assert value so it doesn't!
536  * (1 multiplier == 850 vehicles
537  * 1 vehicle == 128 bytes */
538  _bump_assert_value = (_old_vehicle_multiplier - 1) * 850 * 128;
539 
540  /* The first 17 bytes are used by TTDP1, which translates to the first 9 m3s and first 8 m4s. */
541  for (TileIndex i = 0; i <= 8; i++) { // check tile 0, too
542  Tile tile(i);
543  if (tile.m3() != 0 || (i != 8 && tile.m4() != 0)) _savegame_type = SGT_TTDP1;
544  }
545 
546  /* Check if we have a modern TTDPatch savegame (has extra data all around) */
547  Tile ttdp2_header_first(Map::Size() - 3);
548  Tile ttdp2_header_second(Map::Size() - 2);
549  if (ttdp2_header_first.m3() == 'T' && ttdp2_header_first.m4() == 'T' &&
550  ttdp2_header_second.m3() == 'D' && ttdp2_header_second.m4() == 'p') {
552  }
553 
554  Tile extra_chunk_tile = Tile(_savegame_type == SGT_TTDP2 ? Map::Size() - 1 : 1);
555  _old_extra_chunk_nums = extra_chunk_tile.m3() | extra_chunk_tile.m4() << 8;
556 
557  /* Clean the misused places */
558  for (TileIndex i = 0; i < 9; i++) ClearOldMap3(i);
559  for (TileIndex i = TileXY(0, Map::MaxY()); i < Map::Size(); i++) ClearOldMap3(i);
560 
561  if (_savegame_type == SGT_TTDP2) Debug(oldloader, 2, "Found TTDPatch game");
562 
563  Debug(oldloader, 3, "Vehicle-multiplier is set to {} ({} vehicles)", _old_vehicle_multiplier, _old_vehicle_multiplier * 850);
564 }
565 
566 static const OldChunks town_chunk[] = {
567  OCL_SVAR( OC_TILE, Town, xy ),
568  OCL_NULL( 2 ),
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 ),
572  OCL_NULL( 1 ),
573  OCL_NULL( 4 ),
574  OCL_NULL( 2 ),
575  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, Town, flags ),
576  OCL_NULL( 10 ),
577 
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] ),
586 
587  OCL_SVAR( OC_FILE_U32 | OC_VAR_U16, Town, have_ratings ),
588  OCL_SVAR( OC_FILE_U32 | OC_VAR_U16, Town, statues ),
589  OCL_NULL( 2 ),
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 ),
592 
593  OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Town, supplied[CT_PASSENGERS].new_max ),
594  OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Town, supplied[CT_MAIL].new_max ),
595  OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Town, supplied[CT_PASSENGERS].new_act ),
596  OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Town, supplied[CT_MAIL].new_act ),
597  OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Town, supplied[CT_PASSENGERS].old_max ),
598  OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Town, supplied[CT_MAIL].old_max ),
599  OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Town, supplied[CT_PASSENGERS].old_act ),
600  OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Town, supplied[CT_MAIL].old_act ),
601 
602  OCL_NULL( 2 ),
603 
604  OCL_SVAR( OC_TTD | OC_UINT16, Town, received[TAE_FOOD].new_act ),
605  OCL_SVAR( OC_TTD | OC_UINT16, Town, received[TAE_WATER].new_act ),
606  OCL_SVAR( OC_TTD | OC_UINT16, Town, received[TAE_FOOD].old_act ),
607  OCL_SVAR( OC_TTD | OC_UINT16, Town, received[TAE_WATER].old_act ),
608 
609  OCL_SVAR( OC_UINT8, Town, road_build_months ),
610  OCL_SVAR( OC_UINT8, Town, fund_buildings_months ),
611 
612  OCL_CNULL( OC_TTD, 8 ),
613 
614  OCL_END()
615 };
616 
617 static bool LoadOldTown(LoadgameState *ls, int num)
618 {
619  Town *t = new (num) Town();
620  if (!LoadChunk(ls, t, town_chunk)) return false;
621 
622  if (t->xy != 0) {
623  if (_savegame_type == SGT_TTO) {
624  /* 0x10B6 is auto-generated name, others are custom names */
625  t->townnametype = t->townnametype == 0x10B6 ? 0x20C1 : t->townnametype + 0x2A00;
626  }
627  } else {
628  delete t;
629  }
630 
631  return true;
632 }
633 
634 static uint16_t _old_order;
635 static const OldChunks order_chunk[] = {
636  OCL_VAR ( OC_UINT16, 1, &_old_order ),
637  OCL_END()
638 };
639 
640 static bool LoadOldOrder(LoadgameState *ls, int num)
641 {
642  if (!LoadChunk(ls, nullptr, order_chunk)) return false;
643 
644  Order *o = new (num) Order();
645  o->AssignOrder(UnpackOldOrder(_old_order));
646 
647  if (o->IsType(OT_NOTHING)) {
648  delete o;
649  } else {
650  /* Relink the orders to each other (in the orders for one vehicle are behind each other,
651  * with an invalid order (OT_NOTHING) as indication that it is the last order */
652  Order *prev = Order::GetIfValid(num - 1);
653  if (prev != nullptr) prev->next = o;
654  }
655 
656  return true;
657 }
658 
659 static bool LoadOldAnimTileList(LoadgameState *ls, int)
660 {
661  TileIndex anim_list[256];
662  const OldChunks anim_chunk[] = {
663  OCL_VAR ( OC_TILE, 256, anim_list ),
664  OCL_END ()
665  };
666 
667  if (!LoadChunk(ls, nullptr, anim_chunk)) return false;
668 
669  /* The first zero in the loaded array indicates the end of the list. */
670  for (int i = 0; i < 256; i++) {
671  if (anim_list[i] == 0) break;
672  _animated_tiles.push_back(anim_list[i]);
673  }
674 
675  return true;
676 }
677 
678 static const OldChunks depot_chunk[] = {
679  OCL_SVAR( OC_TILE, Depot, xy ),
680  OCL_VAR ( OC_UINT32, 1, &_old_town_index ),
681  OCL_END()
682 };
683 
684 static bool LoadOldDepot(LoadgameState *ls, int num)
685 {
686  Depot *d = new (num) Depot();
687  if (!LoadChunk(ls, d, depot_chunk)) return false;
688 
689  if (d->xy != 0) {
690  d->town = RemapTown(d->xy);
691  } else {
692  delete d;
693  }
694 
695  return true;
696 }
697 
698 static StationID _current_station_id;
699 static uint16_t _waiting_acceptance;
700 static uint8_t _cargo_source;
701 static uint8_t _cargo_periods;
702 
703 static const OldChunks goods_chunk[] = {
704  OCL_VAR ( OC_UINT16, 1, &_waiting_acceptance ),
705  OCL_SVAR( OC_UINT8, GoodsEntry, time_since_pickup ),
706  OCL_SVAR( OC_UINT8, GoodsEntry, rating ),
707  OCL_VAR ( OC_UINT8, 1, &_cargo_source ),
708  OCL_VAR ( OC_UINT8, 1, &_cargo_periods ),
709  OCL_SVAR( OC_UINT8, GoodsEntry, last_speed ),
710  OCL_SVAR( OC_UINT8, GoodsEntry, last_age ),
711 
712  OCL_END()
713 };
714 
715 static bool LoadOldGood(LoadgameState *ls, int num)
716 {
717  /* for TTO games, 12th (num == 11) goods entry is created in the Station constructor */
718  if (_savegame_type == SGT_TTO && num == 11) return true;
719 
720  Station *st = Station::Get(_current_station_id);
721  GoodsEntry *ge = &st->goods[num];
722 
723  if (!LoadChunk(ls, ge, goods_chunk)) return false;
724 
725  SB(ge->status, GoodsEntry::GES_ACCEPTANCE, 1, HasBit(_waiting_acceptance, 15));
726  SB(ge->status, GoodsEntry::GES_RATING, 1, _cargo_source != 0xFF);
727  if (GB(_waiting_acceptance, 0, 12) != 0 && CargoPacket::CanAllocateItem()) {
728  ge->cargo.Append(new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_periods, (_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source, INVALID_TILE, 0),
729  INVALID_STATION);
730  }
731 
732  return true;
733 }
734 
735 static const OldChunks station_chunk[] = {
736  OCL_SVAR( OC_TILE, Station, xy ),
737  OCL_VAR ( OC_UINT32, 1, &_old_town_index ),
738 
739  OCL_NULL( 4 ),
740  OCL_SVAR( OC_TILE, Station, train_station.tile ),
741  OCL_SVAR( OC_TILE, Station, airport.tile ),
742  OCL_NULL( 2 ),
743  OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Station, train_station.w ),
744 
745  OCL_NULL( 1 ),
746  OCL_NULL( 2 ),
747 
748  OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
749 
750  OCL_NULL( 4 ),
751 
752  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, Station, had_vehicle_of_type ),
753 
754  OCL_CHUNK( 12, LoadOldGood ),
755 
756  OCL_SVAR( OC_UINT8, Station, time_since_load ),
757  OCL_SVAR( OC_UINT8, Station, time_since_unload ),
758  OCL_SVAR( OC_UINT8, Station, delete_ctr ),
759  OCL_SVAR( OC_UINT8, Station, owner ),
760  OCL_SVAR( OC_UINT8, Station, facilities ),
761  OCL_SVAR( OC_TTD | OC_UINT8, Station, airport.type ),
762  OCL_SVAR( OC_TTO | OC_FILE_U16 | OC_VAR_U64, Station, airport.flags ),
763  OCL_NULL( 3 ),
764  OCL_CNULL( OC_TTD, 1 ),
765  OCL_SVAR( OC_TTD | OC_FILE_U16 | OC_VAR_U64, Station, airport.flags ),
766  OCL_CNULL( OC_TTD, 2 ),
767  OCL_CNULL( OC_TTD, 4 ),
768 
769  OCL_END()
770 };
771 
772 static bool LoadOldStation(LoadgameState *ls, int num)
773 {
774  Station *st = new (num) Station();
775  _current_station_id = num;
776 
777  if (!LoadChunk(ls, st, station_chunk)) return false;
778 
779  if (st->xy != 0) {
780  st->town = RemapTown(st->xy);
781 
782  if (_savegame_type == SGT_TTO) {
783  if (IsInsideBS(_old_string_id, 0x180F, 32)) {
784  st->string_id = STR_SV_STNAME + (_old_string_id - 0x180F); // automatic name
785  } else {
786  st->string_id = _old_string_id + 0x2800; // custom name
787  }
788 
789  if (HasBit(st->airport.flags, 8)) {
790  st->airport.type = 1; // large airport
791  } else if (HasBit(st->airport.flags, 6)) {
792  st->airport.type = 3; // oil rig
793  } else {
794  st->airport.type = 0; // small airport
795  }
796  } else {
797  st->string_id = RemapOldStringID(_old_string_id);
798  }
799  } else {
800  delete st;
801  }
802 
803  return true;
804 }
805 
806 static const OldChunks industry_chunk[] = {
807  OCL_SVAR( OC_TILE, Industry, location.tile ),
808  OCL_VAR ( OC_UINT32, 1, &_old_town_index ),
809  OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Industry, location.w ),
810  OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Industry, location.h ),
811  OCL_NULL( 2 ),
812 
813  OCL_SVAR( OC_TTD | OC_UINT16, Industry, produced[0].waiting ),
814  OCL_SVAR( OC_TTD | OC_UINT16, Industry, produced[1].waiting ),
815  OCL_SVAR( OC_TTO | OC_FILE_U8 | OC_VAR_U16, Industry, produced[0].waiting ),
816  OCL_SVAR( OC_TTO | OC_FILE_U8 | OC_VAR_U16, Industry, produced[1].waiting ),
817 
818  OCL_SVAR( OC_UINT8, Industry, produced[0].rate ),
819  OCL_SVAR( OC_UINT8, Industry, produced[1].rate ),
820 
821  OCL_NULL( 3 ),
822 
823  OCL_SVAR( OC_UINT8, Industry, prod_level ),
824 
825  OCL_SVAR( OC_UINT16, Industry, produced[0].history[THIS_MONTH].production ),
826  OCL_SVAR( OC_UINT16, Industry, produced[1].history[THIS_MONTH].production ),
827  OCL_SVAR( OC_UINT16, Industry, produced[0].history[THIS_MONTH].transported ),
828  OCL_SVAR( OC_UINT16, Industry, produced[1].history[THIS_MONTH].transported ),
829 
830  OCL_NULL( 2 ),
831 
832  OCL_SVAR( OC_UINT16, Industry, produced[0].history[LAST_MONTH].production ),
833  OCL_SVAR( OC_UINT16, Industry, produced[1].history[LAST_MONTH].production ),
834  OCL_SVAR( OC_UINT16, Industry, produced[0].history[LAST_MONTH].transported ),
835  OCL_SVAR( OC_UINT16, Industry, produced[1].history[LAST_MONTH].transported ),
836 
837  OCL_SVAR( OC_UINT8, Industry, type ),
838  OCL_SVAR( OC_TTO | OC_FILE_U8 | OC_VAR_U16, Industry, counter ),
839  OCL_SVAR( OC_UINT8, Industry, owner ),
840  OCL_SVAR( OC_UINT8, Industry, random_colour ),
841  OCL_SVAR( OC_TTD | OC_FILE_U8 | OC_VAR_I32, Industry, last_prod_year ),
842  OCL_SVAR( OC_TTD | OC_UINT16, Industry, counter ),
843  OCL_SVAR( OC_TTD | OC_UINT8, Industry, was_cargo_delivered ),
844 
845  OCL_CNULL( OC_TTD, 9 ),
846 
847  OCL_END()
848 };
849 
850 static bool LoadOldIndustry(LoadgameState *ls, int num)
851 {
852  Industry *i = new (num) Industry();
853  if (!LoadChunk(ls, i, industry_chunk)) return false;
854 
855  if (i->location.tile != 0) {
856  i->town = RemapTown(i->location.tile);
857 
858  if (_savegame_type == SGT_TTO) {
859  if (i->type > 0x06) i->type++; // Printing Works were added
860  if (i->type == 0x0A) i->type = 0x12; // Iron Ore Mine has different ID
861 
862  TimerGameEconomy::YearMonthDay ymd = TimerGameEconomy::ConvertDateToYMD(TimerGameEconomy::date);
863  i->last_prod_year = ymd.year;
864 
866  }
867 
869  } else {
870  delete i;
871  }
872 
873  return true;
874 }
875 
876 static CompanyID _current_company_id;
877 static int32_t _old_yearly;
878 
879 static const OldChunks _company_yearly_chunk[] = {
880  OCL_VAR( OC_INT32, 1, &_old_yearly ),
881  OCL_END()
882 };
883 
884 static bool LoadOldCompanyYearly(LoadgameState *ls, int num)
885 {
886  Company *c = Company::Get(_current_company_id);
887 
888  for (uint i = 0; i < 13; i++) {
889  if (_savegame_type == SGT_TTO && i == 6) {
890  _old_yearly = 0; // property maintenance
891  } else {
892  if (!LoadChunk(ls, nullptr, _company_yearly_chunk)) return false;
893  }
894 
895  c->yearly_expenses[num][i] = _old_yearly;
896  }
897 
898  return true;
899 }
900 
901 static const OldChunks _company_economy_chunk[] = {
902  OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, income ),
903  OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, expenses ),
904  OCL_SVAR( OC_INT32, CompanyEconomyEntry, delivered_cargo[NUM_CARGO - 1] ),
905  OCL_SVAR( OC_INT32, CompanyEconomyEntry, performance_history ),
906  OCL_SVAR( OC_TTD | OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, company_value ),
907 
908  OCL_END()
909 };
910 
911 static bool LoadOldCompanyEconomy(LoadgameState *ls, int)
912 {
913  Company *c = Company::Get(_current_company_id);
914 
915  if (!LoadChunk(ls, &c->cur_economy, _company_economy_chunk)) return false;
916 
917  /* Don't ask, but the number in TTD(Patch) are inversed to OpenTTD */
920 
921  for (uint i = 0; i < 24; i++) {
922  if (!LoadChunk(ls, &c->old_economy[i], _company_economy_chunk)) return false;
923 
924  c->old_economy[i].income = -c->old_economy[i].income;
925  c->old_economy[i].expenses = -c->old_economy[i].expenses;
926  }
927 
928  return true;
929 }
930 
931 static const OldChunks _company_chunk[] = {
932  OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
933  OCL_SVAR( OC_UINT32, Company, name_2 ),
934  OCL_SVAR( OC_UINT32, Company, face ),
935  OCL_VAR ( OC_UINT16, 1, &_old_string_id_2 ),
936  OCL_SVAR( OC_UINT32, Company, president_name_2 ),
937 
938  OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, Company, money ),
939  OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, Company, current_loan ),
940 
941  OCL_SVAR( OC_UINT8, Company, colour ),
942  OCL_SVAR( OC_UINT8, Company, money_fraction ),
943  OCL_SVAR( OC_UINT8, Company, months_of_bankruptcy ),
944  OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Company, bankrupt_asked ),
945  OCL_SVAR( OC_FILE_U32 | OC_VAR_I64, Company, bankrupt_value ),
946  OCL_SVAR( OC_UINT16, Company, bankrupt_timeout ),
947 
948  OCL_CNULL( OC_TTD, 4 ), // cargo_types
949  OCL_CNULL( OC_TTO, 2 ), // cargo_types
950 
951  OCL_CHUNK( 3, LoadOldCompanyYearly ),
952  OCL_CHUNK( 1, LoadOldCompanyEconomy ),
953 
954  OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Company, inaugurated_year),
955  OCL_SVAR( OC_TILE, Company, last_build_coordinate ),
956  OCL_SVAR( OC_UINT8, Company, num_valid_stat_ent ),
957 
958  OCL_NULL( 230 ), // Old AI
959 
960  OCL_SVAR( OC_UINT8, Company, block_preview ),
961  OCL_CNULL( OC_TTD, 1 ), // Old AI
962  OCL_CNULL( OC_TTD, 1 ), // avail_railtypes
963  OCL_SVAR( OC_TILE, Company, location_of_HQ ),
964 
965  OCL_CNULL( OC_TTD, 4 ), // Shares
966 
967  OCL_CNULL( OC_TTD, 8 ), // junk at end of chunk
968 
969  OCL_END()
970 };
971 
972 static bool LoadOldCompany(LoadgameState *ls, int num)
973 {
974  Company *c = new (num) Company();
975 
976  _current_company_id = (CompanyID)num;
977 
978  if (!LoadChunk(ls, c, _company_chunk)) return false;
979 
980  if (_old_string_id == 0) {
981  delete c;
982  return true;
983  }
984 
985  if (_savegame_type == SGT_TTO) {
986  /* adjust manager's face */
987  if (HasBit(c->face, 27) && GB(c->face, 26, 1) == GB(c->face, 19, 1)) {
988  /* if face would be black in TTD, adjust tie colour and thereby face colour */
989  ClrBit(c->face, 27);
990  }
991 
992  /* Company name */
993  if (_old_string_id == 0 || _old_string_id == 0x4C00) {
994  _old_string_id = STR_SV_UNNAMED; // "Unnamed"
995  } else if (GB(_old_string_id, 8, 8) == 0x52) {
996  _old_string_id += 0x2A00; // Custom name
997  } else {
998  _old_string_id = RemapOldStringID(_old_string_id += 0x240D); // Automatic name
999  }
1000  c->name_1 = _old_string_id;
1001 
1002  /* Manager name */
1003  switch (_old_string_id_2) {
1004  case 0x4CDA: _old_string_id_2 = SPECSTR_PRESIDENT_NAME; break; // automatic name
1005  case 0x0006: _old_string_id_2 = STR_SV_EMPTY; break; // empty name
1006  default: _old_string_id_2 = _old_string_id_2 + 0x2A00; break; // custom name
1007  }
1008  c->president_name_1 = _old_string_id_2;
1009 
1010  c->colour = RemapTTOColour(c->colour);
1011 
1012  if (num != 0) c->is_ai = true;
1013  } else {
1014  c->name_1 = RemapOldStringID(_old_string_id);
1015  c->president_name_1 = RemapOldStringID(_old_string_id_2);
1016 
1017  if (num == 0) {
1018  /* If the first company has no name, make sure we call it UNNAMED */
1019  if (c->name_1 == 0) {
1020  c->name_1 = STR_SV_UNNAMED;
1021  }
1022  } else {
1023  /* Beside some multiplayer maps (1 on 1), which we don't official support,
1024  * all other companies are an AI.. mark them as such */
1025  c->is_ai = true;
1026  }
1027 
1028  /* Sometimes it is better to not ask.. in old scenarios, the money
1029  * was always 893288 pounds. In the newer versions this is correct,
1030  * but correct for those oldies
1031  * Ps: this also means that if you had exact 893288 pounds, you will go back
1032  * to 100000.. this is a very VERY small chance ;) */
1033  if (c->money == 893288) c->money = c->current_loan = 100000;
1034  }
1035 
1036  _company_colours[num] = c->colour;
1038 
1039  return true;
1040 }
1041 
1042 static uint32_t _old_order_ptr;
1043 static uint16_t _old_next_ptr;
1044 static VehicleID _current_vehicle_id;
1045 
1046 static const OldChunks vehicle_train_chunk[] = {
1047  OCL_SVAR( OC_UINT8, Train, track ),
1048  OCL_SVAR( OC_UINT8, Train, force_proceed ),
1049  OCL_SVAR( OC_UINT16, Train, crash_anim_pos ),
1050  OCL_SVAR( OC_UINT8, Train, railtype ),
1051 
1052  OCL_NULL( 5 ),
1053 
1054  OCL_END()
1055 };
1056 
1057 static const OldChunks vehicle_road_chunk[] = {
1058  OCL_SVAR( OC_UINT8, RoadVehicle, state ),
1059  OCL_SVAR( OC_UINT8, RoadVehicle, frame ),
1060  OCL_SVAR( OC_UINT16, RoadVehicle, blocked_ctr ),
1061  OCL_SVAR( OC_UINT8, RoadVehicle, overtaking ),
1062  OCL_SVAR( OC_UINT8, RoadVehicle, overtaking_ctr ),
1063  OCL_SVAR( OC_UINT16, RoadVehicle, crashed_ctr ),
1064  OCL_SVAR( OC_UINT8, RoadVehicle, reverse_ctr ),
1065 
1066  OCL_NULL( 1 ),
1067 
1068  OCL_END()
1069 };
1070 
1071 static const OldChunks vehicle_ship_chunk[] = {
1072  OCL_SVAR( OC_UINT8, Ship, state ),
1073 
1074  OCL_NULL( 9 ),
1075 
1076  OCL_END()
1077 };
1078 
1079 static const OldChunks vehicle_air_chunk[] = {
1080  OCL_SVAR( OC_UINT8, Aircraft, pos ),
1081  OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Aircraft, targetairport ),
1082  OCL_SVAR( OC_UINT16, Aircraft, crashed_counter ),
1083  OCL_SVAR( OC_UINT8, Aircraft, state ),
1084 
1085  OCL_NULL( 5 ),
1086 
1087  OCL_END()
1088 };
1089 
1090 static const OldChunks vehicle_effect_chunk[] = {
1091  OCL_SVAR( OC_UINT16, EffectVehicle, animation_state ),
1092  OCL_SVAR( OC_UINT8, EffectVehicle, animation_substate ),
1093 
1094  OCL_NULL( 7 ), // Junk
1095 
1096  OCL_END()
1097 };
1098 
1099 static const OldChunks vehicle_disaster_chunk[] = {
1100  OCL_SVAR( OC_UINT16, DisasterVehicle, image_override ),
1101  OCL_SVAR( OC_UINT16, DisasterVehicle, big_ufo_destroyer_target ),
1102 
1103  OCL_NULL( 6 ),
1104 
1105  OCL_END()
1106 };
1107 
1108 static const OldChunks vehicle_empty_chunk[] = {
1109  OCL_NULL( 10 ),
1110 
1111  OCL_END()
1112 };
1113 
1114 static bool LoadOldVehicleUnion(LoadgameState *ls, int)
1115 {
1116  Vehicle *v = Vehicle::GetIfValid(_current_vehicle_id);
1117  uint temp = ls->total_read;
1118  bool res;
1119 
1120  if (v == nullptr) {
1121  res = LoadChunk(ls, nullptr, vehicle_empty_chunk);
1122  } else {
1123  switch (v->type) {
1124  default: SlErrorCorrupt("Invalid vehicle type");
1125  case VEH_TRAIN : res = LoadChunk(ls, v, vehicle_train_chunk); break;
1126  case VEH_ROAD : res = LoadChunk(ls, v, vehicle_road_chunk); break;
1127  case VEH_SHIP : res = LoadChunk(ls, v, vehicle_ship_chunk); break;
1128  case VEH_AIRCRAFT: res = LoadChunk(ls, v, vehicle_air_chunk); break;
1129  case VEH_EFFECT : res = LoadChunk(ls, v, vehicle_effect_chunk); break;
1130  case VEH_DISASTER: res = LoadChunk(ls, v, vehicle_disaster_chunk); break;
1131  }
1132  }
1133 
1134  /* This chunk size should always be 10 bytes */
1135  if (ls->total_read - temp != 10) {
1136  Debug(oldloader, 0, "Assert failed in VehicleUnion: invalid chunk size");
1137  return false;
1138  }
1139 
1140  return res;
1141 }
1142 
1143 static uint16_t _cargo_count;
1144 
1145 static const OldChunks vehicle_chunk[] = {
1146  OCL_SVAR( OC_UINT8, Vehicle, subtype ),
1147 
1148  OCL_NULL( 2 ),
1149  OCL_NULL( 2 ),
1150 
1151  OCL_VAR ( OC_UINT32, 1, &_old_order_ptr ),
1152  OCL_VAR ( OC_UINT16, 1, &_old_order ),
1153 
1154  OCL_NULL ( 1 ),
1155  OCL_SVAR( OC_UINT8, Vehicle, cur_implicit_order_index ),
1156  OCL_SVAR( OC_TILE, Vehicle, dest_tile ),
1157  OCL_SVAR( OC_UINT16, Vehicle, load_unload_ticks ),
1158  OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Vehicle, date_of_last_service ),
1159  OCL_SVAR( OC_UINT16, Vehicle, service_interval ),
1160  OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Vehicle, last_station_visited ),
1161  OCL_SVAR( OC_TTD | OC_UINT8, Vehicle, tick_counter ),
1162  OCL_CNULL( OC_TTD, 2 ),
1163  OCL_CNULL( OC_TTO, 1 ),
1164 
1165  OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Vehicle, x_pos ),
1166  OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Vehicle, y_pos ),
1167  OCL_SVAR( OC_FILE_U8 | OC_VAR_I32, Vehicle, z_pos ),
1168  OCL_SVAR( OC_UINT8, Vehicle, direction ),
1169  OCL_NULL( 2 ),
1170  OCL_NULL( 2 ),
1171  OCL_NULL( 1 ),
1172 
1173  OCL_SVAR( OC_UINT8, Vehicle, owner ),
1174  OCL_SVAR( OC_TILE, Vehicle, tile ),
1175  OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Vehicle, sprite_cache.sprite_seq.seq[0].sprite ),
1176 
1177  OCL_NULL( 8 ),
1178 
1179  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, Vehicle, vehstatus ),
1180  OCL_SVAR( OC_TTD | OC_UINT16, Vehicle, cur_speed ),
1181  OCL_SVAR( OC_TTO | OC_FILE_U8 | OC_VAR_U16, Vehicle, cur_speed ),
1182  OCL_SVAR( OC_UINT8, Vehicle, subspeed ),
1183  OCL_SVAR( OC_UINT8, Vehicle, acceleration ),
1184  OCL_SVAR( OC_UINT8, Vehicle, progress ),
1185 
1186  OCL_SVAR( OC_UINT8, Vehicle, cargo_type ),
1187  OCL_SVAR( OC_TTD | OC_UINT16, Vehicle, cargo_cap ),
1188  OCL_SVAR( OC_TTO | OC_FILE_U8 | OC_VAR_U16, Vehicle, cargo_cap ),
1189  OCL_VAR ( OC_TTD | OC_UINT16, 1, &_cargo_count ),
1190  OCL_VAR ( OC_TTO | OC_FILE_U8 | OC_VAR_U16, 1, &_cargo_count ),
1191  OCL_VAR ( OC_UINT8, 1, &_cargo_source ),
1192  OCL_VAR ( OC_UINT8, 1, &_cargo_periods ),
1193 
1194  OCL_SVAR( OC_TTO | OC_UINT8, Vehicle, tick_counter ),
1195 
1196  OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Vehicle, age ),
1197  OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Vehicle, max_age ),
1198  OCL_SVAR( OC_FILE_U8 | OC_VAR_I32, Vehicle, build_year ),
1199  OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Vehicle, unitnumber ),
1200 
1201  OCL_SVAR( OC_TTD | OC_UINT16, Vehicle, engine_type ),
1202  OCL_SVAR( OC_TTO | OC_FILE_U8 | OC_VAR_U16, Vehicle, engine_type ),
1203 
1204  OCL_SVAR( OC_UINT8, Vehicle, spritenum ),
1205  OCL_SVAR( OC_UINT8, Vehicle, day_counter ),
1206 
1207  OCL_SVAR( OC_UINT8, Vehicle, breakdowns_since_last_service ),
1208  OCL_SVAR( OC_UINT8, Vehicle, breakdown_ctr ),
1209  OCL_SVAR( OC_UINT8, Vehicle, breakdown_delay ),
1210  OCL_SVAR( OC_UINT8, Vehicle, breakdown_chance ),
1211 
1212  OCL_CNULL( OC_TTO, 1 ),
1213 
1214  OCL_SVAR( OC_UINT16, Vehicle, reliability ),
1215  OCL_SVAR( OC_UINT16, Vehicle, reliability_spd_dec ),
1216 
1217  OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, Vehicle, profit_this_year ),
1218  OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, Vehicle, profit_last_year ),
1219 
1220  OCL_VAR ( OC_UINT16, 1, &_old_next_ptr ),
1221 
1222  OCL_SVAR( OC_FILE_U32 | OC_VAR_I64, Vehicle, value ),
1223 
1224  OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
1225 
1226  OCL_CHUNK( 1, LoadOldVehicleUnion ),
1227 
1228  OCL_CNULL( OC_TTO, 24 ),
1229  OCL_CNULL( OC_TTD, 20 ),
1230 
1231  OCL_END()
1232 };
1233 
1240 bool LoadOldVehicle(LoadgameState *ls, int num)
1241 {
1242  /* Read the TTDPatch flags, because we need some info from it */
1243  ReadTTDPatchFlags();
1244 
1245  for (uint i = 0; i < _old_vehicle_multiplier; i++) {
1246  _current_vehicle_id = num * _old_vehicle_multiplier + i;
1247 
1248  Vehicle *v;
1249 
1250  if (_savegame_type == SGT_TTO) {
1251  uint type = ReadByte(ls);
1252  switch (type) {
1253  default: return false;
1254  case 0x00 /* VEH_INVALID */: v = nullptr; break;
1255  case 0x25 /* MONORAIL */:
1256  case 0x20 /* VEH_TRAIN */: v = new (_current_vehicle_id) Train(); break;
1257  case 0x21 /* VEH_ROAD */: v = new (_current_vehicle_id) RoadVehicle(); break;
1258  case 0x22 /* VEH_SHIP */: v = new (_current_vehicle_id) Ship(); break;
1259  case 0x23 /* VEH_AIRCRAFT */: v = new (_current_vehicle_id) Aircraft(); break;
1260  case 0x24 /* VEH_EFFECT */: v = new (_current_vehicle_id) EffectVehicle(); break;
1261  case 0x26 /* VEH_DISASTER */: v = new (_current_vehicle_id) DisasterVehicle(); break;
1262  }
1263 
1264  if (!LoadChunk(ls, v, vehicle_chunk)) return false;
1265  if (v == nullptr) continue;
1266  v->refit_cap = v->cargo_cap;
1267 
1268  SpriteID sprite = v->sprite_cache.sprite_seq.seq[0].sprite;
1269  /* no need to override other sprites */
1270  if (IsInsideMM(sprite, 1460, 1465)) {
1271  sprite += 580; // aircraft smoke puff
1272  } else if (IsInsideMM(sprite, 2096, 2115)) {
1273  sprite += 977; // special effects part 1
1274  } else if (IsInsideMM(sprite, 2396, 2436)) {
1275  sprite += 1305; // special effects part 2
1276  } else if (IsInsideMM(sprite, 2516, 2539)) {
1277  sprite += 1385; // rotor or disaster-related vehicles
1278  }
1279  v->sprite_cache.sprite_seq.seq[0].sprite = sprite;
1280 
1281  switch (v->type) {
1282  case VEH_TRAIN: {
1283  static const byte spriteset_rail[] = {
1284  0, 2, 4, 4, 8, 10, 12, 14, 16, 18, 20, 22, 40, 42, 44, 46,
1285  48, 52, 54, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 120, 122,
1286  124, 126, 128, 130, 132, 134, 136, 138, 140
1287  };
1288  if (v->spritenum / 2 >= lengthof(spriteset_rail)) return false;
1289  v->spritenum = spriteset_rail[v->spritenum / 2]; // adjust railway sprite set offset
1290  /* Should be the original values for monorail / rail, can't use RailType constants */
1291  Train::From(v)->railtype = static_cast<RailType>(type == 0x25 ? 1 : 0);
1292  break;
1293  }
1294 
1295  case VEH_ROAD:
1296  if (v->spritenum >= 22) v->spritenum += 12;
1297  break;
1298 
1299  case VEH_SHIP:
1300  v->spritenum += 2;
1301 
1302  switch (v->spritenum) {
1303  case 2: // oil tanker && cargo type != oil
1304  if (v->cargo_type != CT_OIL) v->spritenum = 0; // make it a coal/goods ship
1305  break;
1306  case 4: // passenger ship && cargo type == mail
1307  if (v->cargo_type == CT_MAIL) v->spritenum = 0; // make it a mail ship
1308  break;
1309  default:
1310  break;
1311  }
1312  break;
1313 
1314  default:
1315  break;
1316  }
1317 
1318  switch (_old_string_id) {
1319  case 0x0000: break; // empty (invalid vehicles)
1320  case 0x0006: _old_string_id = STR_SV_EMPTY; break; // empty (special vehicles)
1321  case 0x8495: _old_string_id = STR_SV_TRAIN_NAME; break; // "Train X"
1322  case 0x8842: _old_string_id = STR_SV_ROAD_VEHICLE_NAME; break; // "Road Vehicle X"
1323  case 0x8C3B: _old_string_id = STR_SV_SHIP_NAME; break; // "Ship X"
1324  case 0x9047: _old_string_id = STR_SV_AIRCRAFT_NAME; break; // "Aircraft X"
1325  default: _old_string_id += 0x2A00; break; // custom name
1326  }
1327 
1328  _old_vehicle_names[_current_vehicle_id] = _old_string_id;
1329  } else {
1330  /* Read the vehicle type and allocate the right vehicle */
1331  switch (ReadByte(ls)) {
1332  default: SlErrorCorrupt("Invalid vehicle type");
1333  case 0x00 /* VEH_INVALID */: v = nullptr; break;
1334  case 0x10 /* VEH_TRAIN */: v = new (_current_vehicle_id) Train(); break;
1335  case 0x11 /* VEH_ROAD */: v = new (_current_vehicle_id) RoadVehicle(); break;
1336  case 0x12 /* VEH_SHIP */: v = new (_current_vehicle_id) Ship(); break;
1337  case 0x13 /* VEH_AIRCRAFT*/: v = new (_current_vehicle_id) Aircraft(); break;
1338  case 0x14 /* VEH_EFFECT */: v = new (_current_vehicle_id) EffectVehicle(); break;
1339  case 0x15 /* VEH_DISASTER*/: v = new (_current_vehicle_id) DisasterVehicle(); break;
1340  }
1341 
1342  if (!LoadChunk(ls, v, vehicle_chunk)) return false;
1343  if (v == nullptr) continue;
1344 
1345  _old_vehicle_names[_current_vehicle_id] = RemapOldStringID(_old_string_id);
1346 
1347  /* This should be consistent, else we have a big problem... */
1348  if (v->index != _current_vehicle_id) {
1349  Debug(oldloader, 0, "Loading failed - vehicle-array is invalid");
1350  return false;
1351  }
1352  }
1353 
1354  if (_old_order_ptr != 0 && _old_order_ptr != 0xFFFFFFFF) {
1355  uint max = _savegame_type == SGT_TTO ? 3000 : 5000;
1356  uint old_id = RemapOrderIndex(_old_order_ptr);
1357  if (old_id < max) v->old_orders = Order::Get(old_id); // don't accept orders > max number of orders
1358  }
1359  v->current_order.AssignOrder(UnpackOldOrder(_old_order));
1360 
1361  if (v->type == VEH_DISASTER) {
1363  }
1364 
1365  v->next = (Vehicle *)(size_t)_old_next_ptr;
1366 
1367  if (_cargo_count != 0 && CargoPacket::CanAllocateItem()) {
1368  StationID source = (_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source;
1369  TileIndex source_xy = (source != INVALID_STATION) ? Station::Get(source)->xy : (TileIndex)0;
1370  v->cargo.Append(new CargoPacket(_cargo_count, _cargo_periods, source, source_xy, 0));
1371  }
1372  }
1373 
1374  return true;
1375 }
1376 
1377 static const OldChunks sign_chunk[] = {
1378  OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
1379  OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Sign, x ),
1380  OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Sign, y ),
1381  OCL_SVAR( OC_FILE_U16 | OC_VAR_I8, Sign, z ),
1382 
1383  OCL_NULL( 6 ),
1384 
1385  OCL_END()
1386 };
1387 
1388 static bool LoadOldSign(LoadgameState *ls, int num)
1389 {
1390  Sign *si = new (num) Sign();
1391  if (!LoadChunk(ls, si, sign_chunk)) return false;
1392 
1393  if (_old_string_id != 0) {
1394  if (_savegame_type == SGT_TTO) {
1395  if (_old_string_id != 0x140A) si->name = CopyFromOldName(_old_string_id + 0x2A00);
1396  } else {
1397  si->name = CopyFromOldName(RemapOldStringID(_old_string_id));
1398  }
1399  si->owner = OWNER_NONE;
1400  } else {
1401  delete si;
1402  }
1403 
1404  return true;
1405 }
1406 
1407 static const OldChunks engine_chunk[] = {
1408  OCL_SVAR( OC_UINT16, Engine, company_avail ),
1409  OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, intro_date ),
1410  OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, age ),
1411  OCL_SVAR( OC_UINT16, Engine, reliability ),
1412  OCL_SVAR( OC_UINT16, Engine, reliability_spd_dec ),
1413  OCL_SVAR( OC_UINT16, Engine, reliability_start ),
1414  OCL_SVAR( OC_UINT16, Engine, reliability_max ),
1415  OCL_SVAR( OC_UINT16, Engine, reliability_final ),
1416  OCL_SVAR( OC_UINT16, Engine, duration_phase_1 ),
1417  OCL_SVAR( OC_UINT16, Engine, duration_phase_2 ),
1418  OCL_SVAR( OC_UINT16, Engine, duration_phase_3 ),
1419 
1420  OCL_NULL( 1 ), // lifelength
1421  OCL_SVAR( OC_UINT8, Engine, flags ),
1422  OCL_NULL( 1 ), // preview_company_rank
1423  OCL_SVAR( OC_UINT8, Engine, preview_wait ),
1424 
1425  OCL_CNULL( OC_TTD, 2 ),
1426 
1427  OCL_END()
1428 };
1429 
1430 static bool LoadOldEngine(LoadgameState *ls, int num)
1431 {
1432  Engine *e = _savegame_type == SGT_TTO ? &_old_engines[num] : GetTempDataEngine(num);
1433  return LoadChunk(ls, e, engine_chunk);
1434 }
1435 
1436 static bool LoadOldEngineName(LoadgameState *ls, int num)
1437 {
1438  Engine *e = GetTempDataEngine(num);
1439  e->name = CopyFromOldName(RemapOldStringID(ReadUint16(ls)));
1440  return true;
1441 }
1442 
1443 static const OldChunks subsidy_chunk[] = {
1444  OCL_SVAR( OC_UINT8, Subsidy, cargo_type ),
1445  OCL_SVAR( OC_UINT8, Subsidy, remaining ),
1446  OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Subsidy, src ),
1447  OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Subsidy, dst ),
1448 
1449  OCL_END()
1450 };
1451 
1452 static bool LoadOldSubsidy(LoadgameState *ls, int num)
1453 {
1454  Subsidy *s = new (num) Subsidy();
1455  bool ret = LoadChunk(ls, s, subsidy_chunk);
1456  if (!IsValidCargoID(s->cargo_type)) delete s;
1457  return ret;
1458 }
1459 
1460 static const OldChunks game_difficulty_chunk[] = {
1461  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, max_no_competitors ),
1462  OCL_NULL( 2), // competitor_start_time
1463  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, number_towns ),
1464  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, industry_density ),
1465  OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, DifficultySettings, max_loan ),
1466  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, initial_interest ),
1467  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, vehicle_costs ),
1468  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, competitor_speed ),
1469  OCL_NULL( 2), // competitor_intelligence
1470  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, vehicle_breakdowns ),
1471  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, subsidy_multiplier ),
1472  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, construction_cost ),
1473  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, terrain_type ),
1474  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, quantity_sea_lakes ),
1475  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, economy ),
1476  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, line_reverse_mode ),
1477  OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, disasters ),
1478  OCL_END()
1479 };
1480 
1481 static bool LoadOldGameDifficulty(LoadgameState *ls, int)
1482 {
1483  bool ret = LoadChunk(ls, &_settings_game.difficulty, game_difficulty_chunk);
1485  return ret;
1486 }
1487 
1488 
1489 static bool LoadOldMapPart1(LoadgameState *ls, int)
1490 {
1491  if (_savegame_type == SGT_TTO) {
1492  Map::Allocate(OLD_MAP_SIZE, OLD_MAP_SIZE);
1493  }
1494 
1495  for (auto t : Map::Iterate()) {
1496  t.m1() = ReadByte(ls);
1497  }
1498  for (auto t : Map::Iterate()) {
1499  t.m2() = ReadByte(ls);
1500  }
1501 
1502  if (_savegame_type != SGT_TTO) {
1503  /* old map3 is split into to m3 and m4 */
1504  for (auto t : Map::Iterate()) {
1505  t.m3() = ReadByte(ls);
1506  t.m4() = ReadByte(ls);
1507  }
1508  auto range = Map::Iterate();
1509  for (auto it = range.begin(); it != range.end(); /* nothing. */) {
1510  byte b = ReadByte(ls);
1511  for (int i = 0; i < 8; i += 2, ++it) (*it).m6() = GB(b, i, 2);
1512  }
1513  }
1514 
1515  return true;
1516 }
1517 
1518 static bool LoadOldMapPart2(LoadgameState *ls, int)
1519 {
1520  for (auto t : Map::Iterate()) {
1521  t.type() = ReadByte(ls);
1522  }
1523  for (auto t : Map::Iterate()) {
1524  t.m5() = ReadByte(ls);
1525  }
1526 
1527  return true;
1528 }
1529 
1530 static bool LoadTTDPatchExtraChunks(LoadgameState *ls, int)
1531 {
1532  ReadTTDPatchFlags();
1533 
1534  Debug(oldloader, 2, "Found {} extra chunk(s)", _old_extra_chunk_nums);
1535 
1536  for (int i = 0; i != _old_extra_chunk_nums; i++) {
1537  uint16_t id = ReadUint16(ls);
1538  uint32_t len = ReadUint32(ls);
1539 
1540  switch (id) {
1541  /* List of GRFIDs, used in the savegame. 0x8004 is the new ID
1542  * They are saved in a 'GRFID:4 active:1' format, 5 bytes for each entry */
1543  case 0x2:
1544  case 0x8004: {
1545  /* Skip the first element: TTDP hack for the Action D special variables (FFFF0000 01) */
1546  ReadUint32(ls); ReadByte(ls); len -= 5;
1547 
1549  while (len != 0) {
1550  uint32_t grfid = ReadUint32(ls);
1551 
1552  if (ReadByte(ls) == 1) {
1553  GRFConfig *c = new GRFConfig("TTDP game, no information");
1554  c->ident.grfid = grfid;
1555 
1557  Debug(oldloader, 3, "TTDPatch game using GRF file with GRFID {:08X}", BSWAP32(c->ident.grfid));
1558  }
1559  len -= 5;
1560  }
1561 
1562  /* Append static NewGRF configuration */
1564  break;
1565  }
1566 
1567  /* TTDPatch version and configuration */
1568  case 0x3:
1569  _ttdp_version = ReadUint32(ls);
1570  Debug(oldloader, 3, "Game saved with TTDPatch version {}.{}.{} r{}",
1571  GB(_ttdp_version, 24, 8), GB(_ttdp_version, 20, 4), GB(_ttdp_version, 16, 4), GB(_ttdp_version, 0, 16));
1572  len -= 4;
1573  while (len-- != 0) ReadByte(ls); // skip the configuration
1574  break;
1575 
1576  default:
1577  Debug(oldloader, 4, "Skipping unknown extra chunk {}", id);
1578  while (len-- != 0) ReadByte(ls);
1579  break;
1580  }
1581  }
1582 
1583  return true;
1584 }
1585 
1586 extern TileIndex _cur_tileloop_tile;
1587 extern uint16_t _disaster_delay;
1588 extern byte _trees_tick_ctr;
1589 extern byte _age_cargo_skip_counter; // From misc_sl.cpp
1590 extern uint8_t _old_diff_level;
1591 extern uint8_t _old_units;
1592 static const OldChunks main_chunk[] = {
1593  OCL_ASSERT( OC_TTD, 0 ),
1594  OCL_ASSERT( OC_TTO, 0 ),
1595  OCL_VAR ( OC_FILE_U16 | OC_VAR_U32, 1, &TimerGameCalendar::date ),
1596  OCL_VAR ( OC_UINT16, 1, &TimerGameCalendar::date_fract ),
1597  OCL_NULL( 600 ),
1598  OCL_VAR ( OC_UINT32, 2, &_random.state ),
1599 
1600  OCL_ASSERT( OC_TTD, 0x264 ),
1601  OCL_ASSERT( OC_TTO, 0x264 ),
1602 
1603  OCL_CCHUNK( OC_TTD, 70, LoadOldTown ),
1604  OCL_CCHUNK( OC_TTO, 80, LoadOldTown ),
1605 
1606  OCL_ASSERT( OC_TTD, 0x1C18 ),
1607  OCL_ASSERT( OC_TTO, 0x1AC4 ),
1608 
1609  OCL_CCHUNK( OC_TTD, 5000, LoadOldOrder ),
1610  OCL_CCHUNK( OC_TTO, 3000, LoadOldOrder ),
1611 
1612  OCL_ASSERT( OC_TTD, 0x4328 ),
1613  OCL_ASSERT( OC_TTO, 0x3234 ),
1614 
1615  OCL_CHUNK( 1, LoadOldAnimTileList ),
1616  OCL_NULL( 4 ),
1617 
1618  OCL_ASSERT( OC_TTO, 0x3438 ),
1619 
1620  OCL_CCHUNK( OC_TTD, 255, LoadOldDepot ),
1621  OCL_CCHUNK( OC_TTO, 252, LoadOldDepot ),
1622 
1623  OCL_ASSERT( OC_TTD, 0x4B26 ),
1624  OCL_ASSERT( OC_TTO, 0x3A20 ),
1625 
1626  OCL_NULL( 4 ),
1627  OCL_NULL( 2 ),
1628  OCL_NULL( 2 ),
1629 
1630  OCL_VAR ( OC_FILE_U16 | OC_VAR_U8, 1, &_age_cargo_skip_counter ),
1631  OCL_VAR ( OC_FILE_U16 | OC_VAR_U64, 1, &TimerGameTick::counter ),
1632  OCL_VAR ( OC_TILE, 1, &_cur_tileloop_tile ),
1633 
1634  OCL_ASSERT( OC_TTO, 0x3A2E ),
1635 
1636  OCL_CNULL( OC_TTO, 48 * 6 ),
1637  OCL_CNULL( OC_TTD, 49 * 6 ),
1638 
1639  OCL_ASSERT( OC_TTO, 0x3B4E ),
1640 
1641  OCL_CNULL( OC_TTO, 11 * 8 ),
1642  OCL_CNULL( OC_TTD, 12 * 8 ),
1643 
1644  OCL_ASSERT( OC_TTD, 0x4CBA ),
1645  OCL_ASSERT( OC_TTO, 0x3BA6 ),
1646 
1647  OCL_CHUNK( 1, LoadOldMapPart1 ),
1648 
1649  OCL_ASSERT( OC_TTD, 0x48CBA ),
1650  OCL_ASSERT( OC_TTO, 0x23BA6 ),
1651 
1652  OCL_CCHUNK( OC_TTD, 250, LoadOldStation ),
1653  OCL_CCHUNK( OC_TTO, 200, LoadOldStation ),
1654 
1655  OCL_ASSERT( OC_TTO, 0x29E16 ),
1656 
1657  OCL_CCHUNK( OC_TTD, 90, LoadOldIndustry ),
1658  OCL_CCHUNK( OC_TTO, 100, LoadOldIndustry ),
1659 
1660  OCL_ASSERT( OC_TTO, 0x2ADB6 ),
1661 
1662  OCL_CHUNK( 8, LoadOldCompany ),
1663 
1664  OCL_ASSERT( OC_TTD, 0x547F2 ),
1665  OCL_ASSERT( OC_TTO, 0x2C746 ),
1666 
1667  OCL_CCHUNK( OC_TTD, 850, LoadOldVehicle ),
1668  OCL_CCHUNK( OC_TTO, 800, LoadOldVehicle ),
1669 
1670  OCL_ASSERT( OC_TTD, 0x6F0F2 ),
1671  OCL_ASSERT( OC_TTO, 0x45746 ),
1672 
1673  OCL_VAR ( OC_TTD | OC_UINT8 | OC_DEREFERENCE_POINTER, 32 * 500, &_old_name_array ),
1674  OCL_VAR ( OC_TTO | OC_UINT8 | OC_DEREFERENCE_POINTER, 24 * 200, &_old_name_array ),
1675 
1676  OCL_ASSERT( OC_TTO, 0x46A06 ),
1677 
1678  OCL_NULL( 0x2000 ),
1679 
1680  OCL_CHUNK( 40, LoadOldSign ),
1681 
1682  OCL_ASSERT( OC_TTO, 0x48C36 ),
1683 
1684  OCL_CCHUNK( OC_TTD, 256, LoadOldEngine ),
1685  OCL_CCHUNK( OC_TTO, 103, LoadOldEngine ),
1686 
1687  OCL_ASSERT( OC_TTO, 0x496AC ),
1688 
1689  OCL_NULL ( 2 ), // _vehicle_id_ctr_day
1690 
1691  OCL_CHUNK( 8, LoadOldSubsidy ),
1692 
1693  OCL_ASSERT( OC_TTO, 0x496CE ),
1694 
1695  OCL_VAR ( OC_FILE_U16 | OC_VAR_U32, 1, &_new_competitor_timeout.period ),
1696 
1697  OCL_CNULL( OC_TTO, 2 ),
1698 
1699  OCL_VAR ( OC_FILE_I16 | OC_VAR_I32, 1, &_saved_scrollpos_x ),
1700  OCL_VAR ( OC_FILE_I16 | OC_VAR_I32, 1, &_saved_scrollpos_y ),
1701  OCL_VAR ( OC_FILE_U16 | OC_VAR_U8, 1, &_saved_scrollpos_zoom ),
1702 
1703  OCL_NULL( 4 ),
1704  OCL_VAR ( OC_FILE_U32 | OC_VAR_I64, 1, &_economy.old_max_loan_unround ),
1705  OCL_VAR ( OC_INT16, 1, &_economy.fluct ),
1706 
1707  OCL_VAR ( OC_UINT16, 1, &_disaster_delay ),
1708 
1709  OCL_ASSERT( OC_TTO, 0x496E4 ),
1710 
1711  OCL_CNULL( OC_TTD, 144 ),
1712 
1713  OCL_CCHUNK( OC_TTD, 256, LoadOldEngineName ),
1714 
1715  OCL_CNULL( OC_TTD, 144 ),
1716  OCL_NULL( 2 ),
1717  OCL_NULL( 1 ),
1718 
1719  OCL_VAR ( OC_UINT8, 1, &_settings_game.locale.currency ),
1720  OCL_VAR ( OC_UINT8, 1, &_old_units ),
1721  OCL_VAR ( OC_FILE_U8 | OC_VAR_U32, 1, &_cur_company_tick_index ),
1722 
1723  OCL_NULL( 2 ),
1724  OCL_NULL( 8 ),
1725 
1726  OCL_VAR ( OC_UINT8, 1, &_economy.infl_amount ),
1727  OCL_VAR ( OC_UINT8, 1, &_economy.infl_amount_pr ),
1728  OCL_VAR ( OC_UINT8, 1, &_economy.interest_rate ),
1729  OCL_NULL( 1 ), // available airports
1730  OCL_VAR ( OC_UINT8, 1, &_settings_game.vehicle.road_side ),
1731  OCL_VAR ( OC_UINT8, 1, &_settings_game.game_creation.town_name ),
1732 
1733  OCL_CHUNK( 1, LoadOldGameDifficulty ),
1734 
1735  OCL_ASSERT( OC_TTD, 0x77130 ),
1736 
1737  OCL_VAR ( OC_UINT8, 1, &_old_diff_level ),
1738 
1739  OCL_VAR ( OC_TTD | OC_UINT8, 1, &_settings_game.game_creation.landscape ),
1740  OCL_VAR ( OC_TTD | OC_UINT8, 1, &_trees_tick_ctr ),
1741 
1742  OCL_CNULL( OC_TTD, 1 ),
1743  OCL_VAR ( OC_TTD | OC_UINT8, 1, &_settings_game.game_creation.snow_line_height ),
1744 
1745  OCL_CNULL( OC_TTD, 32 ),
1746  OCL_CNULL( OC_TTD, 36 ),
1747 
1748  OCL_ASSERT( OC_TTD, 0x77179 ),
1749  OCL_ASSERT( OC_TTO, 0x4971D ),
1750 
1751  OCL_CHUNK( 1, LoadOldMapPart2 ),
1752 
1753  OCL_ASSERT( OC_TTD, 0x97179 ),
1754  OCL_ASSERT( OC_TTO, 0x6971D ),
1755 
1756  /* Below any (if available) extra chunks from TTDPatch can follow */
1757  OCL_CHUNK(1, LoadTTDPatchExtraChunks),
1758 
1759  OCL_END()
1760 };
1761 
1762 bool LoadTTDMain(LoadgameState *ls)
1763 {
1764  Debug(oldloader, 3, "Reading main chunk...");
1765 
1766  _read_ttdpatch_flags = false;
1767 
1768  /* Load the biggest chunk */
1769  _old_vehicle_names = nullptr;
1770  try {
1771  if (!LoadChunk(ls, nullptr, main_chunk)) {
1772  Debug(oldloader, 0, "Loading failed");
1773  free(_old_vehicle_names);
1774  return false;
1775  }
1776  } catch (...) {
1777  free(_old_vehicle_names);
1778  throw;
1779  }
1780 
1781  Debug(oldloader, 3, "Done, converting game data...");
1782 
1783  FixTTDMapArray();
1784  FixTTDDepots();
1785 
1786  /* Fix some general stuff */
1788 
1789  /* Fix the game to be compatible with OpenTTD */
1790  FixOldTowns();
1791  FixOldVehicles();
1792 
1793  /* We have a new difficulty setting */
1794  _settings_game.difficulty.town_council_tolerance = Clamp(_old_diff_level, 0, 2);
1795 
1796  Debug(oldloader, 3, "Finished converting game data");
1797  Debug(oldloader, 1, "TTD(Patch) savegame successfully converted");
1798 
1799  free(_old_vehicle_names);
1800 
1801  return true;
1802 }
1803 
1804 bool LoadTTOMain(LoadgameState *ls)
1805 {
1806  Debug(oldloader, 3, "Reading main chunk...");
1807 
1808  _read_ttdpatch_flags = false;
1809 
1810  std::array<byte, 103 * sizeof(Engine)> engines; // we don't want to call Engine constructor here
1811  _old_engines = (Engine *)engines.data();
1812  std::array<StringID, 800> vehnames;
1813  _old_vehicle_names = vehnames.data();
1814 
1815  /* Load the biggest chunk */
1816  if (!LoadChunk(ls, nullptr, main_chunk)) {
1817  Debug(oldloader, 0, "Loading failed");
1818  return false;
1819  }
1820  Debug(oldloader, 3, "Done, converting game data...");
1821 
1823 
1825  _trees_tick_ctr = 0xFF;
1826 
1827  if (!FixTTOMapArray() || !FixTTOEngines()) {
1828  Debug(oldloader, 0, "Conversion failed");
1829  return false;
1830  }
1831 
1832  FixOldTowns();
1833  FixOldVehicles();
1834  FixTTOCompanies();
1835 
1836  /* We have a new difficulty setting */
1837  _settings_game.difficulty.town_council_tolerance = Clamp(_old_diff_level, 0, 2);
1838 
1839  /* SVXConverter about cargo payment rates correction:
1840  * "increase them to compensate for the faster time advance in TTD compared to TTO
1841  * which otherwise would cause much less income while the annual running costs of
1842  * the vehicles stay the same" */
1843  _economy.inflation_payment = std::min(_economy.inflation_payment * 124 / 74, MAX_INFLATION);
1844 
1845  Debug(oldloader, 3, "Finished converting game data");
1846  Debug(oldloader, 1, "TTO savegame successfully converted");
1847 
1848  return true;
1849 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
RoadVehicle
Buses, trucks and trams belong to this class.
Definition: roadveh.h:106
FixTTOEngines
static bool FixTTOEngines()
Definition: oldloader_sl.cpp:343
MP_CLEAR
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition: tile_type.h:48
MP_HOUSE
@ MP_HOUSE
A house by a town.
Definition: tile_type.h:51
Engine::reliability_max
uint16_t reliability_max
Maximal reliability of the engine.
Definition: engine_base.h:44
OC_DEREFERENCE_POINTER
@ OC_DEREFERENCE_POINTER
Dereference the pointer once before writing to it, so we do not have to use big static arrays.
Definition: oldloader.h:77
CompanyProperties::is_ai
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition: company_base.h:95
RoadVehicle::state
byte state
Definition: roadveh.h:108
LoadgameState
Definition: oldloader.h:19
Airport::flags
uint64_t flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
Definition: station_base.h:293
Station::goods
GoodsEntry goods[NUM_CARGO]
Goods at this station.
Definition: station_base.h:471
oldloader.h
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:71
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
TimerGameTick::counter
static TickCounter counter
Monotonic counter, in ticks, since start of game.
Definition: timer_game_tick.h:33
MutableSpriteCache::sprite_seq
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Definition: vehicle_base.h:196
TimerGameConst< struct Calendar >::DAYS_TILL_ORIGINAL_BASE_YEAR
static constexpr TimerGame< struct Calendar >::Date DAYS_TILL_ORIGINAL_BASE_YEAR
The date of the first day of the original base year.
Definition: timer_game_common.h:184
TAE_FOOD
@ TAE_FOOD
Cargo behaves food/fizzy-drinks-like.
Definition: cargotype.h:31
IsInsideMM
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition: math_func.hpp:268
RemapOldStringID
StringID RemapOldStringID(StringID s)
Remap a string ID from the old format to the new format.
Definition: strings_sl.cpp:30
Pool::PoolItem<&_vehicle_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:346
CalcEngineReliability
void CalcEngineReliability(Engine *e, bool new_month)
Update Engine::reliability and (if needed) update the engine GUIs.
Definition: engine.cpp:609
ClearGRFConfigList
void ClearGRFConfigList(GRFConfig **config)
Clear a GRF Config list, freeing all nodes.
Definition: newgrf_config.cpp:356
Vehicle::cargo_cap
uint16_t cargo_cap
total capacity
Definition: vehicle_base.h:338
TimerGameCalendar::date_fract
static DateFract date_fract
Fractional part of the day.
Definition: timer_game_calendar.h:35
_disaster_delay
uint16_t _disaster_delay
Delay counter for considering the next disaster.
Definition: disaster_vehicle.cpp:57
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:356
Engine::reliability_spd_dec
uint16_t reliability_spd_dec
Speed of reliability decay between services (per day).
Definition: engine_base.h:42
BaseStation::town
Town * town
The town this station is associated with.
Definition: base_station_base.h:73
_new_competitor_timeout
TimeoutTimer< TimerGameTick > _new_competitor_timeout
Start a new competitor company if possible.
Economy::interest_rate
byte interest_rate
Interest.
Definition: economy_type.h:46
ReadByte
byte ReadByte(LoadgameState *ls)
Reads a byte from the buffer and decompress if needed.
Definition: oldloader.cpp:76
Station
Station data structure.
Definition: station_base.h:442
Order::GetDestination
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:104
DifficultySettings
Settings related to the difficulty of the game.
Definition: settings_type.h:95
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Economy::inflation_payment
uint64_t inflation_payment
Cumulated inflation of cargo payment since game start; 16 bit fractional part.
Definition: economy_type.h:52
Engine::company_avail
CompanyMask company_avail
Bit for each company whether the engine is available for that company.
Definition: engine_base.h:53
_read_ttdpatch_flags
static bool _read_ttdpatch_flags
Have we (tried to) read TTDPatch extra flags?
Definition: oldloader_sl.cpp:42
DifficultySettings::town_council_tolerance
byte town_council_tolerance
minimum required town ratings to be allowed to demolish stuff
Definition: settings_type.h:116
Vehicle::old_orders
Order * old_orders
Only used during conversion of old save games.
Definition: vehicle_base.h:353
GB
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
FixOldVehicles
void FixOldVehicles()
Convert the old style vehicles into something that resembles the old new style savegames.
Definition: oldloader_sl.cpp:163
Map::Allocate
static void Allocate(uint size_x, uint size_y)
(Re)allocates a map with the given dimension
Definition: map.cpp:41
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
_ttdp_version
uint32_t _ttdp_version
version of TTDP savegame (if applicable)
Definition: saveload.cpp:62
SlErrorCorrupt
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
Definition: saveload.cpp:362
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
Engine::reliability_final
uint16_t reliability_final
Final reliability of the engine.
Definition: engine_base.h:45
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition: settings_type.h:618
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
SGT_TTDP1
@ SGT_TTDP1
TTDP savegame ( -//- ) (data at NW border)
Definition: saveload.h:405
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition: tile_type.h:49
Vehicle::next
Vehicle * next
pointer to the next vehicle in the chain
Definition: vehicle_base.h:244
GameCreationSettings::town_name
byte town_name
the town name generator used for town names
Definition: settings_type.h:355
Tile
Wrapper class to abstract away the way the tiles are stored.
Definition: map_func.h:25
_random
Randomizer _random
Random used in the game state calculations.
Definition: random_func.cpp:37
SpecializedStation< Station, false >::Get
static Station * Get(size_t index)
Gets station with given index.
Definition: base_station_base.h:259
GRFConfig::ident
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
Definition: newgrf_config.h:154
Order::AssignOrder
void AssignOrder(const Order &other)
Assign data to an order (from another order) This function makes sure that the index is maintained co...
Definition: order_cmd.cpp:273
Town::xy
TileIndex xy
town center tile
Definition: town.h:51
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:56
Engine::preview_company
CompanyID preview_company
Company which is currently being offered a preview INVALID_COMPANY means no company.
Definition: engine_base.h:51
LoadOldVehicle
bool LoadOldVehicle(LoadgameState *ls, int num)
Load the vehicles of an old style savegame.
Definition: oldloader_sl.cpp:1240
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
CompanyProperties::face
CompanyManagerFace face
Face description of the president.
Definition: company_base.h:65
VehicleSettings::road_side
byte road_side
the side of the road vehicles drive on
Definition: settings_type.h:533
Tile::m5
debug_inline byte & m5()
General purpose.
Definition: map_func.h:161
Engine
Definition: engine_base.h:37
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
Industry
Defines the internal data of a functional industry.
Definition: industry.h:68
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
CalculateCompanyValue
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
Definition: economy.cpp:149
Tile::m4
debug_inline byte & m4()
General purpose.
Definition: map_func.h:149
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition: tile_type.h:50
Economy::fluct
int16_t fluct
Economy fluctuation status.
Definition: economy_type.h:45
_old_name_array
char * _old_name_array
Location to load the old names to.
Definition: strings_sl.cpp:52
GoodsEntry::status
byte status
Status of this cargo, see GoodsEntryStatus.
Definition: station_base.h:217
CompanyProperties::current_loan
Money current_loan
Amount of money borrowed from the bank.
Definition: company_base.h:69
CompanyEconomyEntry
Statistics about the economy.
Definition: company_base.h:24
_savegame_type
SavegameType _savegame_type
type of savegame we are loading
Definition: saveload.cpp:59
Debug
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
MakeSea
void MakeSea(Tile t)
Make a sea tile.
Definition: water_map.h:423
BaseStation::string_id
StringID string_id
Default name (town area) of station.
Definition: base_station_base.h:70
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:619
Aircraft
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:74
GetTileType
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
GoodsEntry::cargo
StationCargoList cargo
The cargo packets of cargo waiting in this station.
Definition: station_base.h:210
_company_colours
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
Definition: company_cmd.cpp:51
_old_extra_chunk_nums
static uint16_t _old_extra_chunk_nums
Number of extra TTDPatch chunks.
Definition: oldloader_sl.cpp:43
IsInsideBS
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:252
Economy::infl_amount_pr
byte infl_amount_pr
inflation rate for payment rates
Definition: economy_type.h:48
Subsidy::cargo_type
CargoID cargo_type
Cargo type involved in this subsidy, INVALID_CARGO for invalid subsidy.
Definition: subsidy_base.h:23
Subsidy
Struct about subsidies, offered and awarded.
Definition: subsidy_base.h:22
_age_cargo_skip_counter
byte _age_cargo_skip_counter
Skip aging of cargo? Used before savegame version 162.
Definition: misc_sl.cpp:80
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
Industry::location
TileArea location
Location of the industry.
Definition: industry.h:96
BSWAP32
static uint32_t BSWAP32(uint32_t x)
Perform a 32 bits endianness bitswap on x.
Definition: bitmath_func.hpp:345
StartupOneEngine
void StartupOneEngine(Engine *e, const TimerGameCalendar::YearMonthDay &aging_ymd, uint32_t seed)
Start/initialise one engine.
Definition: engine.cpp:680
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:147
Map::Iterate
static IterateWrapper Iterate()
Returns an iterable ensemble of all Tiles.
Definition: map_func.h:363
SGT_TTO
@ SGT_TTO
TTO savegame.
Definition: saveload.h:408
CalcClosestTownFromTile
Town * CalcClosestTownFromTile(TileIndex tile, uint threshold=UINT_MAX)
Return the town closest to the given tile within threshold.
Definition: town_cmd.cpp:3726
Industry::type
IndustryType type
type of industry.
Definition: industry.h:104
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:260
free
void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:379
LoadChunk
bool LoadChunk(LoadgameState *ls, void *base, const OldChunks *chunks)
Loads a chunk from the old savegame.
Definition: oldloader.cpp:110
Engine::intro_date
TimerGameCalendar::Date intro_date
Date of introduction of the engine.
Definition: engine_base.h:39
MP_OBJECT
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition: tile_type.h:58
TimerGameCalendar::ConvertYMDToDate
static Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition: timer_game_calendar.cpp:55
CompanyProperties::colour
Colours colour
Company colour.
Definition: company_base.h:72
CompanyProperties::money
Money money
Money owned by the company.
Definition: company_base.h:67
MP_WATER
@ MP_WATER
Water tile.
Definition: tile_type.h:54
VehicleCargoList::Append
void Append(CargoPacket *cp, MoveToAction action=MTA_KEEP)
Appends the given cargo packet.
Definition: cargopacket.cpp:260
Vehicle::cargo
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:340
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:349
CopyFromOldName
std::string CopyFromOldName(StringID id)
Copy and convert old custom names to UTF-8.
Definition: strings_sl.cpp:61
Engine::preview_asked
CompanyMask preview_asked
Bit for each company which has already been offered a preview.
Definition: engine_base.h:50
Station::airport
Airport airport
Tile area the airport covers.
Definition: station_base.h:456
VEH_EFFECT
@ VEH_EFFECT
Effect vehicle type (smoke, explosions, sparks, bubbles)
Definition: vehicle_type.h:31
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
IsCompanyBuildableVehicleType
bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
Definition: vehicle_func.h:89
OC_TTO
@ OC_TTO
-//- TTO (default is neither of these)
Definition: oldloader.h:43
TimerGameCalendar::ConvertDateToYMD
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
Definition: timer_game_calendar.cpp:42
GameCreationSettings::snow_line_height
byte snow_line_height
the configured snow line height (deduced from "snow_coverage")
Definition: settings_type.h:347
_animated_tiles
std::vector< TileIndex > _animated_tiles
The table/list with animated tiles.
Definition: animated_tile.cpp:19
Train
'Train' is either a loco or a wagon.
Definition: train.h:89
VehicleID
uint32_t VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:57
IsDepotTile
bool IsDepotTile(Tile tile)
Is the given tile a tile with a depot on it?
Definition: depot_map.h:41
Engine::duration_phase_1
uint16_t duration_phase_1
First reliability phase in months, increasing reliability from reliability_start to reliability_max.
Definition: engine_base.h:46
TimerGameEconomy::ConvertDateToYMD
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
Definition: timer_game_economy.cpp:46
Vehicle::sprite_cache
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
Definition: vehicle_base.h:363
SetTileOwner
void SetTileOwner(Tile tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:198
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
GetDepotIndex
DepotID GetDepotIndex(Tile t)
Get the index of which depot is attached to the tile.
Definition: depot_map.h:52
Engine::reliability
uint16_t reliability
Current reliability of the engine.
Definition: engine_base.h:41
ENGINE_AVAILABLE
@ ENGINE_AVAILABLE
This vehicle is available to everyone.
Definition: engine_type.h:182
_cur_company_tick_index
uint _cur_company_tick_index
used to generate a name for one company that doesn't have a name yet per tick
Definition: company_cmd.cpp:53
_old_vehicle_multiplier
static byte _old_vehicle_multiplier
TTDPatch vehicle multiplier.
Definition: oldloader_sl.cpp:44
DisasterVehicle
Disasters, like submarines, skyrangers and their shadows, belong to this class.
Definition: disaster_vehicle.h:37
FixTTDDepots
static void FixTTDDepots()
Definition: oldloader_sl.cpp:102
Industry::random_colour
Colours random_colour
randomized colour of the industry, for display purpose
Definition: industry.h:106
MP_TREES
@ MP_TREES
Tile got trees.
Definition: tile_type.h:52
Engine::reliability_start
uint16_t reliability_start
Initial reliability of the engine.
Definition: engine_base.h:43
Industry::town
Town * town
Nearest town.
Definition: industry.h:97
CompanyEconomyEntry::expenses
Money expenses
The amount of expenses.
Definition: company_base.h:26
CompanyProperties::inaugurated_year
TimerGameEconomy::Year inaugurated_year
Economy year of starting the company.
Definition: company_base.h:79
Ship
All ships have this type.
Definition: ship.h:24
GoodsEntry
Stores station stats for a single cargo.
Definition: station_base.h:166
Engine::name
std::string name
Custom name of engine.
Definition: engine_base.h:38
Pool::PoolItem<&_depot_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:384
TimeoutTimer
A timeout timer will fire once after the interval.
Definition: timer.h:116
Map::MaxY
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:306
CompanyProperties::cur_economy
CompanyEconomyEntry cur_economy
Economic data of the company of this quarter.
Definition: company_base.h:98
LocaleSettings::currency
byte currency
currency we currently use
Definition: settings_type.h:260
OldChunks
Definition: oldloader.h:87
MP_VOID
@ MP_VOID
Invisible tiles at the SW and SE border.
Definition: tile_type.h:55
AppendStaticGRFConfigs
void AppendStaticGRFConfigs(GRFConfig **dst)
Appends the static GRFs to a list of GRFs.
Definition: newgrf_config.cpp:426
CompanyProperties::yearly_expenses
std::array< Expenses, 3 > yearly_expenses
Expenses of the company for the last three years.
Definition: company_base.h:97
SpecializedVehicle< RoadVehicle, Type >::From
static RoadVehicle * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1201
TileType
TileType
The different types of tiles.
Definition: tile_type.h:47
Map::Size
static debug_inline uint Size()
Get the size of the map.
Definition: map_func.h:288
Industry::IncIndustryTypeCount
static void IncIndustryTypeCount(IndustryType type)
Increment the count of industries for this type.
Definition: industry.h:220
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
TAE_WATER
@ TAE_WATER
Cargo behaves water-like.
Definition: cargotype.h:30
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:53
DifficultySettings::max_loan
uint32_t max_loan
the maximum initial loan
Definition: settings_type.h:103
GoodsEntry::GES_ACCEPTANCE
@ GES_ACCEPTANCE
Set when the station accepts the cargo currently for final deliveries.
Definition: station_base.h:173
Economy::infl_amount
byte infl_amount
inflation amount
Definition: economy_type.h:47
SetTileType
void SetTileType(Tile tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:131
Pool::PoolItem<&_cargopacket_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition: pool_type.hpp:305
Sign
Definition: signs_base.h:21
MAX_UVALUE
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
Definition: stdafx.h:388
Economy::old_max_loan_unround
Money old_max_loan_unround
Old: Unrounded max loan.
Definition: economy_type.h:55
Engine::preview_wait
byte preview_wait
Daily countdown timer for timeout of offering the engine to the preview_company company.
Definition: engine_base.h:52
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition: base_station_base.h:65
EffectVehicle
A special vehicle is one of the following:
Definition: effectvehicle_base.h:24
UnpackOldOrder
Order UnpackOldOrder(uint16_t packed)
Unpacks a order from savegames made with TTD(Patch)
Definition: order_sl.cpp:92
TileIndex
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition: tile_type.h:87
_trees_tick_ctr
byte _trees_tick_ctr
Determines when to consider building more trees.
Definition: tree_cmd.cpp:55
VEH_DISASTER
@ VEH_DISASTER
Disaster vehicle type.
Definition: vehicle_type.h:32
CompanyEconomyEntry::income
Money income
The amount of income.
Definition: company_base.h:25
CompanyProperties::president_name_1
StringID president_name_1
Name of the president if the user did not change it.
Definition: company_base.h:61
_grfconfig
GRFConfig * _grfconfig
First item in list of current GRF set up.
Definition: newgrf_config.cpp:164
saveload_internal.h
Depot
Definition: depot_base.h:20
Town
Town data structure.
Definition: town.h:50
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
RVSB_WORMHOLE
@ RVSB_WORMHOLE
The vehicle is in a tunnel and/or bridge.
Definition: roadveh.h:39
CargoPacket
Container for cargo from the same location and time.
Definition: cargopacket.h:40
TileXY
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:385
GRFIdentifier::grfid
uint32_t grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:84
Randomizer::state
uint32_t state[2]
The state of the randomizer.
Definition: random_func.hpp:23
GameSettings::locale
LocaleSettings locale
settings related to used currency/unit system in the current game
Definition: settings_type.h:631
TimerGameConst< struct Economy >::ORIGINAL_BASE_YEAR
static constexpr TimerGame< struct Economy >::Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
Definition: timer_game_common.h:163
Airport::type
byte type
Type of this airport,.
Definition: station_base.h:294
OC_TTD
@ OC_TTD
chunk is valid ONLY for TTD savegames
Definition: oldloader.h:42
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:336
IsValidCargoID
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
Definition: cargo_type.h:90
Vehicle::spritenum
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Definition: vehicle_base.h:310
StationCargoList::Append
void Append(CargoPacket *cp, StationID next)
Appends the given cargo packet to the range of packets with the same next station.
Definition: cargopacket.cpp:684
Industry::last_prod_year
TimerGameEconomy::Year last_prod_year
last economy year of production
Definition: industry.h:107
RVS_IN_DT_ROAD_STOP
@ RVS_IN_DT_ROAD_STOP
The vehicle is in a drive-through road stop.
Definition: roadveh.h:46
SB
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
Definition: bitmath_func.hpp:58
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition: timer_game_calendar.h:34
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:627
EngineID
uint16_t EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
EngineInfo::climates
byte climates
Climates supported by the engine.
Definition: engine_type.h:150
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:51
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
RemapTTOColour
static Colours RemapTTOColour(Colours tto)
Definition: oldloader_sl.cpp:458
NUM_CARGO
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
Definition: cargo_type.h:68
Engine::flags
byte flags
Flags of the engine.
Definition: engine_base.h:49
Engine::duration_phase_2
uint16_t duration_phase_2
Second reliability phase in months, keeping reliability_max.
Definition: engine_base.h:47
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Company
Definition: company_base.h:116
RVSB_IN_DEPOT
@ RVSB_IN_DEPOT
The vehicle is in a depot.
Definition: roadveh.h:38
DisasterVehicle::state
uint16_t state
Action stage of the disaster vehicle.
Definition: disaster_vehicle.h:41
ClrBit
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
MAX_INFLATION
static const uint64_t MAX_INFLATION
Maximum inflation (including fractional part) without causing overflows in int64_t price computations...
Definition: economy_type.h:229
CompanyProperties::old_economy
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
Definition: company_base.h:99
OWNER_WATER
@ OWNER_WATER
The tile/execution is done by "water".
Definition: company_type.h:26
Tile::m3
debug_inline byte & m3()
General purpose.
Definition: map_func.h:137
Engine::duration_phase_3
uint16_t duration_phase_3
Third reliability phase in months, decaying to reliability_final.
Definition: engine_base.h:48
Order::next
Order * next
Pointer to next order. If nullptr, end of list.
Definition: order_base.h:59
Order
Definition: order_base.h:36
SGT_TTDP2
@ SGT_TTDP2
TTDP savegame in new format (data at SE border)
Definition: saveload.h:406
GoodsEntry::GES_RATING
@ GES_RATING
This indicates whether a cargo has a rating at the station.
Definition: station_base.h:183
AppendToGRFConfigList
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el)
Appends an element to a list of GRFs.
Definition: newgrf_config.cpp:440
Vehicle::refit_cap
uint16_t refit_cap
Capacity left over from before last refit.
Definition: vehicle_base.h:339
CompanyProperties::name_1
StringID name_1
Name of the company if the user did not change it.
Definition: company_base.h:58
TimerGameEconomy::date
static Date date
Current date in days (day counter).
Definition: timer_game_economy.h:37
Engine::age
int32_t age
Age of the engine in months.
Definition: engine_base.h:40
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103