OpenTTD Source 15.0-beta1
vehicle_cmd.h File Reference

Command definitions for vehicles. More...

#include "command_type.h"
#include "engine_type.h"
#include "vehicle_type.h"
#include "vehiclelist.h"
#include "vehiclelist_cmd.h"
#include "cargo_type.h"

Go to the source code of this file.

Functions

std::tuple< CommandCost, VehicleID, uint, uint16_t, CargoArrayCmdBuildVehicle (DoCommandFlag flags, TileIndex tile, EngineID eid, bool use_free_vehicles, CargoID cargo, ClientID client_id)
 Build a vehicle.
 
CommandCost CmdSellVehicle (DoCommandFlag flags, VehicleID v_id, bool sell_chain, bool backup_order, ClientID client_id)
 Sell a vehicle.
 
std::tuple< CommandCost, uint, uint16_t, CargoArrayCmdRefitVehicle (DoCommandFlag flags, VehicleID veh_id, CargoID new_cid, uint8_t new_subtype, bool auto_refit, bool only_this, uint8_t num_vehicles)
 Refits a vehicle to the specified cargo type.
 
CommandCost CmdSendVehicleToDepot (DoCommandFlag flags, VehicleID veh_id, DepotCommand depot_cmd, const VehicleListIdentifier &vli)
 Send a vehicle to the depot.
 
CommandCost CmdChangeServiceInt (DoCommandFlag flags, VehicleID veh_id, uint16_t serv_int, bool is_custom, bool is_percent)
 Change the service interval of a vehicle.
 
CommandCost CmdRenameVehicle (DoCommandFlag flags, VehicleID veh_id, const std::string &text)
 Give a custom name to your vehicle.
 
std::tuple< CommandCost, VehicleIDCmdCloneVehicle (DoCommandFlag flags, TileIndex tile, VehicleID veh_id, bool share_orders)
 Clone a vehicle.
 
CommandCost CmdStartStopVehicle (DoCommandFlag flags, VehicleID veh_id, bool evaluate_startstop_cb)
 Start/Stop a vehicle.
 
CommandCost CmdMassStartStopVehicle (DoCommandFlag flags, TileIndex tile, bool do_start, bool vehicle_list_window, const VehicleListIdentifier &vli)
 Starts or stops a lot of vehicles.
 
CommandCost CmdDepotSellAllVehicles (DoCommandFlag flags, TileIndex tile, VehicleType vehicle_type)
 Sells all vehicles in a depot.
 
CommandCost CmdDepotMassAutoReplace (DoCommandFlag flags, TileIndex tile, VehicleType vehicle_type)
 Autoreplace all vehicles in the depot.
 
void CcBuildPrimaryVehicle (Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray)
 This is the Callback method after the construction attempt of a primary vehicle.
 
void CcStartStopVehicle (Commands cmd, const CommandCost &result, VehicleID veh_id, bool)
 This is the Callback method after attempting to start/stop a vehicle.
 
template<typename Tcont , typename Titer >
EndianBufferWriter< Tcont, Titer > & operator<< (EndianBufferWriter< Tcont, Titer > &buffer, const CargoArray &cargo_array)
 
EndianBufferReaderoperator>> (EndianBufferReader &buffer, CargoArray &cargo_array)
 

Detailed Description

Command definitions for vehicles.

Definition in file vehicle_cmd.h.

Function Documentation

◆ CcBuildPrimaryVehicle()

void CcBuildPrimaryVehicle ( Commands  cmd,
const CommandCost result,
VehicleID  new_veh_id,
uint  ,
uint16_t  ,
CargoArray   
)

This is the Callback method after the construction attempt of a primary vehicle.

Parameters
resultindicates completion (or not) of the operation
new_veh_idID of the new vehicle.

Definition at line 3567 of file vehicle_gui.cpp.

References CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), and ShowVehicleViewWindow().

◆ CcStartStopVehicle()

