OpenTTD Source: src/vehicle_cmd.h File Reference

OpenTTD Source 14.0-beta3

Functions | Variables
vehicle_cmd.h File Reference
`#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, CargoArray > | CmdBuildVehicle (DoCommandFlag flags, TileIndex tile, EngineID eid, bool use_free_vehicles, CargoID cargo, ClientID client_id)
| Build a vehicle. More...
CommandCost | CmdSellVehicle (DoCommandFlag flags, VehicleID v_id, bool sell_chain, bool backup_order, ClientID client_id)
| Sell a vehicle. More...
std::tuple< CommandCost, uint, uint16_t, CargoArray > | CmdRefitVehicle (DoCommandFlag flags, VehicleID veh_id, CargoID new_cid, byte new_subtype, bool auto_refit, bool only_this, uint8_t num_vehicles)
| Refits a vehicle to the specified cargo type. More...
CommandCost | CmdSendVehicleToDepot (DoCommandFlag flags, VehicleID veh_id, DepotCommand depot_cmd, const VehicleListIdentifier &vli)
| Send a vehicle to the depot. More...
CommandCost | CmdChangeServiceInt (DoCommandFlag flags, VehicleID veh_id, uint16_t serv_int, bool is_custom, bool is_percent)
| Change the service interval of a vehicle. More...
CommandCost | CmdRenameVehicle (DoCommandFlag flags, VehicleID veh_id, const std::string &text)
| Give a custom name to your vehicle. More...
std::tuple< CommandCost, VehicleID > | CmdCloneVehicle (DoCommandFlag flags, TileIndex tile, VehicleID veh_id, bool share_orders)
| Clone a vehicle. More...
CommandCost | CmdStartStopVehicle (DoCommandFlag flags, VehicleID veh_id, bool evaluate_startstop_cb)
| Start/Stop a vehicle. More...
CommandCost | CmdMassStartStopVehicle (DoCommandFlag flags, TileIndex tile, bool do_start, bool vehicle_list_window, const VehicleListIdentifier &vli)
| Starts or stops a lot of vehicles. More...
CommandCost | CmdDepotSellAllVehicles (DoCommandFlag flags, TileIndex tile, VehicleType vehicle_type)
| Sells all vehicles in a depot. More...
CommandCost | CmdDepotMassAutoReplace (DoCommandFlag flags, TileIndex tile, VehicleType vehicle_type)
| Autoreplace all vehicles in the depot. More...
| DEF_CMD_TRAIT (CMD_CLONE_VEHICLE, CmdCloneVehicle, CMD_NO_TEST, CMDT_VEHICLE_CONSTRUCTION) void CcBuildPrimaryVehicle(Commands cmd
void | CcStartStopVehicle (Commands cmd, const CommandCost &result, VehicleID veh_id, bool)
| This is the Callback method after attempting to start/stop a vehicle. More...
template<typename Tcont , typename Titer >
EndianBufferWriter< Tcont, Titer > & | operator<< (EndianBufferWriter< Tcont, Titer > &buffer, const CargoArray &cargo_array)
EndianBufferReader & | operator>> (EndianBufferReader &buffer, CargoArray &cargo_array)

## Variables
const CommandCost & | result
const CommandCost VehicleID | new_veh_id
const CommandCost VehicleID | uint
const CommandCost VehicleID | uint16_t
const CommandCost VehicleID | CargoArray

## Detailed Description

Command definitions for vehicles.

Definition in file vehicle_cmd.h.

## Function Documentation

## ◆ CcStartStopVehicle()

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

This is the Callback method after attempting to start/stop a vehicle.

Parameters

  result | the result of the start/stop command
  veh_id | Vehicle ID.

Definition at line 2893 of file vehicle_gui.cpp.

## ◆ 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

  flags | for command
  tile | tile of depot where the vehicle is built
  eid | vehicle type being built.
  use_free_vehicles | use free vehicles when building the vehicle.
  cargo | refit cargo type.
  client_id | User

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, AIR_CTOL, CMD_ERROR, CountArticulatedParts(), EXPENSES_NEW_VEHICLES, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Engine::GetCost(), Engine::GetDefaultCargoType(), GetDepotVehicleType(), INVALID_VEHICLE, IsDepotTile(), IsEngineBuildable(), IsTileOwner(), IsValidCargoID(), NUM_CARGO, RAILVEH_MULTIHEAD, AircraftVehicleInfo::subtype, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

## ◆ CmdChangeServiceInt()

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

Change the service interval of a vehicle.

Parameters

  flags | type of operation
  veh_id | vehicle ID that is being service-interval-changed
  serv_int | new service interval
  is_custom | service interval is custom flag
  is_percent | service interval is percentage flag

Returns
  the cost of this operation or an error

Definition at line 1109 of file vehicle_cmd.cpp.

## ◆ 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

  flags | type of operation
  tile | tile of the depot where the cloned vehicle is build
  veh_id | the original vehicle's index
  share_orders | shared orders, else copied orders

Returns
  the cost of this operation + the new vehicle ID or an error

Definition at line 828 of file vehicle_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::CanAllocateItem(), CheckOwnership(), CMD_ERROR, Train::crash_anim_pos, DC_EXEC, EXPENSES_NEW_VEHICLES, CommandCost::Failed(), SpecializedVehicle< Train, Type >::From(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), INVALID_VEHICLE, Vehicle::IsFrontEngine(), Vehicle::IsPrimaryVehicle(), Vehicle::Next(), Vehicle::owner, BaseVehicle::type, and VEH_TRAIN.

## ◆ CmdDepotMassAutoReplace()

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

Autoreplace all vehicles in the depot.

Parameters

  flags | type of operation
  tile | Tile of the depot where the vehicles are
  vehicle_type | Type 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, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::IsChainInDepot(), IsCompanyBuildableVehicleType(), IsDepotTile(), IsTileOwner(), and CommandCost::Succeeded().

## ◆ CmdDepotSellAllVehicles()

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

Sells all vehicles in a depot.

Parameters

  flags | type of operation
  tile | Tile of the depot where the depot is
  vehicle_type | Vehicle 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

  flags | type of operation
  tile | Tile of the depot where the vehicles are started/stopped (only used for depots)
  do_start | set = start vehicles, unset = stop vehicles
  vehicle_list_window | if set, then it's a vehicle list window, not a depot and Tile is ignored in this case
  vli | VehicleListIdentifier

Returns
  the cost of this operation or an error

Definition at line 656 of file vehicle_cmd.cpp.

References _current_company, BuildDepotVehicleList(), CMD_ERROR, do_start, GenerateVehicleSortList(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::IsChainInDepot(), IsCompanyBuildableVehicleType(), IsDepotTile(), IsTileOwner(), Vehicle::vehstatus, VS_STOPPED, and VehicleListIdentifier::vtype.

## ◆ CmdRefitVehicle()

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

Refits a vehicle to the specified cargo type.

Parameters

  flags | type of operation
  veh_id | vehicle ID to refit
  new_cid | New cargo type to refit to.
  new_subtype | New cargo subtype to refit to. 0xFF means to try keeping the same subtype according to GetBestFittingSubType().
  auto_refit | Automatic refitting.
  only_this | Refit only this vehicle. Used only for cloning vehicles.
  num_vehicles | Number 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 488 of file vehicle_cmd.cpp.

References CheckOwnership(), CMD_ERROR, Vehicle::current_order, DC_QUERY_COST, CommandCost::Failed(), Vehicle::First(), SpecializedVehicle< Train, Type >::From(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), IsCompanyBuildableVehicleType(), GroundVehicle< T, Type >::IsFreeWagon(), Order::IsType(), Vehicle::owner, BaseVehicle::type, VEH_AIRCRAFT, VEH_SHIP, and VEH_TRAIN.

## ◆ CmdRenameVehicle()

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

Give a custom name to your vehicle.

Parameters

  flags | type of operation
  veh_id | vehicle ID to name
  text | the new name or an empty string when resetting to the default

Returns
  the cost of this operation or an error

Definition at line 1071 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, return_cmd_error, BaseVehicle::type, and Utf8StringLength().

## ◆ CmdSellVehicle()

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

Sell a vehicle.

Parameters

  flags | for command.
  v_id | vehicle ID being sold.
  sell_chain | sell the vehicle and all vehicles following it in the chain.
  backup_order | make a backup of the vehicle's order (if an engine).
  client_id | User.

Returns
  the cost of this operation or an error.

Definition at line 221 of file vehicle_cmd.cpp.

References OrderBackup::Backup(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_pool >::CanAllocateItem(), CheckOwnership(), CMD_ERROR, CmdSellRailWagon(), DC_EXEC, EXPENSES_NEW_VEHICLES, CommandCost::Failed(), Vehicle::First(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), OrderList::GetNumOrders(), Vehicle::IsPrimaryVehicle(), OrderList::IsShared(), Vehicle::IsStoppedInDepot(), Vehicle::orders, Vehicle::owner, return_cmd_error, BaseVehicle::type, Vehicle::value, VEH_TRAIN, Vehicle::vehstatus, and VS_CRASHED.

## ◆ CmdSendVehicleToDepot()

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

Send a vehicle to the depot.

Parameters

  flags | for command type
  veh_id | vehicle ID to send to the depot
  depot_cmd | DEPOT_ flags (see vehicle_type.h)
  vli | VehicleListIdentifier.

Returns
  the cost of this operation or an error

Definition at line 1049 of file vehicle_cmd.cpp.

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

## ◆ CmdStartStopVehicle()

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

Start/Stop a vehicle.

Parameters

  flags | type of operation
  veh_id | vehicle to start/stop, don't forget to change CcStartStopVehicle if you modify this!
  evaluate_startstop_cb | Shall the start/stop newgrf callback be evaluated (only valid with DC_AUTOREPLACE for network safety)

Returns
  the cost of this operation or an error

Definition at line 570 of file vehicle_cmd.cpp.

References GroundVehicleCache::cached_power, CheckOwnership(), CMD_ERROR, DC_AUTOREPLACE, CommandCost::Failed(), Aircraft::flags, SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedVehicle< Train, Type >::From(), GroundVehicle< T, Type >::gcache, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), HasBit(), Vehicle::IsPrimaryVehicle(), Vehicle::owner, return_cmd_error, STARTTAKEOFF, Aircraft::state, TERM7, BaseVehicle::type, VAF_HELI_DIRECT_DESCENT, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, Vehicle::vehstatus, VS_CRASHED, and VS_STOPPED.