OpenTTD
Macros | Typedefs | Functions | Variables
vehicle.cpp File Reference

Base implementations of all vehicles. More...

#include "stdafx.h"
#include "error.h"
#include "roadveh.h"
#include "ship.h"
#include "spritecache.h"
#include "timetable.h"
#include "viewport_func.h"
#include "news_func.h"
#include "command_func.h"
#include "company_func.h"
#include "train.h"
#include "aircraft.h"
#include "newgrf_debug.h"
#include "newgrf_sound.h"
#include "newgrf_station.h"
#include "group_gui.h"
#include "strings_func.h"
#include "zoom_func.h"
#include "date_func.h"
#include "vehicle_func.h"
#include "autoreplace_func.h"
#include "autoreplace_gui.h"
#include "station_base.h"
#include "ai/ai.hpp"
#include "depot_func.h"
#include "network/network.h"
#include "core/pool_func.hpp"
#include "economy_base.h"
#include "articulated_vehicles.h"
#include "roadstop_base.h"
#include "core/random_func.hpp"
#include "core/backup_type.hpp"
#include "order_backup.h"
#include "sound_func.h"
#include "effectvehicle_func.h"
#include "effectvehicle_base.h"
#include "vehiclelist.h"
#include "bridge_map.h"
#include "tunnel_map.h"
#include "depot_map.h"
#include "gamelog.h"
#include "linkgraph/linkgraph.h"
#include "linkgraph/refresh.h"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Macros

#define GEN_HASHX(x)   GB((x), GEN_HASHX_BUCKET_BITS + ZOOM_LVL_SHIFT, GEN_HASHX_BITS)
 
#define GEN_HASHY(y)   (GB((y), GEN_HASHY_BUCKET_BITS + ZOOM_LVL_SHIFT, GEN_HASHY_BITS) << GEN_HASHX_BITS)
 
#define GEN_HASH(x, y)   (GEN_HASHY(y) + GEN_HASHX(x))
 

Typedefs

typedef SmallMap< Vehicle *, bool, 4 > AutoreplaceMap
 List of vehicles that should check for autoreplace this tick. More...
 

Functions

void VehicleServiceInDepot (Vehicle *v)
 Service a vehicle and all subsequent vehicles in the consist. More...
 
void ShowNewGrfVehicleError (EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical)
 Displays a "NewGrf Bug" error message for a engine, and pauses the game if not networking. More...
 
void VehicleLengthChanged (const Vehicle *u)
 Logs a bug in GRF and shows a warning message if this is for the first time this happened. More...
 
byte VehicleRandomBits ()
 Get a value for a vehicle's random_bits. More...
 
static VehicleVehicleFromTileHash (int xl, int yl, int xu, int yu, void *data, VehicleFromPosProc *proc, bool find_first)
 
static VehicleVehicleFromPosXY (int x, int y, void *data, VehicleFromPosProc *proc, bool find_first)
 Helper function for FindVehicleOnPos/HasVehicleOnPos. More...
 
void FindVehicleOnPosXY (int x, int y, void *data, VehicleFromPosProc *proc)
 Find a vehicle from a specific location. More...
 
bool HasVehicleOnPosXY (int x, int y, void *data, VehicleFromPosProc *proc)
 Checks whether a vehicle in on a specific location. More...
 
static VehicleVehicleFromPos (TileIndex tile, void *data, VehicleFromPosProc *proc, bool find_first)
 Helper function for FindVehicleOnPos/HasVehicleOnPos. More...
 
void FindVehicleOnPos (TileIndex tile, void *data, VehicleFromPosProc *proc)
 Find a vehicle from a specific location. More...
 
bool HasVehicleOnPos (TileIndex tile, void *data, VehicleFromPosProc *proc)
 Checks whether a vehicle is on a specific location. More...
 
static VehicleEnsureNoVehicleProcZ (Vehicle *v, void *data)
 Callback that returns 'real' vehicles lower or at height *(int*)data . More...
 
CommandCost EnsureNoVehicleOnGround (TileIndex tile)
 Ensure there is no vehicle at the ground at the given position. More...
 
static VehicleGetVehicleTunnelBridgeProc (Vehicle *v, void *data)
 Procedure called for every vehicle found in tunnel/bridge in the hash map.
 
CommandCost TunnelBridgeIsFree (TileIndex tile, TileIndex endtile, const Vehicle *ignore)
 Finds vehicle in tunnel / bridge. More...
 