void CcStartStopVehicle ( Commands  cmd,
const CommandCost result,
VehicleID  veh_id,
bool   
)

◆ CmdBuildVehicle()

std::tuple< CommandCost, VehicleID, uint, uint16_t, CargoArray > CmdBuildVehicle ( DoCommandFlag  flags,
TileIndex  tile,
EngineID  eid,
bool  use_free_vehicles,
CargoID  cargo,
ClientID  client_id 
)

Build a vehicle.

Parameters
flagsfor command
tiletile of depot where the vehicle is built
eidvehicle type being built.
use_free_vehiclesuse free vehicles when building the vehicle.
cargorefit cargo type.
client_idUser
Returns
the cost of this operation + the new vehicle ID + the refitted capacity + the refitted mail capacity (aircraft) or an error

Definition at line 87 of file vehicle_cmd.cpp.

References _current_company, CommandCost::AddCost(), AIR_CTOL, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::CanAllocateItem(), CMD_ERROR, CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRoadVehicle(), CmdBuildShip(), CmdRefitVehicle(), CountArticulatedParts(), GroupStatistics::CountEngine(), GroupStatistics::CountVehicle(), DC_AUTOREPLACE, DC_EXEC, DC_QUERY_COST, Vehicle::engine_type, EXPENSES_NEW_VEHICLES, SpecializedVehicle< T, Type >::From(), 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<&_company_pool >::Get(), GetCapacityOfArticulatedParts(), CommandCost::GetCost(), Engine::GetCost(), Engine::GetDefaultCargoType(), GetDepotVehicleType(), Engine::GetDisplayDefaultCapacity(), GetFreeUnitNumber(), GetWindowClassForVehicleType(), Vehicle::group_id, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_CLIENT_ID, INVALID_VEHICLE, InvalidateAutoreplaceWindow(), InvalidateWindowClassesData(), InvalidateWindowData(), IsDepotTile(), IsEngineBuildable(), IsLocalCompany(), Vehicle::IsPrimaryVehicle(), IsTileOwner(), IsValidCargoID(), NormalizeTrainVehInDepot(), NUM_CARGO, Vehicle::owner, RAILVEH_MULTIHEAD, RAILVEH_WAGON, OrderBackup::Restore(), RestoreRandomSeeds(), SaveRandomSeeds(), SetWindowDirty(), AircraftVehicleInfo::subtype, CommandCost::Succeeded(), Vehicle::tile, Engine::type, BaseVehicle::type, Vehicle::unitnumber, GroupStatistics::UpdateAutoreplace(), Vehicle::value, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, WC_COMPANY, and WC_VEHICLE_DEPOT.

◆ CmdChangeServiceInt()

CommandCost CmdChangeServiceInt ( DoCommandFlag  flags,
VehicleID  veh_id,
uint16_t  serv_int,
bool  is_custom,
bool  is_percent 
)

◆ CmdCloneVehicle()

std::tuple< CommandCost, VehicleID > CmdCloneVehicle ( DoCommandFlag  flags,
TileIndex  tile,
VehicleID  veh_id,
bool  share_orders 
)

Clone a vehicle.

If it is a train, it will clone all the cars too

Parameters
flagstype of operation
tiletile of the depot where the cloned vehicle is build
veh_idthe original vehicle's index
share_ordersshared orders, else copied orders
Returns
the cost of this operation + the new vehicle ID or an error

Definition at line 826 of file vehicle_cmd.cpp.

