OpenTTD: src/saveload/saveload_internal.h File Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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.
char * | CopyFromOldName (StringID id)
| Copy and convert old custom names to UTF-8.
void | ResetOldNames ()
| Free the memory of the old names array.
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.
const SaveLoad * | GetBaseStationDescription ()
| Get the base station description to be used for SL_ST_INCLUDE.
void | AfterLoadVehicles (bool part_of_load)
| Called after load to update coordinates.
void | FixupTrainLengths ()
| Fixup old train spacing.
void | AfterLoadStations ()
void | AfterLoadRoadStops ()
| (Re)building of road stop caches after loading a savegame.
void | AfterLoadLabelMaps ()
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.
Engine * | GetTempDataEngine (EngineID index)
void | CopyTempEngineData ()
| Copy data from temporary engine array into the real engine pool.
CompanyManagerFace | ConvertFromOldCompanyManagerFace (uint32 face)
| Converts an old company manager's face format to the new company manager's face format.
Order | UnpackOldOrder (uint16 packed)
| Unpacks a order from savegames made with TTD(Patch)

## Variables
int32 | _saved_scrollpos_x
int32 | _saved_scrollpos_y
ZoomLevelByte | _saved_scrollpos_zoom
SavegameType | _savegame_type
| type of savegame we are loading
uint32 | _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

void AfterLoadCompanyStats | ( |  | ) |

Rebuilding of company statistics after loading a savegame.

Definition at line 95 of file company_sl.cpp.

References CountBits(), FACIL_AIRPORT, BaseStation::facilities, FOR_EACH_SET_ROADTYPE, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), GetLockPart(), GetOtherTunnelBridgeEnd(), GetPresentSignals(), GetRailType(), GetRoadBits(), GetRoadOwner(), GetRoadTypes(), GetStationType(), GetTileOwner(), GetTileType(), GetTrackBits(), GetTunnelBridgeLength(), GetTunnelBridgeTransportType(), GetWaterClass(), HasSignals(), Company::infrastructure, IsBuoy(), IsLevelCrossing(), IsLock(), IsNormalRoad(), IsPlainRail(), IsRoadDepot(), IsShipDepot(), IsStationTileBlocked(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), LEVELCROSSING_TRACKBIT_FACTOR, LOCK_DEPOT_TILE_FACTOR, LOCK_PART_MIDDLE, MapSize(), MemSetT(), MP_OBJECT, MP_RAILWAY, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, MP_WATER, BaseStation::owner, CompanyInfrastructure::rail, CompanyInfrastructure::road, CompanyInfrastructure::signal, CompanyInfrastructure::station, TracksOverlap(), TRANSPORT_RAIL, TRANSPORT_ROAD, TRANSPORT_WATER, TUNNELBRIDGE_TRACKBIT_FACTOR, CompanyInfrastructure::water, and WATER_CLASS_CANAL.

Referenced by AfterLoadGame(), CheckCaches(), and ReloadNewGRFData().

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 230 of file linkgraph_sl.cpp.

References SpecializedStation< Station, false >::Get(), LinkGraphJob::Graph(), LinkGraphSchedule::Instance(), IsSavegameVersionBefore(), LinkGraph::Size(), and LinkGraphSchedule::SpawnAll().

Referenced by AfterLoadGame().

void AfterLoadStoryBook | ( |  | ) |

Called after load to trash broken pages.

Definition at line 20 of file story_sl.cpp.

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

Referenced by AfterLoadGame().

void AfterLoadVehicles | ( | bool | part_of_load | ) |

Called after load to update coordinates.

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

For instantiating the shared vehicle chain.

Definition at line 249 of file vehicle_sl.cpp.

