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