OpenTTD Source 20250428-master-ga5578166bb
vehicle_func.h File Reference

Functions related to vehicles. More...

#include "gfx_type.h"
#include "direction_type.h"
#include "timer/timer_game_economy.h"
#include "command_type.h"
#include "vehicle_type.h"
#include "engine_type.h"
#include "transport_type.h"
#include "newgrf_config.h"
#include "track_type.h"
#include "livery.h"

Go to the source code of this file.

Data Structures

class  VehiclesOnTile
 Iterate over all vehicles on a tile. More...
 
class  VehiclesOnTile::Iterator
 Forward iterator. More...
 
class  VehiclesNearTileXY
 Iterate over all vehicles near a given world coordinate. More...
 
class  VehiclesNearTileXY::Iterator
 Forward iterator. More...
 
struct  GetNewVehiclePosResult
 Position information of a vehicle after it moved. More...
 

Typedefs

typedef std::vector< VehicleIDVehicleSet
 

Enumerations

enum  CustomVehicleSpriteNum { CUSTOM_VEHICLE_SPRITENUM = 0xFD , CUSTOM_VEHICLE_SPRITENUM_REVERSED = 0xFE }
 Special values for Vehicle::spritenum and (Aircraft|Rail|Road|Ship)VehicleInfo::image_index. More...
 

Functions

static bool IsCustomVehicleSpriteNum (uint8_t spritenum)
 
template<VehicleType T>
bool IsValidImageIndex (uint8_t image_index)
 Helper to check whether an image index is valid for a particular vehicle.
 
template<class UnaryPred >
bool HasVehicleOnTile (TileIndex tile, UnaryPred &&predicate)
 Loop over vehicles on a tile, and check whether a predicate is true for any of them.
 
template<class UnaryPred >
bool HasVehicleNearTileXY (int32_t x, int32_t y, uint max_dist, UnaryPred &&predicate)
 Loop over vehicles near a given world coordinate, and check whether a predicate is true for any of them.
 
void VehicleServiceInDepot (Vehicle *v)
 Service a vehicle and all subsequent vehicles in the consist.
 
uint CountVehiclesInChain (const Vehicle *v)
 
void CallVehicleTicks ()
 
uint8_t CalcPercentVehicleFilled (const Vehicle *v, StringID *colour)
 Calculates how full a vehicle is.
 
void VehicleLengthChanged (const Vehicle *u)
 Logs a bug in GRF and shows a warning message if this is for the first time this happened.
 
void ResetVehicleHash ()
 
void ResetVehicleColourMap ()
 
uint8_t GetBestFittingSubType (Vehicle *v_from, Vehicle *v_for, CargoType dest_cargo_type)
 Get the best fitting subtype when 'cloning'/'replacing' v_from with v_for.
 
void ViewportAddVehicles (DrawPixelInfo *dpi)
 Add the vehicle sprites that should be drawn at a part of the screen.
 
void ShowNewGrfVehicleError (EngineID engine, StringID part1, StringID part2, GRFBug bug_type, bool critical)
 Displays a "NewGrf Bug" error message for a engine, and pauses the game if not networking.
 
CommandCost TunnelBridgeIsFree (TileIndex tile, TileIndex endtile, const Vehicle *ignore=nullptr)
 Finds vehicle in tunnel / bridge.
 
void DecreaseVehicleValue (Vehicle *v)
 Decrease the value of a vehicle.
 
void CheckVehicleBreakdown (Vehicle *v)
 
void EconomyAgeVehicle (Vehicle *v)
 Update economy age of a vehicle.
 
void AgeVehicle (Vehicle *v)
 Update age of a vehicle.
 
void RunVehicleCalendarDayProc ()
 Age all vehicles, spreading out the action using the current TimerGameCalendar::date_fract.
 
UnitID GetFreeUnitNumber (VehicleType type)
 Get an unused unit number for a vehicle (if allowed).
 
void VehicleEnterDepot (Vehicle *v)
 Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it, etc.
 
bool CanBuildVehicleInfrastructure (VehicleType type, uint8_t subtype=0)
 Check whether we can build infrastructure for the given vehicle type.
 
GetNewVehiclePosResult GetNewVehiclePos (const Vehicle *v)
 Get position information of a vehicle when moving one pixel in the direction it is facing.
 
Direction GetDirectionTowards (const Vehicle *v, int x, int y)
 
