# afterload.cpp File Reference

Code updating data after game load. More...

`#include "../stdafx.h"`
`#include "../void_map.h"`
`#include "../signs_base.h"`
`#include "../window_func.h"`
`#include "../fios.h"`
`#include "../train.h"`
`#include "../string_func.h"`
`#include "../gamelog.h"`
`#include "../network/network.h"`
`#include "../gfxinit.h"`
`#include "../functions.h"`
`#include "../industry_map.h"`
`#include "../town_map.h"`
`#include "../clear_map.h"`
`#include "../vehicle_func.h"`
`#include "../newgrf_station.h"`
`#include "../yapf/yapf.hpp"`
`#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 "table/strings.h"`
`#include "saveload_internal.h"`
`#include <signal.h>`

Go to the source code of this file.

## Functions
Company * | DoStartupNewCompany (bool is_ai)
| 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)
static bool | InitializeWindowsAndCaches ()
| Initialization of the windows and several kinds of caches.
void CDECL | HandleSavegameLoadCrash (int unused)
| 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 | 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 []

## Detailed Description

Code updating data after game load.

Definition in file afterload.cpp.

## Function Documentation

Company* DoStartupNewCompany | ( | bool | is_ai | ) |

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

Parameters:

  | is_ai | is a ai company?

Returns:
  the company struct

Definition at line 425 of file company_cmd.cpp.

References _company_colours, _cur_year, _settings_client, GUISettings::autorenew, GUISettings::autorenew_money, GUISettings::autorenew_months, GetCompanyRailtypes(), GetCompanyRoadtypes(), ClientSettings::gui, INVALID_OWNER, InvalidateWindow(), MAX_COMPANIES, RandomCompanyManagerFaceBits(), and ResetCompanyLivery().

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

References CLEAR_GRASS, DIAGDIR_BEGIN, DIAGDIR_END, GetTileOwner(), GetTileTrackStatus(), GetTownIndex(), IsPlainRailTile(), MakeClear(), ReverseDiagDir(), ROADTYPE_ROAD, ROADTYPE_TRAM, SetTileOwner(), TileOffsByDiagDir(), and TRANSPORT_RAIL.

void CDECL HandleSavegameLoadCrash | ( | int | unused | ) |

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:

  | unused | well... unused

Definition at line 244 of file afterload.cpp.

References _grfconfig, BSWAP32(), buf, GCF_COMPATIBLE, GCS_NOT_FOUND, HasBit(), lastof, md5sumToString(), GRFConfig::next, and seprintf().

static bool 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.

Returns:
  true if everything went according to plan, otherwise false.

Definition at line 202 of file afterload.cpp.

References _cur_year, CheckTrainsLengths(), FT_SCENARIO, ResetWindowSystem(), SetCachedEngineCounts(), UpdateAirportsNoise(), UpdateAllSignVirtCoords(), UpdateAllStationVirtCoord(), UpdateAllTownVirtCoords(), and UpdateAllWaypointSigns().

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

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

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

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.
  | o | the owner of the new tile.
  | include_invalid_water_class | Also consider WATER_CLASS_INVALID, i.e. industry tiles on land

Definition at line 52 of file afterload.cpp.

References DIAGDIR_BEGIN, DIAGDIR_END, GetTileSlope(), GetTileType(), GetTreeGround(), 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 161 of file afterload.cpp.