OpenTTD Source 20260208-master-g43af8e94d0
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 (DoCommandFlags flags, TileIndex tile, EngineID eid, bool use_free_vehicles, CargoType cargo, ClientID client_id)
 Build a vehicle.
CommandCost CmdSellVehicle (DoCommandFlags flags, VehicleID v_id, bool sell_chain, bool backup_order, ClientID client_id)
 Sell a vehicle.
std::tuple< CommandCost, uint, uint16_t, CargoArrayCmdRefitVehicle (DoCommandFlags flags, VehicleID veh_id, CargoType new_cargo_type, uint8_t new_subtype, bool auto_refit, bool only_this, uint8_t num_vehicles)
 Refits a vehicle to the specified cargo type.
CommandCost CmdSendVehicleToDepot (DoCommandFlags flags, VehicleID veh_id, DepotCommandFlags depot_cmd, const VehicleListIdentifier &vli)
 Send a vehicle to the depot.
CommandCost CmdChangeServiceInt (DoCommandFlags flags, VehicleID veh_id, uint16_t serv_int, bool is_custom, bool is_percent)
 Change the service interval of a vehicle.
CommandCost CmdRenameVehicle (DoCommandFlags flags, VehicleID veh_id, const std::string &text)
 Give a custom name to your vehicle.
std::tuple< CommandCost, VehicleIDCmdCloneVehicle (DoCommandFlags flags, TileIndex tile, VehicleID veh_id, bool share_orders)
 Clone a vehicle.
CommandCost CmdStartStopVehicle (DoCommandFlags flags, VehicleID veh_id, bool evaluate_startstop_cb)
 Start/Stop a vehicle.
CommandCost CmdMassStartStopVehicle (DoCommandFlags flags, TileIndex tile, bool do_start, bool vehicle_list_window, const VehicleListIdentifier &vli)
 Starts or stops a lot of vehicles.
CommandCost CmdDepotSellAllVehicles (DoCommandFlags flags, TileIndex tile, VehicleType vehicle_type)
 Sells all vehicles in a depot.
CommandCost CmdDepotMassAutoReplace (DoCommandFlags flags, TileIndex tile, VehicleType vehicle_type)
 Autoreplace all vehicles in the depot.
