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