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