# 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 "../window_func.h"`
`#include "../fios.h"`
`#include "../gamelog_internal.h"`
`#include "../network/network.h"`
`#include "../gfxinit.h"`
`#include "../functions.h"`
`#include "../industry.h"`
`#include "../clear_map.h"`
`#include "../vehicle_func.h"`
`#include "../debug.h"`
`#include "../string_func.h"`
`#include "../date_func.h"`
`#include "../roadveh.h"`
`#include "../train.h"`
`#include "../station_base.h"`
`#include "../waypoint_base.h"`
`#include "../roadstop_base.h"`
`#include "../tunnelbridge_map.h"`
`#include "../landscape.h"`
`#include "../pathfinder/yapf/yapf_cache.h"`
`#include "../elrail_func.h"`
`#include "../signs_func.h"`
`#include "../aircraft.h"`
`#include "../unmovable_map.h"`
`#include "../tree_map.h"`
`#include "../company_func.h"`
`#include "../road_cmd.h"`
`#include "../ai/ai.hpp"`
`#include "../ai/ai_gui.hpp"`
`#include "../town.h"`
`#include "../economy_base.h"`
`#include "../animated_tile_func.h"`
`#include "../subsidy_base.h"`
`#include "../subsidy_func.h"`
`#include "../company_base.h"`
`#include "../newgrf.h"`
`#include "../engine_base.h"`
`#include "../engine_func.h"`
`#include "table/strings.h"`
`#include "saveload_internal.h"`
`#include <signal.h>`

Go to the source code of this file.

## Typedefs
typedef void(CDECL * | SignalHandlerPointer )(int)
## Functions
Company * | DoStartupNewCompany (bool is_ai, CompanyID company=INVALID_COMPANY)
| Create a new company and sets all company variables default values.
void | InitializeRailGUI ()
| Resets the rail GUI - sets default railtype to build and resets the signal GUI.
void | SetWaterClassDependingOnSurroundings (TileIndex t, bool include_invalid_water_class)
| Makes a tile canal or water depending on the surroundings.
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.
static void | InitializeWindowsAndCaches ()
| Initialization of the windows and several kinds of caches.
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.
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.
static const GRFIdentifier * | GetOverriddenIdentifier (const GRFConfig *c)
| Try to find the overridden GRF identifier of the given GRF.
bool | SaveloadCrashWithMissingNewGRFs ()
| Did loading the savegame cause a crash? If so, were NewGRFs missing?
static void | FixOwnerOfRailTrack (TileIndex t)
| Tries to change owner of this rail tile to a valid owner.
bool | AfterLoadGame ()
void | ReloadNewGRFData ()
| Reload all NewGRF files during a running game.
## Variables
StringID | _switch_mode_errorstr
static const byte | convert_currency []
static SignalHandlerPointer | _prev_segfault = NULL
static SignalHandlerPointer | _prev_abort = NULL
static SignalHandlerPointer | _prev_fpe = NULL
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

Company* DoStartupNewCompany | ( | bool | is_ai,
|  | CompanyID | company = `INVALID_COMPANY` |
| ) |  |  |

Create a new company and sets all company variables default values.

Parameters:

  | is_ai | is a ai company?
  | company | CompanyID to use for the new company

Returns:
  the company struct

Definition at line 464 of file company_cmd.cpp.

References _company_colours, _cur_year, _network_server, _networking, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::CanAllocateItem(), GetCompanyRailtypes(), GetCompanyRoadtypes(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::GetPoolSize(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_COMPANY, INVALID_OWNER, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), Company::num_engines, RandomCompanyManagerFaceBits(), ResetCompanyLivery(), SetDefaultCompanySettings(), SetWindowDirty(), and AI::StartNew().

Referenced by CmdCompanyCtrl().

static void FixOwnerOfRailTrack | ( | TileIndex | 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:

  | t | tile to update

Definition at line 387 of file afterload.cpp.

References CLEAR_GRASS, DIAGDIR_BEGIN, DIAGDIR_END, GetTileOwner(), GetTileTrackStatus(), GetTownIndex(), IsPlainRailTile(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), MakeClear(), ReverseDiagDir(), ROADTYPE_ROAD, ROADTYPE_TRAM, SetTileOwner(), TileOffsByDiagDir(), and TRANSPORT_RAIL.

static const GRFIdentifier* GetOverriddenIdentifier | ( | const GRFConfig * | c | ) | `[static]`

Try to find the overridden GRF identifier of the given GRF.

Parameters:

  | c | the GRF to get the 'previous' version of.

Returns:
  the GRF identifier or c if none could be found.

Definition at line 303 of file afterload.cpp.

References _gamelog_action, _gamelog_actions, LoggedAction::at, LoggedAction::change, LoggedAction::changes, GLAT_LOAD, GLCT_GRFCOMPAT, LoggedChange::grfcompat, and GRFIdentifier::grfid.

Referenced by 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:

  | signum | received signal

Definition at line 335 of file afterload.cpp.

References _grfconfig, BSWAP32(), GCF_COMPATIBLE, GCS_NOT_FOUND, GetOverriddenIdentifier(), HasBit(), lastof, GRFIdentifier::md5sum, md5sumToString(), GRFConfig::next, ResetSignalHandlers(), and seprintf().

Referenced by SetSignalHandlers().

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 intialization 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 233 of file afterload.cpp.

References _cur_year, CheckTrainsLengths(), SmallFiosItem::filetype, FT_SCENARIO, MIN_YEAR, Station::RecomputeIndustriesNearForAll(), RecomputePrices(), ResetWindowSystem(), SetCachedEngineCounts(), ShowAIDebugWindowIfAIError(), ShowNewGRFError(), UpdateAirportsNoise(), and UpdateAllVirtCoords().

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 2093 of file afterload.cpp.

References AfterLoadVehicles(), CheckTrainsLengths(), COMPANY_FIRST, InvalidateWindowData(), LoadStringWidthTable(), MarkWholeScreenDirty(), MAX_COMPANIES, RecomputePrices(), SetCachedEngineCounts(), and UpdateHousesAndTowns().

Referenced by ChangeDynamicEngines(), ClickChangeClimateCheat(), NewGRFConfirmationCallback(), and NewGRFWindow::OnClick().

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 324 of file afterload.cpp.

Referenced by HandleCrash().

void SetWaterClassDependingOnSurroundings | ( | TileIndex | 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:

  | t | the tile to change.
  | include_invalid_water_class | Also consider WATER_CLASS_INVALID, i.e. industry tiles on land

Definition at line 75 of file afterload.cpp.

References _m, DIAGDIR_BEGIN, DIAGDIR_END, GB(), GetTileSlope(), GetTileType(), MapMaxX(), MapMaxY(), MarkTileDirtyByTile(), MP_RAILWAY, MP_TREES, MP_WATER, RAIL_GROUND_WATER, SLOPE_FLAT, TileAddByDiagDir(), TileX(), TileY(), TREE_GROUND_SHORE, and WATER_CLASS_INVALID.

## Variable Documentation

const byte 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 184 of file afterload.cpp.