OpenTTD
afterload.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "../stdafx.h"
11 #include "../void_map.h"
12 #include "../signs_base.h"
13 #include "../depot_base.h"
14 #include "../fios.h"
15 #include "../gamelog_internal.h"
16 #include "../network/network.h"
17 #include "../network/network_func.h"
18 #include "../gfxinit.h"
19 #include "../viewport_func.h"
20 #include "../viewport_kdtree.h"
21 #include "../industry.h"
22 #include "../clear_map.h"
23 #include "../vehicle_func.h"
24 #include "../string_func.h"
25 #include "../date_func.h"
26 #include "../roadveh.h"
27 #include "../train.h"
28 #include "../station_base.h"
29 #include "../waypoint_base.h"
30 #include "../roadstop_base.h"
31 #include "../tunnelbridge_map.h"
32 #include "../pathfinder/yapf/yapf_cache.h"
33 #include "../elrail_func.h"
34 #include "../signs_func.h"
35 #include "../aircraft.h"
36 #include "../object_map.h"
37 #include "../object_base.h"
38 #include "../tree_map.h"
39 #include "../company_func.h"
40 #include "../road_cmd.h"
41 #include "../ai/ai.hpp"
42 #include "../ai/ai_gui.hpp"
43 #include "../town.h"
44 #include "../economy_base.h"
45 #include "../animated_tile_func.h"
46 #include "../subsidy_base.h"
47 #include "../subsidy_func.h"
48 #include "../newgrf.h"
49 #include "../engine_func.h"
50 #include "../rail_gui.h"
51 #include "../core/backup_type.hpp"
52 #include "../smallmap_gui.h"
53 #include "../news_func.h"
54 #include "../order_backup.h"
55 #include "../error.h"
56 #include "../disaster_vehicle.h"
57 #include "../ship.h"
58 #include "../water.h"
59 
60 
61 #include "saveload_internal.h"
62 
63 #include <signal.h>
64 
65 #include "../safeguards.h"
66 
67 extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY);
68 
79 void SetWaterClassDependingOnSurroundings(TileIndex t, bool include_invalid_water_class)
80 {
81  /* If the slope is not flat, we always assume 'land' (if allowed). Also for one-corner-raised-shores.
82  * Note: Wrt. autosloping under industry tiles this is the most fool-proof behaviour. */
83  if (!IsTileFlat(t)) {
84  if (include_invalid_water_class) {
86  return;
87  } else {
88  SlErrorCorrupt("Invalid water class for dry tile");
89  }
90  }
91 
92  /* Mark tile dirty in all cases */
94 
95  if (TileX(t) == 0 || TileY(t) == 0 || TileX(t) == MapMaxX() - 1 || TileY(t) == MapMaxY() - 1) {
96  /* tiles at map borders are always WATER_CLASS_SEA */
98  return;
99  }
100 
101  bool has_water = false;
102  bool has_canal = false;
103  bool has_river = false;
104 
105  for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
106  TileIndex neighbour = TileAddByDiagDir(t, dir);
107  switch (GetTileType(neighbour)) {
108  case MP_WATER:
109  /* clear water and shipdepots have already a WaterClass associated */
110  if (IsCoast(neighbour)) {
111  has_water = true;
112  } else if (!IsLock(neighbour)) {
113  switch (GetWaterClass(neighbour)) {
114  case WATER_CLASS_SEA: has_water = true; break;
115  case WATER_CLASS_CANAL: has_canal = true; break;
116  case WATER_CLASS_RIVER: has_river = true; break;
117  default: SlErrorCorrupt("Invalid water class for tile");
118  }
119  }
120  break;
121 
122  case MP_RAILWAY:
123  /* Shore or flooded halftile */
124  has_water |= (GetRailGroundType(neighbour) == RAIL_GROUND_WATER);
125  break;
126 
127  case MP_TREES:
128  /* trees on shore */
129  has_water |= (GB(_m[neighbour].m2, 4, 2) == TREE_GROUND_SHORE);
130  break;
131 
132  default: break;
133  }
134  }
135 
136  if (!has_water && !has_canal && !has_river && include_invalid_water_class) {
138  return;
139  }
140 
141  if (has_river && !has_canal) {
143  } else if (has_canal || !has_water) {
145  } else {
147  }
148 }
149 
150 static void ConvertTownOwner()
151 {
152  for (TileIndex tile = 0; tile != MapSize(); tile++) {
153  switch (GetTileType(tile)) {
154  case MP_ROAD:
155  if (GB(_m[tile].m5, 4, 2) == ROAD_TILE_CROSSING && HasBit(_m[tile].m3, 7)) {
156  _m[tile].m3 = OWNER_TOWN;
157  }
158  FALLTHROUGH;
159 
160  case MP_TUNNELBRIDGE:
161  if (_m[tile].m1 & 0x80) SetTileOwner(tile, OWNER_TOWN);
162  break;
163 
164  default: break;
165  }
166  }
167 }
168 
169 /* since savegame version 4.1, exclusive transport rights are stored at towns */
170 static void UpdateExclusiveRights()
171 {
172  for (Town *t : Town::Iterate()) {
173  t->exclusivity = INVALID_COMPANY;
174  }
175 
176  /* FIXME old exclusive rights status is not being imported (stored in s->blocked_months_obsolete)
177  * could be implemented this way:
178  * 1.) Go through all stations
179  * Build an array town_blocked[ town_id ][ company_id ]
180  * that stores if at least one station in that town is blocked for a company
181  * 2.) Go through that array, if you find a town that is not blocked for
182  * one company, but for all others, then give him exclusivity.
183  */
184 }
185 
186 static const byte convert_currency[] = {
187  0, 1, 12, 8, 3,
188  10, 14, 19, 4, 5,
189  9, 11, 13, 6, 17,
190  16, 22, 21, 7, 15,
191  18, 2, 20,
192 };
193 
194 /* since savegame version 4.2 the currencies are arranged differently */
195 static void UpdateCurrencies()
196 {
198 }
199 
200 /* Up to revision 1413 the invisible tiles at the southern border have not been
201  * MP_VOID, even though they should have. This is fixed by this function
202  */
203 static void UpdateVoidTiles()
204 {
205  for (uint x = 0; x < MapSizeX(); x++) MakeVoid(TileXY(x, MapMaxY()));
206  for (uint y = 0; y < MapSizeY(); y++) MakeVoid(TileXY(MapMaxX(), y));
207 }
208 
209 static inline RailType UpdateRailType(RailType rt, RailType min)
210 {
211  return rt >= min ? (RailType)(rt + 1): rt;
212 }
213 
218 {
222  RebuildViewportKdtree();
223 }
224 
235 {
236  /* Initialize windows */
239 
240  /* Update coordinates of the signs. */
242  ResetViewportAfterLoadGame();
243 
244  for (Company *c : Company::Iterate()) {
245  /* For each company, verify (while loading a scenario) that the inauguration date is the current year and set it
246  * accordingly if it is not the case. No need to set it on companies that are not been used already,
247  * thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */
248  if (_file_to_saveload.abstract_ftype == FT_SCENARIO && c->inaugurated_year != MIN_YEAR) {
249  c->inaugurated_year = _cur_year;
250  }
251  }
252 
253  /* Count number of objects per type */
254  for (Object *o : Object::Iterate()) {
255  Object::IncTypeCount(o->type);
256  }
257 
258  /* Identify owners of persistent storage arrays */
259  for (Industry *i : Industry::Iterate()) {
260  if (i->psa != nullptr) {
261  i->psa->feature = GSF_INDUSTRIES;
262  i->psa->tile = i->location.tile;
263  }
264  }
265  for (Station *s : Station::Iterate()) {
266  if (s->airport.psa != nullptr) {
267  s->airport.psa->feature = GSF_AIRPORTS;
268  s->airport.psa->tile = s->airport.tile;
269  }
270  }
271  for (Town *t : Town::Iterate()) {
272  for (std::list<PersistentStorage *>::iterator it = t->psa_list.begin(); it != t->psa_list.end(); ++it) {
273  (*it)->feature = GSF_FAKE_TOWNS;
274  (*it)->tile = t->xy;
275  }
276  }
277  for (RoadVehicle *rv : RoadVehicle::Iterate()) {
278  if (rv->IsFrontEngine()) {
279  rv->CargoChanged();
280  }
281  }
282 
283  RecomputePrices();
284 
286 
288 
289  /* Towns have a noise controlled number of airports system
290  * So each airport's noise value must be added to the town->noise_reached value
291  * Reset each town's noise_reached value to '0' before. */
293 
295  ShowNewGRFError();
297 
298  /* Rebuild the smallmap list of owners. */
300 }
301 
302 typedef void (CDECL *SignalHandlerPointer)(int);
303 static SignalHandlerPointer _prev_segfault = nullptr;
304 static SignalHandlerPointer _prev_abort = nullptr;
305 static SignalHandlerPointer _prev_fpe = nullptr;
306 
307 static void CDECL HandleSavegameLoadCrash(int signum);
308 
313 static void SetSignalHandlers()
314 {
315  _prev_segfault = signal(SIGSEGV, HandleSavegameLoadCrash);
316  _prev_abort = signal(SIGABRT, HandleSavegameLoadCrash);
317  _prev_fpe = signal(SIGFPE, HandleSavegameLoadCrash);
318 }
319 
323 static void ResetSignalHandlers()
324 {
325  signal(SIGSEGV, _prev_segfault);
326  signal(SIGABRT, _prev_abort);
327  signal(SIGFPE, _prev_fpe);
328 }
329 
336 {
338  if (la->at != GLAT_LOAD) return &c->ident;
339 
340  const LoggedChange *lcend = &la->change[la->changes];
341  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
342  if (lc->ct == GLCT_GRFCOMPAT && lc->grfcompat.grfid == c->ident.grfid) return &lc->grfcompat;
343  }
344 
345  return &c->ident;
346 }
347 
350 
357 {
359 }
360 
367 static void CDECL HandleSavegameLoadCrash(int signum)
368 {
370 
371  char buffer[8192];
372  char *p = buffer;
373  p += seprintf(p, lastof(buffer), "Loading your savegame caused OpenTTD to crash.\n");
374 
375  for (const GRFConfig *c = _grfconfig; !_saveload_crash_with_missing_newgrfs && c != nullptr; c = c->next) {
377  }
378 
380  p += seprintf(p, lastof(buffer),
381  "This is most likely caused by a missing NewGRF or a NewGRF that\n"
382  "has been loaded as replacement for a missing NewGRF. OpenTTD\n"
383  "cannot easily determine whether a replacement NewGRF is of a newer\n"
384  "or older version.\n"
385  "It will load a NewGRF with the same GRF ID as the missing NewGRF.\n"
386  "This means that if the author makes incompatible NewGRFs with the\n"
387  "same GRF ID OpenTTD cannot magically do the right thing. In most\n"
388  "cases OpenTTD will load the savegame and not crash, but this is an\n"
389  "exception.\n"
390  "Please load the savegame with the appropriate NewGRFs installed.\n"
391  "The missing/compatible NewGRFs are:\n");
392 
393  for (const GRFConfig *c = _grfconfig; c != nullptr; c = c->next) {
394  if (HasBit(c->flags, GCF_COMPATIBLE)) {
395  const GRFIdentifier *replaced = GetOverriddenIdentifier(c);
396  char buf[40];
397  md5sumToString(buf, lastof(buf), replaced->md5sum);
398  p += seprintf(p, lastof(buffer), "NewGRF %08X (checksum %s) not found.\n Loaded NewGRF \"%s\" with same GRF ID instead.\n", BSWAP32(c->ident.grfid), buf, c->filename);
399  }
400  if (c->status == GCS_NOT_FOUND) {
401  char buf[40];
402  md5sumToString(buf, lastof(buf), c->ident.md5sum);
403  p += seprintf(p, lastof(buffer), "NewGRF %08X (%s) not found; checksum %s.\n", BSWAP32(c->ident.grfid), c->filename, buf);
404  }
405  }
406  } else {
407  p += seprintf(p, lastof(buffer),
408  "This is probably caused by a corruption in the savegame.\n"
409  "Please file a bug report and attach this savegame.\n");
410  }
411 
412  ShowInfo(buffer);
413 
414  SignalHandlerPointer call = nullptr;
415  switch (signum) {
416  case SIGSEGV: call = _prev_segfault; break;
417  case SIGABRT: call = _prev_abort; break;
418  case SIGFPE: call = _prev_fpe; break;
419  default: NOT_REACHED();
420  }
421  if (call != nullptr) call(signum);
422 }
423 
430 {
432 
433  /* remove leftover rail piece from crossing (from very old savegames) */
434  Train *v = nullptr;
435  for (Train *w : Train::Iterate()) {
436  if (w->tile == t) {
437  v = w;
438  break;
439  }
440  }
441 
442  if (v != nullptr) {
443  /* when there is a train on crossing (it could happen in TTD), set owner of crossing to train owner */
444  SetTileOwner(t, v->owner);
445  return;
446  }
447 
448  /* try to find any connected rail */
449  for (DiagDirection dd = DIAGDIR_BEGIN; dd < DIAGDIR_END; dd++) {
450  TileIndex tt = t + TileOffsByDiagDir(dd);
451  if (GetTileTrackStatus(t, TRANSPORT_RAIL, 0, dd) != 0 &&
454  SetTileOwner(t, GetTileOwner(tt));
455  return;
456  }
457  }
458 
459  if (IsLevelCrossingTile(t)) {
460  /* else change the crossing to normal road (road vehicles won't care) */
461  Owner road = GetRoadOwner(t, RTT_ROAD);
462  Owner tram = GetRoadOwner(t, RTT_TRAM);
463  RoadBits bits = GetCrossingRoadBits(t);
464  bool hasroad = HasBit(_me[t].m7, 6);
465  bool hastram = HasBit(_me[t].m7, 7);
466 
467  /* MakeRoadNormal */
468  SetTileType(t, MP_ROAD);
469  SetTileOwner(t, road);
470  _m[t].m3 = (hasroad ? bits : 0);
471  _m[t].m5 = (hastram ? bits : 0) | ROAD_TILE_NORMAL << 6;
472  SB(_me[t].m6, 2, 4, 0);
473  SetRoadOwner(t, RTT_TRAM, tram);
474  return;
475  }
476 
477  /* if it's not a crossing, make it clean land */
478  MakeClear(t, CLEAR_GRASS, 0);
479 }
480 
488 {
489  /* Compute place where this vehicle entered the tile */
490  int entry_x = v->x_pos;
491  int entry_y = v->y_pos;
492  switch (dir) {
493  case DIR_NE: entry_x |= TILE_UNIT_MASK; break;
494  case DIR_NW: entry_y |= TILE_UNIT_MASK; break;
495  case DIR_SW: entry_x &= ~TILE_UNIT_MASK; break;
496  case DIR_SE: entry_y &= ~TILE_UNIT_MASK; break;
497  case INVALID_DIR: break;
498  default: NOT_REACHED();
499  }
500  byte entry_z = GetSlopePixelZ(entry_x, entry_y);
501 
502  /* Compute middle of the tile. */
503  int middle_x = (v->x_pos & ~TILE_UNIT_MASK) + TILE_SIZE / 2;
504  int middle_y = (v->y_pos & ~TILE_UNIT_MASK) + TILE_SIZE / 2;
505  byte middle_z = GetSlopePixelZ(middle_x, middle_y);
506 
507  /* middle_z == entry_z, no height change. */
508  if (middle_z == entry_z) return 0;
509 
510  /* middle_z < entry_z, we are going downwards. */
511  if (middle_z < entry_z) return 1U << GVF_GOINGDOWN_BIT;
512 
513  /* middle_z > entry_z, we are going upwards. */
514  return 1U << GVF_GOINGUP_BIT;
515 }
516 
523 static inline bool MayHaveBridgeAbove(TileIndex t)
524 {
525  return IsTileType(t, MP_CLEAR) || IsTileType(t, MP_RAILWAY) || IsTileType(t, MP_ROAD) ||
527 }
528 
535 {
537 
538  TileIndex map_size = MapSize();
539 
540  extern TileIndex _cur_tileloop_tile; // From landscape.cpp.
541  /* The LFSR used in RunTileLoop iteration cannot have a zeroed state, make it non-zeroed. */
542  if (_cur_tileloop_tile == 0) _cur_tileloop_tile = 1;
543 
545 
547  GamelogTestMode();
548 
549  RebuildTownKdtree();
550  RebuildStationKdtree();
551  /* This needs to be done even before conversion, because some conversions will destroy objects
552  * that otherwise won't exist in the tree. */
553  RebuildViewportKdtree();
554 
556 
559  } else if (_network_dedicated && (_pause_mode & PM_PAUSED_ERROR) != 0) {
560  DEBUG(net, 0, "The loading savegame was paused due to an error state.");
561  DEBUG(net, 0, " The savegame cannot be used for multiplayer!");
562  /* Restore the signals */
564  return false;
565  } else if (!_networking || _network_server) {
566  /* If we are in single player, i.e. not networking, and loading the
567  * savegame or we are loading the savegame as network server we do
568  * not want to be bothered by being paused because of the automatic
569  * reason of a network server, e.g. joining clients or too few
570  * active clients. Note that resetting these values for a network
571  * client are very bad because then the client is going to execute
572  * the game loop when the server is not, i.e. it desyncs. */
574  }
575 
576  /* In very old versions, size of train stations was stored differently.
577  * They had swapped width and height if station was built along the Y axis.
578  * TTO and TTD used 3 bits for width/height, while OpenTTD used 4.
579  * Because the data stored by TTDPatch are unusable for rail stations > 7x7,
580  * recompute the width and height. Doing this unconditionally for all old
581  * savegames simplifies the code. */
583  for (Station *st : Station::Iterate()) {
584  st->train_station.w = st->train_station.h = 0;
585  }
586  for (TileIndex t = 0; t < map_size; t++) {
587  if (!IsTileType(t, MP_STATION)) continue;
588  if (_m[t].m5 > 7) continue; // is it a rail station tile?
589  Station *st = Station::Get(_m[t].m2);
590  assert(st->train_station.tile != 0);
591  int dx = TileX(t) - TileX(st->train_station.tile);
592  int dy = TileY(t) - TileY(st->train_station.tile);
593  assert(dx >= 0 && dy >= 0);
594  st->train_station.w = max<uint>(st->train_station.w, dx + 1);
595  st->train_station.h = max<uint>(st->train_station.h, dy + 1);
596  }
597  }
598 
601 
602  /* In old savegame versions, the heightlevel was coded in bits 0..3 of the type field */
603  for (TileIndex t = 0; t < map_size; t++) {
604  _m[t].height = GB(_m[t].type, 0, 4);
605  SB(_m[t].type, 0, 2, GB(_me[t].m6, 0, 2));
606  SB(_me[t].m6, 0, 2, 0);
607  if (MayHaveBridgeAbove(t)) {
608  SB(_m[t].type, 2, 2, GB(_me[t].m6, 6, 2));
609  SB(_me[t].m6, 6, 2, 0);
610  } else {
611  SB(_m[t].type, 2, 2, 0);
612  }
613  }
614  }
615 
616  /* in version 2.1 of the savegame, town owner was unified. */
617  if (IsSavegameVersionBefore(SLV_2, 1)) ConvertTownOwner();
618 
619  /* from version 4.1 of the savegame, exclusive rights are stored at towns */
620  if (IsSavegameVersionBefore(SLV_4, 1)) UpdateExclusiveRights();
621 
622  /* from version 4.2 of the savegame, currencies are in a different order */
623  if (IsSavegameVersionBefore(SLV_4, 2)) UpdateCurrencies();
624 
625  /* In old version there seems to be a problem that water is owned by
626  * OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current
627  * (4.3) version, so I just check when versions are older, and then
628  * walk through the whole map.. */
629  if (IsSavegameVersionBefore(SLV_4, 3)) {
630  for (TileIndex t = 0; t < map_size; t++) {
631  if (IsTileType(t, MP_WATER) && GetTileOwner(t) >= MAX_COMPANIES) {
633  }
634  }
635  }
636 
638  for (Company *c : Company::Iterate()) {
639  c->name = CopyFromOldName(c->name_1);
640  if (c->name != nullptr) c->name_1 = STR_SV_UNNAMED;
641  c->president_name = CopyFromOldName(c->president_name_1);
642  if (c->president_name != nullptr) c->president_name_1 = SPECSTR_PRESIDENT_NAME;
643  }
644 
645  for (Station *st : Station::Iterate()) {
646  st->name = CopyFromOldName(st->string_id);
647  /* generating new name would be too much work for little effect, use the station name fallback */
648  if (st->name != nullptr) st->string_id = STR_SV_STNAME_FALLBACK;
649  }
650 
651  for (Town *t : Town::Iterate()) {
652  t->name = CopyFromOldName(t->townnametype);
653  if (t->name != nullptr) t->townnametype = SPECSTR_TOWNNAME_START + _settings_game.game_creation.town_name;
654  }
655  }
656 
657  /* From this point the old names array is cleared. */
658  ResetOldNames();
659 
661  /* no station is determined by 'tile == INVALID_TILE' now (instead of '0') */
662  for (Station *st : Station::Iterate()) {
663  if (st->airport.tile == 0) st->airport.tile = INVALID_TILE;
664  if (st->train_station.tile == 0) st->train_station.tile = INVALID_TILE;
665  }
666 
667  /* the same applies to Company::location_of_HQ */
668  for (Company *c : Company::Iterate()) {
669  if (c->location_of_HQ == 0 || (IsSavegameVersionBefore(SLV_4) && c->location_of_HQ == 0xFFFF)) {
670  c->location_of_HQ = INVALID_TILE;
671  }
672  }
673  }
674 
675  /* convert road side to my format. */
677 
678  /* Check if all NewGRFs are present, we are very strict in MP mode */
680  for (GRFConfig *c = _grfconfig; c != nullptr; c = c->next) {
681  if (c->status == GCS_NOT_FOUND) {
682  GamelogGRFRemove(c->ident.grfid);
683  } else if (HasBit(c->flags, GCF_COMPATIBLE)) {
684  GamelogGRFCompatible(&c->ident);
685  }
686  }
687 
688  if (_networking && gcf_res != GLC_ALL_GOOD) {
689  SetSaveLoadError(STR_NETWORK_ERROR_CLIENT_NEWGRF_MISMATCH);
690  /* Restore the signals */
692  return false;
693  }
694 
695  switch (gcf_res) {
696  case GLC_COMPATIBLE: ShowErrorMessage(STR_NEWGRF_COMPATIBLE_LOAD_WARNING, INVALID_STRING_ID, WL_CRITICAL); break;
697  case GLC_NOT_FOUND: ShowErrorMessage(STR_NEWGRF_DISABLED_WARNING, INVALID_STRING_ID, WL_CRITICAL); _pause_mode = PM_PAUSED_ERROR; break;
698  default: break;
699  }
700 
701  /* The value of _date_fract got divided, so make sure that old games are converted correctly. */
703 
704  /* Update current year
705  * must be done before loading sprites as some newgrfs check it */
707 
708  /*
709  * Force the old behaviour for compatibility reasons with old savegames. As new
710  * settings can only be loaded from new savegames loading old savegames with new
711  * versions of OpenTTD will normally initialize settings newer than the savegame
712  * version with "new game" defaults which the player can define to their liking.
713  * For some settings we override that to keep the behaviour the same as when the
714  * game was saved.
715  *
716  * Note that there is no non-stop in here. This is because the setting could have
717  * either value in TTDPatch. To convert it properly the user has to make sure the
718  * right value has been chosen in the settings. Otherwise we will be converting
719  * it incorrectly in half of the times without a means to correct that.
720  */
729  }
735  }
741  }
748  }
749 
750  /* Load the sprites */
751  GfxLoadSprites();
753 
754  /* Copy temporary data to Engine pool */
756 
757  /* Connect front and rear engines of multiheaded trains and converts
758  * subtype to the new format */
760 
761  /* Connect front and rear engines of multiheaded trains */
763 
764  /* Fix the CargoPackets *and* fix the caches of CargoLists.
765  * If this isn't done before Stations and especially Vehicles are
766  * running their AfterLoad we might get in trouble. In the case of
767  * vehicles we could give the wrong (cached) count of items in a
768  * vehicle which causes different results when getting their caches
769  * filled; and that could eventually lead to desyncs. */
771 
772  /* Oilrig was moved from id 15 to 9. We have to do this conversion
773  * here as AfterLoadVehicles can check it indirectly via the newgrf
774  * code. */
776  for (Station *st : Station::Iterate()) {
777  if (st->airport.tile != INVALID_TILE && st->airport.type == 15) {
778  st->airport.type = AT_OILRIG;
779  }
780  }
781  }
782 
783  /* Update all vehicles */
784  AfterLoadVehicles(true);
785 
786  /* Make sure there is an AI attached to an AI company */
787  {
788  for (const Company *c : Company::Iterate()) {
789  if (c->is_ai && c->ai_instance == nullptr) AI::StartNew(c->index);
790  }
791  }
792 
793  /* make sure there is a town in the game */
794  if (_game_mode == GM_NORMAL && Town::GetNumItems() == 0) {
795  SetSaveLoadError(STR_ERROR_NO_TOWN_IN_SCENARIO);
796  /* Restore the signals */
798  return false;
799  }
800 
801  /* The void tiles on the southern border used to belong to a wrong class (pre 4.3).
802  * This problem appears in savegame version 21 too, see r3455. But after loading the
803  * savegame and saving again, the buggy map array could be converted to new savegame
804  * version. It didn't show up before r12070. */
805  if (IsSavegameVersionBefore(SLV_87)) UpdateVoidTiles();
806 
807  /* If Load Scenario / New (Scenario) Game is used,
808  * a company does not exist yet. So create one here.
809  * 1 exception: network-games. Those can have 0 companies
810  * But this exception is not true for non-dedicated network servers! */
812  DoStartupNewCompany(false);
815  }
816 
817  /* Fix the cache for cargo payments. */
818  for (CargoPayment *cp : CargoPayment::Iterate()) {
819  cp->front->cargo_payment = cp;
820  cp->current_station = cp->front->last_station_visited;
821  }
822 
824  /* Locks in very old savegames had OWNER_WATER as owner */
825  for (TileIndex t = 0; t < MapSize(); t++) {
826  switch (GetTileType(t)) {
827  default: break;
828 
829  case MP_WATER:
831  break;
832 
833  case MP_STATION: {
834  if (HasBit(_me[t].m6, 3)) SetBit(_me[t].m6, 2);
835  StationGfx gfx = GetStationGfx(t);
836  StationType st;
837  if ( IsInsideMM(gfx, 0, 8)) { // Rail station
838  st = STATION_RAIL;
839  SetStationGfx(t, gfx - 0);
840  } else if (IsInsideMM(gfx, 8, 67)) { // Airport
841  st = STATION_AIRPORT;
842  SetStationGfx(t, gfx - 8);
843  } else if (IsInsideMM(gfx, 67, 71)) { // Truck
844  st = STATION_TRUCK;
845  SetStationGfx(t, gfx - 67);
846  } else if (IsInsideMM(gfx, 71, 75)) { // Bus
847  st = STATION_BUS;
848  SetStationGfx(t, gfx - 71);
849  } else if (gfx == 75) { // Oil rig
850  st = STATION_OILRIG;
851  SetStationGfx(t, gfx - 75);
852  } else if (IsInsideMM(gfx, 76, 82)) { // Dock
853  st = STATION_DOCK;
854  SetStationGfx(t, gfx - 76);
855  } else if (gfx == 82) { // Buoy
856  st = STATION_BUOY;
857  SetStationGfx(t, gfx - 82);
858  } else if (IsInsideMM(gfx, 83, 168)) { // Extended airport
859  st = STATION_AIRPORT;
860  SetStationGfx(t, gfx - 83 + 67 - 8);
861  } else if (IsInsideMM(gfx, 168, 170)) { // Drive through truck
862  st = STATION_TRUCK;
864  } else if (IsInsideMM(gfx, 170, 172)) { // Drive through bus
865  st = STATION_BUS;
867  } else {
868  /* Restore the signals */
870  return false;
871  }
872  SB(_me[t].m6, 3, 3, st);
873  break;
874  }
875  }
876  }
877  }
878 
879  for (TileIndex t = 0; t < map_size; t++) {
880  switch (GetTileType(t)) {
881  case MP_STATION: {
883 
884  /* Set up station spread */
885  bst->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
886 
887  /* Waypoints don't have road stops/oil rigs in the old format */
888  if (!Station::IsExpected(bst)) break;
889  Station *st = Station::From(bst);
890 
891  switch (GetStationType(t)) {
892  case STATION_TRUCK:
893  case STATION_BUS:
895  /* Before version 5 you could not have more than 250 stations.
896  * Version 6 adds large maps, so you could only place 253*253
897  * road stops on a map (no freeform edges) = 64009. So, yes
898  * someone could in theory create such a full map to trigger
899  * this assertion, it's safe to assume that's only something
900  * theoretical and does not happen in normal games. */
901  assert(RoadStop::CanAllocateItem());
902 
903  /* From this version on there can be multiple road stops of the
904  * same type per station. Convert the existing stops to the new
905  * internal data structure. */
906  RoadStop *rs = new RoadStop(t);
907 
908  RoadStop **head =
909  IsTruckStop(t) ? &st->truck_stops : &st->bus_stops;
910  *head = rs;
911  }
912  break;
913 
914  case STATION_OILRIG: {
915  /* Very old savegames sometimes have phantom oil rigs, i.e.
916  * an oil rig which got shut down, but not completely removed from
917  * the map
918  */
919  TileIndex t1 = TILE_ADDXY(t, 0, 1);
920  if (IsTileType(t1, MP_INDUSTRY) &&
921  GetIndustryGfx(t1) == GFX_OILRIG_1) {
922  /* The internal encoding of oil rigs was changed twice.
923  * It was 3 (till 2.2) and later 5 (till 5.1).
924  * Setting it unconditionally does not hurt.
925  */
927  } else {
928  DeleteOilRig(t);
929  }
930  break;
931  }
932 
933  default: break;
934  }
935  break;
936  }
937 
938  default: break;
939  }
940  }
941 
942  /* In version 2.2 of the savegame, we have new airports, so status of all aircraft is reset.
943  * This has to be called after the oilrig airport_type update above ^^^ ! */
945 
946  /* In version 6.1 we put the town index in the map-array. To do this, we need
947  * to use m2 (16bit big), so we need to clean m2, and that is where this is
948  * all about ;) */
949  if (IsSavegameVersionBefore(SLV_6, 1)) {
950  for (TileIndex t = 0; t < map_size; t++) {
951  switch (GetTileType(t)) {
952  case MP_HOUSE:
953  _m[t].m4 = _m[t].m2;
955  break;
956 
957  case MP_ROAD:
958  _m[t].m4 |= (_m[t].m2 << 4);
959  if ((GB(_m[t].m5, 4, 2) == ROAD_TILE_CROSSING ? (Owner)_m[t].m3 : GetTileOwner(t)) == OWNER_TOWN) {
961  } else {
962  SetTownIndex(t, 0);
963  }
964  break;
965 
966  default: break;
967  }
968  }
969  }
970 
971  /* Force the freeform edges to false for old savegames. */
974  }
975 
976  /* From version 9.0, we update the max passengers of a town (was sometimes negative
977  * before that. */
979  for (Town *t : Town::Iterate()) UpdateTownMaxPass(t);
980  }
981 
982  /* From version 16.0, we included autorenew on engines, which are now saved, but
983  * of course, we do need to initialize them for older savegames. */
985  for (Company *c : Company::Iterate()) {
986  c->engine_renew_list = nullptr;
987  c->settings.engine_renew = false;
988  c->settings.engine_renew_months = 6;
989  c->settings.engine_renew_money = 100000;
990  }
991 
992  /* When loading a game, _local_company is not yet set to the correct value.
993  * However, in a dedicated server we are a spectator, so nothing needs to
994  * happen. In case we are not a dedicated server, the local company always
995  * becomes company 0, unless we are in the scenario editor where all the
996  * companies are 'invalid'.
997  */
999  if (!_network_dedicated && c != nullptr) {
1001  }
1002  }
1003 
1005  for (TileIndex t = 0; t < map_size; t++) {
1006  switch (GetTileType(t)) {
1007  case MP_RAILWAY:
1008  if (IsPlainRail(t)) {
1009  /* Swap ground type and signal type for plain rail tiles, so the
1010  * ground type uses the same bits as for depots and waypoints. */
1011  uint tmp = GB(_m[t].m4, 0, 4);
1012  SB(_m[t].m4, 0, 4, GB(_m[t].m2, 0, 4));
1013  SB(_m[t].m2, 0, 4, tmp);
1014  } else if (HasBit(_m[t].m5, 2)) {
1015  /* Split waypoint and depot rail type and remove the subtype. */
1016  ClrBit(_m[t].m5, 2);
1017  ClrBit(_m[t].m5, 6);
1018  }
1019  break;
1020 
1021  case MP_ROAD:
1022  /* Swap m3 and m4, so the track type for rail crossings is the
1023  * same as for normal rail. */
1024  Swap(_m[t].m3, _m[t].m4);
1025  break;
1026 
1027  default: break;
1028  }
1029  }
1030  }
1031 
1033  /* Added the RoadType */
1034  bool old_bridge = IsSavegameVersionBefore(SLV_42);
1035  for (TileIndex t = 0; t < map_size; t++) {
1036  switch (GetTileType(t)) {
1037  case MP_ROAD:
1038  SB(_m[t].m5, 6, 2, GB(_m[t].m5, 4, 2));
1039  switch (GetRoadTileType(t)) {
1040  default: SlErrorCorrupt("Invalid road tile type");
1041  case ROAD_TILE_NORMAL:
1042  SB(_m[t].m4, 0, 4, GB(_m[t].m5, 0, 4));
1043  SB(_m[t].m4, 4, 4, 0);
1044  SB(_me[t].m6, 2, 4, 0);
1045  break;
1046  case ROAD_TILE_CROSSING:
1047  SB(_m[t].m4, 5, 2, GB(_m[t].m5, 2, 2));
1048  break;
1049  case ROAD_TILE_DEPOT: break;
1050  }
1051  SB(_me[t].m7, 6, 2, 1); // Set pre-NRT road type bits for conversion later.
1052  break;
1053 
1054  case MP_STATION:
1055  if (IsRoadStop(t)) SB(_me[t].m7, 6, 2, 1);
1056  break;
1057 
1058  case MP_TUNNELBRIDGE:
1059  /* Middle part of "old" bridges */
1060  if (old_bridge && IsBridge(t) && HasBit(_m[t].m5, 6)) break;
1061  if (((old_bridge && IsBridge(t)) ? (TransportType)GB(_m[t].m5, 1, 2) : GetTunnelBridgeTransportType(t)) == TRANSPORT_ROAD) {
1062  SB(_me[t].m7, 6, 2, 1); // Set pre-NRT road type bits for conversion later.
1063  }
1064  break;
1065 
1066  default: break;
1067  }
1068  }
1069  }
1070 
1072  bool fix_roadtypes = !IsSavegameVersionBefore(SLV_61);
1073  bool old_bridge = IsSavegameVersionBefore(SLV_42);
1074 
1075  for (TileIndex t = 0; t < map_size; t++) {
1076  switch (GetTileType(t)) {
1077  case MP_ROAD:
1078  if (fix_roadtypes) SB(_me[t].m7, 6, 2, (RoadTypes)GB(_me[t].m7, 5, 3));
1079  SB(_me[t].m7, 5, 1, GB(_m[t].m3, 7, 1)); // snow/desert
1080  switch (GetRoadTileType(t)) {
1081  default: SlErrorCorrupt("Invalid road tile type");
1082  case ROAD_TILE_NORMAL:
1083  SB(_me[t].m7, 0, 4, GB(_m[t].m3, 0, 4)); // road works
1084  SB(_me[t].m6, 3, 3, GB(_m[t].m3, 4, 3)); // ground
1085  SB(_m[t].m3, 0, 4, GB(_m[t].m4, 4, 4)); // tram bits
1086  SB(_m[t].m3, 4, 4, GB(_m[t].m5, 0, 4)); // tram owner
1087  SB(_m[t].m5, 0, 4, GB(_m[t].m4, 0, 4)); // road bits
1088  break;
1089 
1090  case ROAD_TILE_CROSSING:
1091  SB(_me[t].m7, 0, 5, GB(_m[t].m4, 0, 5)); // road owner
1092  SB(_me[t].m6, 3, 3, GB(_m[t].m3, 4, 3)); // ground
1093  SB(_m[t].m3, 4, 4, GB(_m[t].m5, 0, 4)); // tram owner
1094  SB(_m[t].m5, 0, 1, GB(_m[t].m4, 6, 1)); // road axis
1095  SB(_m[t].m5, 5, 1, GB(_m[t].m4, 5, 1)); // crossing state
1096  break;
1097 
1098  case ROAD_TILE_DEPOT:
1099  break;
1100  }
1101  if (!IsRoadDepot(t) && !HasTownOwnedRoad(t)) {
1102  const Town *town = CalcClosestTownFromTile(t);
1103  if (town != nullptr) SetTownIndex(t, town->index);
1104  }
1105  _m[t].m4 = 0;
1106  break;
1107 
1108  case MP_STATION:
1109  if (!IsRoadStop(t)) break;
1110 
1111  if (fix_roadtypes) SB(_me[t].m7, 6, 2, (RoadTypes)GB(_m[t].m3, 0, 3));
1112  SB(_me[t].m7, 0, 5, HasBit(_me[t].m6, 2) ? OWNER_TOWN : GetTileOwner(t));
1113  SB(_m[t].m3, 4, 4, _m[t].m1);
1114  _m[t].m4 = 0;
1115  break;
1116 
1117  case MP_TUNNELBRIDGE:
1118  if (old_bridge && IsBridge(t) && HasBit(_m[t].m5, 6)) break;
1119  if (((old_bridge && IsBridge(t)) ? (TransportType)GB(_m[t].m5, 1, 2) : GetTunnelBridgeTransportType(t)) == TRANSPORT_ROAD) {
1120  if (fix_roadtypes) SB(_me[t].m7, 6, 2, (RoadTypes)GB(_m[t].m3, 0, 3));
1121 
1122  Owner o = GetTileOwner(t);
1123  SB(_me[t].m7, 0, 5, o); // road owner
1124  SB(_m[t].m3, 4, 4, o == OWNER_NONE ? OWNER_TOWN : o); // tram owner
1125  }
1126  SB(_me[t].m6, 2, 4, GB(_m[t].m2, 4, 4)); // bridge type
1127  SB(_me[t].m7, 5, 1, GB(_m[t].m4, 7, 1)); // snow/desert
1128 
1129  _m[t].m2 = 0;
1130  _m[t].m4 = 0;
1131  break;
1132 
1133  default: break;
1134  }
1135  }
1136  }
1137 
1138  /* Railtype moved from m3 to m8 in version SLV_EXTEND_RAILTYPES. */
1140  for (TileIndex t = 0; t < map_size; t++) {
1141  switch (GetTileType(t)) {
1142  case MP_RAILWAY:
1143  SetRailType(t, (RailType)GB(_m[t].m3, 0, 4));
1144  break;
1145 
1146  case MP_ROAD:
1147  if (IsLevelCrossing(t)) {
1148  SetRailType(t, (RailType)GB(_m[t].m3, 0, 4));
1149  }
1150  break;
1151 
1152  case MP_STATION:
1153  if (HasStationRail(t)) {
1154  SetRailType(t, (RailType)GB(_m[t].m3, 0, 4));
1155  }
1156  break;
1157 
1158  case MP_TUNNELBRIDGE:
1160  SetRailType(t, (RailType)GB(_m[t].m3, 0, 4));
1161  }
1162  break;
1163 
1164  default:
1165  break;
1166  }
1167  }
1168  }
1169 
1171  for (TileIndex t = 0; t < map_size; t++) {
1173  if (IsBridgeTile(t)) {
1174  if (HasBit(_m[t].m5, 6)) { // middle part
1175  Axis axis = (Axis)GB(_m[t].m5, 0, 1);
1176 
1177  if (HasBit(_m[t].m5, 5)) { // transport route under bridge?
1178  if (GB(_m[t].m5, 3, 2) == TRANSPORT_RAIL) {
1179  MakeRailNormal(
1180  t,
1181  GetTileOwner(t),
1182  axis == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X,
1183  GetRailType(t)
1184  );
1185  } else {
1186  TownID town = IsTileOwner(t, OWNER_TOWN) ? ClosestTownFromTile(t, UINT_MAX)->index : 0;
1187 
1188  /* MakeRoadNormal */
1189  SetTileType(t, MP_ROAD);
1190  _m[t].m2 = town;
1191  _m[t].m3 = 0;
1192  _m[t].m5 = (axis == AXIS_X ? ROAD_Y : ROAD_X) | ROAD_TILE_NORMAL << 6;
1193  SB(_me[t].m6, 2, 4, 0);
1194  _me[t].m7 = 1 << 6;
1195  SetRoadOwner(t, RTT_TRAM, OWNER_NONE);
1196  }
1197  } else {
1198  if (GB(_m[t].m5, 3, 2) == 0) {
1199  MakeClear(t, CLEAR_GRASS, 3);
1200  } else {
1201  if (!IsTileFlat(t)) {
1202  MakeShore(t);
1203  } else {
1204  if (GetTileOwner(t) == OWNER_WATER) {
1205  MakeSea(t);
1206  } else {
1207  MakeCanal(t, GetTileOwner(t), Random());
1208  }
1209  }
1210  }
1211  }
1212  SetBridgeMiddle(t, axis);
1213  } else { // ramp
1214  Axis axis = (Axis)GB(_m[t].m5, 0, 1);
1215  uint north_south = GB(_m[t].m5, 5, 1);
1216  DiagDirection dir = ReverseDiagDir(XYNSToDiagDir(axis, north_south));
1217  TransportType type = (TransportType)GB(_m[t].m5, 1, 2);
1218 
1219  _m[t].m5 = 1 << 7 | type << 2 | dir;
1220  }
1221  }
1222  }
1223 
1224  for (Vehicle* v : Vehicle::Iterate()) {
1225  if (!v->IsGroundVehicle()) continue;
1226  if (IsBridgeTile(v->tile)) {
1227  DiagDirection dir = GetTunnelBridgeDirection(v->tile);
1228 
1229  if (dir != DirToDiagDir(v->direction)) continue;
1230  switch (dir) {
1231  default: SlErrorCorrupt("Invalid vehicle direction");
1232  case DIAGDIR_NE: if ((v->x_pos & 0xF) != 0) continue; break;
1233  case DIAGDIR_SE: if ((v->y_pos & 0xF) != TILE_SIZE - 1) continue; break;
1234  case DIAGDIR_SW: if ((v->x_pos & 0xF) != TILE_SIZE - 1) continue; break;
1235  case DIAGDIR_NW: if ((v->y_pos & 0xF) != 0) continue; break;
1236  }
1237  } else if (v->z_pos > GetSlopePixelZ(v->x_pos, v->y_pos)) {
1238  v->tile = GetNorthernBridgeEnd(v->tile);
1239  } else {
1240  continue;
1241  }
1242  if (v->type == VEH_TRAIN) {
1243  Train::From(v)->track = TRACK_BIT_WORMHOLE;
1244  } else {
1246  }
1247  }
1248  }
1249 
1251  /* Add road subtypes */
1252  for (TileIndex t = 0; t < map_size; t++) {
1253  bool has_road = false;
1254  switch (GetTileType(t)) {
1255  case MP_ROAD:
1256  has_road = true;
1257  break;
1258  case MP_STATION:
1259  has_road = IsRoadStop(t);
1260  break;
1261  case MP_TUNNELBRIDGE:
1263  break;
1264  default:
1265  break;
1266  }
1267 
1268  if (has_road) {
1269  RoadType road_rt = HasBit(_me[t].m7, 6) ? ROADTYPE_ROAD : INVALID_ROADTYPE;
1270  RoadType tram_rt = HasBit(_me[t].m7, 7) ? ROADTYPE_TRAM : INVALID_ROADTYPE;
1271 
1272  assert(road_rt != INVALID_ROADTYPE || tram_rt != INVALID_ROADTYPE);
1273  SetRoadTypes(t, road_rt, tram_rt);
1274  SB(_me[t].m7, 6, 2, 0); // Clear pre-NRT road type bits.
1275  }
1276  }
1277  }
1278 
1279  /* Elrails got added in rev 24 */
1281  RailType min_rail = RAILTYPE_ELECTRIC;
1282 
1283  for (Train *v : Train::Iterate()) {
1284  RailType rt = RailVehInfo(v->engine_type)->railtype;
1285 
1286  v->railtype = rt;
1287  if (rt == RAILTYPE_ELECTRIC) min_rail = RAILTYPE_RAIL;
1288  }
1289 
1290  /* .. so we convert the entire map from normal to elrail (so maintain "fairness") */
1291  for (TileIndex t = 0; t < map_size; t++) {
1292  switch (GetTileType(t)) {
1293  case MP_RAILWAY:
1294  SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
1295  break;
1296 
1297  case MP_ROAD:
1298  if (IsLevelCrossing(t)) {
1299  SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
1300  }
1301  break;
1302 
1303  case MP_STATION:
1304  if (HasStationRail(t)) {
1305  SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
1306  }
1307  break;
1308 
1309  case MP_TUNNELBRIDGE:
1311  SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
1312  }
1313  break;
1314 
1315  default:
1316  break;
1317  }
1318  }
1319 
1320  for (Train *v : Train::Iterate()) {
1321  if (v->IsFrontEngine() || v->IsFreeWagon()) v->ConsistChanged(CCF_TRACK);
1322  }
1323 
1324  }
1325 
1326  /* In version 16.1 of the savegame a company can decide if trains, which get
1327  * replaced, shall keep their old length. In all prior versions, just default
1328  * to false */
1329  if (IsSavegameVersionBefore(SLV_16, 1)) {
1330  for (Company *c : Company::Iterate()) c->settings.renew_keep_length = false;
1331  }
1332 
1334  /* Waypoints became subclasses of stations ... */
1336  /* ... and buoys were moved to waypoints. */
1338  }
1339 
1340  /* From version 15, we moved a semaphore bit from bit 2 to bit 3 in m4, making
1341  * room for PBS. Now in version 21 move it back :P. */
1343  for (TileIndex t = 0; t < map_size; t++) {
1344  switch (GetTileType(t)) {
1345  case MP_RAILWAY:
1346  if (HasSignals(t)) {
1347  /* Original signal type/variant was stored in m4 but since saveload
1348  * version 48 they are in m2. The bits has been already moved to m2
1349  * (see the code somewhere above) so don't use m4, use m2 instead. */
1350 
1351  /* convert PBS signals to combo-signals */
1352  if (HasBit(_m[t].m2, 2)) SB(_m[t].m2, 0, 2, SIGTYPE_COMBO);
1353 
1354  /* move the signal variant back */
1355  SB(_m[t].m2, 2, 1, HasBit(_m[t].m2, 3) ? SIG_SEMAPHORE : SIG_ELECTRIC);
1356  ClrBit(_m[t].m2, 3);
1357  }
1358 
1359  /* Clear PBS reservation on track */
1360  if (!IsRailDepotTile(t)) {
1361  SB(_m[t].m4, 4, 4, 0);
1362  } else {
1363  ClrBit(_m[t].m3, 6);
1364  }
1365  break;
1366 
1367  case MP_STATION: // Clear PBS reservation on station
1368  ClrBit(_m[t].m3, 6);
1369  break;
1370 
1371  default: break;
1372  }
1373  }
1374  }
1375 
1377  for (RoadVehicle *rv : RoadVehicle::Iterate()) {
1378  rv->vehstatus &= ~0x40;
1379  }
1380  }
1381 
1383  for (Station *st : Station::Iterate()) {
1384  st->last_vehicle_type = VEH_INVALID;
1385  }
1386  }
1387 
1389 
1392  }
1393 
1394  for (Company *c : Company::Iterate()) {
1395  c->avail_railtypes = GetCompanyRailtypes(c->index);
1396  c->avail_roadtypes = GetCompanyRoadTypes(c->index);
1397  }
1398 
1399  if (!IsSavegameVersionBefore(SLV_27)) AfterLoadStations();
1400 
1401  /* Time starts at 0 instead of 1920.
1402  * Account for this in older games by adding an offset */
1406 
1407  for (Station *st : Station::Iterate()) st->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
1408  for (Waypoint *wp : Waypoint::Iterate()) wp->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
1409  for (Engine *e : Engine::Iterate()) e->intro_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
1410  for (Company *c : Company::Iterate()) c->inaugurated_year += ORIGINAL_BASE_YEAR;
1411  for (Industry *i : Industry::Iterate()) i->last_prod_year += ORIGINAL_BASE_YEAR;
1412 
1413  for (Vehicle *v : Vehicle::Iterate()) {
1414  v->date_of_last_service += DAYS_TILL_ORIGINAL_BASE_YEAR;
1415  v->build_year += ORIGINAL_BASE_YEAR;
1416  }
1417  }
1418 
1419  /* From 32 on we save the industry who made the farmland.
1420  * To give this prettiness to old savegames, we remove all farmfields and
1421  * plant new ones. */
1423  for (TileIndex t = 0; t < map_size; t++) {
1424  if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_FIELDS)) {
1425  /* remove fields */
1426  MakeClear(t, CLEAR_GRASS, 3);
1427  }
1428  }
1429 
1430  for (Industry *i : Industry::Iterate()) {
1431  uint j;
1432 
1434  for (j = 0; j != 50; j++) PlantRandomFarmField(i);
1435  }
1436  }
1437  }
1438 
1439  /* Setting no refit flags to all orders in savegames from before refit in orders were added */
1441  for (Order *order : Order::Iterate()) {
1442  order->SetRefit(CT_NO_REFIT);
1443  }
1444 
1445  for (Vehicle *v : Vehicle::Iterate()) {
1446  v->current_order.SetRefit(CT_NO_REFIT);
1447  }
1448  }
1449 
1450  /* from version 38 we have optional elrails, since we cannot know the
1451  * preference of a user, let elrails enabled; it can be disabled manually */
1453  /* do the same as when elrails were enabled/disabled manually just now */
1456 
1457  /* From version 53, the map array was changed for house tiles to allow
1458  * space for newhouses grf features. A new byte, m7, was also added. */
1460  for (TileIndex t = 0; t < map_size; t++) {
1461  if (IsTileType(t, MP_HOUSE)) {
1462  if (GB(_m[t].m3, 6, 2) != TOWN_HOUSE_COMPLETED) {
1463  /* Move the construction stage from m3[7..6] to m5[5..4].
1464  * The construction counter does not have to move. */
1465  SB(_m[t].m5, 3, 2, GB(_m[t].m3, 6, 2));
1466  SB(_m[t].m3, 6, 2, 0);
1467 
1468  /* The "house is completed" bit is now in m6[2]. */
1469  SetHouseCompleted(t, false);
1470  } else {
1471  /* The "lift has destination" bit has been moved from
1472  * m5[7] to m7[0]. */
1473  SB(_me[t].m7, 0, 1, HasBit(_m[t].m5, 7));
1474  ClrBit(_m[t].m5, 7);
1475 
1476  /* The "lift is moving" bit has been removed, as it does
1477  * the same job as the "lift has destination" bit. */
1478  ClrBit(_m[t].m1, 7);
1479 
1480  /* The position of the lift goes from m1[7..0] to m6[7..2],
1481  * making m1 totally free, now. The lift position does not
1482  * have to be a full byte since the maximum value is 36. */
1483  SetLiftPosition(t, GB(_m[t].m1, 0, 6 ));
1484 
1485  _m[t].m1 = 0;
1486  _m[t].m3 = 0;
1487  SetHouseCompleted(t, true);
1488  }
1489  }
1490  }
1491  }
1492 
1493  /* Check and update house and town values */
1495 
1497  for (TileIndex t = 0; t < map_size; t++) {
1498  if (IsTileType(t, MP_INDUSTRY)) {
1499  switch (GetIndustryGfx(t)) {
1500  case GFX_POWERPLANT_SPARKS:
1501  _m[t].m3 = GB(_m[t].m1, 2, 5);
1502  break;
1503 
1504  case GFX_OILWELL_ANIMATED_1:
1505  case GFX_OILWELL_ANIMATED_2:
1506  case GFX_OILWELL_ANIMATED_3:
1507  _m[t].m3 = GB(_m[t].m1, 0, 2);
1508  break;
1509 
1510  case GFX_COAL_MINE_TOWER_ANIMATED:
1511  case GFX_COPPER_MINE_TOWER_ANIMATED:
1512  case GFX_GOLD_MINE_TOWER_ANIMATED:
1513  _m[t].m3 = _m[t].m1;
1514  break;
1515 
1516  default: // No animation states to change
1517  break;
1518  }
1519  }
1520  }
1521  }
1522 
1524  /* Originally just the fact that some cargo had been paid for was
1525  * stored to stop people cheating and cashing in several times. This
1526  * wasn't enough though as it was cleared when the vehicle started
1527  * loading again, even if it didn't actually load anything, so now the
1528  * amount that has been paid is stored. */
1529  for (Vehicle *v : Vehicle::Iterate()) {
1530  ClrBit(v->vehicle_flags, 2);
1531  }
1532  }
1533 
1534  /* Buoys do now store the owner of the previous water tile, which can never
1535  * be OWNER_NONE. So replace OWNER_NONE with OWNER_WATER. */
1537  for (Waypoint *wp : Waypoint::Iterate()) {
1538  if ((wp->facilities & FACIL_DOCK) != 0 && IsTileOwner(wp->xy, OWNER_NONE) && TileHeight(wp->xy) == 0) SetTileOwner(wp->xy, OWNER_WATER);
1539  }
1540  }
1541 
1543  /* Aircraft units changed from 8 mph to 1 km-ish/h */
1544  for (Aircraft *v : Aircraft::Iterate()) {
1545  if (v->subtype <= AIR_AIRCRAFT) {
1546  const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
1547  v->cur_speed *= 128;
1548  v->cur_speed /= 10;
1549  v->acceleration = avi->acceleration;
1550  }
1551  }
1552  }
1553 
1555 
1557  for (TileIndex t = 0; t < map_size; t++) {
1558  if (IsTileType(t, MP_OBJECT) && _m[t].m5 == OBJECT_STATUE) {
1560  }
1561  }
1562  }
1563 
1564  /* A setting containing the proportion of towns that grow twice as
1565  * fast was added in version 54. From version 56 this is now saved in the
1566  * town as cities can be built specifically in the scenario editor. */
1568  for (Town *t : Town::Iterate()) {
1569  if (_settings_game.economy.larger_towns != 0 && (t->index % _settings_game.economy.larger_towns) == 0) {
1570  t->larger_town = true;
1571  }
1572  }
1573  }
1574 
1576  /* Added a FIFO queue of vehicles loading at stations */
1577  for (Vehicle *v : Vehicle::Iterate()) {
1578  if ((v->type != VEH_TRAIN || Train::From(v)->IsFrontEngine()) && // for all locs
1579  !(v->vehstatus & (VS_STOPPED | VS_CRASHED)) && // not stopped or crashed
1580  v->current_order.IsType(OT_LOADING)) { // loading
1581  Station::Get(v->last_station_visited)->loading_vehicles.push_back(v);
1582 
1583  /* The loading finished flag is *only* set when actually completely
1584  * finished. Because the vehicle is loading, it is not finished. */
1585  ClrBit(v->vehicle_flags, VF_LOADING_FINISHED);
1586  }
1587  }
1588  } else if (IsSavegameVersionBefore(SLV_59)) {
1589  /* For some reason non-loading vehicles could be in the station's loading vehicle list */
1590 
1591  for (Station *st : Station::Iterate()) {
1592  std::list<Vehicle *>::iterator iter;
1593  for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end();) {
1594  Vehicle *v = *iter;
1595  iter++;
1596  if (!v->current_order.IsType(OT_LOADING)) st->loading_vehicles.remove(v);
1597  }
1598  }
1599  }
1600 
1602  /* Setting difficulty industry_density other than zero get bumped to +1
1603  * since a new option (very low at position 1) has been added */
1606  }
1607 
1608  /* Same goes for number of towns, although no test is needed, just an increment */
1610  }
1611 
1613  /* Since now we allow different signal types and variants on a single tile.
1614  * Move signal states to m4 to make room and clone the signal type/variant. */
1615  for (TileIndex t = 0; t < map_size; t++) {
1616  if (IsTileType(t, MP_RAILWAY) && HasSignals(t)) {
1617  /* move signal states */
1618  SetSignalStates(t, GB(_m[t].m2, 4, 4));
1619  SB(_m[t].m2, 4, 4, 0);
1620  /* clone signal type and variant */
1621  SB(_m[t].m2, 4, 3, GB(_m[t].m2, 0, 3));
1622  }
1623  }
1624  }
1625 
1627  /* In some old savegames a bit was cleared when it should not be cleared */
1628  for (RoadVehicle *rv : RoadVehicle::Iterate()) {
1629  if (rv->state == 250 || rv->state == 251) {
1630  SetBit(rv->state, 2);
1631  }
1632  }
1633  }
1634 
1636  /* Added variables to support newindustries */
1637  for (Industry *i : Industry::Iterate()) i->founder = OWNER_NONE;
1638  }
1639 
1640  /* From version 82, old style canals (above sealevel (0), WATER owner) are no longer supported.
1641  Replace the owner for those by OWNER_NONE. */
1643  for (TileIndex t = 0; t < map_size; t++) {
1644  if (IsTileType(t, MP_WATER) &&
1646  GetTileOwner(t) == OWNER_WATER &&
1647  TileHeight(t) != 0) {
1649  }
1650  }
1651  }
1652 
1653  /*
1654  * Add the 'previous' owner to the ship depots so we can reset it with
1655  * the correct values when it gets destroyed. This prevents that
1656  * someone can remove canals owned by somebody else and it prevents
1657  * making floods using the removal of ship depots.
1658  */
1660  for (TileIndex t = 0; t < map_size; t++) {
1661  if (IsShipDepotTile(t)) {
1662  _m[t].m4 = (TileHeight(t) == 0) ? OWNER_WATER : OWNER_NONE;
1663  }
1664  }
1665  }
1666 
1668  for (Station *st : Station::Iterate()) {
1669  for (CargoID c = 0; c < NUM_CARGO; c++) {
1670  st->goods[c].last_speed = 0;
1671  if (st->goods[c].cargo.AvailableCount() != 0) SetBit(st->goods[c].status, GoodsEntry::GES_RATING);
1672  }
1673  }
1674  }
1675 
1677  uint j;
1678  for (Industry * i : Industry::Iterate()) {
1679  const IndustrySpec *indsp = GetIndustrySpec(i->type);
1680  for (j = 0; j < lengthof(i->produced_cargo); j++) {
1681  i->produced_cargo[j] = indsp->produced_cargo[j];
1682  }
1683  for (j = 0; j < lengthof(i->accepts_cargo); j++) {
1684  i->accepts_cargo[j] = indsp->accepts_cargo[j];
1685  }
1686  }
1687  }
1688 
1689  /* Before version 81, the density of grass was always stored as zero, and
1690  * grassy trees were always drawn fully grassy. Furthermore, trees on rough
1691  * land used to have zero density, now they have full density. Therefore,
1692  * make all grassy/rough land trees have a density of 3. */
1694  for (TileIndex t = 0; t < map_size; t++) {
1695  if (GetTileType(t) == MP_TREES) {
1696  TreeGround groundType = (TreeGround)GB(_m[t].m2, 4, 2);
1697  if (groundType != TREE_GROUND_SNOW_DESERT) SB(_m[t].m2, 6, 2, 3);
1698  }
1699  }
1700  }
1701 
1702 
1704  /* Rework of orders. */
1705  for (Order *order : Order::Iterate()) order->ConvertFromOldSavegame();
1706 
1707  for (Vehicle *v : Vehicle::Iterate()) {
1708  if (v->orders.list != nullptr && v->orders.list->GetFirstOrder() != nullptr && v->orders.list->GetFirstOrder()->IsType(OT_NOTHING)) {
1709  v->orders.list->FreeChain();
1710  v->orders.list = nullptr;
1711  }
1712 
1713  v->current_order.ConvertFromOldSavegame();
1714  if (v->type == VEH_ROAD && v->IsPrimaryVehicle() && v->FirstShared() == v) {
1715  Order* order;
1716  FOR_VEHICLE_ORDERS(v, order) order->SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
1717  }
1718  }
1719  } else if (IsSavegameVersionBefore(SLV_94)) {
1720  /* Unload and transfer are now mutual exclusive. */
1721  for (Order *order : Order::Iterate()) {
1722  if ((order->GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) == (OUFB_UNLOAD | OUFB_TRANSFER)) {
1723  order->SetUnloadType(OUFB_TRANSFER);
1724  order->SetLoadType(OLFB_NO_LOAD);
1725  }
1726  }
1727 
1728  for (Vehicle *v : Vehicle::Iterate()) {
1729  if ((v->current_order.GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) == (OUFB_UNLOAD | OUFB_TRANSFER)) {
1730  v->current_order.SetUnloadType(OUFB_TRANSFER);
1731  v->current_order.SetLoadType(OLFB_NO_LOAD);
1732  }
1733  }
1734  }
1735 
1737  /* Set all share owners to INVALID_COMPANY for
1738  * 1) all inactive companies
1739  * (when inactive companies were stored in the savegame - TTD, TTDP and some
1740  * *really* old revisions of OTTD; else it is already set in InitializeCompanies())
1741  * 2) shares that are owned by inactive companies or self
1742  * (caused by cheating clients in earlier revisions) */
1743  for (Company *c : Company::Iterate()) {
1744  for (uint i = 0; i < 4; i++) {
1745  CompanyID company = c->share_owners[i];
1746  if (company == INVALID_COMPANY) continue;
1747  if (!Company::IsValidID(company) || company == c->index) c->share_owners[i] = INVALID_COMPANY;
1748  }
1749  }
1750  }
1751 
1752  /* The water class was moved/unified. */
1754  for (TileIndex t = 0; t < map_size; t++) {
1755  switch (GetTileType(t)) {
1756  case MP_STATION:
1757  switch (GetStationType(t)) {
1758  case STATION_OILRIG:
1759  case STATION_DOCK:
1760  case STATION_BUOY:
1761  SetWaterClass(t, (WaterClass)GB(_m[t].m3, 0, 2));
1762  SB(_m[t].m3, 0, 2, 0);
1763  break;
1764 
1765  default:
1767  break;
1768  }
1769  break;
1770 
1771  case MP_WATER:
1772  SetWaterClass(t, (WaterClass)GB(_m[t].m3, 0, 2));
1773  SB(_m[t].m3, 0, 2, 0);
1774  break;
1775 
1776  case MP_OBJECT:
1778  break;
1779 
1780  default:
1781  /* No water class. */
1782  break;
1783  }
1784  }
1785  }
1786 
1788  for (TileIndex t = 0; t < map_size; t++) {
1789  /* Move river flag and update canals to use water class */
1790  if (IsTileType(t, MP_WATER)) {
1791  if (GetWaterClass(t) != WATER_CLASS_RIVER) {
1792  if (IsWater(t)) {
1793  Owner o = GetTileOwner(t);
1794  if (o == OWNER_WATER) {
1795  MakeSea(t);
1796  } else {
1797  MakeCanal(t, o, Random());
1798  }
1799  } else if (IsShipDepot(t)) {
1800  Owner o = (Owner)_m[t].m4; // Original water owner
1802  }
1803  }
1804  }
1805  }
1806 
1807  /* Update locks, depots, docks and buoys to have a water class based
1808  * on its neighbouring tiles. Done after river and canal updates to
1809  * ensure neighbours are correct. */
1810  for (TileIndex t = 0; t < map_size; t++) {
1811  if (!IsTileFlat(t)) continue;
1812 
1814  if (IsTileType(t, MP_STATION) && (IsDock(t) || IsBuoy(t))) SetWaterClassDependingOnSurroundings(t, false);
1815  }
1816  }
1817 
1819  for (TileIndex t = 0; t < map_size; t++) {
1820  /* skip oil rigs at borders! */
1821  if ((IsTileType(t, MP_WATER) || IsBuoyTile(t)) &&
1822  (TileX(t) == 0 || TileY(t) == 0 || TileX(t) == MapMaxX() - 1 || TileY(t) == MapMaxY() - 1)) {
1823  /* Some version 86 savegames have wrong water class at map borders (under buoy, or after removing buoy).
1824  * This conversion has to be done before buoys with invalid owner are removed. */
1826  }
1827 
1828  if (IsBuoyTile(t) || IsDriveThroughStopTile(t) || IsTileType(t, MP_WATER)) {
1829  Owner o = GetTileOwner(t);
1830  if (o < MAX_COMPANIES && !Company::IsValidID(o)) {
1831  Backup<CompanyID> cur_company(_current_company, o, FILE_LINE);
1833  cur_company.Restore();
1834  }
1835  if (IsBuoyTile(t)) {
1836  /* reset buoy owner to OWNER_NONE in the station struct
1837  * (even if it is owned by active company) */
1839  }
1840  } else if (IsTileType(t, MP_ROAD)) {
1841  /* works for all RoadTileType */
1842  FOR_ALL_ROADTRAMTYPES(rtt) {
1843  /* update even non-existing road types to update tile owner too */
1844  Owner o = GetRoadOwner(t, rtt);
1845  if (o < MAX_COMPANIES && !Company::IsValidID(o)) SetRoadOwner(t, rtt, OWNER_NONE);
1846  }
1847  if (IsLevelCrossing(t)) {
1849  }
1850  } else if (IsPlainRailTile(t)) {
1852  }
1853  }
1854 
1855  /* Convert old PF settings to new */
1858  } else {
1860  }
1861 
1864  } else {
1866  }
1867 
1870  } else {
1872  }
1873  }
1874 
1876  /* Profits are now with 8 bit fract */
1877  for (Vehicle *v : Vehicle::Iterate()) {
1878  v->profit_this_year <<= 8;
1879  v->profit_last_year <<= 8;
1880  v->running_ticks = 0;
1881  }
1882  }
1883 
1885  /* Increase HouseAnimationFrame from 5 to 7 bits */
1886  for (TileIndex t = 0; t < map_size; t++) {
1887  if (IsTileType(t, MP_HOUSE) && GetHouseType(t) >= NEW_HOUSE_OFFSET) {
1888  SB(_me[t].m6, 2, 6, GB(_me[t].m6, 3, 5));
1889  SB(_m[t].m3, 5, 1, 0);
1890  }
1891  }
1892  }
1893 
1895  GroupStatistics::UpdateAfterLoad(); // Ensure statistics pool is initialised before trying to delete vehicles
1896  /* Remove all trams from savegames without tram support.
1897  * There would be trams without tram track under causing crashes sooner or later. */
1898  for (RoadVehicle *v : RoadVehicle::Iterate()) {
1899  if (v->First() == v && HasBit(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM)) {
1900  ShowErrorMessage(STR_WARNING_LOADGAME_REMOVED_TRAMS, INVALID_STRING_ID, WL_CRITICAL);
1901  delete v;
1902  }
1903  }
1904  }
1905 
1907  for (TileIndex t = 0; t < map_size; t++) {
1908  /* Set newly introduced WaterClass of industry tiles */
1909  if (IsTileType(t, MP_STATION) && IsOilRig(t)) {
1911  }
1912  if (IsTileType(t, MP_INDUSTRY)) {
1913  if ((GetIndustrySpec(GetIndustryType(t))->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0) {
1915  } else {
1917  }
1918  }
1919 
1920  /* Replace "house construction year" with "house age" */
1921  if (IsTileType(t, MP_HOUSE) && IsHouseCompleted(t)) {
1922  _m[t].m5 = Clamp(_cur_year - (_m[t].m5 + ORIGINAL_BASE_YEAR), 0, 0xFF);
1923  }
1924  }
1925  }
1926 
1927  /* Move the signal variant back up one bit for PBS. We don't convert the old PBS
1928  * format here, as an old layout wouldn't work properly anyway. To be safe, we
1929  * clear any possible PBS reservations as well. */
1931  for (TileIndex t = 0; t < map_size; t++) {
1932  switch (GetTileType(t)) {
1933  case MP_RAILWAY:
1934  if (HasSignals(t)) {
1935  /* move the signal variant */
1936  SetSignalVariant(t, TRACK_UPPER, HasBit(_m[t].m2, 2) ? SIG_SEMAPHORE : SIG_ELECTRIC);
1937  SetSignalVariant(t, TRACK_LOWER, HasBit(_m[t].m2, 6) ? SIG_SEMAPHORE : SIG_ELECTRIC);
1938  ClrBit(_m[t].m2, 2);
1939  ClrBit(_m[t].m2, 6);
1940  }
1941 
1942  /* Clear PBS reservation on track */
1943  if (IsRailDepot(t)) {
1944  SetDepotReservation(t, false);
1945  } else {
1947  }
1948  break;
1949 
1950  case MP_ROAD: // Clear PBS reservation on crossing
1951  if (IsLevelCrossing(t)) SetCrossingReservation(t, false);
1952  break;
1953 
1954  case MP_STATION: // Clear PBS reservation on station
1955  if (HasStationRail(t)) SetRailStationReservation(t, false);
1956  break;
1957 
1958  case MP_TUNNELBRIDGE: // Clear PBS reservation on tunnels/bridges
1960  break;
1961 
1962  default: break;
1963  }
1964  }
1965  }
1966 
1967  /* Reserve all tracks trains are currently on. */
1969  for (const Train *t : Train::Iterate()) {
1970  if (t->First() == t) t->ReserveTrackUnderConsist();
1971  }
1972  }
1973 
1975  for (TileIndex t = 0; t < map_size; t++) {
1976  /* Now all crossings should be in correct state */
1977  if (IsLevelCrossingTile(t)) UpdateLevelCrossing(t, false);
1978  }
1979  }
1980 
1982  /* Non-town-owned roads now store the closest town */
1984 
1985  /* signs with invalid owner left from older savegames */
1986  for (Sign *si : Sign::Iterate()) {
1987  if (si->owner != OWNER_NONE && !Company::IsValidID(si->owner)) si->owner = OWNER_NONE;
1988  }
1989 
1990  /* Station can get named based on an industry type, but the current ones
1991  * are not, so mark them as if they are not named by an industry. */
1992  for (Station *st : Station::Iterate()) {
1993  st->indtype = IT_INVALID;
1994  }
1995  }
1996 
1998  for (Aircraft *a : Aircraft::Iterate()) {
1999  /* Set engine_type of shadow and rotor */
2000  if (!a->IsNormalAircraft()) {
2001  a->engine_type = a->First()->engine_type;
2002  }
2003  }
2004 
2005  /* More companies ... */
2006  for (Company *c : Company::Iterate()) {
2007  if (c->bankrupt_asked == 0xFF) c->bankrupt_asked = 0xFFFF;
2008  }
2009 
2010  for (Engine *e : Engine::Iterate()) {
2011  if (e->company_avail == 0xFF) e->company_avail = 0xFFFF;
2012  }
2013 
2014  for (Town *t : Town::Iterate()) {
2015  if (t->have_ratings == 0xFF) t->have_ratings = 0xFFFF;
2016  for (uint i = 8; i != MAX_COMPANIES; i++) t->ratings[i] = RATING_INITIAL;
2017  }
2018  }
2019 
2021  for (TileIndex t = 0; t < map_size; t++) {
2022  /* Check for HQ bit being set, instead of using map accessor,
2023  * since we've already changed it code-wise */
2024  if (IsTileType(t, MP_OBJECT) && HasBit(_m[t].m5, 7)) {
2025  /* Move size and part identification of HQ out of the m5 attribute,
2026  * on new locations */
2027  _m[t].m3 = GB(_m[t].m5, 0, 5);
2028  _m[t].m5 = OBJECT_HQ;
2029  }
2030  }
2031  }
2033  for (TileIndex t = 0; t < map_size; t++) {
2034  if (!IsTileType(t, MP_OBJECT)) continue;
2035 
2036  /* Reordering/generalisation of the object bits. */
2037  ObjectType type = _m[t].m5;
2038  SB(_me[t].m6, 2, 4, type == OBJECT_HQ ? GB(_m[t].m3, 2, 3) : 0);
2039  _m[t].m3 = type == OBJECT_HQ ? GB(_m[t].m3, 1, 1) | GB(_m[t].m3, 0, 1) << 4 : 0;
2040 
2041  /* Make sure those bits are clear as well! */
2042  _m[t].m4 = 0;
2043  _me[t].m7 = 0;
2044  }
2045  }
2046 
2048  /* Make real objects for object tiles. */
2049  for (TileIndex t = 0; t < map_size; t++) {
2050  if (!IsTileType(t, MP_OBJECT)) continue;
2051 
2052  if (Town::GetNumItems() == 0) {
2053  /* No towns, so remove all objects! */
2054  DoClearSquare(t);
2055  } else {
2056  uint offset = _m[t].m3;
2057 
2058  /* Also move the animation state. */
2059  _m[t].m3 = GB(_me[t].m6, 2, 4);
2060  SB(_me[t].m6, 2, 4, 0);
2061 
2062  if (offset == 0) {
2063  /* No offset, so make the object. */
2064  ObjectType type = _m[t].m5;
2065  int size = type == OBJECT_HQ ? 2 : 1;
2066 
2067  if (!Object::CanAllocateItem()) {
2068  /* Nice... you managed to place 64k lighthouses and
2069  * antennae on the map... boohoo. */
2070  SlError(STR_ERROR_TOO_MANY_OBJECTS);
2071  }
2072 
2073  Object *o = new Object();
2074  o->location.tile = t;
2075  o->location.w = size;
2076  o->location.h = size;
2077  o->build_date = _date;
2078  o->town = type == OBJECT_STATUE ? Town::Get(_m[t].m2) : CalcClosestTownFromTile(t, UINT_MAX);
2079  _m[t].m2 = o->index;
2080  Object::IncTypeCount(type);
2081  } else {
2082  /* We're at an offset, so get the ID from our "root". */
2083  TileIndex northern_tile = t - TileXY(GB(offset, 0, 4), GB(offset, 4, 4));
2084  assert(IsTileType(northern_tile, MP_OBJECT));
2085  _m[t].m2 = _m[northern_tile].m2;
2086  }
2087  }
2088  }
2089  }
2090 
2092  /* allow_town_roads is added, set it if town_layout wasn't TL_NO_ROADS */
2093  if (_settings_game.economy.town_layout == 0) { // was TL_NO_ROADS
2096  } else {
2099  }
2100 
2101  /* Initialize layout of all towns. Older versions were using different
2102  * generator for random town layout, use it if needed. */
2103  for (Town *t : Town::Iterate()) {
2105  t->layout = _settings_game.economy.town_layout;
2106  continue;
2107  }
2108 
2109  /* Use old layout randomizer code */
2110  byte layout = TileHash(TileX(t->xy), TileY(t->xy)) % 6;
2111  switch (layout) {
2112  default: break;
2113  case 5: layout = 1; break;
2114  case 0: layout = 2; break;
2115  }
2116  t->layout = static_cast<TownLayout>(layout - 1);
2117  }
2118  }
2119 
2121  /* There could be (deleted) stations with invalid owner, set owner to OWNER NONE.
2122  * The conversion affects oil rigs and buoys too, but it doesn't matter as
2123  * they have st->owner == OWNER_NONE already. */
2124  for (Station *st : Station::Iterate()) {
2125  if (!Company::IsValidID(st->owner)) st->owner = OWNER_NONE;
2126  }
2127  }
2128 
2129  /* Trains could now stop in a specific location. */
2131  for (Order *o : Order::Iterate()) {
2132  if (o->IsType(OT_GOTO_STATION)) o->SetStopLocation(OSL_PLATFORM_FAR_END);
2133  }
2134  }
2135 
2138  for (Company *c : Company::Iterate()) {
2139  c->settings.vehicle = _old_vds;
2140  }
2141  }
2142 
2144  /* Delete small ufos heading for non-existing vehicles */
2145  for (Vehicle *v : DisasterVehicle::Iterate()) {
2146  if (v->subtype == 2 /* ST_SMALL_UFO */ && v->current_order.GetDestination() != 0) {
2147  const Vehicle *u = Vehicle::GetIfValid(v->dest_tile);
2148  if (u == nullptr || u->type != VEH_ROAD || !RoadVehicle::From(u)->IsFrontEngine()) {
2149  delete v;
2150  }
2151  }
2152  }
2153 
2154  /* We didn't store cargo payment yet, so make them for vehicles that are
2155  * currently at a station and loading/unloading. If they don't get any
2156  * payment anymore they just removed in the next load/unload cycle.
2157  * However, some 0.7 versions might have cargo payment. For those we just
2158  * add cargopayment for the vehicles that don't have it.
2159  */
2160  for (Station *st : Station::Iterate()) {
2161  std::list<Vehicle *>::iterator iter;
2162  for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) {
2163  /* There are always as many CargoPayments as Vehicles. We need to make the
2164  * assert() in Pool::GetNew() happy by calling CanAllocateItem(). */
2167  Vehicle *v = *iter;
2168  if (v->cargo_payment == nullptr) v->cargo_payment = new CargoPayment(v);
2169  }
2170  }
2171  }
2172 
2174  /* Animated tiles would sometimes not be actually animated or
2175  * in case of old savegames duplicate. */
2176 
2177  extern std::vector<TileIndex> _animated_tiles;
2178 
2179  for (auto tile = _animated_tiles.begin(); tile < _animated_tiles.end(); /* Nothing */) {
2180  /* Remove if tile is not animated */
2181  bool remove = _tile_type_procs[GetTileType(*tile)]->animate_tile_proc == nullptr;
2182 
2183  /* and remove if duplicate */
2184  for (auto j = _animated_tiles.begin(); !remove && j < tile; j++) {
2185  remove = *tile == *j;
2186  }
2187 
2188  if (remove) {
2189  DeleteAnimatedTile(*tile);
2190  } else {
2191  tile++;
2192  }
2193  }
2194  }
2195 
2197  /* The train station tile area was added, but for really old (TTDPatch) it's already valid. */
2198  for (Waypoint *wp : Waypoint::Iterate()) {
2199  if (wp->facilities & FACIL_TRAIN) {
2200  wp->train_station.tile = wp->xy;
2201  wp->train_station.w = 1;
2202  wp->train_station.h = 1;
2203  } else {
2204  wp->train_station.tile = INVALID_TILE;
2205  wp->train_station.w = 0;
2206  wp->train_station.h = 0;
2207  }
2208  }
2209  }
2210 
2212  /* Convert old subsidies */
2213  for (Subsidy *s : Subsidy::Iterate()) {
2214  if (s->remaining < 12) {
2215  /* Converting nonawarded subsidy */
2216  s->remaining = 12 - s->remaining; // convert "age" to "remaining"
2217  s->awarded = INVALID_COMPANY; // not awarded to anyone
2218  const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
2219  switch (cs->town_effect) {
2220  case TE_PASSENGERS:
2221  case TE_MAIL:
2222  /* Town -> Town */
2223  s->src_type = s->dst_type = ST_TOWN;
2224  if (Town::IsValidID(s->src) && Town::IsValidID(s->dst)) continue;
2225  break;
2226  case TE_GOODS:
2227  case TE_FOOD:
2228  /* Industry -> Town */
2229  s->src_type = ST_INDUSTRY;
2230  s->dst_type = ST_TOWN;
2231  if (Industry::IsValidID(s->src) && Town::IsValidID(s->dst)) continue;
2232  break;
2233  default:
2234  /* Industry -> Industry */
2235  s->src_type = s->dst_type = ST_INDUSTRY;
2236  if (Industry::IsValidID(s->src) && Industry::IsValidID(s->dst)) continue;
2237  break;
2238  }
2239  } else {
2240  /* Do our best for awarded subsidies. The original source or destination industry
2241  * can't be determined anymore for awarded subsidies, so invalidate them.
2242  * Town -> Town subsidies are converted using simple heuristic */
2243  s->remaining = 24 - s->remaining; // convert "age of awarded subsidy" to "remaining"
2244  const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
2245  switch (cs->town_effect) {
2246  case TE_PASSENGERS:
2247  case TE_MAIL: {
2248  /* Town -> Town */
2249  const Station *ss = Station::GetIfValid(s->src);
2250  const Station *sd = Station::GetIfValid(s->dst);
2251  if (ss != nullptr && sd != nullptr && ss->owner == sd->owner &&
2252  Company::IsValidID(ss->owner)) {
2253  s->src_type = s->dst_type = ST_TOWN;
2254  s->src = ss->town->index;
2255  s->dst = sd->town->index;
2256  s->awarded = ss->owner;
2257  continue;
2258  }
2259  break;
2260  }
2261  default:
2262  break;
2263  }
2264  }
2265  /* Awarded non-town subsidy or invalid source/destination, invalidate */
2266  delete s;
2267  }
2268  }
2269 
2271  /* Recompute inflation based on old unround loan limit
2272  * Note: Max loan is 500000. With an inflation of 4% across 170 years
2273  * that results in a max loan of about 0.7 * 2^31.
2274  * So taking the 16 bit fractional part into account there are plenty of bits left
2275  * for unmodified savegames ...
2276  */
2277  uint64 aimed_inflation = (_economy.old_max_loan_unround << 16 | _economy.old_max_loan_unround_fract) / _settings_game.difficulty.max_loan;
2278 
2279  /* ... well, just clamp it then. */
2280  if (aimed_inflation > MAX_INFLATION) aimed_inflation = MAX_INFLATION;
2281 
2282  /* Simulate the inflation, so we also get the payment inflation */
2283  while (_economy.inflation_prices < aimed_inflation) {
2284  if (AddInflation(false)) break;
2285  }
2286  }
2287 
2289  for (const Depot *d : Depot::Iterate()) {
2290  /* At some point, invalid depots were saved into the game (possibly those removed in the past?)
2291  * Remove them here, so they don't cause issues further down the line */
2292  if (!IsDepotTile(d->xy)) {
2293  DEBUG(sl, 0, "Removing invalid depot %d at %d, %d", d->index, TileX(d->xy), TileY(d->xy));
2294  delete d;
2295  d = nullptr;
2296  continue;
2297  }
2298  _m[d->xy].m2 = d->index;
2299  if (IsTileType(d->xy, MP_WATER)) _m[GetOtherShipDepotTile(d->xy)].m2 = d->index;
2300  }
2301  }
2302 
2303  /* The behaviour of force_proceed has been changed. Now
2304  * it counts signals instead of some random time out. */
2306  for (Train *t : Train::Iterate()) {
2307  if (t->force_proceed != TFP_NONE) {
2308  t->force_proceed = TFP_STUCK;
2309  }
2310  }
2311  }
2312 
2313  /* The bits for the tree ground and tree density have
2314  * been swapped (m2 bits 7..6 and 5..4. */
2316  for (TileIndex t = 0; t < map_size; t++) {
2317  if (IsTileType(t, MP_CLEAR)) {
2318  if (GetRawClearGround(t) == CLEAR_SNOW) {
2320  SetBit(_m[t].m3, 4);
2321  } else {
2322  ClrBit(_m[t].m3, 4);
2323  }
2324  }
2325  if (IsTileType(t, MP_TREES)) {
2326  uint density = GB(_m[t].m2, 6, 2);
2327  uint ground = GB(_m[t].m2, 4, 2);
2328  uint counter = GB(_m[t].m2, 0, 4);
2329  _m[t].m2 = ground << 6 | density << 4 | counter;
2330  }
2331  }
2332  }
2333 
2334  /* Wait counter and load/unload ticks got split. */
2336  for (Aircraft *a : Aircraft::Iterate()) {
2337  a->turn_counter = a->current_order.IsType(OT_LOADING) ? 0 : a->load_unload_ticks;
2338  }
2339 
2340  for (Train *t : Train::Iterate()) {
2341  t->wait_counter = t->current_order.IsType(OT_LOADING) ? 0 : t->load_unload_ticks;
2342  }
2343  }
2344 
2345  /* Airport tile animation uses animation frame instead of other graphics id */
2347  struct AirportTileConversion {
2348  byte old_start;
2349  byte num_frames;
2350  };
2351  static const AirportTileConversion atc[] = {
2352  {31, 12}, // APT_RADAR_GRASS_FENCE_SW
2353  {50, 4}, // APT_GRASS_FENCE_NE_FLAG
2354  {62, 2}, // 1 unused tile
2355  {66, 12}, // APT_RADAR_FENCE_SW
2356  {78, 12}, // APT_RADAR_FENCE_NE
2357  {101, 10}, // 9 unused tiles
2358  {111, 8}, // 7 unused tiles
2359  {119, 15}, // 14 unused tiles (radar)
2360  {140, 4}, // APT_GRASS_FENCE_NE_FLAG_2
2361  };
2362  for (TileIndex t = 0; t < map_size; t++) {
2363  if (IsAirportTile(t)) {
2364  StationGfx old_gfx = GetStationGfx(t);
2365  byte offset = 0;
2366  for (uint i = 0; i < lengthof(atc); i++) {
2367  if (old_gfx < atc[i].old_start) {
2368  SetStationGfx(t, old_gfx - offset);
2369  break;
2370  }
2371  if (old_gfx < atc[i].old_start + atc[i].num_frames) {
2372  SetAnimationFrame(t, old_gfx - atc[i].old_start);
2373  SetStationGfx(t, atc[i].old_start - offset);
2374  break;
2375  }
2376  offset += atc[i].num_frames - 1;
2377  }
2378  }
2379  }
2380  }
2381 
2383  for (Station *st : Station::Iterate()) {
2384  if (st->airport.tile != INVALID_TILE) {
2385  st->airport.w = st->airport.GetSpec()->size_x;
2386  st->airport.h = st->airport.GetSpec()->size_y;
2387  }
2388  }
2389  }
2390 
2392  for (TileIndex t = 0; t < map_size; t++) {
2393  /* Reset tropic zone for VOID tiles, they shall not have any. */
2395  }
2396 
2397  /* We need to properly number/name the depots.
2398  * The first step is making sure none of the depots uses the
2399  * 'default' names, after that we can assign the names. */
2400  for (Depot *d : Depot::Iterate()) d->town_cn = UINT16_MAX;
2401 
2402  for (Depot* d : Depot::Iterate()) MakeDefaultName(d);
2403  }
2404 
2406  for (Depot *d : Depot::Iterate()) d->build_date = _date;
2407  }
2408 
2409  /* In old versions it was possible to remove an airport while a plane was
2410  * taking off or landing. This gives all kind of problems when building
2411  * another airport in the same station so we don't allow that anymore.
2412  * For old savegames with such aircraft we just throw them in the air and
2413  * treat the aircraft like they were flying already. */
2415  for (Aircraft *v : Aircraft::Iterate()) {
2416  if (!v->IsNormalAircraft()) continue;
2418  if (st == nullptr && v->state != FLYING) {
2419  v->state = FLYING;
2422  /* get aircraft back on running altitude */
2423  if ((v->vehstatus & VS_CRASHED) == 0) {
2424  GetAircraftFlightLevelBounds(v, &v->z_pos, nullptr);
2425  SetAircraftPosition(v, v->x_pos, v->y_pos, GetAircraftFlightLevel(v));
2426  }
2427  }
2428  }
2429  }
2430 
2431  /* Move the animation frame to the same location (m7) for all objects. */
2433  for (TileIndex t = 0; t < map_size; t++) {
2434  switch (GetTileType(t)) {
2435  case MP_HOUSE:
2436  if (GetHouseType(t) >= NEW_HOUSE_OFFSET) {
2437  uint per_proc = _me[t].m7;
2438  _me[t].m7 = GB(_me[t].m6, 2, 6) | (GB(_m[t].m3, 5, 1) << 6);
2439  SB(_m[t].m3, 5, 1, 0);
2440  SB(_me[t].m6, 2, 6, min(per_proc, 63));
2441  }
2442  break;
2443 
2444  case MP_INDUSTRY: {
2445  uint rand = _me[t].m7;
2446  _me[t].m7 = _m[t].m3;
2447  _m[t].m3 = rand;
2448  break;
2449  }
2450 
2451  case MP_OBJECT:
2452  _me[t].m7 = _m[t].m3;
2453  _m[t].m3 = 0;
2454  break;
2455 
2456  default:
2457  /* For stations/airports it's already at m7 */
2458  break;
2459  }
2460  }
2461  }
2462 
2463  /* Add (random) colour to all objects. */
2465  for (Object *o : Object::Iterate()) {
2466  Owner owner = GetTileOwner(o->location.tile);
2467  o->colour = (owner == OWNER_NONE) ? Random() & 0xF : Company::Get(owner)->livery->colour1;
2468  }
2469  }
2470 
2472  for (TileIndex t = 0; t < map_size; t++) {
2473  if (!IsTileType(t, MP_STATION)) continue;
2474  if (!IsBuoy(t) && !IsOilRig(t) && !(IsDock(t) && IsTileFlat(t))) {
2476  }
2477  }
2478 
2479  /* Waypoints with custom name may have a non-unique town_cn,
2480  * renumber those. First set all affected waypoints to the
2481  * highest possible number to get them numbered in the
2482  * order they have in the pool. */
2483  for (Waypoint *wp : Waypoint::Iterate()) {
2484  if (wp->name != nullptr) wp->town_cn = UINT16_MAX;
2485  }
2486 
2487  for (Waypoint* wp : Waypoint::Iterate()) {
2488  if (wp->name != nullptr) MakeDefaultName(wp);
2489  }
2490  }
2491 
2493  _industry_builder.Reset(); // Initialize industry build data.
2494 
2495  /* The moment vehicles go from hidden to visible changed. This means
2496  * that vehicles don't always get visible anymore causing things to
2497  * get messed up just after loading the savegame. This fixes that. */
2498  for (Vehicle *v : Vehicle::Iterate()) {
2499  /* Not all vehicle types can be inside a tunnel. Furthermore,
2500  * testing IsTunnelTile() for invalid tiles causes a crash. */
2501  if (!v->IsGroundVehicle()) continue;
2502 
2503  /* Is the vehicle in a tunnel? */
2504  if (!IsTunnelTile(v->tile)) continue;
2505 
2506  /* Is the vehicle actually at a tunnel entrance/exit? */
2507  TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos);
2508  if (!IsTunnelTile(vtile)) continue;
2509 
2510  /* Are we actually in this tunnel? Or maybe a lower tunnel? */
2511  if (GetSlopePixelZ(v->x_pos, v->y_pos) != v->z_pos) continue;
2512 
2513  /* What way are we going? */
2514  const DiagDirection dir = GetTunnelBridgeDirection(vtile);
2515  const DiagDirection vdir = DirToDiagDir(v->direction);
2516 
2517  /* Have we passed the visibility "switch" state already? */
2518  byte pos = (DiagDirToAxis(vdir) == AXIS_X ? v->x_pos : v->y_pos) & TILE_UNIT_MASK;
2519  byte frame = (vdir == DIAGDIR_NE || vdir == DIAGDIR_NW) ? TILE_SIZE - 1 - pos : pos;
2520  extern const byte _tunnel_visibility_frame[DIAGDIR_END];
2521 
2522  /* Should the vehicle be hidden or not? */
2523  bool hidden;
2524  if (dir == vdir) { // Entering tunnel
2525  hidden = frame >= _tunnel_visibility_frame[dir];
2526  v->tile = vtile;
2527  } else if (dir == ReverseDiagDir(vdir)) { // Leaving tunnel
2528  hidden = frame < TILE_SIZE - _tunnel_visibility_frame[dir];
2529  /* v->tile changes at the moment when the vehicle leaves the tunnel. */
2530  v->tile = hidden ? GetOtherTunnelBridgeEnd(vtile) : vtile;
2531  } else {
2532  /* We could get here in two cases:
2533  * - for road vehicles, it is reversing at the end of the tunnel
2534  * - it is crashed in the tunnel entry (both train or RV destroyed by UFO)
2535  * Whatever case it is, do not change anything and use the old values.
2536  * Especially changing RV's state would break its reversing in the middle. */
2537  continue;
2538  }
2539 
2540  if (hidden) {
2541  v->vehstatus |= VS_HIDDEN;
2542 
2543  switch (v->type) {
2544  case VEH_TRAIN: Train::From(v)->track = TRACK_BIT_WORMHOLE; break;
2545  case VEH_ROAD: RoadVehicle::From(v)->state = RVSB_WORMHOLE; break;
2546  default: NOT_REACHED();
2547  }
2548  } else {
2549  v->vehstatus &= ~VS_HIDDEN;
2550 
2551  switch (v->type) {
2552  case VEH_TRAIN: Train::From(v)->track = DiagDirToDiagTrackBits(vdir); break;
2553  case VEH_ROAD: RoadVehicle::From(v)->state = DiagDirToDiagTrackdir(vdir); RoadVehicle::From(v)->frame = frame; break;
2554  default: NOT_REACHED();
2555  }
2556  }
2557  }
2558  }
2559 
2561  for (RoadVehicle *rv : RoadVehicle::Iterate()) {
2562  if (rv->state == RVSB_IN_DEPOT || rv->state == RVSB_WORMHOLE) continue;
2563 
2564  bool loading = rv->current_order.IsType(OT_LOADING) || rv->current_order.IsType(OT_LEAVESTATION);
2565  if (HasBit(rv->state, RVS_IN_ROAD_STOP)) {
2566  extern const byte _road_stop_stop_frame[];
2567  SB(rv->state, RVS_ENTERED_STOP, 1, loading || rv->frame > _road_stop_stop_frame[rv->state - RVSB_IN_ROAD_STOP + (_settings_game.vehicle.road_side << RVS_DRIVE_SIDE)]);
2568  } else if (HasBit(rv->state, RVS_IN_DT_ROAD_STOP)) {
2569  SB(rv->state, RVS_ENTERED_STOP, 1, loading || rv->frame > RVC_DRIVE_THROUGH_STOP_FRAME);
2570  }
2571  }
2572  }
2573 
2575  /* The train's pathfinder lost flag got moved. */
2576  for (Train *t : Train::Iterate()) {
2577  if (!HasBit(t->flags, 5)) continue;
2578 
2579  ClrBit(t->flags, 5);
2580  SetBit(t->vehicle_flags, VF_PATHFINDER_LOST);
2581  }
2582 
2583  /* Introduced terraform/clear limits. */
2584  for (Company *c : Company::Iterate()) {
2585  c->terraform_limit = _settings_game.construction.terraform_frame_burst << 16;
2586  c->clear_limit = _settings_game.construction.clear_frame_burst << 16;
2587  }
2588  }
2589 
2591  for (Vehicle *v : Vehicle::Iterate()) {
2592  switch (v->type) {
2593  case VEH_TRAIN: {
2594  Train *t = Train::From(v);
2595 
2596  /* Clear old GOINGUP / GOINGDOWN flags.
2597  * It was changed in savegame version 139, but savegame
2598  * version 158 doesn't use these bits, so it doesn't hurt
2599  * to clear them unconditionally. */
2600  ClrBit(t->flags, 1);
2601  ClrBit(t->flags, 2);
2602 
2603  /* Clear both bits first. */
2606 
2607  /* Crashed vehicles can't be going up/down. */
2608  if (t->vehstatus & VS_CRASHED) break;
2609 
2610  /* Only X/Y tracks can be sloped. */
2611  if (t->track != TRACK_BIT_X && t->track != TRACK_BIT_Y) break;
2612 
2614  break;
2615  }
2616  case VEH_ROAD: {
2617  RoadVehicle *rv = RoadVehicle::From(v);
2620 
2621  /* Crashed vehicles can't be going up/down. */
2622  if (rv->vehstatus & VS_CRASHED) break;
2623 
2624  if (rv->state == RVSB_IN_DEPOT || rv->state == RVSB_WORMHOLE) break;
2625 
2626  TrackStatus ts = GetTileTrackStatus(rv->tile, TRANSPORT_ROAD, GetRoadTramType(rv->roadtype));
2627  TrackBits trackbits = TrackStatusToTrackBits(ts);
2628 
2629  /* Only X/Y tracks can be sloped. */
2630  if (trackbits != TRACK_BIT_X && trackbits != TRACK_BIT_Y) break;
2631 
2632  Direction dir = rv->direction;
2633 
2634  /* Test if we are reversing. */
2635  Axis a = trackbits == TRACK_BIT_X ? AXIS_X : AXIS_Y;
2636  if (AxisToDirection(a) != dir &&
2637  AxisToDirection(a) != ReverseDir(dir)) {
2638  /* When reversing, the road vehicle is on the edge of the tile,
2639  * so it can be safely compared to the middle of the tile. */
2640  dir = INVALID_DIR;
2641  }
2642 
2643  rv->gv_flags |= FixVehicleInclination(rv, dir);
2644  break;
2645  }
2646  case VEH_SHIP:
2647  break;
2648 
2649  default:
2650  continue;
2651  }
2652 
2653  if (IsBridgeTile(v->tile) && TileVirtXY(v->x_pos, v->y_pos) == v->tile) {
2654  /* In old versions, z_pos was 1 unit lower on bridge heads.
2655  * However, this invalid state could be converted to new savegames
2656  * by loading and saving the game in a new version. */
2657  v->z_pos = GetSlopePixelZ(v->x_pos, v->y_pos);
2658  DiagDirection dir = GetTunnelBridgeDirection(v->tile);
2659  if (v->type == VEH_TRAIN && !(v->vehstatus & VS_CRASHED) &&
2660  v->direction != DiagDirToDir(dir)) {
2661  /* If the train has left the bridge, it shouldn't have
2662  * track == TRACK_BIT_WORMHOLE - this could happen
2663  * when the train was reversed while on the last "tick"
2664  * on the ramp before leaving the ramp to the bridge. */
2665  Train::From(v)->track = DiagDirToDiagTrackBits(dir);
2666  }
2667  }
2668 
2669  /* If the vehicle is really above v->tile (not in a wormhole),
2670  * it should have set v->z_pos correctly. */
2671  assert(v->tile != TileVirtXY(v->x_pos, v->y_pos) || v->z_pos == GetSlopePixelZ(v->x_pos, v->y_pos));
2672  }
2673 
2674  /* Fill Vehicle::cur_real_order_index */
2675  for (Vehicle *v : Vehicle::Iterate()) {
2676  if (!v->IsPrimaryVehicle()) continue;
2677 
2678  /* Older versions are less strict with indices being in range and fix them on the fly */
2679  if (v->cur_implicit_order_index >= v->GetNumOrders()) v->cur_implicit_order_index = 0;
2680 
2681  v->cur_real_order_index = v->cur_implicit_order_index;
2682  v->UpdateRealOrderIndex();
2683  }
2684  }
2685 
2687  /* If the savegame is old (before version 100), then the value of 255
2688  * for these settings did not mean "disabled". As such everything
2689  * before then did reverse.
2690  * To simplify stuff we disable all turning around or we do not
2691  * disable anything at all. So, if some reversing was disabled we
2692  * will keep reversing disabled, otherwise it'll be turned on. */
2694 
2695  for (Train *t : Train::Iterate()) {
2696  _settings_game.vehicle.max_train_length = max<uint8>(_settings_game.vehicle.max_train_length, CeilDiv(t->gcache.cached_total_length, TILE_SIZE));
2697  }
2698  }
2699 
2701  /* Setting difficulty industry_density other than zero get bumped to +1
2702  * since a new option (minimal at position 1) has been added */
2705  }
2706  }
2707 
2709  /* Before savegame version 161, persistent storages were not stored in a pool. */
2710 
2712  for (Industry *ind : Industry::Iterate()) {
2713  assert(ind->psa != nullptr);
2714 
2715  /* Check if the old storage was empty. */
2716  bool is_empty = true;
2717  for (uint i = 0; i < sizeof(ind->psa->storage); i++) {
2718  if (ind->psa->GetValue(i) != 0) {
2719  is_empty = false;
2720  break;
2721  }
2722  }
2723 
2724  if (!is_empty) {
2725  ind->psa->grfid = _industry_mngr.GetGRFID(ind->type);
2726  } else {
2727  delete ind->psa;
2728  ind->psa = nullptr;
2729  }
2730  }
2731  }
2732 
2734  for (Station *st : Station::Iterate()) {
2735  if (!(st->facilities & FACIL_AIRPORT)) continue;
2736  assert(st->airport.psa != nullptr);
2737 
2738  /* Check if the old storage was empty. */
2739  bool is_empty = true;
2740  for (uint i = 0; i < sizeof(st->airport.psa->storage); i++) {
2741  if (st->airport.psa->GetValue(i) != 0) {
2742  is_empty = false;
2743  break;
2744  }
2745  }
2746 
2747  if (!is_empty) {
2748  st->airport.psa->grfid = _airport_mngr.GetGRFID(st->airport.type);
2749  } else {
2750  delete st->airport.psa;
2751  st->airport.psa = nullptr;
2752 
2753  }
2754  }
2755  }
2756  }
2757 
2758  /* This triggers only when old snow_lines were copied into the snow_line_height. */
2761  }
2762 
2764  /* We store 4 fences in the field tiles instead of only SE and SW. */
2765  for (TileIndex t = 0; t < map_size; t++) {
2766  if (!IsTileType(t, MP_CLEAR) && !IsTileType(t, MP_TREES)) continue;
2767  if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_FIELDS)) continue;
2768  uint fence = GB(_m[t].m4, 5, 3);
2769  if (fence != 0 && IsTileType(TILE_ADDXY(t, 1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(t, 1, 0), CLEAR_FIELDS)) {
2770  SetFence(TILE_ADDXY(t, 1, 0), DIAGDIR_NE, fence);
2771  }
2772  fence = GB(_m[t].m4, 2, 3);
2773  if (fence != 0 && IsTileType(TILE_ADDXY(t, 0, 1), MP_CLEAR) && IsClearGround(TILE_ADDXY(t, 0, 1), CLEAR_FIELDS)) {
2774  SetFence(TILE_ADDXY(t, 0, 1), DIAGDIR_NW, fence);
2775  }
2776  SB(_m[t].m4, 2, 3, 0);
2777  SB(_m[t].m4, 5, 3, 0);
2778  }
2779  }
2780 
2781  /* The center of train vehicles was changed, fix up spacing. */
2783 
2785  for (Town *t : Town::Iterate()) {
2786  /* Set the default cargo requirement for town growth */
2788  case LT_ARCTIC:
2789  if (FindFirstCargoWithTownEffect(TE_FOOD) != nullptr) t->goal[TE_FOOD] = TOWN_GROWTH_WINTER;
2790  break;
2791 
2792  case LT_TROPIC:
2793  if (FindFirstCargoWithTownEffect(TE_FOOD) != nullptr) t->goal[TE_FOOD] = TOWN_GROWTH_DESERT;
2795  break;
2796  }
2797  }
2798  }
2799 
2801  /* Adjust zoom level to account for new levels */
2802  _saved_scrollpos_zoom = static_cast<ZoomLevel>(_saved_scrollpos_zoom + ZOOM_LVL_SHIFT);
2803  _saved_scrollpos_x *= ZOOM_LVL_BASE;
2804  _saved_scrollpos_y *= ZOOM_LVL_BASE;
2805  }
2806 
2807  /* When any NewGRF has been changed the availability of some vehicles might
2808  * have been changed too. e->company_avail must be set to 0 in that case
2809  * which is done by StartupEngines(). */
2810  if (gcf_res != GLC_ALL_GOOD) StartupEngines();
2811 
2813  /* Update cargo acceptance map of towns. */
2814  for (TileIndex t = 0; t < map_size; t++) {
2815  if (!IsTileType(t, MP_HOUSE)) continue;
2816  Town::Get(GetTownIndex(t))->cargo_accepted.Add(t);
2817  }
2818 
2819  for (Town *town : Town::Iterate()) {
2820  UpdateTownCargoes(town);
2821  }
2822  }
2823 
2824  /* The road owner of standard road stops was not properly accounted for. */
2826  for (TileIndex t = 0; t < map_size; t++) {
2827  if (!IsStandardRoadStopTile(t)) continue;
2828  Owner o = GetTileOwner(t);
2829  SetRoadOwner(t, RTT_ROAD, o);
2830  SetRoadOwner(t, RTT_TRAM, o);
2831  }
2832  }
2833 
2835  /* Introduced tree planting limit. */
2836  for (Company *c : Company::Iterate()) c->tree_limit = _settings_game.construction.tree_frame_burst << 16;
2837  }
2838 
2840  /* Fix too high inflation rates */
2841  if (_economy.inflation_prices > MAX_INFLATION) _economy.inflation_prices = MAX_INFLATION;
2843 
2844  /* We have to convert the quarters of bankruptcy into months of bankruptcy */
2845  for (Company *c : Company::Iterate()) {
2846  c->months_of_bankruptcy = 3 * c->months_of_bankruptcy;
2847  }
2848  }
2849 
2851  extern uint8 _old_diff_level;
2852  /* Initialise script settings profile */
2853  _settings_game.script.settings_profile = IsInsideMM(_old_diff_level, SP_BEGIN, SP_END) ? _old_diff_level : (uint)SP_MEDIUM;
2854  }
2855 
2857  /* Aircraft acceleration variable was bonkers */
2858  for (Aircraft *v : Aircraft::Iterate()) {
2859  if (v->subtype <= AIR_AIRCRAFT) {
2860  const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
2861  v->acceleration = avi->acceleration;
2862  }
2863  }
2864 
2865  /* Blocked tiles could be reserved due to a bug, which causes
2866  * other places to assert upon e.g. station reconstruction. */
2867  for (TileIndex t = 0; t < map_size; t++) {
2869  SetRailStationReservation(t, false);
2870  }
2871  }
2872  }
2873 
2875  /* The global units configuration is split up in multiple configurations. */
2876  extern uint8 _old_units;
2877  _settings_game.locale.units_velocity = Clamp(_old_units, 0, 2);
2878  _settings_game.locale.units_power = Clamp(_old_units, 0, 2);
2879  _settings_game.locale.units_weight = Clamp(_old_units, 1, 2);
2880  _settings_game.locale.units_volume = Clamp(_old_units, 1, 2);
2882  _settings_game.locale.units_height = Clamp(_old_units, 0, 2);
2883  }
2884 
2886  /* Move ObjectType from map to pool */
2887  for (TileIndex t = 0; t < map_size; t++) {
2888  if (IsTileType(t, MP_OBJECT)) {
2889  Object *o = Object::Get(_m[t].m2);
2890  o->type = _m[t].m5;
2891  _m[t].m5 = 0; // zero upper bits of (now bigger) ObjectID
2892  }
2893  }
2894  }
2895 
2897  /* Fix articulated road vehicles.
2898  * Some curves were shorter than other curves.
2899  * Now they have the same length, but that means that trailing articulated parts will
2900  * take longer to go through the curve than the parts in front which already left the courve.
2901  * So, make articulated parts catch up. */
2902  bool roadside = _settings_game.vehicle.road_side == 1;
2903  std::vector<uint> skip_frames;
2904  for (RoadVehicle *v : RoadVehicle::Iterate()) {
2905  if (!v->IsFrontEngine()) continue;
2906  skip_frames.clear();
2907  TileIndex prev_tile = v->tile;
2908  uint prev_tile_skip = 0;
2909  uint cur_skip = 0;
2910  for (RoadVehicle *u = v; u != nullptr; u = u->Next()) {
2911  if (u->tile != prev_tile) {
2912  prev_tile_skip = cur_skip;
2913  prev_tile = u->tile;
2914  } else {
2915  cur_skip = prev_tile_skip;
2916  }
2917 
2918  /*C++17: uint &this_skip = */ skip_frames.push_back(prev_tile_skip);
2919  uint &this_skip = skip_frames.back();
2920 
2921  /* The following 3 curves now take longer than before */
2922  switch (u->state) {
2923  case 2:
2924  cur_skip++;
2925  if (u->frame <= (roadside ? 9 : 5)) this_skip = cur_skip;
2926  break;
2927 
2928  case 4:
2929  cur_skip++;
2930  if (u->frame <= (roadside ? 5 : 9)) this_skip = cur_skip;
2931  break;
2932 
2933  case 5:
2934  cur_skip++;
2935  if (u->frame <= (roadside ? 4 : 2)) this_skip = cur_skip;
2936  break;
2937 
2938  default:
2939  break;
2940  }
2941  }
2942  while (cur_skip > skip_frames[0]) {
2943  RoadVehicle *u = v;
2944  RoadVehicle *prev = nullptr;
2945  for (uint sf : skip_frames) {
2946  extern bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *prev);
2947  if (sf >= cur_skip) IndividualRoadVehicleController(u, prev);
2948 
2949  prev = u;
2950  u = u->Next();
2951  }
2952  cur_skip--;
2953  }
2954  }
2955  }
2956 
2957  /*
2958  * Only keep order-backups for network clients (and when replaying).
2959  * If we are a network server or not networking, then we just loaded a previously
2960  * saved-by-server savegame. There are no clients with a backup, so clear it.
2961  * Furthermore before savegame version SLV_192 the actual content was always corrupt.
2962  */
2964 #ifndef DEBUG_DUMP_COMMANDS
2965  /* Note: We cannot use CleanPool since that skips part of the destructor
2966  * and then leaks un-reachable Orders in the order pool. */
2967  for (OrderBackup *ob : OrderBackup::Iterate()) {
2968  delete ob;
2969  }
2970 #endif
2971  }
2972 
2974  /* Convert towns growth_rate and grow_counter to ticks */
2975  for (Town *t : Town::Iterate()) {
2976  /* 0x8000 = TOWN_GROWTH_RATE_CUSTOM previously */
2977  if (t->growth_rate & 0x8000) SetBit(t->flags, TOWN_CUSTOM_GROWTH);
2978  if (t->growth_rate != TOWN_GROWTH_RATE_NONE) {
2979  t->growth_rate = TownTicksToGameTicks(t->growth_rate & ~0x8000);
2980  }
2981  /* Add t->index % TOWN_GROWTH_TICKS to spread growth across ticks. */
2982  t->grow_counter = TownTicksToGameTicks(t->grow_counter) + t->index % TOWN_GROWTH_TICKS;
2983  }
2984  }
2985 
2987  /* Make sure added industry cargo slots are cleared */
2988  for (Industry *i : Industry::Iterate()) {
2989  for (size_t ci = 2; ci < lengthof(i->produced_cargo); ci++) {
2990  i->produced_cargo[ci] = CT_INVALID;
2991  i->produced_cargo_waiting[ci] = 0;
2992  i->production_rate[ci] = 0;
2993  i->last_month_production[ci] = 0;
2994  i->last_month_transported[ci] = 0;
2995  i->last_month_pct_transported[ci] = 0;
2996  i->this_month_production[ci] = 0;
2997  i->this_month_transported[ci] = 0;
2998  }
2999  for (size_t ci = 3; ci < lengthof(i->accepts_cargo); ci++) {
3000  i->accepts_cargo[ci] = CT_INVALID;
3001  i->incoming_cargo_waiting[ci] = 0;
3002  }
3003  /* Make sure last_cargo_accepted_at is copied to elements for every valid input cargo.
3004  * The loading routine should put the original singular value into the first array element. */
3005  for (size_t ci = 0; ci < lengthof(i->accepts_cargo); ci++) {
3006  if (i->accepts_cargo[ci] != CT_INVALID) {
3007  i->last_cargo_accepted_at[ci] = i->last_cargo_accepted_at[0];
3008  } else {
3009  i->last_cargo_accepted_at[ci] = 0;
3010  }
3011  }
3012  }
3013  }
3014 
3016  /* Move ships from lock slope to upper or lower position. */
3017  for (Ship *s : Ship::Iterate()) {
3018  /* Suitable tile? */
3019  if (!IsTileType(s->tile, MP_WATER) || !IsLock(s->tile) || GetLockPart(s->tile) != LOCK_PART_MIDDLE) continue;
3020 
3021  /* We don't need to adjust position when at the tile centre */
3022  int x = s->x_pos & 0xF;
3023  int y = s->y_pos & 0xF;
3024  if (x == 8 && y == 8) continue;
3025 
3026  /* Test if ship is on the second half of the tile */
3027  bool second_half;
3028  DiagDirection shipdiagdir = DirToDiagDir(s->direction);
3029  switch (shipdiagdir) {
3030  default: NOT_REACHED();
3031  case DIAGDIR_NE: second_half = x < 8; break;
3032  case DIAGDIR_NW: second_half = y < 8; break;
3033  case DIAGDIR_SW: second_half = x > 8; break;
3034  case DIAGDIR_SE: second_half = y > 8; break;
3035  }
3036 
3037  DiagDirection slopediagdir = GetInclinedSlopeDirection(GetTileSlope(s->tile));
3038 
3039  /* Heading up slope == passed half way */
3040  if ((shipdiagdir == slopediagdir) == second_half) {
3041  /* On top half of lock */
3042  s->z_pos = GetTileMaxZ(s->tile) * (int)TILE_HEIGHT;
3043  } else {
3044  /* On lower half of lock */
3045  s->z_pos = GetTileZ(s->tile) * (int)TILE_HEIGHT;
3046  }
3047  }
3048  }
3049 
3051  /* Ensure the original cargo generation mode is used */
3053  }
3054 
3056  /* Ensure the original neutral industry/station behaviour is used */
3058 
3059  /* Link oil rigs to their industry and back. */
3060  for (Station *st : Station::Iterate()) {
3061  if (IsTileType(st->xy, MP_STATION) && IsOilRig(st->xy)) {
3062  /* Industry tile is always adjacent during construction by TileDiffXY(0, 1) */
3063  st->industry = Industry::GetByTile(st->xy + TileDiffXY(0, 1));
3064  st->industry->neutral_station = st;
3065  }
3066  }
3067  } else {
3068  /* Link neutral station back to industry, as this is not saved. */
3069  for (Industry *ind : Industry::Iterate()) if (ind->neutral_station != nullptr) ind->neutral_station->industry = ind;
3070  }
3071 
3073  /* Update water class for trees. */
3074  for (TileIndex t = 0; t < map_size; t++) {
3076  }
3077  }
3078 
3079  /* Update structures for multitile docks */
3081  for (TileIndex t = 0; t < map_size; t++) {
3082  /* Clear docking tile flag from relevant tiles as it
3083  * was not previously cleared. */
3085  SetDockingTile(t, false);
3086  }
3087  /* Add docks and oilrigs to Station::ship_station. */
3088  if (IsTileType(t, MP_STATION)) {
3089  if (IsDock(t) || IsOilRig(t)) Station::GetByTile(t)->ship_station.Add(t);
3090  }
3091  }
3092 
3093  /* Scan for docking tiles */
3094  for (Station *st : Station::Iterate()) {
3095  if (st->ship_station.tile != INVALID_TILE) UpdateStationDockingTiles(st);
3096  }
3097  }
3098 
3099  /* Compute station catchment areas. This is needed here in case UpdateStationAcceptance is called below. */
3101 
3102  /* Station acceptance is some kind of cache */
3104  for (Station *st : Station::Iterate()) UpdateStationAcceptance(st, false);
3105  }
3106 
3107  /* Road stops is 'only' updating some caches */
3109  AfterLoadLabelMaps();
3112 
3113  GamelogPrintDebug(1);
3114 
3116  /* Restore the signals */
3118 
3120  return true;
3121 }
3122 
3132 {
3133  /* reload grf data */
3134  GfxLoadSprites();
3136  RecomputePrices();
3137  /* reload vehicles */
3138  ResetVehicleHash();
3139  AfterLoadVehicles(false);
3140  StartupEngines();
3142  /* update station graphics */
3143  AfterLoadStations();
3144  /* Update company statistics. */
3146  /* Check and update house and town values */
3148  /* Delete news referring to no longer existing entities */
3150  /* Update livery selection windows */
3152  /* Update company infrastructure counts. */
3154  /* redraw the whole screen */
3157 }
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 accepted cargoes.
Definition: industrytype.h:120
bool disable_elrails
when true, the elrails are disabled
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows. ...
Definition: main_gui.cpp:552
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
Owner
Enum for all companies/owners.
Definition: company_type.h:18
static const uint TOWN_GROWTH_WINTER
The town only needs this cargo in the winter (any amount)
Definition: town.h:34
static void UpdateAfterLoad()
Update all caches after loading a game, changing NewGRF, etc.
Definition: group_cmd.cpp:101
Normal operation.
Definition: train.h:38
VehicleSettings vehicle
options for vehicles
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
Change the owner of a tile.
Definition: landscape.cpp:600
static void Swap(T &a, T &b)
Type safe swap operation.
Definition: math_func.hpp:275
byte type
Type of this airport,.
Definition: station_base.h:309
Source/destination is a town.
Definition: cargo_type.h:148
presignal inter-block
Definition: signal_type.h:27
Vehicle is stopped by the player.
Definition: vehicle_base.h:31
static const int TOWN_GROWTH_TICKS
cycle duration for towns trying to grow. (this originates from the size of the town array in TTD ...
Definition: date_type.h:37
141 19799
Definition: saveload.h:211
uint8 max_heightlevel
maximum allowed heightlevel
static void ResetSignalHandlers()
Resets signal handlers back to original handlers.
Definition: afterload.cpp:323
static void ClearBridgeMiddle(TileIndex t)
Removes bridges from the given, that is bridges along the X and Y axis.
Definition: bridge_map.h:103
byte state
Definition: roadveh.h:109
static uint MapSizeX()
Get the size of the map along the X.
Definition: map_func.h:72
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:79
127 17439
Definition: saveload.h:194
106 14919
Definition: saveload.h:169
static void StartNew(CompanyID company, bool rerandomise_ai=true)
Start a new AI company.
Definition: ai_core.cpp:36
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:302
void UpdateNearestTownForRoadTiles(bool invalidate)
Updates cached nearest town for all road tiles.
Definition: road_cmd.cpp:1823
bool _networking
are we in networking mode?
Definition: network.cpp:52
149 20832
Definition: saveload.h:220
Default settings for vehicles.
void CopyTempEngineData()
Copy data from temporary engine array into the real engine pool.
Definition: engine_sl.cpp:118
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
void UpdateOldAircraft()
need to be called to load aircraft from old version
Definition: vehicle_sl.cpp:162
static void SetAnimationFrame(TileIndex t, byte frame)
Set a new animation frame.
Definition: tile_map.h:262
static uint MapSizeY()
Get the size of the map along the Y.
Definition: map_func.h:82
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:763
Direction direction
facing
Definition: vehicle_base.h:269
Normal tropiczone.
Definition: tile_type.h:70
Non-existing type of vehicle.
Definition: vehicle_type.h:35
void UpdateTownCargoes(Town *t)
Update cargo acceptance for the complete town.
Definition: town_cmd.cpp:821
static void SetTunnelBridgeReservation(TileIndex t, bool b)
Set the reservation state of the rail tunnel/bridge.
Money old_max_loan_unround
Old: Unrounded max loan.
Definition: economy_type.h:31
static byte GetLockPart(TileIndex t)
Get the part of a lock.
Definition: water_map.h:320
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:198
static const byte TOWN_HOUSE_COMPLETED
Simple value that indicates the house has reached the final stage of construction.
Definition: house.h:23
Flag for an invalid track.
Definition: track_type.h:28
static void FixOwnerOfRailTrack(TileIndex t)
Tries to change owner of this rail tile to a valid owner.
Definition: afterload.cpp:429
static void MakeVoid(TileIndex t)
Make a nice void tile ;)
Definition: void_map.h:19
117 16037
Definition: saveload.h:182
70 10541
Definition: saveload.h:126
Level crossing.
Definition: road_map.h:23
GRFConfig * _grfconfig
First item in list of current GRF set up.
TileArea ship_station
Tile area the ship &#39;station&#39; part covers.
Definition: station_base.h:465
static DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
byte landscape
the landscape we&#39;re currently in
IndustryBuildData _industry_builder
In-game manager of industries.
76 11139
Definition: saveload.h:133
void BuildOwnerLegend()
Completes the array for the owned property legend.
static void CDECL HandleSavegameLoadCrash(int signum)
Signal handler used to give a user a more useful report for crashes during the savegame loading proce...
Definition: afterload.cpp:367
Yet Another PathFinder.
Definition: vehicle_type.h:61
135 18719
Definition: saveload.h:204
52 9066
Definition: saveload.h:104
An invalid owner.
Definition: company_type.h:29
static bool IsAirportTile(TileIndex t)
Is this tile a station tile and an airport tile?
Definition: station_map.h:167
2.0 0.3.0 2.1 0.3.1, 0.3.2
Definition: saveload.h:33
61 9892
Definition: saveload.h:115
102 14332
Definition: saveload.h:164
All GRF needed by game are present.
Definition: newgrf_config.h:52
Part of an industry.
Definition: tile_type.h:49
Track in the lower corner of the tile (south)
Definition: track_type.h:24
EconomySettings economy
settings to change the economy
Vehicle has finished loading.
Definition: vehicle_base.h:42
void AfterLoadCompanyStats()
Rebuilding of company statistics after loading a savegame.
Definition: company_sl.cpp:94
#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:80
Compatible (eg. the same ID, but different checksum) GRF found in at least one case.
Definition: newgrf_config.h:53
static bool IsWater(TileIndex t)
Is it a plain water tile?
Definition: water_map.h:141
void NORETURN SlErrorCorrupt(const char *msg)
Error handler for corrupt savegames.
Definition: saveload.cpp:354
Train vehicle type.
Definition: vehicle_type.h:24
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:291
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
Definition: water_map.h:106
Town * town
Town the object is built in.
Definition: object_base.h:25
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:36
byte units_weight
unit system for weight
Northwest.
void SetWaterClassDependingOnSurroundings(TileIndex t, bool include_invalid_water_class)
Makes a tile canal or water depending on the surroundings.
Definition: afterload.cpp:79
Basic road type.
Definition: road_type.h:24
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:407
Random town layout.
Definition: town_type.h:85
98 13375
Definition: saveload.h:159
The vehicle is in a drive-through road stop.
Definition: roadveh.h:47
byte m7
Primarily used for newgrf support.
Definition: map_type.h:35
void CheckTrainsLengths()
Checks if lengths of all rail vehicles are valid.
Definition: train_cmd.cpp:72
uint16 m2
Primarily used for indices to towns, industries and stations.
Definition: map_type.h:20
Used for iterations.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
uint16 old_max_loan_unround_fract
Old: Fraction of the unrounded max loan.
Definition: economy_type.h:32
static void MakeShore(TileIndex t)
Helper function to make a coast tile.
Definition: water_map.h:375
87 12129
Definition: saveload.h:146
A tile with road (or tram tracks)
Definition: tile_type.h:43
bool road_use_yapf
use YAPF for road
26 4466
Definition: saveload.h:73
uint32 GetGRFID(uint16 entity_id) const
Gives the GRFID of the file the entity belongs to.
Ship vehicle type.
Definition: vehicle_type.h:26
static const ObjectType OBJECT_STATUE
Statue in towns.
Definition: object_type.h:18
static IndustryGfx GetIndustryGfx(TileIndex t)
Get the industry graphics ID for the given industry tile.
Definition: industry_map.h:137
Maximal number of cargo types in a game.
Definition: cargo_type.h:64
120 16439
Definition: saveload.h:186
Full road along the x-axis (south-west + north-east)
Definition: road_type.h:56
uint64 inflation_prices
Cumulated inflation of prices since game start; 16 bit fractional part.
Definition: economy_type.h:27
210 PR#7234 Company stations can serve industries with attached neutral stations. ...
Definition: saveload.h:295
A town owns the tile, or a town is expanding.
Definition: company_type.h:24
Tile * _m
Tiles of the map.
Definition: map.cpp:30
void NORETURN SlError(StringID string, const char *extra_msg)
Error handler.
Definition: saveload.cpp:326
an airplane
Definition: aircraft.h:32
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition: saveload.cpp:58
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
Get the road types the given company can build.
Definition: road.cpp:188
Specification of a cargo type.
Definition: cargotype.h:55
static TileIndex GetOtherShipDepotTile(TileIndex t)
Get the other tile of the ship depot.
Definition: water_map.h:272
103 14598
Definition: saveload.h:165
static bool IsRoadStop(TileIndex t)
Is the station at t a road station?
Definition: station_map.h:202
char * CopyFromOldName(StringID id)
Copy and convert old custom names to UTF-8.
Definition: strings_sl.cpp:59
145 20376
Definition: saveload.h:216
16.0 2817 16.1 3155
Definition: saveload.h:59
X-axis track.
Definition: track_type.h:40
Proceed till next signal, but ignore being stuck till then. This includes force leaving depots...
Definition: train.h:39
static TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir. ...
Definition: track_func.h:532
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:74
104 14735
Definition: saveload.h:166
Medium difficulty.
Definition: settings_type.h:28
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
Definition: string.cpp:425
25 4259
Definition: saveload.h:72
Date build_date
Date of construction.
Definition: object_base.h:27
TownLayout
Town Layouts.
Definition: town_type.h:78
121 16694
Definition: saveload.h:187
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
Definition: afterload.cpp:3131
188 26169 v1.4 FS#5831 Unify RV travel time
Definition: saveload.h:267
uint32 changes
Number of changes in this action.
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
void AfterLoadStoryBook()
Called after load to trash broken pages.
Definition: story_sl.cpp:18
125 17113
Definition: saveload.h:192
113 15340
Definition: saveload.h:177
PathfinderSettings pf
settings for all pathfinders
TileArea train_station
Tile area the train &#39;station&#39; part covers.
Only used when retrieving move data.
Definition: roadveh.h:45
static TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Definition: map_func.h:382
Vehicle data structure.
Definition: vehicle_base.h:210
GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig)
Check if all GRFs in the GRF config from a savegame can be loaded.
void UpdateAllTownVirtCoords()
Update the virtual coords needed to draw the town sign for all towns.
Definition: town_cmd.cpp:408
static bool IsExpected(const BaseStation *st)
Helper for checking whether the given station is of this type.
static void AfterLoad()
Savegame conversion for cargopackets.
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
175 24136
Definition: saveload.h:252
byte units_velocity
unit system for velocity
Defines the internal data of a functional industry.
Definition: industry.h:40
DifficultySettings difficulty
settings related to the difficulty
Tindex index
Index of this pool item.
Definition: pool_type.hpp:189
Vehicle is flying in the air.
Definition: airport.h:75
flag for invalid roadtype
Definition: road_type.h:27
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
Definition: error_gui.cpp:380
Manual distribution. No link graph calculations are run.
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
Definition: date_type.h:28
42 7573
Definition: saveload.h:92
82 11410
Definition: saveload.h:140
101 14233
Definition: saveload.h:163
119 16242
Definition: saveload.h:184
114 15601
Definition: saveload.h:178
bool forbid_90_deg
forbid trains to make 90 deg turns
Cargo behaves water-like.
Definition: cargotype.h:30
28 4987
Definition: saveload.h:75
DistributionType distribution_default
distribution type for all other goods
Representation of a waypoint.
Definition: waypoint_base.h:16
TownLayout town_layout
select town layout,
static void SetRailStationReservation(TileIndex t, bool b)
Set the reservation state of the rail station.
Definition: station_map.h:405
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:48
const byte _tunnel_visibility_frame[DIAGDIR_END]
Frame when a vehicle should be hidden in a tunnel with a certain direction.
165 23304
Definition: saveload.h:240
void GamelogPrintDebug(int level)
Prints gamelog to debug output.
Definition: gamelog.cpp:364
A railway.
Definition: tile_type.h:42
uint16 tree_frame_burst
how many trees may, over a short period, be planted?
GRF file was not found in the local cache.
Definition: newgrf_config.h:36
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
initial rating
Definition: town_type.h:44
Loading compatible GRF.
Cargo behaves goods/candy-like.
Definition: cargotype.h:29
void AircraftNextAirportPos_and_Order(Aircraft *v)
set the right pos when heading to other airports after takeoff
void GamelogOldver()
Logs loading from savegame without gamelog.
Definition: gamelog.cpp:464
Contains objects such as transmitters and owned land.
Definition: tile_type.h:51
static uint FixVehicleInclination(Vehicle *v, Direction dir)
Fixes inclination of a vehicle.
Definition: afterload.cpp:487
static void InitializeWindowsAndCaches()
Initialization of the windows and several kinds of caches.
Definition: afterload.cpp:234
void ShowAIDebugWindowIfAIError()
Open the AI debug window if one of the AI scripts has crashed.
Definition: ai_gui.cpp:1548
11.0 2033 11.1 2041
Definition: saveload.h:52
134 18703
Definition: saveload.h:202
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
Definition: station_map.h:223
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
void GetAircraftFlightLevelBounds(const Vehicle *v, int *min, int *max)
Get the &#39;flight level&#39; bounds, in pixels from &#39;z_pos&#39; 0 for a particular vehicle for normal flight si...
static bool IsLevelCrossing(TileIndex t)
Return whether a tile is a level crossing.
Definition: road_map.h:84
static void SetWaterClass(TileIndex t, WaterClass wc)
Set the water class at a tile.
Definition: water_map.h:118
RoadType
The different roadtypes we support.
Definition: road_type.h:22
byte units_force
unit system for force
static bool IsDriveThroughStopTile(TileIndex t)
Is tile t a drive through road stop station?
Definition: station_map.h:233
bool allow_town_roads
towns are allowed to build roads (always allowed when generating world / in SE)
Town * town
The town this station is associated with.
GRFIdentifier grfcompat
ID and new md5sum of changed GRF.
byte vehstatus
Status.
Definition: vehicle_base.h:315
byte units_height
unit system for height
static bool IsClearGround(TileIndex t, ClearGround ct)
Set the type of clear tile.
Definition: clear_map.h:71
uint32 max_loan
the maximum initial loan
Definition: settings_type.h:57
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:24
uint16 w
The width of the area.
Definition: tilearea_type.h:18
17.0 3212 17.1 3218
Definition: saveload.h:61
bool infrastructure_maintenance
enable monthly maintenance fee for owner infrastructure
137 18912
Definition: saveload.h:206
Basic data to distinguish a GRF.
Definition: newgrf_config.h:82
59 9779
Definition: saveload.h:112
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
Definition: tile_map.cpp:100
uint _gamelog_actions
number of actions
Definition: gamelog.cpp:36
206 PR#7150 Ship/lock movement changes.
Definition: saveload.h:290
CompanySettings settings
settings specific for each company
Definition: company_base.h:127
static void SetRoadTypes(TileIndex t, RoadType road_rt, RoadType tram_rt)
Set the present road types of a tile.
Definition: road_map.h:619
bool AfterLoadGame()
Perform a (large) amount of savegame conversion magic in order to load older savegames and to fill th...
Definition: afterload.cpp:534
static StationType GetStationType(TileIndex t)
Get the station type of this tile.
Definition: station_map.h:44
StationSettings station
settings related to station management
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:13
struct GRFConfig * next
NOSAVE: Next item in the linked list.
Southwest.
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
Definition: cargo_type.h:67
void UpdateStationAcceptance(Station *st, bool show_msg)
Update the acceptance for a station.
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.
48 8935
Definition: saveload.h:99
96 13226
Definition: saveload.h:157
58 9762
Definition: saveload.h:111
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:39
15.0 2499
Definition: saveload.h:58
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
Use this function to notify YAPF that track layout (or signal configuration) has change.
Definition: yapf_rail.cpp:642
static Station * From(BaseStation *st)
Converts a BaseStation to SpecializedStation with type checking.
24 4150
Definition: saveload.h:70
57 9691
Definition: saveload.h:110
byte m1
Primarily used for ownership information.
Definition: map_type.h:21
static bool IsLock(TileIndex t)
Is there a lock on a given water tile?
Definition: water_map.h:297
bool _network_dedicated
are we a dedicated server?
Definition: network.cpp:55
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:21
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition: tile_map.cpp:121
Normal road.
Definition: road_map.h:22
72 10601
Definition: saveload.h:128
21 3472 0.4.x
Definition: saveload.h:67
static bool HasStationRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint...
Definition: station_map.h:135
std::vector< TileIndex > _animated_tiles
The table/list with animated tiles.
bool freeform_edges
allow terraforming the tiles at the map edges
Invalid cargo type.
Definition: cargo_type.h:68
Plain water.
Definition: water_map.h:40
static bool IsHouseCompleted(TileIndex t)
Get the completion of this house.
Definition: town_map.h:145
177 24619
Definition: saveload.h:254
Stop at the far end of the platform.
Definition: order_type.h:86
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
static const size_t MAX_SIZE
Make template parameter accessible from outside.
Definition: pool_type.hpp:86
old or new scenario
Definition: fileio_type.h:19
122 16855
Definition: saveload.h:188
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:264
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition: window.cpp:3334
bool reverse_at_signals
whether to reverse at signals at all
Buses, trucks and trams belong to this class.
Definition: roadveh.h:107
Fake town GrfSpecFeature for NewGRF debugging (parent scope)
Definition: newgrf.h:89
Critical errors, the MessageBox is shown in all cases.
Definition: error.h:24
RoadType roadtype
Roadtype of this vehicle.
Definition: roadveh.h:117
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition: tile_map.h:214
void UpdateAirportsNoise()
Recalculate the noise generated by the airports of each town.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold...
Definition: town_cmd.cpp:3488
static void SetCrossingReservation(TileIndex t, bool b)
Set the reservation state of the rail crossing.
Definition: road_map.h:393
void SetDate(Date date, DateFract fract)
Set the date.
Definition: date.cpp:35
static void MakeSea(TileIndex t)
Make a sea tile.
Definition: water_map.h:414
Vehicle is crashed.
Definition: vehicle_base.h:37
88 12134
Definition: saveload.h:147
Electric rails.
Definition: rail_type.h:30
The tile has no ownership.
Definition: company_type.h:25
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
DistributionType distribution_mail
distribution type for mail
static bool IsBuoy(TileIndex t)
Is tile t a buoy tile?
Definition: station_map.h:306
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
Definition: town.h:236
Southeast.
static bool _saveload_crash_with_missing_newgrfs
Was the saveload crash because of missing NewGRFs?
Definition: afterload.cpp:349
The vehicle is in a road stop.
Definition: roadveh.h:46
94 12816
Definition: saveload.h:154
void SetNonStopType(OrderNonStopFlags non_stop_type)
Set whether we must stop at stations or not.
Definition: order_base.h:152
The y axis.
static bool IsCoast(TileIndex t)
Is it a coast tile?
Definition: water_map.h:195
RoadStop * truck_stops
All the truck stops.
Definition: station_base.h:461
Contains information about one logged action that caused at least one logged change.
This indicates whether a cargo has a rating at the station.
Definition: station_base.h:187
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
Definition: tilearea.cpp:43
void ConvertOldMultiheadToNew()
Converts all trains to the new subtype format introduced in savegame 16.2 It also links multiheaded e...
Definition: vehicle_sl.cpp:110
43 7642
Definition: saveload.h:93
DateFract _date_fract
Fractional part of the day.
Definition: date.cpp:27
bool serve_neutral_industries
company stations can serve industries with attached neutral stations
void UpdateAircraftCache(Aircraft *v, bool update_range=false)
Update cached values of an aircraft.
A normal unpaused game.
Definition: openttd.h:56
CompanySettings company
default values for per-company settings
Information about GRF, used in the game and (part of it) in savegames.
Original algorithm (quadratic cargo by population)
Definition: town_type.h:103
YAPFSettings yapf
pathfinder settings for the yet another pathfinder
62 9905
Definition: saveload.h:116
static void SetStationGfx(TileIndex t, StationGfx gfx)
Set the station graphics of this tile.
Definition: station_map.h:80
38 7195
Definition: saveload.h:87
byte road_side
the side of the road vehicles drive on
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:47
static bool IsTruckStop(TileIndex t)
Is the station at t a truck stop?
Definition: station_map.h:180
void MoveBuoysToWaypoints()
Perform all steps to upgrade from the old station buoys to the new version that uses waypoints...
Definition: station_sl.cpp:40
static bool HasTownOwnedRoad(TileIndex t)
Checks if given tile has town owned road.
Definition: road_map.h:279
34 6455
Definition: saveload.h:82
Do not load anything.
Definition: order_type.h:66
byte units_volume
unit system for volume
static TownID GetTownIndex(TileIndex t)
Get the index of which town this house/street is attached to.
Definition: town_map.h:22
194 26881 v1.5
Definition: saveload.h:275
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:61
The vehicle is in a tunnel and/or bridge.
Definition: roadveh.h:40
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
Southeast.
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
Definition: afterload.cpp:217
T * Next() const
Get next vehicle in the chain.
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:78
Standard non-electric rails.
Definition: rail_type.h:29
byte snow_line_height
the configured snow line height
143 20048
Definition: saveload.h:213
static bool HasStationTileRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint...
Definition: station_map.h:146
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
void DeleteAnimatedTile(TileIndex tile)
Removes the given tile from the animated tile table.
void LoadStringWidthTable(bool monospace)
Initialize _stringwidth_table cache.
Definition: gfx.cpp:1133
111 15190
Definition: saveload.h:175
static const int GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET
The offset for the drive through parts.
Definition: station_map.h:36
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
Definition: map_func.h:258
Trams.
Definition: road_type.h:25
IndustryType GetIndustryType(TileIndex tile)
Retrieve the type for this industry.
Game loaded.
Definition: gamelog.h:18
202 PR#6867 Increase industry cargo slots to 16 in, 16 out
Definition: saveload.h:285
Direction
Defines the 8 directions on the map.
Water tile.
Definition: tile_type.h:47
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:31
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:314
bool dynamic_engines
enable dynamic allocation of engine data
Station * GetTargetAirportIfValid(const Aircraft *v)
Returns aircraft&#39;s target station if v->target_airport is a valid station with airport.
static void SetClearGroundDensity(TileIndex t, ClearGround type, uint density)
Sets ground type and density in one go, also sets the counter to 0.
Definition: clear_map.h:158
byte m5
General purpose.
Definition: map_type.h:24
RoadBits
Enumeration for the road parts on a tile.
Definition: road_type.h:50
158 21933
Definition: saveload.h:231
An object, such as transmitter, on the map.
Definition: object_base.h:23
The vehicle is in a depot.
Definition: roadveh.h:39
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Definition: tile_type.h:16
static bool IsBuoyTile(TileIndex t)
Is tile t a buoy tile?
Definition: station_map.h:316
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:38
const CargoSpec * FindFirstCargoWithTownEffect(TownEffect effect)
Determines the first cargo with a certain town effect.
Definition: town_cmd.cpp:2699
Extended original algorithm (min. 2 distance between roads)
Definition: town_type.h:81
void GamelogGRFAddList(const GRFConfig *newg)
Logs adding of list of GRFs.
Definition: gamelog.cpp:676
static void SetSignalStates(TileIndex tile, uint state)
Set the states of the signals (Along/AgainstTrackDir)
Definition: rail_map.h:352
Company colour selection; Window numbers:
Definition: window_type.h:223
uint16 max_bridge_length
maximum length of bridges
bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition: vehicle_base.h:881
static WaterTileType GetWaterTileType(TileIndex t)
Get the water tile type at a tile.
Definition: water_map.h:77
TileIndex tile
Current tile index.
Definition: vehicle_base.h:228
Defines the data structure for constructing industry.
Definition: industrytype.h:106
CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32 face)
Converts an old company manager&#39;s face format to the new company manager&#39;s face format.
Definition: company_sl.cpp:43
New PathFinder.
Definition: vehicle_type.h:60
Grass with a fence and shore or water on the free halftile.
Definition: rail_map.h:499
void SetSaveLoadError(StringID str)
Set the error message from outside of the actual loading/saving of the game (AfterLoadGame and friend...
Definition: saveload.cpp:2424
static void SetHouseCompleted(TileIndex t, bool status)
Mark this house as been completed.
Definition: town_map.h:156
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1938
static Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition: track_func.h:545
A game normally paused.
Definition: openttd.h:57
const byte _road_stop_stop_frame[]
Table of road stop stop frames, when to stop at a road stop.
void UpdateAllSignVirtCoords()
Update the coordinates of all signs.
Definition: signs.cpp:60
void GamelogGRFCompatible(const GRFIdentifier *newg)
Logs loading compatible GRF (the same ID, but different MD5 hash)
Definition: gamelog.cpp:630
void AfterLoadLinkGraphs()
Spawn the threads for running link graph calculations.
146 20446
Definition: saveload.h:217
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:271
uint16 clear_frame_burst
how many tiles may, over a short period, be cleared?
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:40
84 11822
Definition: saveload.h:142
Company * DoStartupNewCompany(bool is_ai, CompanyID company=INVALID_COMPANY)
Create a new company and sets all company variables default values.
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
Definition: industrytype.h:124
static uint TileHash(uint x, uint y)
Calculate a hash value from a tile position.
Definition: tile_map.h:316
void UpdateHousesAndTowns()
Check and update town and house values.
Definition: town_sl.cpp:64
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:40
void GamelogTestRevision()
Finds out if current revision is different than last revision stored in the savegame.
Definition: gamelog.cpp:498
static bool IsShipDepotTile(TileIndex t)
Is it a ship depot tile?
Definition: water_map.h:226
Helper class to perform the cargo payment.
Definition: economy_base.h:24
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:47
uint16 ObjectType
Types of objects.
Definition: object_type.h:14
183 25363 Cargodist
Definition: saveload.h:261
uint8 plane_speed
divisor for speed of aircraft
static DiagDirection GetInclinedSlopeDirection(Slope s)
Returns the direction of an inclined slope.
Definition: slope_func.h:239
53 9316
Definition: saveload.h:105
static void SetBridgeMiddle(TileIndex t, Axis a)
Set that there is a bridge over the given axis.
Definition: bridge_map.h:114
static const Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
Definition: date_type.h:49
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
static bool IsPlainRailTile(TileIndex t)
Checks whether the tile is a rail tile or rail tile with signals.
Definition: rail_map.h:60
byte number_towns
the amount of towns
Definition: settings_type.h:55
Vehicle is currently going uphill. (Cached track information for acceleration)
a desert or snow tile, depend on landscape
Definition: tree_map.h:55
Vehicle&#39;s pathfinder is lost.
Definition: vehicle_base.h:49
6.0 1721 6.1 1768
Definition: saveload.h:45
123 16909
Definition: saveload.h:189
static void RecomputeCatchmentForAll()
Recomputes catchment of all stations.
Definition: station.cpp:476
148 20659
Definition: saveload.h:219
83 11589
Definition: saveload.h:141
164 23290
Definition: saveload.h:238
static StationGfx GetStationGfx(TileIndex t)
Get the station graphics of this tile.
Definition: station_map.h:68
void UpdateLevelCrossing(TileIndex tile, bool sound=true)
Sets correct crossing state.
Definition: train_cmd.cpp:1672
Bitflag for a wormhole (used for tunnels)
Definition: track_type.h:55
uint8 plane_crashes
number of plane crashes, 0 = none, 1 = reduced, 2 = normal
All ships have this type.
Definition: ship.h:26
124 16993
Definition: saveload.h:190
RoadStop * bus_stops
All the road stops.
Definition: station_base.h:459
Transfer all cargo onto the platform.
Definition: order_type.h:55
DistributionType distribution_armoured
distribution type for armoured cargo class
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:589
static void SetRoadOwner(TileIndex t, RoadTramType rtt, Owner o)
Set the owner of a specific road type.
Definition: road_map.h:250
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:137
static bool HasSignals(TileIndex t)
Checks if a rail tile has signals.
Definition: rail_map.h:72
91 12347
Definition: saveload.h:151
Flag for an invalid direction.
ScriptSettings script
settings for scripts
void MoveWaypointsToBaseStations()
Perform all steps to upgrade from the old waypoints to the new version that uses station.
Definition: waypoint_sl.cpp:65
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:35
Struct about subsidies, offered and awarded.
Definition: subsidy_base.h:22
&#39;Train&#39; is either a loco or a wagon.
Definition: train.h:85
LoggedAction * _gamelog_action
first logged action
Definition: gamelog.cpp:35
Water lock.
Definition: water_map.h:42
End of setting profiles.
Definition: settings_type.h:31
byte units_power
unit system for power
1.0 0.1.x, 0.2.x
Definition: saveload.h:32
static RoadBits GetCrossingRoadBits(TileIndex tile)
Get the road bits of a level crossing.
Definition: road_map.h:348
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:17
static uint GetClearDensity(TileIndex t)
Get the density of a non-field clear tile.
Definition: clear_map.h:83
void StartupEngines()
Start/initialise all our engines.
Definition: engine.cpp:693
void ResetOldNames()
Free the memory of the old names array.
Definition: strings_sl.cpp:107
159 21962
Definition: saveload.h:232
uint8 train_slope_steepness
Steepness of hills for trains when using realistic acceleration.
void ShowNewGRFError()
Show the first NewGRF error we can find.
Definition: newgrf_gui.cpp:44
void UpdateAllStationVirtCoords()
Update the virtual coords needed to draw the station sign for all stations.
The X axis.
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Cargo behaves passenger-like.
Definition: cargotype.h:27
Town * CalcClosestTownFromTile(TileIndex tile, uint threshold=UINT_MAX)
Return the town closest to the given tile within threshold.
Definition: town_cmd.cpp:3470
153 21263
Definition: saveload.h:225
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
byte StationGfx
Copy from station_map.h.
Transport by train.
Company infrastructure overview; Window numbers:
Definition: window_type.h:570
Station with an airport.
Definition: station_type.h:55
Cargo behaves mail-like.
Definition: cargotype.h:28
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
static const uint TOWN_GROWTH_DESERT
The town needs the cargo for growth when on desert (any amount)
Definition: town.h:35
The tile/execution is done by "water".
Definition: company_type.h:26
static const uint MIN_SNOWLINE_HEIGHT
Minimum snowline height.
Definition: tile_type.h:28
112 15290
Definition: saveload.h:176
9.0 1909
Definition: saveload.h:49
void ConnectMultiheadedTrains()
Link front and rear multiheaded engines to each other This is done when loading a savegame...
Definition: vehicle_sl.cpp:32
Station with a dock.
Definition: station_type.h:56
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition: map_func.h:194
Vehicle is currently going downhill. (Cached track information for acceleration)
An invalid company.
Definition: company_type.h:30
Tile got trees.
Definition: tile_type.h:45
No track.
Definition: track_type.h:39
160 21974 1.1.x
Definition: saveload.h:234
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
TownEffect town_effect
The effect that delivering this cargo type has on towns. Also affects destination of subsidies...
Definition: cargotype.h:66
StationType
Station types.
Definition: station_type.h:32
GamelogActionType at
Type of action.
static Owner GetRoadOwner(TileIndex t, RoadTramType rtt)
Get the owner of a specific road type.
Definition: road_map.h:233
void SetAircraftPosition(Aircraft *v, int x, int y, int z)
Set aircraft position.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
static RoadTileType GetRoadTileType(TileIndex t)
Get the type of the road tile.
Definition: road_map.h:51
139 19346
Definition: saveload.h:208
static bool IsRailDepot(TileIndex t)
Is this rail tile a rail depot?
Definition: rail_map.h:95
bool IsStationTileBlocked(TileIndex tile)
Check whether a rail station tile is NOT traversable.
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:50
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:340
186 25833 Objects storage
Definition: saveload.h:265
56 9667
Definition: saveload.h:109
144 20334
Definition: saveload.h:214
is built on water (oil rig)
Definition: industrytype.h:65
DistributionType distribution_pax
distribution type for passengers
static bool IsRailDepotTile(TileIndex t)
Is this tile rail tile and a rail depot?
Definition: rail_map.h:105
Invisible tiles at the SW and SE border.
Definition: tile_type.h:48
bool station_noise_level
build new airports when the town noise level is still within accepted limits
static DiagDirection XYNSToDiagDir(Axis xy, uint ns)
Convert an axis and a flag for north/south into a DiagDirection.
void RecomputePrices()
Computes all prices, payments and maximum loan.
Definition: economy.cpp:746
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition: tile_map.cpp:141
static void SetLiftPosition(TileIndex t, byte pos)
Set the position of the lift on this animated house.
Definition: town_map.h:135
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:117
static bool IsShipDepot(TileIndex t)
Is it a water tile with a ship depot on it?
Definition: water_map.h:216
Oilrig airport.
Definition: airport.h:38
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
Used for iterations.
Middle part of a lock.
Definition: water_map.h:65
void FixupTrainLengths()
Fixup old train spacing.
Definition: vehicle_sl.cpp:483
GRFListCompatibility
Status of post-gameload GRF compatibility check.
Definition: newgrf_config.h:51
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:321
147 20621
Definition: saveload.h:218
static const uint64 MAX_INFLATION
Maximum inflation (including fractional part) without causing overflows in int64 price computations...
Definition: economy_type.h:199
static void IncTypeCount(ObjectType type)
Increment the count of objects for this type.
Definition: object_base.h:43
First company, same as owner.
Definition: company_type.h:22
bool ship_use_yapf
use YAPF for ships
Information about a aircraft vehicle.
Definition: engine_type.h:97
static TreeGround GetTreeGround(TileIndex t)
Returns the groundtype for tree tiles.
Definition: tree_map.h:88
bool modified_catchment
different-size catchment areas
At least one GRF couldn&#39;t be found (higher priority than GLC_COMPATIBLE)
Definition: newgrf_config.h:54
CargoPayment * cargo_payment
The cargo payment we&#39;re currently in.
Definition: vehicle_base.h:241
LoggedChange * change
First logged change in this action.
static HouseID GetHouseType(TileIndex t)
Get the type of this house, which is an index into the house spec array.
Definition: town_map.h:59
static bool IsLevelCrossingTile(TileIndex t)
Return whether a tile is a level crossing tile.
Definition: road_map.h:94
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
Only set when a vehicle has entered the stop.
Definition: roadveh.h:44
static Direction AxisToDirection(Axis a)
Converts an Axis to a Direction.
void AfterLoadRoadStops()
(Re)building of road stop caches after loading a savegame.
Definition: station_sl.cpp:129
static void MakeClear(TileIndex t, ClearGround g, uint density)
Make a clear tile.
Definition: clear_map.h:259
Contains information about one logged change.
uint8 pathfinder_for_trains
the pathfinder to use for trains
uint16 terraform_frame_burst
how many tile heights may, over a short period, be terraformed?
Old-fashioned semaphore signal.
Definition: signal_type.h:18
138 18942 1.0.x
Definition: saveload.h:207
byte height
The height of the northern corner.
Definition: map_type.h:19
208 PR#6965 New algorithms for town building cargo generation.
Definition: saveload.h:292
TileArea location
Location of the object.
Definition: object_base.h:26
void RebuildSubsidisedSourceAndDestinationCache()
Perform a full rebuild of the subsidies cache.
Definition: subsidy.cpp:131
TransportType
Available types of transport.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
byte wait_twoway_signal
waitingtime in days before a twoway signal
93 12648
Definition: saveload.h:153
static ClearGround GetRawClearGround(TileIndex t)
Get the type of clear tile but never return CLEAR_SNOW.
Definition: clear_map.h:47
static bool IsOilRig(TileIndex t)
Is tile t part of an oilrig?
Definition: station_map.h:274
ObjectType type
Type of the object.
Definition: object_base.h:24
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:131
void AfterLoadVehicles(bool part_of_load)
Called after load to update coordinates.
Definition: vehicle_sl.cpp:240
Growth rate is controlled by GS.
Definition: town.h:178
A tile of a station.
Definition: tile_type.h:46
0-3
Definition: clear_map.h:24
const TileTypeProcs *const _tile_type_procs[16]
Tile callback functions for each type of tile.
Definition: landscape.cpp:60
VehicleDefaultSettings _old_vds
Used for loading default vehicles settings from old savegames.
Definition: settings.cpp:81
uint8 larger_towns
the number of cities to build. These start off larger and grow twice as fast
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
Definition: house.h:28
Maximum number of companies.
Definition: company_type.h:23
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:111
Town data structure.
Definition: town.h:53
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
static TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:371
Northwest.
static void MakeCanal(TileIndex t, Owner o, uint8 random_bits)
Make a canal tile.
Definition: water_map.h:435
uint64 inflation_payment
Cumulated inflation of cargo paypent since game start; 16 bit fractional part.
Definition: economy_type.h:28
50 8973
Definition: saveload.h:102
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
Definition: pool_type.hpp:261
Transport by road vehicle.
static const uint16 TOWN_GROWTH_RATE_NONE
Special value for Town::growth_rate to disable town growth.
Definition: town.h:36
The vehicle will not stop at any stations it passes except the destination.
Definition: order_type.h:74
static const uint TILE_UNIT_MASK
For masking in/out the inner-tile world coordinate units.
Definition: tile_type.h:14
LocaleSettings locale
settings related to used currency/unit system in the current game
The vehicle is in a road stop.
Definition: roadveh.h:50
184 25508 Unit localisation split
Definition: saveload.h:262
Vehicle is not visible.
Definition: vehicle_base.h:30
byte town_name
the town name generator used for town names
198 PR#6763 Switch town growth rate and counter to actual game ticks
Definition: saveload.h:280
Pause mode bits when paused for network reasons.
Definition: openttd.h:65
bool _network_server
network-server is active
Definition: network.cpp:53
214 PR#6811 NewGRF road types.
Definition: saveload.h:299
A Stop for a Road Vehicle.
Definition: roadstop_base.h:22
void GamelogGRFRemove(uint32 grfid)
Logs removal of a GRF.
Definition: gamelog.cpp:599
Northeast.
49 8969
Definition: saveload.h:100
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:45
Owner owner
The owner of this station.
void InitializeRailGUI()
Resets the rail GUI - sets default railtype to build and resets the signal GUI.
Definition: rail_gui.cpp:1979
TownCargoGenMode town_cargogen_mode
algorithm for generating cargo from houses,
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:280
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Definition: tile_map.h:29
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
Definition: saveload.h:319
uint8 train_acceleration_model
realistic acceleration for trains
Fields are planted around when built (all farms)
Definition: industrytype.h:69
Cargo behaves food/fizzy-drinks-like.
Definition: cargotype.h:31
ConstructionSettings construction
construction of things in-game
static const Year MIN_YEAR
The absolute minimum & maximum years in OTTD.
Definition: date_type.h:83
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:179
static Pool::IterateWrapper< RoadVehicle > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
192 26700 FS#6066 Fix saving of order backups
Definition: saveload.h:273
uint32 grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:83
156 21728
Definition: saveload.h:229
static bool IsTunnelTile(TileIndex t)
Is this a tunnel (entrance)?
Definition: tunnel_map.h:33
Airport airport
Tile area the airport covers.
Definition: station_base.h:464
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
140 19382
Definition: saveload.h:210
69 10319
Definition: saveload.h:124
uint8 settings_profile
difficulty profile to set initial settings of scripts, esp. random AIs
32 6001
Definition: saveload.h:80
int32 x_pos
x coordinate.
Definition: vehicle_base.h:266
45 8501
Definition: saveload.h:96
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
void Restore()
Restore the variable.
DiagDirection
Enumeration for diagonal directions.
Light signal.
Definition: signal_type.h:17
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:83
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:19
78 11176
Definition: saveload.h:135
static bool MayHaveBridgeAbove(TileIndex t)
Checks for the possibility that a bridge may be on this tile These are in fact all the tile types on ...
Definition: afterload.cpp:523
bool AddInflation(bool check_year)
Add monthly inflation.
Definition: economy.cpp:708
static void SetFence(TileIndex t, DiagDirection side, uint h)
Sets the type of fence (and whether there is one) for the given border.
Definition: clear_map.h:240
178 24789
Definition: saveload.h:255
Northeast, upper right on your monitor.
GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches) ...
Definition: newgrf_config.h:25
216 PR#7380 Multiple docks per station.
Definition: saveload.h:302
GameCreationSettings game_creation
settings used during the creation of a game (map)
static bool IsPlainRail(TileIndex t)
Returns whether this is plain rails, with or without signals.
Definition: rail_map.h:49
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition: tile_type.h:41
void GamelogTestMode()
Finds last stored game mode or landscape.
Definition: gamelog.cpp:521
142 20003
Definition: saveload.h:212
99 13838
Definition: saveload.h:160
A house by a town.
Definition: tile_type.h:44
Full road along the y-axis (north-west + south-east)
Definition: road_type.h:57
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
182 25115 FS#5492, r25259, r25296 Goal status
Definition: saveload.h:260
uint8 roadveh_slope_steepness
Steepness of hills for road vehicles when using realistic acceleration.
int32 y_pos
y coordinate.
Definition: vehicle_base.h:267
74 11030
Definition: saveload.h:130
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:102
TreeGround
Enumeration for ground types of tiles with trees.
Definition: tree_map.h:52
136 18764
Definition: saveload.h:205
152 21171
Definition: saveload.h:224
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:113
Road vehicle is a tram/light rail vehicle.
Definition: engine_type.h:154
161 22567
Definition: saveload.h:235
byte wait_for_pbs_path
how long to wait for a path reservation.
RailTypes GetCompanyRailtypes(CompanyID company, bool introduces)
Get the rail types the given company can build.
Definition: rail.cpp:251
128 18281
Definition: saveload.h:195
95 12924
Definition: saveload.h:156
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
void ResetWindowSystem()
Reset the windowing system, by means of shutting it down followed by re-initialization.
Definition: window.cpp:1934
static bool IsDepotTile(TileIndex tile)
Is the given tile a tile with a depot on it?
Definition: depot_map.h:41
Station with train station.
Definition: station_type.h:52
bool SaveloadCrashWithMissingNewGRFs()
Did loading the savegame cause a crash? If so, were NewGRFs missing?
Definition: afterload.cpp:356
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF) ...
Definition: newgrf_config.h:84
void DeleteInvalidEngineNews()
Remove engine announcements for invalid engines.
Definition: news_gui.cpp:949
Force unloading all cargo onto the platform, possibly not getting paid.
Definition: order_type.h:54
byte industry_density
The industry density.
Definition: settings_type.h:56
uint8 pathfinder_for_ships
the pathfinder to use for ships
bool rail_use_yapf
use YAPF for rail
static void SetTrackReservation(TileIndex t, TrackBits b)
Sets the reserved track bits of the tile.
Definition: rail_map.h:209
126 17433
Definition: saveload.h:193
213 PR#7405 WaterClass update for tree tiles.
Definition: saveload.h:298
36 6624
Definition: saveload.h:85
Data for backing up an order of a vehicle so it can be restored after a vehicle is rebuilt in the sam...
Definition: order_backup.h:35
172 23947
Definition: saveload.h:248
static void SetTownIndex(TileIndex t, TownID index)
Set the town index for a road or house tile.
Definition: town_map.h:34
31 5999
Definition: saveload.h:79
static bool IsDock(TileIndex t)
Is tile t a dock tile?
Definition: station_map.h:285
static Station * Get(size_t index)
Gets station with given index.
133 18674
Definition: saveload.h:201
Date _date
Current date in days (day counter)
Definition: date.cpp:26
void ResetCompanyLivery(Company *c)
Reset the livery schemes to the company&#39;s primary colour.
200 PR#6805 Extend railtypes to 64, adding uint16 to map array.
Definition: saveload.h:283
81 11244
Definition: saveload.h:139
uint16 h
The height of the area.
Definition: tilearea_type.h:19
static Direction ReverseDir(Direction d)
Return the reverse of a direction.
byte wait_oneway_signal
waitingtime in days before a oneway signal
static void SetDockingTile(TileIndex t, bool b)
Set the docking tile state of a tile.
Definition: water_map.h:355
64 10006
Definition: saveload.h:118
46 8705
Definition: saveload.h:97
bool allow_town_level_crossings
towns are allowed to build level crossings
byte m3
General purpose.
Definition: map_type.h:22
100 13952
Definition: saveload.h:162
Declaration of functions used in more save/load files.
27 4757
Definition: saveload.h:74
Depot (one entrance)
Definition: road_map.h:24
uint8 feeder_payment_share
percentage of leg payment to virtually pay in feeder systems
Y-axis track.
Definition: track_type.h:41
Valid changes while vehicle is driving, and possibly changing tracks.
Definition: train.h:48
Base class for all station-ish types.
Station data structure.
Definition: station_base.h:450
Axis
Allow incrementing of DiagDirDiff variables.
static const GRFIdentifier * GetOverriddenIdentifier(const GRFConfig *c)
Try to find the overridden GRF identifier of the given GRF.
Definition: afterload.cpp:335
static bool IsRoadDepot(TileIndex t)
Return whether a tile is a road depot.
Definition: road_map.h:105
static const ObjectType OBJECT_HQ
HeadQuarter of a player.
Definition: object_type.h:20
LinkGraphSettings linkgraph
settings for link graph calculations
Used for industry tiles on land (also for oilrig if newgrf says so).
Definition: water_map.h:51
Road vehicle type.
Definition: vehicle_type.h:25
A game paused because a (critical) error.
Definition: openttd.h:60
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:163
131 18481
Definition: saveload.h:199
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:115
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:316
static bool IsBridge(TileIndex t)
Checks if this is a bridge, instead of a tunnel.
Definition: bridge_map.h:24
static Direction DiagDirToDir(DiagDirection dir)
Convert a DiagDirection to a Direction.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3316
static void SetTropicZone(TileIndex tile, TropicZone type)
Set the tropic zone.
Definition: tile_map.h:225
4.0 1 4.1 122 0.3.3, 0.3.4 4.2 1222 0.3.5 4.3 1417 4.4 1426
Definition: saveload.h:36
Track in the upper corner of the tile (north)
Definition: track_type.h:23
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1462
Source/destination is an industry.
Definition: cargo_type.h:147
static void SetSignalHandlers()
Replaces signal handlers of SIGSEGV and SIGABRT and stores pointers to original handlers in memory...
Definition: afterload.cpp:313
static void SetRailType(TileIndex t, RailType r)
Sets the rail type of the given tile.
Definition: rail_map.h:125
Southwest.
166 23415
Definition: saveload.h:241
90 12293
Definition: saveload.h:150
void GfxLoadSprites()
Initialise and load all the sprites.
Definition: gfxinit.cpp:338
86 12042
Definition: saveload.h:145
uint16 max_tunnel_length
maximum length of tunnels
void Reset()
Completely reset the industry build data.
uint8 pathfinder_for_roadvehs
the pathfinder to use for roadvehicles
byte currency
currency we currently use
bool SettingsDisableElrail(int32 p1)
_settings_game.disable_elrail callback
Definition: elrail.cpp:592
uint8 max_train_length
maximum length for trains
static void SetDepotReservation(TileIndex t, bool b)
Set the reservation state of the depot.
Definition: rail_map.h:270
byte m4
General purpose.
Definition: map_type.h:23
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.