Functions | Variables

vehicle_sl.cpp File Reference

Code handling saving and loading of vehicles. More...

#include "../stdafx.h"
#include "../vehicle_func.h"
#include "../train.h"
#include "../roadveh.h"
#include "../ship.h"
#include "../aircraft.h"
#include "../station_base.h"
#include "../effectvehicle_base.h"
#include "saveload.h"
#include <map>

Go to the source code of this file.

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 AfterLoadVehicles (bool part_of_load)
 Called after load to update coordinates.
const SaveLoadGetVehicleDescription (VehicleType vt)
 Make it possible to make the saveload tables "friends" of other classes.
static void Save_VEHS ()
 Will be called when the vehicles need to be saved.
void Load_VEHS ()
 Will be called when vehicles need to be loaded.
static void Ptrs_VEHS ()

Variables

static uint8 _cargo_days
static uint16 _cargo_source
static uint32 _cargo_source_xy
static uint16 _cargo_count
static uint16 _cargo_paid_for
static Money _cargo_feeder_share
static uint32 _cargo_loaded_at_xy
const ChunkHandler _veh_chunk_handlers []

Detailed Description

Code handling saving and loading of vehicles.

Definition in file vehicle_sl.cpp.


Function Documentation

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 241 of file vehicle_sl.cpp.

References _settings_game, Vehicle::AddToShared(), AIR_HELICOPTER, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool >::CanAllocateItem(), GroundVehicle< T, Type >::CargoChanged(), CheckValidVehicles(), Train::ConsistChanged(), Vehicle::coord, Vehicle::cur_image, Vehicle::cur_speed, Vehicle::current_order, Vehicle::direction, EF_ROAD_TRAM, 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< Ship, VEH_SHIP >::From(), SpecializedVehicle< RoadVehicle, Type >::From(), SpecializedVehicle< Train, Type >::From(), GroundVehicle< T, Type >::gcache, 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::Previous(), Vehicle::previous, Vehicle::previous_shared, Vehicle::PreviousShared(), ROADTYPE_TRAM, RoadTypeToRoadTypes(), VehicleSettings::roadveh_acceleration_model, RoadVehUpdateCache(), GroundVehicle< T, Type >::SetArticulatedPart(), GroundVehicle< T, Type >::SetFrontEngine(), SlErrorCorrupt(), Vehicle::subtype, BaseVehicle::type, Vehicle::unitnumber, UpdateAircraftCache(), Ship::UpdateCache(), Vehicle::UpdateDeltaXY(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, GameSettings::vehicle, VehicleMove(), Vehicle::vehstatus, and VS_STOPPED.

Referenced by AfterLoadGame(), and ReloadNewGRFData().

static void CheckValidVehicles (  )  [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 210 of file vehicle_sl.cpp.

References Vehicle::engine_type, FOR_ALL_VEHICLES, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::GetPoolSize(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_ENGINE, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by AfterLoadVehicles().

const SaveLoad* GetVehicleDescription ( VehicleType  vt  ) 

Make it possible to make the saveload tables "friends" of other classes.

So we can use private/protected variables in the saveload code.

Saving and loading the current order of vehicles.

The vehicles have a cargo list (and we want that saved).

Parameters:
vt the vehicle type. Can be VEH_END for the common vehicle description data
Returns:
the saveload description

Save and load of vehicles

Definition at line 454 of file vehicle_sl.cpp.

References REF_CARGO_PACKET, REF_ORDER, REF_ORDERLIST, REF_VEHICLE, REF_VEHICLE_OLD, SL_MAX_VERSION, SLE_CONDLST, SLE_CONDNULL, SLE_CONDREF, SLE_CONDSTR, SLE_CONDVAR, SLE_END, SLE_REF, SLE_STR, SLE_VAR, SLE_WRITEBYTE, SLEG_CONDVAR, VEH_AIRCRAFT, VEH_DISASTER, VEH_EFFECT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by Load_VEHS(), and Save_VEHS().

void Load_VEHS (  ) 
static void Save_VEHS (  )  [static]

Variable Documentation

const ChunkHandler _veh_chunk_handlers[]
Initial value:
 {
  { 'VEHS', Save_VEHS, Load_VEHS, Ptrs_VEHS, NULL, CH_SPARSE_ARRAY | CH_LAST},
}