static VehicleEnsureNoTrainOnTrackProc (Vehicle *v, void *data)
 
CommandCost EnsureNoTrainOnTrackBits (TileIndex tile, TrackBits track_bits)
 Tests if a vehicle interacts with the specified track bits. More...
 
static void UpdateVehicleTileHash (Vehicle *v, bool remove)
 
static void UpdateVehicleViewportHash (Vehicle *v, int x, int y)
 
void ResetVehicleHash ()
 
void ResetVehicleColourMap ()
 
void InitializeVehicles ()
 
uint CountVehiclesInChain (const Vehicle *v)
 
void VehicleEnteredDepotThisTick (Vehicle *v)
 Adds a vehicle to the list of vehicles that visited a depot this tick. More...
 
static void RunVehicleDayProc ()
 Increases the day counter for all vehicles and calls 1-day and 32-day handlers. More...
 
void CallVehicleTicks ()
 
static void DoDrawVehicle (const Vehicle *v)
 Add vehicle sprite for drawing to the screen. More...
 
void ViewportAddVehicles (DrawPixelInfo *dpi)
 Add the vehicle sprites that should be drawn at a part of the screen. More...
 
VehicleCheckClickOnVehicle (const ViewPort *vp, int x, int y)
 Find the vehicle close to the clicked coordinates. More...
 
void DecreaseVehicleValue (Vehicle *v)
 Decrease the value of a vehicle. More...
 
void CheckVehicleBreakdown (Vehicle *v)
 
void AgeVehicle (Vehicle *v)
 Update age of a vehicle. More...
 
uint8 CalcPercentVehicleFilled (const Vehicle *front, StringID *colour)
 Calculates how full a vehicle is. More...
 
void VehicleEnterDepot (Vehicle *v)
 Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it, etc. More...
 
GetNewVehiclePosResult GetNewVehiclePos (const Vehicle *v)
 Get position information of a vehicle when moving one pixel in the direction it is facing. More...
 
Direction GetDirectionTowards (const Vehicle *v, int x, int y)
 
VehicleEnterTileStatus VehicleEnterTile (Vehicle *v, TileIndex tile, int x, int y)
 Call the tile callback function for a vehicle entering a tile. More...
 
UnitID GetFreeUnitNumber (VehicleType type)
 Get an unused unit number for a vehicle (if allowed). More...
 
bool CanBuildVehicleInfrastructure (VehicleType type)
 Check whether we can build infrastructure for the given vehicle type. More...
 
LiveryScheme GetEngineLiveryScheme (EngineID engine_type, EngineID parent_engine_type, const Vehicle *v)
 Determines the LiveryScheme for a vehicle. More...
 
const LiveryGetEngineLivery (EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, byte livery_setting)
 Determines the livery for a vehicle. More...
 
static PaletteID GetEngineColourMap (EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v)
 
PaletteID GetEnginePalette (EngineID engine_type, CompanyID company)
 Get the colour map for an engine. More...
 
PaletteID GetVehiclePalette (const Vehicle *v)
 Get the colour map for a vehicle. More...
 
static void SpawnAdvancedVisualEffect (const Vehicle *v)
 Call CBID_VEHICLE_SPAWN_VISUAL_EFFECT and spawn requested effects. More...
 
void VehiclesYearlyLoop ()
 
bool CanVehicleUseStation (EngineID engine_type, const Station *st)
 Can this station be used by the given engine type? More...
 
bool CanVehicleUseStation (const Vehicle *v, const Station *st)
 Can this station be used by the given vehicle? More...
 
void GetVehicleSet (VehicleSet &set, Vehicle *v, uint8 num_vehicles)
 Calculates the set of vehicles that will be affected by a given selection. More...
 

Variables

static const uint GEN_HASHX_BITS = 6
 
static const uint GEN_HASHY_BITS = 6
 
static const uint GEN_HASHX_BUCKET_BITS = 7
 
static const uint GEN_HASHY_BUCKET_BITS = 6
 
static const int GEN_HASHX_SIZE = 1 << (GEN_HASHX_BUCKET_BITS + GEN_HASHX_BITS + ZOOM_LVL_SHIFT)
 
static const int GEN_HASHY_SIZE = 1 << (GEN_HASHY_BUCKET_BITS + GEN_HASHY_BITS + ZOOM_LVL_SHIFT)
 
