OpenTTD Source: src/saveload/saveload_internal.h File Reference

OpenTTD Source 15.3

Functions | Variables
saveload_internal.h File Reference

Declaration of functions used in more save/load files. More...

`#include "../company_manager_face.h"`
`#include "../order_base.h"`
`#include "../engine_type.h"`
`#include "saveload.h"`

Go to the source code of this file.

## Functions
void | InitializeOldNames ()
| Initialize the old names table memory.
StringID | RemapOldStringID (StringID s)
| Remap a string ID from the old format to the new format.
std::string | CopyFromOldName (StringID id)
| Copy and convert old custom names to UTF-8.
void | ResetOldNames ()
| Free the memory of the old names array.
void | ResetOldWaypoints ()
void | MoveBuoysToWaypoints ()
| Perform all steps to upgrade from the old station buoys to the new version that uses waypoints.
void | MoveWaypointsToBaseStations ()
| Perform all steps to upgrade from the old waypoints to the new version that uses station.
void | AfterLoadVehiclesPhase1 (bool part_of_load)
| Called after load for phase 1 of vehicle initialisation.
void | AfterLoadVehiclesPhase2 (bool part_of_load)
| Called after load for phase 2 of vehicle initialisation.
void | FixupTrainLengths ()
| Fixup old train spacing.
void | AfterLoadStations ()
void | AfterLoadRoadStops ()
| (Re)building of road stop caches after loading a savegame.
void | AfterLoadLabelMaps ()
| Perform rail type and road type conversion if necessary.
void | AfterLoadStoryBook ()
| Called after load to trash broken pages.
void | AfterLoadLinkGraphs ()
| Spawn the threads for running link graph calculations.
void | AfterLoadCompanyStats ()
| Rebuilding of company statistics after loading a savegame.
void | UpdateHousesAndTowns ()
| Check and update town and house values.
void | UpdateOldAircraft ()
| need to be called to load aircraft from old version
void | SaveViewportBeforeSaveGame ()
void | ResetViewportAfterLoadGame ()
void | ConvertOldMultiheadToNew ()
| Converts all trains to the new subtype format introduced in savegame 16.2 It also links multiheaded engines or make them forget they are multiheaded if no suitable partner is found.
void | ConnectMultiheadedTrains ()
| Link front and rear multiheaded engines to each other This is done when loading a savegame.
void | ResetTempEngineData ()
Engine * | GetTempDataEngine (EngineID index)
void | CopyTempEngineData ()
| Copy data from temporary engine array into the real engine pool.
CompanyManagerFace | ConvertFromOldCompanyManagerFace (uint32_t face)
| Converts an old company manager's face format to the new company manager's face format.
Order | UnpackOldOrder (uint16_t packed)
| Unpacks a order from savegames made with TTD(Patch)

## Variables
int32_t | _saved_scrollpos_x
int32_t | _saved_scrollpos_y
ZoomLevel | _saved_scrollpos_zoom
SavegameType | _savegame_type
| type of savegame we are loading
uint32_t | _ttdp_version
| version of TTDP savegame (if applicable)

## Detailed Description

Declaration of functions used in more save/load files.

Definition in file saveload_internal.h.

## Function Documentation

## ◆ AfterLoadCompanyStats()

void AfterLoadCompanyStats | ( |  | ) |

Rebuilding of company statistics after loading a savegame.

Definition at line 126 of file company_sl.cpp.

## ◆ AfterLoadLabelMaps()

void AfterLoadLabelMaps | ( |  | ) |

Perform rail type and road type conversion if necessary.

Definition at line 27 of file labelmaps_sl.cpp.

References ConvertRailTypes(), ConvertRoadTypes(), SetCurrentRailTypeLabelList(), and SetCurrentRoadTypeLabelList().

Referenced by AfterLoadGame(), and ReloadNewGRFData().

## ◆ AfterLoadLinkGraphs()

void AfterLoadLinkGraphs | ( |  | ) |

Spawn the threads for running link graph calculations.

Has to be done after loading as the cargo classes might have changed.

Definition at line 232 of file linkgraph_sl.cpp.

