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