static const int GEN_HASHX_INC = 1
 
static const int GEN_HASHY_INC = 1 << GEN_HASHX_BITS
 
static const uint GEN_HASHX_MASK = (1 << GEN_HASHX_BITS) - 1
 
static const uint GEN_HASHY_MASK = ((1 << GEN_HASHY_BITS) - 1) << GEN_HASHX_BITS
 
VehicleID _new_vehicle_id
 
uint16 _returned_refit_capacity
 Stores the capacity after a refit operation.
 
uint16 _returned_mail_refit_capacity
 Stores the mail capacity after a refit operation (Aircraft only).
 
VehiclePool _vehicle_pool ("Vehicle")
 The pool with all our precious vehicles. More...
 
const int HASH_BITS = 7
 
const int HASH_SIZE = 1 << HASH_BITS
 
const int HASH_MASK = HASH_SIZE - 1
 
const int TOTAL_HASH_SIZE = 1 << (HASH_BITS * 2)
 
const int TOTAL_HASH_MASK = TOTAL_HASH_SIZE - 1
 
const int HASH_RES = 0
 
static Vehicle_vehicle_tile_hash [TOTAL_HASH_SIZE]
 
static Vehicle_vehicle_viewport_hash [1<<(GEN_HASHX_BITS+GEN_HASHY_BITS)]
 
static AutoreplaceMap _vehicles_to_autoreplace
 
static const byte _breakdown_chance [64]
 
static const Direction _new_direction_table []
 
static const int8 _vehicle_smoke_pos [8]
 

Detailed Description

Base implementations of all vehicles.

Definition in file vehicle.cpp.

Typedef Documentation

◆ AutoreplaceMap

typedef SmallMap<Vehicle *, bool, 4> AutoreplaceMap

List of vehicles that should check for autoreplace this tick.

Mapping of vehicle -> leave depot immediately after autoreplace.

Definition at line 690 of file vehicle.cpp.

Function Documentation

◆ AgeVehicle()

void AgeVehicle ( Vehicle v)

◆ CalcPercentVehicleFilled()

uint8 CalcPercentVehicleFilled ( const Vehicle front,
StringID colour 
)

Calculates how full a vehicle is.

Parameters
frontThe front vehicle of the consist to check.
colourThe string to show depending on if we are unloading or loading
Returns
A percentage of how full the Vehicle is. Percentages are rounded towards 50%, so that 0% and 100% are only returned if the vehicle is completely empty or full. This is useful for both display and conditional orders.

Definition at line 1367 of file vehicle.cpp.

References Vehicle::current_order, Order::IsType(), and max().

◆ CanBuildVehicleInfrastructure()

bool CanBuildVehicleInfrastructure ( VehicleType  type)

Check whether we can build infrastructure for the given vehicle type.

This to disable building stations etc. when you are not allowed/able to have the vehicle type yet.

Parameters
typethe vehicle type to check this for
Returns
true if there is any reason why you may build the infrastructure for the given vehicle type

Definition at line 1743 of file vehicle.cpp.

Referenced by BuildAirToolbarWindow::OnInvalidateData(), BuildDocksToolbarWindow::OnInvalidateData(), BuildRoadToolbarWindow::OnInvalidateData(), BuildRailToolbarWindow::OnInvalidateData(), and MainToolbarWindow::OnPaint().

◆ CanVehicleUseStation() [1/2]

bool CanVehicleUseStation ( EngineID  engine_type,
const Station st 
)

Can this station be used by the given engine type?

Parameters
engine_typethe type of vehicles to test
stthe station to test for
Returns
true if and only if the vehicle of the type can use this station.
Note
For road vehicles the Vehicle is needed to determine whether it can use the station. This function will return true for road vehicles when at least one of the facilities is available.

Definition at line 2752 of file vehicle.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::GetIfValid().

Referenced by CanVehicleUseStation(), and CmdBuildAircraft().

◆ CanVehicleUseStation() [2/2]

bool CanVehicleUseStation ( const Vehicle v,
const Station st 
)

Can this station be used by the given vehicle?

Parameters
vthe vehicle to test
stthe station to test for
Returns
true if and only if the vehicle can use this station.

Definition at line 2785 of file vehicle.cpp.

References CanVehicleUseStation(), Vehicle::engine_type, SpecializedVehicle< RoadVehicle, Type >::From(), BaseVehicle::type, and VEH_ROAD.

