OpenTTD
afterload.cpp
Go to the documentation of this file.
1 /* $Id: afterload.cpp 27893 2017-08-13 18:38:42Z frosch $ */
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 
59 
60 #include "saveload_internal.h"
61 
62 #include <signal.h>
63 
64 #include "../safeguards.h"
65 
66 extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY);
67 
78 void SetWaterClassDependingOnSurroundings(TileIndex t, bool include_invalid_water_class)
79 {
80  /* If the slope is not flat, we always assume 'land' (if allowed). Also for one-corner-raised-shores.
81  * Note: Wrt. autosloping under industry tiles this is the most fool-proof behaviour. */
82  if (!IsTileFlat(t)) {
83  if (include_invalid_water_class) {
85  return;
86  } else {
87  SlErrorCorrupt("Invalid water class for dry tile");
88  }
89  }
90 
91  /* Mark tile dirty in all cases */
93 
94  if (TileX(t) == 0 || TileY(t) == 0 || TileX(t) == MapMaxX() - 1 || TileY(t) == MapMaxY() - 1) {
95  /* tiles at map borders are always WATER_CLASS_SEA */
97  return;
98  }
99 
100  bool has_water = false;
101  bool has_canal = false;
102  bool has_river = false;
103 
104  for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
105  TileIndex neighbour = TileAddByDiagDir(t, dir);
106  switch (GetTileType(neighbour)) {
107  case MP_WATER:
108  /* clear water and shipdepots have already a WaterClass associated */
109  if (IsCoast(neighbour)) {
110  has_water = true;
111  } else if (!IsLock(neighbour)) {
112  switch (GetWaterClass(neighbour)) {
113  case WATER_CLASS_SEA: has_water = true; break;
114  case WATER_CLASS_CANAL: has_canal = true; break;
115  case WATER_CLASS_RIVER: has_river = true; break;
116  default: SlErrorCorrupt("Invalid water class for tile");
117  }
118  }
119  break;
120 
121  case MP_RAILWAY:
122  /* Shore or flooded halftile */
123  has_water |= (GetRailGroundType(neighbour) == RAIL_GROUND_WATER);
124  break;
125 
126  case MP_TREES:
127  /* trees on shore */
128  has_water |= (GB(_m[neighbour].m2, 4, 2) == TREE_GROUND_SHORE);
129  break;
130 
131  default: break;
132  }
133  }
134 
135  if (!has_water && !has_canal && !has_river && include_invalid_water_class) {
137  return;
138  }
139 
140  if (has_river && !has_canal) {
142  } else if (has_canal || !has_water) {
144  } else {
146  }
147 }
148 
149 static void ConvertTownOwner()
150 {
151  for (TileIndex tile = 0; tile != MapSize(); tile++) {
152  switch (GetTileType(tile)) {
153  case MP_ROAD:
154  if (GB(_m[tile].m5, 4, 2) == ROAD_TILE_CROSSING && HasBit(_m[tile].m3, 7)) {
155  _m[tile].m3 = OWNER_TOWN;
156  }
157  FALLTHROUGH;
158 
159  case MP_TUNNELBRIDGE:
160  if (_m[tile].m1 & 0x80) SetTileOwner(tile, OWNER_TOWN);
161  break;
162 
163  default: break;
164  }
165  }
166 }
167 
168 /* since savegame version 4.1, exclusive transport rights are stored at towns */
169 static void UpdateExclusiveRights()
170 {
171  Town *t;
172 
173  FOR_ALL_TOWNS(t) {
175  }
176 
177  /* FIXME old exclusive rights status is not being imported (stored in s->blocked_months_obsolete)
178  * could be implemented this way:
179  * 1.) Go through all stations
180  * Build an array town_blocked[ town_id ][ company_id ]
181  * that stores if at least one station in that town is blocked for a company
182  * 2.) Go through that array, if you find a town that is not blocked for
183  * one company, but for all others, then give him exclusivity.
184  */
185 }
186 
187 static const byte convert_currency[] = {
188  0, 1, 12, 8, 3,
189  10, 14, 19, 4, 5,
190  9, 11, 13, 6, 17,
191  16, 22, 21, 7, 15,
192  18, 2, 20,
193 };
194 
195 /* since savegame version 4.2 the currencies are arranged differently */
196 static void UpdateCurrencies()
197 {
199 }
200 
201 /* Up to revision 1413 the invisible tiles at the southern border have not been
202  * MP_VOID, even though they should have. This is fixed by this function
203  */
204 static void UpdateVoidTiles()
205 {
206  uint i;
207 
208  for (i = 0; i < MapMaxY(); ++i) MakeVoid(i * MapSizeX() + MapMaxX());
209  for (i = 0; i < MapSizeX(); ++i) MakeVoid(MapSizeX() * MapMaxY() + i);
210 }
211 
212 static inline RailType UpdateRailType(RailType rt, RailType min)
213 {
214  return rt >= min ? (RailType)(rt + 1): rt;
215 }
216 
221 {
225 }
226 
237 {
238  /* Initialize windows */
241 
242  /* Update coordinates of the signs. */
244  ResetViewportAfterLoadGame();
245 
246  Company *c;
247  FOR_ALL_COMPANIES(c) {
248  /* For each company, verify (while loading a scenario) that the inauguration date is the current year and set it
249  * accordingly if it is not the case. No need to set it on companies that are not been used already,
250  * thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */
253  }
254  }
255 
256  /* Count number of objects per type */
257  Object *o;
258  FOR_ALL_OBJECTS(o) {
260  }
261 
262  /* Identify owners of persistent storage arrays */
263  Industry *i;
264  FOR_ALL_INDUSTRIES(i) {
265  if (i->psa != NULL) {
266  i->psa->feature = GSF_INDUSTRIES;
267  i->psa->tile = i->location.tile;
268  }
269  }
270  Station *s;
271  FOR_ALL_STATIONS(s) {
272  if (s->airport.psa != NULL) {
273  s->airport.psa->feature = GSF_AIRPORTS;
274  s->airport.psa->tile = s->airport.tile;
275  }
276  }
277  Town *t;
278  FOR_ALL_TOWNS(t) {
279  for (std::list<PersistentStorage *>::iterator it = t->psa_list.begin(); it != t->psa_list.end(); ++it) {
280  (*it)->feature = GSF_FAKE_TOWNS;
281  (*it)->tile = t->xy;
282  }
283  }
284 
285  RecomputePrices();
286 
288 
291 
292  /* Towns have a noise controlled number of airports system
293  * So each airport's noise value must be added to the town->noise_reached value
294  * Reset each town's noise_reached value to '0' before. */
296 
298  ShowNewGRFError();
300 
301  /* Rebuild the smallmap list of owners. */
303 }
304 
305 typedef void (CDECL *SignalHandlerPointer)(int);
306 static SignalHandlerPointer _prev_segfault = NULL;
307 static SignalHandlerPointer _prev_abort = NULL;
308 static SignalHandlerPointer _prev_fpe = NULL;
309 
310 static void CDECL HandleSavegameLoadCrash(int signum);
311 
316 static void SetSignalHandlers()
317 {
318  _prev_segfault = signal(SIGSEGV, HandleSavegameLoadCrash);
319  _prev_abort = signal(SIGABRT, HandleSavegameLoadCrash);
320  _prev_fpe = signal(SIGFPE, HandleSavegameLoadCrash);
321 }
322 
326 static void ResetSignalHandlers()
327 {
328  signal(SIGSEGV, _prev_segfault);
329  signal(SIGABRT, _prev_abort);
330  signal(SIGFPE, _prev_fpe);
331 }
332 
339 {
341  if (la->at != GLAT_LOAD) return &c->ident;
342 
343  const LoggedChange *lcend = &la->change[la->changes];
344  for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
345  if (lc->ct == GLCT_GRFCOMPAT && lc->grfcompat.grfid == c->ident.grfid) return &lc->grfcompat;
346  }
347 
348  return &c->ident;
349 }
350 
353 
360 {
362 }
363 
370 static void CDECL HandleSavegameLoadCrash(int signum)
371 {
373 
374  char buffer[8192];
375  char *p = buffer;
376  p += seprintf(p, lastof(buffer), "Loading your savegame caused OpenTTD to crash.\n");
377 
378  for (const GRFConfig *c = _grfconfig; !_saveload_crash_with_missing_newgrfs && c != NULL; c = c->next) {
380  }
381 
383  p += seprintf(p, lastof(buffer),
384  "This is most likely caused by a missing NewGRF or a NewGRF that\n"
385  "has been loaded as replacement for a missing NewGRF. OpenTTD\n"
386  "cannot easily determine whether a replacement NewGRF is of a newer\n"
387  "or older version.\n"
388  "It will load a NewGRF with the same GRF ID as the missing NewGRF.\n"
389  "This means that if the author makes incompatible NewGRFs with the\n"
390  "same GRF ID OpenTTD cannot magically do the right thing. In most\n"
391  "cases OpenTTD will load the savegame and not crash, but this is an\n"
392  "exception.\n"
393  "Please load the savegame with the appropriate NewGRFs installed.\n"
394  "The missing/compatible NewGRFs are:\n");
395 
396  for (const GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
397  if (HasBit(c->flags, GCF_COMPATIBLE)) {
398  const GRFIdentifier *replaced = GetOverriddenIdentifier(c);
399  char buf[40];
400  md5sumToString(buf, lastof(buf), replaced->md5sum);
401  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);
402  }
403  if (c->status == GCS_NOT_FOUND) {
404  char buf[40];
405  md5sumToString(buf, lastof(buf), c->ident.md5sum);
406  p += seprintf(p, lastof(buffer), "NewGRF %08X (%s) not found; checksum %s.\n", BSWAP32(c->ident.grfid), c->filename, buf);
407  }
408  }
409  } else {
410  p += seprintf(p, lastof(buffer),
411  "This is probably caused by a corruption in the savegame.\n"
412  "Please file a bug report and attach this savegame.\n");
413  }
414 
415  ShowInfo(buffer);
416 
417  SignalHandlerPointer call = NULL;
418  switch (signum) {
419  case SIGSEGV: call = _prev_segfault; break;
420  case SIGABRT: call = _prev_abort; break;
421  case SIGFPE: call = _prev_fpe; break;
422  default: NOT_REACHED();
423  }
424  if (call != NULL) call(signum);
425 }
426 
433 {
435 
436  /* remove leftover rail piece from crossing (from very old savegames) */
437  Train *v = NULL, *w;
438  FOR_ALL_TRAINS(w) {
439  if (w->tile == t) {
440  v = w;
441  break;
442  }
443  }
444 
445  if (v != NULL) {
446  /* when there is a train on crossing (it could happen in TTD), set owner of crossing to train owner */
447  SetTileOwner(t, v->owner);
448  return;
449  }
450 
451  /* try to find any connected rail */
452  for (DiagDirection dd = DIAGDIR_BEGIN; dd < DIAGDIR_END; dd++) {
453  TileIndex tt = t + TileOffsByDiagDir(dd);
454  if (GetTileTrackStatus(t, TRANSPORT_RAIL, 0, dd) != 0 &&
457  SetTileOwner(t, GetTileOwner(tt));
458  return;
459  }
460  }
461 
462  if (IsLevelCrossingTile(t)) {
463  /* else change the crossing to normal road (road vehicles won't care) */
466  return;
467  }
468 
469  /* if it's not a crossing, make it clean land */
470  MakeClear(t, CLEAR_GRASS, 0);
471 }
472 
480 {
481  /* Compute place where this vehicle entered the tile */
482  int entry_x = v->x_pos;
483  int entry_y = v->y_pos;
484  switch (dir) {
485  case DIR_NE: entry_x |= TILE_UNIT_MASK; break;
486  case DIR_NW: entry_y |= TILE_UNIT_MASK; break;
487  case DIR_SW: entry_x &= ~TILE_UNIT_MASK; break;
488  case DIR_SE: entry_y &= ~TILE_UNIT_MASK; break;
489  case INVALID_DIR: break;
490  default: NOT_REACHED();
491  }
492  byte entry_z = GetSlopePixelZ(entry_x, entry_y);
493 
494  /* Compute middle of the tile. */
495  int middle_x = (v->x_pos & ~TILE_UNIT_MASK) + TILE_SIZE / 2;
496  int middle_y = (v->y_pos & ~TILE_UNIT_MASK) + TILE_SIZE / 2;
497  byte middle_z = GetSlopePixelZ(middle_x, middle_y);
498 
499  /* middle_z == entry_z, no height change. */
500  if (middle_z == entry_z) return 0;
501 
502  /* middle_z < entry_z, we are going downwards. */
503  if (middle_z < entry_z) return 1U << GVF_GOINGDOWN_BIT;
504 
505  /* middle_z > entry_z, we are going upwards. */
506  return 1U << GVF_GOINGUP_BIT;
507 }
508 
515 static inline bool MayHaveBridgeAbove(TileIndex t)
516 {
517  return IsTileType(t, MP_CLEAR) || IsTileType(t, MP_RAILWAY) || IsTileType(t, MP_ROAD) ||
519 }
520 
527 {
529 
530  TileIndex map_size = MapSize();
531 
532  extern TileIndex _cur_tileloop_tile; // From landscape.cpp.
533  /* The LFSR used in RunTileLoop iteration cannot have a zeroed state, make it non-zeroed. */
534  if (_cur_tileloop_tile == 0) _cur_tileloop_tile = 1;
535 
537 
539  GamelogTestMode();
540 
542 
543  if (IsSavegameVersionBefore(119)) {
545  } else if (_network_dedicated && (_pause_mode & PM_PAUSED_ERROR) != 0) {
546  DEBUG(net, 0, "The loading savegame was paused due to an error state.");
547  DEBUG(net, 0, " The savegame cannot be used for multiplayer!");
548  /* Restore the signals */
550  return false;
551  } else if (!_networking || _network_server) {
552  /* If we are in single player, i.e. not networking, and loading the
553  * savegame or we are loading the savegame as network server we do
554  * not want to be bothered by being paused because of the automatic
555  * reason of a network server, e.g. joining clients or too few
556  * active clients. Note that resetting these values for a network
557  * client are very bad because then the client is going to execute
558  * the game loop when the server is not, i.e. it desyncs. */
560  }
561 
562  /* In very old versions, size of train stations was stored differently.
563  * They had swapped width and height if station was built along the Y axis.
564  * TTO and TTD used 3 bits for width/height, while OpenTTD used 4.
565  * Because the data stored by TTDPatch are unusable for rail stations > 7x7,
566  * recompute the width and height. Doing this unconditionally for all old
567  * savegames simplifies the code. */
568  if (IsSavegameVersionBefore(2)) {
569  Station *st;
570  FOR_ALL_STATIONS(st) {
571  st->train_station.w = st->train_station.h = 0;
572  }
573  for (TileIndex t = 0; t < map_size; t++) {
574  if (!IsTileType(t, MP_STATION)) continue;
575  if (_m[t].m5 > 7) continue; // is it a rail station tile?
576  st = Station::Get(_m[t].m2);
577  assert(st->train_station.tile != 0);
578  int dx = TileX(t) - TileX(st->train_station.tile);
579  int dy = TileY(t) - TileY(st->train_station.tile);
580  assert(dx >= 0 && dy >= 0);
581  st->train_station.w = max<uint>(st->train_station.w, dx + 1);
582  st->train_station.h = max<uint>(st->train_station.h, dy + 1);
583  }
584  }
585 
586  if (IsSavegameVersionBefore(194)) {
588 
589  /* In old savegame versions, the heightlevel was coded in bits 0..3 of the type field */
590  for (TileIndex t = 0; t < map_size; t++) {
591  _m[t].height = GB(_m[t].type, 0, 4);
592  SB(_m[t].type, 0, 2, GB(_me[t].m6, 0, 2));
593  SB(_me[t].m6, 0, 2, 0);
594  if (MayHaveBridgeAbove(t)) {
595  SB(_m[t].type, 2, 2, GB(_me[t].m6, 6, 2));
596  SB(_me[t].m6, 6, 2, 0);
597  } else {
598  SB(_m[t].type, 2, 2, 0);
599  }
600  }
601  }
602 
603  /* in version 2.1 of the savegame, town owner was unified. */
604  if (IsSavegameVersionBefore(2, 1)) ConvertTownOwner();
605 
606  /* from version 4.1 of the savegame, exclusive rights are stored at towns */
607  if (IsSavegameVersionBefore(4, 1)) UpdateExclusiveRights();
608 
609  /* from version 4.2 of the savegame, currencies are in a different order */
610  if (IsSavegameVersionBefore(4, 2)) UpdateCurrencies();
611 
612  /* In old version there seems to be a problem that water is owned by
613  * OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current
614  * (4.3) version, so I just check when versions are older, and then
615  * walk through the whole map.. */
616  if (IsSavegameVersionBefore(4, 3)) {
617  for (TileIndex t = 0; t < map_size; t++) {
618  if (IsTileType(t, MP_WATER) && GetTileOwner(t) >= MAX_COMPANIES) {
620  }
621  }
622  }
623 
624  if (IsSavegameVersionBefore(84)) {
625  Company *c;
626  FOR_ALL_COMPANIES(c) {
627  c->name = CopyFromOldName(c->name_1);
628  if (c->name != NULL) c->name_1 = STR_SV_UNNAMED;
630  if (c->president_name != NULL) c->president_name_1 = SPECSTR_PRESIDENT_NAME;
631  }
632 
633  Station *st;
634  FOR_ALL_STATIONS(st) {
635  st->name = CopyFromOldName(st->string_id);
636  /* generating new name would be too much work for little effect, use the station name fallback */
637  if (st->name != NULL) st->string_id = STR_SV_STNAME_FALLBACK;
638  }
639 
640  Town *t;
641  FOR_ALL_TOWNS(t) {
642  t->name = CopyFromOldName(t->townnametype);
643  if (t->name != NULL) t->townnametype = SPECSTR_TOWNNAME_START + _settings_game.game_creation.town_name;
644  }
645  }
646 
647  /* From this point the old names array is cleared. */
648  ResetOldNames();
649 
650  if (IsSavegameVersionBefore(106)) {
651  /* no station is determined by 'tile == INVALID_TILE' now (instead of '0') */
652  Station *st;
653  FOR_ALL_STATIONS(st) {
654  if (st->airport.tile == 0) st->airport.tile = INVALID_TILE;
655  if (st->dock_tile == 0) st->dock_tile = INVALID_TILE;
656  if (st->train_station.tile == 0) st->train_station.tile = INVALID_TILE;
657  }
658 
659  /* the same applies to Company::location_of_HQ */
660  Company *c;
661  FOR_ALL_COMPANIES(c) {
662  if (c->location_of_HQ == 0 || (IsSavegameVersionBefore(4) && c->location_of_HQ == 0xFFFF)) {
664  }
665  }
666  }
667 
668  /* convert road side to my format. */
670 
671  /* Check if all NewGRFs are present, we are very strict in MP mode */
673  for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
674  if (c->status == GCS_NOT_FOUND) {
675  GamelogGRFRemove(c->ident.grfid);
676  } else if (HasBit(c->flags, GCF_COMPATIBLE)) {
677  GamelogGRFCompatible(&c->ident);
678  }
679  }
680 
681  if (_networking && gcf_res != GLC_ALL_GOOD) {
682  SetSaveLoadError(STR_NETWORK_ERROR_CLIENT_NEWGRF_MISMATCH);
683  /* Restore the signals */
685  return false;
686  }
687 
688  switch (gcf_res) {
689  case GLC_COMPATIBLE: ShowErrorMessage(STR_NEWGRF_COMPATIBLE_LOAD_WARNING, INVALID_STRING_ID, WL_CRITICAL); break;
690  case GLC_NOT_FOUND: ShowErrorMessage(STR_NEWGRF_DISABLED_WARNING, INVALID_STRING_ID, WL_CRITICAL); _pause_mode = PM_PAUSED_ERROR; break;
691  default: break;
692  }
693 
694  /* The value of _date_fract got divided, so make sure that old games are converted correctly. */
696 
697  /* Update current year
698  * must be done before loading sprites as some newgrfs check it */
700 
701  /*
702  * Force the old behaviour for compatibility reasons with old savegames. As new
703  * settings can only be loaded from new savegames loading old savegames with new
704  * versions of OpenTTD will normally initialize settings newer than the savegame
705  * version with "new game" defaults which the player can define to their liking.
706  * For some settings we override that to keep the behaviour the same as when the
707  * game was saved.
708  *
709  * Note that there is no non-stop in here. This is because the setting could have
710  * either value in TTDPatch. To convert it properly the user has to make sure the
711  * right value has been chosen in the settings. Otherwise we will be converting
712  * it incorrectly in half of the times without a means to correct that.
713  */
720  if (IsSavegameVersionBefore(133)) {
722  }
725  if (IsSavegameVersionBefore(139)) {
728  }
730  if (IsSavegameVersionBefore(159)) {
734  }
736  if (IsSavegameVersionBefore(183)) {
741  }
742 
743  /* Load the sprites */
744  GfxLoadSprites();
746 
747  /* Copy temporary data to Engine pool */
749 
750  /* Connect front and rear engines of multiheaded trains and converts
751  * subtype to the new format */
753 
754  /* Connect front and rear engines of multiheaded trains */
756 
757  /* Fix the CargoPackets *and* fix the caches of CargoLists.
758  * If this isn't done before Stations and especially Vehicles are
759  * running their AfterLoad we might get in trouble. In the case of
760  * vehicles we could give the wrong (cached) count of items in a
761  * vehicle which causes different results when getting their caches
762  * filled; and that could eventually lead to desyncs. */
764 
765  /* Oilrig was moved from id 15 to 9. We have to do this conversion
766  * here as AfterLoadVehicles can check it indirectly via the newgrf
767  * code. */
768  if (IsSavegameVersionBefore(139)) {
769  Station *st;
770  FOR_ALL_STATIONS(st) {
771  if (st->airport.tile != INVALID_TILE && st->airport.type == 15) {
772  st->airport.type = AT_OILRIG;
773  }
774  }
775  }
776 
777  /* Update all vehicles */
778  AfterLoadVehicles(true);
779 
780  /* Make sure there is an AI attached to an AI company */
781  {
782  Company *c;
783  FOR_ALL_COMPANIES(c) {
784  if (c->is_ai && c->ai_instance == NULL) AI::StartNew(c->index);
785  }
786  }
787 
788  /* make sure there is a town in the game */
789  if (_game_mode == GM_NORMAL && Town::GetNumItems() == 0) {
790  SetSaveLoadError(STR_ERROR_NO_TOWN_IN_SCENARIO);
791  /* Restore the signals */
793  return false;
794  }
795 
796  /* The void tiles on the southern border used to belong to a wrong class (pre 4.3).
797  * This problem appears in savegame version 21 too, see r3455. But after loading the
798  * savegame and saving again, the buggy map array could be converted to new savegame
799  * version. It didn't show up before r12070. */
800  if (IsSavegameVersionBefore(87)) UpdateVoidTiles();
801 
802  /* If Load Scenario / New (Scenario) Game is used,
803  * a company does not exist yet. So create one here.
804  * 1 exception: network-games. Those can have 0 companies
805  * But this exception is not true for non-dedicated network servers! */
807  DoStartupNewCompany(false);
810  }
811 
812  /* Fix the cache for cargo payments. */
813  CargoPayment *cp;
815  cp->front->cargo_payment = cp;
817  }
818 
819  if (IsSavegameVersionBefore(72)) {
820  /* Locks in very old savegames had OWNER_WATER as owner */
821  for (TileIndex t = 0; t < MapSize(); t++) {
822  switch (GetTileType(t)) {
823  default: break;
824 
825  case MP_WATER:
827  break;
828 
829  case MP_STATION: {
830  if (HasBit(_me[t].m6, 3)) SetBit(_me[t].m6, 2);
831  StationGfx gfx = GetStationGfx(t);
832  StationType st;
833  if ( IsInsideMM(gfx, 0, 8)) { // Rail station
834  st = STATION_RAIL;
835  SetStationGfx(t, gfx - 0);
836  } else if (IsInsideMM(gfx, 8, 67)) { // Airport
837  st = STATION_AIRPORT;
838  SetStationGfx(t, gfx - 8);
839  } else if (IsInsideMM(gfx, 67, 71)) { // Truck
840  st = STATION_TRUCK;
841  SetStationGfx(t, gfx - 67);
842  } else if (IsInsideMM(gfx, 71, 75)) { // Bus
843  st = STATION_BUS;
844  SetStationGfx(t, gfx - 71);
845  } else if (gfx == 75) { // Oil rig
846  st = STATION_OILRIG;
847  SetStationGfx(t, gfx - 75);
848  } else if (IsInsideMM(gfx, 76, 82)) { // Dock
849  st = STATION_DOCK;
850  SetStationGfx(t, gfx - 76);
851  } else if (gfx == 82) { // Buoy
852  st = STATION_BUOY;
853  SetStationGfx(t, gfx - 82);
854  } else if (IsInsideMM(gfx, 83, 168)) { // Extended airport
855  st = STATION_AIRPORT;
856  SetStationGfx(t, gfx - 83 + 67 - 8);
857  } else if (IsInsideMM(gfx, 168, 170)) { // Drive through truck
858  st = STATION_TRUCK;
860  } else if (IsInsideMM(gfx, 170, 172)) { // Drive through bus
861  st = STATION_BUS;
863  } else {
864  /* Restore the signals */
866  return false;
867  }
868  SB(_me[t].m6, 3, 3, st);
869  break;
870  }
871  }
872  }
873  }
874 
875  for (TileIndex t = 0; t < map_size; t++) {
876  switch (GetTileType(t)) {
877  case MP_STATION: {
879 
880  /* Set up station spread */
881  bst->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
882 
883  /* Waypoints don't have road stops/oil rigs in the old format */
884  if (!Station::IsExpected(bst)) break;
885  Station *st = Station::From(bst);
886 
887  switch (GetStationType(t)) {
888  case STATION_TRUCK:
889  case STATION_BUS:
890  if (IsSavegameVersionBefore(6)) {
891  /* Before version 5 you could not have more than 250 stations.
892  * Version 6 adds large maps, so you could only place 253*253
893  * road stops on a map (no freeform edges) = 64009. So, yes
894  * someone could in theory create such a full map to trigger
895  * this assertion, it's safe to assume that's only something
896  * theoretical and does not happen in normal games. */
897  assert(RoadStop::CanAllocateItem());
898 
899  /* From this version on there can be multiple road stops of the
900  * same type per station. Convert the existing stops to the new
901  * internal data structure. */
902  RoadStop *rs = new RoadStop(t);
903 
904  RoadStop **head =
905  IsTruckStop(t) ? &st->truck_stops : &st->bus_stops;
906  *head = rs;
907  }
908  break;
909 
910  case STATION_OILRIG: {
911  /* Very old savegames sometimes have phantom oil rigs, i.e.
912  * an oil rig which got shut down, but not completely removed from
913  * the map
914  */
915  TileIndex t1 = TILE_ADDXY(t, 0, 1);
916  if (IsTileType(t1, MP_INDUSTRY) &&
917  GetIndustryGfx(t1) == GFX_OILRIG_1) {
918  /* The internal encoding of oil rigs was changed twice.
919  * It was 3 (till 2.2) and later 5 (till 5.1).
920  * Setting it unconditionally does not hurt.
921  */
923  } else {
924  DeleteOilRig(t);
925  }
926  break;
927  }
928 
929  default: break;
930  }
931  break;
932  }
933 
934  default: break;
935  }
936  }
937 
938  /* In version 2.2 of the savegame, we have new airports, so status of all aircraft is reset.
939  * This has to be called after the oilrig airport_type update above ^^^ ! */
941 
942  /* In version 6.1 we put the town index in the map-array. To do this, we need
943  * to use m2 (16bit big), so we need to clean m2, and that is where this is
944  * all about ;) */
945  if (IsSavegameVersionBefore(6, 1)) {
946  for (TileIndex t = 0; t < map_size; t++) {
947  switch (GetTileType(t)) {
948  case MP_HOUSE:
949  _m[t].m4 = _m[t].m2;
951  break;
952 
953  case MP_ROAD:
954  _m[t].m4 |= (_m[t].m2 << 4);
955  if ((GB(_m[t].m5, 4, 2) == ROAD_TILE_CROSSING ? (Owner)_m[t].m3 : GetTileOwner(t)) == OWNER_TOWN) {
957  } else {
958  SetTownIndex(t, 0);
959  }
960  break;
961 
962  default: break;
963  }
964  }
965  }
966 
967  /* Force the freeform edges to false for old savegames. */
968  if (IsSavegameVersionBefore(111)) {
970  }
971 
972  /* From version 9.0, we update the max passengers of a town (was sometimes negative
973  * before that. */
974  if (IsSavegameVersionBefore(9)) {
975  Town *t;
976  FOR_ALL_TOWNS(t) UpdateTownMaxPass(t);
977  }
978 
979  /* From version 16.0, we included autorenew on engines, which are now saved, but
980  * of course, we do need to initialize them for older savegames. */
981  if (IsSavegameVersionBefore(16)) {
982  Company *c;
983  FOR_ALL_COMPANIES(c) {
984  c->engine_renew_list = NULL;
985  c->settings.engine_renew = false;
987  c->settings.engine_renew_money = 100000;
988  }
989 
990  /* When loading a game, _local_company is not yet set to the correct value.
991  * However, in a dedicated server we are a spectator, so nothing needs to
992  * happen. In case we are not a dedicated server, the local company always
993  * becomes company 0, unless we are in the scenario editor where all the
994  * companies are 'invalid'.
995  */
997  if (!_network_dedicated && c != NULL) {
999  }
1000  }
1001 
1002  if (IsSavegameVersionBefore(48)) {
1003  for (TileIndex t = 0; t < map_size; t++) {
1004  switch (GetTileType(t)) {
1005  case MP_RAILWAY:
1006  if (IsPlainRail(t)) {
1007  /* Swap ground type and signal type for plain rail tiles, so the
1008  * ground type uses the same bits as for depots and waypoints. */
1009  uint tmp = GB(_m[t].m4, 0, 4);
1010  SB(_m[t].m4, 0, 4, GB(_m[t].m2, 0, 4));
1011  SB(_m[t].m2, 0, 4, tmp);
1012  } else if (HasBit(_m[t].m5, 2)) {
1013  /* Split waypoint and depot rail type and remove the subtype. */
1014  ClrBit(_m[t].m5, 2);
1015  ClrBit(_m[t].m5, 6);
1016  }
1017  break;
1018 
1019  case MP_ROAD:
1020  /* Swap m3 and m4, so the track type for rail crossings is the
1021  * same as for normal rail. */
1022  Swap(_m[t].m3, _m[t].m4);
1023  break;
1024 
1025  default: break;
1026  }
1027  }
1028  }
1029 
1030  if (IsSavegameVersionBefore(61)) {
1031  /* Added the RoadType */
1032  bool old_bridge = IsSavegameVersionBefore(42);
1033  for (TileIndex t = 0; t < map_size; t++) {
1034  switch (GetTileType(t)) {
1035  case MP_ROAD:
1036  SB(_m[t].m5, 6, 2, GB(_m[t].m5, 4, 2));
1037  switch (GetRoadTileType(t)) {
1038  default: SlErrorCorrupt("Invalid road tile type");
1039  case ROAD_TILE_NORMAL:
1040  SB(_m[t].m4, 0, 4, GB(_m[t].m5, 0, 4));
1041  SB(_m[t].m4, 4, 4, 0);
1042  SB(_me[t].m6, 2, 4, 0);
1043  break;
1044  case ROAD_TILE_CROSSING:
1045  SB(_m[t].m4, 5, 2, GB(_m[t].m5, 2, 2));
1046  break;
1047  case ROAD_TILE_DEPOT: break;
1048  }
1050  break;
1051 
1052  case MP_STATION:
1054  break;
1055 
1056  case MP_TUNNELBRIDGE:
1057  /* Middle part of "old" bridges */
1058  if (old_bridge && IsBridge(t) && HasBit(_m[t].m5, 6)) break;
1059  if (((old_bridge && IsBridge(t)) ? (TransportType)GB(_m[t].m5, 1, 2) : GetTunnelBridgeTransportType(t)) == TRANSPORT_ROAD) {
1061  }
1062  break;
1063 
1064  default: break;
1065  }
1066  }
1067  }
1068 
1069  if (IsSavegameVersionBefore(114)) {
1070  bool fix_roadtypes = !IsSavegameVersionBefore(61);
1071  bool old_bridge = IsSavegameVersionBefore(42);
1072 
1073  for (TileIndex t = 0; t < map_size; t++) {
1074  switch (GetTileType(t)) {
1075  case MP_ROAD:
1076  if (fix_roadtypes) SetRoadTypes(t, (RoadTypes)GB(_me[t].m7, 5, 3));
1077  SB(_me[t].m7, 5, 1, GB(_m[t].m3, 7, 1)); // snow/desert
1078  switch (GetRoadTileType(t)) {
1079  default: SlErrorCorrupt("Invalid road tile type");
1080  case ROAD_TILE_NORMAL:
1081  SB(_me[t].m7, 0, 4, GB(_m[t].m3, 0, 4)); // road works
1082  SB(_me[t].m6, 3, 3, GB(_m[t].m3, 4, 3)); // ground
1083  SB(_m[t].m3, 0, 4, GB(_m[t].m4, 4, 4)); // tram bits
1084  SB(_m[t].m3, 4, 4, GB(_m[t].m5, 0, 4)); // tram owner
1085  SB(_m[t].m5, 0, 4, GB(_m[t].m4, 0, 4)); // road bits
1086  break;
1087 
1088  case ROAD_TILE_CROSSING:
1089  SB(_me[t].m7, 0, 5, GB(_m[t].m4, 0, 5)); // road owner
1090  SB(_me[t].m6, 3, 3, GB(_m[t].m3, 4, 3)); // ground
1091  SB(_m[t].m3, 4, 4, GB(_m[t].m5, 0, 4)); // tram owner
1092  SB(_m[t].m5, 0, 1, GB(_m[t].m4, 6, 1)); // road axis
1093  SB(_m[t].m5, 5, 1, GB(_m[t].m4, 5, 1)); // crossing state
1094  break;
1095 
1096  case ROAD_TILE_DEPOT:
1097  break;
1098  }
1099  if (!IsRoadDepot(t) && !HasTownOwnedRoad(t)) {
1100  const Town *town = CalcClosestTownFromTile(t);
1101  if (town != NULL) SetTownIndex(t, town->index);
1102  }
1103  _m[t].m4 = 0;
1104  break;
1105 
1106  case MP_STATION:
1107  if (!IsRoadStop(t)) break;
1108 
1109  if (fix_roadtypes) SetRoadTypes(t, (RoadTypes)GB(_m[t].m3, 0, 3));
1110  SB(_me[t].m7, 0, 5, HasBit(_me[t].m6, 2) ? OWNER_TOWN : GetTileOwner(t));
1111  SB(_m[t].m3, 4, 4, _m[t].m1);
1112  _m[t].m4 = 0;
1113  break;
1114 
1115  case MP_TUNNELBRIDGE:
1116  if (old_bridge && IsBridge(t) && HasBit(_m[t].m5, 6)) break;
1117  if (((old_bridge && IsBridge(t)) ? (TransportType)GB(_m[t].m5, 1, 2) : GetTunnelBridgeTransportType(t)) == TRANSPORT_ROAD) {
1118  if (fix_roadtypes) SetRoadTypes(t, (RoadTypes)GB(_m[t].m3, 0, 3));
1119 
1120  Owner o = GetTileOwner(t);
1121  SB(_me[t].m7, 0, 5, o); // road owner
1122  SB(_m[t].m3, 4, 4, o == OWNER_NONE ? OWNER_TOWN : o); // tram owner
1123  }
1124  SB(_me[t].m6, 2, 4, GB(_m[t].m2, 4, 4)); // bridge type
1125  SB(_me[t].m7, 5, 1, GB(_m[t].m4, 7, 1)); // snow/desert
1126 
1127  _m[t].m2 = 0;
1128  _m[t].m4 = 0;
1129  break;
1130 
1131  default: break;
1132  }
1133  }
1134  }
1135 
1136  if (IsSavegameVersionBefore(42)) {
1137  Vehicle *v;
1138 
1139  for (TileIndex t = 0; t < map_size; t++) {
1141  if (IsBridgeTile(t)) {
1142  if (HasBit(_m[t].m5, 6)) { // middle part
1143  Axis axis = (Axis)GB(_m[t].m5, 0, 1);
1144 
1145  if (HasBit(_m[t].m5, 5)) { // transport route under bridge?
1146  if (GB(_m[t].m5, 3, 2) == TRANSPORT_RAIL) {
1147  MakeRailNormal(
1148  t,
1149  GetTileOwner(t),
1150  axis == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X,
1151  GetRailType(t)
1152  );
1153  } else {
1154  TownID town = IsTileOwner(t, OWNER_TOWN) ? ClosestTownFromTile(t, UINT_MAX)->index : 0;
1155 
1157  t,
1158  axis == AXIS_X ? ROAD_Y : ROAD_X,
1160  town,
1162  );
1163  }
1164  } else {
1165  if (GB(_m[t].m5, 3, 2) == 0) {
1166  MakeClear(t, CLEAR_GRASS, 3);
1167  } else {
1168  if (!IsTileFlat(t)) {
1169  MakeShore(t);
1170  } else {
1171  if (GetTileOwner(t) == OWNER_WATER) {
1172  MakeSea(t);
1173  } else {
1174  MakeCanal(t, GetTileOwner(t), Random());
1175  }
1176  }
1177  }
1178  }
1179  SetBridgeMiddle(t, axis);
1180  } else { // ramp
1181  Axis axis = (Axis)GB(_m[t].m5, 0, 1);
1182  uint north_south = GB(_m[t].m5, 5, 1);
1183  DiagDirection dir = ReverseDiagDir(XYNSToDiagDir(axis, north_south));
1184  TransportType type = (TransportType)GB(_m[t].m5, 1, 2);
1185 
1186  _m[t].m5 = 1 << 7 | type << 2 | dir;
1187  }
1188  }
1189  }
1190 
1191  FOR_ALL_VEHICLES(v) {
1192  if (!v->IsGroundVehicle()) continue;
1193  if (IsBridgeTile(v->tile)) {
1195 
1196  if (dir != DirToDiagDir(v->direction)) continue;
1197  switch (dir) {
1198  default: SlErrorCorrupt("Invalid vehicle direction");
1199  case DIAGDIR_NE: if ((v->x_pos & 0xF) != 0) continue; break;
1200  case DIAGDIR_SE: if ((v->y_pos & 0xF) != TILE_SIZE - 1) continue; break;
1201  case DIAGDIR_SW: if ((v->x_pos & 0xF) != TILE_SIZE - 1) continue; break;
1202  case DIAGDIR_NW: if ((v->y_pos & 0xF) != 0) continue; break;
1203  }
1204  } else if (v->z_pos > GetSlopePixelZ(v->x_pos, v->y_pos)) {
1205  v->tile = GetNorthernBridgeEnd(v->tile);
1206  } else {
1207  continue;
1208  }
1209  if (v->type == VEH_TRAIN) {
1210  Train::From(v)->track = TRACK_BIT_WORMHOLE;
1211  } else {
1213  }
1214  }
1215  }
1216 
1217  /* Elrails got added in rev 24 */
1218  if (IsSavegameVersionBefore(24)) {
1219  RailType min_rail = RAILTYPE_ELECTRIC;
1220 
1221  Train *v;
1222  FOR_ALL_TRAINS(v) {
1223  RailType rt = RailVehInfo(v->engine_type)->railtype;
1224 
1225  v->railtype = rt;
1226  if (rt == RAILTYPE_ELECTRIC) min_rail = RAILTYPE_RAIL;
1227  }
1228 
1229  /* .. so we convert the entire map from normal to elrail (so maintain "fairness") */
1230  for (TileIndex t = 0; t < map_size; t++) {
1231  switch (GetTileType(t)) {
1232  case MP_RAILWAY:
1233  SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
1234  break;
1235 
1236  case MP_ROAD:
1237  if (IsLevelCrossing(t)) {
1238  SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
1239  }
1240  break;
1241 
1242  case MP_STATION:
1243  if (HasStationRail(t)) {
1244  SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
1245  }
1246  break;
1247 
1248  case MP_TUNNELBRIDGE:
1250  SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
1251  }
1252  break;
1253 
1254  default:
1255  break;
1256  }
1257  }
1258 
1259  FOR_ALL_TRAINS(v) {
1260  if (v->IsFrontEngine() || v->IsFreeWagon()) v->ConsistChanged(CCF_TRACK);
1261  }
1262 
1263  }
1264 
1265  /* In version 16.1 of the savegame a company can decide if trains, which get
1266  * replaced, shall keep their old length. In all prior versions, just default
1267  * to false */
1268  if (IsSavegameVersionBefore(16, 1)) {
1269  Company *c;
1270  FOR_ALL_COMPANIES(c) c->settings.renew_keep_length = false;
1271  }
1272 
1273  if (IsSavegameVersionBefore(123)) {
1274  /* Waypoints became subclasses of stations ... */
1276  /* ... and buoys were moved to waypoints. */
1278  }
1279 
1280  /* From version 15, we moved a semaphore bit from bit 2 to bit 3 in m4, making
1281  * room for PBS. Now in version 21 move it back :P. */
1283  for (TileIndex t = 0; t < map_size; t++) {
1284  switch (GetTileType(t)) {
1285  case MP_RAILWAY:
1286  if (HasSignals(t)) {
1287  /* Original signal type/variant was stored in m4 but since saveload
1288  * version 48 they are in m2. The bits has been already moved to m2
1289  * (see the code somewhere above) so don't use m4, use m2 instead. */
1290 
1291  /* convert PBS signals to combo-signals */
1292  if (HasBit(_m[t].m2, 2)) SB(_m[t].m2, 0, 2, SIGTYPE_COMBO);
1293 
1294  /* move the signal variant back */
1295  SB(_m[t].m2, 2, 1, HasBit(_m[t].m2, 3) ? SIG_SEMAPHORE : SIG_ELECTRIC);
1296  ClrBit(_m[t].m2, 3);
1297  }
1298 
1299  /* Clear PBS reservation on track */
1300  if (!IsRailDepotTile(t)) {
1301  SB(_m[t].m4, 4, 4, 0);
1302  } else {
1303  ClrBit(_m[t].m3, 6);
1304  }
1305  break;
1306 
1307  case MP_STATION: // Clear PBS reservation on station
1308  ClrBit(_m[t].m3, 6);
1309  break;
1310 
1311  default: break;
1312  }
1313  }
1314  }
1315 
1316  if (IsSavegameVersionBefore(25)) {
1317  RoadVehicle *rv;
1318  FOR_ALL_ROADVEHICLES(rv) {
1319  rv->vehstatus &= ~0x40;
1320  }
1321  }
1322 
1323  if (IsSavegameVersionBefore(26)) {
1324  Station *st;
1325  FOR_ALL_STATIONS(st) {
1326  st->last_vehicle_type = VEH_INVALID;
1327  }
1328  }
1329 
1331 
1332  if (IsSavegameVersionBefore(34)) {
1333  Company *c;
1334  FOR_ALL_COMPANIES(c) ResetCompanyLivery(c);
1335  }
1336 
1337  Company *c;
1338  FOR_ALL_COMPANIES(c) {
1341  }
1342 
1343  if (!IsSavegameVersionBefore(27)) AfterLoadStations();
1344 
1345  /* Time starts at 0 instead of 1920.
1346  * Account for this in older games by adding an offset */
1347  if (IsSavegameVersionBefore(31)) {
1348  Station *st;
1349  Waypoint *wp;
1350  Engine *e;
1351  Industry *i;
1352  Vehicle *v;
1353 
1356 
1357  FOR_ALL_STATIONS(st) st->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
1359  FOR_ALL_ENGINES(e) e->intro_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
1360  FOR_ALL_COMPANIES(c) c->inaugurated_year += ORIGINAL_BASE_YEAR;
1361  FOR_ALL_INDUSTRIES(i) i->last_prod_year += ORIGINAL_BASE_YEAR;
1362 
1363  FOR_ALL_VEHICLES(v) {
1366  }
1367  }
1368 
1369  /* From 32 on we save the industry who made the farmland.
1370  * To give this prettiness to old savegames, we remove all farmfields and
1371  * plant new ones. */
1372  if (IsSavegameVersionBefore(32)) {
1373  Industry *i;
1374 
1375  for (TileIndex t = 0; t < map_size; t++) {
1376  if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_FIELDS)) {
1377  /* remove fields */
1378  MakeClear(t, CLEAR_GRASS, 3);
1379  }
1380  }
1381 
1382  FOR_ALL_INDUSTRIES(i) {
1383  uint j;
1384 
1386  for (j = 0; j != 50; j++) PlantRandomFarmField(i);
1387  }
1388  }
1389  }
1390 
1391  /* Setting no refit flags to all orders in savegames from before refit in orders were added */
1392  if (IsSavegameVersionBefore(36)) {
1393  Order *order;
1394  Vehicle *v;
1395 
1396  FOR_ALL_ORDERS(order) {
1397  order->SetRefit(CT_NO_REFIT);
1398  }
1399 
1400  FOR_ALL_VEHICLES(v) {
1402  }
1403  }
1404 
1405  /* from version 38 we have optional elrails, since we cannot know the
1406  * preference of a user, let elrails enabled; it can be disabled manually */
1408  /* do the same as when elrails were enabled/disabled manually just now */
1411 
1412  /* From version 53, the map array was changed for house tiles to allow
1413  * space for newhouses grf features. A new byte, m7, was also added. */
1414  if (IsSavegameVersionBefore(53)) {
1415  for (TileIndex t = 0; t < map_size; t++) {
1416  if (IsTileType(t, MP_HOUSE)) {
1417  if (GB(_m[t].m3, 6, 2) != TOWN_HOUSE_COMPLETED) {
1418  /* Move the construction stage from m3[7..6] to m5[5..4].
1419  * The construction counter does not have to move. */
1420  SB(_m[t].m5, 3, 2, GB(_m[t].m3, 6, 2));
1421  SB(_m[t].m3, 6, 2, 0);
1422 
1423  /* The "house is completed" bit is now in m6[2]. */
1424  SetHouseCompleted(t, false);
1425  } else {
1426  /* The "lift has destination" bit has been moved from
1427  * m5[7] to m7[0]. */
1428  SB(_me[t].m7, 0, 1, HasBit(_m[t].m5, 7));
1429  ClrBit(_m[t].m5, 7);
1430 
1431  /* The "lift is moving" bit has been removed, as it does
1432  * the same job as the "lift has destination" bit. */
1433  ClrBit(_m[t].m1, 7);
1434 
1435  /* The position of the lift goes from m1[7..0] to m6[7..2],
1436  * making m1 totally free, now. The lift position does not
1437  * have to be a full byte since the maximum value is 36. */
1438  SetLiftPosition(t, GB(_m[t].m1, 0, 6 ));
1439 
1440  _m[t].m1 = 0;
1441  _m[t].m3 = 0;
1442  SetHouseCompleted(t, true);
1443  }
1444  }
1445  }
1446  }
1447 
1448  /* Check and update house and town values */
1450 
1451  if (IsSavegameVersionBefore(43)) {
1452  for (TileIndex t = 0; t < map_size; t++) {
1453  if (IsTileType(t, MP_INDUSTRY)) {
1454  switch (GetIndustryGfx(t)) {
1455  case GFX_POWERPLANT_SPARKS:
1456  _m[t].m3 = GB(_m[t].m1, 2, 5);
1457  break;
1458 
1459  case GFX_OILWELL_ANIMATED_1:
1460  case GFX_OILWELL_ANIMATED_2:
1461  case GFX_OILWELL_ANIMATED_3:
1462  _m[t].m3 = GB(_m[t].m1, 0, 2);
1463  break;
1464 
1465  case GFX_COAL_MINE_TOWER_ANIMATED:
1466  case GFX_COPPER_MINE_TOWER_ANIMATED:
1467  case GFX_GOLD_MINE_TOWER_ANIMATED:
1468  _m[t].m3 = _m[t].m1;
1469  break;
1470 
1471  default: // No animation states to change
1472  break;
1473  }
1474  }
1475  }
1476  }
1477 
1478  if (IsSavegameVersionBefore(45)) {
1479  Vehicle *v;
1480  /* Originally just the fact that some cargo had been paid for was
1481  * stored to stop people cheating and cashing in several times. This
1482  * wasn't enough though as it was cleared when the vehicle started
1483  * loading again, even if it didn't actually load anything, so now the
1484  * amount that has been paid is stored. */
1485  FOR_ALL_VEHICLES(v) {
1486  ClrBit(v->vehicle_flags, 2);
1487  }
1488  }
1489 
1490  /* Buoys do now store the owner of the previous water tile, which can never
1491  * be OWNER_NONE. So replace OWNER_NONE with OWNER_WATER. */
1492  if (IsSavegameVersionBefore(46)) {
1493  Waypoint *wp;
1494  FOR_ALL_WAYPOINTS(wp) {
1495  if ((wp->facilities & FACIL_DOCK) != 0 && IsTileOwner(wp->xy, OWNER_NONE) && TileHeight(wp->xy) == 0) SetTileOwner(wp->xy, OWNER_WATER);
1496  }
1497  }
1498 
1499  if (IsSavegameVersionBefore(50)) {
1500  Aircraft *v;
1501  /* Aircraft units changed from 8 mph to 1 km-ish/h */
1502  FOR_ALL_AIRCRAFT(v) {
1503  if (v->subtype <= AIR_AIRCRAFT) {
1504  const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
1505  v->cur_speed *= 128;
1506  v->cur_speed /= 10;
1507  v->acceleration = avi->acceleration;
1508  }
1509  }
1510  }
1511 
1512  if (IsSavegameVersionBefore(49)) FOR_ALL_COMPANIES(c) c->face = ConvertFromOldCompanyManagerFace(c->face);
1513 
1514  if (IsSavegameVersionBefore(52)) {
1515  for (TileIndex t = 0; t < map_size; t++) {
1516  if (IsTileType(t, MP_OBJECT) && _m[t].m5 == OBJECT_STATUE) {
1518  }
1519  }
1520  }
1521 
1522  /* A setting containing the proportion of towns that grow twice as
1523  * fast was added in version 54. From version 56 this is now saved in the
1524  * town as cities can be built specifically in the scenario editor. */
1525  if (IsSavegameVersionBefore(56)) {
1526  Town *t;
1527 
1528  FOR_ALL_TOWNS(t) {
1530  t->larger_town = true;
1531  }
1532  }
1533  }
1534 
1535  if (IsSavegameVersionBefore(57)) {
1536  Vehicle *v;
1537  /* Added a FIFO queue of vehicles loading at stations */
1538  FOR_ALL_VEHICLES(v) {
1539  if ((v->type != VEH_TRAIN || Train::From(v)->IsFrontEngine()) && // for all locs
1540  !(v->vehstatus & (VS_STOPPED | VS_CRASHED)) && // not stopped or crashed
1541  v->current_order.IsType(OT_LOADING)) { // loading
1542  Station::Get(v->last_station_visited)->loading_vehicles.push_back(v);
1543 
1544  /* The loading finished flag is *only* set when actually completely
1545  * finished. Because the vehicle is loading, it is not finished. */
1547  }
1548  }
1549  } else if (IsSavegameVersionBefore(59)) {
1550  /* For some reason non-loading vehicles could be in the station's loading vehicle list */
1551 
1552  Station *st;
1553  FOR_ALL_STATIONS(st) {
1554  std::list<Vehicle *>::iterator iter;
1555  for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end();) {
1556  Vehicle *v = *iter;
1557  iter++;
1558  if (!v->current_order.IsType(OT_LOADING)) st->loading_vehicles.remove(v);
1559  }
1560  }
1561  }
1562 
1563  if (IsSavegameVersionBefore(58)) {
1564  /* Setting difficulty industry_density other than zero get bumped to +1
1565  * since a new option (very low at position 1) has been added */
1568  }
1569 
1570  /* Same goes for number of towns, although no test is needed, just an increment */
1572  }
1573 
1574  if (IsSavegameVersionBefore(64)) {
1575  /* Since now we allow different signal types and variants on a single tile.
1576  * Move signal states to m4 to make room and clone the signal type/variant. */
1577  for (TileIndex t = 0; t < map_size; t++) {
1578  if (IsTileType(t, MP_RAILWAY) && HasSignals(t)) {
1579  /* move signal states */
1580  SetSignalStates(t, GB(_m[t].m2, 4, 4));
1581  SB(_m[t].m2, 4, 4, 0);
1582  /* clone signal type and variant */
1583  SB(_m[t].m2, 4, 3, GB(_m[t].m2, 0, 3));
1584  }
1585  }
1586  }
1587 
1588  if (IsSavegameVersionBefore(69)) {
1589  /* In some old savegames a bit was cleared when it should not be cleared */
1590  RoadVehicle *rv;
1591  FOR_ALL_ROADVEHICLES(rv) {
1592  if (rv->state == 250 || rv->state == 251) {
1593  SetBit(rv->state, 2);
1594  }
1595  }
1596  }
1597 
1598  if (IsSavegameVersionBefore(70)) {
1599  /* Added variables to support newindustries */
1600  Industry *i;
1601  FOR_ALL_INDUSTRIES(i) i->founder = OWNER_NONE;
1602  }
1603 
1604  /* From version 82, old style canals (above sealevel (0), WATER owner) are no longer supported.
1605  Replace the owner for those by OWNER_NONE. */
1606  if (IsSavegameVersionBefore(82)) {
1607  for (TileIndex t = 0; t < map_size; t++) {
1608  if (IsTileType(t, MP_WATER) &&
1610  GetTileOwner(t) == OWNER_WATER &&
1611  TileHeight(t) != 0) {
1613  }
1614  }
1615  }
1616 
1617  /*
1618  * Add the 'previous' owner to the ship depots so we can reset it with
1619  * the correct values when it gets destroyed. This prevents that
1620  * someone can remove canals owned by somebody else and it prevents
1621  * making floods using the removal of ship depots.
1622  */
1623  if (IsSavegameVersionBefore(83)) {
1624  for (TileIndex t = 0; t < map_size; t++) {
1625  if (IsShipDepotTile(t)) {
1626  _m[t].m4 = (TileHeight(t) == 0) ? OWNER_WATER : OWNER_NONE;
1627  }
1628  }
1629  }
1630 
1631  if (IsSavegameVersionBefore(74)) {
1632  Station *st;
1633  FOR_ALL_STATIONS(st) {
1634  for (CargoID c = 0; c < NUM_CARGO; c++) {
1635  st->goods[c].last_speed = 0;
1636  if (st->goods[c].cargo.AvailableCount() != 0) SetBit(st->goods[c].status, GoodsEntry::GES_RATING);
1637  }
1638  }
1639  }
1640 
1641  if (IsSavegameVersionBefore(78)) {
1642  Industry *i;
1643  uint j;
1644  FOR_ALL_INDUSTRIES(i) {
1645  const IndustrySpec *indsp = GetIndustrySpec(i->type);
1646  for (j = 0; j < lengthof(i->produced_cargo); j++) {
1647  i->produced_cargo[j] = indsp->produced_cargo[j];
1648  }
1649  for (j = 0; j < lengthof(i->accepts_cargo); j++) {
1650  i->accepts_cargo[j] = indsp->accepts_cargo[j];
1651  }
1652  }
1653  }
1654 
1655  /* Before version 81, the density of grass was always stored as zero, and
1656  * grassy trees were always drawn fully grassy. Furthermore, trees on rough
1657  * land used to have zero density, now they have full density. Therefore,
1658  * make all grassy/rough land trees have a density of 3. */
1659  if (IsSavegameVersionBefore(81)) {
1660  for (TileIndex t = 0; t < map_size; t++) {
1661  if (GetTileType(t) == MP_TREES) {
1662  TreeGround groundType = (TreeGround)GB(_m[t].m2, 4, 2);
1663  if (groundType != TREE_GROUND_SNOW_DESERT) SB(_m[t].m2, 6, 2, 3);
1664  }
1665  }
1666  }
1667 
1668 
1669  if (IsSavegameVersionBefore(93)) {
1670  /* Rework of orders. */
1671  Order *order;
1672  FOR_ALL_ORDERS(order) order->ConvertFromOldSavegame();
1673 
1674  Vehicle *v;
1675  FOR_ALL_VEHICLES(v) {
1676  if (v->orders.list != NULL && v->orders.list->GetFirstOrder() != NULL && v->orders.list->GetFirstOrder()->IsType(OT_NOTHING)) {
1677  v->orders.list->FreeChain();
1678  v->orders.list = NULL;
1679  }
1680 
1682  if (v->type == VEH_ROAD && v->IsPrimaryVehicle() && v->FirstShared() == v) {
1683  FOR_VEHICLE_ORDERS(v, order) order->SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
1684  }
1685  }
1686  } else if (IsSavegameVersionBefore(94)) {
1687  /* Unload and transfer are now mutual exclusive. */
1688  Order *order;
1689  FOR_ALL_ORDERS(order) {
1690  if ((order->GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) == (OUFB_UNLOAD | OUFB_TRANSFER)) {
1691  order->SetUnloadType(OUFB_TRANSFER);
1692  order->SetLoadType(OLFB_NO_LOAD);
1693  }
1694  }
1695 
1696  Vehicle *v;
1697  FOR_ALL_VEHICLES(v) {
1701  }
1702  }
1703  }
1704 
1705  if (IsSavegameVersionBefore(84)) {
1706  /* Set all share owners to INVALID_COMPANY for
1707  * 1) all inactive companies
1708  * (when inactive companies were stored in the savegame - TTD, TTDP and some
1709  * *really* old revisions of OTTD; else it is already set in InitializeCompanies())
1710  * 2) shares that are owned by inactive companies or self
1711  * (caused by cheating clients in earlier revisions) */
1712  FOR_ALL_COMPANIES(c) {
1713  for (uint i = 0; i < 4; i++) {
1714  CompanyID company = c->share_owners[i];
1715  if (company == INVALID_COMPANY) continue;
1716  if (!Company::IsValidID(company) || company == c->index) c->share_owners[i] = INVALID_COMPANY;
1717  }
1718  }
1719  }
1720 
1721  /* The water class was moved/unified. */
1722  if (IsSavegameVersionBefore(146)) {
1723  for (TileIndex t = 0; t < map_size; t++) {
1724  switch (GetTileType(t)) {
1725  case MP_STATION:
1726  switch (GetStationType(t)) {
1727  case STATION_OILRIG:
1728  case STATION_DOCK:
1729  case STATION_BUOY:
1730  SetWaterClass(t, (WaterClass)GB(_m[t].m3, 0, 2));
1731  SB(_m[t].m3, 0, 2, 0);
1732  break;
1733 
1734  default:
1736  break;
1737  }
1738  break;
1739 
1740  case MP_WATER:
1741  SetWaterClass(t, (WaterClass)GB(_m[t].m3, 0, 2));
1742  SB(_m[t].m3, 0, 2, 0);
1743  break;
1744 
1745  case MP_OBJECT:
1747  break;
1748 
1749  default:
1750  /* No water class. */
1751  break;
1752  }
1753  }
1754  }
1755 
1756  if (IsSavegameVersionBefore(86)) {
1757  for (TileIndex t = 0; t < map_size; t++) {
1758  /* Move river flag and update canals to use water class */
1759  if (IsTileType(t, MP_WATER)) {
1760  if (GetWaterClass(t) != WATER_CLASS_RIVER) {
1761  if (IsWater(t)) {
1762  Owner o = GetTileOwner(t);
1763  if (o == OWNER_WATER) {
1764  MakeSea(t);
1765  } else {
1766  MakeCanal(t, o, Random());
1767  }
1768  } else if (IsShipDepot(t)) {
1769  Owner o = (Owner)_m[t].m4; // Original water owner
1771  }
1772  }
1773  }
1774  }
1775 
1776  /* Update locks, depots, docks and buoys to have a water class based
1777  * on its neighbouring tiles. Done after river and canal updates to
1778  * ensure neighbours are correct. */
1779  for (TileIndex t = 0; t < map_size; t++) {
1780  if (!IsTileFlat(t)) continue;
1781 
1783  if (IsTileType(t, MP_STATION) && (IsDock(t) || IsBuoy(t))) SetWaterClassDependingOnSurroundings(t, false);
1784  }
1785  }
1786 
1787  if (IsSavegameVersionBefore(87)) {
1788  for (TileIndex t = 0; t < map_size; t++) {
1789  /* skip oil rigs at borders! */
1790  if ((IsTileType(t, MP_WATER) || IsBuoyTile(t)) &&
1791  (TileX(t) == 0 || TileY(t) == 0 || TileX(t) == MapMaxX() - 1 || TileY(t) == MapMaxY() - 1)) {
1792  /* Some version 86 savegames have wrong water class at map borders (under buoy, or after removing buoy).
1793  * This conversion has to be done before buoys with invalid owner are removed. */
1795  }
1796 
1797  if (IsBuoyTile(t) || IsDriveThroughStopTile(t) || IsTileType(t, MP_WATER)) {
1798  Owner o = GetTileOwner(t);
1799  if (o < MAX_COMPANIES && !Company::IsValidID(o)) {
1800  Backup<CompanyByte> cur_company(_current_company, o, FILE_LINE);
1802  cur_company.Restore();
1803  }
1804  if (IsBuoyTile(t)) {
1805  /* reset buoy owner to OWNER_NONE in the station struct
1806  * (even if it is owned by active company) */
1808  }
1809  } else if (IsTileType(t, MP_ROAD)) {
1810  /* works for all RoadTileType */
1811  for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
1812  /* update even non-existing road types to update tile owner too */
1813  Owner o = GetRoadOwner(t, rt);
1814  if (o < MAX_COMPANIES && !Company::IsValidID(o)) SetRoadOwner(t, rt, OWNER_NONE);
1815  }
1816  if (IsLevelCrossing(t)) {
1818  }
1819  } else if (IsPlainRailTile(t)) {
1821  }
1822  }
1823 
1824  /* Convert old PF settings to new */
1827  } else {
1829  }
1830 
1833  } else {
1835  }
1836 
1839  } else {
1841  }
1842  }
1843 
1844  if (IsSavegameVersionBefore(88)) {
1845  /* Profits are now with 8 bit fract */
1846  Vehicle *v;
1847  FOR_ALL_VEHICLES(v) {
1848  v->profit_this_year <<= 8;
1849  v->profit_last_year <<= 8;
1850  v->running_ticks = 0;
1851  }
1852  }
1853 
1854  if (IsSavegameVersionBefore(91)) {
1855  /* Increase HouseAnimationFrame from 5 to 7 bits */
1856  for (TileIndex t = 0; t < map_size; t++) {
1857  if (IsTileType(t, MP_HOUSE) && GetHouseType(t) >= NEW_HOUSE_OFFSET) {
1858  SB(_me[t].m6, 2, 6, GB(_me[t].m6, 3, 5));
1859  SB(_m[t].m3, 5, 1, 0);
1860  }
1861  }
1862  }
1863 
1864  if (IsSavegameVersionBefore(62)) {
1865  /* Remove all trams from savegames without tram support.
1866  * There would be trams without tram track under causing crashes sooner or later. */
1867  RoadVehicle *v;
1868  FOR_ALL_ROADVEHICLES(v) {
1869  if (v->First() == v && HasBit(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM)) {
1870  ShowErrorMessage(STR_WARNING_LOADGAME_REMOVED_TRAMS, INVALID_STRING_ID, WL_CRITICAL);
1871  delete v;
1872  }
1873  }
1874  }
1875 
1876  if (IsSavegameVersionBefore(99)) {
1877  for (TileIndex t = 0; t < map_size; t++) {
1878  /* Set newly introduced WaterClass of industry tiles */
1879  if (IsTileType(t, MP_STATION) && IsOilRig(t)) {
1881  }
1882  if (IsTileType(t, MP_INDUSTRY)) {
1883  if ((GetIndustrySpec(GetIndustryType(t))->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0) {
1885  } else {
1887  }
1888  }
1889 
1890  /* Replace "house construction year" with "house age" */
1891  if (IsTileType(t, MP_HOUSE) && IsHouseCompleted(t)) {
1892  _m[t].m5 = Clamp(_cur_year - (_m[t].m5 + ORIGINAL_BASE_YEAR), 0, 0xFF);
1893  }
1894  }
1895  }
1896 
1897  /* Move the signal variant back up one bit for PBS. We don't convert the old PBS
1898  * format here, as an old layout wouldn't work properly anyway. To be safe, we
1899  * clear any possible PBS reservations as well. */
1900  if (IsSavegameVersionBefore(100)) {
1901  for (TileIndex t = 0; t < map_size; t++) {
1902  switch (GetTileType(t)) {
1903  case MP_RAILWAY:
1904  if (HasSignals(t)) {
1905  /* move the signal variant */
1906  SetSignalVariant(t, TRACK_UPPER, HasBit(_m[t].m2, 2) ? SIG_SEMAPHORE : SIG_ELECTRIC);
1907  SetSignalVariant(t, TRACK_LOWER, HasBit(_m[t].m2, 6) ? SIG_SEMAPHORE : SIG_ELECTRIC);
1908  ClrBit(_m[t].m2, 2);
1909  ClrBit(_m[t].m2, 6);
1910  }
1911 
1912  /* Clear PBS reservation on track */
1913  if (IsRailDepot(t)) {
1914  SetDepotReservation(t, false);
1915  } else {
1917  }
1918  break;
1919 
1920  case MP_ROAD: // Clear PBS reservation on crossing
1921  if (IsLevelCrossing(t)) SetCrossingReservation(t, false);
1922  break;
1923 
1924  case MP_STATION: // Clear PBS reservation on station
1925  if (HasStationRail(t)) SetRailStationReservation(t, false);
1926  break;
1927 
1928  case MP_TUNNELBRIDGE: // Clear PBS reservation on tunnels/bridges
1930  break;
1931 
1932  default: break;
1933  }
1934  }
1935  }
1936 
1937  /* Reserve all tracks trains are currently on. */
1938  if (IsSavegameVersionBefore(101)) {
1939  const Train *t;
1940  FOR_ALL_TRAINS(t) {
1941  if (t->First() == t) t->ReserveTrackUnderConsist();
1942  }
1943  }
1944 
1945  if (IsSavegameVersionBefore(102)) {
1946  for (TileIndex t = 0; t < map_size; t++) {
1947  /* Now all crossings should be in correct state */
1948  if (IsLevelCrossingTile(t)) UpdateLevelCrossing(t, false);
1949  }
1950  }
1951 
1952  if (IsSavegameVersionBefore(103)) {
1953  /* Non-town-owned roads now store the closest town */
1955 
1956  /* signs with invalid owner left from older savegames */
1957  Sign *si;
1958  FOR_ALL_SIGNS(si) {
1959  if (si->owner != OWNER_NONE && !Company::IsValidID(si->owner)) si->owner = OWNER_NONE;
1960  }
1961 
1962  /* Station can get named based on an industry type, but the current ones
1963  * are not, so mark them as if they are not named by an industry. */
1964  Station *st;
1965  FOR_ALL_STATIONS(st) {
1966  st->indtype = IT_INVALID;
1967  }
1968  }
1969 
1970  if (IsSavegameVersionBefore(104)) {
1971  Aircraft *a;
1972  FOR_ALL_AIRCRAFT(a) {
1973  /* Set engine_type of shadow and rotor */
1974  if (!a->IsNormalAircraft()) {
1975  a->engine_type = a->First()->engine_type;
1976  }
1977  }
1978 
1979  /* More companies ... */
1980  Company *c;
1981  FOR_ALL_COMPANIES(c) {
1982  if (c->bankrupt_asked == 0xFF) c->bankrupt_asked = 0xFFFF;
1983  }
1984 
1985  Engine *e;
1986  FOR_ALL_ENGINES(e) {
1987  if (e->company_avail == 0xFF) e->company_avail = 0xFFFF;
1988  }
1989 
1990  Town *t;
1991  FOR_ALL_TOWNS(t) {
1992  if (t->have_ratings == 0xFF) t->have_ratings = 0xFFFF;
1993  for (uint i = 8; i != MAX_COMPANIES; i++) t->ratings[i] = RATING_INITIAL;
1994  }
1995  }
1996 
1997  if (IsSavegameVersionBefore(112)) {
1998  for (TileIndex t = 0; t < map_size; t++) {
1999  /* Check for HQ bit being set, instead of using map accessor,
2000  * since we've already changed it code-wise */
2001  if (IsTileType(t, MP_OBJECT) && HasBit(_m[t].m5, 7)) {
2002  /* Move size and part identification of HQ out of the m5 attribute,
2003  * on new locations */
2004  _m[t].m3 = GB(_m[t].m5, 0, 5);
2005  _m[t].m5 = OBJECT_HQ;
2006  }
2007  }
2008  }
2009  if (IsSavegameVersionBefore(144)) {
2010  for (TileIndex t = 0; t < map_size; t++) {
2011  if (!IsTileType(t, MP_OBJECT)) continue;
2012 
2013  /* Reordering/generalisation of the object bits. */
2014  ObjectType type = _m[t].m5;
2015  SB(_me[t].m6, 2, 4, type == OBJECT_HQ ? GB(_m[t].m3, 2, 3) : 0);
2016  _m[t].m3 = type == OBJECT_HQ ? GB(_m[t].m3, 1, 1) | GB(_m[t].m3, 0, 1) << 4 : 0;
2017 
2018  /* Make sure those bits are clear as well! */
2019  _m[t].m4 = 0;
2020  _me[t].m7 = 0;
2021  }
2022  }
2023 
2024  if (IsSavegameVersionBefore(147) && Object::GetNumItems() == 0) {
2025  /* Make real objects for object tiles. */
2026  for (TileIndex t = 0; t < map_size; t++) {
2027  if (!IsTileType(t, MP_OBJECT)) continue;
2028 
2029  if (Town::GetNumItems() == 0) {
2030  /* No towns, so remove all objects! */
2031  DoClearSquare(t);
2032  } else {
2033  uint offset = _m[t].m3;
2034 
2035  /* Also move the animation state. */
2036  _m[t].m3 = GB(_me[t].m6, 2, 4);
2037  SB(_me[t].m6, 2, 4, 0);
2038 
2039  if (offset == 0) {
2040  /* No offset, so make the object. */
2041  ObjectType type = _m[t].m5;
2042  int size = type == OBJECT_HQ ? 2 : 1;
2043 
2044  if (!Object::CanAllocateItem()) {
2045  /* Nice... you managed to place 64k lighthouses and
2046  * antennae on the map... boohoo. */
2047  SlError(STR_ERROR_TOO_MANY_OBJECTS);
2048  }
2049 
2050  Object *o = new Object();
2051  o->location.tile = t;
2052  o->location.w = size;
2053  o->location.h = size;
2054  o->build_date = _date;
2055  o->town = type == OBJECT_STATUE ? Town::Get(_m[t].m2) : CalcClosestTownFromTile(t, UINT_MAX);
2056  _m[t].m2 = o->index;
2057  Object::IncTypeCount(type);
2058  } else {
2059  /* We're at an offset, so get the ID from our "root". */
2060  TileIndex northern_tile = t - TileXY(GB(offset, 0, 4), GB(offset, 4, 4));
2061  assert(IsTileType(northern_tile, MP_OBJECT));
2062  _m[t].m2 = _m[northern_tile].m2;
2063  }
2064  }
2065  }
2066  }
2067 
2068  if (IsSavegameVersionBefore(113)) {
2069  /* allow_town_roads is added, set it if town_layout wasn't TL_NO_ROADS */
2070  if (_settings_game.economy.town_layout == 0) { // was TL_NO_ROADS
2073  } else {
2076  }
2077 
2078  /* Initialize layout of all towns. Older versions were using different
2079  * generator for random town layout, use it if needed. */
2080  Town *t;
2081  FOR_ALL_TOWNS(t) {
2084  continue;
2085  }
2086 
2087  /* Use old layout randomizer code */
2088  byte layout = TileHash(TileX(t->xy), TileY(t->xy)) % 6;
2089  switch (layout) {
2090  default: break;
2091  case 5: layout = 1; break;
2092  case 0: layout = 2; break;
2093  }
2094  t->layout = layout - 1;
2095  }
2096  }
2097 
2098  if (IsSavegameVersionBefore(114)) {
2099  /* There could be (deleted) stations with invalid owner, set owner to OWNER NONE.
2100  * The conversion affects oil rigs and buoys too, but it doesn't matter as
2101  * they have st->owner == OWNER_NONE already. */
2102  Station *st;
2103  FOR_ALL_STATIONS(st) {
2104  if (!Company::IsValidID(st->owner)) st->owner = OWNER_NONE;
2105  }
2106  }
2107 
2108  /* Trains could now stop in a specific location. */
2109  if (IsSavegameVersionBefore(117)) {
2110  Order *o;
2111  FOR_ALL_ORDERS(o) {
2112  if (o->IsType(OT_GOTO_STATION)) o->SetStopLocation(OSL_PLATFORM_FAR_END);
2113  }
2114  }
2115 
2116  if (IsSavegameVersionBefore(120)) {
2118  Company *c;
2119  FOR_ALL_COMPANIES(c) {
2120  c->settings.vehicle = _old_vds;
2121  }
2122  }
2123 
2124  if (IsSavegameVersionBefore(121)) {
2125  /* Delete small ufos heading for non-existing vehicles */
2126  Vehicle *v;
2128  if (v->subtype == 2 /* ST_SMALL_UFO */ && v->current_order.GetDestination() != 0) {
2129  const Vehicle *u = Vehicle::GetIfValid(v->dest_tile);
2130  if (u == NULL || u->type != VEH_ROAD || !RoadVehicle::From(u)->IsFrontEngine()) {
2131  delete v;
2132  }
2133  }
2134  }
2135 
2136  /* We didn't store cargo payment yet, so make them for vehicles that are
2137  * currently at a station and loading/unloading. If they don't get any
2138  * payment anymore they just removed in the next load/unload cycle.
2139  * However, some 0.7 versions might have cargo payment. For those we just
2140  * add cargopayment for the vehicles that don't have it.
2141  */
2142  Station *st;
2143  FOR_ALL_STATIONS(st) {
2144  std::list<Vehicle *>::iterator iter;
2145  for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) {
2146  /* There are always as many CargoPayments as Vehicles. We need to make the
2147  * assert() in Pool::GetNew() happy by calling CanAllocateItem(). */
2150  Vehicle *v = *iter;
2151  if (v->cargo_payment == NULL) v->cargo_payment = new CargoPayment(v);
2152  }
2153  }
2154  }
2155 
2156  if (IsSavegameVersionBefore(122)) {
2157  /* Animated tiles would sometimes not be actually animated or
2158  * in case of old savegames duplicate. */
2159 
2161  extern uint _animated_tile_count;
2162 
2163  for (uint i = 0; i < _animated_tile_count; /* Nothing */) {
2164  /* Remove if tile is not animated */
2165  bool remove = _tile_type_procs[GetTileType(_animated_tile_list[i])]->animate_tile_proc == NULL;
2166 
2167  /* and remove if duplicate */
2168  for (uint j = 0; !remove && j < i; j++) {
2169  remove = _animated_tile_list[i] == _animated_tile_list[j];
2170  }
2171 
2172  if (remove) {
2173  DeleteAnimatedTile(_animated_tile_list[i]);
2174  } else {
2175  i++;
2176  }
2177  }
2178  }
2179 
2181  /* The train station tile area was added, but for really old (TTDPatch) it's already valid. */
2182  Waypoint *wp;
2183  FOR_ALL_WAYPOINTS(wp) {
2184  if (wp->facilities & FACIL_TRAIN) {
2185  wp->train_station.tile = wp->xy;
2186  wp->train_station.w = 1;
2187  wp->train_station.h = 1;
2188  } else {
2190  wp->train_station.w = 0;
2191  wp->train_station.h = 0;
2192  }
2193  }
2194  }
2195 
2196  if (IsSavegameVersionBefore(125)) {
2197  /* Convert old subsidies */
2198  Subsidy *s;
2199  FOR_ALL_SUBSIDIES(s) {
2200  if (s->remaining < 12) {
2201  /* Converting nonawarded subsidy */
2202  s->remaining = 12 - s->remaining; // convert "age" to "remaining"
2203  s->awarded = INVALID_COMPANY; // not awarded to anyone
2204  const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
2205  switch (cs->town_effect) {
2206  case TE_PASSENGERS:
2207  case TE_MAIL:
2208  /* Town -> Town */
2209  s->src_type = s->dst_type = ST_TOWN;
2210  if (Town::IsValidID(s->src) && Town::IsValidID(s->dst)) continue;
2211  break;
2212  case TE_GOODS:
2213  case TE_FOOD:
2214  /* Industry -> Town */
2215  s->src_type = ST_INDUSTRY;
2216  s->dst_type = ST_TOWN;
2217  if (Industry::IsValidID(s->src) && Town::IsValidID(s->dst)) continue;
2218  break;
2219  default:
2220  /* Industry -> Industry */
2221  s->src_type = s->dst_type = ST_INDUSTRY;
2222  if (Industry::IsValidID(s->src) && Industry::IsValidID(s->dst)) continue;
2223  break;
2224  }
2225  } else {
2226  /* Do our best for awarded subsidies. The original source or destination industry
2227  * can't be determined anymore for awarded subsidies, so invalidate them.
2228  * Town -> Town subsidies are converted using simple heuristic */
2229  s->remaining = 24 - s->remaining; // convert "age of awarded subsidy" to "remaining"
2230  const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
2231  switch (cs->town_effect) {
2232  case TE_PASSENGERS:
2233  case TE_MAIL: {
2234  /* Town -> Town */
2235  const Station *ss = Station::GetIfValid(s->src);
2236  const Station *sd = Station::GetIfValid(s->dst);
2237  if (ss != NULL && sd != NULL && ss->owner == sd->owner &&
2238  Company::IsValidID(ss->owner)) {
2239  s->src_type = s->dst_type = ST_TOWN;
2240  s->src = ss->town->index;
2241  s->dst = sd->town->index;
2242  s->awarded = ss->owner;
2243  continue;
2244  }
2245  break;
2246  }
2247  default:
2248  break;
2249  }
2250  }
2251  /* Awarded non-town subsidy or invalid source/destination, invalidate */
2252  delete s;
2253  }
2254  }
2255 
2256  if (IsSavegameVersionBefore(126)) {
2257  /* Recompute inflation based on old unround loan limit
2258  * Note: Max loan is 500000. With an inflation of 4% across 170 years
2259  * that results in a max loan of about 0.7 * 2^31.
2260  * So taking the 16 bit fractional part into account there are plenty of bits left
2261  * for unmodified savegames ...
2262  */
2263  uint64 aimed_inflation = (_economy.old_max_loan_unround << 16 | _economy.old_max_loan_unround_fract) / _settings_game.difficulty.max_loan;
2264 
2265  /* ... well, just clamp it then. */
2266  if (aimed_inflation > MAX_INFLATION) aimed_inflation = MAX_INFLATION;
2267 
2268  /* Simulate the inflation, so we also get the payment inflation */
2269  while (_economy.inflation_prices < aimed_inflation) {
2270  if (AddInflation(false)) break;
2271  }
2272  }
2273 
2274  if (IsSavegameVersionBefore(128)) {
2275  const Depot *d;
2276  FOR_ALL_DEPOTS(d) {
2277  _m[d->xy].m2 = d->index;
2278  if (IsTileType(d->xy, MP_WATER)) _m[GetOtherShipDepotTile(d->xy)].m2 = d->index;
2279  }
2280  }
2281 
2282  /* The behaviour of force_proceed has been changed. Now
2283  * it counts signals instead of some random time out. */
2284  if (IsSavegameVersionBefore(131)) {
2285  Train *t;
2286  FOR_ALL_TRAINS(t) {
2287  if (t->force_proceed != TFP_NONE) {
2288  t->force_proceed = TFP_STUCK;
2289  }
2290  }
2291  }
2292 
2293  /* The bits for the tree ground and tree density have
2294  * been swapped (m2 bits 7..6 and 5..4. */
2295  if (IsSavegameVersionBefore(135)) {
2296  for (TileIndex t = 0; t < map_size; t++) {
2297  if (IsTileType(t, MP_CLEAR)) {
2298  if (GetRawClearGround(t) == CLEAR_SNOW) {
2300  SetBit(_m[t].m3, 4);
2301  } else {
2302  ClrBit(_m[t].m3, 4);
2303  }
2304  }
2305  if (IsTileType(t, MP_TREES)) {
2306  uint density = GB(_m[t].m2, 6, 2);
2307  uint ground = GB(_m[t].m2, 4, 2);
2308  uint counter = GB(_m[t].m2, 0, 4);
2309  _m[t].m2 = ground << 6 | density << 4 | counter;
2310  }
2311  }
2312  }
2313 
2314  /* Wait counter and load/unload ticks got split. */
2315  if (IsSavegameVersionBefore(136)) {
2316  Aircraft *a;
2317  FOR_ALL_AIRCRAFT(a) {
2318  a->turn_counter = a->current_order.IsType(OT_LOADING) ? 0 : a->load_unload_ticks;
2319  }
2320 
2321  Train *t;
2322  FOR_ALL_TRAINS(t) {
2323  t->wait_counter = t->current_order.IsType(OT_LOADING) ? 0 : t->load_unload_ticks;
2324  }
2325  }
2326 
2327  /* Airport tile animation uses animation frame instead of other graphics id */
2328  if (IsSavegameVersionBefore(137)) {
2329  struct AirportTileConversion {
2330  byte old_start;
2331  byte num_frames;
2332  };
2333  static const AirportTileConversion atc[] = {
2334  {31, 12}, // APT_RADAR_GRASS_FENCE_SW
2335  {50, 4}, // APT_GRASS_FENCE_NE_FLAG
2336  {62, 2}, // 1 unused tile
2337  {66, 12}, // APT_RADAR_FENCE_SW
2338  {78, 12}, // APT_RADAR_FENCE_NE
2339  {101, 10}, // 9 unused tiles
2340  {111, 8}, // 7 unused tiles
2341  {119, 15}, // 14 unused tiles (radar)
2342  {140, 4}, // APT_GRASS_FENCE_NE_FLAG_2
2343  };
2344  for (TileIndex t = 0; t < map_size; t++) {
2345  if (IsAirportTile(t)) {
2346  StationGfx old_gfx = GetStationGfx(t);
2347  byte offset = 0;
2348  for (uint i = 0; i < lengthof(atc); i++) {
2349  if (old_gfx < atc[i].old_start) {
2350  SetStationGfx(t, old_gfx - offset);
2351  break;
2352  }
2353  if (old_gfx < atc[i].old_start + atc[i].num_frames) {
2354  SetAnimationFrame(t, old_gfx - atc[i].old_start);
2355  SetStationGfx(t, atc[i].old_start - offset);
2356  break;
2357  }
2358  offset += atc[i].num_frames - 1;
2359  }
2360  }
2361  }
2362  }
2363 
2364  if (IsSavegameVersionBefore(140)) {
2365  Station *st;
2366  FOR_ALL_STATIONS(st) {
2367  if (st->airport.tile != INVALID_TILE) {
2368  st->airport.w = st->airport.GetSpec()->size_x;
2369  st->airport.h = st->airport.GetSpec()->size_y;
2370  }
2371  }
2372  }
2373 
2374  if (IsSavegameVersionBefore(141)) {
2375  for (TileIndex t = 0; t < map_size; t++) {
2376  /* Reset tropic zone for VOID tiles, they shall not have any. */
2378  }
2379 
2380  /* We need to properly number/name the depots.
2381  * The first step is making sure none of the depots uses the
2382  * 'default' names, after that we can assign the names. */
2383  Depot *d;
2384  FOR_ALL_DEPOTS(d) d->town_cn = UINT16_MAX;
2385 
2386  FOR_ALL_DEPOTS(d) MakeDefaultName(d);
2387  }
2388 
2389  if (IsSavegameVersionBefore(142)) {
2390  Depot *d;
2391  FOR_ALL_DEPOTS(d) d->build_date = _date;
2392  }
2393 
2394  /* In old versions it was possible to remove an airport while a plane was
2395  * taking off or landing. This gives all kind of problems when building
2396  * another airport in the same station so we don't allow that anymore.
2397  * For old savegames with such aircraft we just throw them in the air and
2398  * treat the aircraft like they were flying already. */
2399  if (IsSavegameVersionBefore(146)) {
2400  Aircraft *v;
2401  FOR_ALL_AIRCRAFT(v) {
2402  if (!v->IsNormalAircraft()) continue;
2404  if (st == NULL && v->state != FLYING) {
2405  v->state = FLYING;
2408  /* get aircraft back on running altitude */
2409  if ((v->vehstatus & VS_CRASHED) == 0) {
2410  GetAircraftFlightLevelBounds(v, &v->z_pos, NULL);
2411  SetAircraftPosition(v, v->x_pos, v->y_pos, GetAircraftFlightLevel(v));
2412  }
2413  }
2414  }
2415  }
2416 
2417  /* Move the animation frame to the same location (m7) for all objects. */
2418  if (IsSavegameVersionBefore(147)) {
2419  for (TileIndex t = 0; t < map_size; t++) {
2420  switch (GetTileType(t)) {
2421  case MP_HOUSE:
2422  if (GetHouseType(t) >= NEW_HOUSE_OFFSET) {
2423  uint per_proc = _me[t].m7;
2424  _me[t].m7 = GB(_me[t].m6, 2, 6) | (GB(_m[t].m3, 5, 1) << 6);
2425  SB(_m[t].m3, 5, 1, 0);
2426  SB(_me[t].m6, 2, 6, min(per_proc, 63));
2427  }
2428  break;
2429 
2430  case MP_INDUSTRY: {
2431  uint rand = _me[t].m7;
2432  _me[t].m7 = _m[t].m3;
2433  _m[t].m3 = rand;
2434  break;
2435  }
2436 
2437  case MP_OBJECT:
2438  _me[t].m7 = _m[t].m3;
2439  _m[t].m3 = 0;
2440  break;
2441 
2442  default:
2443  /* For stations/airports it's already at m7 */
2444  break;
2445  }
2446  }
2447  }
2448 
2449  /* Add (random) colour to all objects. */
2450  if (IsSavegameVersionBefore(148)) {
2451  Object *o;
2452  FOR_ALL_OBJECTS(o) {
2453  Owner owner = GetTileOwner(o->location.tile);
2454  o->colour = (owner == OWNER_NONE) ? Random() & 0xF : Company::Get(owner)->livery->colour1;
2455  }
2456  }
2457 
2458  if (IsSavegameVersionBefore(149)) {
2459  for (TileIndex t = 0; t < map_size; t++) {
2460  if (!IsTileType(t, MP_STATION)) continue;
2461  if (!IsBuoy(t) && !IsOilRig(t) && !(IsDock(t) && IsTileFlat(t))) {
2463  }
2464  }
2465 
2466  /* Waypoints with custom name may have a non-unique town_cn,
2467  * renumber those. First set all affected waypoints to the
2468  * highest possible number to get them numbered in the
2469  * order they have in the pool. */
2470  Waypoint *wp;
2471  FOR_ALL_WAYPOINTS(wp) {
2472  if (wp->name != NULL) wp->town_cn = UINT16_MAX;
2473  }
2474 
2475  FOR_ALL_WAYPOINTS(wp) {
2476  if (wp->name != NULL) MakeDefaultName(wp);
2477  }
2478  }
2479 
2480  if (IsSavegameVersionBefore(152)) {
2481  _industry_builder.Reset(); // Initialize industry build data.
2482 
2483  /* The moment vehicles go from hidden to visible changed. This means
2484  * that vehicles don't always get visible anymore causing things to
2485  * get messed up just after loading the savegame. This fixes that. */
2486  Vehicle *v;
2487  FOR_ALL_VEHICLES(v) {
2488  /* Not all vehicle types can be inside a tunnel. Furthermore,
2489  * testing IsTunnelTile() for invalid tiles causes a crash. */
2490  if (!v->IsGroundVehicle()) continue;
2491 
2492  /* Is the vehicle in a tunnel? */
2493  if (!IsTunnelTile(v->tile)) continue;
2494 
2495  /* Is the vehicle actually at a tunnel entrance/exit? */
2496  TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos);
2497  if (!IsTunnelTile(vtile)) continue;
2498 
2499  /* Are we actually in this tunnel? Or maybe a lower tunnel? */
2500  if (GetSlopePixelZ(v->x_pos, v->y_pos) != v->z_pos) continue;
2501 
2502  /* What way are we going? */
2503  const DiagDirection dir = GetTunnelBridgeDirection(vtile);
2504  const DiagDirection vdir = DirToDiagDir(v->direction);
2505 
2506  /* Have we passed the visibility "switch" state already? */
2507  byte pos = (DiagDirToAxis(vdir) == AXIS_X ? v->x_pos : v->y_pos) & TILE_UNIT_MASK;
2508  byte frame = (vdir == DIAGDIR_NE || vdir == DIAGDIR_NW) ? TILE_SIZE - 1 - pos : pos;
2509  extern const byte _tunnel_visibility_frame[DIAGDIR_END];
2510 
2511  /* Should the vehicle be hidden or not? */
2512  bool hidden;
2513  if (dir == vdir) { // Entering tunnel
2514  hidden = frame >= _tunnel_visibility_frame[dir];
2515  v->tile = vtile;
2516  } else if (dir == ReverseDiagDir(vdir)) { // Leaving tunnel
2517  hidden = frame < TILE_SIZE - _tunnel_visibility_frame[dir];
2518  /* v->tile changes at the moment when the vehicle leaves the tunnel. */
2519  v->tile = hidden ? GetOtherTunnelBridgeEnd(vtile) : vtile;
2520  } else {
2521  /* We could get here in two cases:
2522  * - for road vehicles, it is reversing at the end of the tunnel
2523  * - it is crashed in the tunnel entry (both train or RV destroyed by UFO)
2524  * Whatever case it is, do not change anything and use the old values.
2525  * Especially changing RV's state would break its reversing in the middle. */
2526  continue;
2527  }
2528 
2529  if (hidden) {
2530  v->vehstatus |= VS_HIDDEN;
2531 
2532  switch (v->type) {
2533  case VEH_TRAIN: Train::From(v)->track = TRACK_BIT_WORMHOLE; break;
2534  case VEH_ROAD: RoadVehicle::From(v)->state = RVSB_WORMHOLE; break;
2535  default: NOT_REACHED();
2536  }
2537  } else {
2538  v->vehstatus &= ~VS_HIDDEN;
2539 
2540  switch (v->type) {
2541  case VEH_TRAIN: Train::From(v)->track = DiagDirToDiagTrackBits(vdir); break;
2542  case VEH_ROAD: RoadVehicle::From(v)->state = DiagDirToDiagTrackdir(vdir); RoadVehicle::From(v)->frame = frame; break;
2543  default: NOT_REACHED();
2544  }
2545  }
2546  }
2547  }
2548 
2549  if (IsSavegameVersionBefore(153)) {
2550  RoadVehicle *rv;
2551  FOR_ALL_ROADVEHICLES(rv) {
2552  if (rv->state == RVSB_IN_DEPOT || rv->state == RVSB_WORMHOLE) continue;
2553 
2554  bool loading = rv->current_order.IsType(OT_LOADING) || rv->current_order.IsType(OT_LEAVESTATION);
2555  if (HasBit(rv->state, RVS_IN_ROAD_STOP)) {
2556  extern const byte _road_stop_stop_frame[];
2557  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)]);
2558  } else if (HasBit(rv->state, RVS_IN_DT_ROAD_STOP)) {
2559  SB(rv->state, RVS_ENTERED_STOP, 1, loading || rv->frame > RVC_DRIVE_THROUGH_STOP_FRAME);
2560  }
2561  }
2562  }
2563 
2564  if (IsSavegameVersionBefore(156)) {
2565  /* The train's pathfinder lost flag got moved. */
2566  Train *t;
2567  FOR_ALL_TRAINS(t) {
2568  if (!HasBit(t->flags, 5)) continue;
2569 
2570  ClrBit(t->flags, 5);
2572  }
2573 
2574  /* Introduced terraform/clear limits. */
2575  Company *c;
2576  FOR_ALL_COMPANIES(c) {
2579  }
2580  }
2581 
2582  if (IsSavegameVersionBefore(158)) {
2583  Vehicle *v;
2584  FOR_ALL_VEHICLES(v) {
2585  switch (v->type) {
2586  case VEH_TRAIN: {
2587  Train *t = Train::From(v);
2588 
2589  /* Clear old GOINGUP / GOINGDOWN flags.
2590  * It was changed in savegame version 139, but savegame
2591  * version 158 doesn't use these bits, so it doesn't hurt
2592  * to clear them unconditionally. */
2593  ClrBit(t->flags, 1);
2594  ClrBit(t->flags, 2);
2595 
2596  /* Clear both bits first. */
2599 
2600  /* Crashed vehicles can't be going up/down. */
2601  if (t->vehstatus & VS_CRASHED) break;
2602 
2603  /* Only X/Y tracks can be sloped. */
2604  if (t->track != TRACK_BIT_X && t->track != TRACK_BIT_Y) break;
2605 
2607  break;
2608  }
2609  case VEH_ROAD: {
2610  RoadVehicle *rv = RoadVehicle::From(v);
2613 
2614  /* Crashed vehicles can't be going up/down. */
2615  if (rv->vehstatus & VS_CRASHED) break;
2616 
2617  if (rv->state == RVSB_IN_DEPOT || rv->state == RVSB_WORMHOLE) break;
2618 
2619  TrackStatus ts = GetTileTrackStatus(rv->tile, TRANSPORT_ROAD, rv->compatible_roadtypes);
2620  TrackBits trackbits = TrackStatusToTrackBits(ts);
2621 
2622  /* Only X/Y tracks can be sloped. */
2623  if (trackbits != TRACK_BIT_X && trackbits != TRACK_BIT_Y) break;
2624 
2625  Direction dir = rv->direction;
2626 
2627  /* Test if we are reversing. */
2628  Axis a = trackbits == TRACK_BIT_X ? AXIS_X : AXIS_Y;
2629  if (AxisToDirection(a) != dir &&
2630  AxisToDirection(a) != ReverseDir(dir)) {
2631  /* When reversing, the road vehicle is on the edge of the tile,
2632  * so it can be safely compared to the middle of the tile. */
2633  dir = INVALID_DIR;
2634  }
2635 
2636  rv->gv_flags |= FixVehicleInclination(rv, dir);
2637  break;
2638  }
2639  case VEH_SHIP:
2640  break;
2641 
2642  default:
2643  continue;
2644  }
2645 
2646  if (IsBridgeTile(v->tile) && TileVirtXY(v->x_pos, v->y_pos) == v->tile) {
2647  /* In old versions, z_pos was 1 unit lower on bridge heads.
2648  * However, this invalid state could be converted to new savegames
2649  * by loading and saving the game in a new version. */
2650  v->z_pos = GetSlopePixelZ(v->x_pos, v->y_pos);
2652  if (v->type == VEH_TRAIN && !(v->vehstatus & VS_CRASHED) &&
2653  v->direction != DiagDirToDir(dir)) {
2654  /* If the train has left the bridge, it shouldn't have
2655  * track == TRACK_BIT_WORMHOLE - this could happen
2656  * when the train was reversed while on the last "tick"
2657  * on the ramp before leaving the ramp to the bridge. */
2658  Train::From(v)->track = DiagDirToDiagTrackBits(dir);
2659  }
2660  }
2661 
2662  /* If the vehicle is really above v->tile (not in a wormhole),
2663  * it should have set v->z_pos correctly. */
2664  assert(v->tile != TileVirtXY(v->x_pos, v->y_pos) || v->z_pos == GetSlopePixelZ(v->x_pos, v->y_pos));
2665  }
2666 
2667  /* Fill Vehicle::cur_real_order_index */
2668  FOR_ALL_VEHICLES(v) {
2669  if (!v->IsPrimaryVehicle()) continue;
2670 
2671  /* Older versions are less strict with indices being in range and fix them on the fly */
2673 
2675  v->UpdateRealOrderIndex();
2676  }
2677  }
2678 
2679  if (IsSavegameVersionBefore(159)) {
2680  /* If the savegame is old (before version 100), then the value of 255
2681  * for these settings did not mean "disabled". As such everything
2682  * before then did reverse.
2683  * To simplify stuff we disable all turning around or we do not
2684  * disable anything at all. So, if some reversing was disabled we
2685  * will keep reversing disabled, otherwise it'll be turned on. */
2687 
2688  Train *t;
2689  FOR_ALL_TRAINS(t) {
2691  }
2692  }
2693 
2694  if (IsSavegameVersionBefore(160)) {
2695  /* Setting difficulty industry_density other than zero get bumped to +1
2696  * since a new option (minimal at position 1) has been added */
2699  }
2700  }
2701 
2702  if (IsSavegameVersionBefore(161)) {
2703  /* Before savegame version 161, persistent storages were not stored in a pool. */
2704 
2705  if (!IsSavegameVersionBefore(76)) {
2706  Industry *ind;
2707  FOR_ALL_INDUSTRIES(ind) {
2708  assert(ind->psa != NULL);
2709 
2710  /* Check if the old storage was empty. */
2711  bool is_empty = true;
2712  for (uint i = 0; i < sizeof(ind->psa->storage); i++) {
2713  if (ind->psa->GetValue(i) != 0) {
2714  is_empty = false;
2715  break;
2716  }
2717  }
2718 
2719  if (!is_empty) {
2720  ind->psa->grfid = _industry_mngr.GetGRFID(ind->type);
2721  } else {
2722  delete ind->psa;
2723  ind->psa = NULL;
2724  }
2725  }
2726  }
2727 
2728  if (!IsSavegameVersionBefore(145)) {
2729  Station *st;
2730  FOR_ALL_STATIONS(st) {
2731  if (!(st->facilities & FACIL_AIRPORT)) continue;
2732  assert(st->airport.psa != NULL);
2733 
2734  /* Check if the old storage was empty. */
2735  bool is_empty = true;
2736  for (uint i = 0; i < sizeof(st->airport.psa->storage); i++) {
2737  if (st->airport.psa->GetValue(i) != 0) {
2738  is_empty = false;
2739  break;
2740  }
2741  }
2742 
2743  if (!is_empty) {
2744  st->airport.psa->grfid = _airport_mngr.GetGRFID(st->airport.type);
2745  } else {
2746  delete st->airport.psa;
2747  st->airport.psa = NULL;
2748 
2749  }
2750  }
2751  }
2752  }
2753 
2754  /* This triggers only when old snow_lines were copied into the snow_line_height. */
2757  }
2758 
2760  /* We store 4 fences in the field tiles instead of only SE and SW. */
2761  for (TileIndex t = 0; t < map_size; t++) {
2762  if (!IsTileType(t, MP_CLEAR) && !IsTileType(t, MP_TREES)) continue;
2763  if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_FIELDS)) continue;
2764  uint fence = GB(_m[t].m4, 5, 3);
2765  if (fence != 0 && IsTileType(TILE_ADDXY(t, 1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(t, 1, 0), CLEAR_FIELDS)) {
2766  SetFence(TILE_ADDXY(t, 1, 0), DIAGDIR_NE, fence);
2767  }
2768  fence = GB(_m[t].m4, 2, 3);
2769  if (fence != 0 && IsTileType(TILE_ADDXY(t, 0, 1), MP_CLEAR) && IsClearGround(TILE_ADDXY(t, 0, 1), CLEAR_FIELDS)) {
2770  SetFence(TILE_ADDXY(t, 0, 1), DIAGDIR_NW, fence);
2771  }
2772  SB(_m[t].m4, 2, 3, 0);
2773  SB(_m[t].m4, 5, 3, 0);
2774  }
2775  }
2776 
2777  /* The center of train vehicles was changed, fix up spacing. */
2779 
2780  if (IsSavegameVersionBefore(165)) {
2781  Town *t;
2782 
2783  FOR_ALL_TOWNS(t) {
2784  /* Set the default cargo requirement for town growth */
2786  case LT_ARCTIC:
2788  break;
2789 
2790  case LT_TROPIC:
2793  break;
2794  }
2795  }
2796  }
2797 
2798  if (IsSavegameVersionBefore(165)) {
2799  /* Adjust zoom level to account for new levels */
2800  _saved_scrollpos_zoom = _saved_scrollpos_zoom + ZOOM_LVL_SHIFT;
2801  _saved_scrollpos_x *= ZOOM_LVL_BASE;
2802  _saved_scrollpos_y *= ZOOM_LVL_BASE;
2803  }
2804 
2805  /* When any NewGRF has been changed the availability of some vehicles might
2806  * have been changed too. e->company_avail must be set to 0 in that case
2807  * which is done by StartupEngines(). */
2808  if (gcf_res != GLC_ALL_GOOD) StartupEngines();
2809 
2810  if (IsSavegameVersionBefore(166)) {
2811  /* Update cargo acceptance map of towns. */
2812  for (TileIndex t = 0; t < map_size; t++) {
2813  if (!IsTileType(t, MP_HOUSE)) continue;
2814  Town::Get(GetTownIndex(t))->cargo_accepted.Add(t);
2815  }
2816 
2817  Town *town;
2818  FOR_ALL_TOWNS(town) {
2819  UpdateTownCargoes(town);
2820  }
2821  }
2822 
2823  /* The road owner of standard road stops was not properly accounted for. */
2824  if (IsSavegameVersionBefore(172)) {
2825  for (TileIndex t = 0; t < map_size; t++) {
2826  if (!IsStandardRoadStopTile(t)) continue;
2827  Owner o = GetTileOwner(t);
2828  SetRoadOwner(t, ROADTYPE_ROAD, o);
2829  SetRoadOwner(t, ROADTYPE_TRAM, o);
2830  }
2831  }
2832 
2833  if (IsSavegameVersionBefore(175)) {
2834  /* Introduced tree planting limit. */
2835  Company *c;
2836  FOR_ALL_COMPANIES(c) c->tree_limit = _settings_game.construction.tree_frame_burst << 16;
2837  }
2838 
2839  if (IsSavegameVersionBefore(177)) {
2840  /* Fix too high inflation rates */
2841  if (_economy.inflation_prices > MAX_INFLATION) _economy.inflation_prices = MAX_INFLATION;
2843 
2844  /* We have to convert the quarters of bankruptcy into months of bankruptcy */
2845  FOR_ALL_COMPANIES(c) {
2847  }
2848  }
2849 
2850  if (IsSavegameVersionBefore(178)) {
2851  extern uint8 _old_diff_level;
2852  /* Initialise script settings profile */
2853  _settings_game.script.settings_profile = IsInsideMM(_old_diff_level, SP_BEGIN, SP_END) ? _old_diff_level : (uint)SP_MEDIUM;
2854  }
2855 
2856  if (IsSavegameVersionBefore(182)) {
2857  Aircraft *v;
2858  /* Aircraft acceleration variable was bonkers */
2859  FOR_ALL_AIRCRAFT(v) {
2860  if (v->subtype <= AIR_AIRCRAFT) {
2861  const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
2862  v->acceleration = avi->acceleration;
2863  }
2864  }
2865 
2866  /* Blocked tiles could be reserved due to a bug, which causes
2867  * other places to assert upon e.g. station reconstruction. */
2868  for (TileIndex t = 0; t < map_size; t++) {
2870  SetRailStationReservation(t, false);
2871  }
2872  }
2873  }
2874 
2875  if (IsSavegameVersionBefore(184)) {
2876  /* The global units configuration is split up in multiple configurations. */
2877  extern uint8 _old_units;
2878  _settings_game.locale.units_velocity = Clamp(_old_units, 0, 2);
2879  _settings_game.locale.units_power = Clamp(_old_units, 0, 2);
2880  _settings_game.locale.units_weight = Clamp(_old_units, 1, 2);
2881  _settings_game.locale.units_volume = Clamp(_old_units, 1, 2);
2883  _settings_game.locale.units_height = Clamp(_old_units, 0, 2);
2884  }
2885 
2886  if (IsSavegameVersionBefore(186)) {
2887  /* Move ObjectType from map to pool */
2888  for (TileIndex t = 0; t < map_size; t++) {
2889  if (IsTileType(t, MP_OBJECT)) {
2890  Object *o = Object::Get(_m[t].m2);
2891  o->type = _m[t].m5;
2892  _m[t].m5 = 0; // zero upper bits of (now bigger) ObjectID
2893  }
2894  }
2895  }
2896 
2897  if (IsSavegameVersionBefore(188)) {
2898  /* Fix articulated road vehicles.
2899  * Some curves were shorter than other curves.
2900  * Now they have the same length, but that means that trailing articulated parts will
2901  * take longer to go through the curve than the parts in front which already left the courve.
2902  * So, make articulated parts catch up. */
2903  RoadVehicle *v;
2904  bool roadside = _settings_game.vehicle.road_side == 1;
2905  SmallVector<uint, 16> skip_frames;
2906  FOR_ALL_ROADVEHICLES(v) {
2907  if (!v->IsFrontEngine()) continue;
2908  skip_frames.Clear();
2909  TileIndex prev_tile = v->tile;
2910  uint prev_tile_skip = 0;
2911  uint cur_skip = 0;
2912  for (RoadVehicle *u = v; u != NULL; u = u->Next()) {
2913  if (u->tile != prev_tile) {
2914  prev_tile_skip = cur_skip;
2915  prev_tile = u->tile;
2916  } else {
2917  cur_skip = prev_tile_skip;
2918  }
2919 
2920  uint *this_skip = skip_frames.Append();
2921  *this_skip = prev_tile_skip;
2922 
2923  /* The following 3 curves now take longer than before */
2924  switch (u->state) {
2925  case 2:
2926  cur_skip++;
2927  if (u->frame <= (roadside ? 9 : 5)) *this_skip = cur_skip;
2928  break;
2929 
2930  case 4:
2931  cur_skip++;
2932  if (u->frame <= (roadside ? 5 : 9)) *this_skip = cur_skip;
2933  break;
2934 
2935  case 5:
2936  cur_skip++;
2937  if (u->frame <= (roadside ? 4 : 2)) *this_skip = cur_skip;
2938  break;
2939 
2940  default:
2941  break;
2942  }
2943  }
2944  while (cur_skip > skip_frames[0]) {
2945  RoadVehicle *u = v;
2946  RoadVehicle *prev = NULL;
2947  for (uint *it = skip_frames.Begin(); it != skip_frames.End(); ++it, prev = u, u = u->Next()) {
2948  extern bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *prev);
2949  if (*it >= cur_skip) IndividualRoadVehicleController(u, prev);
2950  }
2951  cur_skip--;
2952  }
2953  }
2954  }
2955 
2956  /*
2957  * Only keep order-backups for network clients (and when replaying).
2958  * If we are a network server or not networking, then we just loaded a previously
2959  * saved-by-server savegame. There are no clients with a backup, so clear it.
2960  * Furthermore before savegame version 192 the actual content was always corrupt.
2961  */
2963 #ifndef DEBUG_DUMP_COMMANDS
2964  /* Note: We cannot use CleanPool since that skips part of the destructor
2965  * and then leaks un-reachable Orders in the order pool. */
2966  OrderBackup *ob;
2967  FOR_ALL_ORDER_BACKUPS(ob) {
2968  delete ob;
2969  }
2970 #endif
2971  }
2972 
2973 
2974  /* Station acceptance is some kind of cache */
2975  if (IsSavegameVersionBefore(127)) {
2976  Station *st;
2977  FOR_ALL_STATIONS(st) UpdateStationAcceptance(st, false);
2978  }
2979 
2980  /* Road stops is 'only' updating some caches */
2982  AfterLoadLabelMaps();
2985 
2986  GamelogPrintDebug(1);
2987 
2989  /* Restore the signals */
2991 
2993  return true;
2994 }
2995 
3005 {
3006  /* reload grf data */
3007  GfxLoadSprites();
3009  RecomputePrices();
3010  /* reload vehicles */
3011  ResetVehicleHash();
3012  AfterLoadVehicles(false);
3013  StartupEngines();
3015  /* update station graphics */
3016  AfterLoadStations();
3017  /* Update company statistics. */
3019  /* Check and update house and town values */
3021  /* Delete news referring to no longer existing entities */
3023  /* Update livery selection windows */
3025  /* Update company infrastructure counts. */
3027  /* redraw the whole screen */
3030 }
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:549
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:89
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:520
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
Source/destination is a town.
Definition: cargo_type.h:141
uint8 max_heightlevel
maximum allowed heightlevel
static void ResetSignalHandlers()
Resets signal handlers back to original handlers.
Definition: afterload.cpp:326
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
static void StartNew(CompanyID company, bool rerandomise_ai=true)
Start a new AI company.
Definition: ai_core.cpp:37
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:1439
bool _networking
are we in networking mode?
Definition: network.cpp:56
Default settings for vehicles.
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:255
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 void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:191
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:432
static void MakeVoid(TileIndex t)
Make a nice void tile ;)
Definition: void_map.h:21
A game normally paused.
Definition: openttd.h:59
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.
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:35
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:370
Yet Another PathFinder.
Definition: vehicle_type.h:63
SourceID src
Index of source. Either TownID or IndustryID.
Definition: subsidy_base.h:30
static bool IsAirportTile(TileIndex t)
Is this tile a station tile and an airport tile?
Definition: station_map.h:168
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:561
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:63
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:78
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:398
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:79
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:94
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
EngineRenewList engine_renew_list
Engine renewals of this company.
Definition: company_base.h:120
uint16 cur_speed
current speed
Definition: vehicle_base.h:293
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:2923
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
Date intro_date
Date of introduction of the engine.
Definition: engine_base.h:25
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:61
void NORETURN SlError(StringID string, const char *extra_msg)
Error handler.
Definition: saveload.cpp:533
an airplane
Definition: aircraft.h:34
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition: saveload.cpp:272
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
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:82
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
static TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir. ...
Definition: track_func.h:512
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:74
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:416
Manual distribution. No link graph calculations are run.
Date build_date
Date of construction.
Definition: object_base.h:29
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
Definition: afterload.cpp:3004
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
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:372
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:166
TownLayoutByte town_layout
select town layout,
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
byte units_velocity
unit system for velocity
Defines the internal data of a functional industry.
Definition: industry.h:39
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:81
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
T * First() const
Get the first vehicle in the chain.
bool forbid_90_deg
forbid trains to make 90 deg turns
Cargo behaves water-like.
Definition: cargotype.h:31
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.
void GamelogPrintDebug(int level)
Prints gamelog to debug output.
Definition: gamelog.cpp:341
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:441
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:479
Standard non-electric rails.
Definition: rail_type.h:31
static void InitializeWindowsAndCaches()
Initialization of the windows and several kinds of caches.
Definition: afterload.cpp:236
void ShowAIDebugWindowIfAIError()
Open the AI debug window if one of the AI scripts has crashed.
Definition: ai_gui.cpp:1546
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
bool infrastructure_maintenance
enable monthly maintenance fee for owner infrastructure
Basic data to distinguish a GRF.
Definition: newgrf_config.h:84
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:159
uint _gamelog_actions
number of actions
Definition: gamelog.cpp:38
CompanySettings settings
settings specific for each company
Definition: company_base.h:121
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:526
bool IsNormalAircraft() const
Check if the aircraft type is a normal flying device; eg not a rotor or a shadow. ...
Definition: aircraft.h:121
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.
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.
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:41
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
Use this function to notify YAPF that track layout (or signal configuration) has change.
Definition: yapf_rail.cpp:642
static Station * From(BaseStation *st)
Converts a BaseStation to SpecializedStation with type checking.
#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
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:676
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:23
Normal road.
Definition: road_map.h:24
Northeast.
TileIndex * _animated_tile_list
The table/list with animated tiles.
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
Plain water.
Definition: water_map.h:42
static bool IsHouseCompleted(TileIndex t)
Get the completion of this house.
Definition: town_map.h:147
Stop at the far end of the platform.
Definition: order_type.h:92
static const size_t MAX_SIZE
Make template parameter accessible from outside.
Definition: pool_type.hpp:87
byte subtype
subtype (Filled with values from #EffectVehicles/#TrainSubTypes/#AircraftSubTypes) ...
Definition: vehicle_base.h:327
old or new scenario
Definition: fileio_type.h:21
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:3238
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
uint _animated_tile_count
The number of animated tiles in the current state.
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:207
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:3239
static void SetCrossingReservation(TileIndex t, bool b)
Set the reservation state of the rail crossing.
Definition: road_map.h:363
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
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:434
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 give tiletype.
Definition: tile_map.h:143
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:352
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:86
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
PersistentStorage * psa
Persistent storage for NewGRF industries.
Definition: industry.h:71
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:129
X-axis track.
Definition: track_type.h:43
YAPFSettings yapf
pathfinder settings for the yet another pathfinder
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
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
Definition: cargo_type.h:69
int16 ratings[MAX_COMPANIES]
ratings of each company for this town
Definition: town.h:77
VehicleDefaultSettings vehicle
default settings for vehicles
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
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:58
static TownID GetTownIndex(TileIndex t)
Get the index of which town this house/street is attached to.
Definition: town_map.h:24
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:171
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:220
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
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:74
void LoadStringWidthTable(bool monospace)
Initialize _stringwidth_table cache.
Definition: gfx.cpp:1130
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
IndustryType type
type of industry.
Definition: industry.h:55
uint32 clear_limit
Amount of tiles we can (still) clear (times 65536).
Definition: company_base.h:87
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
CargoID accepts_cargo[3]
3 input cargo slots
Definition: industry.h:47
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:323
void UpdateRealOrderIndex()
Skip implicit orders until cur_real_order_index is a non-implicit order.
Definition: vehicle_base.h:838
An object, such as transmitter, on the map.
Definition: object_base.h:25
TileArea location
Location of the industry.
Definition: industry.h:40
TYPE storage[SIZE]
Memory to for the storage array.
Used for iterations.
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
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:2510
void GamelogGRFAddList(const GRFConfig *newg)
Logs adding of list of GRFs.
Definition: gamelog.cpp:653
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:882
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:101
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:62
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:2490
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition: company_base.h:94
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
PersistentStorage * psa
Persistent storage for NewGRF airports.
Definition: station_base.h:313
CargoID produced_cargo[2]
2 production cargo slots
Definition: industry.h:42
static Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition: track_func.h:525
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:607
void AfterLoadLinkGraphs()
Spawn the threads for running link graph calculations.
StationFacilityByte facilities
The facilities that this station has.
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.
static bool IsSavegameVersionBefore(uint16 major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:465
#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
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:25
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
Definition: industrytype.h:120
static uint TileHash(uint x, uint y)
Calculate a hash value from a tile position.
Definition: tile_map.h:314
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:475
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
Station with a dock.
Definition: station_type.h:59
uint8 plane_speed
divisor for speed of aircraft
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:56
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:257
CargoID cargo_type
Cargo type involved in this subsidy, CT_INVALID for invalid subsidy.
Definition: subsidy_base.h:25
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:1699
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
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:36
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:88
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:509
byte state
State of the airport.
Definition: aircraft.h:79
int16 engine_renew_months
months before/after the maximum vehicle age a vehicle should be renewed
byte turn_counter
Ticks between each turn to prevent > 45 degree turns.
Definition: aircraft.h:82
bool engine_renew
is autorenew enabled
Ship vehicle type.
Definition: vehicle_type.h:26
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
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:39
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
Maximal number of cargo types in a game.
Definition: cargo_type.h:66
End of setting profiles.
Definition: settings_type.h:33
byte units_power
unit system for power
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 MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1904
void StartupEngines()
Start/initialise all our engines.
Definition: engine.cpp:688
void ResetOldNames()
Free the memory of the old names array.
Definition: strings_sl.cpp:109
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:45
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
Town * CalcClosestTownFromTile(TileIndex tile, uint threshold=UINT_MAX)
Return the town closest to the given tile within threshold.
Definition: town_cmd.cpp:3214
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
void ConnectMultiheadedTrains()
Link front and rear multiheaded engines to each other This is done when loading a savegame...
Definition: vehicle_sl.cpp:34
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
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:35
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:472
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
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:760
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
void FixupTrainLengths()
Fixup old train spacing.
Definition: vehicle_sl.cpp:476
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:77
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
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
RailTypes avail_railtypes
Rail types available to the company.
Definition: company_base.h:70
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
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:140
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
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:115
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
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
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:61
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:351
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
Station with train station.
Definition: station_type.h:55
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.
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:380
The vehicle is in a road stop.
Definition: roadveh.h:50
int32 z_pos
z coordinate.
Definition: vehicle_base.h:270
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
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:576
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 aircrafts.
Definition: aircraft.h:142
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:29
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
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:553
ConstructionSettings construction
construction of things in-game
CargoID accepts_cargo[3]
3 accepted cargoes.
Definition: industrytype.h:116
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:688
#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
uint32 grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:85
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.
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:288
uint8 settings_profile
difficulty profile to set initial settings of scripts, esp. random AIs
int32 x_pos
x coordinate.
Definition: vehicle_base.h:268
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:986
Light signal.
Definition: signal_type.h:19
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
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:515
bool AddInflation(bool check_year)
Add monthly inflation.
Definition: economy.cpp:722
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
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:498
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
uint8 roadveh_slope_steepness
Steepness of hills for road vehicles when using realistic acceleration.
int32 y_pos
y coordinate.
Definition: vehicle_base.h:269
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:53
Pause mode bits when paused for network reasons.
Definition: openttd.h:67
Road vehicle is a tram/light rail vehicle.
Definition: engine_type.h:154
byte wait_for_pbs_path
how long to wait for a path reservation.
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:1910
byte remaining
Remaining months when this subsidy is valid.
Definition: subsidy_base.h:26
bool SaveloadCrashWithMissingNewGRFs()
Did loading the savegame cause a crash? If so, were NewGRFs missing?
Definition: afterload.cpp:359
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:840
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
union Vehicle::@46 orders
The orders currently assigned to the vehicle.
static void SetTrackReservation(TileIndex t, TrackBits b)
Sets the reserved track bits of the tile.
Definition: rail_map.h:210
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
static void SetTownIndex(TileIndex t, TownID index)
Set the town index for a road or house tile.
Definition: town_map.h:36
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.
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.
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
An invalid company.
Definition: company_type.h:32
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
Declaration of functions used in more save/load files.
The tile/execution is done by "water".
Definition: company_type.h:28
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:54
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:338
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:58
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:165
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:3220
static void SetTropicZone(TileIndex tile, TropicZone type)
Set the tropic zone.
Definition: tile_map.h:218
GroundVehicleCache gcache
Cache of often calculated values.
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:1461
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:316
static void SetRailType(TileIndex t, RailType r)
Sets the rail type of the given tile.
Definition: rail_map.h:126
void GfxLoadSprites()
Initialise and load all the sprites.
Definition: gfxinit.cpp:337
uint16 max_tunnel_length
maximum length of tunnels
void Reset()
Completely reset the industry build data.
Train vehicle type.
Definition: vehicle_type.h:24
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.