References _network_server, _networking, AfterLoad_LinkGraphPauseControl(), SpecializedStation< Station, false >::GetIfValid(), LinkGraphJob::Graph(), LinkGraphSchedule::instance, IsSavegameVersionBefore(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_link_graph_job_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_link_graph_pool >::Iterate(), LinkGraph::Size(), SLV_191, LinkGraphSchedule::SpawnAll(), and BaseStation::xy.

Referenced by AfterLoadGame().

## ◆ AfterLoadRoadStops()

void AfterLoadRoadStops | ( |  | ) |

(Re)building of road stop caches after loading a savegame.

Definition at line 144 of file station_sl.cpp.

References RoadStop::BaseEntry, DIAGDIR_NE, DIAGDIR_NW, IsDriveThroughStopTile(), and Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_roadstop_pool >::Iterate().

Referenced by AfterLoadGame().

## ◆ AfterLoadStations()

void AfterLoadStations | ( |  | ) |

Definition at line 111 of file station_sl.cpp.

## ◆ AfterLoadStoryBook()

void AfterLoadStoryBook | ( |  | ) |

Called after load to trash broken pages.

Definition at line 20 of file story_sl.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::CleanPool(), IsSavegameVersionBefore(), and SLV_185.

Referenced by AfterLoadGame().

## ◆ AfterLoadVehiclesPhase1()

void AfterLoadVehiclesPhase1 | ( | bool | part_of_load | ) |

Called after load for phase 1 of vehicle initialisation.

So we can set the #previous and #first pointers while loading.

For instantiating the shared vehicle chain.

Definition at line 256 of file vehicle_sl.cpp.

Referenced by AfterLoadGame(), and ReloadNewGRFData().

## ◆ AfterLoadVehiclesPhase2()

void AfterLoadVehiclesPhase2 | ( | bool | part_of_load | ) |

Called after load for phase 2 of vehicle initialisation.

Definition at line 420 of file vehicle_sl.cpp.

References _settings_game, AIR_HELICOPTER, CalcPercentVehicleFilled(), GroundVehicle< T, Type >::CargoChanged(), CCF_SAVELOAD, RoadVehicle::compatible_roadtypes, Train::ConsistChanged(), VehicleSpriteSeq::CopyWithoutPalette(), Vehicle::cur_speed, RoadVehicle::disaster_vehicle, EIT_ON_MAP, Vehicle::engine_type, SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedVehicle< T, Type >::From(), SpecializedVehicle< Ship, VEH_SHIP >::From(), SpecializedVehicle< DisasterVehicle, VEH_DISASTER >::From(), GroundVehicle< T, Type >::gcache, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), SpecializedVehicle< T, Type >::GetIfValid(), GetRoadTypeInfo(), INVALID_COORD, INVALID_ROADTYPE, GroundVehicle< T, Type >::IsEngine(), GroundVehicle< T, Type >::IsFreeWagon(), Vehicle::IsFrontEngine(), Aircraft::IsNormalAircraft(), IsSavegameVersionBefore(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Iterate(), GroundVehicleCache::last_speed, Vehicle::Next(), SpecializedVehicle< T, Type >::Next(), RoadTypeInfo::powered_roadtypes, RoadVehicle::roadtype, VehicleSettings::roadveh_acceleration_model, RoadVehUpdateCache(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SlErrorCorrupt(), SLV_112, SLV_2, Vehicle::sprite_cache, MutableSpriteCache::sprite_seq, ST_SMALL_UFO, Stopped, UpdateAircraftCache(), Ship::UpdateCache(), VEH_AIRCRAFT, VEH_DISASTER, VEH_EFFECT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, GameSettings::vehicle, and Vehicle::vehstatus.

Referenced by AfterLoadGame(), and ReloadNewGRFData().

## ◆ ConnectMultiheadedTrains()

void ConnectMultiheadedTrains | ( |  | ) |

Link front and rear multiheaded engines to each other This is done when loading a savegame.

Definition at line 35 of file vehicle_sl.cpp.

References GroundVehicle< T, Type >::ClearEngine(), GroundVehicle< T, Type >::ClearMultiheaded(), Vehicle::engine_type, SpecializedVehicle< T, Type >::GetNextVehicle(), GroundVehicle< T, Type >::IsEngine(), GroundVehicle< T, Type >::IsMultiheaded(), SpecializedVehicle< T, Type >::Iterate(), and Vehicle::spritenum.

Referenced by AfterLoadGame().

## ◆ ConvertFromOldCompanyManagerFace()

CompanyManagerFace ConvertFromOldCompanyManagerFace | ( | uint32_t | face | ) |

Converts an old company manager's face format to the new company manager's face format.

Meaning of the bits in the old face (some bits are used in several times):

- 4 and 5: chin
- 6 to 9: eyebrows
- 10 to 13: nose
- 13 to 15: lips (also moustache for males)
- 16 to 19: hair
- 20 to 22: eye colour
- 20 to 27: tie, ear rings etc.
- 28 to 30: glasses
- 19, 26 and 27: race (bit 27 set and bit 19 equal to bit 26 = black, otherwise white)
- 31: gender (0 = male, 1 = female)

Parameters

  face | the face in the old format

Returns
  the face in the new format

Definition at line 59 of file company_sl.cpp.

References ClampU(), FindFaceVar(), GB(), GetCompanyManagerFaceSpec(), HasBit(), and CompanyManagerFace::style.

Referenced by AfterLoadGame().

## ◆ ConvertOldMultiheadToNew()

void ConvertOldMultiheadToNew | ( |  | ) |

Converts all trains to the new subtype format introduced in savegame 16.2 It also links multiheaded engines or make them forget they are multiheaded if no suitable partner is found.

Definition at line 113 of file vehicle_sl.cpp.

References ClrBit(), HasBit(), SpecializedVehicle< T, Type >::Iterate(), SpecializedVehicle< T, Type >::Next(), RAILVEH_MULTIHEAD, RAILVEH_WAGON, SetBit(), and SlErrorCorrupt().

Referenced by AfterLoadGame().

## ◆ CopyFromOldName()

std::string CopyFromOldName | ( | StringID | id | ) |

Copy and convert old custom names to UTF-8.

They were all stored in a 512 by 32 (200 by 24 for TTO) long string array and are now stored with stations, waypoints and other places with names.

Parameters

  id | the StringID of the custom name to clone.

Returns
  the clones custom name.

Definition at line 59 of file strings_sl.cpp.

References _old_name_array, GB(), GetStringTab(), IsSavegameVersionBefore(), BaseStringBuilder::PutUtf8(), SLV_37, and StrMakeValid().

Referenced by AfterLoadGame(), CHKPChunkHandler::FixPointers(), ENGSChunkHandler::Load(), and WriteValue().

## ◆ CopyTempEngineData()

void CopyTempEngineData | ( |  | ) |

Copy data from temporary engine array into the real engine pool.

Definition at line 96 of file engine_sl.cpp.

References Engine::age, Engine::company_avail, Engine::company_hidden, Engine::duration_phase_1, Engine::duration_phase_2, Engine::duration_phase_3, Engine::flags, Engine::intro_date, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Iterate(), Engine::name, Engine::preview_asked, Engine::preview_company, Engine::preview_wait, Engine::reliability, Engine::reliability_final, Engine::reliability_max, Engine::reliability_spd_dec, and Engine::reliability_start.

Referenced by AfterLoadGame().

## ◆ FixupTrainLengths()

void FixupTrainLengths | ( |  | ) |

Fixup old train spacing.

Definition at line 554 of file vehicle_sl.cpp.

References CCF_TRACK, Crashed, SpecializedVehicle< T, Type >::From(), GetRailDepotTrack(), Hidden, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Iterate(), SpecializedVehicle< T, Type >::Next(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), ReverseTrainSwapVeh(), TFP_SIGNAL, TicksToLeaveDepot(), Vehicle::tile, TRACK_BIT_DEPOT, TrackToTrackBits(), TrainController(), VEH_TRAIN, VEHICLE_LENGTH, and Vehicle::vehstatus.

Referenced by AfterLoadGame().

## ◆ GetTempDataEngine()

Engine * GetTempDataEngine | ( | EngineID | index | ) |

Definition at line 46 of file engine_sl.cpp.

## ◆ InitializeOldNames()

void InitializeOldNames | ( |  | ) |

Initialize the old names table memory.

Definition at line 108 of file strings_sl.cpp.

## ◆ MoveBuoysToWaypoints()

void MoveBuoysToWaypoints | ( |  | ) |

Perform all steps to upgrade from the old station buoys to the new version that uses waypoints.

This includes some old saveload mechanics.

Definition at line 45 of file station_sl.cpp.

References BaseStation::build_date, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_station_pool >::CanAllocateItem(), BaseStation::delete_ctr, Dock, BaseStation::facilities, GetStationIndex(), GetTileOwner(), HVOT_WAYPOINT, INVALID_TILE, IsBuoyTile(), IsInsideBS(), IsTileType(), SpecializedStation< Station, false >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_orderlist_pool >::Iterate(), Tile::m6(), MP_STATION, BaseStation::name, Town::name, BaseStation::owner, OWNER_NONE, BaseStation::rect, SB(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), BaseStation::string_id, to_underlying(), BaseStation::town, Waypoint::town_cn, Train, BaseStation::train_station, UpdateWaypointOrder(), VEH_SHIP, and VEH_TRAIN.

Referenced by AfterLoadGame().

## ◆ MoveWaypointsToBaseStations()

void MoveWaypointsToBaseStations | ( |  | ) |

Perform all steps to upgrade from the old waypoints to the new version that uses station.

This includes some old saveload mechanics.

Definition at line 68 of file waypoint_sl.cpp.

References _old_waypoints, AllocateSpecToStation(), AssignSpecToStation(), BaseStation::build_date, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_station_pool >::CanAllocateItem(), Debug, BaseStation::delete_ctr, BaseStation::facilities, GB(), NewGRFClass< Tspec, Tindex, Tmax >::Get(), GetRailTileType(), GetRailType(), NewGRFClass< Tspec, Tindex, Tmax >::GetSpec(), GetTileOwner(), StationSpec::grf_prop, GRFFilePropsBase::grfid, HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, INVALID_TILE, IsSavegameVersionBefore(), IsTileType(), Map::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_orderlist_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Iterate(), GRFFilePropsBase::local_id, Tile::m2(), Tile::m3(), Tile::m4(), Tile::m5(), MakeRailWaypoint(), MP_RAILWAY, BaseStation::name, BaseStation::owner, BaseStation::rect, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SetCustomStationSpecIndex(), SetRailStationReservation(), SlError(), SlErrorCorrupt(), SLV_100, SLV_17, NewGRFClass< Tspec, Tindex, Tmax >::Specs(), STAT_CLASS_WAYP, BaseStation::string_id, BaseStation::town, Waypoint::town_cn, Train, UpdateWaypointOrder(), and VEH_TRAIN.

Referenced by AfterLoadGame().

## ◆ RemapOldStringID()

StringID RemapOldStringID | ( | StringID | s | ) |

Remap a string ID from the old format to the new format.

Parameters

  s | StringID that requires remapping

Returns
  translated ID

Definition at line 28 of file strings_sl.cpp.

References IsInsideMM(), and SPECSTR_COMPANY_NAME_START.

Referenced by SlSaveLoadConv().

## ◆ ResetOldNames()

void ResetOldNames | ( |  | ) |

Free the memory of the old names array.

Should be called once the old names have all been converted.

Definition at line 100 of file strings_sl.cpp.

References _old_name_array.

Referenced by AfterLoadGame().

## ◆ ResetOldWaypoints()

void ResetOldWaypoints | ( |  | ) |

Definition at line 164 of file waypoint_sl.cpp.

## ◆ ResetTempEngineData()

void ResetTempEngineData | ( |  | ) |

Definition at line 124 of file engine_sl.cpp.

## ◆ ResetViewportAfterLoadGame()

void ResetViewportAfterLoadGame | ( |  | ) |

Definition at line 54 of file misc_sl.cpp.

## ◆ SaveViewportBeforeSaveGame()

void SaveViewportBeforeSaveGame | ( |  | ) |

Definition at line 38 of file misc_sl.cpp.

## ◆ UnpackOldOrder()

Order UnpackOldOrder | ( | uint16_t | packed | ) |

Unpacks a order from savegames made with TTD(Patch)

Parameters

  packed | packed order

Returns
  unpacked order

Definition at line 95 of file order_sl.cpp.

References Order::IsType(), Order::MakeDummy(), and UnpackVersion4Order().

## ◆ UpdateHousesAndTowns()

void UpdateHousesAndTowns | ( |  | ) |

Check and update town and house values.

Checked are the HouseIDs. Updated are the town population the number of houses per town, the town radius and the max passengers of the town.

Definition at line 65 of file town_sl.cpp.

References HouseSpec::building_flags, HouseSpec::Get(), GetCleanHouseType(), GetHouseNorthPart(), OverrideManagerBase::GetSubstituteID(), IsTileType(), Map::Iterate(), MP_HOUSE, NEW_HOUSE_OFFSET, RebuildTownCaches(), SetHouseType(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and TileDiffXY().

Referenced by AfterLoadGame(), and ReloadNewGRFData().

## ◆ UpdateOldAircraft()

void UpdateOldAircraft | ( |  | ) |

need to be called to load aircraft from old version

Definition at line 165 of file vehicle_sl.cpp.

References AIR_HELICOPTER, AircraftLeaveHangar(), AircraftNextAirportPos_and_Order(), Vehicle::cargo_payment, Vehicle::current_order, FLYING, GetAircraftFlightLevelBounds(), GetNewVehiclePos(), HANGAR, Order::IsType(), SpecializedStation< Station, false >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Iterate(), SetAircraftPosition(), Stopped, BaseVehicle::type, UpdateAircraftCache(), VEH_AIRCRAFT, and GetNewVehiclePosResult::y.

Referenced by AfterLoadGame().

## Variable Documentation

## ◆ _saved_scrollpos_x

int32_t _saved_scrollpos_x
| extern

Definition at line 34 of file misc_sl.cpp.

## ◆ _saved_scrollpos_y

int32_t _saved_scrollpos_y
| extern

Definition at line 35 of file misc_sl.cpp.

## ◆ _saved_scrollpos_zoom

ZoomLevel _saved_scrollpos_zoom
| extern

Definition at line 36 of file misc_sl.cpp.

## ◆ _savegame_type

SavegameType _savegame_type
| extern

type of savegame we are loading

Definition at line 77 of file saveload.cpp.

Referenced by DoLoad().

## ◆ _ttdp_version

uint32_t _ttdp_version
| extern

version of TTDP savegame (if applicable)

Definition at line 80 of file saveload.cpp.