◆ CheckClickOnVehicle()

Vehicle* CheckClickOnVehicle ( const ViewPort vp,
int  x,
int  y 
)

Find the vehicle close to the clicked coordinates.

Parameters
vpViewport clicked in.
xX coordinate in the viewport.
yY coordinate in the viewport.
Returns
Closest vehicle, or NULL if none found.

Definition at line 1161 of file vehicle.cpp.

◆ DecreaseVehicleValue()

void DecreaseVehicleValue ( Vehicle v)

◆ DoDrawVehicle()

static void DoDrawVehicle ( const Vehicle v)
static

Add vehicle sprite for drawing to the screen.

Parameters
vVehicle to draw.

Definition at line 1073 of file vehicle.cpp.

◆ EnsureNoTrainOnTrackBits()

CommandCost EnsureNoTrainOnTrackBits ( TileIndex  tile,
TrackBits  track_bits 
)

Tests if a vehicle interacts with the specified track bits.

All track bits interact except parallel TRACK_BIT_HORZ or TRACK_BIT_VERT.

Parameters
tileThe tile.
track_bitsThe track bits.
Returns
true if no train that interacts, is found. false if a train is found.

Definition at line 600 of file vehicle.cpp.

References VehicleFromPos().

Referenced by CmdConvertRail(), and EnsureNoTrainOnTrack().

◆ EnsureNoVehicleOnGround()

CommandCost EnsureNoVehicleOnGround ( TileIndex  tile)

Ensure there is no vehicle at the ground at the given position.

Parameters
tilePosition to examine.
Returns
Succeeded command (ground is free) or failed command (a vehicle is found).

Definition at line 538 of file vehicle.cpp.

References EnsureNoVehicleProcZ(), GetTileMaxPixelZ(), return_cmd_error, BaseVehicle::type, and VehicleFromPos().

Referenced by CheckBuildableTile(), CheckIfIndustryTilesAreFree(), CmdConvertRail(), DoBuildLock(), RemoveAirport(), RemoveBuoy(), RemoveDock(), RemoveFromRailBaseStation(), RemoveLock(), and RemoveRoad().

◆ EnsureNoVehicleProcZ()

static Vehicle* EnsureNoVehicleProcZ ( Vehicle v,
void *  data 
)
static

Callback that returns 'real' vehicles lower or at height *(int*)data .

Parameters
vVehicle to examine.
dataPointer to height data.
Returns
v if conditions are met, else NULL.

Definition at line 523 of file vehicle.cpp.

References AIR_SHADOW, Vehicle::subtype, BaseVehicle::type, VEH_AIRCRAFT, VEH_DISASTER, and Vehicle::z_pos.

Referenced by EnsureNoVehicleOnGround().

◆ FindVehicleOnPos()

void FindVehicleOnPos ( TileIndex  tile,
void *  data,
VehicleFromPosProc *  proc 
)

Find a vehicle from a specific location.

It will call proc for ALL vehicles on the tile and YOU must make SURE that the "best one" is stored in the data value and is ALWAYS the same regardless of the order of the vehicles where proc was called on! When you fail to do this properly you create an almost untraceable DESYNC!

Note
The return value of proc will be ignored.
Use this function when you have the intention that all vehicles should be iterated over.
Parameters
tileThe location on the map
dataArbitrary data passed to proc.
procThe proc that determines whether a vehicle will be "found".

Definition at line 497 of file vehicle.cpp.

Referenced by CmdConvertRail(), DeleteLastWagon(), and FloodVehicles().

◆ FindVehicleOnPosXY()

void FindVehicleOnPosXY ( int  x,
int  y,
void *  data,
VehicleFromPosProc *  proc 
)

Find a vehicle from a specific location.

It will call proc for ALL vehicles on the tile and YOU must make SURE that the "best one" is stored in the data value and is ALWAYS the same regardless of the order of the vehicles where proc was called on! When you fail to do this properly you create an almost untraceable DESYNC!

Note
The return value of proc will be ignored.
Use this when you have the intention that all vehicles should be iterated over.
Parameters
xThe X location on the map
yThe Y location on the map
dataArbitrary data passed to proc
procThe proc that determines whether a vehicle will be "found".

Definition at line 437 of file vehicle.cpp.

◆ GetEngineLivery()