References _age_cargo_skip_counter, _settings_game, Vehicle::AddToShared(), AIR_HELICOPTER, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool >::CanAllocateItem(), Vehicle::cargo_age_counter, GroundVehicle< T, Type >::CargoChanged(), CCF_SAVELOAD, CheckValidVehicles(), CompanyServiceInterval(), Train::ConsistChanged(), Vehicle::coord, Vehicle::cur_image, Vehicle::cur_speed, Vehicle::current_order, Vehicle::direction, EF_ROAD_TRAM, EIT_ON_MAP, Vehicle::engine_type, Vehicle::fill_percent_te_id, Vehicle::first, OrderList::first, Vehicle::First(), GroundVehicleCache::first_engine, FOR_ALL_VEHICLES, Order::Free(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedVehicle< Train, Type >::From(), SpecializedVehicle< RoadVehicle, Type >::From(), SpecializedVehicle< Ship, VEH_SHIP >::From(), GroundVehicle< T, Type >::gcache, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), OrderList::GetFirstSharedVehicle(), Vehicle::GetGroundVehicleCache(), Vehicle::GetImage(), HasBit(), OrderList::Initialize(), INVALID_COORD, INVALID_ENGINE, GroundVehicle< T, Type >::IsEngine(), GroundVehicle< T, Type >::IsFreeWagon(), Vehicle::IsFrontEngine(), Vehicle::IsGroundVehicle(), Vehicle::IsPrimaryVehicle(), IsSavegameVersionBefore(), GroundVehicleCache::last_speed, Vehicle::list, Vehicle::Next(), Vehicle::next_shared, Vehicle::NextShared(), Vehicle::old, Vehicle::orders, Vehicle::owner, Vehicle::previous, Vehicle::Previous(), Vehicle::previous_shared, Vehicle::PreviousShared(), ROADTYPE_ROAD, ROADTYPE_TRAM, RoadTypeToRoadTypes(), VehicleSettings::roadveh_acceleration_model, RoadVehUpdateCache(), VehicleDefaultSettings::servint_ispercent, GroundVehicle< T, Type >::SetArticulatedPart(), GroundVehicle< T, Type >::SetFrontEngine(), Company::settings, SlErrorCorrupt(), Vehicle::subtype, BaseVehicle::type, Vehicle::unitnumber, UpdateAircraftCache(), Ship::UpdateCache(), Vehicle::UpdateDeltaXY(), Vehicle::UpdatePosition(), Vehicle::UpdateViewport(), VEH_AIRCRAFT, VEH_DISASTER, VEH_ROAD, VEH_SHIP, VEH_TRAIN, CompanySettings::vehicle, GameSettings::vehicle, Vehicle::vehstatus, and VS_STOPPED.

Referenced by AfterLoadGame(), and ReloadNewGRFData().