void CcBuildPrimaryVehicle (Commands, 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, 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 ,
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 3504 of file vehicle_gui.cpp.

References CommandCost::Failed(), and ShowVehicleViewWindow().

◆ CcStartStopVehicle()

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

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

Parameters
resultthe result of the start/stop command
veh_idVehicle ID.

Definition at line 2922 of file vehicle_gui.cpp.

References _local_company, Ticks::DAY_TICKS, CommandCost::Failed(), GetEncodedString(), Vehicle::IsPrimaryVehicle(), Vehicle::owner, Point, RemapCoords(), Stopped, TE_RISING, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Vehicle::vehstatus, Coord2D< T >::x, Vehicle::x_pos, Coord2D< T >::y, Vehicle::y_pos, and Vehicle::z_pos.

Referenced by StartStopVehicle().

◆ CmdBuildVehicle()

std::tuple< CommandCost, VehicleID, uint, uint16_t, CargoArray > CmdBuildVehicle ( DoCommandFlags flags,
TileIndex tile,
EngineID eid,
bool use_free_vehicles,
CargoType 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 100 of file vehicle_cmd.cpp.

References _current_company, CommandCost::AddCost(), AIR_CTOL, AutoReplace, CMD_ERROR, CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRoadVehicle(), CmdBuildShip(), CmdRefitVehicle(), CountArticulatedParts(), GroupStatistics::CountEngine(), GroupStatistics::CountVehicle(), Vehicle::engine_type, Execute, EXPENSES_NEW_VEHICLES, SpecializedVehicle< Train, Type >::From(), GetCapacityOfArticulatedParts(), CommandCost::GetCost(), Engine::GetCost(), Engine::GetDefaultCargoType(), GetDepotVehicleType(), Engine::GetDisplayDefaultCapacity(), GetFreeUnitNumber(), GetWindowClassForVehicleType(), Vehicle::group_id, INVALID_CLIENT_ID, InvalidateAutoreplaceWindow(), InvalidateWindowClassesData(), InvalidateWindowData(), IsDepotTile(), IsEngineBuildable(), IsLocalCompany(), Vehicle::IsPrimaryVehicle(), IsTileOwner(), IsValidCargoType(), NormalizeTrainVehInDepot(), NUM_CARGO, Vehicle::owner, QueryCost, RAILVEH_MULTIHEAD, RAILVEH_WAGON, OrderBackup::Restore(), RestoreRandomSeeds(), SaveRandomSeeds(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SetWindowDirty(), CommandCost::Succeeded(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Vehicle::tile, BaseVehicle::type, Engine::type, Vehicle::unitnumber, GroupStatistics::UpdateAutoreplace(), Vehicle::value, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, WC_COMPANY, and WC_VEHICLE_DEPOT.

◆ CmdChangeServiceInt()

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

Change the service interval of a vehicle.

Parameters
flagstype of operation
veh_idvehicle ID that is being service-interval-changed
serv_intnew service interval
is_customservice interval is custom flag
is_percentservice interval is percentage flag
Returns
the cost of this operation or an error

Definition at line 1116 of file vehicle_cmd.cpp.

References CheckOwnership(), CMD_ERROR, CompanyServiceInterval(), Execute, CommandCost::Failed(), GetServiceIntervalClamped(), Vehicle::IsPrimaryVehicle(), Vehicle::owner, VehicleDefaultSettings::servint_ispercent, CompanyProperties::settings, SetWindowDirty(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), BaseVehicle::type, CompanySettings::vehicle, and WC_VEHICLE_DETAILS.

◆ CmdCloneVehicle()

◆ CmdDepotMassAutoReplace()

CommandCost CmdDepotMassAutoReplace ( DoCommandFlags 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 734 of file vehicle_cmd.cpp.

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

◆ CmdDepotSellAllVehicles()

CommandCost CmdDepotSellAllVehicles ( DoCommandFlags 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 700 of file vehicle_cmd.cpp.

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

◆ CmdMassStartStopVehicle()

CommandCost CmdMassStartStopVehicle ( DoCommandFlags 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 666 of file vehicle_cmd.cpp.

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

◆ CmdRefitVehicle()

std::tuple< CommandCost, uint, uint16_t, CargoArray > CmdRefitVehicle ( DoCommandFlags flags,
VehicleID veh_id,
CargoType new_cargo_type,
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_cargo_typeNew 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 493 of file vehicle_cmd.cpp.

References _settings_game, GroundVehicle< T, Type >::CargoChanged(), CCF_AUTOREFIT, CCF_REFIT, CheckOwnership(), CMD_ERROR, Train::ConsistChanged(), Crashed, Vehicle::current_order, Execute, CommandCost::Failed(), Vehicle::First(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedVehicle< RoadVehicle, Type >::From(), SpecializedVehicle< Ship, VEH_SHIP >::From(), SpecializedVehicle< Train, Type >::From(), GetWindowClassForVehicleType(), Vehicle::InvalidateNewGRFCacheOfChain(), InvalidateWindowClassesData(), InvalidateWindowData(), IsCompanyBuildableVehicleType(), GroundVehicle< T, Type >::IsFreeWagon(), Vehicle::IsStoppedInDepot(), Order::IsType(), Vehicle::MarkDirty(), NUM_CARGO, Vehicle::owner, QueryCost, RefitVehicle(), RoadVehUpdateCache(), SetWindowDirty(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Vehicle::tile, BaseVehicle::type, UpdateAircraftCache(), Ship::UpdateCache(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, Vehicle::vehstatus, WC_VEHICLE_DEPOT, and WC_VEHICLE_DETAILS.

Referenced by CmdBuildVehicle().

◆ CmdRenameVehicle()

CommandCost CmdRenameVehicle ( DoCommandFlags 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 1078 of file vehicle_cmd.cpp.

References AutoReplace, CheckOwnership(), CMD_ERROR, Execute, CommandCost::Failed(), GetWindowClassForVehicleType(), InvalidateWindowClassesData(), Vehicle::IsPrimaryVehicle(), IsUniqueVehicleName(), MarkWholeScreenDirty(), MAX_LENGTH_VEHICLE_NAME_CHARS, BaseConsist::name, Vehicle::owner, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), BaseVehicle::type, and Utf8StringLength().

◆ CmdSellVehicle()

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

Sell a vehicle.

Parameters
flagsfor command.
v_idvehicle ID being sold.
sell_chainsell the vehicle and all vehicles following it in the chain.
backup_ordermake a backup of the vehicle's order (if an engine).
client_idUser.
Returns
the cost of this operation or an error.

Definition at line 236 of file vehicle_cmd.cpp.

References OrderBackup::Backup(), CheckOwnership(), CMD_ERROR, CmdSellRailWagon(), Crashed, Execute, EXPENSES_NEW_VEHICLES, CommandCost::Failed(), Vehicle::First(), Vehicle::IsPrimaryVehicle(), Vehicle::IsStoppedInDepot(), Vehicle::owner, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), BaseVehicle::type, Vehicle::value, VEH_TRAIN, and Vehicle::vehstatus.

◆ CmdSendVehicleToDepot()

CommandCost CmdSendVehicleToDepot ( DoCommandFlags flags,
VehicleID veh_id,
DepotCommandFlags 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 1056 of file vehicle_cmd.cpp.

References CMD_ERROR, Vehicle::IsPrimaryVehicle(), MassSend, SendAllVehiclesToDepot(), Vehicle::SendToDepot(), Service, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

◆ CmdStartStopVehicle()

CommandCost CmdStartStopVehicle ( DoCommandFlags 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.