bool IsCompanyBuildableVehicleType (VehicleType type)
 Is the given vehicle type buildable by a company?
 
bool IsCompanyBuildableVehicleType (const BaseVehicle *v)
 Is the given vehicle buildable by a company?
 
LiveryScheme GetEngineLiveryScheme (EngineID engine_type, EngineID parent_engine_type, const Vehicle *v)
 Determines the LiveryScheme for a vehicle.
 
const struct LiveryGetEngineLivery (EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, uint8_t livery_setting)
 Determines the livery for a vehicle.
 
SpriteID GetEnginePalette (EngineID engine_type, CompanyID company)
 Get the colour map for an engine.
 
SpriteID GetVehiclePalette (const Vehicle *v)
 Get the colour map for a vehicle.
 
StringID GetCmdBuildVehMsg (VehicleType type)
 
StringID GetCmdBuildVehMsg (const BaseVehicle *v)
 
StringID GetCmdSellVehMsg (VehicleType type)
 
StringID GetCmdSellVehMsg (const BaseVehicle *v)
 
StringID GetCmdSellAllVehMsg (VehicleType type)
 
StringID GetCmdAutoreplaceVehMsg (VehicleType type)
 
StringID GetCmdRefitVehMsg (VehicleType type)
 
StringID GetCmdRefitVehMsg (const BaseVehicle *v)
 
StringID GetCmdSendToDepotMsg (VehicleType type)
 
StringID GetCmdSendToDepotMsg (const BaseVehicle *v)
 
CommandCost EnsureNoVehicleOnGround (TileIndex tile)
 Ensure there is no vehicle at the ground at the given position.
 
CommandCost EnsureNoTrainOnTrackBits (TileIndex tile, TrackBits track_bits)
 Tests if a vehicle interacts with the specified track bits.
 
bool CanVehicleUseStation (EngineID engine_type, const struct Station *st)
 
bool CanVehicleUseStation (const Vehicle *v, const struct Station *st)
 
StringID GetVehicleCannotUseStationReason (const Vehicle *v, const Station *st)
 Get reason string why this station can't be used by the given vehicle.
 
void ReleaseDisasterVehicle (VehicleID vehicle)
 Notify disasters that we are about to delete a vehicle.
 
void GetVehicleSet (VehicleSet &set, Vehicle *v, uint8_t num_vehicles)
 Calculates the set of vehicles that will be affected by a given selection.
 
void CheckCargoCapacity (Vehicle *v)
 Check the capacity of all vehicles in a chain and spread cargo if needed.
 
bool VehiclesHaveSameEngineList (const Vehicle *v1, const Vehicle *v2)
 Checks if two vehicle chains have the same list of engines.
 
bool VehiclesHaveSameOrderList (const Vehicle *v1, const Vehicle *v2)
 Checks if two vehicles have the same list of orders.
 
bool IsUniqueVehicleName (const std::string &name)
 Test if a name is unique among vehicle names.
 

Variables

static const TimerGameEconomy::Date VEHICLE_PROFIT_MIN_AGE {CalendarTime::DAYS_IN_YEAR * 2}
 Only vehicles older than this have a meaningful profit.
 
static const Money VEHICLE_PROFIT_THRESHOLD = 10000
 Threshold for a vehicle to be considered making good profit.
 
const StringID _veh_build_msg_table []
 
const StringID _veh_sell_msg_table []
 
const StringID _veh_sell_all_msg_table []
 
const StringID _veh_autoreplace_msg_table []
 
const StringID _veh_refit_msg_table []
 
const StringID _send_to_depot_msg_table []
 

Detailed Description

Functions related to vehicles.

Definition in file vehicle_func.h.

Typedef Documentation

◆ VehicleSet

typedef std::vector<VehicleID> VehicleSet

Definition at line 316 of file vehicle_func.h.

Enumeration Type Documentation

◆ CustomVehicleSpriteNum

Special values for Vehicle::spritenum and (Aircraft|Rail|Road|Ship)VehicleInfo::image_index.

Enumerator
CUSTOM_VEHICLE_SPRITENUM 

Vehicle sprite from NewGRF.

CUSTOM_VEHICLE_SPRITENUM_REVERSED 

Vehicle sprite from NewGRF with reverse driving direction (from articulation callback)

Definition at line 27 of file vehicle_func.h.

Function Documentation

◆ AgeVehicle()

