OpenTTD Source: src/saveload/afterload.cpp Source File

OpenTTD Source 14.0-beta1

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