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