OpenTTD Source 20261112-master-gbcbec5e63f
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
9
10#include "../stdafx.h"
11#include "../void_map.h"
12#include "../signs_base.h"
13#include "../depot_base.h"
14#include "../network/network.h"
15#include "../gfxinit.h"
16#include "../viewport_func.h"
17#include "../viewport_kdtree.h"
18#include "../industry.h"
19#include "../clear_map.h"
20#include "../vehicle_func.h"
21#include "../string_func.h"
22#include "../strings_func.h"
23#include "../window_func.h"
24#include "../roadveh.h"
25#include "../roadveh_cmd.h"
26#include "../train.h"
27#include "../station_base.h"
28#include "../station_func.h"
29#include "../waypoint_base.h"
30#include "../roadstop_base.h"
31#include "../tunnelbridge_map.h"
33#include "../elrail_func.h"
34#include "../signs_func.h"
35#include "../aircraft.h"
36#include "../object_base.h"
37#include "../tree_map.h"
38#include "../company_func.h"
40#include "../road_cmd.h"
41#include "../ai/ai.hpp"
43#include "../game/game.hpp"
44#include "../town.h"
45#include "../economy_base.h"
47#include "../subsidy_base.h"
48#include "../subsidy_func.h"
49#include "../newgrf.h"
50#include "../engine_func.h"
51#include "../rail_gui.h"
53#include "../smallmap_gui.h"
54#include "../news_func.h"
55#include "../order_backup.h"
56#include "../error.h"
57#include "../disaster_vehicle.h"
58#include "../ship.h"
59#include "../timer/timer.h"
63#include "../picker_func.h"
64
65#include "saveload_error.hpp"
66#include "saveload_func.h"
67#include "saveload_internal.h"
68
69#include <signal.h>
70
71#include "table/strings.h"
72
73#include "../safeguards.h"
74
75extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = CompanyID::Invalid());
76extern void ClearOldOrders();
77
88void SetWaterClassDependingOnSurroundings(Tile t, bool include_invalid_water_class)
89{
90 /* If the slope is not flat, we always assume 'land' (if allowed). Also for one-corner-raised-shores.
91 * Note: Wrt. autosloping under industry tiles this is the most fool-proof behaviour. */
92 if (!IsTileFlat(t)) {
93 if (include_invalid_water_class) {
95 return;
96 } else {
97 SlErrorCorrupt("Invalid water class for dry tile");
98 }
99 }
100
101 /* Mark tile dirty in all cases */
103
104 if (TileX(t) == 0 || TileY(t) == 0 || TileX(t) == Map::MaxX() - 1 || TileY(t) == Map::MaxY() - 1) {
105 /* tiles at map borders are always WaterClass::Sea */
107 return;
108 }
109
110 bool has_water = false;
111 bool has_canal = false;
112 bool has_river = false;
113
115 Tile neighbour = TileAddByDiagDir(t, dir);
116 switch (GetTileType(neighbour)) {
117 case TileType::Water:
118 /* clear water and shipdepots have already a WaterClass associated */
119 if (IsCoast(neighbour)) {
120 has_water = true;
121 } else if (!IsLock(neighbour)) {
122 switch (GetWaterClass(neighbour)) {
123 case WaterClass::Sea: has_water = true; break;
124 case WaterClass::Canal: has_canal = true; break;
125 case WaterClass::River: has_river = true; break;
126 default: SlErrorCorrupt("Invalid water class for tile");
127 }
128 }
129 break;
130
132 /* Shore or flooded halftile */
133 has_water |= (GetRailGroundType(neighbour) == RailGroundType::HalfTileWater);
134 break;
135
136 case TileType::Trees:
137 /* trees on shore */
138 has_water |= (static_cast<TreeGround>(GB(neighbour.m2(), 4, 2)) == TreeGround::Shore);
139 break;
140
141 default: break;
142 }
143 }
144
145 if (!has_water && !has_canal && !has_river && include_invalid_water_class) {
147 return;
148 }
149
150 if (has_river && !has_canal) {
152 } else if (has_canal || !has_water) {
154 } else {
156 }
157}
158
159static void ConvertTownOwner()
160{
161 for (auto tile : Map::Iterate()) {
162 switch (GetTileType(tile)) {
163 case TileType::Road:
164 if (GB(tile.m5(), 4, 2) == to_underlying(RoadTileType::Crossing) && HasBit(tile.m3(), 7)) {
165 tile.m3() = OWNER_TOWN.base();
166 }
167 [[fallthrough]];
168
170 if (tile.m1() & 0x80) SetTileOwner(tile, OWNER_TOWN);
171 break;
172
173 default: break;
174 }
175 }
176}
177
180{
181 for (Town *t : Town::Iterate()) {
182 t->exclusivity = CompanyID::Invalid();
183 }
184}
185
199
204static void UpdateVoidTiles()
205{
206 for (uint x = 0; x < Map::SizeX(); x++) MakeVoid(TileXY(x, Map::MaxY()));
207 for (uint y = 0; y < Map::SizeY(); y++) MakeVoid(TileXY(Map::MaxX(), y));
208}
209
210static inline RailType UpdateRailType(RailType rt, RailType min)
211{
212 return rt >= min ? (RailType)(rt + 1): rt;
213}
214
219{
223 UpdateAllTextEffectVirtCoords();
224 RebuildViewportKdtree();
225}
226
227void ClearAllCachedNames()
228{
229 ClearAllStationCachedNames();
231 ClearAllIndustryCachedNames();
232}
233
244{
245 /* Initialize windows */
248
249 /* Update coordinates of the signs. */
250 ClearAllCachedNames();
252 ResetViewportAfterLoadGame();
253
254 for (Company *c : Company::Iterate()) {
255 /* For each company, verify (while loading a scenario) that the inauguration date is the current year and set it
256 * accordingly if it is not the case. No need to set it on companies that are not been used already,
257 * thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */
258 if (_file_to_saveload.ftype.abstract == AbstractFileType::Scenario && c->inaugurated_year != EconomyTime::MIN_YEAR) {
259 c->inaugurated_year = TimerGameEconomy::year;
260 }
261 }
262
263 /* Count number of objects per type */
264 for (Object *o : Object::Iterate()) {
265 Object::IncTypeCount(o->type);
266 }
267
268 /* Identify owners of persistent storage arrays */
269 for (Industry *i : Industry::Iterate()) {
270 if (i->psa != nullptr) {
271 i->psa->feature = GrfSpecFeature::Industries;
272 i->psa->tile = i->location.tile;
273 }
274 }
275 for (Station *s : Station::Iterate()) {
276 if (s->airport.psa != nullptr) {
277 s->airport.psa->feature = GrfSpecFeature::Airports;
278 s->airport.psa->tile = s->airport.tile;
279 }
280 }
281 for (Town *t : Town::Iterate()) {
282 for (auto &it : t->psa_list) {
283 it->feature = GrfSpecFeature::FakeTowns;
284 it->tile = t->xy;
285 }
286 }
287 for (RoadVehicle *rv : RoadVehicle::Iterate()) {
288 if (rv->IsFrontEngine()) {
289 rv->CargoChanged();
290 }
291 }
292
294
296
298
299 /* Towns have a noise controlled number of airports system
300 * So each airport's noise value must be added to the town->noise_reached value
301 * Reset each town's noise_reached value to '0' before. */
303
306
307 /* Rebuild the smallmap list of owners. */
309}
310
311typedef void (CDECL *SignalHandlerPointer)(int);
312static SignalHandlerPointer _prev_segfault = nullptr;
313static SignalHandlerPointer _prev_abort = nullptr;
314static SignalHandlerPointer _prev_fpe = nullptr;
315
316static void CDECL HandleSavegameLoadCrash(int signum);
317
322static void SetSignalHandlers()
323{
324 _prev_segfault = signal(SIGSEGV, HandleSavegameLoadCrash);
325 _prev_abort = signal(SIGABRT, HandleSavegameLoadCrash);
326 _prev_fpe = signal(SIGFPE, HandleSavegameLoadCrash);
327}
328
333{
334 signal(SIGSEGV, _prev_segfault);
335 signal(SIGABRT, _prev_abort);
336 signal(SIGFPE, _prev_fpe);
337}
338
341
351
358static void CDECL HandleSavegameLoadCrash(int signum)
359{
361
362 std::string message;
363 message.reserve(1024);
364 message += "Loading your savegame caused OpenTTD to crash.\n";
365
366 _saveload_crash_with_missing_newgrfs = std::ranges::any_of(_grfconfig, [](const auto &c) { return c->flags.Test(GRFConfigFlag::Compatible) || c->status == GRFStatus::NotFound; });
367
369 message +=
370 "This is most likely caused by a missing NewGRF or a NewGRF that\n"
371 "has been loaded as replacement for a missing NewGRF. OpenTTD\n"
372 "cannot easily determine whether a replacement NewGRF is of a newer\n"
373 "or older version.\n"
374 "It will load a NewGRF with the same GRF ID as the missing NewGRF.\n"
375 "This means that if the author makes incompatible NewGRFs with the\n"
376 "same GRF ID, OpenTTD cannot magically do the right thing. In most\n"
377 "cases, OpenTTD will load the savegame and not crash, but this is an\n"
378 "exception.\n"
379 "Please load the savegame with the appropriate NewGRFs installed.\n"
380 "The missing/compatible NewGRFs are:\n";
381
382 for (const auto &c : _grfconfig) {
383 if (c->flags.Test(GRFConfigFlag::Compatible)) {
384 const GRFIdentifier &replaced = _gamelog.GetOverriddenIdentifier(*c);
385 format_append(message, "NewGRF {} (checksum {}) not found.\n Loaded NewGRF \"{}\" (checksum {}) with same GRF ID instead.\n",
386 FormatArrayAsHex(c->ident.grfid), FormatArrayAsHex(c->original_md5sum), c->filename, FormatArrayAsHex(replaced.md5sum));
387 }
388 if (c->status == GRFStatus::NotFound) {
389 format_append(message, "NewGRF {} ({}) not found; checksum {}.\n",
390 FormatArrayAsHex(c->ident.grfid), c->filename, FormatArrayAsHex(c->ident.md5sum));
391 }
392 }
393 } else {
394 message +=
395 "This is probably caused by a corruption in the savegame.\n"
396 "Please file a bug report and attach this savegame.\n";
397 }
398
399 ShowInfoI(message);
400
401 SignalHandlerPointer call = nullptr;
402 switch (signum) {
403 case SIGSEGV: call = _prev_segfault; break;
404 case SIGABRT: call = _prev_abort; break;
405 case SIGFPE: call = _prev_fpe; break;
406 default: NOT_REACHED();
407 }
408 if (call != nullptr) call(signum);
409}
410
417{
419
420 /* remove leftover rail piece from crossing (from very old savegames) */
421 Train *v = nullptr;
422 for (Train *w : Train::Iterate()) {
423 if (w->tile == TileIndex(t)) {
424 v = w;
425 break;
426 }
427 }
428
429 if (v != nullptr) {
430 /* when there is a train on crossing (it could happen in TTD), set owner of crossing to train owner */
431 SetTileOwner(t, v->owner);
432 return;
433 }
434
435 /* try to find any connected rail */
437 TileIndex tt{t + TileOffsByDiagDir(dd)};
438 if (GetTileTrackStatus(t, TransportType::Rail, RoadTramType::Invalid, dd).trackdirs.Any() &&
442 return;
443 }
444 }
445
446 if (IsLevelCrossingTile(t)) {
447 /* else change the crossing to normal road (road vehicles won't care) */
448 Owner road = GetRoadOwner(t, RoadTramType::Road);
449 Owner tram = GetRoadOwner(t, RoadTramType::Tram);
451 bool hasroad = HasBit(t.m7(), 6);
452 bool hastram = HasBit(t.m7(), 7);
453
454 /* MakeRoadNormal */
456 SetTileOwner(t, road);
457 t.m3() = (hasroad ? bits.base() : 0);
458 t.m5() = (hastram ? bits.base() : 0) | to_underlying(RoadTileType::Normal) << 6;
459 SB(t.m6(), 2, 4, 0);
461 return;
462 }
463
464 /* if it's not a crossing, make it clean land */
466}
467
475{
476 /* Compute place where this vehicle entered the tile */
477 int entry_x = v->x_pos;
478 int entry_y = v->y_pos;
479 switch (dir) {
480 case Direction::NE: entry_x |= TILE_UNIT_MASK; break;
481 case Direction::NW: entry_y |= TILE_UNIT_MASK; break;
482 case Direction::SW: entry_x &= ~TILE_UNIT_MASK; break;
483 case Direction::SE: entry_y &= ~TILE_UNIT_MASK; break;
484 case Direction::Invalid: break;
485 default: NOT_REACHED();
486 }
487 uint8_t entry_z = GetSlopePixelZ(entry_x, entry_y, true);
488
489 /* Compute middle of the tile. */
490 int middle_x = (v->x_pos & ~TILE_UNIT_MASK) + TILE_SIZE / 2;
491 int middle_y = (v->y_pos & ~TILE_UNIT_MASK) + TILE_SIZE / 2;
492 uint8_t middle_z = GetSlopePixelZ(middle_x, middle_y, true);
493
494 /* middle_z == entry_z, no height change. */
495 if (middle_z == entry_z) return {};
496
497 /* middle_z < entry_z, we are going downwards. */
498 if (middle_z < entry_z) return GroundVehicleFlag::GoingDown;
499
500 /* middle_z > entry_z, we are going upwards. */
502}
503
510{
511 for (Vehicle *v : Vehicle::Iterate()) {
512 if (v->IsGroundVehicle()) {
513 /*
514 * Either the vehicle is not actually on the given tile, i.e. it is
515 * in the wormhole of a bridge or a tunnel, or the Z-coordinate must
516 * be the same as when it would be recalculated right now.
517 */
518 assert(v->tile != TileVirtXY(v->x_pos, v->y_pos) || v->z_pos == GetSlopePixelZ(v->x_pos, v->y_pos, true));
519 }
520 }
521}
522
534
538static void StartScripts()
539{
540 /* Script debug window requires AIs to be started before trying to start GameScript. */
541
542 /* Start the AIs. */
543 for (const Company *c : Company::Iterate()) {
544 if (Company::IsValidAiID(c->index)) AI::StartNew(c->index);
545 }
546
547 /* Start the GameScript. */
549
551}
552
559{
561
562 extern TileIndex _cur_tileloop_tile; // From landscape.cpp.
563 /* The LFSR used in RunTileLoop iteration cannot have a zeroed state, make it non-zeroed. */
564 if (_cur_tileloop_tile == 0) _cur_tileloop_tile = TileIndex{1};
565
567
568 _gamelog.TestRevision();
569 _gamelog.TestMode();
570
571 RebuildTownKdtree();
572 RebuildStationKdtree();
573 /* This needs to be done even before conversion, because some conversions will destroy objects
574 * that otherwise won't exist in the tree. */
575 RebuildViewportKdtree();
576
577 /* Group hierarchy may be evaluated during conversion, so ensure its correct early on. */
579
581
584 } else if (_network_dedicated && _pause_mode.Test(PauseMode::Error)) {
585 Debug(Facility::Net, Severity::Critical, "The loading savegame was paused due to an error state");
586 Debug(Facility::Net, Severity::Critical, " This savegame cannot be used for multiplayer");
587 /* Restore the signals */
589 return false;
590 } else if (!_networking || _network_server) {
591 /* If we are in singleplayer mode, i.e. not networking, and loading the
592 * savegame or we are loading the savegame as network server we do
593 * not want to be bothered by being paused because of the automatic
594 * reason of a network server, e.g. joining clients or too few
595 * active clients. Note that resetting these values for a network
596 * client are very bad because then the client is going to execute
597 * the game loop when the server is not, i.e. it desyncs. */
599 }
600
601 /* In very old versions, size of train stations was stored differently.
602 * They had swapped width and height if station was built along the Y axis.
603 * TTO and TTD used 3 bits for width/height, while OpenTTD used 4.
604 * Because the data stored by TTDPatch are unusable for rail stations > 7x7,
605 * recompute the width and height. Doing this unconditionally for all old
606 * savegames simplifies the code. */
608 for (Station *st : Station::Iterate()) {
609 st->train_station.w = st->train_station.h = 0;
610 }
611 for (auto t : Map::Iterate()) {
612 if (!IsTileType(t, TileType::Station)) continue;
613 if (t.m5() > 7) continue; // is it a rail station tile?
614 Station *st = Station::Get(t.m2());
615 assert(st->train_station.tile != 0);
616 int dx = TileX(t) - TileX(st->train_station.tile);
617 int dy = TileY(t) - TileY(st->train_station.tile);
618 assert(dx >= 0 && dy >= 0);
619 st->train_station.w = std::max<uint16_t>(st->train_station.w, dx + 1);
620 st->train_station.h = std::max<uint16_t>(st->train_station.h, dy + 1);
621 }
622 }
623
625 _settings_game.construction.map_height_limit = 15;
626
627 /* In old savegame versions, the heightlevel was coded in bits 0..3 of the type field */
628 for (auto t : Map::Iterate()) {
629 t.height() = GB(t.type(), 0, 4);
630 SB(t.type(), 0, 2, GB(t.m6(), 0, 2));
631 SB(t.m6(), 0, 2, 0);
632 if (MayHaveBridgeAbove(t)) {
633 SB(t.type(), 2, 2, GB(t.m6(), 6, 2));
634 SB(t.m6(), 6, 2, 0);
635 } else {
636 SB(t.type(), 2, 2, 0);
637 }
638 }
639 }
640
641 /* in version 2.1 of the savegame, town owner was unified. */
643
644 /* from version 4.1 of the savegame, exclusive rights are stored at towns */
646
647 /* from version 4.2 of the savegame, currencies are in a different order */
649
650 /* In old version there seems to be a problem that water is owned by
651 * OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current
652 * (4.3) version, so I just check when versions are older, and then
653 * walk through the whole map.. */
655 for (const auto t : Map::Iterate()) {
656 if (IsTileType(t, TileType::Water) && GetTileOwner(t) >= MAX_COMPANIES) {
658 }
659 }
660 }
661
663 for (Company *c : Company::Iterate()) {
664 c->name = CopyFromOldName(c->name_1);
665 if (!c->name.empty()) c->name_1 = STR_SV_UNNAMED;
666 c->president_name = CopyFromOldName(c->president_name_1);
667 if (!c->president_name.empty()) c->president_name_1 = SPECSTR_PRESIDENT_NAME;
668 }
669
670 for (Station *st : Station::Iterate()) {
671 st->name = CopyFromOldName(st->string_id);
672 /* generating new name would be too much work for little effect, use the station name fallback */
673 if (!st->name.empty()) st->string_id = STR_SV_STNAME_FALLBACK;
674 }
675
676 for (Town *t : Town::Iterate()) {
677 t->name = CopyFromOldName(static_cast<StringID>(t->townnametype));
678 if (!t->name.empty()) t->townnametype = SPECSTR_TOWNNAME_START + _settings_game.game_creation.town_name;
679 }
680 }
681
682 /* From this point the old names array is cleared. */
684
686 /* no station is determined by 'tile == INVALID_TILE' now (instead of '0') */
687 for (Station *st : Station::Iterate()) {
688 if (st->airport.tile == 0) st->airport.tile = INVALID_TILE;
689 if (st->train_station.tile == 0) st->train_station.tile = INVALID_TILE;
690 }
691
692 /* the same applies to Company::location_of_HQ */
693 for (Company *c : Company::Iterate()) {
694 if (c->location_of_HQ == 0 || (IsSavegameVersionBefore(SaveLoadVersion::TownTolerancePauseMode) && c->location_of_HQ == 0xFFFF)) {
695 c->location_of_HQ = INVALID_TILE;
696 }
697 }
698 }
699
700 /* convert road side to my format. */
701 if (to_underlying(_settings_game.vehicle.road_side) != 0) _settings_game.vehicle.road_side = RoadVehicleDrivingSide::Right;
702
703 /* Check if all NewGRFs are present, we are very strict in MP mode */
705 for (const auto &c : _grfconfig) {
706 if (c->status == GRFStatus::NotFound) {
707 _gamelog.GRFRemove(c->ident.grfid);
708 } else if (c->flags.Test(GRFConfigFlag::Compatible)) {
709 _gamelog.GRFCompatible(c->ident);
710 }
711 }
712
713 if (_networking && gcf_res != GRFListCompatibility::AllGood) {
714 SetSaveLoadError(STR_NETWORK_ERROR_CLIENT_NEWGRF_MISMATCH);
715 /* Restore the signals */
717 return false;
718 }
719
720 switch (gcf_res) {
721 case GRFListCompatibility::Compatible: ShowErrorMessage(GetEncodedString(STR_NEWGRF_COMPATIBLE_LOAD_WARNING), {}, WarningLevel::Critical); break;
723 default: break;
724 }
725
726 /* The value of TimerGameCalendar::date_fract got divided, so make sure that old games are converted correctly. */
728
729 /* Update current year
730 * must be done before loading sprites as some newgrfs check it */
732
733 /* Only new games can use wallclock units. */
734 if (IsSavegameVersionBefore(SaveLoadVersion::EconomyModeTimekeepingUnits)) _settings_game.economy.timekeeping_units = TimekeepingUnits::Calendar;
735
736 /* Set the correct default for 'minutes per year' if the savegame was created before the setting existed. */
737 if (IsSavegameVersionBefore(SaveLoadVersion::CalendarSubDateFract)) _settings_game.economy.minutes_per_calendar_year = CalendarTime::DEF_MINUTES_PER_YEAR;
738
739 /* Update economy year. If we don't have a separate economy date saved, follow the calendar date. */
742 } else {
744 }
745
746 /*
747 * Force the old behaviour for compatibility reasons with old savegames. As new
748 * settings can only be loaded from new savegames loading old savegames with new
749 * versions of OpenTTD will normally initialize settings newer than the savegame
750 * version with "new game" defaults which the player can define to their liking.
751 * For some settings we override that to keep the behaviour the same as when the
752 * game was saved.
753 *
754 * Note that there is no non-stop in here. This is because the setting could have
755 * either value in TTDPatch. To convert it properly the user has to make sure the
756 * right value has been chosen in the settings. Otherwise we will be converting
757 * it incorrectly in half of the times without a means to correct that.
758 */
759 if (IsSavegameVersionBefore(SaveLoadVersion::TownTolerancePauseMode, 2)) _settings_game.station.modified_catchment = false;
763 if (IsSavegameVersionBefore(SaveLoadVersion::MoreEngineTypes)) _settings_game.vehicle.dynamic_engines = false;
764 if (IsSavegameVersionBefore(SaveLoadVersion::AirportNoise)) _settings_game.economy.station_noise_level = false;
766 _settings_game.vehicle.train_slope_steepness = 3;
767 }
771 _settings_game.vehicle.roadveh_acceleration_model = AccelerationModel::Original;
772 _settings_game.vehicle.roadveh_slope_steepness = 7;
773 }
774 if (IsSavegameVersionBefore(SaveLoadVersion::DisableTownLevelCrossing)) _settings_game.economy.allow_town_level_crossings = true;
776 _settings_game.vehicle.max_train_length = 50;
777 _settings_game.construction.max_bridge_length = 64;
778 _settings_game.construction.max_tunnel_length = 64;
779 }
780 if (IsSavegameVersionBefore(SaveLoadVersion::InfrastructureMaintenanceCosts)) _settings_game.economy.infrastructure_maintenance = false;
782 _settings_game.linkgraph.distribution_pax = DistributionType::Manual;
783 _settings_game.linkgraph.distribution_mail = DistributionType::Manual;
784 _settings_game.linkgraph.distribution_armoured = DistributionType::Manual;
785 _settings_game.linkgraph.distribution_default = DistributionType::Manual;
786 }
787
789 _settings_game.game_creation.ending_year = CalendarTime::DEF_END_YEAR;
790 }
791
792 /* Convert linkgraph update settings from days to seconds. */
794 _settings_game.linkgraph.recalc_interval *= CalendarTime::SECONDS_PER_DAY;
795 _settings_game.linkgraph.recalc_time *= CalendarTime::SECONDS_PER_DAY;
796 }
797
798 /* Load the sprites */
801
802 /* Copy temporary data to Engine pool */
804
805 /* Connect front and rear engines of multiheaded trains and converts
806 * subtype to the new format */
808
809 /* Connect front and rear engines of multiheaded trains */
811
812 /* Fix the CargoPackets *and* fix the caches of CargoLists.
813 * If this isn't done before Stations and especially Vehicles are
814 * running their AfterLoad we might get in trouble. In the case of
815 * vehicles we could give the wrong (cached) count of items in a
816 * vehicle which causes different results when getting their caches
817 * filled; and that could eventually lead to desyncs. */
819
820 /* Update all vehicles: Phase 1 */
822
823 /* Old orders are no longer needed. */
825
826 /* make sure there is a town in the game */
827 if (_game_mode == GameMode::Normal && Town::GetNumItems() == 0) {
828 SetSaveLoadError(STR_ERROR_NO_TOWN_IN_SCENARIO);
829 /* Restore the signals */
831 return false;
832 }
833
834 /* The void tiles on the southern border used to belong to a wrong class (pre 4.3).
835 * This problem appears in savegame version 21 too, see r3455. But after loading the
836 * savegame and saving again, the buggy map array could be converted to new savegame
837 * version. It didn't show up before r12070. */
839
840 /* Fix the cache for cargo payments. */
841 for (CargoPayment *cp : CargoPayment::Iterate()) {
842 cp->front->cargo_payment = cp;
843 cp->current_station = cp->front->last_station_visited;
844 }
845
846
848 /* Prior to SaveLoadVersion::WaterTileType, the water tile type was stored differently from the enumeration. This has to be
849 * converted before SaveLoadVersion::SplitStationTypeFromGfxid and SaveLoadVersion::NewGRFIndustryRandomTriggers conversions which use GetWaterTileType. */
850 static constexpr uint8_t WBL_COAST_FLAG = 0;
851
852 for (auto t : Map::Iterate()) {
853 if (!IsTileType(t, TileType::Water)) continue;
854
855 switch (GB(t.m5(), 4, 4)) {
856 case 0x0: /* Previously WBL_TYPE_NORMAL, Clear water or coast. */
858 break;
859
860 case 0x1: SetWaterTileType(t, WaterTileType::Lock); break; /* Previously WBL_TYPE_LOCK */
861 case 0x8: SetWaterTileType(t, WaterTileType::Depot); break; /* Previously WBL_TYPE_DEPOT */
862 default: SetWaterTileType(t, WaterTileType::Clear); break; /* Shouldn't happen... */
863 }
864 }
865 }
866
868 /* Locks in very old savegames had OWNER_WATER as owner */
869 for (auto t : Map::Iterate()) {
870 switch (GetTileType(t)) {
871 default: break;
872
873 case TileType::Water:
875 break;
876
877 case TileType::Station: {
878 if (HasBit(t.m6(), 3)) SetBit(t.m6(), 2);
879 StationGfx gfx = GetStationGfx(t);
880 StationType st;
881 if ( IsInsideMM(gfx, 0, 8)) { // Rail station
883 SetStationGfx(t, gfx - 0);
884 } else if (IsInsideMM(gfx, 8, 67)) { // Airport
886 SetStationGfx(t, gfx - 8);
887 } else if (IsInsideMM(gfx, 67, 71)) { // Truck
889 SetStationGfx(t, gfx - 67);
890 } else if (IsInsideMM(gfx, 71, 75)) { // Bus
891 st = StationType::Bus;
892 SetStationGfx(t, gfx - 71);
893 } else if (gfx == 75) { // Oil rig
895 SetStationGfx(t, gfx - 75);
896 } else if (IsInsideMM(gfx, 76, 82)) { // Dock
898 SetStationGfx(t, gfx - 76);
899 } else if (gfx == 82) { // Buoy
901 SetStationGfx(t, gfx - 82);
902 } else if (IsInsideMM(gfx, 83, 168)) { // Extended airport
904 SetStationGfx(t, gfx - 83 + 67 - 8);
905 } else if (IsInsideMM(gfx, 168, 170)) { // Drive through truck
908 } else if (IsInsideMM(gfx, 170, 172)) { // Drive through bus
909 st = StationType::Bus;
911 } else {
912 /* Restore the signals */
914 return false;
915 }
916 SB(t.m6(), 3, 3, to_underlying(st));
917 break;
918 }
919 }
920 }
921 }
922
924 /* Expansion of station type field in m6 */
925 for (auto t : Map::Iterate()) {
927 ClrBit(t.m6(), 6);
928 }
929 }
930 }
931
932 for (const auto t : Map::Iterate()) {
933 switch (GetTileType(t)) {
934 case TileType::Station: {
936
937 /* Sanity check */
938 if (!IsBuoy(t) && bst->owner != GetTileOwner(t)) SlErrorCorrupt("Wrong owner for station tile");
939
940 /* Set up station spread */
941 bst->spread.Add(t);
942
943 /* Waypoints don't have road stops/oil rigs in the old format */
944 if (!Station::IsExpected(bst)) break;
945 Station *st = Station::From(bst);
946
947 switch (GetStationType(t)) {
949 case StationType::Bus:
951 /* Before version 5 you could not have more than 250 stations.
952 * Version 6 adds large maps, so you could only place 253*253
953 * road stops on a map (no freeform edges) = 64009. So, yes
954 * someone could in theory create such a full map to trigger
955 * this assertion, it's safe to assume that's only something
956 * theoretical and does not happen in normal games. */
958
959 /* From this version on there can be multiple road stops of the
960 * same type per station. Convert the existing stops to the new
961 * internal data structure. */
962 RoadStop *rs = RoadStop::Create(t);
963
964 RoadStop **head =
965 IsTruckStop(t) ? &st->truck_stops : &st->bus_stops;
966 *head = rs;
967 }
968 break;
969
970 case StationType::Oilrig: {
971 /* The internal encoding of oil rigs was changed twice.
972 * It was 3 (till 2.2) and later 5 (till 5.1).
973 * DeleteOilRig asserts on the correct type, and
974 * setting it unconditionally does not hurt.
975 */
976 Station::GetByTile(t)->airport.type = AT_OILRIG;
977
978 /* Very old savegames sometimes have phantom oil rigs, i.e.
979 * an oil rig which got shut down, but not completely removed from
980 * the map
981 */
982 TileIndex t1 = TileAddXY(t, 0, 1);
984 DeleteOilRig(t);
985 }
986 break;
987 }
988
989 default: break;
990 }
991 break;
992 }
993
994 default: break;
995 }
996 }
997
998 /* In version 6.1 we put the town index in the map-array. To do this, we need
999 * to use m2 (16bit big), so we need to clean m2, and that is where this is
1000 * all about ;) */
1002 for (auto t : Map::Iterate()) {
1003 switch (GetTileType(t)) {
1004 case TileType::House:
1005 t.m4() = t.m2();
1007 break;
1008
1009 case TileType::Road:
1010 t.m4() |= (t.m2() << 4);
1011 if (GB(t.m5(), 4, 2) == to_underlying(RoadTileType::Depot)) break;
1012 if ((GB(t.m5(), 4, 2) == to_underlying(RoadTileType::Crossing) ? (Owner)t.m3() : GetTileOwner(t)) == OWNER_TOWN) {
1014 } else {
1015 SetTownIndex(t, TownID::Begin());
1016 }
1017 break;
1018
1019 default: break;
1020 }
1021 }
1022 }
1023
1024 /* Force the freeform edges to false for old savegames. */
1026 _settings_game.construction.freeform_edges = false;
1027 }
1028
1029 /* From version 9.0, we update the max passengers of a town (was sometimes negative
1030 * before that. */
1032 for (Town *t : Town::Iterate()) UpdateTownMaxPass(t);
1033 }
1034
1035 /* From version 16.0, we included autorenew on engines, which are now saved, but
1036 * of course, we do need to initialize them for older savegames. */
1038 for (Company *c : Company::Iterate()) {
1039 c->engine_renew_list = nullptr;
1040 c->settings.engine_renew = false;
1041 c->settings.engine_renew_months = 6;
1042 c->settings.engine_renew_money = 100000;
1043 }
1044
1045 /* When loading a game, _local_company is not yet set to the correct value.
1046 * However, in a dedicated server we are a spectator, so nothing needs to
1047 * happen. In case we are not a dedicated server, the local company always
1048 * becomes the first available company, unless we are in the scenario editor
1049 * where all the companies are 'invalid'.
1050 */
1052 if (!_network_dedicated && c != nullptr) {
1053 c->settings = _settings_client.company;
1054 }
1055 }
1056
1058 for (auto t : Map::Iterate()) {
1059 switch (GetTileType(t)) {
1060 case TileType::Railway:
1061 if (IsPlainRail(t)) {
1062 /* Swap ground type and signal type for plain rail tiles, so the
1063 * ground type uses the same bits as for depots and waypoints. */
1064 uint tmp = GB(t.m4(), 0, 4);
1065 SB(t.m4(), 0, 4, GB(t.m2(), 0, 4));
1066 SB(t.m2(), 0, 4, tmp);
1067 } else if (HasBit(t.m5(), 2)) {
1068 /* Split waypoint and depot rail type and remove the subtype. */
1069 ClrBit(t.m5(), 2);
1070 ClrBit(t.m5(), 6);
1071 }
1072 break;
1073
1074 case TileType::Road:
1075 /* Swap m3 and m4, so the track type for rail crossings is the
1076 * same as for normal rail. */
1077 std::swap(t.m3(), t.m4());
1078 break;
1079
1080 default: break;
1081 }
1082 }
1083 }
1084
1086 /* Added the RoadType */
1088 for (auto t : Map::Iterate()) {
1089 switch (GetTileType(t)) {
1090 case TileType::Road:
1091 SB(t.m5(), 6, 2, GB(t.m5(), 4, 2));
1092 switch (GetRoadTileType(t)) {
1093 default: SlErrorCorrupt("Invalid road tile type");
1095 SB(t.m4(), 0, 4, GB(t.m5(), 0, 4));
1096 SB(t.m4(), 4, 4, 0);
1097 SB(t.m6(), 2, 4, 0);
1098 break;
1100 SB(t.m4(), 5, 2, GB(t.m5(), 2, 2));
1101 break;
1102 case RoadTileType::Depot: break;
1103 }
1104 SB(t.m7(), 6, 2, 1); // Set pre-NRT road type bits for conversion later.
1105 break;
1106
1107 case TileType::Station:
1108 if (IsStationRoadStop(t)) SB(t.m7(), 6, 2, 1);
1109 break;
1110
1112 /* Middle part of "old" bridges */
1113 if (old_bridge && IsBridge(t) && HasBit(t.m5(), 6)) break;
1114 if (((old_bridge && IsBridge(t)) ? (TransportType)GB(t.m5(), 1, 2) : GetTunnelBridgeTransportType(t)) == TransportType::Road) {
1115 SB(t.m7(), 6, 2, 1); // Set pre-NRT road type bits for conversion later.
1116 }
1117 break;
1118
1119 default: break;
1120 }
1121 }
1122 }
1123
1127
1128 for (auto t : Map::Iterate()) {
1129 switch (GetTileType(t)) {
1130 case TileType::Road:
1131 if (fix_roadtypes) SB(t.m7(), 6, 2, GB(t.m7(), 5, 3));
1132 SB(t.m7(), 5, 1, GB(t.m3(), 7, 1)); // snow/desert
1133 switch (GetRoadTileType(t)) {
1134 default: SlErrorCorrupt("Invalid road tile type");
1136 SB(t.m7(), 0, 4, GB(t.m3(), 0, 4)); // road works
1137 SB(t.m6(), 3, 3, GB(t.m3(), 4, 3)); // ground
1138 SB(t.m3(), 0, 4, GB(t.m4(), 4, 4)); // tram bits
1139 SB(t.m3(), 4, 4, GB(t.m5(), 0, 4)); // tram owner
1140 SB(t.m5(), 0, 4, GB(t.m4(), 0, 4)); // road bits
1141 break;
1142
1144 SB(t.m7(), 0, 5, GB(t.m4(), 0, 5)); // road owner
1145 SB(t.m6(), 3, 3, GB(t.m3(), 4, 3)); // ground
1146 SB(t.m3(), 4, 4, GB(t.m5(), 0, 4)); // tram owner
1147 SB(t.m5(), 0, 1, GB(t.m4(), 6, 1)); // road axis
1148 SB(t.m5(), 5, 1, GB(t.m4(), 5, 1)); // crossing state
1149 break;
1150
1152 break;
1153 }
1154 if (!IsRoadDepot(t) && !HasTownOwnedRoad(t)) {
1155 const Town *town = CalcClosestTownFromTile(t);
1156 if (town != nullptr) SetTownIndex(t, town->index);
1157 }
1158 t.m4() = 0;
1159 break;
1160
1161 case TileType::Station:
1162 if (!IsStationRoadStop(t)) break;
1163
1164 if (fix_roadtypes) SB(t.m7(), 6, 2, GB(t.m3(), 0, 3));
1165 SB(t.m7(), 0, 5, (HasBit(t.m6(), 2) ? OWNER_TOWN : GetTileOwner(t)).base());
1166 SB(t.m3(), 4, 4, t.m1());
1167 t.m4() = 0;
1168 break;
1169
1171 if (old_bridge && IsBridge(t) && HasBit(t.m5(), 6)) break;
1172 if (((old_bridge && IsBridge(t)) ? (TransportType)GB(t.m5(), 1, 2) : GetTunnelBridgeTransportType(t)) == TransportType::Road) {
1173 if (fix_roadtypes) SB(t.m7(), 6, 2, GB(t.m3(), 0, 3));
1174
1175 Owner o = GetTileOwner(t);
1176 SB(t.m7(), 0, 5, o.base()); // road owner
1177 SB(t.m3(), 4, 4, (o == OWNER_NONE ? OWNER_TOWN : o).base()); // tram owner
1178 }
1179 SB(t.m6(), 2, 4, GB(t.m2(), 4, 4)); // bridge type
1180 SB(t.m7(), 5, 1, GB(t.m4(), 7, 1)); // snow/desert
1181
1182 t.m2() = 0;
1183 t.m4() = 0;
1184 break;
1185
1186 default: break;
1187 }
1188 }
1189 }
1190
1191 /* Railtype moved from m3 to m8 in version SaveLoadVersion::ExtendRailtypes. */
1193 for (auto t : Map::Iterate()) {
1194 switch (GetTileType(t)) {
1195 case TileType::Railway:
1196 SetRailType(t, (RailType)GB(t.m3(), 0, 4));
1197 break;
1198
1199 case TileType::Road:
1200 if (IsLevelCrossing(t)) {
1201 SetRailType(t, (RailType)GB(t.m3(), 0, 4));
1202 }
1203 break;
1204
1205 case TileType::Station:
1206 if (HasStationRail(t)) {
1207 SetRailType(t, (RailType)GB(t.m3(), 0, 4));
1208 }
1209 break;
1210
1213 SetRailType(t, (RailType)GB(t.m3(), 0, 4));
1214 }
1215 break;
1216
1217 default:
1218 break;
1219 }
1220 }
1221 }
1222
1224 for (auto t : Map::Iterate()) {
1226 if (IsBridgeTile(t)) {
1227 if (HasBit(t.m5(), 6)) { // middle part
1228 Axis axis = static_cast<Axis>(GB(t.m5(), 0, 1));
1229
1230 if (HasBit(t.m5(), 5)) { // transport route under bridge?
1231 if (static_cast<TransportType>(GB(t.m5(), 3, 2)) == TransportType::Rail) {
1233 t,
1234 GetTileOwner(t),
1235 AxisToTrack(OtherAxis(axis)),
1236 GetRailType(t)
1237 );
1238 } else {
1239 TownID town = IsTileOwner(t, OWNER_TOWN) ? ClosestTownFromTile(t, UINT_MAX)->index : TownID::Begin();
1240
1241 /* MakeRoadNormal */
1243 t.m2() = town.base();
1244 t.m3() = 0;
1246 SB(t.m6(), 2, 4, 0);
1247 t.m7() = 1 << 6;
1249 }
1250 } else {
1251 if (GB(t.m5(), 3, 2) == 0) {
1253 } else {
1254 if (!IsTileFlat(t)) {
1255 MakeShore(t);
1256 } else {
1257 if (GetTileOwner(t) == OWNER_WATER) {
1258 MakeSea(t);
1259 } else {
1260 MakeCanal(t, GetTileOwner(t), Random());
1261 }
1262 }
1263 }
1264 }
1265 SetBridgeMiddle(t, axis);
1266 } else { // ramp
1267 Axis axis = static_cast<Axis>(GB(t.m5(), 0, 1));
1268 uint north_south = GB(t.m5(), 5, 1);
1269 DiagDirection dir = ReverseDiagDir(XYNSToDiagDir(axis, north_south));
1270 TransportType type = static_cast<TransportType>(GB(t.m5(), 1, 2));
1271
1272 t.m5() = 1 << 7 | to_underlying(type) << 2 | to_underlying(dir);
1273 }
1274 }
1275 }
1276
1277 for (Vehicle *v : Vehicle::Iterate()) {
1278 if (!v->IsGroundVehicle()) continue;
1279 if (IsBridgeTile(v->tile)) {
1281
1282 if (dir != DirToDiagDir(v->direction)) continue;
1283 switch (dir) {
1284 default: SlErrorCorrupt("Invalid vehicle direction");
1285 case DiagDirection::NE: if ((v->x_pos & 0xF) != 0) continue; break;
1286 case DiagDirection::SE: if ((v->y_pos & 0xF) != TILE_SIZE - 1) continue; break;
1287 case DiagDirection::SW: if ((v->x_pos & 0xF) != TILE_SIZE - 1) continue; break;
1288 case DiagDirection::NW: if ((v->y_pos & 0xF) != 0) continue; break;
1289 }
1290 } else if (v->z_pos > GetTileMaxPixelZ(TileVirtXY(v->x_pos, v->y_pos))) {
1291 v->tile = GetNorthernBridgeEnd(v->tile);
1292 v->UpdatePosition();
1293 } else {
1294 continue;
1295 }
1296 if (v->type == VehicleType::Train) {
1298 } else {
1300 }
1301 }
1302 }
1303
1305 /* Add road subtypes */
1306 for (auto t : Map::Iterate()) {
1307 bool has_road = false;
1308 switch (GetTileType(t)) {
1309 case TileType::Road:
1310 has_road = true;
1311 break;
1312 case TileType::Station:
1313 has_road = IsAnyRoadStop(t);
1314 break;
1317 break;
1318 default:
1319 break;
1320 }
1321
1322 if (has_road) {
1323 RoadType road_rt = HasBit(t.m7(), 6) ? ROADTYPE_ROAD : INVALID_ROADTYPE;
1324 RoadType tram_rt = HasBit(t.m7(), 7) ? ROADTYPE_TRAM : INVALID_ROADTYPE;
1325
1326 assert(road_rt != INVALID_ROADTYPE || tram_rt != INVALID_ROADTYPE);
1327 SetRoadTypes(t, road_rt, tram_rt);
1328 SB(t.m7(), 6, 2, 0); // Clear pre-NRT road type bits.
1329 }
1330 }
1331 }
1332
1333 /* Elrails got added in rev 24 but can be disabled since version 38. */
1335 RailType min_rail = static_cast<RailType>(1); // Monorail was 1 before elrails were introduced.
1336
1337 if (!_settings_game.vehicle.disable_elrails) {
1338 for (Train *v : Train::Iterate()) {
1339 RailTypes rts = RailVehInfo(v->engine_type)->railtypes;
1340
1341 if (rts.Test(RAILTYPE_ELECTRIC)) {
1342 min_rail = RAILTYPE_RAIL;
1343 break;
1344 }
1345 }
1346 }
1347
1348 /* We update the entire map to keep monorail and maglev in place. */
1349 /* If min_rail == RAILTYPE_RAIL, this will also upgrade normal rail to electric rail. */
1350 for (const auto t : Map::Iterate()) {
1351 switch (GetTileType(t)) {
1352 case TileType::Railway:
1353 SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
1354 break;
1355
1356 case TileType::Road:
1357 if (IsLevelCrossing(t)) {
1358 SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
1359 }
1360 break;
1361
1362 case TileType::Station:
1363 if (HasStationRail(t)) {
1364 SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
1365 }
1366 break;
1367
1370 SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
1371 }
1372 break;
1373
1374 default:
1375 break;
1376 }
1377 }
1379 /* Since we cannot know the preference of a user, let elrails enabled; it
1380 * can be disabled manually. */
1381 _settings_game.vehicle.disable_elrails = false;
1382 }
1383 /* Do the same as when elrails were enabled/disabled manually just now. */
1384 UpdateDisableElrailSettingState(_settings_game.vehicle.disable_elrails, false);
1386
1387 /* In version 16.1 of the savegame a company can decide if trains, which get
1388 * replaced, shall keep their old length. In all prior versions, just default
1389 * to false */
1391 for (Company *c : Company::Iterate()) c->settings.renew_keep_length = false;
1392 }
1393
1395 /* Waypoints became subclasses of stations ... */
1397 /* ... and buoys were moved to waypoints. */
1399 }
1400
1401 /* From version 15, we moved a semaphore bit from bit 2 to bit 3 in m4, making
1402 * room for PBS. Now in version 21 move it back :P. */
1404 for (auto t : Map::Iterate()) {
1405 switch (GetTileType(t)) {
1406 case TileType::Railway:
1407 if (HasSignals(t)) {
1408 /* Original signal type/variant was stored in m4 but since saveload
1409 * version 48 they are in m2. The bits has been already moved to m2
1410 * (see the code somewhere above) so don't use m4, use m2 instead. */
1411
1412 /* convert old PBS signals to combo-signals */
1413 if (HasBit(t.m2(), 2)) SB(t.m2(), 0, 2, to_underlying(SignalType::Combo));
1414
1415 /* move the signal variant back */
1417 ClrBit(t.m2(), 3);
1418 }
1419
1420 /* Clear PBS reservation on track */
1421 if (!IsRailDepotTile(t)) {
1422 SB(t.m4(), 4, 4, 0);
1423 } else {
1424 ClrBit(t.m3(), 6);
1425 }
1426 break;
1427
1428 case TileType::Station: // Clear PBS reservation on station
1429 ClrBit(t.m3(), 6);
1430 break;
1431
1432 default: break;
1433 }
1434 }
1435 }
1436
1438 /* Remove obsolete VS_WAIT_FOR_SLOT state from road vehicles. */
1439 static constexpr VehStates OLD_VS_WAIT_FOR_SLOT{0x40};
1440 for (RoadVehicle *rv : RoadVehicle::Iterate()) {
1441 rv->vehstatus.Reset(OLD_VS_WAIT_FOR_SLOT);
1442 }
1443 }
1444
1446 for (Station *st : Station::Iterate()) {
1447 st->last_vehicle_type = VehicleType::Invalid;
1448 }
1449 }
1450
1452
1455 }
1456
1457 for (Company *c : Company::Iterate()) {
1458 c->avail_railtypes = GetCompanyRailTypes(c->index);
1459 c->avail_roadtypes = GetCompanyRoadTypes(c->index);
1460 }
1461
1462 AfterLoadStations();
1463
1464 /* Time starts at 0 instead of 1920.
1465 * Account for this in older games by adding an offset */
1471
1475 for (Company *c : Company::Iterate()) c->inaugurated_year += EconomyTime::ORIGINAL_BASE_YEAR;
1476 for (Industry *i : Industry::Iterate()) i->last_prod_year += EconomyTime::ORIGINAL_BASE_YEAR;
1477
1478 for (Vehicle *v : Vehicle::Iterate()) {
1479 v->date_of_last_service += EconomyTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
1480 v->build_year += CalendarTime::ORIGINAL_BASE_YEAR;
1481 }
1482 }
1483
1484 /* From 32 on we save the industry who made the farmland.
1485 * To give this prettiness to old savegames, we remove all farmfields and
1486 * plant new ones. */
1488 for (const auto t : Map::Iterate()) {
1490 /* remove fields */
1492 }
1493 }
1494
1495 for (Industry *i : Industry::Iterate()) {
1496 uint j;
1497
1499 for (j = 0; j != 50; j++) PlantRandomFarmField(i);
1500 }
1501 }
1502 }
1503
1504 /* Setting no refit flags to all orders in savegames from before refit in orders were added */
1506 for (OrderList *orderlist : OrderList::Iterate()) {
1507 for (Order &order : orderlist->GetOrders()) {
1508 order.SetRefit(CARGO_NO_REFIT);
1509 }
1510 }
1511
1512 for (Vehicle *v : Vehicle::Iterate()) {
1513 v->current_order.SetRefit(CARGO_NO_REFIT);
1514 }
1515 }
1516
1517 /* From version 53, the map array was changed for house tiles to allow
1518 * space for newhouses grf features. A new byte, m7, was also added. */
1520 for (auto t : Map::Iterate()) {
1521 if (IsTileType(t, TileType::House)) {
1522 if (GB(t.m3(), 6, 2) != TOWN_HOUSE_COMPLETED) {
1523 /* Move the construction stage from m3[7..6] to m5[5..4].
1524 * The construction counter does not have to move. */
1525 SB(t.m5(), 3, 2, GB(t.m3(), 6, 2));
1526 SB(t.m3(), 6, 2, 0);
1527
1528 /* The "house is completed" bit is now in m6[2]. */
1529 SetHouseCompleted(t, false);
1530 } else {
1531 /* The "lift has destination" bit has been moved from
1532 * m5[7] to m7[0]. */
1533 AssignBit(t.m7(), 0, HasBit(t.m5(), 7));
1534 ClrBit(t.m5(), 7);
1535
1536 /* The "lift is moving" bit has been removed, as it does
1537 * the same job as the "lift has destination" bit. */
1538 ClrBit(t.m1(), 7);
1539
1540 /* The position of the lift goes from m1[7..0] to m6[7..2],
1541 * making m1 totally free, now. The lift position does not
1542 * have to be a full byte since the maximum value is 36. */
1543 SetLiftPosition(t, GB(t.m1(), 0, 6 ));
1544
1545 t.m1() = 0;
1546 t.m3() = 0;
1547 SetHouseCompleted(t, true);
1548 }
1549 }
1550 }
1551 }
1552
1554 for (auto t : Map::Iterate()) {
1555 if (IsTileType(t, TileType::House)) {
1556 /* House type is moved from m4 + m3[6] to m8. */
1557 SetHouseType(t, t.m4() | (GB(t.m3(), 6, 1) << 8));
1558 t.m4() = 0;
1559 ClrBit(t.m3(), 6);
1560 }
1561 }
1562 }
1563
1564 /* Check and update house and town values */
1566
1568 for (auto t : Map::Iterate()) {
1570 switch (GetIndustryGfx(t)) {
1572 t.m3() = GB(t.m1(), 2, 5);
1573 break;
1574
1578 t.m3() = GB(t.m1(), 0, 2);
1579 break;
1580
1584 t.m3() = t.m1();
1585 break;
1586
1587 default: // No animation states to change
1588 break;
1589 }
1590 }
1591 }
1592 }
1593
1595 /* Originally just the fact that some cargo had been paid for was
1596 * stored to stop people cheating and cashing in several times. This
1597 * wasn't enough though as it was cleared when the vehicle started
1598 * loading again, even if it didn't actually load anything, so now the
1599 * amount that has been paid is stored. */
1600 for (Vehicle *v : Vehicle::Iterate()) {
1601 v->vehicle_flags.Reset(VehicleFlag{2});
1602 }
1603 }
1604
1605 /* Buoys do now store the owner of the previous water tile, which can never
1606 * be OWNER_NONE. So replace OWNER_NONE with OWNER_WATER. */
1608 for (Waypoint *wp : Waypoint::Iterate()) {
1609 if (wp->facilities.Test(StationFacility::Dock) && IsTileOwner(wp->xy, OWNER_NONE) && TileHeight(wp->xy) == 0) SetTileOwner(wp->xy, OWNER_WATER);
1610 }
1611 }
1612
1614 /* Aircraft units changed from 8 mph to 1 km-ish/h */
1615 for (Aircraft *v : Aircraft::Iterate()) {
1616 if (v->subtype <= AIR_AIRCRAFT) {
1617 const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
1618 v->cur_speed *= 128;
1619 v->cur_speed /= 10;
1620 v->acceleration = avi->acceleration;
1621 }
1622 }
1623 }
1624
1626 /* Perform conversion of very old face bits. */
1627 for (Company *c : Company::Iterate()) {
1628 c->face = ConvertFromOldCompanyManagerFace(c->face.bits);
1629 }
1631 /* Convert old gender and ethnicity bits to face style. */
1632 for (Company *c : Company::Iterate()) {
1633 SetCompanyManagerFaceStyle(c->face, GB(c->face.bits, 0, 2));
1634 }
1635 } else {
1636 /* Look up each company face style by its label. */
1637 for (Company *c : Company::Iterate()) {
1638 auto style = FindCompanyManagerFaceLabel(c->face.style_label);
1639 if (style.has_value()) {
1640 SetCompanyManagerFaceStyle(c->face, *style);
1641 } else {
1642 /* Style no longer exists, pick an entirely new face. */
1644 }
1645 }
1646 }
1647
1649 for (auto t : Map::Iterate()) {
1650 if (IsTileType(t, TileType::Object) && t.m5() == OBJECT_STATUE) {
1651 t.m2() = CalcClosestTownFromTile(t)->index.base();
1652 }
1653 }
1654 }
1655
1656 /* A setting containing the proportion of towns that grow twice as
1657 * fast was added in version 54. From version 56 this is now saved in the
1658 * town as cities can be built specifically in the scenario editor. */
1660 for (Town *t : Town::Iterate()) {
1661 if (_settings_game.economy.larger_towns != 0 && (t->index % _settings_game.economy.larger_towns) == 0) {
1662 t->larger_town = true;
1663 }
1664 }
1665 }
1666
1668 /* Added a FIFO queue of vehicles loading at stations */
1669 for (Vehicle *v : Vehicle::Iterate()) {
1670 if ((v->type != VehicleType::Train || Train::From(v)->IsFrontEngine()) && // for all locs
1671 !v->vehstatus.Any({VehState::Stopped, VehState::Crashed}) && // not stopped or crashed
1672 v->current_order.IsType(OT_LOADING)) { // loading
1673 Station::Get(v->last_station_visited)->loading_vehicles.push_back(v);
1674
1675 /* The loading finished flag is *only* set when actually completely
1676 * finished. Because the vehicle is loading, it is not finished. */
1677 v->vehicle_flags.Reset(VehicleFlag::LoadingFinished);
1678 }
1679 }
1681 /* For some reason non-loading vehicles could be in the station's loading vehicle list */
1682
1683 for (Station *st : Station::Iterate()) {
1684 for (auto iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); /* nothing */) {
1685 Vehicle *v = *iter;
1686 if (!v->current_order.IsType(OT_LOADING)) {
1687 iter = st->loading_vehicles.erase(iter);
1688 } else {
1689 ++iter;
1690 }
1691 }
1692 }
1693 }
1694
1696 /* Setting difficulty industry_density other than zero get bumped to +1
1697 * since a new option (very low at position 1) has been added */
1698 if (_settings_game.difficulty.industry_density > IndustryDensity::FundedOnly) {
1699 _settings_game.difficulty.industry_density = static_cast<IndustryDensity>(to_underlying(_settings_game.difficulty.industry_density) + 1);
1700 }
1701
1702 /* Same goes for number of towns, although no test is needed, just an increment */
1703 _settings_game.difficulty.number_towns++;
1704 }
1705
1707 /* Since now we allow different signal types and variants on a single tile.
1708 * Move signal states to m4 to make room and clone the signal type/variant. */
1709 for (auto t : Map::Iterate()) {
1710 if (IsTileType(t, TileType::Railway) && HasSignals(t)) {
1711 /* move signal states */
1712 SetSignalStates(t, GB(t.m2(), 4, 4));
1713 SB(t.m2(), 4, 4, 0);
1714 /* clone signal type and variant */
1715 SB(t.m2(), 4, 3, GB(t.m2(), 0, 3));
1716 }
1717 }
1718 }
1719
1721 /* In some old savegames a bit was cleared when it should not be cleared */
1722 for (RoadVehicle *rv : RoadVehicle::Iterate()) {
1723 if (rv->state == 250 || rv->state == 251) {
1724 SetBit(rv->state, 2);
1725 }
1726 }
1727 }
1728
1730 /* Added variables to support newindustries */
1731 for (Industry *i : Industry::Iterate()) i->founder = OWNER_NONE;
1732 }
1733
1734 /* From version 82, old style canals (above sealevel (0), WATER owner) are no longer supported.
1735 Replace the owner for those by OWNER_NONE. */
1737 for (const auto t : Map::Iterate()) {
1738 if (IsTileType(t, TileType::Water) &&
1740 GetTileOwner(t) == OWNER_WATER &&
1741 TileHeight(t) != 0) {
1743 }
1744 }
1745 }
1746
1747 /*
1748 * Add the 'previous' owner to the ship depots so we can reset it with
1749 * the correct values when it gets destroyed. This prevents that
1750 * someone can remove canals owned by somebody else and it prevents
1751 * making floods using the removal of ship depots.
1752 */
1754 for (auto t : Map::Iterate()) {
1755 if (IsShipDepotTile(t)) {
1756 t.m4() = (TileHeight(t) == 0 ? OWNER_WATER : OWNER_NONE).base();
1757 }
1758 }
1759 }
1760
1762 for (Station *st : Station::Iterate()) {
1763 for (GoodsEntry &ge : st->goods) {
1764 ge.last_speed = 0;
1766 }
1767 }
1768 }
1769
1770 /* At version 78, industry cargo types can be changed, and are stored with the industry. For older save versions
1771 * copy the IndustrySpec's cargo types over to the Industry. */
1773 for (Industry *i : Industry::Iterate()) {
1774 const IndustrySpec *indsp = GetIndustrySpec(i->type);
1775 for (uint j = 0; j < std::size(i->produced); j++) {
1776 i->produced[j].cargo = indsp->produced_cargo[j];
1777 }
1778 for (uint j = 0; j < std::size(i->accepted); j++) {
1779 i->accepted[j].cargo = indsp->accepts_cargo[j];
1780 }
1781 }
1782 }
1783
1784 /* Industry cargo slots were fixed size before (and including) SaveLoadVersion::VehicleEconomyAge (either 2/3 or 16/16),
1785 * after this they are dynamic. Trim excess slots. */
1787 for (Industry *i : Industry::Iterate()) {
1789 }
1790 }
1791
1792 /* Before version 81, the density of grass was always stored as zero, and
1793 * grassy trees were always drawn fully grassy. Furthermore, trees on rough
1794 * land used to have zero density, now they have full density. Therefore,
1795 * make all grassy/rough land trees have a density of 3. */
1797 for (auto t : Map::Iterate()) {
1798 if (GetTileType(t) == TileType::Trees) {
1799 TreeGround ground_type = (TreeGround)GB(t.m2(), 4, 2);
1800 if (ground_type != TreeGround::SnowOrDesert) SB(t.m2(), 6, 2, 3);
1801 }
1802 }
1803 }
1804
1805
1807 /* Rework of orders. */
1808 for (OrderList *orderlist : OrderList::Iterate()) {
1809 for (Order &o : orderlist->GetOrders()) {
1810 o.ConvertFromOldSavegame();
1811 }
1812 }
1813
1814 for (Vehicle *v : Vehicle::Iterate()) {
1815 if (v->orders != nullptr && v->GetFirstOrder() != nullptr && v->GetFirstOrder()->IsType(OT_NOTHING)) {
1816 v->orders->FreeChain();
1817 v->orders = nullptr;
1818 }
1819
1820 v->current_order.ConvertFromOldSavegame();
1821 if (v->type == VehicleType::Road && v->IsPrimaryVehicle() && v->FirstShared() == v) {
1822 for (Order &order : v->Orders()) order.SetNonStopType(OrderNonStopFlag::NonStop);
1823 }
1824 }
1826 /* Unload and transfer are now mutual exclusive. */
1827 for (OrderList *orderlist : OrderList::Iterate()) {
1828 for (Order &order : orderlist->GetOrders()) {
1829 if (order.GetUnloadType() == OrderUnloadType{3}) { // 3 used to mean transfer and don't load.
1830 order.SetUnloadType(OrderUnloadType::Transfer);
1831 order.SetLoadType(OrderLoadType::NoLoad);
1832 }
1833 }
1834 }
1835
1836 for (Vehicle *v : Vehicle::Iterate()) {
1837 if (v->current_order.GetUnloadType() == OrderUnloadType{3}) { // 3 used to mean transfer and don't load.
1838 v->current_order.SetUnloadType(OrderUnloadType::Transfer);
1839 v->current_order.SetLoadType(OrderLoadType::NoLoad);
1840 }
1841 }
1843 /* OrderDepotActionFlags were moved, instead of starting at bit 4 they now start at bit 3. */
1844 for (OrderList *orderlist : OrderList::Iterate()) {
1845 for (Order &order : orderlist->GetOrders()) {
1846 if (!order.IsType(OT_GOTO_DEPOT)) continue;
1847 order.SetDepotActionType(static_cast<OrderDepotActionFlags>(order.GetDepotActionType().base() >> 1));
1848 }
1849 }
1850
1851 for (Vehicle *v : Vehicle::Iterate()) {
1852 if (!v->current_order.IsType(OT_GOTO_DEPOT)) continue;
1853 v->current_order.SetDepotActionType(static_cast<OrderDepotActionFlags>(v->current_order.GetDepotActionType().base() >> 1));
1854 }
1855 }
1856
1857 /* The water class was moved/unified. */
1859 for (auto t : Map::Iterate()) {
1860 switch (GetTileType(t)) {
1861 case TileType::Station:
1862 switch (GetStationType(t)) {
1864 case StationType::Dock:
1865 case StationType::Buoy:
1866 SetWaterClass(t, (WaterClass)GB(t.m3(), 0, 2));
1867 SB(t.m3(), 0, 2, 0);
1868 break;
1869
1870 default:
1872 break;
1873 }
1874 break;
1875
1876 case TileType::Water:
1877 SetWaterClass(t, (WaterClass)GB(t.m3(), 0, 2));
1878 SB(t.m3(), 0, 2, 0);
1879 break;
1880
1881 case TileType::Object:
1883 break;
1884
1885 default:
1886 /* No water class. */
1887 break;
1888 }
1889 }
1890 }
1891
1893 for (auto t : Map::Iterate()) {
1894 /* Move river flag and update canals to use water class */
1895 if (IsTileType(t, TileType::Water)) {
1896 if (GetWaterClass(t) != WaterClass::River) {
1897 if (IsWater(t)) {
1898 Owner o = GetTileOwner(t);
1899 if (o == OWNER_WATER) {
1900 MakeSea(t);
1901 } else {
1902 MakeCanal(t, o, Random());
1903 }
1904 } else if (IsShipDepot(t)) {
1905 Owner o = (Owner)t.m4(); // Original water owner
1907 }
1908 }
1909 }
1910 }
1911
1912 /* Update locks, depots, docks and buoys to have a water class based
1913 * on its neighbouring tiles. Done after river and canal updates to
1914 * ensure neighbours are correct. */
1915 for (const auto t : Map::Iterate()) {
1916 if (!IsTileFlat(t)) continue;
1917
1920 }
1921 }
1922
1924 for (const auto t : Map::Iterate()) {
1925 /* skip oil rigs at borders! */
1926 if ((IsTileType(t, TileType::Water) || IsBuoyTile(t)) &&
1927 (TileX(t) == 0 || TileY(t) == 0 || TileX(t) == Map::MaxX() - 1 || TileY(t) == Map::MaxY() - 1)) {
1928 /* Some version 86 savegames have wrong water class at map borders (under buoy, or after removing buoy).
1929 * This conversion has to be done before buoys with invalid owner are removed. */
1931 }
1932
1934 Owner o = GetTileOwner(t);
1935 if (o < MAX_COMPANIES && !Company::IsValidID(o)) {
1936 AutoRestoreBackup cur_company(_current_company, o);
1938 }
1939 if (IsBuoyTile(t)) {
1940 /* reset buoy owner to OWNER_NONE in the station struct
1941 * (even if it is owned by active company) */
1943 }
1944 } else if (IsTileType(t, TileType::Road)) {
1945 /* works for all RoadTileType */
1946 for (RoadTramType rtt : ROADTRAMTYPES_ALL) {
1947 /* update even non-existing road types to update tile owner too */
1948 Owner o = GetRoadOwner(t, rtt);
1949 if (o < MAX_COMPANIES && !Company::IsValidID(o)) SetRoadOwner(t, rtt, OWNER_NONE);
1950 }
1951 if (IsLevelCrossing(t)) {
1953 }
1954 } else if (IsPlainRailTile(t)) {
1956 }
1957 }
1958 }
1959
1961 /* Profits are now with 8 bit fract */
1962 for (Vehicle *v : Vehicle::Iterate()) {
1963 v->profit_this_year <<= 8;
1964 v->profit_last_year <<= 8;
1965 v->running_ticks = 0;
1966 }
1967 }
1968
1970 /* Increase HouseAnimationFrame from 5 to 7 bits */
1971 for (auto t : Map::Iterate()) {
1973 SB(t.m6(), 2, 6, GB(t.m6(), 3, 5));
1974 SB(t.m3(), 5, 1, 0);
1975 }
1976 }
1977 }
1978
1980 GroupStatistics::UpdateAfterLoad(); // Ensure statistics pool is initialised before trying to delete vehicles
1981 /* Remove all trams from savegames without tram support.
1982 * There would be trams without tram track under causing crashes sooner or later. */
1983 for (RoadVehicle *v : RoadVehicle::Iterate()) {
1984 if (v->First() == v && EngInfo(v->engine_type)->misc_flags.Test(EngineMiscFlag::RoadIsTram)) {
1985 ShowErrorMessage(GetEncodedString(STR_WARNING_LOADGAME_REMOVED_TRAMS), {}, WarningLevel::Critical);
1986 delete v;
1987 }
1988 }
1989 }
1990
1992 for (auto t : Map::Iterate()) {
1993 /* Set newly introduced WaterClass of industry tiles */
1994 if (IsTileType(t, TileType::Station) && IsOilRig(t)) {
1996 }
2000 } else {
2002 }
2003 }
2004
2005 /* Replace "house construction year" with "house age" */
2008 }
2009 }
2010 }
2011
2012 /* Move the signal variant back up one bit for PBS. We don't convert the old PBS
2013 * format here, as an old layout wouldn't work properly anyway. To be safe, we
2014 * clear any possible PBS reservations as well. */
2016 for (auto t : Map::Iterate()) {
2017 switch (GetTileType(t)) {
2018 case TileType::Railway:
2019 if (HasSignals(t)) {
2020 /* move the signal variant */
2023 ClrBit(t.m2(), 2);
2024 ClrBit(t.m2(), 6);
2025 }
2026
2027 /* Clear PBS reservation on track */
2028 if (IsRailDepot(t)) {
2029 SetDepotReservation(t, false);
2030 } else {
2031 SetTrackReservation(t, {});
2032 }
2033 break;
2034
2035 case TileType::Road: // Clear PBS reservation on crossing
2036 if (IsLevelCrossing(t)) SetCrossingReservation(t, false);
2037 break;
2038
2039 case TileType::Station: // Clear PBS reservation on station
2040 if (HasStationRail(t)) SetRailStationReservation(t, false);
2041 break;
2042
2043 case TileType::TunnelBridge: // Clear PBS reservation on tunnels/bridges
2045 break;
2046
2047 default: break;
2048 }
2049 }
2050 }
2051
2052 /* Reserve all tracks trains are currently on. */
2054 for (const Train *t : Train::Iterate()) {
2055 if (t->First() == t) t->ReserveTrackUnderConsist();
2056 }
2057 }
2058
2060 /* Non-town-owned roads now store the closest town */
2062
2063 /* signs with invalid owner left from older savegames */
2064 for (Sign *si : Sign::Iterate()) {
2065 if (si->owner != OWNER_NONE && !Company::IsValidID(si->owner)) si->owner = OWNER_NONE;
2066 }
2067
2068 /* Station can get named based on an industry type, but the current ones
2069 * are not, so mark them as if they are not named by an industry. */
2070 for (Station *st : Station::Iterate()) {
2071 st->indtype = IT_INVALID;
2072 }
2073 }
2074
2076 for (Aircraft *a : Aircraft::Iterate()) {
2077 /* Set engine_type of shadow and rotor */
2078 if (!a->IsNormalAircraft()) {
2079 a->engine_type = a->First()->engine_type;
2080 }
2081 }
2082
2083 /* More companies ... */
2084 for (Company *c : Company::Iterate()) {
2085 if (c->bankrupt_asked.base() == 0xFF) c->bankrupt_asked.Set();
2086 }
2087
2088 for (Engine *e : Engine::Iterate()) {
2089 if (e->company_avail.base() == 0xFF) e->company_avail.Set();
2090 }
2091
2092 for (Town *t : Town::Iterate()) {
2093 if (t->have_ratings.base() == 0xFF) t->have_ratings.Set();
2094 t->ratings.fill(RATING_INITIAL);
2095 }
2096 }
2097
2099 for (auto t : Map::Iterate()) {
2100 /* Check for HQ bit being set, instead of using map accessor,
2101 * since we've already changed it code-wise */
2102 if (IsTileType(t, TileType::Object) && HasBit(t.m5(), 7)) {
2103 /* Move size and part identification of HQ out of the m5 attribute,
2104 * on new locations */
2105 t.m3() = GB(t.m5(), 0, 5);
2106 t.m5() = OBJECT_HQ;
2107 }
2108 }
2109 }
2111 for (auto t : Map::Iterate()) {
2112 if (!IsTileType(t, TileType::Object)) continue;
2113
2114 /* Reordering/generalisation of the object bits. */
2115 ObjectType type = t.m5();
2116 SB(t.m6(), 2, 4, type == OBJECT_HQ ? GB(t.m3(), 2, 3) : 0);
2117 t.m3() = type == OBJECT_HQ ? GB(t.m3(), 1, 1) | GB(t.m3(), 0, 1) << 4 : 0;
2118
2119 /* Make sure those bits are clear as well! */
2120 t.m4() = 0;
2121 t.m7() = 0;
2122 }
2123 }
2124
2126 /* Make real objects for object tiles. */
2127 for (auto t : Map::Iterate()) {
2128 if (!IsTileType(t, TileType::Object)) continue;
2129
2130 if (Town::GetNumItems() == 0) {
2131 /* No towns, so remove all objects! */
2132 DoClearSquare(t);
2133 } else {
2134 uint offset = t.m3();
2135
2136 /* Also move the animation state. */
2137 t.m3() = GB(t.m6(), 2, 4);
2138 SB(t.m6(), 2, 4, 0);
2139
2140 if (offset == 0) {
2141 /* No offset, so make the object. */
2142 ObjectType type = t.m5();
2143 int size = type == OBJECT_HQ ? 2 : 1;
2144
2145 if (!Object::CanAllocateItem()) {
2146 /* Nice... you managed to place 64k lighthouses and
2147 * antennae on the map... boohoo. */
2148 SlError(STR_ERROR_TOO_MANY_OBJECTS);
2149 }
2150
2151 Object *o = Object::Create();
2152 o->location.tile = (TileIndex)t;
2153 o->location.w = size;
2154 o->location.h = size;
2156 o->town = type == OBJECT_STATUE ? Town::Get(t.m2()) : CalcClosestTownFromTile(t, UINT_MAX);
2157 t.m2() = o->index.base();
2158 } else {
2159 /* We're at an offset, so get the ID from our "root". */
2160 Tile northern_tile = t - TileXY(GB(offset, 0, 4), GB(offset, 4, 4));
2161 assert(IsTileType(northern_tile, TileType::Object));
2162 t.m2() = northern_tile.m2();
2163 }
2164 }
2165 }
2166 }
2167
2169 /* allow_town_roads is added, set it if town_layout wasn't TL_NO_ROADS */
2170 uint8_t old_town_layout = to_underlying(_settings_game.economy.town_layout);
2171 if (old_town_layout == 0) { // was TL_NO_ROADS
2172 _settings_game.economy.allow_town_roads = false;
2173 _settings_game.economy.town_layout = TownLayout::BetterRoads;
2174 } else {
2175 _settings_game.economy.allow_town_roads = true;
2176 _settings_game.economy.town_layout = static_cast<TownLayout>(old_town_layout - 1);
2177 }
2178
2179 /* Initialize layout of all towns. Older versions were using different
2180 * generator for random town layout, use it if needed. */
2181 for (Town *t : Town::Iterate()) {
2182 if (_settings_game.economy.town_layout != TownLayout::Random) {
2183 t->layout = _settings_game.economy.town_layout;
2184 continue;
2185 }
2186
2187 /* Use old layout randomizer code */
2188 uint8_t layout = TileHash(TileX(t->xy), TileY(t->xy)) % 6;
2189 switch (layout) {
2190 default: break;
2191 case 5: layout = 1; break;
2192 case 0: layout = 2; break;
2193 }
2194 t->layout = static_cast<TownLayout>(layout - 1);
2195 }
2196 }
2197
2199 /* There could be (deleted) stations with invalid owner, set owner to OWNER NONE.
2200 * The conversion affects oil rigs and buoys too, but it doesn't matter as
2201 * they have st->owner == OWNER_NONE already. */
2202 for (Station *st : Station::Iterate()) {
2203 if (!Company::IsValidID(st->owner)) st->owner = OWNER_NONE;
2204 }
2205 }
2206
2207 /* Trains could now stop in a specific location. */
2209 for (OrderList *orderlist : OrderList::Iterate()) {
2210 for (Order &o : orderlist->GetOrders()) {
2211 if (o.IsType(OT_GOTO_STATION)) o.SetStopLocation(OrderStopLocation::FarEnd);
2212 }
2213 }
2214 }
2215
2218 for (Company *c : Company::Iterate()) {
2219 c->settings.vehicle = _old_vds;
2220 }
2221 }
2222
2224 /* Tile for no orders is now INVALID_TILE instead of 0. */
2225 for (Vehicle *v : Vehicle::Iterate()) {
2226 if (v->dest_tile == 0) v->SetDestTile(INVALID_TILE);
2227 }
2228 }
2229
2231 /* Delete small ufos heading for non-existing vehicles */
2233 if (v->subtype == 2 /* ST_SMALL_UFO */ && v->state != 0) {
2234 const Vehicle *u = Vehicle::GetIfValid(v->dest_tile.base());
2235 if (u == nullptr || u->type != VehicleType::Road || !RoadVehicle::From(u)->IsFrontEngine()) {
2236 delete v;
2237 }
2238 }
2239 }
2240
2241 /* We didn't store cargo payment yet, so make them for vehicles that are
2242 * currently at a station and loading/unloading. If they don't get any
2243 * payment anymore they just removed in the next load/unload cycle.
2244 * However, some 0.7 versions might have cargo payment. For those we just
2245 * add cargopayment for the vehicles that don't have it.
2246 */
2247 for (Station *st : Station::Iterate()) {
2248 for (Vehicle *v : st->loading_vehicles) {
2249 /* There are always as many CargoPayments as Vehicles. We need to make the
2250 * assert() in Pool::GetNew() happy by calling CanAllocateItem(). */
2253 if (v->cargo_payment == nullptr) v->cargo_payment = CargoPayment::Create(v);
2254 }
2255 }
2256 }
2257
2259 /* Animated tiles would sometimes not be actually animated or
2260 * in case of old savegames duplicate. */
2261
2262 extern std::vector<TileIndex> _animated_tiles;
2263
2264 for (auto tile = _animated_tiles.begin(); tile < _animated_tiles.end(); /* Nothing */) {
2265 /* Remove if tile is not animated */
2266 bool remove = !MayAnimateTile(*tile);
2267
2268 /* and remove if duplicate */
2269 for (auto j = _animated_tiles.begin(); !remove && j < tile; j++) {
2270 remove = *tile == *j;
2271 }
2272
2273 if (remove) {
2274 tile = _animated_tiles.erase(tile);
2275 } else {
2276 tile++;
2277 }
2278 }
2279 }
2280
2282 for (auto t : Map::Iterate()) {
2283 if (!IsTileType(t, TileType::Water)) continue;
2284 SetNonFloodingWaterTile(t, false);
2285 }
2286 }
2287
2289 /* Animated tile state is stored in the map array, allowing
2290 * quicker addition and deletion of animated tiles. */
2291
2292 extern std::vector<TileIndex> _animated_tiles;
2293
2294 for (auto t : Map::Iterate()) {
2295 /* Ensure there is no spurious animated tile state. */
2297 }
2298
2299 /* Set animated flag for all valid animated tiles. */
2300 for (const TileIndex &tile : _animated_tiles) {
2302 }
2303 }
2304
2306 /* The train station tile area was added, but for really old (TTDPatch) it's already valid. */
2307 for (Waypoint *wp : Waypoint::Iterate()) {
2308 if (wp->facilities.Test(StationFacility::Train)) {
2309 wp->train_station.tile = wp->xy;
2310 wp->train_station.w = 1;
2311 wp->train_station.h = 1;
2312 } else {
2313 wp->train_station.tile = INVALID_TILE;
2314 wp->train_station.w = 0;
2315 wp->train_station.h = 0;
2316 }
2317 }
2318 }
2319
2321 /* Convert old subsidies */
2322 for (Subsidy *s : Subsidy::Iterate()) {
2323 if (s->remaining < 12) {
2324 /* Converting nonawarded subsidy */
2325 s->remaining = 12 - s->remaining; // convert "age" to "remaining"
2326 s->awarded = CompanyID::Invalid(); // not awarded to anyone
2327 const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
2328 switch (cs->town_acceptance_effect) {
2331 /* Town -> Town */
2332 s->src.type = s->dst.type = SourceType::Town;
2333 if (Town::IsValidID(s->src.ToTownID()) && Town::IsValidID(s->dst.ToTownID())) continue;
2334 break;
2337 /* Industry -> Town */
2338 s->src.type = SourceType::Industry;
2339 s->dst.type = SourceType::Town;
2340 if (Industry::IsValidID(s->src.ToIndustryID()) && Town::IsValidID(s->dst.ToTownID())) continue;
2341 break;
2342 default:
2343 /* Industry -> Industry */
2344 s->src.type = s->dst.type = SourceType::Industry;
2345 if (Industry::IsValidID(s->src.ToIndustryID()) && Industry::IsValidID(s->dst.ToIndustryID())) continue;
2346 break;
2347 }
2348 } else {
2349 /* Do our best for awarded subsidies. The original source or destination industry
2350 * can't be determined anymore for awarded subsidies, so invalidate them.
2351 * Town -> Town subsidies are converted using simple heuristic */
2352 s->remaining = 24 - s->remaining; // convert "age of awarded subsidy" to "remaining"
2353 const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
2354 switch (cs->town_acceptance_effect) {
2357 /* Town -> Town */
2358 const Station *ss = Station::GetIfValid(s->src.id);
2359 const Station *sd = Station::GetIfValid(s->dst.id);
2360 if (ss != nullptr && sd != nullptr && ss->owner == sd->owner &&
2362 s->src.type = s->dst.type = SourceType::Town;
2363 s->src.SetIndex(ss->town->index);
2364 s->dst.SetIndex(sd->town->index);
2365 s->awarded = ss->owner;
2366 continue;
2367 }
2368 break;
2369 }
2370 default:
2371 break;
2372 }
2373 }
2374 /* Awarded non-town subsidy or invalid source/destination, invalidate */
2375 delete s;
2376 }
2377 }
2378
2380 /* Recompute inflation based on old unround loan limit
2381 * Note: Max loan is 500000. With an inflation of 4% across 170 years
2382 * that results in a max loan of about 0.7 * 2^31.
2383 * So taking the 16 bit fractional part into account there are plenty of bits left
2384 * for unmodified savegames ...
2385 */
2386 uint64_t aimed_inflation = (_economy.old_max_loan_unround << 16 | _economy.old_max_loan_unround_fract) / _settings_game.difficulty.max_loan;
2387
2388 /* ... well, just clamp it then. */
2389 if (aimed_inflation > MAX_INFLATION) aimed_inflation = MAX_INFLATION;
2390
2391 /* Simulate the inflation, so we also get the payment inflation */
2392 while (_economy.inflation_prices < aimed_inflation) {
2393 if (AddInflation(false)) break;
2394 }
2395 }
2396
2398 for (const Depot *d : Depot::Iterate()) {
2399 Tile tile = d->xy;
2400 /* At some point, invalid depots were saved into the game (possibly those removed in the past?)
2401 * Remove them here, so they don't cause issues further down the line */
2402 if (!IsDepotTile(tile)) {
2403 Debug(Facility::Sl, Severity::Critical, "Removing invalid depot {} at {}, {}", d->index, TileX(d->xy), TileY(d->xy));
2404 delete d;
2405 d = nullptr;
2406 continue;
2407 }
2408 tile.m2() = d->index.base();
2409 if (IsTileType(tile, TileType::Water)) Tile(GetOtherShipDepotTile(tile)).m2() = d->index.base();
2410 }
2411 }
2412
2413 /* The behaviour of force_proceed has been changed. Now
2414 * it counts signals instead of some random time out. */
2416 for (Train *t : Train::Iterate()) {
2417 if (t->force_proceed != TFP_NONE) {
2418 t->force_proceed = TFP_STUCK;
2419 }
2420 }
2421 }
2422
2423 /* The bits for the tree ground and tree density have
2424 * been swapped (m2 bits 7..6 and 5..4. */
2426 for (auto t : Map::Iterate()) {
2427 if (IsTileType(t, TileType::Clear)) {
2428 if (GetClearGround(t) == ClearGround{4}) { // CLEAR_SNOW becomes ClearGround::Grass with IsSnowTile() set.
2430 SetBit(t.m3(), 4);
2431 } else {
2432 ClrBit(t.m3(), 4);
2433 }
2434 }
2435 if (IsTileType(t, TileType::Trees)) {
2436 uint density = GB(t.m2(), 6, 2);
2437 uint ground = GB(t.m2(), 4, 2);
2438 t.m2() = ground << 6 | density << 4;
2439 }
2440 }
2441 }
2442
2443 /* Wait counter and load/unload ticks got split. */
2445 for (Aircraft *a : Aircraft::Iterate()) {
2446 a->turn_counter = a->current_order.IsType(OT_LOADING) ? 0 : a->load_unload_ticks;
2447 }
2448
2449 for (Train *t : Train::Iterate()) {
2450 t->wait_counter = t->current_order.IsType(OT_LOADING) ? 0 : t->load_unload_ticks;
2451 }
2452 }
2453
2454 /* Airport tile animation uses animation frame instead of other graphics id */
2456 struct AirportTileConversion {
2457 uint8_t old_start;
2458 uint8_t num_frames;
2459 };
2460 static const AirportTileConversion atcs[] = {
2461 {31, 12}, // APT_RADAR_GRASS_FENCE_SW
2462 {50, 4}, // APT_GRASS_FENCE_NE_FLAG
2463 {62, 2}, // 1 unused tile
2464 {66, 12}, // APT_RADAR_FENCE_SW
2465 {78, 12}, // APT_RADAR_FENCE_NE
2466 {101, 10}, // 9 unused tiles
2467 {111, 8}, // 7 unused tiles
2468 {119, 15}, // 14 unused tiles (radar)
2469 {140, 4}, // APT_GRASS_FENCE_NE_FLAG_2
2470 };
2471 for (const auto t : Map::Iterate()) {
2472 if (IsAirportTile(t)) {
2473 StationGfx old_gfx = GetStationGfx(t);
2474 uint8_t offset = 0;
2475 for (const auto &atc : atcs) {
2476 if (old_gfx < atc.old_start) {
2477 SetStationGfx(t, old_gfx - offset);
2478 break;
2479 }
2480 if (old_gfx < atc.old_start + atc.num_frames) {
2481 SetAnimationFrame(t, old_gfx - atc.old_start);
2482 SetStationGfx(t, atc.old_start - offset);
2483 break;
2484 }
2485 offset += atc.num_frames - 1;
2486 }
2487 }
2488 }
2489 }
2490
2491 /* Oilrig was moved from id 15 to 9. */
2493 for (Station *st : Station::Iterate()) {
2494 if (!st->airport.IsEmpty() && st->airport.type == 15) {
2495 st->airport.type = AT_OILRIG;
2496 }
2497 }
2498 }
2499
2501 for (Station *st : Station::Iterate()) {
2502 if (!st->airport.IsEmpty()) {
2503 st->airport.w = st->airport.GetSpec()->size_x;
2504 st->airport.h = st->airport.GetSpec()->size_y;
2505 }
2506 }
2507 }
2508
2510 for (const auto t : Map::Iterate()) {
2511 /* Reset tropic zone for VOID tiles, they shall not have any. */
2513 }
2514
2515 /* We need to properly number/name the depots.
2516 * The first step is making sure none of the depots uses the
2517 * 'default' names, after that we can assign the names. */
2518 for (Depot *d : Depot::Iterate()) d->town_cn = UINT16_MAX;
2519
2520 for (Depot *d : Depot::Iterate()) MakeDefaultName(d);
2521 }
2522
2524 for (Depot *d : Depot::Iterate()) d->build_date = TimerGameCalendar::date;
2525 }
2526
2528 for (Station *st : Station::Iterate()) {
2529 if (st->facilities.Test(StationFacility::Airport)) st->airport.rotation = Direction::N;
2530 }
2531 }
2532
2533 /* In old versions it was possible to remove an airport while a plane was
2534 * taking off or landing. This gives all kind of problems when building
2535 * another airport in the same station so we don't allow that anymore.
2536 * For old savegames with such aircraft we just throw them in the air and
2537 * treat the aircraft like they were flying already. */
2539 for (Aircraft *v : Aircraft::Iterate()) {
2540 if (!v->IsNormalAircraft()) continue;
2542 if (st == nullptr && v->state != FLYING) {
2543 v->state = FLYING;
2546 /* get aircraft back on running altitude */
2547 if (!v->vehstatus.Test(VehState::Crashed)) {
2548 GetAircraftFlightLevelBounds(v, &v->z_pos, nullptr);
2549 SetAircraftPosition(v, v->x_pos, v->y_pos, GetAircraftFlightLevel(v));
2550 }
2551 }
2552 }
2553 }
2554
2555 /* Move the animation frame to the same location (m7) for all objects. */
2557 for (auto t : Map::Iterate()) {
2558 switch (GetTileType(t)) {
2559 case TileType::House:
2560 if (GetHouseType(t) >= NEW_HOUSE_OFFSET) {
2561 uint per_proc = t.m7();
2562 t.m7() = GB(t.m6(), 2, 6) | (GB(t.m3(), 5, 1) << 6);
2563 SB(t.m3(), 5, 1, 0);
2564 SB(t.m6(), 2, 6, std::min(per_proc, 63U));
2565 }
2566 break;
2567
2568 case TileType::Industry: {
2569 uint rand = t.m7();
2570 t.m7() = t.m3();
2571 t.m3() = rand;
2572 break;
2573 }
2574
2575 case TileType::Object:
2576 t.m7() = t.m3();
2577 t.m3() = 0;
2578 break;
2579
2580 default:
2581 /* For stations/airports it's already at m7 */
2582 break;
2583 }
2584 }
2585 }
2586
2587 /* Add (random) colour to all objects. */
2589 for (Object *o : Object::Iterate()) {
2590 Owner owner = GetTileOwner(o->location.tile);
2591 o->recolour_offset = (owner == OWNER_NONE) ? GB(Random(), 0, 4) : to_underlying(Company::Get(owner)->livery[LiveryScheme::Default].colour1);
2592 }
2593 }
2594
2596 for (const auto t : Map::Iterate()) {
2597 if (!IsTileType(t, TileType::Station)) continue;
2598 if (!IsBuoy(t) && !IsOilRig(t) && !(IsDock(t) && IsTileFlat(t))) {
2600 }
2601 }
2602
2603 /* Waypoints with custom name may have a non-unique town_cn,
2604 * renumber those. First set all affected waypoints to the
2605 * highest possible number to get them numbered in the
2606 * order they have in the pool. */
2607 for (Waypoint *wp : Waypoint::Iterate()) {
2608 if (!wp->name.empty()) wp->town_cn = UINT16_MAX;
2609 }
2610
2611 for (Waypoint *wp : Waypoint::Iterate()) {
2612 if (!wp->name.empty()) MakeDefaultName(wp);
2613 }
2614 }
2615
2617 _industry_builder.Reset(); // Initialize industry build data.
2618
2619 /* The moment vehicles go from hidden to visible changed. This means
2620 * that vehicles don't always get visible anymore causing things to
2621 * get messed up just after loading the savegame. This fixes that. */
2622 for (Vehicle *v : Vehicle::Iterate()) {
2623 /* Not all vehicle types can be inside a tunnel. Furthermore,
2624 * testing IsTunnelTile() for invalid tiles causes a crash. */
2625 if (!v->IsGroundVehicle()) continue;
2626
2627 /* Is the vehicle in a tunnel? */
2628 if (!IsTunnelTile(v->tile)) continue;
2629
2630 /* Is the vehicle actually at a tunnel entrance/exit? */
2631 TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos);
2632 if (!IsTunnelTile(vtile)) continue;
2633
2634 /* Are we actually in this tunnel? Or maybe a lower tunnel? */
2635 if (GetSlopePixelZ(v->x_pos, v->y_pos, true) != v->z_pos) continue;
2636
2637 /* What way are we going? */
2638 const DiagDirection dir = GetTunnelBridgeDirection(vtile);
2639 const DiagDirection vdir = DirToDiagDir(v->direction);
2640
2641 /* Have we passed the visibility "switch" state already? */
2642 uint8_t pos = (DiagDirToAxis(vdir) == Axis::X ? v->x_pos : v->y_pos) & TILE_UNIT_MASK;
2643 uint8_t frame = (vdir == DiagDirection::NE || vdir == DiagDirection::NW) ? TILE_SIZE - 1 - pos : pos;
2645
2646 /* Should the vehicle be hidden or not? */
2647 bool hidden;
2648 if (dir == vdir) { // Entering tunnel
2649 hidden = frame >= _tunnel_visibility_frame[dir];
2650 v->tile = vtile;
2651 } else if (dir == ReverseDiagDir(vdir)) { // Leaving tunnel
2652 hidden = frame < TILE_SIZE - _tunnel_visibility_frame[dir];
2653 /* v->tile changes at the moment when the vehicle leaves the tunnel. */
2654 v->tile = hidden ? GetOtherTunnelBridgeEnd(vtile) : vtile;
2655 } else {
2656 /* We could get here in two cases:
2657 * - for road vehicles, it is reversing at the end of the tunnel
2658 * - it is crashed in the tunnel entry (both train or RV destroyed by UFO)
2659 * Whatever case it is, do not change anything and use the old values.
2660 * Especially changing RV's state would break its reversing in the middle. */
2661 continue;
2662 }
2663
2664 if (hidden) {
2665 v->vehstatus.Set(VehState::Hidden);
2666
2667 switch (v->type) {
2670 default: NOT_REACHED();
2671 }
2672 } else {
2673 v->vehstatus.Reset(VehState::Hidden);
2674
2675 switch (v->type) {
2676 case VehicleType::Train: Train::From(v)->track = DiagDirToDiagTrack(vdir); break;
2678 default: NOT_REACHED();
2679 }
2680 }
2681 }
2682 }
2683
2685 for (RoadVehicle *rv : RoadVehicle::Iterate()) {
2686 if (rv->state == RVSB_IN_DEPOT || rv->state == RVSB_WORMHOLE) continue;
2687
2688 bool loading = rv->current_order.IsType(OT_LOADING) || rv->current_order.IsType(OT_LEAVESTATION);
2689 if (HasBit(rv->state, RVS_IN_ROAD_STOP)) {
2690 extern const uint8_t _road_stop_stop_frame[];
2691 SB(rv->state, RVS_ENTERED_STOP, 1, loading || rv->frame > _road_stop_stop_frame[rv->state - RVSB_IN_ROAD_STOP + (to_underlying(_settings_game.vehicle.road_side) << RVS_DRIVE_SIDE)]);
2692 } else if (HasBit(rv->state, RVS_IN_DT_ROAD_STOP)) {
2693 SB(rv->state, RVS_ENTERED_STOP, 1, loading || rv->frame > RVC_DRIVE_THROUGH_STOP_FRAME);
2694 }
2695 }
2696 }
2697
2699 /* The train's pathfinder lost flag got moved. */
2700 for (Train *t : Train::Iterate()) {
2701 if (!t->flags.Test(VehicleRailFlag{5})) continue;
2702
2703 t->flags.Reset(VehicleRailFlag{5});
2704 t->vehicle_flags.Set(VehicleFlag::PathfinderLost);
2705 }
2706
2707 /* Introduced terraform/clear limits. */
2708 for (Company *c : Company::Iterate()) {
2709 c->terraform_limit = _settings_game.construction.terraform_frame_burst << 16;
2710 c->clear_limit = _settings_game.construction.clear_frame_burst << 16;
2711 }
2712 }
2713
2714
2716 /*
2717 * The logic of GetPartialPixelZ has been changed, so the resulting Zs on
2718 * the map are consistent. This requires that the Z position of some
2719 * vehicles is updated to reflect this new situation.
2720 *
2721 * This needs to be before SaveLoadVersion::TrackRealAndAutoOrders, because that performs asserts using
2722 * GetSlopePixelZ which internally uses GetPartialPixelZ.
2723 */
2724 for (Vehicle *v : Vehicle::Iterate()) {
2725 if (v->IsGroundVehicle() && TileVirtXY(v->x_pos, v->y_pos) == v->tile) {
2726 /* Vehicle is on the ground, and not in a wormhole. */
2727 v->z_pos = GetSlopePixelZ(v->x_pos, v->y_pos, true);
2728 }
2729 }
2730 }
2731
2733 for (Vehicle *v : Vehicle::Iterate()) {
2734 switch (v->type) {
2735 case VehicleType::Train: {
2736 Train *t = Train::From(v);
2737
2738 /* Clear old GOINGUP / GOINGDOWN flags.
2739 * It was changed in savegame version 139, but savegame
2740 * version 158 doesn't use these bits, so it doesn't hurt
2741 * to clear them unconditionally. */
2744
2745 /* Clear both bits first. */
2747
2748 /* Crashed vehicles can't be going up/down. */
2749 if (t->vehstatus.Test(VehState::Crashed)) break;
2750
2751 /* Only X/Y tracks can be sloped. */
2752 if (t->track != Track::X && t->track != Track::Y) break;
2753
2755 break;
2756 }
2757 case VehicleType::Road: {
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, TransportType::Road, GetRoadTramType(rv->roadtype));
2768
2769 /* Only X/Y tracks can be sloped. */
2770 if (trackbits != Track::X && trackbits != Track::Y) break;
2771
2772 Direction dir = rv->direction;
2773
2774 /* Test if we are reversing. */
2775 Axis a = trackbits == Track::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 = Direction::Invalid;
2781 }
2782
2783 rv->gv_flags |= FixVehicleInclination(rv, dir);
2784 break;
2785 }
2786 case VehicleType::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);
2799 if (v->type == VehicleType::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::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. */
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
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(SaveLoadVersion::Yapp) || (_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
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 > IndustryDensity::FundedOnly) {
2844 _settings_game.difficulty.industry_density = static_cast<IndustryDensity>(to_underlying(_settings_game.difficulty.industry_density) + 1);
2845 }
2846 }
2847
2849 /* Before savegame version 161, persistent storages were not stored in a pool. */
2850
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
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. */
2900 _settings_game.game_creation.snow_line_height /= TILE_HEIGHT;
2901 }
2902
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, TileType::Clear) && !IsTileType(t, TileType::Trees)) continue;
2908 uint fence = GB(t.m4(), 5, 3);
2909 if (fence != 0 && IsTileType(TileAddXY(t, 1, 0), TileType::Clear) && IsClearGround(TileAddXY(t, 1, 0), ClearGround::Fields)) {
2910 SetFence(TileAddXY(t, 1, 0), DiagDirection::NE, fence);
2911 }
2912 fence = GB(t.m4(), 2, 3);
2913 if (fence != 0 && IsTileType(TileAddXY(t, 0, 1), TileType::Clear) && IsClearGround(TileAddXY(t, 0, 1), ClearGround::Fields)) {
2914 SetFence(TileAddXY(t, 0, 1), DiagDirection::NW, fence);
2915 }
2916 SB(t.m4(), 2, 3, 0);
2917 SB(t.m4(), 5, 3, 0);
2918 }
2919 }
2920
2922 /* Vehicles used to be reversed immediately when entering depot.
2923 * Now they are reversed when the whole consist has entered.
2924 * Find trains in the process of entering a depot and un-reverse them. */
2925 for (Train *t : Train::Iterate()) {
2926 if (!t->IsPrimaryVehicle()) continue;
2927
2928 /* Front not in depot -> consist not entering depot */
2929 if (t->track != Track::Depot) continue;
2930 /* Back in depot -> consist completely in depot */
2931 if (t->Last()->track == Track::Depot) continue;
2932 for (Train *u = t; u->track == Track::Depot; u = u->Next()) {
2933 u->direction = ReverseDir(u->direction);
2934 }
2935 }
2936
2937 /* Update the setting for train flipping. */
2938 _settings_game.difficulty.train_flip_reverse_allowed = _settings_game.difficulty.line_reverse_mode ? TrainFlipReversingAllowed::EndOfLineOnly : TrainFlipReversingAllowed::All;
2939 }
2940
2942 for (Town *t : Town::Iterate()) {
2943 /* Set the default cargo requirement for town growth */
2944 switch (_settings_game.game_creation.landscape) {
2947 break;
2948
2952 break;
2953
2954 default:
2955 break;
2956 }
2957 }
2958 }
2959
2961 /* Adjust zoom level to account for new levels */
2962 _saved_scrollpos_zoom += ZOOM_BASE_SHIFT;
2963 _saved_scrollpos_x *= ZOOM_BASE;
2964 _saved_scrollpos_y *= ZOOM_BASE;
2965 }
2966
2967 /* When any NewGRF has been changed the availability of some vehicles might
2968 * have been changed too. e->company_avail must be set to 0 in that case
2969 * which is done by StartupEngines(). */
2971
2972 /* The road owner of standard road stops was not properly accounted for. */
2974 for (const auto t : Map::Iterate()) {
2975 if (!IsBayRoadStopTile(t)) continue;
2976 Owner o = GetTileOwner(t);
2979 }
2980 }
2981
2983 /* Introduced tree planting limit. */
2984 for (Company *c : Company::Iterate()) c->tree_limit = _settings_game.construction.tree_frame_burst << 16;
2985 }
2986
2988 /* Fix too high inflation rates */
2989 if (_economy.inflation_prices > MAX_INFLATION) _economy.inflation_prices = MAX_INFLATION;
2990 if (_economy.inflation_payment > MAX_INFLATION) _economy.inflation_payment = MAX_INFLATION;
2991
2992 /* We have to convert the quarters of bankruptcy into months of bankruptcy */
2993 for (Company *c : Company::Iterate()) {
2994 c->months_of_bankruptcy = 3 * c->months_of_bankruptcy;
2995 }
2996 }
2997
2999 /* Aircraft acceleration variable was bonkers */
3000 for (Aircraft *v : Aircraft::Iterate()) {
3001 if (v->subtype <= AIR_AIRCRAFT) {
3002 const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
3003 v->acceleration = avi->acceleration;
3004 }
3005 }
3006
3007 /* Blocked tiles could be reserved due to a bug, which causes
3008 * other places to assert upon e.g. station reconstruction. */
3009 for (const auto t : Map::Iterate()) {
3011 SetRailStationReservation(t, false);
3012 }
3013 }
3014 }
3015
3017 /* The global units configuration is split up in multiple configurations. */
3018 extern uint8_t _old_units;
3019 _settings_game.locale.units_velocity = Clamp(_old_units, 0, 2);
3020 _settings_game.locale.units_power = Clamp(_old_units, 0, 2);
3021 _settings_game.locale.units_weight = Clamp(_old_units, 1, 2);
3022 _settings_game.locale.units_volume = Clamp(_old_units, 1, 2);
3023 _settings_game.locale.units_force = 2;
3024 _settings_game.locale.units_height = Clamp(_old_units, 0, 2);
3025 }
3026
3028 /* Match nautical velocity with land velocity units. */
3029 _settings_game.locale.units_velocity_nautical = _settings_game.locale.units_velocity;
3030 }
3031
3033 /* Move ObjectType from map to pool */
3034 for (auto t : Map::Iterate()) {
3035 if (IsTileType(t, TileType::Object)) {
3036 Object *o = Object::Get(t.m2());
3037 o->type = t.m5();
3038 t.m5() = 0; // zero upper bits of (now bigger) ObjectID
3039 }
3040 }
3041 }
3042
3043 /* Beyond this point, tile types which can be accessed by vehicles must be in a valid state. */
3044
3045 /* Update all vehicles: Phase 2 */
3047
3048 /* The center of train vehicles was changed, fix up spacing. */
3050
3051 /* In version 2.2 of the savegame, we have new airports, so status of all aircraft is reset.
3052 * This has to be called after all map array updates */
3054
3056 /* Fix articulated road vehicles.
3057 * Some curves were shorter than other curves.
3058 * Now they have the same length, but that means that trailing articulated parts will
3059 * take longer to go through the curve than the parts in front which already left the curve.
3060 * So, make articulated parts catch up. */
3061 bool roadside = _settings_game.vehicle.road_side == RoadVehicleDrivingSide::Right;
3062 std::vector<uint> skip_frames;
3063 for (RoadVehicle *v : RoadVehicle::Iterate()) {
3064 if (!v->IsFrontEngine()) continue;
3065 skip_frames.clear();
3066 TileIndex prev_tile = v->tile;
3067 uint prev_tile_skip = 0;
3068 uint cur_skip = 0;
3069 for (RoadVehicle *u = v; u != nullptr; u = u->Next()) {
3070 if (u->tile != prev_tile) {
3071 prev_tile_skip = cur_skip;
3072 prev_tile = u->tile;
3073 } else {
3074 cur_skip = prev_tile_skip;
3075 }
3076
3077 uint &this_skip = skip_frames.emplace_back(prev_tile_skip);
3078
3079 /* The following 3 curves now take longer than before */
3080 switch (u->state) {
3081 case 2:
3082 cur_skip++;
3083 if (u->frame <= (roadside ? 9 : 5)) this_skip = cur_skip;
3084 break;
3085
3086 case 4:
3087 cur_skip++;
3088 if (u->frame <= (roadside ? 5 : 9)) this_skip = cur_skip;
3089 break;
3090
3091 case 5:
3092 cur_skip++;
3093 if (u->frame <= (roadside ? 4 : 2)) this_skip = cur_skip;
3094 break;
3095
3096 default:
3097 break;
3098 }
3099 }
3100 while (cur_skip > skip_frames[0]) {
3101 RoadVehicle *u = v;
3102 RoadVehicle *prev = nullptr;
3103 for (uint sf : skip_frames) {
3104 if (sf >= cur_skip) IndividualRoadVehicleController(u, prev);
3105
3106 prev = u;
3107 u = u->Next();
3108 }
3109 cur_skip--;
3110 }
3111 }
3112 }
3113
3115 for (OrderList *orderlist : OrderList::Iterate()) {
3116 for (Order &order : orderlist->GetOrders()) {
3117 order.SetTravelTimetabled(order.GetTravelTime() > 0);
3118 order.SetWaitTimetabled(order.GetWaitTime() > 0);
3119 }
3120 orderlist->RecalculateTimetableDuration();
3121 }
3122 }
3123
3124 /*
3125 * Only keep order-backups for network clients (and when replaying).
3126 * If we are a network server or not networking, then we just loaded a previously
3127 * saved-by-server savegame. There are no clients with a backup, so clear it.
3128 * Furthermore before savegame version SaveLoadVersion::FixOrderBackup the actual content was always corrupt.
3129 */
3131#ifndef DEBUG_DUMP_COMMANDS
3132 /* Note: We cannot use CleanPool since that skips part of the destructor
3133 * and then leaks un-reachable Orders in the order pool. */
3134 for (OrderBackup *ob : OrderBackup::Iterate()) {
3135 delete ob;
3136 }
3137#endif
3138 }
3139
3141 /* Convert towns growth_rate and grow_counter to ticks */
3142 for (Town *t : Town::Iterate()) {
3143 /* 0x8000 = TOWN_GROWTH_RATE_CUSTOM previously */
3144 if (t->growth_rate & 0x8000) t->flags.Set(TownFlag::CustomGrowth);
3145 if (t->growth_rate != TOWN_GROWTH_RATE_NONE) {
3146 t->growth_rate = TownTicksToGameTicks(t->growth_rate & ~0x8000);
3147 }
3148 /* Add t->index % TOWN_GROWTH_TICKS to spread growth across ticks. */
3149 t->grow_counter = TownTicksToGameTicks(t->grow_counter) + t->index % Ticks::TOWN_GROWTH_TICKS;
3150 }
3151 }
3152
3154 /* Make sure added industry cargo slots are cleared */
3155 for (Industry *i : Industry::Iterate()) {
3156 /* Make sure last_cargo_accepted_at is copied to elements for every valid input cargo.
3157 * The loading routine should put the original singular value into the first array element. */
3158 for (auto &a : i->accepted) {
3159 if (IsValidCargoType(a.cargo)) {
3160 a.last_accepted = i->GetAccepted(0).last_accepted;
3161 } else {
3162 a.last_accepted = EconomyTime::MIN_DATE;
3163 }
3164 }
3165 }
3166 }
3167
3169 /* Move ships from lock slope to upper or lower position. */
3170 for (Ship *s : Ship::Iterate()) {
3171 /* Suitable tile? */
3172 if (!IsTileType(s->tile, TileType::Water) || !IsLock(s->tile) || GetLockPart(s->tile) != LockPart::Middle) continue;
3173
3174 /* We don't need to adjust position when at the tile centre */
3175 int x = s->x_pos & 0xF;
3176 int y = s->y_pos & 0xF;
3177 if (x == 8 && y == 8) continue;
3178
3179 /* Test if ship is on the second half of the tile */
3180 bool second_half;
3181 DiagDirection shipdiagdir = DirToDiagDir(s->direction);
3182 switch (shipdiagdir) {
3183 default: NOT_REACHED();
3184 case DiagDirection::NE: second_half = x < 8; break;
3185 case DiagDirection::NW: second_half = y < 8; break;
3186 case DiagDirection::SW: second_half = x > 8; break;
3187 case DiagDirection::SE: second_half = y > 8; break;
3188 }
3189
3190 DiagDirection slopediagdir = GetInclinedSlopeDirection(GetTileSlope(s->tile));
3191
3192 /* Heading up slope == passed half way */
3193 if ((shipdiagdir == slopediagdir) == second_half) {
3194 /* On top half of lock */
3195 s->z_pos = GetTileMaxZ(s->tile) * (int)TILE_HEIGHT;
3196 } else {
3197 /* On lower half of lock */
3198 s->z_pos = GetTileZ(s->tile) * (int)TILE_HEIGHT;
3199 }
3200 }
3201 }
3202
3204 /* Ensure the original cargo generation mode is used */
3205 _settings_game.economy.town_cargogen_mode = TownCargoGenMode::Original;
3206 }
3207
3209 /* Ensure the original neutral industry/station behaviour is used */
3210 _settings_game.station.serve_neutral_industries = true;
3211
3212 /* Link oil rigs to their industry and back. */
3213 for (Station *st : Station::Iterate()) {
3214 if (IsTileType(st->xy, TileType::Station) && IsOilRig(st->xy)) {
3215 /* Industry tile is always adjacent during construction by TileDiffXY(0, 1) */
3216 st->industry = Industry::GetByTile(st->xy + TileDiffXY(0, 1));
3217 st->industry->neutral_station = st;
3218 }
3219 }
3220 } else {
3221 /* Link neutral station back to industry, as this is not saved. */
3222 for (Industry *ind : Industry::Iterate()) if (ind->neutral_station != nullptr) ind->neutral_station->industry = ind;
3223 }
3224
3226 /* Update water class for trees. */
3227 for (const auto t : Map::Iterate()) {
3229 }
3230 }
3231
3232 /* Update structures for multitile docks */
3234 for (const auto t : Map::Iterate()) {
3235 /* Clear docking tile flag from relevant tiles as it
3236 * was not previously cleared. */
3238 SetDockingTile(t, false);
3239 }
3240 /* Add docks and oilrigs to Station::ship_station. */
3241 if (IsTileType(t, TileType::Station)) {
3242 if (IsDock(t) || IsOilRig(t)) Station::GetByTile(t)->ship_station.Add(t);
3243 }
3244 }
3245 }
3246
3248 /* Placing objects on docking tiles was not updating adjacent station's docking tiles. */
3249 for (Station *st : Station::Iterate()) {
3250 if (!st->ship_station.IsEmpty()) UpdateStationDockingTiles(st);
3251 }
3252 }
3253
3254 /* Make sure all industries exclusive supplier/consumer set correctly. */
3256 for (Industry *i : Industry::Iterate()) {
3257 i->exclusive_supplier = INVALID_OWNER;
3258 i->exclusive_consumer = INVALID_OWNER;
3259 }
3260 }
3261
3263 /* Propagate wagon removal flag for compatibility */
3264 /* Temporary bitmask of company wagon removal setting */
3265 CompanyMask wagon_removal{};
3266 for (const Company *c : Company::Iterate()) {
3267 if (c->settings.renew_keep_length) wagon_removal.Set(c->index);
3268 }
3269 for (Group *g : Group::Iterate()) {
3270 if (g->flags.Any()) {
3271 /* Convert old replace_protection value to flag. */
3273 }
3274 if (wagon_removal.Test(g->owner)) g->flags.Set(GroupFlag::ReplaceWagonRemoval);
3275 }
3276 }
3277
3278 /* Use current order time to approximate last loading time */
3280 for (Vehicle *v : Vehicle::Iterate()) {
3281 v->last_loading_tick = std::max(TimerGameTick::counter, static_cast<uint64_t>(v->current_order_time)) - v->current_order_time;
3282 }
3283 }
3284
3285 /* Road stops is 'only' updating some caches, but they are needed for PF calls in SaveLoadVersion::MultitrackLevelCrossings teleporting. */
3287
3288 /* Road vehicles stopped on multitrack level crossings need teleporting to a depot
3289 * to avoid crashing into the side of the train they're waiting for. */
3291 /* Teleport road vehicles to the nearest depot. */
3292 for (RoadVehicle *rv : RoadVehicle::Iterate()) {
3293 /* Ignore trailers of articulated vehicles. */
3294 if (rv->IsArticulatedPart()) continue;
3295
3296 /* Ignore moving vehicles. */
3297 if (rv->cur_speed > 0) continue;
3298
3299 /* Ignore crashed vehicles. */
3300 if (rv->vehstatus.Test(VehState::Crashed)) continue;
3301
3302 /* Ignore vehicles not on level crossings. */
3303 TileIndex cur_tile = rv->tile;
3304 if (!IsLevelCrossingTile(cur_tile)) continue;
3305
3306 ClosestDepot closest_depot = rv->FindClosestDepot();
3307
3308 /* Try to find a depot with a distance limit of 512 tiles (Manhattan distance). */
3309 if (closest_depot.found && DistanceManhattan(rv->tile, closest_depot.location) < 512u) {
3310 /* Teleport all parts of articulated vehicles. */
3311 for (RoadVehicle *u = rv; u != nullptr; u = u->Next()) {
3312 u->tile = closest_depot.location;
3313 int x = TileX(closest_depot.location) * TILE_SIZE + TILE_SIZE / 2;
3314 int y = TileY(closest_depot.location) * TILE_SIZE + TILE_SIZE / 2;
3315 u->x_pos = x;
3316 u->y_pos = y;
3317 u->z_pos = GetSlopePixelZ(x, y, true);
3318
3319 u->vehstatus.Set(VehState::Hidden);
3320 u->state = RVSB_IN_DEPOT;
3321 u->UpdatePosition();
3322 }
3323 RoadVehLeaveDepot(rv, false);
3324 }
3325 }
3326
3328 /* Reset unused tree counters to reduce the savegame size. */
3329 for (auto t : Map::Iterate()) {
3330 if (IsTileType(t, TileType::Trees)) {
3331 SB(t.m2(), 0, 4, 0);
3332 }
3333 }
3334 }
3335
3336 /* Refresh all level crossings to bar adjacent crossing tiles, if needed. */
3337 for (const auto tile : Map::Iterate()) {
3338 if (IsLevelCrossingTile(tile)) UpdateLevelCrossing(tile, false);
3339 }
3340 }
3341
3342 /* Compute station catchment areas. This is needed here in case UpdateStationAcceptance is called below. */
3344
3345 /* Station acceptance is some kind of cache */
3347 for (Station *st : Station::Iterate()) UpdateStationAcceptance(st, false);
3348 }
3349
3352 }
3353
3355 /* For older savegames, we don't now the actual interval; so set it to the newgame value. */
3356 _settings_game.difficulty.competitors_interval = _settings_newgame.difficulty.competitors_interval;
3357
3358 /* We did load the "period" of the timer, but not the fired/elapsed. We can deduce that here. */
3360 _new_competitor_timeout.storage.elapsed = 0;
3361 _new_competitor_timeout.fired = _new_competitor_timeout.period.value == 0;
3362 }
3363
3365 /* Set service date provided to NewGRF. */
3366 for (Vehicle *v : Vehicle::Iterate()) {
3367 v->date_of_last_service_newgrf = TimerGameCalendar::Date{v->date_of_last_service.base()};
3368 }
3369 }
3370
3372 /* NewGRF acceleration information was added to ships. */
3373 for (Ship *s : Ship::Iterate()) {
3374 if (s->acceleration == 0) s->acceleration = ShipVehInfo(s->engine_type)->acceleration;
3375 }
3376 }
3377
3379 for (Company *c : Company::Iterate()) {
3380 c->max_loan = COMPANY_MAX_LOAN_DEFAULT;
3381 }
3382 }
3383
3385 ScriptObject::InitializeRandomizers();
3386 }
3387
3389 for (Company *c : Company::Iterate()) {
3390 c->inaugurated_year_calendar = _settings_game.game_creation.starting_year;
3391 }
3392 }
3393
3395 /* Between these two versions (actually from f8b1e303 to 77236258) EngineFlags had an off-by-one. Depending
3396 * on when the save was started, this may or may not affect existing engines. Here we try to detect invalid flags
3397 * and reset them to what they should be. */
3398 for (Engine *e : Engine::Iterate()) {
3399 if (e->flags.Test(EngineFlag::Available)) continue;
3400 if (e->flags.Test(EngineFlag{2}) || (e->flags.Test(EngineFlag::ExclusivePreview) && e->preview_asked.None())) {
3401 e->flags = EngineFlags(e->flags.base() >> 1U);
3402 }
3403 }
3404 }
3405
3407 /* Default waypoints were built with an incorrect layout that prevents building bridges over them. */
3408 for (auto tile : Map::Iterate()) {
3409 if (!IsRailWaypointTile(tile)) continue; // Not a waypoint.
3410 if (GetCustomStationSpecIndex(tile) > 0) continue; // Not a default waypoint.
3411 SetStationGfx(tile, GetStationGfx(tile) & 1);
3412 }
3413 }
3414
3415 for (Company *c : Company::Iterate()) {
3417 }
3418
3419 /* Update free group numbers data for each company, required regardless of savegame version. */
3420 for (Group *g : Group::Iterate()) {
3421 Company *c = Company::Get(g->owner);
3423 /* Use the index as group number when converting old savegames. */
3424 g->number = c->freegroups.UseID(g->index.base());
3425 } else {
3426 c->freegroups.UseID(g->number);
3427 }
3428 }
3429
3433
3434 _gamelog.PrintDebug(Severity::Error);
3435
3437 /* Restore the signals */
3439
3441
3443
3444 /* Start the scripts. This MUST happen after everything else except
3445 * starting a new company. */
3446 StartScripts();
3447
3448 /* If Load Scenario / New (Scenario) Game is used,
3449 * a company does not exist yet. So create one here.
3450 * 1 exception: network-games. Those can have 0 companies
3451 * But this exception is not true for non-dedicated network servers! */
3453 CompanyID first_human_company = GetFirstPlayableCompanyID();
3454 if (!Company::IsValidID(first_human_company)) {
3455 Company *c = DoStartupNewCompany(false, first_human_company);
3456 c->settings = _settings_client.company;
3457 }
3458 }
3459
3460 return true;
3461}
3462
3472{
3473 /* reload grf data */
3477 /* reload vehicles */
3478 ResetVehicleHash();
3484 /* update station graphics */
3485 AfterLoadStations();
3486 /* Update company statistics. */
3488 /* Check and update house and town values */
3490 /* Delete news referring to no longer existing entities */
3492 /* Update livery selection windows */
3493 for (CompanyID i = CompanyID::Begin(); i < MAX_COMPANIES; ++i) InvalidateWindowData(WindowClass::CompanyLivery, i);
3494 /* Update company infrastructure counts. */
3495 InvalidateWindowClassesData(WindowClass::CompanyInfrastructure);
3496 InvalidateWindowClassesData(WindowClass::BuildToolbar);
3497 InvalidateAllPickerWindows();
3498 /* redraw the whole screen */
3501}
static void SetSignalHandlers()
Replaces signal handlers of SIGSEGV and SIGABRT and stores pointers to original handlers in memory.
static void UpdateExclusiveRights()
Since savegame version 4.1, exclusive transport rights are stored at towns.
Company * DoStartupNewCompany(bool is_ai, CompanyID company=CompanyID::Invalid())
Create a new company and sets all company variables default values.
static void InitializeWindowsAndCaches()
Initialization of the windows and several kinds of caches.
static void CheckGroundVehiclesAtCorrectZ()
Check whether the ground vehicles are at the correct Z-coordinate.
static bool _saveload_crash_with_missing_newgrfs
Was the saveload crash because of missing NewGRFs?
static void HandleSavegameLoadCrash(int signum)
Signal handler used to give a user a more useful report for crashes during the savegame loading proce...
static void FixOwnerOfRailTrack(Tile t)
Tries to change owner of this rail tile to a valid owner.
static void UpdateVoidTiles()
Up to revision 1413 the invisible tiles at the southern border have not been TileType::Void,...
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 ...
static void UpdateCurrencies()
Since savegame version 4.2 the currencies are arranged differently.
void SetWaterClassDependingOnSurroundings(Tile t, bool include_invalid_water_class)
Makes a tile canal or water depending on the surroundings.
Definition afterload.cpp:88
static GroundVehicleFlags FixVehicleInclination(Vehicle *v, Direction dir)
Fixes inclination of a vehicle.
static void StartScripts()
Start the scripts.
bool SaveloadCrashWithMissingNewGRFs()
Did loading the savegame cause a crash?
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
void ClearOldOrders()
Clear all old orders.
Definition order_sl.cpp:115
bool AfterLoadGame()
Perform a (large) amount of savegame conversion magic in order to load older savegames and to fill th...
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
static void ResetSignalHandlers()
Resets signal handlers back to original handlers.
Base functions for all AIs.
Base for aircraft.
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...
void AircraftNextAirportPos_and_Order(Aircraft *v)
Set the right pos when heading to other airports after takeoff.
Station * GetTargetAirportIfValid(const Aircraft *v)
Returns aircraft's target station if v->target_airport is a valid station with airport.
void SetAircraftPosition(Aircraft *v, int x, int y, int z)
Set aircraft position.
@ AIR_AIRCRAFT
an airplane
Definition aircraft.h:30
void UpdateAircraftCache(Aircraft *v, bool update_range=false)
Update cached values of an aircraft.
@ FLYING
Vehicle is flying in the air.
Definition airport.h:78
@ AT_OILRIG
Oilrig airport.
Definition airport.h:38
std::vector< TileIndex > _animated_tiles
The table/list with animated tiles.
Maps accessors for animated tiles.
@ Animated
Tile is animated.
@ None
Tile is not animated.
void SetAnimatedTileState(Tile t, AnimatedTileState state)
Set the animated state of a tile.
Class for backupping variables and making sure they are restored later.
VehicleFlag
Bit numbers in Vehicle::vehicle_flags.
@ PathfinderLost
Vehicle's pathfinder is lost.
@ LoadingFinished
Vehicle has finished loading.
constexpr T AssignBit(T &x, const uint8_t y, bool value)
Assigns a bit in a variable.
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.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
void SetBridgeMiddle(Tile t, Axis a)
Set that there is a bridge over the given axis.
Definition bridge_map.h:114
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition bridge_map.h:35
void ClearBridgeMiddle(Tile t)
Removes bridges from the given, that is bridges along the X and Y axis.
Definition bridge_map.h:103
bool IsBridge(Tile t)
Checks if this is a bridge, instead of a tunnel.
Definition bridge_map.h:24
void AfterLoadCompanyStats()
Rebuilding of company statistics after loading a savegame.
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
Definition cargo_type.h:112
static constexpr CargoType CARGO_NO_REFIT
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-renew).
Definition cargo_type.h:81
@ Food
Cargo behaves food/fizzy-drinks-like.
Definition cargotype.h:28
@ Water
Cargo behaves water-like.
Definition cargotype.h:27
@ Mail
Cargo behaves mail-like.
Definition cargotype.h:25
@ Passengers
Cargo behaves passenger-like.
Definition cargotype.h:24
@ Goods
Cargo behaves goods/candy-like.
Definition cargotype.h:26
static void StartNew(CompanyID company)
Start a new AI company.
Definition ai_core.cpp:36
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
constexpr Timpl & Reset()
Reset all bits.
constexpr Timpl & Set()
Set all bits.
Iterate a range of enum values.
UnitID UseID(UnitID index)
Use a unit number.
Definition vehicle.cpp:1890
static void StartNew()
Start up a new GameScript.
Definition game_core.cpp:70
uint16_t w
The width of the area.
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
TileIndex tile
The base tile of the area.
uint16_t h
The height of the area.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
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).
Wrapper class to abstract away the way the tiles are stored.
Definition map_func.h:25
uint8_t & m5()
General purpose.
Definition map_func.h:156
uint8_t & m6()
General purpose.
Definition map_func.h:167
uint8_t & m7()
Primarily used for newgrf support.
Definition map_func.h:178
uint8_t & m3()
General purpose.
Definition map_func.h:134
uint16_t & m2()
Primarily used for indices to towns, industries and stations.
Definition map_func.h:123
A timeout timer will fire once after the interval.
Definition timer.h:116
static void SetDate(Date date, DateFract fract)
Set the date.
static Date date
Current date in days (day counter).
static Year year
Current year, starting at 0.
static DateFract date_fract
Fractional part of the day.
static constexpr TimerGame< struct Economy >::Date MIN_DATE
static constexpr TimerGame< struct Calendar >::Year DEF_END_YEAR
static constexpr TimerGame< struct Economy >::Year MIN_YEAR
static constexpr TimerGame< struct Calendar >::Year ORIGINAL_BASE_YEAR
static constexpr TimerGame< struct Calendar >::Date DAYS_TILL_ORIGINAL_BASE_YEAR
static Date date
Current date in days (day counter).
static Year year
Current year, starting at 0.
static DateFract date_fract
Fractional part of the day.
static void SetDate(Date date, DateFract fract)
Set the date.
static TickCounter counter
Monotonic counter, in ticks, since start of game.
StrongType::Typedef< int32_t, DateTag< struct Economy >, StrongType::Compare, StrongType::Integer > Date
Map accessors for 'clear' tiles.
bool IsClearGround(Tile t, ClearGround ct)
Set the type of clear tile.
Definition clear_map.h:65
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:234
ClearGround
Ground types.
Definition clear_map.h:21
@ Fields
Farm fields (3).
Definition clear_map.h:25
@ Grass
Plain grass with dirt transition (0-3).
Definition clear_map.h:22
void MakeClear(Tile t, ClearGround g, uint density)
Make a clear tile.
Definition clear_map.h:253
ClearGround GetClearGround(Tile t)
Get the type of clear tile.
Definition clear_map.h:52
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:152
uint GetClearDensity(Tile t)
Get the density of a non-field clear tile.
Definition clear_map.h:77
void RandomiseCompanyManagerFace(CompanyManagerFace &cmf, Randomizer &randomizer)
Completely randomise a company manager face, including style.
TimeoutTimer< TimerGameTick > _new_competitor_timeout({ TimerGameTick::Priority::CompetitorTimeout, 0 }, []() { if(_game_mode==GameMode::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< Commands::CompanyControl >::Post(CompanyCtrlAction::NewAI, CompanyID::Invalid(), CompanyRemoveReason::None, ClientID::Invalid);})
Start a new competitor company if possible.
void ResetCompanyLivery(Company *c)
Reset the livery schemes to the company's primary colour.
void UpdateCompanyLiveries(Company *c)
Update liveries for a company.
void SetCompanyManagerFaceStyle(CompanyManagerFace &cmf, uint style)
Set a company face style.
CompanyID GetFirstPlayableCompanyID()
Get the index of the first available company.
std::optional< uint > FindCompanyManagerFaceLabel(std::string_view label)
Find a company manager face style by label.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
Functionality related to the company manager's face.
CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32_t face)
Converts an old company manager's face format to the new company manager's face format.
static constexpr Owner OWNER_TOWN
A town owns the tile, or a town is expanding.
static constexpr Owner OWNER_NONE
The tile has no ownership.
static constexpr Owner INVALID_OWNER
An invalid owner.
static constexpr Owner OWNER_WATER
The tile/execution is done by "water".
Currency
This enum gives the currencies a unique id which must be maintained for savegame compatibility and in...
@ SIT
Slovenian Tolar.
@ JPY
Japanese Yen.
@ RUR
Russian Rouble.
@ NLG
Dutch Gulden.
@ CHF
Swiss Franc.
@ USD
US Dollar.
@ DEM
Deutsche Mark.
@ GBP
British Pound.
@ ESP
Spanish Peseta.
@ ISK
Icelandic Krona.
@ PLN
Polish Zloty.
@ ITL
Italian Lira.
@ DKK
Danish Krona.
@ ATS
Austrian Schilling.
@ GRD
Greek Drachma.
@ FIM
Finish Markka.
@ NOK
Norwegian Krone.
@ EUR
Euro.
@ BEF
Belgian Franc.
@ HUF
Hungarian Forint.
@ FRF
French Franc.
@ RON
Romanian Leu.
@ CZK
Czech Koruna.
#define Debug(facility, severity, format_string,...)
Output a line of debugging information.
Definition debug.h:36
@ Sl
Saveload message facility.
Definition debug_type.h:39
@ Net
Net message facility.
Definition debug_type.h:33
@ Critical
Critical, user should know about this.
Definition debug_type.h:15
@ Error
Error, but we are recovering.
Definition debug_type.h:16
Base for all depots (except hangars).
bool IsDepotTile(Tile tile)
Is the given tile a tile with a depot on it?
Definition depot_map.h:45
Direction DiagDirToDir(DiagDirection dir)
Convert a DiagDirection to a Direction.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Direction ReverseDir(Direction d)
Return the reverse of a direction.
Direction AxisToDirection(Axis a)
Converts an Axis to a Direction.
Axis OtherAxis(Axis a)
Select the other axis as provided.
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
DiagDirection XYNSToDiagDir(Axis xy, uint ns)
Convert an axis and a flag for north/south into a DiagDirection.
DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
EnumIndexArray< T, DiagDirection, DiagDirection::End > DiagDirectionIndexArray
Array with DiagDirection as index.
Direction
Defines the 8 directions on the map.
@ Invalid
Flag for an invalid direction.
@ SW
Southwest.
@ NW
Northwest.
@ NE
Northeast.
@ SE
Southeast.
Axis
Enumeration for the two axis X and Y.
@ X
The X axis.
@ Y
The y axis.
DiagDirection
Enumeration for diagonal directions.
@ SW
Southwest.
@ NW
Northwest.
@ End
Used for iterations.
@ NE
Northeast, upper right on your monitor.
@ SE
Southeast.
All disaster vehicles.
void RecomputePrices()
Computes all prices, payments and maximum loan.
Definition economy.cpp:738
bool AddInflation(bool check_year)
Add monthly inflation.
Definition economy.cpp:700
Base classes related to the economy.
static const uint64_t MAX_INFLATION
Maximum inflation (including fractional part) without causing overflows in int64_t price computations...
Header file for electrified rail specific functions.
void StartupEngines()
Start/initialise all our engines.
Definition engine.cpp:838
Functions related to engines.
void CopyTempEngineData()
Copy data from temporary engine array into the real engine pool.
EnumBitSet< EngineFlag, uint8_t > EngineFlags
Bitset of EngineFlag elements.
@ RoadIsTram
Road vehicle is a tram/light rail vehicle.
EngineFlag
Engine.flags is a bitmask, with the following values.
@ Available
This vehicle is available to everyone.
@ ExclusivePreview
This vehicle is in the exclusive preview stage, either being used or being offered to a company.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
Functions related to errors.
@ Critical
Critical errors, the MessageBox is shown in all cases.
Definition error.h:25
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
@ Scenario
old or new scenario
Definition fileio_type.h:19
Base functions for all Games.
Gamelog _gamelog
Gamelog instance.
Definition gamelog.cpp:30
void LoadStringWidthTable(FontSizes fontsizes)
Initialize _stringwidth_table cache for the specified font sizes.
Definition gfx.cpp:1255
PauseModes _pause_mode
The current pause mode.
Definition gfx.cpp:46
void GfxLoadSprites()
Initialise and load all the sprites.
Definition gfxinit.cpp:335
Functions related to the graphics initialization.
@ Tile
Destination is a tile.
Definition goal_type.h:53
void UpdateGroupChildren()
Update children list for each group.
Definition group_cmd.cpp:48
@ ReplaceProtection
If set, the global autoreplace has no effect on the group.
Definition group.h:68
@ ReplaceWagonRemoval
If set, autoreplace will perform wagon removal on vehicles in this group.
Definition group.h:69
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1548
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
Definition house.h:28
static const uint8_t TOWN_HOUSE_COMPLETED
Simple value that indicates the house has reached the final stage of construction.
Definition house.h:25
Base of all industries.
IndustryBuildData _industry_builder
In-game manager of industries.
void TrimIndustryAcceptedProduced(Industry *ind)
Remove unused industry accepted/produced slots – entries after the last slot with valid cargo.
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
IndustryType GetIndustryType(Tile tile)
Retrieve the type for this industry.
IndustryGfx GetIndustryGfx(Tile t)
Get the industry graphics ID for the given industry tile.
static constexpr IndustryGfx GFX_GOLD_MINE_TOWER_ANIMATED
static constexpr IndustryGfx GFX_OILWELL_ANIMATED_1
static constexpr IndustryGfx GFX_POWERPLANT_SPARKS
static constexpr IndustryGfx GFX_OILWELL_ANIMATED_2
static constexpr IndustryGfx GFX_COPPER_MINE_TOWER_ANIMATED
static constexpr IndustryGfx GFX_COAL_MINE_TOWER_ANIMATED
static constexpr IndustryGfx GFX_OILRIG_1
static constexpr IndustryGfx GFX_OILWELL_ANIMATED_3
@ PlantOnBuild
Fields are planted around when built (all farms).
@ BuiltOnWater
is built on water (oil rig)
void AfterLoadLabelMaps()
Perform rail type and road type conversion if necessary.
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
Change the owner of a tile.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, RoadTramType sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
@ Arctic
Landscape with snow levels.
@ Tropic
Landscape with distinct rainforests and deserts,.
void AfterLoadLinkGraphs()
Spawn the threads for running link graph calculations.
@ Manual
Manual distribution. No link graph calculations are run.
@ Default
Default scheme.
Definition livery.h:24
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows.
Definition main_gui.cpp:549
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition map.cpp:168
TileIndex TileAddXY(TileIndex tile, int x, int y)
Adds a given offset to a tile.
Definition map_func.h:474
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition map_func.h:407
TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Definition map_func.h:615
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition map_func.h:392
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition map_func.h:376
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:429
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:419
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:574
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
constexpr To ClampTo(From value)
Clamp the given value down to lie within the requested type.
void GenerateSavegameId()
Generate an unique savegame ID.
Definition misc.cpp:87
ZoomLevel _saved_scrollpos_zoom
Definition misc_sl.cpp:38
int _saved_scrollpos_x
Definition misc_sl.cpp:36
int _saved_scrollpos_y
Definition misc_sl.cpp:37
bool _networking
are we in networking mode?
Definition network.cpp:63
bool _network_dedicated
are we a dedicated server?
Definition network.cpp:66
bool _network_server
network-server is active
Definition network.cpp:64
Basic functions/variables used all over the place.
Base for the NewGRF implementation.
@ FakeTowns
Fake town GrfSpecFeature for NewGRF debugging (parent scope).
Definition newgrf.h:107
@ Airports
Airports feature.
Definition newgrf.h:95
@ Industries
Industries feature.
Definition newgrf.h:92
void ShowNewGRFError()
Show the first NewGRF error we can find.
GRFConfigList _grfconfig
First item in list of current GRF set up.
GRFListCompatibility IsGoodGRFConfigList(GRFConfigList &grfconfig)
Check if all GRFs in the GRF config from a savegame can be loaded.
GRFListCompatibility
Status of post-gameload GRF compatibility check.
@ NotFound
At least one GRF couldn't be found (higher priority than GRFListCompatibility::Compatible).
@ AllGood
All GRF needed by game are present.
@ Compatible
Compatible (eg. the same ID, but different checksum) GRF found in at least one case.
@ NotFound
GRF file was not found in the local cache.
@ Compatible
GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches).
Functions related to news.
void DeleteInvalidEngineNews()
Remove engine announcements for invalid engines.
Base for all objects.
uint16_t ObjectType
Types of objects.
Definition object_type.h:16
static const ObjectType OBJECT_STATUE
Statue in towns.
Definition object_type.h:20
static const ObjectType OBJECT_HQ
HeadQuarter of a player.
Definition object_type.h:22
@ Error
A game paused because a (critical) error.
Definition openttd.h:75
@ ActiveClients
A game paused for 'min_active_clients'.
Definition openttd.h:76
@ Normal
A game normally paused.
Definition openttd.h:72
@ Join
A game paused for 'pause_on_join'.
Definition openttd.h:74
@ Normal
Playing a game.
Definition openttd.h:20
EnumBitSet< PauseMode, uint8_t > PauseModes
Bitset of PauseMode elements.
Definition openttd.h:83
Functions related to order backups.
OrderUnloadType
Unloading order types.
Definition order_type.h:67
@ Transfer
Transfer all cargo onto the platform.
Definition order_type.h:70
@ FarEnd
Stop at the far end of the platform.
Definition order_type.h:101
@ NonStop
The vehicle will not stop at any stations it passes except the destination, aka non-stop.
Definition order_type.h:88
EnumBitSet< OrderDepotActionFlag, uint8_t > OrderDepotActionFlags
Bitset of OrderDepotActionFlag elements.
Definition order_type.h:126
@ NoLoad
Do not load anything.
Definition order_type.h:81
Functions/types etc.
RailTypes GetCompanyRailTypes(CompanyID company, bool introduces)
Get the rail types the given company can build.
Definition rail.cpp:137
void InitializeSignalGui()
Resets the signal GUI.
Functions/types etc.
static bool IsPlainRail(Tile t)
Returns whether this is plain rails, with or without signals.
Definition rail_map.h:49
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Definition rail_map.h:115
static bool IsRailDepot(Tile t)
Is this rail tile a rail depot?
Definition rail_map.h:95
RailGroundType GetRailGroundType(Tile t)
Get the ground type for rail tiles.
Definition rail_map.h:601
static bool IsPlainRailTile(Tile t)
Checks whether the tile is a rail tile or rail tile with signals.
Definition rail_map.h:60
void MakeRailNormal(Tile t, Owner o, TrackBits b, RailType r)
Make the given tile a normal rail.
Definition rail_map.h:624
void SetTrackReservation(Tile t, TrackBits b)
Sets the reserved track bits of the tile.
Definition rail_map.h:209
@ HalfTileWater
Grass with a fence and shore or water on the free halftile.
Definition rail_map.h:582
void SetDepotReservation(Tile t, bool b)
Set the reservation state of the depot.
Definition rail_map.h:268
bool HasSignals(Tile t)
Checks if a rail tile has signals.
Definition rail_map.h:72
void SetSignalVariant(Tile t, Track track, SignalVariant v)
Set the signal variant for a track on a tile.
Definition rail_map.h:398
static bool IsRailDepotTile(Tile t)
Is this tile rail tile and a rail depot?
Definition rail_map.h:105
void SetSignalStates(Tile tile, uint state)
Set the states of the signals (Along/AgainstTrackDir).
Definition rail_map.h:410
void SetRailType(Tile t, RailType r)
Sets the rail type of the given tile.
Definition rail_map.h:125
EnumBitSet< RailType, uint64_t > RailTypes
Bitset of RailType elements.
Definition rail_type.h:37
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:26
@ RAILTYPE_ELECTRIC
Electric rails.
Definition rail_type.h:29
@ RAILTYPE_RAIL
Standard non-electric rails.
Definition rail_type.h:28
Randomizer _random
Random used in the game state calculations.
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
Get the road types the given company can build.
Definition road.cpp:209
bool UpdateNearestTownForRoadTiles(bool invalidate)
Updates cached nearest town for all road tiles.
Road related functions.
RoadBits AxisToRoadBits(Axis a)
Create the road-part which belongs to the given Axis.
Definition road_func.h:93
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).
void SetRoadOwner(Tile t, RoadTramType rtt, Owner o)
Set the owner of a specific road type.
Definition road_map.h:261
static RoadTileType GetRoadTileType(Tile t)
Get the type of the road tile.
Definition road_map.h:36
bool HasTownOwnedRoad(Tile t)
Checks if given tile has town owned road.
Definition road_map.h:290
bool IsLevelCrossingTile(Tile t)
Return whether a tile is a level crossing tile.
Definition road_map.h:79
void SetRoadTypes(Tile t, RoadType road_rt, RoadType tram_rt)
Set the present road types of a tile.
Definition road_map.h:630
static bool IsRoadDepot(Tile t)
Return whether a tile is a road depot.
Definition road_map.h:90
@ Normal
Normal road.
Definition road_map.h:23
@ Depot
Depot (one entrance).
Definition road_map.h:25
@ Crossing
Level crossing.
Definition road_map.h:24
RoadBits GetCrossingRoadBits(Tile tile)
Get the road bits of a level crossing.
Definition road_map.h:369
Owner GetRoadOwner(Tile t, RoadTramType rtt)
Get the owner of a specific road type.
Definition road_map.h:244
void SetCrossingReservation(Tile t, bool b)
Set the reservation state of the rail crossing.
Definition road_map.h:403
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
Definition road_map.h:69
EnumBitSet< RoadBit, uint8_t > RoadBits
Bitset of RoadBit elements.
Definition road_type.h:65
static constexpr RoadTramTypes ROADTRAMTYPES_ALL
All possible RoadTramTypes.
Definition road_type.h:49
RoadType
The different roadtypes we support.
Definition road_type.h:24
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:29
@ ROADTYPE_TRAM
Trams.
Definition road_type.h:27
@ ROADTYPE_ROAD
Basic road type.
Definition road_type.h:26
RoadTramType
The different types of road type.
Definition road_type.h:38
@ Invalid
Invalid marker.
Definition road_type.h:42
@ Tram
Tram type.
Definition road_type.h:40
@ Road
Road type.
Definition road_type.h:39
Base class for roadstops.
Road vehicle states.
@ RVS_ENTERED_STOP
Only set when a vehicle has entered the stop.
Definition roadveh.h:43
@ RVSB_IN_ROAD_STOP
The vehicle is in a road stop.
Definition roadveh.h:49
@ RVS_IN_DT_ROAD_STOP
The vehicle is in a drive-through road stop.
Definition roadveh.h:46
@ RVS_IN_ROAD_STOP
The vehicle is in a road stop.
Definition roadveh.h:45
@ RVSB_IN_DEPOT
The vehicle is in a depot.
Definition roadveh.h:38
@ RVSB_WORMHOLE
The vehicle is in a tunnel and/or bridge.
Definition roadveh.h:39
@ RVS_DRIVE_SIDE
Only used when retrieving move data.
Definition roadveh.h:44
static const uint RVC_DRIVE_THROUGH_STOP_FRAME
Stop frame for a vehicle in a drive-through stop.
Definition roadveh.h:82
Command definitions related to road vehicles.
const uint8_t _road_stop_stop_frame[]
Table of road stop stop frames, when to stop at a road stop.
A number of safeguards to prevent using unsafe methods.
void SlError(StringID string, const std::string &extra_msg)
Error handler.
Definition saveload.cpp:342
void SetSaveLoadError(StringID str)
Set the error message from outside of the actual loading/saving of the game (AfterLoadGame and friend...
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
Definition saveload.cpp:372
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition saveload.cpp:81
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
Definition saveload.h:1225
@ LastLoadingTick
Saveload version: 301, GitHub pull request: 9693 Store tick of last loading for vehicles.
Definition saveload.h:346
@ LargerTownCargoStatistics
Saveload version: 9.0, SVN revision: 1909 Increase size of passenger/mail production of this and pre...
Definition saveload.h:56
@ BigDates
Saveload version: 31, SVN revision: 5999 Change date from 1920 - 2090 to 0 - 5 000 000.
Definition saveload.h:86
@ IncreaseHouseLimit
Saveload version: 348, GitHub pull request: 12288 Increase house limit to 4096.
Definition saveload.h:402
@ CustomSeaLevel
Saveload version: 149, SVN revision: 20832 Setting to influence the sea level (amount of water).
Definition saveload.h:227
@ StoreIndustryCargo
Saveload version: 78, SVN revision: 11176 Store an industry's cargo, so it can be customised upon bu...
Definition saveload.h:142
@ MoreEngineTypes
Saveload version: 95, SVN revision: 12924 Allow more than the original 255 engine types.
Definition saveload.h:163
@ TrainSlopeSteepness
Saveload version: 133, SVN revision: 18674 Setting to increase steepness of slopes for trains under ...
Definition saveload.h:208
@ FractionProfitRunningTicks
Saveload version: 88, SVN revision: 12134 Store vehicle profits as a (fixed point) fraction,...
Definition saveload.h:154
@ UnifyWaypointAndStation
Saveload version: 123, SVN revision: 16909 Unify stations and waypoints.
Definition saveload.h:196
@ InfrastructureMaintenanceCosts
Saveload version: 166, SVN revision: 23415 Infrastructure can now cost some periodic fee.
Definition saveload.h:248
@ VehicleEconomyAge
Saveload version: 334, GitHub pull request: 12141, release: 14.0 Add vehicle age in economy year,...
Definition saveload.h:385
@ GroupReplaceWagonRemoval
Saveload version: 291, GitHub pull request: 7441 Per-group wagon removal flag.
Definition saveload.h:334
@ PauseModes
Saveload version: 119, SVN revision: 16242 Use bitmask of reason to pause, so manual/auto pausing do...
Definition saveload.h:191
@ ImproveMultistop
Saveload version: 25, SVN revision: 4259 Improve the behaviour of RVs going to road stops.
Definition saveload.h:79
@ MonthlyBankruptcyCheck
Saveload version: 177, SVN revision: 24619 Check for bankruptcy on a monthly cycle.
Definition saveload.h:261
@ CompanyInauguratedPeriodV2
Saveload version: 349, GitHub pull request: 13448 Fix savegame storage for company inaugurated year ...
Definition saveload.h:403
@ GoalProgressPlaneAcceleration
Saveload version: 182, SVN revision: 25115, r25259, r25296 Goal status and plane acceleration fixes.
Definition saveload.h:267
@ CountPaidForCargo
Saveload version: 45, SVN revision: 8501 Count the amount of cargo that was paid for.
Definition saveload.h:103
@ EndingYear
Saveload version: 218, GitHub pull request: 7747, release: 1.10 Configurable ending year.
Definition saveload.h:310
@ FifoLoading
Saveload version: 57, SVN revision: 9691 First-in-first-out loading of vehicles.
Definition saveload.h:117
@ LargerTownIterator
Saveload version: 11.0, SVN revision: 2033 Increase size of the town iterator.
Definition saveload.h:59
@ FreeformEdges
Saveload version: 111, SVN revision: 15190 Allow terraforming along the edge of the map.
Definition saveload.h:182
@ UnifyAnimationState
Saveload version: 43, SVN revision: 7642 Put all animation state information in same map bits.
Definition saveload.h:100
@ MoveSemaphoreBits
Saveload version: 15.0, SVN revision: 2499 Move rail signal bit for semaphores.
Definition saveload.h:65
@ ReplaceCustomNameArray
Saveload version: 84, SVN revision: 11822 Replace single fixed size array of custom names,...
Definition saveload.h:149
@ IncreaseStationTypeFieldSize
Saveload version: 337, GitHub pull request: 12572 Increase size of StationType field in map array.
Definition saveload.h:389
@ WaterClass
Saveload version: 86, SVN revision: 12042 Store the type of water (sea/ocean, canal,...
Definition saveload.h:152
@ LastVehicleType
Saveload version: 26, SVN revision: 4466 Store the last vehicle type at stations instead of the vehi...
Definition saveload.h:80
@ RoadLayoutPerTown
Saveload version: 113, SVN revision: 15340 Allow for different road layouts for each of the towns.
Definition saveload.h:184
@ SplitStationTypeFromGfxid
Saveload version: 72, SVN revision: 10601 Splits the encoding of station type from the graphics iden...
Definition saveload.h:135
@ NewGRFSuppliedStationName
Saveload version: 103, SVN revision: 14598 NewGRF industry supplying default names for nearby statio...
Definition saveload.h:172
@ MaxLengthAndReverseSignals
Saveload version: 159, SVN revision: 21962 Settings for reversing at signals, and maximum train,...
Definition saveload.h:239
@ ObjectTypeToPool
Saveload version: 186, SVN revision: 25833 Move object type from map to pool object.
Definition saveload.h:272
@ MultipleSignalTypes
Saveload version: 64, SVN revision: 10006 Multiple different signal types on the same (diagonal) til...
Definition saveload.h:125
@ SimplifyPlayerFace
Saveload version: 49, SVN revision: 8969 Simplify the storage of player face information.
Definition saveload.h:107
@ VehicleCurrencyStationChanges
Saveload version: 2.0, release: 0.3.0 Adding vehicle state, larger currency size for statistics,...
Definition saveload.h:39
@ TownTolerancePauseMode
Saveload version: 4.0, SVN revision: 1 Town council tolerance and pause mode.
Definition saveload.h:43
@ RoadTypes
Saveload version: 214, GitHub pull request: 6811 NewGRF road types.
Definition saveload.h:305
@ AircraftSpeedHolding
Saveload version: 50, SVN revision: 8973 Aircraft speed in km-ish/h and reduced speed in holding pat...
Definition saveload.h:109
@ MaxLoanForCompany
Saveload version: 330, GitHub pull request: 11224 Separate max loan for each company.
Definition saveload.h:381
@ TrackRealAndAutoOrders
Saveload version: 158, SVN revision: 21933 Track which real and auto order is the current order.
Definition saveload.h:238
@ VehicleCentreAndZPos
Saveload version: 164, SVN revision: 23290 Vehicle centres are not fixed at 4/8 of the vehicle; chan...
Definition saveload.h:245
@ VirtualFeederSharePayment
Saveload version: 134, SVN revision: 18703 Pay a part of the virtual profit during a transfer to the...
Definition saveload.h:209
@ SimplifyPathfinderSettings
Saveload version: 87, SVN revision: 12129 Make it easier to select the pathfinder to use.
Definition saveload.h:153
@ EconomyModeTimekeepingUnits
Saveload version: 327, GitHub pull request: 11341 Mode to display economy measurements in wallclock ...
Definition saveload.h:377
@ DriveBackwards
Saveload version: 365, GitHub pull request: 15379 Trains can drive backwards.
Definition saveload.h:423
@ MultipleRoadTypes
Saveload version: 61, SVN revision: 9892 Multiple road types for the same tile.
Definition saveload.h:122
@ MultitileDocks
Saveload version: 216, GitHub pull request: 7380 Multiple docks per station.
Definition saveload.h:308
@ RailTrackTypeUnification
Saveload version: 48, SVN revision: 8935 Put all the rail track type information in same map bits.
Definition saveload.h:106
@ AnimatedTileStateInMap
Saveload version: 347, GitHub pull request: 13082 Animated tile state saved for improved performance...
Definition saveload.h:401
@ NewGRFIndustryRandomTriggers
Saveload version: 82, SVN revision: 11410 NewGRF random triggers for industries.
Definition saveload.h:147
@ NewGRFLastService
Saveload version: 317, GitHub pull request: 11124 Added stable date_of_last_service to avoid NewGRF ...
Definition saveload.h:365
@ LinkgraphSeconds
Saveload version: 308, GitHub pull request: 10610 Store linkgraph update intervals in seconds instea...
Definition saveload.h:354
@ DisableTownLevelCrossing
Saveload version: 143, SVN revision: 20048 Setting to be able to disable building rail/road crossing...
Definition saveload.h:220
@ ShipAcceleration
Saveload version: 329, GitHub pull request: 10734 Start using Vehicle's acceleration field for ships...
Definition saveload.h:379
@ MaximumDepotPenalty
Saveload version: 131, SVN revision: 18481 Add configurable maximum pathfinder penalty for finding a...
Definition saveload.h:206
@ NewGRFPersistentStorage
Saveload version: 76, SVN revision: 11139 Persistently store some state of NewGRF objects/entities.
Definition saveload.h:140
@ TownAcceptance
Saveload version: 127, SVN revision: 17439 Store mask of cargos accepted by town houses and head qua...
Definition saveload.h:201
@ MoreCargoPackets
Saveload version: 69, SVN revision: 10319 Allow more than ~65k cargo packets.
Definition saveload.h:131
@ FixTreeGround
Saveload version: 81, SVN revision: 11244 Various fixes to improve the visuals of the ground under t...
Definition saveload.h:146
@ SeparateOrderTravelWaitTime
Saveload version: 190, SVN revision: 26547 Separate order travel and wait times.
Definition saveload.h:277
@ AirportAnimationFrames
Saveload version: 137, SVN revision: 18912 Use animation frames instead of many airport tile ids for...
Definition saveload.h:213
@ IndustryManagement
Saveload version: 152, SVN revision: 21171 Manage the amount of industries that ought to be spawned ...
Definition saveload.h:231
@ NewGRFHouses
Saveload version: 53, SVN revision: 9316 NewGRF controlled houses.
Definition saveload.h:112
@ FoundTown
Saveload version: 128, SVN revision: 18281 Founding of new towns.
Definition saveload.h:202
@ NonfloodingWaterTiles
Saveload version: 345, GitHub pull request: 13013 Store water tile non-flooding state.
Definition saveload.h:399
@ RefitOrders
Saveload version: 36, SVN revision: 6624 Vehicles can be refitted as part of an order.
Definition saveload.h:92
@ ExtendIndustryCargoSlots
Saveload version: 202, GitHub pull request: 6867 Increase industry cargo slots to 16 in,...
Definition saveload.h:291
@ RemoveSubsidyStationBinding
Saveload version: 125, SVN revision: 17113 Awarded subsidies are not bound to stations,...
Definition saveload.h:199
@ ImprovedOrders
Saveload version: 93, SVN revision: 12648 Orders support all full load/non stop types at the same ti...
Definition saveload.h:160
@ DisableElrailSetting
Saveload version: 38, SVN revision: 7195 Add setting to disable electrified rails.
Definition saveload.h:94
@ AIStartDate
Saveload version: 309, GitHub pull request: 10653 Removal of individual AI start dates and added a g...
Definition saveload.h:355
@ StoreAirportSize
Saveload version: 140, SVN revision: 19382 Store the size of the airport in the station.
Definition saveload.h:217
@ StoreWaypointIdInMap
Saveload version: 17.0, SVN revision: 3212 Store the ID of waypoints in m2 of the map.
Definition saveload.h:68
@ BuoysAt0_0
Saveload version: 364, GitHub pull request: 14983 Allow to build buoys at (0x0).
Definition saveload.h:421
@ PlatformStopLocation
Saveload version: 117, SVN revision: 16037 Set the platform stop location via train orders.
Definition saveload.h:189
@ SeparateRoadOwners
Saveload version: 114, SVN revision: 15601 Separate owners for road bits, tram bits and the road sto...
Definition saveload.h:185
@ MoreCompanies
Saveload version: 104, SVN revision: 14735 Increase maximum number of companies to 15.
Definition saveload.h:173
@ NewGRFPalette
Saveload version: 101, SVN revision: 14233 Store palette used by each of the NewGRFs.
Definition saveload.h:170
@ MultipleRoadStops
Saveload version: 6.0, SVN revision: 1721 Multi tile road stops, and some map size related fixes.
Definition saveload.h:52
@ SavegameId
Saveload version: 313, GitHub pull request: 10719 Add an unique ID to every savegame (used to dedupl...
Definition saveload.h:360
@ UnifyAnimationFrame
Saveload version: 147, SVN revision: 20621 Unify location of animation frame.
Definition saveload.h:225
@ AutoreplaceWhenOldTreeLimit
Saveload version: 175, SVN revision: 24136 Autoreplace vehicle only when they are old,...
Definition saveload.h:259
@ CargoPayments
Saveload version: 121, SVN revision: 16694 Perform payment of cargo after unloading.
Definition saveload.h:194
@ MultitrackLevelCrossings
Saveload version: 302, GitHub pull request: 9931, release: 13.0 Multi-track level crossings.
Definition saveload.h:347
@ PlaneSpeedFactor
Saveload version: 90, SVN revision: 12293 Setting to increase aircraft speed to be on par with the o...
Definition saveload.h:157
@ StationsUnderBridges
Saveload version: 359, GitHub pull request: 14477 Allow stations under bridges.
Definition saveload.h:415
@ CumulatedInflation
Saveload version: 126, SVN revision: 17433 Store cumulated inflation, and recalculate prices/payment...
Definition saveload.h:200
@ TownCargogen
Saveload version: 208, GitHub pull request: 6965 New algorithms for town building cargo generation.
Definition saveload.h:298
@ DisallowRoadReconstruction
Saveload version: 160, SVN revision: 21974, release: 1.1.x Setting to disallow road reconstruction.
Definition saveload.h:241
@ Cargodist
Saveload version: 183, SVN revision: 25363 Cargodist.
Definition saveload.h:268
@ Elrail
Saveload version: 24, SVN revision: 4150 Electrified railways.
Definition saveload.h:77
@ CompanyServiceIntervals
Saveload version: 120, SVN revision: 16439 Make service intervals configurable per company.
Definition saveload.h:193
@ MoreAirportBlocks
Saveload version: 46, SVN revision: 8705 Increase number of blocks an airport can have.
Definition saveload.h:104
@ ReducePlaneCrashes
Saveload version: 138, SVN revision: 18942, release: 1.0.x Setting to reduce/disable crashing of pla...
Definition saveload.h:214
@ RocksStayUnderSnow
Saveload version: 135, SVN revision: 18719 Rocks stay under snow, i.e. they return when the snow goe...
Definition saveload.h:211
@ MinVersion
First savegame version.
Definition saveload.h:36
@ EconomyDate
Saveload version: 326, GitHub pull request: 10700 Split calendar and economy timers and dates.
Definition saveload.h:376
@ OrderMaxSpeed
Saveload version: 172, SVN revision: 23947 Set maximum speed for orders.
Definition saveload.h:255
@ MoreHouseAnimationFrames
Saveload version: 91, SVN revision: 12347 Increase number of animation frames for NewGRF houses.
Definition saveload.h:158
@ WaypointMoreLikeStation
Saveload version: 122, SVN revision: 16855 Make waypoint data look more like stations.
Definition saveload.h:195
@ ExtendRailtypes
Saveload version: 200, GitHub pull request: 6805 Extend railtypes to 64, adding uint16_t to map arra...
Definition saveload.h:289
@ VeryLowTownIndustryNumber
Saveload version: 58, SVN revision: 9762 Difficulty settings for very low number of industries and t...
Definition saveload.h:118
@ SplitLoadWaitCounters
Saveload version: 136, SVN revision: 18764 Split counters for (un)loading and signal waiting/turning...
Definition saveload.h:212
@ LeaveRoadStopSeparately
Saveload version: 153, SVN revision: 21263 Fix issue where multiple vehicles could leave a road stop...
Definition saveload.h:232
@ StatueOwner
Saveload version: 52, SVN revision: 9066 Store the owner of the statue, so the town can be informed ...
Definition saveload.h:111
@ SplitHQ
Saveload version: 112, SVN revision: 15290 Split the behaviour of headquarters from the other unmova...
Definition saveload.h:183
@ UniqueDepotNames
Saveload version: 141, SVN revision: 19799 Give depots unique names.
Definition saveload.h:218
@ DepotWaterOwners
Saveload version: 83, SVN revision: 11589 Store the owner of the water under depots,...
Definition saveload.h:148
@ EngineRenew
Saveload version: 16.0, SVN revision: 2817 Automatic replacing/renewing of vehicles.
Definition saveload.h:66
@ TownGrowthInGameTicks
Saveload version: 198, GitHub pull request: 6763 Switch town growth rate and counter to actual game ...
Definition saveload.h:286
@ DepotUnbunching
Saveload version: 331, GitHub pull request: 11945 Allow unbunching shared order vehicles at a depot.
Definition saveload.h:382
@ ShipsStopInLocks
Saveload version: 206, GitHub pull request: 7150 Ship/lock movement changes.
Definition saveload.h:296
@ IndustryTileWaterClass
Saveload version: 99, SVN revision: 13838 Add water classes to industry tiles.
Definition saveload.h:167
@ ScriptRandomizer
Saveload version: 333, GitHub pull request: 12063, release: 14.0-RC1 Save script randomizers.
Definition saveload.h:384
@ RepairObjectDockingTiles
Saveload version: 299, GitHub pull request: 9594, release: 12.0 Fixing issue with docking tiles over...
Definition saveload.h:343
@ RemoveOldPbs
Saveload version: 21, SVN revision: 3472, release: 0.4.x Remove old implementation of path based sig...
Definition saveload.h:74
@ NewGRFDepotBuildDate
Saveload version: 142, SVN revision: 20003 Depot build date for NewGRFs.
Definition saveload.h:219
@ NewGRFAirportSmoke
Saveload version: 145, SVN revision: 20376 NewGRF support for airport and configurable amount of smo...
Definition saveload.h:223
@ FixStationPickupAccounting
Saveload version: 74, SVN revision: 11030 Accounting of which cargos a station would pick up was don...
Definition saveload.h:137
@ DistantStationJoining
Saveload version: 106, SVN revision: 14919 Distant joining of stations.
Definition saveload.h:176
@ VelocityNautical
Saveload version: 305, GitHub pull request: 10594 Separation of land and nautical velocity (knots!...
Definition saveload.h:351
@ CalendarSubDateFract
Saveload version: 328, GitHub pull request: 11428 Add sub_date_fract to measure calendar days.
Definition saveload.h:378
@ Liveries
Saveload version: 34, SVN revision: 6455 Liveries and two company colours (2cc).
Definition saveload.h:89
@ GroupNumbers
Saveload version: 336, GitHub pull request: 12297 Add per-company group numbers.
Definition saveload.h:388
@ RvRealisticAcceleration
Saveload version: 139, SVN revision: 19346 Realistic acceleration of road vehicles.
Definition saveload.h:215
@ ServeNeutralIndustries
Saveload version: 210, GitHub pull request: 7234 Company stations can serve industries with attached...
Definition saveload.h:301
@ ReorderUnmovableRemoveReserved
Saveload version: 144, SVN revision: 20334 Reorder map bits of unmovable tiles and remove unused res...
Definition saveload.h:221
@ Yapp
Saveload version: 100, SVN revision: 13952 New version of path based signals.
Definition saveload.h:169
@ MultiTileWaypoints
Saveload version: 124, SVN revision: 16993 Waypoints can be bigger than a single tile.
Definition saveload.h:197
@ FaceStyles
Saveload version: 355, GitHub pull request: 14319 Addition of face styles, replacing gender and ethn...
Definition saveload.h:411
@ TerraformLimits
Saveload version: 156, SVN revision: 21728 Introduce limits for terraforming and clearing times.
Definition saveload.h:236
@ SeparateLocaleUnits
Saveload version: 184, SVN revision: 25508 Unit localisation split.
Definition saveload.h:269
@ TreesWaterClass
Saveload version: 213, GitHub pull request: 7405 WaterClass update for tree tiles.
Definition saveload.h:304
@ AdjacentStations
Saveload version: 62, SVN revision: 9905 Allow building multiple stations directly next to eachother...
Definition saveload.h:123
@ UnifyRvTravelTime
Saveload version: 188, SVN revision: 26169, release: 1.4 Unify RV travel time.
Definition saveload.h:274
@ MaxBridgeMapHeight
Saveload version: 194, SVN revision: 26881, release: 1.5 Setting for maximum bridge and map height.
Definition saveload.h:281
@ ScriptSaveInstances
Saveload version: 352, GitHub pull request: 13556 Scripts are allowed to save instances.
Definition saveload.h:407
@ IndustryPlatform
Saveload version: 148, SVN revision: 20659 Setting to make a flat area around (new) industries.
Definition saveload.h:226
@ ScriptTownGrowth
Saveload version: 165, SVN revision: 23304 Storage of cargo statistics for use by game scripts.
Definition saveload.h:247
@ FixCompanyCargoTypes
Saveload version: 94, SVN revision: 12816 The company's cargo types should have increased in since w...
Definition saveload.h:161
@ Gamelog
Saveload version: 98, SVN revision: 13375 Logging of important actions/situations in the save.
Definition saveload.h:166
@ PersistentStoragePool
Saveload version: 161, SVN revision: 22567 Store persistent storage in a pool.
Definition saveload.h:242
@ TownLayout
Saveload version: 59, SVN revision: 9779 More layout options for towns.
Definition saveload.h:119
@ UnifyWaterClass
Saveload version: 146, SVN revision: 20446 Unify location for storing water class in the map.
Definition saveload.h:224
@ Cities
Saveload version: 56, SVN revision: 9667 Cities that start bigger and grow faster.
Definition saveload.h:116
@ AirportNoise
Saveload version: 96, SVN revision: 13226 Introduce noise for airports, to allow more than two airpo...
Definition saveload.h:164
@ CargoPaymentOverflow
Saveload version: 70, SVN revision: 10541 Fix overflow of cargo payment rates, plus preparation for ...
Definition saveload.h:133
@ WaterTileType
Saveload version: 342, GitHub pull request: 13030 Simplify water tile type.
Definition saveload.h:395
@ FixOrderBackup
Saveload version: 192, SVN revision: 26700 Fix saving of order backups.
Definition saveload.h:279
@ BridgeWormhole
Saveload version: 42, SVN revision: 7573 Bridges become wormholes, so more things can be built under...
Definition saveload.h:99
@ GSIndustryControl
Saveload version: 287, GitHub pull request: 7912 and 8115 GS industry control.
Definition saveload.h:329
@ LinkFarmFieldToIndustry
Saveload version: 32, SVN revision: 6001 Link farm fields to the industry, so it gets removed when t...
Definition saveload.h:87
@ ConsistentPartialZ
Saveload version: 306, GitHub pull request: 10570 Conversion from an inconsistent partial Z calculat...
Definition saveload.h:352
bool IsSavegameVersionBeforeOrAt(SaveLoadVersion major)
Checks whether the savegame is below or at major.
Definition saveload.h:1239
Functions/types related to errors from savegames.
Functions related to saving and loading games.
Declaration of functions used in more save/load files.
void AfterLoadVehiclesPhase1(bool part_of_load)
Called after load for phase 1 of vehicle initialisation.
void ResetOldNames()
Free the memory of the old names array.
void FixupTrainLengths()
Fixup old train spacing.
void MoveBuoysToWaypoints()
Perform all steps to upgrade from the old station buoys to the new version that uses waypoints.
void UpdateOldAircraft()
need to be called to load aircraft from old version
void ConvertOldMultiheadToNew()
Converts all trains to the new subtype format introduced in savegame 16.2 It also links multiheaded e...
void ConnectMultiheadedTrains()
Link front and rear multiheaded engines to each other This is done when loading a savegame.
void AfterLoadRoadStops()
(Re)building of road stop caches after loading a savegame.
void MoveWaypointsToBaseStations()
Perform all steps to upgrade from the old waypoints to the new version that uses station.
void AfterLoadVehiclesPhase2(bool part_of_load)
Called after load for phase 2 of vehicle initialisation.
void UpdateHousesAndTowns()
Check and update town and house values.
Definition town_sl.cpp:64
std::string CopyFromOldName(StringID id)
Copy and convert old custom names to UTF-8.
void AfterLoadStoryBook()
Called after load to trash broken pages.
Definition story_sl.cpp:20
void ShowScriptDebugWindowIfScriptError()
Open the AI debug window if one of the AI scripts has crashed.
Window for configuring the scripts.
VehicleDefaultSettings _old_vds
Used for loading default vehicles settings from old savegames.
Definition settings.cpp:63
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition settings.cpp:62
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
IndustryDensity
Available industry map generation densities.
@ FundedOnly
The game does not build industries.
@ EndOfLineOnly
Trains can only flip when the track ends.
@ All
Trains can flip anywhere.
@ Right
Drive on the right side.
Base for ships.
@ Combo
presignal inter-block.
Definition signal_type.h:26
@ Electric
Light signal.
Definition signal_type.h:15
@ Semaphore
Old-fashioned semaphore signal.
Definition signal_type.h:16
void UpdateAllSignVirtCoords()
Update the coordinates of all signs.
Definition signs.cpp:50
Base class for signs.
Functions related to signs.
DiagDirection GetInclinedSlopeDirection(Slope s)
Returns the direction of an inclined slope.
Definition slope_func.h:249
void BuildOwnerLegend()
Completes the array for the owned property legend.
Smallmap GUI functions.
@ Industry
Source/destination is an industry.
Definition source_type.h:21
@ Town
Source/destination is a town.
Definition source_type.h:22
Base classes/functions for stations.
void UpdateAllStationVirtCoords()
Update the virtual coords needed to draw the station sign for all stations.
void UpdateAirportsNoise()
Recalculate the noise generated by the airports of each town.
void UpdateStationAcceptance(Station *st, bool show_msg)
Update the acceptance for a station.
Functions related to stations.
StationType GetStationType(Tile t)
Get the station type of this tile.
Definition station_map.h:42
StationGfx GetStationGfx(Tile t)
Get the station graphics of this tile.
Definition station_map.h:66
void SetStationGfx(Tile t, StationGfx gfx)
Set the station graphics of this tile.
Definition station_map.h:78
bool IsAirportTile(Tile t)
Is this tile a station tile and an airport tile?
bool IsBayRoadStopTile(Tile t)
Is tile t a bay (non-drive through) road stop station?
bool IsRailWaypointTile(Tile t)
Is this tile a station tile and a rail waypoint?
bool IsBuoy(Tile t)
Is tile t a buoy tile?
bool IsDriveThroughStopTile(Tile t)
Is tile t a drive through road stop station or waypoint?
bool HasStationTileRail(Tile t)
Has this station tile a rail?
uint GetCustomStationSpecIndex(Tile t)
Get the custom station spec for this tile.
void SetRailStationReservation(Tile t, bool b)
Set the reservation state of the rail station.
bool IsAnyRoadStop(Tile t)
Is the station at t a road station?
bool IsStationTileBlocked(Tile t)
Is tile t a blocked tile?
bool IsTruckStop(Tile t)
Is the station at t a truck stop?
uint8_t StationGfx
Index of station graphics.
Definition station_map.h:18
bool IsStationRoadStop(Tile t)
Is the station at t a road station?
bool HasStationRail(Tile t)
Has this station tile a rail?
static const int GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET
The offset for the drive through parts.
Definition station_map.h:34
bool IsOilRig(Tile t)
Is tile t part of an oilrig?
bool IsBuoyTile(Tile t)
Is tile t a buoy tile?
bool IsDock(Tile t)
Is tile t a dock tile?
@ Dock
Station with a dock.
@ Train
Station with train station.
@ Airport
Station with an airport.
StationType
Station types.
@ Dock
Ship port.
@ Rail
Railways/train station.
@ Bus
Road stop for busses.
@ Truck
Road stop for trucks.
@ Buoy
Waypoint for ships.
@ Oilrig
Heliport on an oil rig.
@ Airport
Airports and heliports, excluding the ones on oil rigs.
Definition of base types and functions in a cross-platform compatible way.
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
Definition string.cpp:76
Functions related to low-level strings.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:89
Functions related to OTTD's strings.
static constexpr uint16_t SPECSTR_TOWNNAME_START
Special strings for town names.
static constexpr StringID SPECSTR_PRESIDENT_NAME
Special string for the president's name.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
Information about a aircraft vehicle.
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition aircraft.h:75
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Base class for all station-ish types.
TileArea train_station
Tile area the train 'station' part covers.
Owner owner
The owner of this station.
Town * town
The town this station is associated with.
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
TileArea spread
NOSAVE: Station spread tile area.
VehicleType type
Type of vehicle.
static void AfterLoad()
Savegame conversion for cargopackets.
Helper class to perform the cargo payment.
Specification of a cargo type.
Definition cargotype.h:76
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo type.
Definition cargotype.h:140
TownAcceptanceEffect town_acceptance_effect
The effect that delivering this cargo type has on towns. Also affects destination of subsidies.
Definition cargotype.h:88
Structure to return information about the closest depot location, and whether it could be found.
CompanySettings settings
settings specific for each company
static bool IsValidAiID(auto index)
Is this company a valid company, controlled by the computer (a NoAI program)?
Disasters, like submarines, skyrangers and their shadows, belong to this class.
Basic data to distinguish a GRF.
MD5Hash md5sum
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF).
Stores station stats for a single cargo.
uint8_t last_speed
Maximum speed (up to 255) of the last vehicle that tried to load this cargo.
States status
Status of this cargo, see State.
@ Rating
This indicates whether a cargo has a rating at the station.
uint AvailableCount() const
Returns sum of cargo still available for loading at the station.
GroundVehicleFlags gv_flags
static void UpdateAfterLoad()
Update all caches after loading a game, changing NewGRF, etc.
Group data.
Definition group.h:76
Defines the data structure for constructing industry.
std::array< CargoType, INDUSTRY_NUM_INPUTS > accepts_cargo
16 accepted cargoes.
IndustryBehaviours behaviour
How this industry will behave, and how others entities can use it.
Defines the internal data of a functional industry.
Definition industry.h:64
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition industry.h:253
static uint SizeX()
Get the size of the map along the X.
Definition map_func.h:262
static uint SizeY()
Get the size of the map along the Y.
Definition map_func.h:271
static IterateWrapper Iterate()
Returns an iterable ensemble of all Tiles.
Definition map_func.h:366
static uint MaxY()
Gets the maximum Y coordinate within the map, including TileType::Void.
Definition map_func.h:298
static uint MaxX()
Gets the maximum X coordinate within the map, including TileType::Void.
Definition map_func.h:289
An object, such as transmitter, on the map.
Definition object_base.h:23
ObjectType type
Type of the object.
Definition object_base.h:24
Town * town
Town the object is built in.
Definition object_base.h:25
static void IncTypeCount(ObjectType type)
Increment the count of objects for this type.
Definition object_base.h:42
TimerGameCalendar::Date build_date
Date of construction.
Definition object_base.h:27
TileArea location
Location of the object.
Definition object_base.h:26
Data for backing up an order of a vehicle so it can be restored after a vehicle is rebuilt in the sam...
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
Definition order_base.h:383
If you change this, keep in mind that it is also saved in 2 other places:
Definition order_base.h:33
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition order_base.h:66
static Pool::IterateWrapper< Town > Iterate(size_t from=0)
static T * Create(Targs &&... args)
static Town * Get(auto index)
static Company * GetIfValid(auto index)
A Stop for a Road Vehicle.
Buses, trucks and trams belong to this class.
Definition roadveh.h:105
uint8_t state
Definition roadveh.h:107
RoadType roadtype
NOSAVE: Roadtype of this vehicle.
Definition roadveh.h:115
All ships have this type.
Definition ship.h:39
static bool IsExpected(const BaseStation *st)
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
static Station * Get(auto index)
static Station * GetIfValid(auto index)
static Station * From(BaseStation *st)
T * Next() const
Get next vehicle in the chain.
static Train * From(Vehicle *v)
Station data structure.
RoadStop * bus_stops
All the road stops.
static void RecomputeCatchmentForAll()
Recomputes catchment of all stations.
Definition station.cpp:513
RoadStop * truck_stops
All the truck stops.
Struct about subsidies, offered and awarded.
Town data structure.
Definition town.h:64
Track status of a tile.
Definition track_type.h:105
TrackdirBits trackdirs
Trackdirs present on the tile.
Definition track_type.h:106
'Train' is either a loco or a wagon.
Definition train.h:97
TrackBits track
On which track the train currently is.
Definition train.h:110
VehicleRailFlags flags
Which flags has this train currently set.
Definition train.h:98
Default settings for vehicles.
Vehicle data structure.
CargoPayment * cargo_payment
The cargo payment we're currently in.
Direction direction
facing
VehStates vehstatus
Status.
Order current_order
The current order (+ status, like: loading).
int32_t y_pos
y coordinate.
int32_t x_pos
x coordinate.
TileIndex tile
Current tile index.
Owner owner
Which company owns the vehicle?
Representation of a waypoint.
void RebuildSubsidisedSourceAndDestinationCache()
Perform a full rebuild of the subsidies cache.
Definition subsidy.cpp:103
Subsidy base class.
Functions related to subsidies.
bool MayAnimateTile(TileIndex tile)
Test if a tile may be animated.
Definition tile_cmd.h:269
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
Definition tile_map.cpp:94
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition tile_map.cpp:135
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition tile_map.cpp:115
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
uint TileHash(uint x, uint y)
Calculate a hash value from a tile position.
Definition tile_map.h:324
static uint TileHeight(Tile tile)
Returns the height of a tile.
Definition tile_map.h:29
bool IsTileOwner(Tile tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition tile_map.h:214
void SetTileType(Tile tile, TileType type)
Set the type of a tile.
Definition tile_map.h:131
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
void SetTileOwner(Tile tile, Owner owner)
Sets the owner of a tile.
Definition tile_map.h:198
int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
Definition tile_map.h:312
void SetAnimationFrame(Tile t, uint8_t frame)
Set a new animation frame.
Definition tile_map.h:262
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
Definition tile_map.h:279
void SetTropicZone(Tile tile, TropicZone type)
Set the tropic zone.
Definition tile_map.h:225
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
static constexpr uint TILE_UNIT_MASK
For masking in/out the inner-tile world coordinate units.
Definition tile_type.h:16
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:92
@ Normal
Normal tropiczone.
Definition tile_type.h:82
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
static constexpr uint TILE_SIZE
Tile size in world coordinates.
Definition tile_type.h:15
static constexpr uint MIN_SNOWLINE_HEIGHT
Minimum snowline height.
Definition tile_type.h:32
static constexpr uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in ZOOM_BASE.
Definition tile_type.h:18
@ TunnelBridge
Tunnel entry/exit and bridge heads.
Definition tile_type.h:58
@ Water
Water tile.
Definition tile_type.h:55
@ Station
A tile of a station or airport.
Definition tile_type.h:54
@ Object
Contains objects such as transmitters and owned land.
Definition tile_type.h:59
@ Industry
Part of an industry.
Definition tile_type.h:57
@ Railway
A tile with railway.
Definition tile_type.h:50
@ Void
Invisible tiles at the SW and SE border.
Definition tile_type.h:56
@ Trees
Tile with one or more trees.
Definition tile_type.h:53
@ House
A house by a town.
Definition tile_type.h:52
@ Road
A tile with road and/or tram tracks.
Definition tile_type.h:51
@ Clear
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition tile_type.h:49
Definition of Interval and OneShot timers.
Definition of the game-calendar-timer.
Definition of the game-economy-timer.
Definition of the tick-based game-timer.
Base of the town class.
static const uint TOWN_GROWTH_WINTER
The town only needs this cargo in the winter (any amount).
Definition town.h:32
const CargoSpec * FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect effect)
Determines the first cargo with a certain town effect.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
static const uint TOWN_GROWTH_DESERT
The town needs the cargo for growth when on desert (any amount).
Definition town.h:33
void UpdateTownMaxPass(Town *t)
Update the maximum amount of monthly passengers and mail for a town, based on its population.
void ClearAllTownCachedNames()
Clear the cached_name of all towns.
Definition town_cmd.cpp:413
Town * CalcClosestTownFromTile(TileIndex tile, uint threshold=UINT_MAX)
Return the town closest to the given tile within threshold.
@ CustomGrowth
Growth rate is controlled by GS.
Definition town.h:45
static const uint16_t TOWN_GROWTH_RATE_NONE
Special value for Town::growth_rate to disable town growth.
Definition town.h:34
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
Definition town.h:335
void UpdateAllTownVirtCoords()
Update the virtual coords needed to draw the town sign for all towns.
Definition town_cmd.cpp:405
HouseID GetHouseType(Tile t)
Get the type of this house, which is an index into the house spec array.
Definition town_map.h:60
void SetHouseType(Tile t, HouseID house_id)
Set the house type.
Definition town_map.h:71
void SetLiftPosition(Tile t, uint8_t pos)
Set the position of the lift on this animated house.
Definition town_map.h:157
void SetHouseCompleted(Tile t, bool status)
Mark this house as been completed.
Definition town_map.h:178
void SetTownIndex(Tile t, TownID index)
Set the town index for a road or house tile.
Definition town_map.h:35
bool IsHouseCompleted(Tile t)
Get the completion of this house.
Definition town_map.h:167
static constexpr int RATING_INITIAL
initial rating
Definition town_type.h:44
@ Original
Original algorithm (quadratic cargo by population).
Definition town_type.h:112
TownLayout
Town Layouts.
Definition town_type.h:83
@ Random
Random town layout.
Definition town_type.h:89
@ BetterRoads
Extended original algorithm (min. 2 distance between roads).
Definition town_type.h:85
Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition track_func.h:432
Track AxisToTrack(Axis a)
Convert an Axis to the corresponding Track Axis::X -> Track::X Axis::Y -> Track::Y Uses the fact that...
Definition track_func.h:62
Track DiagDirToDiagTrack(DiagDirection diagdir)
Maps a DiagDirection to the associated diagonal Track.
Definition track_func.h:419
TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
Definition track_func.h:281
EnumBitSet< Track, uint8_t > TrackBits
Bitset of Track elements.
Definition track_type.h:43
@ X
Track along the x-axis (north-east to south-west).
Definition track_type.h:21
@ Upper
Track in the upper corner of the tile (north).
Definition track_type.h:23
@ Invalid
Flag for an invalid track.
Definition track_type.h:32
@ Y
Track along the y-axis (north-west to south-east).
Definition track_type.h:22
@ Depot
Special flag indicating a vehicle is inside a depot.
Definition track_type.h:30
@ Lower
Track in the lower corner of the tile (south).
Definition track_type.h:24
@ Wormhole
Special flag indicating vehicle is inside a bridge or tunnel.
Definition track_type.h:29
Base for the train class.
void CheckTrainsLengths()
Checks if lengths of all rail vehicles are valid.
Definition train_cmd.cpp:87
VehicleRailFlag
Rail vehicle flags.
Definition train.h:25
@ TFP_NONE
Normal operation.
Definition train.h:40
@ TFP_STUCK
Proceed till next signal, but ignore being stuck till then. This includes force leaving depots.
Definition train.h:41
TransportType
Available types of transport.
@ Rail
Transport by train.
@ Road
Transport by road vehicle.
Map accessors for tree tiles.
TreeGround GetTreeGround(Tile t)
Returns the groundtype for tree tiles.
Definition tree_map.h:102
TreeGround
Enumeration for ground types of tiles with trees.
Definition tree_map.h:52
@ SnowOrDesert
Snow or desert, depending on landscape.
Definition tree_map.h:55
@ Shore
Shore.
Definition tree_map.h:56
bool IsTunnelTile(Tile t)
Is this a tunnel (entrance)?
Definition tunnel_map.h:34
const DiagDirectionIndexArray< uint8_t > _tunnel_visibility_frame
Frame when a vehicle should be hidden in a tunnel with a certain direction.
Functions that have tunnels and bridges in common.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
TileIndex GetOtherTunnelBridgeEnd(Tile t)
Determines type of the wormhole and returns its other end.
void SetTunnelBridgeReservation(Tile t, bool b)
Set the reservation state of the rail tunnel/bridge.
@ Crashed
Vehicle is crashed.
@ Hidden
Vehicle is not visible.
EnumBitSet< VehState, uint8_t > VehStates
Bitset of VehState elements.
Functions related to vehicles.
@ Ship
Ship vehicle type.
@ Invalid
Non-existing type of vehicle.
@ Road
Road vehicle type.
@ Train
Train vehicle type.
@ Original
Original acceleration model.
EnumBitSet< GroundVehicleFlag, uint16_t > GroundVehicleFlags
Bitset of GroundVehicleFlag elements.
@ GoingUp
Vehicle is currently going uphill. (Cached track information for acceleration).
@ GoingDown
Vehicle is currently going downhill. (Cached track information for acceleration).
Functions related to (drawing on) viewports.
Declarations for accessing the k-d tree of viewports.
Map accessors for void tiles.
void MakeVoid(Tile t)
Make a nice void tile ;).
Definition void_map.h:19
void SetWaterClass(Tile t, WaterClass wc)
Set the water class at a tile.
Definition water_map.h:128
bool IsShipDepot(Tile t)
Is it a water tile with a ship depot on it?
Definition water_map.h:227
WaterClass
classes of water (for WaterTileType::Clear water tile type).
Definition water_map.h:41
@ River
River.
Definition water_map.h:44
@ Invalid
Used for industry tiles on land (also for oilrig if newgrf says so).
Definition water_map.h:45
@ Canal
Canal.
Definition water_map.h:43
@ Sea
Sea.
Definition water_map.h:42
bool IsShipDepotTile(Tile t)
Is it a ship depot tile?
Definition water_map.h:237
bool IsCoast(Tile t)
Is it a coast tile?
Definition water_map.h:205
WaterTileType GetWaterTileType(Tile t)
Get the water tile type of a tile.
Definition water_map.h:82
void SetNonFloodingWaterTile(Tile t, bool b)
Set the non-flooding water tile state of a tile.
Definition water_map.h:538
void SetWaterTileType(Tile t, WaterTileType type)
Set the water tile type of a tile.
Definition water_map.h:93
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
Definition water_map.h:116
void MakeCanal(Tile t, Owner o, uint8_t random_bits)
Make a canal tile.
Definition water_map.h:455
TileIndex GetOtherShipDepotTile(Tile t)
Get the other tile of the ship depot.
Definition water_map.h:283
void MakeShore(Tile t, bool rocks=false)
Helper function to make a coast tile.
Definition water_map.h:389
@ Coast
Coast.
Definition water_map.h:33
@ Depot
Water Depot.
Definition water_map.h:35
@ Lock
Water lock.
Definition water_map.h:34
@ Clear
Plain water.
Definition water_map.h:32
void SetDockingTile(Tile t, bool b)
Set the docking tile state of a tile.
Definition water_map.h:367
@ Middle
Middle part of a lock.
Definition water_map.h:68
bool IsWater(Tile t)
Is it a plain water tile?
Definition water_map.h:151
bool IsLock(Tile t)
Is there a lock on a given water tile?
Definition water_map.h:308
void MakeSea(Tile t, bool rocks=false)
Make a sea tile.
Definition water_map.h:434
LockPart GetLockPart(Tile t)
Get the part of a lock.
Definition water_map.h:331
Base of waypoints.
void ResetWindowSystem()
Reset the windowing system, by means of shutting it down followed by re-initialization.
Definition window.cpp:1941
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:3377
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:3395
Window functions not directly related to making/drawing windows.
Entry point for OpenTTD to YAPF's cache.
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
Use this function to notify YAPF that track layout (or signal configuration) has change.