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

OpenTTD Source 15.0-RC2

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