OpenTTD Source 20241224-master-gf74b0cf984
|
Code handling saving and loading of vehicles. More...
#include "../stdafx.h"
#include "saveload.h"
#include "compat/vehicle_sl_compat.h"
#include "../debug.h"
#include "../vehicle_func.h"
#include "../train.h"
#include "../roadveh.h"
#include "../ship.h"
#include "../aircraft.h"
#include "../timetable.h"
#include "../station_base.h"
#include "../effectvehicle_base.h"
#include "../company_base.h"
#include "../company_func.h"
#include "../disaster_vehicle.h"
#include "../economy_base.h"
#include "../safeguards.h"
Go to the source code of this file.
Data Structures | |
class | SlVehicleCommon |
class | SlVehicleTrain |
class | SlVehicleRoadVehPath |
class | SlVehicleRoadVeh |
class | SlVehicleShipPath |
class | SlVehicleShip |
class | SlVehicleAircraft |
class | SlVehicleEffect |
class | SlVehicleDisaster |
struct | VEHSChunkHandler |
Functions | |
void | ConnectMultiheadedTrains () |
Link front and rear multiheaded engines to each other This is done when loading a savegame. | |
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 | UpdateOldAircraft () |
need to be called to load aircraft from old version | |
static void | CheckValidVehicles () |
Check all vehicles to ensure their engine type is valid for the currently loaded NewGRFs (that includes none...) This only makes a difference if NewGRFs are missing, otherwise all vehicles will be valid. | |
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. | |
bool | TrainController (Train *v, Vehicle *nomove, bool reverse=true) |
Move a vehicle chain one movement stop forwards. | |
void | ReverseTrainDirection (Train *v) |
Turn a train around. | |
void | ReverseTrainSwapVeh (Train *v, int l, int r) |
Swap vehicles l and r in consist v, and reverse their direction. | |
void | FixupTrainLengths () |
Fixup old train spacing. | |
const ChunkHandlerTable | _veh_chunk_handlers (veh_chunk_handlers) |
Variables | |
uint8_t | _age_cargo_skip_counter |
Skip aging of cargo? Used before savegame version 162. | |
static uint8_t | _cargo_periods |
static uint16_t | _cargo_source |
static uint32_t | _cargo_source_xy |
static uint16_t | _cargo_count |
static uint16_t | _cargo_paid_for |
static Money | _cargo_feeder_share |
static const SaveLoad | _vehicle_desc [] |
static const VEHSChunkHandler | VEHS |
static const ChunkHandlerRef | veh_chunk_handlers [] |
Code handling saving and loading of vehicles.
Definition in file vehicle_sl.cpp.
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().
void AfterLoadVehiclesPhase2 | ( | bool | part_of_load | ) |
Called after load for phase 2 of vehicle initialisation.
Definition at line 415 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< Ship, VEH_SHIP >::From(), SpecializedVehicle< T, Type >::From(), SpecializedVehicle< DisasterVehicle, VEH_DISASTER >::From(), GroundVehicle< T, Type >::gcache, 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<&_engine_pool >::Get(), SpecializedVehicle< T, Type >::GetIfValid(), GetRoadTypeInfo(), INVALID_COORD, INVALID_ROADTYPE, INVALID_VEHICLE, GroundVehicle< T, Type >::IsEngine(), GroundVehicle< T, Type >::IsFreeWagon(), Vehicle::IsFrontEngine(), Aircraft::IsNormalAircraft(), IsSavegameVersionBefore(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), GroundVehicleCache::last_speed, Vehicle::Next(), SpecializedVehicle< T, Type >::Next(), RoadTypeInfo::powered_roadtypes, RoadVehicle::roadtype, VehicleSettings::roadveh_acceleration_model, RoadVehUpdateCache(), SlErrorCorrupt(), SLV_112, SLV_2, Vehicle::sprite_cache, MutableSpriteCache::sprite_seq, ST_SMALL_UFO, UpdateAircraftCache(), Ship::UpdateCache(), VEH_AIRCRAFT, VEH_DISASTER, VEH_ROAD, VEH_SHIP, VEH_TRAIN, GameSettings::vehicle, Vehicle::vehstatus, and VS_STOPPED.
Referenced by AfterLoadGame(), and ReloadNewGRFData().
|
static |
Check all vehicles to ensure their engine type is valid for the currently loaded NewGRFs (that includes none...) This only makes a difference if NewGRFs are missing, otherwise all vehicles will be valid.
This does not make such a game playable, it only prevents crash.
Definition at line 225 of file vehicle_sl.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::GetPoolSize(), INVALID_ENGINE, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), Engine::IterateType(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.
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().
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().
void FixupTrainLengths | ( | ) |
Fixup old train spacing.
Definition at line 549 of file vehicle_sl.cpp.
References CCF_TRACK, SpecializedVehicle< T, Type >::From(), GetRailDepotTrack(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), SpecializedVehicle< T, Type >::Next(), ReverseTrainSwapVeh(), TFP_SIGNAL, TicksToLeaveDepot(), Vehicle::tile, TRACK_BIT_DEPOT, TrackToTrackBits(), TrainController(), VEH_TRAIN, VEHICLE_LENGTH, Vehicle::vehstatus, and VS_CRASHED.
Referenced by AfterLoadGame().
void ReverseTrainDirection | ( | Train * | v | ) |
Turn a train around.
v | Train to turn around. |
Definition at line 1967 of file train_cmd.cpp.
References _settings_game, AdvanceWagonsAfterSwap(), AdvanceWagonsBeforeSwap(), CCF_TRACK, CheckNextTrainTile(), ClrBit(), Train::ConsistChanged(), Vehicle::current_order, Vehicle::direction, FindFirstTrack(), FreeTrainTrackReservation(), GetRailDepotDirection(), Order::GetType(), Train::GetVehicleTrackdir(), HasBit(), HasSignalOnTrackdir(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_DIAGDIR, INVALID_TILE, InvalidateWindowData(), IsRailDepotTile(), IsRailStationTile(), IsTileType(), MarkTrainAsStuck(), MaybeBarCrossingWithSound(), MP_RAILWAY, MP_TUNNELBRIDGE, SpecializedVehicle< T, Type >::Next(), Vehicle::owner, GameSettings::pf, PathfinderSettings::reserve_paths, ReverseTrainSwapVeh(), SetRailStationPlatformReservation(), SetWindowWidgetDirty(), SIGSEG_PBS, Vehicle::tile, ToggleBit(), TRACK_BIT_DEPOT, TrackdirToExitdir(), TrainApproachingCrossingTile(), TryPathReserve(), UpdateLevelCrossing(), UpdateSignalsOnSegment(), SpecializedVehicle< T, Type >::UpdateViewport(), VehicleExitDir(), VRF_TOGGLE_REVERSE, VRF_TRAIN_STUCK, Train::wait_counter, WC_VEHICLE_DEPOT, WC_VEHICLE_VIEW, and WID_VV_START_STOP.
Referenced by CmdReverseTrainDirection(), TrainApproachingLineEnd(), and TrainController().
void ReverseTrainSwapVeh | ( | Train * | v, |
int | l, | ||
int | r | ||
) |
Swap vehicles l and r in consist v, and reverse their direction.
v | Consist to change. |
l | Vehicle index in the consist of the first vehicle. |
r | Vehicle index in the consist of the second vehicle. |
Definition at line 1630 of file train_cmd.cpp.
References Vehicle::direction, GroundVehicle< T, Type >::gv_flags, SpecializedVehicle< T, Type >::Next(), Swap(), SwapTrainFlags(), Vehicle::tile, UpdateStatusAfterSwap(), Vehicle::vehstatus, VS_HIDDEN, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.
Referenced by FixupTrainLengths(), and ReverseTrainDirection().
Move a vehicle chain one movement stop forwards.
v | First vehicle to move. |
nomove | Stop moving this and all following vehicles. |
reverse | Set to false to not execute the vehicle reversing. This does not change any other logic. |
Definition at line 3278 of file train_cmd.cpp.
References _accel_slowdown, _settings_client, _settings_game, RailTypeInfo::acceleration_type, AffectSpeedByZChange(), SoundSettings::ambient, TrainCache::cached_max_curve_speed, CCF_TRACK, CheckNextTrainTile(), ClearPathReservation(), Vehicle::cur_speed, Ticks::DAY_TICKS, DIAGDIR_BEGIN, DIAGDIR_END, DiagdirBetweenTiles(), DiagdirReachesTrackdirs(), DiagDirToDiagTrack(), DIRDIFF_45LEFT, DIRDIFF_45RIGHT, DirDifference(), Vehicle::direction, FindFirstBit(), FindFirstTrack(), FindFirstTrackdir(), SpecializedVehicle< T, Type >::First(), Train::GetCurveSpeedLimit(), GetNewVehiclePos(), GetOtherTunnelBridgeEnd(), GetRailTypeInfo(), GetReservedTrackbits(), GetTileRailType(), GetTileTrackStatus(), GetTunnelBridgeDirection(), Train::GetVehicleTrackdir(), HasBit(), HasCrossingReservation(), HasOnewaySignalBlockingTrackdir(), HasPbsSignalOnTrackdir(), HasReservedTracks(), HasSignalOnTrackdir(), HasSignals(), HasVehicleOnPos(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_TILE, Vehicle::IsFrontEngine(), IsLevelCrossingTile(), IsPlainRailTile(), IsTileType(), IsTunnel(), IsValidDiagDirection(), AccelerationSlowdownParams::large_turn, MarkTileDirtyByTile(), MarkTrainAsStuck(), MP_TUNNELBRIDGE, GetNewVehiclePosResult::new_tile, SpecializedVehicle< T, Type >::Next(), GetNewVehiclePosResult::old_tile, Vehicle::owner, PathfinderSettings::path_backoff_interval, GameSettings::pf, SpecializedVehicle< T, Type >::Previous(), Vehicle::progress, Rail90DegTurnDisallowed(), PathfinderSettings::reverse_at_signals, ReverseDiagDir(), ReverseTrackdir(), ReverseTrainDirection(), SetSignalStateByTrackdir(), SetWindowDirty(), SIGNAL_STATE_RED, SIGSEG_PBS, SIGTYPE_PBS, AccelerationSlowdownParams::small_turn, SND_0E_LEVEL_CROSSING, ClientSettings::sound, Vehicle::subspeed, TFP_NONE, TFP_SIGNAL, TFP_STUCK, Vehicle::tick_counter, Vehicle::tile, TileAddByDiagDir(), TRACK_BIT_DEPOT, TRACK_BIT_LEFT, TRACK_BIT_LOWER, TRACK_BIT_NONE, TRACK_BIT_RIGHT, TRACK_BIT_UPPER, TRACK_BIT_WORMHOLE, TRACK_BIT_X, TRACK_BIT_Y, TrackBitsToTrack(), TrackdirBitsToTrackBits(), TrackDirectionToTrackdir(), TrackdirToExitdir(), TrackdirToTrack(), TrackStatusToRedSignals(), TrackStatusToTrackdirBits(), TrackToTrackBits(), VehicleSettings::train_acceleration_model, TrainApproachingCrossingTile(), TrainCheckIfLineEnds(), TrainEnterStation(), TRANSPORT_RAIL, TryPathReserve(), TryReserveRailTrack(), Train::UpdateDeltaXY(), GroundVehicle< T, Type >::UpdateInclination(), UpdateLevelCrossing(), Vehicle::UpdatePosition(), UpdateSignalsOnSegment(), GameSettings::vehicle, VehicleEnterTile(), Vehicle::vehstatus, VETS_CANNOT_ENTER, VETS_ENTERED_STATION, VETS_ENTERED_WORMHOLE, VETS_STATION_ID_OFFSET, VRF_TRAIN_STUCK, VS_HIDDEN, Train::wait_counter, PathfinderSettings::wait_oneway_signal, PathfinderSettings::wait_twoway_signal, WC_VEHICLE_VIEW, Vehicle::x_pos, GetNewVehiclePosResult::y, and Vehicle::y_pos.
Referenced by AdvanceWagonsAfterSwap(), AdvanceWagonsBeforeSwap(), and FixupTrainLengths().
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, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), SetAircraftPosition(), BaseVehicle::type, UpdateAircraftCache(), VEH_AIRCRAFT, VS_STOPPED, and GetNewVehiclePosResult::y.
Referenced by AfterLoadGame().
|
extern |
Skip aging of cargo? Used before savegame version 162.
Definition at line 79 of file misc_sl.cpp.
|
static |
Definition at line 636 of file vehicle_sl.cpp.
|
static |
Definition at line 638 of file vehicle_sl.cpp.
|
static |
Definition at line 637 of file vehicle_sl.cpp.
|
static |
Definition at line 633 of file vehicle_sl.cpp.
|
static |
Definition at line 634 of file vehicle_sl.cpp.
|
static |
Definition at line 635 of file vehicle_sl.cpp.
|
static |
Definition at line 1090 of file vehicle_sl.cpp.
|
static |
Definition at line 1173 of file vehicle_sl.cpp.
|
static |
Definition at line 1172 of file vehicle_sl.cpp.