OpenTTD Source  20241108-master-g80f628063a
afterload.cpp File Reference

Code updating data after game load. More...

#include "../stdafx.h"
#include "../void_map.h"
#include "../signs_base.h"
#include "../depot_base.h"
#include "../fios.h"
#include "../gamelog_internal.h"
#include "../network/network.h"
#include "../network/network_func.h"
#include "../gfxinit.h"
#include "../viewport_func.h"
#include "../viewport_kdtree.h"
#include "../industry.h"
#include "../clear_map.h"
#include "../vehicle_func.h"
#include "../string_func.h"
#include "../roadveh.h"
#include "../roadveh_cmd.h"
#include "../train.h"
#include "../station_base.h"
#include "../waypoint_base.h"
#include "../roadstop_base.h"
#include "../tunnelbridge_map.h"
#include "../pathfinder/yapf/yapf_cache.h"
#include "../elrail_func.h"
#include "../signs_func.h"
#include "../aircraft.h"
#include "../object_map.h"
#include "../object_base.h"
#include "../tree_map.h"
#include "../company_func.h"
#include "../road_cmd.h"
#include "../ai/ai.hpp"
#include "../script/script_gui.h"
#include "../game/game.hpp"
#include "../town.h"
#include "../economy_base.h"
#include "../animated_tile_func.h"
#include "../subsidy_base.h"
#include "../subsidy_func.h"
#include "../newgrf.h"
#include "../newgrf_station.h"
#include "../engine_func.h"
#include "../rail_gui.h"
#include "../core/backup_type.hpp"
#include "../smallmap_gui.h"
#include "../news_func.h"
#include "../order_backup.h"
#include "../error.h"
#include "../disaster_vehicle.h"
#include "../ship.h"
#include "../water.h"
#include "../timer/timer.h"
#include "../timer/timer_game_calendar.h"
#include "../timer/timer_game_economy.h"
#include "../timer/timer_game_tick.h"
#include "saveload_internal.h"
#include <signal.h>
#include "../safeguards.h"
#include "window_func.h"

Go to the source code of this file.

Typedefs

typedef void(CDECL * SignalHandlerPointer) (int)
 

Functions

CompanyDoStartupNewCompany (bool is_ai, CompanyID company=INVALID_COMPANY)
 Create a new company and sets all company variables default values. More...
 
void SetWaterClassDependingOnSurroundings (Tile t, bool include_invalid_water_class)
 Makes a tile canal or water depending on the surroundings. More...
 
static void ConvertTownOwner ()
 
static void UpdateExclusiveRights ()
 
static void UpdateCurrencies ()
 
static void UpdateVoidTiles ()
 
static RailType UpdateRailType (RailType rt, RailType min)
 
void UpdateAllVirtCoords ()
 Update the viewport coordinates of all signs.
 
void ClearAllCachedNames ()
 
static void InitializeWindowsAndCaches ()
 Initialization of the windows and several kinds of caches. More...
 
static void CDECL HandleSavegameLoadCrash (int signum)
 Signal handler used to give a user a more useful report for crashes during the savegame loading process; especially when there's problems with the NewGRFs that are required by the savegame. More...
 
static void SetSignalHandlers ()
 Replaces signal handlers of SIGSEGV and SIGABRT and stores pointers to original handlers in memory.
 
static void ResetSignalHandlers ()
 Resets signal handlers back to original handlers.
 
bool SaveloadCrashWithMissingNewGRFs ()
 Did loading the savegame cause a crash? If so, were NewGRFs missing? More...
 
static void FixOwnerOfRailTrack (Tile t)
 Tries to change owner of this rail tile to a valid owner. More...
 
static uint FixVehicleInclination (Vehicle *v, Direction dir)
 Fixes inclination of a vehicle. More...
 
static void CheckGroundVehiclesAtCorrectZ ()
 Check whether the ground vehicles are at the correct Z-coordinate. More...
 
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 which a bridge can be found. More...
 
static void StartScripts ()
 Start the scripts.
 
bool AfterLoadGame ()
 Perform a (large) amount of savegame conversion magic in order to load older savegames and to fill the caches for various purposes. More...
 
void ReloadNewGRFData ()
 Reload all NewGRF files during a running game. More...
 

Variables

static const uint8_t convert_currency []
 
static SignalHandlerPointer _prev_segfault = nullptr
 
static SignalHandlerPointer _prev_abort = nullptr
 
static SignalHandlerPointer _prev_fpe = nullptr
 
static bool _saveload_crash_with_missing_newgrfs = false
 Was the saveload crash because of missing NewGRFs?
 

Detailed Description

Code updating data after game load.

Definition in file afterload.cpp.

Function Documentation

◆ AfterLoadGame()

bool AfterLoadGame ( )

Perform a (large) amount of savegame conversion magic in order to load older savegames and to fill the caches for various purposes.

Returns
True iff conversion went without a problem.

< Flag for coast.

Definition at line 565 of file afterload.cpp.

References SetSignalHandlers().

◆ CheckGroundVehiclesAtCorrectZ()

static void CheckGroundVehiclesAtCorrectZ ( )
static

Check whether the ground vehicles are at the correct Z-coordinate.

When they are not, this will cause all kinds of problems later on as the vehicle might not get onto bridges and so on.

Definition at line 516 of file afterload.cpp.

References GetSlopePixelZ(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), and TileVirtXY().

◆ DoStartupNewCompany()