const Livery* GetEngineLivery ( EngineID  engine_type,
CompanyID  company,
EngineID  parent_engine_type,
const Vehicle v,
byte  livery_setting 
)

Determines the livery for a vehicle.

Parameters
engine_typeEngineID of the vehicle
companyOwner of the vehicle
parent_engine_typeEngineID of the front vehicle. INVALID_VEHICLE if vehicle is at front itself.
vthe vehicle. NULL if in purchase list etc.
livery_settingThe livery settings to use for acquiring the livery information.
Returns
livery to use

Definition at line 1876 of file vehicle.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get().

Referenced by IsCompanyBuildableVehicleType(), and LiveryHelper().

◆ GetEngineLiveryScheme()

LiveryScheme GetEngineLiveryScheme ( EngineID  engine_type,
EngineID  parent_engine_type,
const Vehicle v 
)

Determines the LiveryScheme for a vehicle.

Parameters
engine_typeEngine of the vehicle.
parent_engine_typeEngine of the front vehicle, INVALID_ENGINE if vehicle is at front itself.
vthe vehicle, NULL if in purchase list etc.
Returns
livery scheme to use.

Definition at line 1786 of file vehicle.cpp.

References Vehicle::cargo_type, CT_INVALID, and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get().

Referenced by IsCompanyBuildableVehicleType().

◆ GetEnginePalette()

PaletteID GetEnginePalette ( EngineID  engine_type,
CompanyID  company 
)

Get the colour map for an engine.

This used for unbuilt engines in the user interface.

Parameters
engine_typeID of engine
companyID of company
Returns
A ready-to-use palette modifier

Definition at line 1944 of file vehicle.cpp.

Referenced by IsCompanyBuildableVehicleType().

◆ GetFreeUnitNumber()

UnitID GetFreeUnitNumber ( VehicleType  type)

Get an unused unit number for a vehicle (if allowed).

Parameters
typeType of vehicle
Returns
A unused unit number for the given type of vehicle if it is allowed to build one, else UINT16_MAX.

Definition at line 1714 of file vehicle.cpp.

References _settings_game, VehicleSettings::max_aircraft, VehicleSettings::max_roadveh, VehicleSettings::max_ships, VehicleSettings::max_trains, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, and GameSettings::vehicle.

Referenced by CheckNewTrain(), and NormaliseTrainHead().

◆ GetNewVehiclePos()

GetNewVehiclePosResult GetNewVehiclePos ( const Vehicle v)

Get position information of a vehicle when moving one pixel in the direction it is facing.

Parameters
vVehicle to move
Returns
Position information after the move

Definition at line 1608 of file vehicle.cpp.

Referenced by DisasterTick_Aircraft(), DisasterTick_Big_Ufo_Destroyer(), DisasterTick_Submarine(), DisasterTick_Zeppeliner(), and TrainController().

◆ GetVehiclePalette()

PaletteID GetVehiclePalette ( const Vehicle v)

Get the colour map for a vehicle.

Parameters
vVehicle to get colour map for
Returns
A ready-to-use palette modifier

Definition at line 1954 of file vehicle.cpp.

References Vehicle::IsGroundVehicle().

Referenced by IsCompanyBuildableVehicleType().

◆ GetVehicleSet()

void GetVehicleSet ( VehicleSet set,
Vehicle v,
uint8  num_vehicles 
)

Calculates the set of vehicles that will be affected by a given selection.

Parameters
set[inout] Set of affected vehicles.
vFirst vehicle of the selection.
num_vehiclesNumber of vehicles in the selection (not counting articulated parts).
Precondition
set must be empty.
Postcondition
set will contain the vehicles that will be refitted.

Definition at line 2860 of file vehicle.cpp.