CompanyManagerFace ConvertFromOldCompanyManagerFace | ( | uint32 | 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 44 of file company_sl.cpp.

References ClampU(), ETHNICITY_BLACK, GB(), GE_WF, GE_WM, GENDER_FEMALE, HasBit(), max(), ScaleCompanyManagerFaceValue(), SetBit(), and SetCompanyManagerFaceBits().

Referenced by AfterLoadGame().

char* 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 60 of file strings_sl.cpp.

References _old_name_array, _savegame_type, GB(), IsSavegameVersionBefore(), lastof, LEN_OLD_STRINGS, LEN_OLD_STRINGS_TTO, MAX_CHAR_LENGTH, SGT_TTO, stredup(), Utf8CharLen(), and Utf8Encode().

Referenced by AfterLoadGame(), FixOldVehicles(), and WriteValue().

void FixupTrainLengths | ( |  | ) |

Fixup old train spacing.

Definition at line 474 of file vehicle_sl.cpp.

References CCF_TRACK, Train::ConsistChanged(), FOR_ALL_VEHICLES, SpecializedVehicle< Train, Type >::From(), GetRailDepotTrack(), Vehicle::IsPrimaryVehicle(), SpecializedVehicle< T, Type >::Next(), ReverseTrainSwapVeh(), TFP_SIGNAL, TicksToLeaveDepot(), Vehicle::tile, TRACK_BIT_DEPOT, TrackToTrackBits(), TrainController(), BaseVehicle::type, VEH_TRAIN, VEHICLE_LENGTH, Vehicle::vehstatus, VS_CRASHED, and VS_HIDDEN.

Referenced by AfterLoadGame().

const SaveLoad* GetBaseStationDescription | ( |  | ) |

Get the base station description to be used for SL_ST_INCLUDE.

Returns
  the base station description.

Definition at line 461 of file station_sl.cpp.

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 42 of file station_sl.cpp.

References _me, BaseStation::build_date, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_station_pool >::CanAllocateItem(), Vehicle::current_order, BaseStation::delete_ctr, FACIL_DOCK, FACIL_TRAIN, BaseStation::facilities, FOR_ALL_VEHICLES, OrderList::GetFirstOrder(), OrderList::GetFirstSharedVehicle(), GetStationIndex(), GetTileOwner(), HVOT_WAYPOINT, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_TILE, IsBuoyTile(), IsInsideBS(), IsTileType(), MP_STATION, BaseStation::name, Order::next, BaseStation::owner, OWNER_NONE, BaseStation::rect, SB(), BaseStation::string_id, OrthogonalTileArea::tile, TILE_AREA_LOOP, BaseStation::town, Waypoint::town_cn, BaseStation::train_station, BaseVehicle::type, UpdateWaypointOrder(), VEH_SHIP, VEH_TRAIN, and BaseStation::xy.

Referenced by AfterLoadGame().

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 67 of file waypoint_sl.cpp.

References _m, AllocateSpecToStation(), SmallVector< T, S >::Begin(), BaseStation::build_date, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_station_pool >::CanAllocateItem(), Vehicle::current_order, BaseStation::delete_ctr, SmallVector< T, S >::End(), FACIL_TRAIN, BaseStation::facilities, FOR_ALL_VEHICLES, GB(), NewGRFClass< Tspec, Tid, Tmax >::Get(), OrderList::GetFirstOrder(), OrderList::GetFirstSharedVehicle(), GetRailTileType(), GetRailType(), NewGRFClass< Tspec, Tid, Tmax >::GetSpecCount(), GetTileOwner(), StationSpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, IsSavegameVersionBefore(), IsTileType(), SmallVector< T, S >::Length(), GRFFilePropsBase< Tcnt >::local_id, Tile::m2, Tile::m3, Tile::m4, MakeRailWaypoint(), MP_RAILWAY, BaseStation::name, Order::next, BaseStation::owner, BaseStation::rect, SmallVector< T, S >::Reset(), SetCustomStationSpecIndex(), SetRailStationReservation(), SlError(), STAT_CLASS_WAYP, BaseStation::string_id, BaseStation::town, Waypoint::town_cn, BaseVehicle::type, UpdateWaypointOrder(), and VEH_TRAIN.

Referenced by AfterLoadGame().

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 29 of file strings_sl.cpp.

References IsInsideMM().

Referenced by LoadOldVehicle(), and SlSaveLoadConv().

void ResetOldNames | ( |  | ) |

Free the memory of the old names array.

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

Definition at line 108 of file strings_sl.cpp.

References _old_name_array, and free().

Referenced by AfterLoadGame().

Order UnpackOldOrder | ( | uint16 | packed | ) |

Unpacks a order from savegames made with TTD(Patch)

Parameters

  packed | packed order

Returns
  unpacked order

Definition at line 91 of file order_sl.cpp.

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

Referenced by LoadOldVehicle().

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, GetCleanHouseType(), GetHouseNorthPart(), OverrideManagerBase::GetSubstituteID(), IsTileType(), MapSize(), MP_HOUSE, NEW_HOUSE_OFFSET, RebuildTownCaches(), SetHouseType(), and TileDiffXY().

Referenced by AfterLoadGame(), and ReloadNewGRFData().