# vehicle_cmd.cpp File Reference

Commands for vehicles. More...

`#include "stdafx.h"`
`#include "roadveh.h"`
`#include "gfx_func.h"`
`#include "news_func.h"`
`#include "command_func.h"`
`#include "company_func.h"`
`#include "vehicle_gui.h"`
`#include "train.h"`
`#include "newgrf_engine.h"`
`#include "newgrf_text.h"`
`#include "functions.h"`
`#include "window_func.h"`
`#include "vehicle_func.h"`
`#include "string_func.h"`
`#include "depot_map.h"`
`#include "vehiclelist.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Functions
CommandCost | CmdStartStopVehicle (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Start/Stop a vehicle.
CommandCost | CmdMassStartStopVehicle (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Starts or stops a lot of vehicles.
CommandCost | CmdDepotSellAllVehicles (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Sells all vehicles in a depot.
CommandCost | CmdDepotMassAutoReplace (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Autoreplace all vehicles in the depot Note: this command can make incorrect cost estimations Luckily the final price can only drop, not increase.
static bool | IsUniqueVehicleName (const char *name)
| Test if a name is unique among vehicle names.
static void | CloneVehicleName (const Vehicle *src, Vehicle *dst)
| Clone the custom name of a vehicle, adding or incrementing a number.
CommandCost | CmdCloneVehicle (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Clone a vehicle.
CommandCost | SendAllVehiclesToDepot (VehicleType type, DoCommandFlag flags, bool service, Owner owner, uint16 vlw_flag, uint32 id)
| Send all vehicles of type to depots.
CommandCost | CmdRenameVehicle (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Give a custom name to your vehicle.
CommandCost | CmdChangeServiceInt (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Change the service interval of a vehicle.
## Variables
const uint32 | _veh_build_proc_table []
const uint32 | _veh_sell_proc_table []
const uint32 | _veh_refit_proc_table []
const uint32 | _send_to_depot_proc_table []

## Detailed Description

Commands for vehicles.

Definition in file vehicle_cmd.cpp.

## Function Documentation

static void CloneVehicleName | ( | const Vehicle * | src,
|  | Vehicle * | dst |
| ) |  |  | `[static]`

Clone the custom name of a vehicle, adding or incrementing a number.

Parameters:

  | src | Source vehicle, with a custom name.
  | dst | Destination vehicle.

Definition at line 284 of file vehicle_cmd.cpp.

References buf, IsUniqueVehicleName(), lastof, seprintf(), strecat(), and strecpy().

Referenced by CmdCloneVehicle().

CommandCost CmdChangeServiceInt | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Change the service interval of a vehicle.

Parameters:

  | tile | unused
  | flags | type of operation
  | p1 | vehicle ID that is being service-interval-changed
  | p2 | new service interval

Definition at line 564 of file vehicle_cmd.cpp.

References CMD_ERROR, DC_EXEC, GetServiceIntervalClamped(), InvalidateWindow(), and IsValidVehicleID().

CommandCost CmdCloneVehicle | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Clone a vehicle.

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

Parameters:

  | tile | tile of the depot where the cloned vehicle is build
  | flags | type of operation
  | p1 | the original vehicle's index
  | p2 | 1 = shared orders, else copied orders

Definition at line 332 of file vehicle_cmd.cpp.

References CommandCost::AddCost(), CloneVehicleName(), CMD_ADD_VEHICLE_GROUP, CMD_CLONE_ORDER, CMD_ERROR, CMD_MOVE_RAIL_VEHICLE, CmdFailed(), CmdSucceeded(), DC_EXEC, DoCommand(), EngineHasArticPart(), GetNextArticPart(), GetNextVehicle(), GetRefitCost(), HasBit(), IsFrontEngine(), IsRearDualheaded(), IsValidVehicleID(), return_cmd_error, and SetBit().

CommandCost CmdDepotMassAutoReplace | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Autoreplace all vehicles in the depot Note: this command can make incorrect cost estimations Luckily the final price can only drop, not increase.

This is due to the fact that estimation can't predict wagon removal so it presumes worst case which is no income from selling wagons.

Parameters:

  | tile | Tile of the depot where the vehicles are
  | flags | type of operation
  | p1 | Type of vehicle
  | p2 | If bit 0 is set, then either replace all or nothing (instead of replacing until money runs out)

Definition at line 219 of file vehicle_cmd.cpp.

References CommandCost::AddCost(), BuildDepotVehicleList(), CMD_AUTOREPLACE_VEHICLE, CMD_ERROR, CmdSucceeded(), DC_EXEC, DoCommand(), GB(), CommandCost::GetErrorMessage(), HasBit(), IsDepotTile(), IsTileOwner(), and SmallVector< T, S >::Length().

CommandCost CmdDepotSellAllVehicles | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Sells all vehicles in a depot.

Parameters:

  | tile | Tile of the depot where the depot is
  | flags | type of operation
  | p1 | Vehicle type
  | p2 | unused

Definition at line 182 of file vehicle_cmd.cpp.

References CommandCost::AddCost(), BuildDepotVehicleList(), CMD_ERROR, CMD_SELL_AIRCRAFT, CMD_SELL_RAIL_WAGON, CMD_SELL_ROAD_VEH, CMD_SELL_SHIP, CmdSucceeded(), DoCommand(), GB(), CommandCost::GetCost(), and SmallVector< T, S >::Length().

CommandCost CmdMassStartStopVehicle | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Starts or stops a lot of vehicles.

Parameters:

  | tile | Tile of the depot where the vehicles are started/stopped (only used for depots)
  | flags | type of operation
  | p1 | Station/Order/Depot ID (only used for vehicle list windows)
  | p2 | bitmask bit 0-4 Vehicle type bit 5 false = start vehicles, true = stop vehicles bit 6 if set, then it's a vehicle list window, not a depot and Tile is ignored in this case bit 8-11 Vehicle List Window type (ignored unless bit 1 is set)

Definition at line 132 of file vehicle_cmd.cpp.

References BuildDepotVehicleList(), CMD_ERROR, CMD_START_STOP_VEHICLE, CmdSucceeded(), DC_EXEC, DoCommand(), GB(), GenerateVehicleSortList(), HasBit(), and SmallVector< T, S >::Length().

CommandCost CmdRenameVehicle | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Give a custom name to your vehicle.

Parameters:

  | tile | unused
  | flags | type of operation
  | p1 | vehicle ID to name
  | p2 | unused

Definition at line 533 of file vehicle_cmd.cpp.

References CMD_ERROR, DC_AUTOREPLACE, DC_EXEC, InvalidateWindowClassesData(), IsUniqueVehicleName(), IsValidVehicleID(), MarkWholeScreenDirty(), MAX_LENGTH_VEHICLE_NAME_BYTES, return_cmd_error, and StrEmpty().

CommandCost CmdStartStopVehicle | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Start/Stop a vehicle.

Parameters:

  | tile | unused
  | flags | type of operation
  | p1 | vehicle to start/stop
  | p2 | bit 0: Shall the start/stop newgrf callback be evaluated (only valid with DC_AUTOREPLACE for network safety)

Returns:
  result of operation. Nothing if everything went well

Definition at line 59 of file vehicle_cmd.cpp.

References CALLBACK_FAILED, CBID_VEHICLE_START_STOP_CHECK, CMD_ERROR, DC_AUTOREPLACE, DC_EXEC, DeleteVehicleNews(), error, GB(), GetEngineGRFID(), GetGRFStringID(), GetVehicleCallback(), HasBit(), InvalidateWindow(), InvalidateWindowClasses(), InvalidateWindowWidget(), IsValidVehicleID(), return_cmd_error, and SetBit().

static bool IsUniqueVehicleName | ( | const char * | name | ) | `[static]`

Test if a name is unique among vehicle names.

Parameters:

  | name | Name to test.

Returns:
  True ifffffff the name is unique.

Definition at line 269 of file vehicle_cmd.cpp.

Referenced by CloneVehicleName(), and CmdRenameVehicle().

CommandCost SendAllVehiclesToDepot | ( | VehicleType | type,
|  | DoCommandFlag | flags,
|  | bool | service,
|  | Owner | owner,
|  | uint16 | vlw_flag,
|  | uint32 | id |
| ) |  |  |

Send all vehicles of type to depots.

Parameters:

  | type | type of vehicle
  | flags | the flags used for DoCommand()
  | service | should the vehicles only get service in the depots
  | owner | owner of the vehicles to send
  | vlw_flag | tells what kind of list requested the goto depot

Returns:
  0 for success and CMD_ERROR if no vehicle is able to go to depot

Definition at line 504 of file vehicle_cmd.cpp.

References CMD_ERROR, CmdSucceeded(), DC_EXEC, DEPOT_DONT_CANCEL, DoCommand(), GenerateVehicleSortList(), and SmallVector< T, S >::Length().

Referenced by CmdSendAircraftToHangar(), CmdSendRoadVehToDepot(), CmdSendShipToDepot(), and CmdSendTrainToDepot().

## Variable Documentation

const uint32 _send_to_depot_proc_table[]

Initial value:

     {
      CMD_SEND_TRAIN_TO_DEPOT,
      CMD_SEND_ROADVEH_TO_DEPOT,
      CMD_SEND_SHIP_TO_DEPOT,
      CMD_SEND_AIRCRAFT_TO_HANGAR,
    }

Definition at line 45 of file vehicle_cmd.cpp.

const uint32 _veh_build_proc_table[]

Initial value:

     {
      CMD_BUILD_RAIL_VEHICLE,
      CMD_BUILD_ROAD_VEH,
      CMD_BUILD_SHIP,
      CMD_BUILD_AIRCRAFT,
    }

Definition at line 25 of file vehicle_cmd.cpp.

const uint32 _veh_refit_proc_table[]

Initial value:

     {
      CMD_REFIT_RAIL_VEHICLE,
      CMD_REFIT_ROAD_VEH,
      CMD_REFIT_SHIP,
      CMD_REFIT_AIRCRAFT,
    }

Definition at line 38 of file vehicle_cmd.cpp.

const uint32 _veh_sell_proc_table[]

Initial value:

     {
      CMD_SELL_RAIL_WAGON,
      CMD_SELL_ROAD_VEH,
      CMD_SELL_SHIP,
      CMD_SELL_AIRCRAFT,
    }

Definition at line 31 of file vehicle_cmd.cpp.