References SpecializedVehicle< Train, Type >::From(), SpecializedVehicle< T, Type >::GetFirstEnginePart(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::IsArticulatedPart(), GroundVehicle< T, Type >::IsMultiheaded(), SpecializedVehicle< T, Type >::Next(), BaseVehicle::type, and VEH_TRAIN.

Referenced by RefitWindow::BuildRefitList().

◆ HasVehicleOnPos()

bool HasVehicleOnPos ( TileIndex  tile,
void *  data,
VehicleFromPosProc *  proc 
)

Checks whether a vehicle is on a specific location.

It will call proc for vehicles until it returns non-NULL.

Note
Use FindVehicleOnPos when you have the intention that all vehicles should be iterated over.
Parameters
tileThe location on the map
dataArbitrary data passed to proc.
procThe proc that determines whether a vehicle will be "found".
Returns
True if proc returned non-NULL.

Definition at line 512 of file vehicle.cpp.

Referenced by CheckRoadBlockedForOvertaking().

◆ HasVehicleOnPosXY()

bool HasVehicleOnPosXY ( int  x,
int  y,
void *  data,
VehicleFromPosProc *  proc 
)

Checks whether a vehicle in on a specific location.

It will call proc for vehicles until it returns non-NULL.

Note
Use FindVehicleOnPosXY when you have the intention that all vehicles should be iterated over.
Parameters
xThe X location on the map
yThe Y location on the map
dataArbitrary data passed to proc
procThe proc that determines whether a vehicle will be "found".
Returns
True if proc returned non-NULL.

Definition at line 453 of file vehicle.cpp.

◆ RunVehicleDayProc()

static void RunVehicleDayProc ( )
static

Increases the day counter for all vehicles and calls 1-day and 32-day handlers.

Each tick, it processes vehicles with "index % DAY_TICKS == _date_fract", so each day, all vehicles are processes in DAY_TICKS steps.

Definition at line 912 of file vehicle.cpp.

◆ ShowNewGrfVehicleError()

void ShowNewGrfVehicleError ( EngineID  engine,
StringID  part1,
StringID  part2,
GRFBugs  bug_type,
bool  critical 
)

Displays a "NewGrf Bug" error message for a engine, and pauses the game if not networking.

Parameters
engineThe engine that caused the problem
part1Part 1 of the error message, taking the grfname as parameter 1
part2Part 2 of the error message, taking the engine as parameter 2
bug_typeFlag to check and set in grfconfig
criticalShall the "OpenTTD might crash"-message be shown when the player tries to unpause?

Definition at line 297 of file vehicle.cpp.

References _networking, CMD_PAUSE, DC_EXEC, DoCommand(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetGRFConfig(), Engine::GetGRFID(), GRFConfig::GetName(), GRFConfig::grf_bugs, HasBit(), PM_PAUSED_ERROR, PM_PAUSED_NORMAL, SetBit(), SetDParam(), SetDParamStr(), ShowErrorMessage(), and WL_CRITICAL.

Referenced by VehicleLengthChanged().

◆ SpawnAdvancedVisualEffect()

static void SpawnAdvancedVisualEffect ( const Vehicle v)
static

Call CBID_VEHICLE_SPAWN_VISUAL_EFFECT and spawn requested effects.

Parameters
vVehicle to create effects for.

Definition at line 2426 of file vehicle.cpp.

References CBID_VEHICLE_SPAWN_VISUAL_EFFECT, and GetVehicleCallback().

◆ TunnelBridgeIsFree()

CommandCost TunnelBridgeIsFree ( TileIndex  tile,
TileIndex  endtile,
const Vehicle ignore 
)

Finds vehicle in tunnel / bridge.

Parameters
tilefirst end
endtilesecond end
ignoreIgnore this vehicle when searching
Returns
Succeeded command (if tunnel/bridge is free) or failed command (if a vehicle is using the tunnel/bridge).

Definition at line 567 of file vehicle.cpp.

References GetVehicleTunnelBridgeProc(), return_cmd_error, BaseVehicle::type, and VehicleFromPos().

Referenced by ClearPathReservation(), CmdConvertRail(), DoClearBridge(), DoClearTunnel(), and RemoveRoad().

◆ VehicleEnterDepot()

void VehicleEnterDepot ( Vehicle v)

Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it, etc.

Parameters
vVehicle that entered a depot.

Definition at line 1426 of file vehicle.cpp.

Referenced by AircraftEventHandler_EnterHangar().

◆ VehicleEnteredDepotThisTick()

void VehicleEnteredDepotThisTick ( Vehicle v)

Adds a vehicle to the list of vehicles that visited a depot this tick.

Parameters
*vvehicle to add

Definition at line 894 of file vehicle.cpp.

References Vehicle::vehstatus, and VS_STOPPED.

◆ VehicleEnterTile()

VehicleEnterTileStatus VehicleEnterTile ( Vehicle v,
TileIndex  tile,
int  x,
int  y 
)

Call the tile callback function for a vehicle entering a tile.

Parameters
vVehicle entering the tile
tileTile entered
xX position
yY position
Returns
Some meta-data over the to be entered tile.
See also
VehicleEnterTileStatus to see what the bits in the return value mean.

Definition at line 1662 of file vehicle.cpp.

Referenced by TrainController(), and UpdateStatusAfterSwap().

◆ VehicleFromPos()

static Vehicle* VehicleFromPos ( TileIndex  tile,
void *  data,
VehicleFromPosProc *  proc,
bool  find_first 
)
static

Helper function for FindVehicleOnPos/HasVehicleOnPos.

Note
Do not call this function directly!
Parameters
tileThe location on the map
dataArbitrary data passed to proc.
procThe proc that determines whether a vehicle will be "found".
find_firstWhether to return on the first found or iterate over all vehicles
Returns
the best matching or first vehicle (depending on find_first).

Definition at line 468 of file vehicle.cpp.

Referenced by EnsureNoTrainOnTrackBits(), EnsureNoVehicleOnGround(), and TunnelBridgeIsFree().

◆ VehicleFromPosXY()

static Vehicle* VehicleFromPosXY ( int  x,
int  y,
void *  data,
VehicleFromPosProc *  proc,
bool  find_first 
)
static

Helper function for FindVehicleOnPos/HasVehicleOnPos.

Note
Do not call this function directly!
Parameters
xThe X location on the map
yThe Y location on the map
dataArbitrary data passed to proc
procThe proc that determines whether a vehicle will be "found".
find_firstWhether to return on the first found or iterate over all vehicles
Returns
the best matching or first vehicle (depending on find_first).

Definition at line 410 of file vehicle.cpp.

◆ VehicleLengthChanged()

void VehicleLengthChanged ( const Vehicle u)

Logs a bug in GRF and shows a warning message if this is for the first time this happened.

Parameters
ufirst vehicle of chain

Definition at line 330 of file vehicle.cpp.

References Vehicle::engine_type, GamelogGRFBugReverse(), GBUG_VEH_LENGTH, Vehicle::GetEngine(), GetGRFConfig(), GRFConfig::grf_bugs, Engine::grf_prop, GRFFilePropsBase< Tcnt >::grffile, HasBit(), GRFFilePropsBase< Tcnt >::local_id, and ShowNewGrfVehicleError().

◆ VehicleRandomBits()

byte VehicleRandomBits ( )

Get a value for a vehicle's random_bits.

Returns
A random value from 0 to 255.

Definition at line 362 of file vehicle.cpp.

References GB().

◆ VehicleServiceInDepot()

void VehicleServiceInDepot ( Vehicle v)

Service a vehicle and all subsequent vehicles in the consist.

Parameters
*vThe vehicle or vehicle chain being serviced

Definition at line 163 of file vehicle.cpp.

Referenced by AircraftLeaveHangar(), and CheckIfTrainNeedsService().

◆ ViewportAddVehicles()

void ViewportAddVehicles ( DrawPixelInfo dpi)

Add the vehicle sprites that should be drawn at a part of the screen.

Parameters
dpiRectangle being drawn.

Definition at line 1103 of file vehicle.cpp.

References MAX_VEHICLE_PIXEL_X.

Variable Documentation

◆ _breakdown_chance

const byte _breakdown_chance[64]
static
Initial value:
= {
3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 5, 5, 6, 6, 7, 7,
8, 8, 9, 9, 10, 10, 11, 11,
12, 13, 13, 13, 13, 14, 15, 16,
17, 19, 21, 25, 28, 31, 34, 37,
40, 44, 48, 52, 56, 60, 64, 68,
72, 80, 90, 100, 110, 120, 130, 140,
150, 170, 190, 210, 230, 250, 250, 250,
}

Definition at line 1201 of file vehicle.cpp.

◆ _new_direction_table

const Direction _new_direction_table[]
static
Initial value:
= {
}
East.
Southeast.
Northeast.
West.
North.
Northwest.
South.
Southwest.

Definition at line 1626 of file vehicle.cpp.

◆ _vehicle_pool

VehiclePool _vehicle_pool("Vehicle")

The pool with all our precious vehicles.

◆ _vehicle_smoke_pos

const int8 _vehicle_smoke_pos[8]
static
Initial value:
= {
1, 1, 1, 0, -1, -1, -1, 0
}

Definition at line 2418 of file vehicle.cpp.