◆ FixOwnerOfRailTrack()

static void FixOwnerOfRailTrack ( Tile  t)
static

Tries to change owner of this rail tile to a valid owner.

In very old versions it could happen that a rail track had an invalid owner. When conversion isn't possible, track is removed.

Parameters
ttile to update

Definition at line 423 of file afterload.cpp.

References DIAGDIR_BEGIN, DIAGDIR_END, GetRoadOwner(), GetTileOwner(), GetTileTrackStatus(), IsLevelCrossingTile(), IsPlainRailTile(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), SpecializedVehicle< T, Type >::Iterate(), Vehicle::owner, ReverseDiagDir(), SetTileOwner(), TileOffsByDiagDir(), and TRANSPORT_RAIL.

◆ FixVehicleInclination()

static uint FixVehicleInclination ( Vehicle v,
Direction  dir 
)
static

Fixes inclination of a vehicle.

Older OpenTTD versions didn't update the bits correctly.

Parameters
vvehicle
dirvehicle's direction, or # INVALID_DIR if it can be ignored
Returns
inclination bits to set

Definition at line 481 of file afterload.cpp.

References DIR_NE, DIR_NW, DIR_SE, DIR_SW, INVALID_DIR, TILE_UNIT_MASK, Vehicle::x_pos, and Vehicle::y_pos.

◆ HandleSavegameLoadCrash()

static void CDECL HandleSavegameLoadCrash ( int  signum)
static

Signal handler used to give a user a more useful report for crashes during the savegame loading process; especially when there's problems with the NewGRFs that are required by the savegame.

Parameters
signumreceived signal

Definition at line 363 of file afterload.cpp.

References _gamelog, _grfconfig, _saveload_crash_with_missing_newgrfs, BSWAP32(), FormatArrayAsHex(), GCF_COMPATIBLE, GCS_NOT_FOUND, Gamelog::GetOverriddenIdentifier(), HasBit(), GRFIdentifier::md5sum, GRFConfig::next, and ResetSignalHandlers().

◆ InitializeWindowsAndCaches()

static void InitializeWindowsAndCaches ( )
static

Initialization of the windows and several kinds of caches.

This is not done directly in AfterLoadGame because these functions require that all saveload conversions have been done. As people tend to add savegame conversion stuff after the initialization of the windows and caches quite some bugs had been made. Moving this out of there is both cleaner and less bug-prone.

Definition at line 248 of file afterload.cpp.

References ResetWindowSystem(), and SetupColoursAndInitialWindow().

◆ MayHaveBridgeAbove()

static bool MayHaveBridgeAbove ( Tile  t)
inlinestatic

Checks for the possibility that a bridge may be on this tile These are in fact all the tile types on which a bridge can be found.

Parameters
tThe tile to analyze
Returns
True if a bridge might have been present prior to savegame 194.

Definition at line 536 of file afterload.cpp.

References IsTileType(), MP_CLEAR, MP_OBJECT, MP_RAILWAY, MP_ROAD, MP_TUNNELBRIDGE, and MP_WATER.

◆ ReloadNewGRFData()

void ReloadNewGRFData ( )

Reload all NewGRF files during a running game.

This is a cut-down version of AfterLoadGame(). XXX - We need to reset the vehicle position hash because with a non-empty hash AfterLoadVehicles() will loop infinitely. We need AfterLoadVehicles() to recalculate vehicle data as some NewGRF vehicle sets could have been removed or added and changed statistics

Definition at line 3364 of file afterload.cpp.

References GfxLoadSprites(), LoadStringWidthTable(), and RecomputePrices().

Referenced by ClickChangeMaxHlCheat(), and NewGRFConfirmationCallback().

◆ SaveloadCrashWithMissingNewGRFs()

bool SaveloadCrashWithMissingNewGRFs ( )

Did loading the savegame cause a crash? If so, were NewGRFs missing?

Returns
when the saveload crashed due to missing NewGRFs.

Definition at line 352 of file afterload.cpp.

References _saveload_crash_with_missing_newgrfs.

Referenced by HandleCrash().

◆ SetWaterClassDependingOnSurroundings()

void SetWaterClassDependingOnSurroundings ( Tile  t,
bool  include_invalid_water_class 
)

Makes a tile canal or water depending on the surroundings.

Must only be used for converting old savegames. Use WaterClass now.

This as for example docks and shipdepots do not store whether the tile used to be canal or 'normal' water.

Parameters
tthe tile to change.
include_invalid_water_classAlso consider WATER_CLASS_INVALID, i.e. industry tiles on land

Definition at line 85 of file afterload.cpp.

References DIAGDIR_BEGIN, DIAGDIR_END, GetTileType(), GetWaterClass(), IsCoast(), IsLock(), IsTileFlat(), MarkTileDirtyByTile(), Map::MaxX(), Map::MaxY(), MP_RAILWAY, MP_WATER, SetWaterClass(), SlErrorCorrupt(), TileAddByDiagDir(), TileX(), TileY(), WATER_CLASS_CANAL, WATER_CLASS_INVALID, WATER_CLASS_RIVER, and WATER_CLASS_SEA.

Variable Documentation

◆ convert_currency

const uint8_t convert_currency[]
static
Initial value:
= {
0, 1, 12, 8, 3,
10, 14, 19, 4, 5,
9, 11, 13, 6, 17,
16, 22, 21, 7, 15,
18, 2, 20,
}

Definition at line 192 of file afterload.cpp.