◆ CalcPercentVehicleFilled()

uint8_t 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 1462 of file vehicle.cpp.

References Vehicle::cargo, Vehicle::cargo_cap, Vehicle::cargo_type, CargoUnloading, CeilDiv(), Vehicle::current_order, SpecializedStation< Station, false >::GetIfValid(), Order::GetLoadType(), Station::goods, Order::IsType(), Vehicle::last_station_visited, LoadingFinished, Vehicle::Next(), OLFB_FULL_LOAD, OLFB_NO_LOAD, StopLoading, VehicleCargoList::StoredCount(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and BaseConsist::vehicle_flags.

Referenced by AfterLoadVehiclesPhase2(), Vehicle::LeaveStation(), LoadUnloadVehicle(), and ProcessConditionalOrder().

◆ CallVehicleTicks()

void CallVehicleTicks ( )

Definition at line 954 of file vehicle.cpp.

◆ CanBuildVehicleInfrastructure()

◆ CheckCargoCapacity()

void CheckCargoCapacity ( Vehicle v)

Check the capacity of all vehicles in a chain and spread cargo if needed.

Parameters
vThe vehicle to check.
Precondition
You can only do this if the consist is not loading or unloading. It must not carry reserved cargo, nor cargo to be unloaded or transferred.

Definition at line 107 of file autoreplace_cmd.cpp.

References Vehicle::First(), CargoList< VehicleCargoList, CargoPacketList >::MTA_KEEP, and Vehicle::Next().

Referenced by CmdMoveRailVehicle(), and ReplaceChain().

◆ CheckVehicleBreakdown()

void CheckVehicleBreakdown ( Vehicle v)

Definition at line 1288 of file vehicle.cpp.

◆ CountVehiclesInChain()

uint CountVehiclesInChain ( const Vehicle v)

Definition at line 674 of file vehicle.cpp.

◆ DecreaseVehicleValue()

void DecreaseVehicleValue ( Vehicle v)

◆ EconomyAgeVehicle()

◆ 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 575 of file vehicle.cpp.

References SpecializedVehicle< T, Type >::From(), TracksOverlap(), and VEH_TRAIN.

Referenced by CmdConvertRail(), EnsureNoTrainOnTrack(), and ExploreSegment().

◆ EnsureNoVehicleOnGround()

CommandCost EnsureNoVehicleOnGround ( TileIndex  tile)

◆ GetBestFittingSubType()

uint8_t GetBestFittingSubType ( Vehicle v_from,
Vehicle v_for,
CargoType  dest_cargo_type 
)

Get the best fitting subtype when 'cloning'/'replacing' v_from with v_for.

All articulated parts of both vehicles are tested to find a possibly shared subtype. For v_for only vehicle refittable to dest_cargo_type are considered.

Parameters
v_fromthe vehicle to match the subtype from
v_forthe vehicle to get the subtype for
dest_cargo_typeDestination cargo type.
Returns
the best sub type

Definition at line 601 of file vehicle_gui.cpp.

References EngineInfo::callback_mask, Engine::CanCarryCargo(), CargoSuffix, GetCargoSubtypeText(), Vehicle::GetEngine(), Vehicle::GetFirstEnginePart(), Vehicle::GetNextArticulatedPart(), Vehicle::HasArticulatedPart(), HasBit(), include(), MAX_REFIT_CYCLE, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by BuildReplacementVehicle(), CmdCloneVehicle(), LinkRefresher::HandleRefit(), and RefitVehicle().

◆ GetCmdAutoreplaceVehMsg()

StringID GetCmdAutoreplaceVehMsg ( VehicleType  type)
inline

Definition at line 282 of file vehicle_func.h.

◆ GetCmdBuildVehMsg() [1/2]

StringID GetCmdBuildVehMsg ( const BaseVehicle v)
inline

Definition at line 262 of file vehicle_func.h.

◆ GetCmdBuildVehMsg() [2/2]

StringID GetCmdBuildVehMsg ( VehicleType  type)
inline

Definition at line 257 of file vehicle_func.h.

◆ GetCmdRefitVehMsg() [1/2]

StringID GetCmdRefitVehMsg ( const BaseVehicle v)
inline

Definition at line 292 of file vehicle_func.h.

◆ GetCmdRefitVehMsg() [2/2]

StringID GetCmdRefitVehMsg ( VehicleType  type)
inline

Definition at line 287 of file vehicle_func.h.

◆ GetCmdSellAllVehMsg()

StringID GetCmdSellAllVehMsg ( VehicleType  type)
inline

Definition at line 277 of file vehicle_func.h.

◆ GetCmdSellVehMsg() [1/2]

StringID GetCmdSellVehMsg ( const BaseVehicle v)
inline

Definition at line 272 of file vehicle_func.h.

◆ GetCmdSellVehMsg() [2/2]

StringID GetCmdSellVehMsg ( VehicleType  type)
inline

Definition at line 267 of file vehicle_func.h.

◆ GetCmdSendToDepotMsg() [1/2]

StringID GetCmdSendToDepotMsg ( const BaseVehicle v)
inline

Definition at line 302 of file vehicle_func.h.

◆ GetCmdSendToDepotMsg() [2/2]

StringID GetCmdSendToDepotMsg ( VehicleType  type)
inline

Definition at line 297 of file vehicle_func.h.

◆ GetDirectionTowards()

Direction GetDirectionTowards ( const Vehicle v,
int  x,
int  y 
)

Definition at line 1778 of file vehicle.cpp.

◆ GetEngineLivery()

const struct Livery * GetEngineLivery ( EngineID  engine_type,
CompanyID  company,
EngineID  parent_engine_type,
const Vehicle v,
uint8_t  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. VehicleID::Invalid() if vehicle is at front itself.
vthe vehicle. nullptr if in purchase list etc.
livery_settingThe livery settings to use for acquiring the livery information.
Returns
livery to use

Definition at line 2034 of file vehicle.cpp.

References _local_company, Vehicle::First(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), GetEngineLiveryScheme(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::GetIfValid(), Vehicle::group_id, Livery::in_use, LIT_ALL, LIT_COMPANY, Group::livery, and Group::parent.

Referenced by LiveryHelper().

◆ GetEngineLiveryScheme()

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

◆ GetEnginePalette()

SpriteID 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 2112 of file vehicle.cpp.

Referenced by DrawEngineList(), EnginePreviewWindow::DrawWidget(), and NewsWindow::DrawWidget().

◆ 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 1865 of file vehicle.cpp.

References _current_company, _settings_game, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), Company::group_all, 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(), CmdBuildVehicle(), and NormaliseTrainHead().

◆ GetNewVehiclePos()

GetNewVehiclePosResult GetNewVehiclePos ( const Vehicle v)

◆ GetVehicleCannotUseStationReason()

StringID GetVehicleCannotUseStationReason ( const Vehicle v,
const Station st 
)

◆ GetVehiclePalette()

SpriteID 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 2122 of file vehicle.cpp.

References Vehicle::engine_type, GroundVehicleCache::first_engine, Vehicle::GetGroundVehicleCache(), Vehicle::IsGroundVehicle(), and Vehicle::owner.

Referenced by DoDrawVehicle(), DrawAircraftImage(), DrawRoadVehImage(), DrawShipImage(), DrawTrainDetails(), DrawTrainImage(), and SetMouseCursorVehicle().

◆ GetVehicleSet()

void GetVehicleSet ( VehicleSet &  set,
Vehicle v,
uint8_t  num_vehicles 
)

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

Parameters
[in,out]setSet 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 3186 of file vehicle.cpp.

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

Referenced by RefitWindow::BuildRefitList(), RefitWindow::DrawWidget(), and RefitVehicle().

◆ HasVehicleNearTileXY()

template<class UnaryPred >
bool HasVehicleNearTileXY ( int32_t  x,
int32_t  y,
uint  max_dist,
UnaryPred &&  predicate 
)

Loop over vehicles near a given world coordinate, and check whether a predicate is true for any of them.

The predicate must have the signature: bool Predicate(const Vehicle *);

Warning
This only works for vehicles with proper Vehicle::Tile, so only ground vehicles outside wormholes.

Definition at line 176 of file vehicle_func.h.

◆ HasVehicleOnTile()

template<class UnaryPred >
bool HasVehicleOnTile ( TileIndex  tile,
UnaryPred &&  predicate 
)

Loop over vehicles on a tile, and check whether a predicate is true for any of them.

The predicate must have the signature: bool Predicate(const Vehicle *);

Definition at line 106 of file vehicle_func.h.

Referenced by CheckRoadBlockedForOvertaking(), ExploreSegment(), TrainApproachingCrossing(), TrainController(), and TrainOnCrossing().

◆ IsCompanyBuildableVehicleType() [1/2]

bool IsCompanyBuildableVehicleType ( const BaseVehicle v)
inline

Is the given vehicle buildable by a company?

Parameters
vVehicle being queried.
Returns
Vehicle is buildable by a company.

Definition at line 238 of file vehicle_func.h.

References IsCompanyBuildableVehicleType(), and BaseVehicle::type.

◆ IsCompanyBuildableVehicleType() [2/2]

bool IsCompanyBuildableVehicleType ( VehicleType  type)
inline

◆ IsCustomVehicleSpriteNum()

static bool IsCustomVehicleSpriteNum ( uint8_t  spritenum)
inlinestatic

Definition at line 32 of file vehicle_func.h.

◆ IsUniqueVehicleName()

bool IsUniqueVehicleName ( const std::string &  name)

Test if a name is unique among vehicle names.

Parameters
nameName to test.
Returns
True ifffffff the name is unique.

Definition at line 766 of file vehicle_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Iterate().

Referenced by CloneVehicleName(), CmdRenameVehicle(), and OrderBackup::DoRestore().

◆ IsValidImageIndex()

template<VehicleType T>
bool IsValidImageIndex ( uint8_t  image_index)

Helper to check whether an image index is valid for a particular vehicle.

Template Parameters
TThe type of vehicle.
Parameters
image_indexThe image index to check.
Returns
True iff the image index is valid.

◆ ReleaseDisasterVehicle()

void ReleaseDisasterVehicle ( VehicleID  vehicle)

◆ ResetVehicleColourMap()

void ResetVehicleColourMap ( )

Definition at line 656 of file vehicle.cpp.

◆ ResetVehicleHash()

void ResetVehicleHash ( )

Definition at line 649 of file vehicle.cpp.

◆ RunVehicleCalendarDayProc()

◆ ShowNewGrfVehicleError()

void ShowNewGrfVehicleError ( EngineID  engine,
StringID  part1,
StringID  part2,
GRFBug  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 328 of file vehicle.cpp.

References _networking, Debug, Error, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), GetEncodedString(), GetGRFConfig(), Engine::GetGRFID(), GRFConfig::GetName(), GetString(), GRFConfig::grf_bugs, Normal, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), ShowErrorMessage(), StrMakeValid(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and WL_CRITICAL.

Referenced by CheckConsistencyOfArticulatedVehicle(), Train::ConsistChanged(), Vehicle::UpdateVisualEffect(), and VehicleLengthChanged().

◆ 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 551 of file vehicle.cpp.

References VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by ClearPathReservation(), CmdBuildRoad(), CmdConvertRail(), CmdConvertRoad(), 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 1521 of file vehicle.cpp.

References _current_company, _local_company, _settings_client, AddVehicleAdviceNewsItem(), CCF_ARRANGE, Clamp(), ClrBit(), Train::ConsistChanged(), TimerGameTick::counter, BaseConsist::cur_real_order_index, Vehicle::cur_speed, Vehicle::current_order, Vehicle::DeleteUnreachedImplicitOrders(), Depot, BaseConsist::depot_unbunching_last_departure, Vehicle::dest_tile, Execute, CommandCost::Failed(), Vehicle::First(), SpecializedVehicle< T, Type >::From(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedVehicle< Ship, VEH_SHIP >::From(), CommandCost::GetCost(), Order::GetDepotActionType(), Order::GetDepotOrderType(), Order::GetDestination(), GetEncodedString(), Vehicle::GetOrder(), Order::GetRefitCargo(), GetStationIndex(), ClientSettings::gui, HandleAircraftEnterHangar(), Hidden, Vehicle::IncrementImplicitOrderIndex(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, INVALID_DIAGDIR, InvalidateWindowData(), Order::IsRefit(), Order::IsType(), Vehicle::last_loading_station, Order::MakeDummy(), Vehicle::MarkDirty(), MarkTileDirtyByTile(), AI::NewEvent(), ODATFB_HALT, ODATFB_NEAREST_DEPOT, ODATFB_UNBUNCH, ODTFB_PART_OF_ORDERS, Vehicle::owner, Vehicle::profit_this_year, RefitFailed, BaseConsist::ResetDepotUnbunching(), Backup< T >::Restore(), BaseConsist::round_trip_time, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SetDepotReservation(), SetWindowClassesDirty(), SetWindowDirty(), GUISettings::show_track_reservation, ShowCostOrIncomeAnimation(), Ship::state, TFP_NONE, Vehicle::tile, TRACK_BIT_DEPOT, BaseVehicle::type, Ship::UpdateCache(), UpdateSignalsOnSegment(), UpdateVehicleTimetable(), SpecializedVehicle< T, Type >::UpdateViewport(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, VehicleEnteredDepotThisTick(), VehicleServiceInDepot(), VehicleWaiting, Vehicle::vehstatus, VRF_TOGGLE_REVERSE, Train::wait_counter, WC_AIRCRAFT_LIST, WC_ROADVEH_LIST, WC_SHIPS_LIST, WC_TRAINS_LIST, WC_VEHICLE_DEPOT, WC_VEHICLE_VIEW, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.

Referenced by AircraftEventHandler_EnterHangar(), AircraftEventHandler_InHangar(), CheckTrainStayInDepot(), and VehicleEnter_Track().

◆ 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 354 of file vehicle.cpp.

References _gamelog, Vehicle::engine_type, Vehicle::GetEngine(), GetGRFConfig(), GRFConfig::grf_bugs, Engine::grf_prop, Gamelog::GRFBugReverse(), GRFFilePropsBase::grfid, GRFFilePropsBase::local_id, ShowNewGrfVehicleError(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and VehLength.

Referenced by Train::ConsistChanged(), and RoadVehUpdateCache().

◆ VehicleServiceInDepot()

◆ VehiclesHaveSameEngineList()

bool VehiclesHaveSameEngineList ( const Vehicle v1,
const Vehicle v2 
)

Checks if two vehicle chains have the same list of engines.

Parameters
v1First vehicle chain.
v1Second vehicle chain.
Returns
True if same, false if different.

Definition at line 3240 of file vehicle.cpp.

References Vehicle::GetEngine(), and Vehicle::GetNextVehicle().

Referenced by DepotWindow::OnVehicleSelect().

◆ VehiclesHaveSameOrderList()

bool VehiclesHaveSameOrderList ( const Vehicle v1,
const Vehicle v2 
)

Checks if two vehicles have the same list of orders.

Parameters
v1First vehicles.
v1Second vehicles.
Returns
True if same, false if different.

Definition at line 3257 of file vehicle.cpp.

References Order::Equals(), Vehicle::GetFirstOrder(), and Order::next.

Referenced by DepotWindow::OnVehicleSelect(), and OrdersWindow::OnVehicleSelect().

◆ ViewportAddVehicles()

Variable Documentation

◆ _send_to_depot_msg_table

const StringID _send_to_depot_msg_table[]
extern

Definition at line 82 of file vehicle_cmd.cpp.

◆ _veh_autoreplace_msg_table

const StringID _veh_autoreplace_msg_table[]
extern

Definition at line 68 of file vehicle_cmd.cpp.

◆ _veh_build_msg_table

const StringID _veh_build_msg_table[]
extern

Definition at line 47 of file vehicle_cmd.cpp.

◆ _veh_refit_msg_table

const StringID _veh_refit_msg_table[]
extern

Definition at line 75 of file vehicle_cmd.cpp.

◆ _veh_sell_all_msg_table

const StringID _veh_sell_all_msg_table[]
extern

Definition at line 61 of file vehicle_cmd.cpp.

◆ _veh_sell_msg_table

const StringID _veh_sell_msg_table[]
extern

Definition at line 54 of file vehicle_cmd.cpp.

◆ VEHICLE_PROFIT_MIN_AGE

const TimerGameEconomy::Date VEHICLE_PROFIT_MIN_AGE {CalendarTime::DAYS_IN_YEAR * 2}
static

Only vehicles older than this have a meaningful profit.

Definition at line 37 of file vehicle_func.h.

Referenced by GroupStatistics::CountVehicle(), DrawVehicleProfitButton(), EconomyAgeVehicle(), UpdateCompanyRatingAndValue(), and GroupStatistics::UpdateProfits().

◆ VEHICLE_PROFIT_THRESHOLD

const Money VEHICLE_PROFIT_THRESHOLD = 10000
static

Threshold for a vehicle to be considered making good profit.

Definition at line 38 of file vehicle_func.h.

Referenced by VehicleGroupWindow::DrawGroupInfo(), and DrawVehicleProfitButton().