References CommandCost::AddCost(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::CanAllocateItem(), Engine::CanCarryCargo(), Vehicle::cargo_subtype, Vehicle::cargo_type, CheckCompanyHasMoney(), CheckOwnership(), CloneVehicleName(), CMD_ERROR, DC_AUTOREPLACE, DC_EXEC, Vehicle::engine_type, EXPENSES_NEW_VEHICLES, CommandCost::Failed(), SpecializedVehicle< T, Type >::From(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), GetBestFittingSubType(), Engine::GetDefaultCargoType(), Vehicle::GetEngine(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Vehicle::GetNextArticulatedPart(), Vehicle::GetNextVehicle(), GetRefitCost(), Vehicle::group_id, Vehicle::HasArticulatedPart(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_CLIENT_ID, INVALID_VEHICLE, Vehicle::IsFrontEngine(), Vehicle::IsGroundVehicle(), Vehicle::IsPrimaryVehicle(), IsValidCargoID(), BaseConsist::name, Vehicle::Next(), Vehicle::owner, BaseConsist::service_interval, SetBit(), CommandCost::Succeeded(), BaseVehicle::type, VEH_TRAIN, and VRF_REVERSE_DIRECTION.

◆ CmdDepotMassAutoReplace()

CommandCost CmdDepotMassAutoReplace ( DoCommandFlag  flags,
TileIndex  tile,
VehicleType  vehicle_type 
)

Autoreplace all vehicles in the depot.

Parameters
flagstype of operation
tileTile of the depot where the vehicles are
vehicle_typeType of vehicle
Returns
the cost of this operation or an error

Definition at line 726 of file vehicle_cmd.cpp.

References _current_company, CommandCost::AddCost(), BuildDepotVehicleList(), CMD_ERROR, EXPENSES_NEW_VEHICLES, IsCompanyBuildableVehicleType(), IsDepotTile(), IsTileOwner(), and CommandCost::Succeeded().

◆ CmdDepotSellAllVehicles()

CommandCost CmdDepotSellAllVehicles ( DoCommandFlag  flags,
TileIndex  tile,
VehicleType  vehicle_type 
)

Sells all vehicles in a depot.

Parameters
flagstype of operation
tileTile of the depot where the depot is
vehicle_typeVehicle type
Returns
the cost of this operation or an error

Definition at line 692 of file vehicle_cmd.cpp.

References _current_company, CommandCost::AddCost(), BuildDepotVehicleList(), CMD_ERROR, EXPENSES_NEW_VEHICLES, INVALID_CLIENT_ID, IsCompanyBuildableVehicleType(), IsDepotTile(), IsTileOwner(), and CommandCost::Succeeded().

◆ CmdMassStartStopVehicle()

CommandCost CmdMassStartStopVehicle ( DoCommandFlag  flags,
TileIndex  tile,
bool  do_start,
bool  vehicle_list_window,
const VehicleListIdentifier vli 
)

Starts or stops a lot of vehicles.

Parameters
flagstype of operation
tileTile of the depot where the vehicles are started/stopped (only used for depots)
do_startset = start vehicles, unset = stop vehicles
vehicle_list_windowif set, then it's a vehicle list window, not a depot and Tile is ignored in this case
vliVehicleListIdentifier
Returns
the cost of this operation or an error

Definition at line 658 of file vehicle_cmd.cpp.

References _current_company, BuildDepotVehicleList(), CMD_ERROR, do_start, GenerateVehicleSortList(), IsCompanyBuildableVehicleType(), IsDepotTile(), IsTileOwner(), VS_STOPPED, and VehicleListIdentifier::vtype.

◆ CmdRefitVehicle()

std::tuple< CommandCost, uint, uint16_t, CargoArray > CmdRefitVehicle ( DoCommandFlag  flags,
VehicleID  veh_id,
CargoID  new_cid,
uint8_t  new_subtype,
bool  auto_refit,
bool  only_this,
uint8_t  num_vehicles 
)

Refits a vehicle to the specified cargo type.

Parameters
flagstype of operation
veh_idvehicle ID to refit
new_cidNew cargo type to refit to.
new_subtypeNew cargo subtype to refit to. 0xFF means to try keeping the same subtype according to GetBestFittingSubType().
auto_refitAutomatic refitting.
only_thisRefit only this vehicle. Used only for cloning vehicles.
num_vehiclesNumber of vehicles to refit (not counting articulated parts). Zero means all vehicles. Only used if "refit only this vehicle" is false.
Returns
the cost of this operation or an error

Definition at line 490 of file vehicle_cmd.cpp.

References _settings_game, CCF_AUTOREFIT, CCF_REFIT, CheckOwnership(), CMD_ERROR, Vehicle::current_order, DC_EXEC, DC_QUERY_COST, CommandCost::Failed(), Vehicle::First(), SpecializedVehicle< Ship, VEH_SHIP >::From(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedVehicle< T, Type >::From(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), GetWindowClassForVehicleType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::InvalidateNewGRFCacheOfChain(), InvalidateWindowClassesData(), InvalidateWindowData(), IsCompanyBuildableVehicleType(), Vehicle::IsStoppedInDepot(), Order::IsType(), Vehicle::MarkDirty(), NUM_CARGO, Vehicle::owner, RefitVehicle(), VehicleSettings::roadveh_acceleration_model, RoadVehUpdateCache(), SetWindowDirty(), Vehicle::tile, BaseVehicle::type, UpdateAircraftCache(), Ship::UpdateCache(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, GameSettings::vehicle, Vehicle::vehstatus, VS_CRASHED, WC_VEHICLE_DEPOT, and WC_VEHICLE_DETAILS.

Referenced by CmdBuildVehicle().

◆ CmdRenameVehicle()

CommandCost CmdRenameVehicle ( DoCommandFlag  flags,
VehicleID  veh_id,
const std::string &  text 
)

Give a custom name to your vehicle.

Parameters
flagstype of operation
veh_idvehicle ID to name
textthe new name or an empty string when resetting to the default
Returns
the cost of this operation or an error

Definition at line 1069 of file vehicle_cmd.cpp.

References CheckOwnership(), CMD_ERROR, DC_AUTOREPLACE, DC_EXEC, CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), GetWindowClassForVehicleType(), InvalidateWindowClassesData(), Vehicle::IsPrimaryVehicle(), IsUniqueVehicleName(), MarkWholeScreenDirty(), MAX_LENGTH_VEHICLE_NAME_CHARS, BaseConsist::name, Vehicle::owner, BaseVehicle::type, and Utf8StringLength().

◆ CmdSellVehicle()

CommandCost CmdSellVehicle ( DoCommandFlag  flags,
VehicleID  v_id,
bool  sell_chain,
bool  backup_order,
ClientID  client_id 
)

◆ CmdSendVehicleToDepot()

CommandCost CmdSendVehicleToDepot ( DoCommandFlag  flags,
VehicleID  veh_id,
DepotCommand  depot_cmd,
const VehicleListIdentifier vli 
)

Send a vehicle to the depot.

Parameters
flagsfor command type
veh_idvehicle ID to send to the depot
depot_cmdDEPOT_ flags (see vehicle_type.h)
vliVehicleListIdentifier.
Returns
the cost of this operation or an error

Definition at line 1047 of file vehicle_cmd.cpp.

References CMD_ERROR, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), HasFlag(), Vehicle::IsPrimaryVehicle(), MassSend, SendAllVehiclesToDepot(), Vehicle::SendToDepot(), and Service.

◆ CmdStartStopVehicle()

CommandCost CmdStartStopVehicle ( DoCommandFlag  flags,
VehicleID  veh_id,
bool  evaluate_startstop_cb 
)

◆ operator<<()

template<typename Tcont , typename Titer >
EndianBufferWriter< Tcont, Titer > & operator<< ( EndianBufferWriter< Tcont, Titer > &  buffer,
const CargoArray cargo_array 
)
inline

Definition at line 45 of file vehicle_cmd.h.

◆ operator>>()

EndianBufferReader & operator>> ( EndianBufferReader buffer,
CargoArray cargo_array 
)
inline

Definition at line 56 of file vehicle_cmd.h.