OpenTTD
Data Structures | Functions | Variables
vehicle_cmd.cpp File Reference

Commands for vehicles. More...

#include "stdafx.h"
#include "roadveh.h"
#include "news_func.h"
#include "airport.h"
#include "cmd_helper.h"
#include "command_func.h"
#include "company_func.h"
#include "train.h"
#include "aircraft.h"
#include "newgrf_text.h"
#include "vehicle_func.h"
#include "string_func.h"
#include "depot_map.h"
#include "vehiclelist.h"
#include "engine_func.h"
#include "articulated_vehicles.h"
#include "autoreplace_gui.h"
#include "group.h"
#include "order_backup.h"
#include "ship.h"
#include "newgrf.h"
#include "company_base.h"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  RefitResult
 Helper structure for RefitVehicle() More...

Functions

CommandCost CmdBuildRailVehicle (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v)
 Build a railroad vehicle.
CommandCost CmdBuildRoadVehicle (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v)
 Build a road vehicle.
CommandCost CmdBuildShip (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v)
 Build a ship.
CommandCost CmdBuildAircraft (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v)
 Build an aircraft.
CommandCost CmdBuildVehicle (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build a vehicle.
CommandCost CmdSellRailWagon (DoCommandFlag flags, Vehicle *v, uint16 data, uint32 user)
 Sell a (single) train wagon/engine.
CommandCost CmdSellVehicle (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Sell a vehicle.
static int GetRefitCostFactor (const Vehicle *v, EngineID engine_type, CargoID new_cid, byte new_subtype, bool *auto_refit_allowed)
 Helper to run the refit cost callback.
static CommandCost GetRefitCost (const Vehicle *v, EngineID engine_type, CargoID new_cid, byte new_subtype, bool *auto_refit_allowed)
 Learn the price of refitting a certain engine.
static CommandCost RefitVehicle (Vehicle *v, bool only_this, uint8 num_vehicles, CargoID new_cid, byte new_subtype, DoCommandFlag flags, bool auto_refit)
 Refits a vehicle (chain).
CommandCost CmdRefitVehicle (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Refits a vehicle to the specified cargo type.
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.
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.
static CommandCost SendAllVehiclesToDepot (DoCommandFlag flags, bool service, const VehicleListIdentifier &vli)
 Send all vehicles of type to depots.
CommandCost CmdSendVehicleToDepot (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Send a vehicle to the depot.
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
srcSource vehicle, with a custom name.
dstDestination vehicle.

Definition at line 726 of file vehicle_cmd.cpp.

References IsUniqueVehicleName(), lastof, BaseConsist::name, seprintf(), strecat(), strecpy(), and stredup().

Referenced by CmdCloneVehicle().

CommandCost CmdBuildAircraft ( TileIndex  tile,
DoCommandFlag  flags,
const Engine e,
uint16  data,
Vehicle **  ret 
)

Build an aircraft.

Parameters
tiletile of the depot where aircraft is built.
flagstype of operation.
ethe engine to build.
dataunused.
ret[out]the vehicle that has been built.
Returns
the cost of this operation or an error.

Definition at line 244 of file aircraft_cmd.cpp.

References _cur_year, _current_company, _date, Vehicle::acceleration, AIR_AIRCRAFT, AIR_HELICOPTER, AIR_ROTOR, AIR_SHADOW, Station::airport, Vehicle::build_year, CanVehicleUseStation(), Vehicle::cargo_cap, Vehicle::cargo_type, CMD_ERROR, Vehicle::cur_image, Vehicle::date_of_last_service, DC_EXEC, Engine::DetermineCapacity(), DIR_N, DIR_SE, Vehicle::direction, ENGINE_EXCLUSIVE_PREVIEW, Vehicle::engine_type, Engine::flags, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), SpecializedStation< Station, false >::GetByTile(), Engine::GetDefaultCargoType(), Airport::GetHangarNum(), Airport::GetHangarTile(), Engine::GetLifeLengthInDays(), GetStationIndex(), GetVehiclePosOnBuild(), HANGAR, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_DIR, Vehicle::InvalidateNewGRFCacheOfChain(), Vehicle::last_loading_station, Vehicle::last_station_visited, AircraftVehicleInfo::mail_capacity, Vehicle::max_age, BaseConsist::name, Vehicle::owner, AircraftVehicleInfo::passenger_capacity, Aircraft::pos, Aircraft::previous_pos, Vehicle::random_bits, Vehicle::refit_cap, Engine::reliability, Vehicle::reliability, Engine::reliability_spd_dec, Vehicle::reliability_spd_dec, ROTOR_Z_OFFSET, SetBit(), Vehicle::SetNext(), Vehicle::spritenum, Aircraft::state, AircraftVehicleInfo::subtype, Vehicle::subtype, Aircraft::targetairport, Vehicle::tile, TILE_SIZE, TileX(), TileY(), UpdateAircraftCache(), Aircraft::UpdateDeltaXY(), Vehicle::UpdatePosition(), BaseConsist::vehicle_flags, VehicleRandomBits(), Vehicle::vehstatus, VF_BUILT_AS_PROTOTYPE, VS_DEFPAL, VS_HIDDEN, VS_SHADOW, VS_STOPPED, VS_UNCLICKABLE, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.

Referenced by CmdBuildVehicle().

CommandCost CmdBuildRailVehicle ( TileIndex  tile,
DoCommandFlag  flags,
const Engine e,
uint16  data,
Vehicle **  ret 
)

Build a railroad vehicle.

Parameters
tiletile of the depot where rail-vehicle is built.
flagstype of operation.
ethe engine to build.
databit 0 prevents any free cars from being added to the train.
ret[out]the vehicle that has been built.
Returns
the cost of this operation or an error.

Definition at line 728 of file train_cmd.cpp.

References _cur_year, _current_company, _date, AddArticulatedParts(), Vehicle::build_year, RailVehicleInfo::capacity, Vehicle::cargo_cap, Vehicle::cargo_type, CCF_ARRANGE, CheckConsistencyOfArticulatedVehicle(), CMD_ERROR, CmdBuildRailWagon(), Train::ConsistChanged(), Vehicle::cur_image, Vehicle::date_of_last_service, DC_AUTOREPLACE, DC_EXEC, DEFAULT_GROUP, DiagDirToDir(), Vehicle::direction, ENGINE_EXCLUSIVE_PREVIEW, Vehicle::engine_type, GroundVehicleCache::first_engine, Engine::flags, GroundVehicle< T, Type >::gcache, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Engine::GetDefaultCargoType(), Engine::GetLifeLengthInDays(), GetRailDepotDirection(), GetRailType(), Vehicle::group_id, HasBit(), HasPowerOnRail(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_ENGINE, Vehicle::last_loading_station, Vehicle::last_station_visited, Vehicle::max_age, NormalizeTrainVehInDepot(), Vehicle::owner, RAILVEH_MULTIHEAD, RAILVEH_WAGON, Vehicle::random_bits, Vehicle::refit_cap, Engine::reliability, Vehicle::reliability, Engine::reliability_spd_dec, Vehicle::reliability_spd_dec, SetBit(), GroundVehicle< T, Type >::SetEngine(), GroundVehicle< T, Type >::SetFrontEngine(), Vehicle::spritenum, Vehicle::tile, TILE_SIZE, TileX(), TileY(), TRACK_BIT_DEPOT, Vehicle::UpdatePosition(), UpdateTrainGroupID(), BaseConsist::vehicle_flags, VehicleRandomBits(), Vehicle::vehstatus, VF_BUILT_AS_PROTOTYPE, VS_DEFPAL, VS_HIDDEN, VS_STOPPED, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.

Referenced by CmdBuildVehicle().

CommandCost CmdBuildRoadVehicle ( TileIndex  tile,
DoCommandFlag  flags,
const Engine e,
uint16  data,
Vehicle **  ret 
)

Build a road vehicle.

Parameters
tiletile of the depot where road vehicle is built.
flagstype of operation.
ethe engine to build.
dataunused.
ret[out]the vehicle that has been built.
Returns
the cost of this operation or an error.

Definition at line 267 of file roadveh_cmd.cpp.

References _cur_year, _current_company, _date, _settings_game, AddArticulatedParts(), Vehicle::build_year, GroundVehicleCache::cached_veh_length, Vehicle::cargo_cap, Vehicle::cargo_type, GroundVehicle< T, Type >::CargoChanged(), CheckConsistencyOfArticulatedVehicle(), Vehicle::cur_image, Vehicle::date_of_last_service, DC_EXEC, DiagDirToDir(), Vehicle::direction, EF_ROAD_TRAM, ENGINE_EXCLUSIVE_PREVIEW, Vehicle::engine_type, GroundVehicleCache::first_engine, Engine::flags, GroundVehicle< T, Type >::gcache, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Engine::GetDefaultCargoType(), Engine::GetLifeLengthInDays(), GetRoadDepotDirection(), HasBit(), HasTileRoadType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_ENGINE, Vehicle::InvalidateNewGRFCache(), Vehicle::InvalidateNewGRFCacheOfChain(), Vehicle::last_loading_station, Vehicle::last_station_visited, Vehicle::max_age, EngineInfo::misc_flags, SpecializedVehicle< T, Type >::Next(), Vehicle::owner, Vehicle::random_bits, Vehicle::refit_cap, Engine::reliability, Vehicle::reliability, Engine::reliability_spd_dec, Vehicle::reliability_spd_dec, return_cmd_error, ROADTYPE_ROAD, ROADTYPE_TRAM, RoadTypeToRoadTypes(), VehicleSettings::roadveh_acceleration_model, RoadVehUpdateCache(), RVSB_IN_DEPOT, SetBit(), GroundVehicle< T, Type >::SetFrontEngine(), Vehicle::spritenum, RoadVehicle::state, Vehicle::tile, TILE_SIZE, TileX(), TileY(), Vehicle::UpdatePosition(), GameSettings::vehicle, BaseConsist::vehicle_flags, VEHICLE_LENGTH, VehicleRandomBits(), Vehicle::vehstatus, VF_BUILT_AS_PROTOTYPE, VS_DEFPAL, VS_HIDDEN, VS_STOPPED, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.

Referenced by CmdBuildVehicle().

CommandCost CmdBuildShip ( TileIndex  tile,
DoCommandFlag  flags,
const Engine e,
uint16  data,
Vehicle **  ret 
)

Build a ship.

Parameters
tiletile of the depot where ship is built.
flagstype of operation.
ethe engine to build.
dataunused.
ret[out]the vehicle that has been built.
Returns
the cost of this operation or an error.

Definition at line 671 of file ship_cmd.cpp.

References _cur_year, _current_company, _date, Vehicle::build_year, Vehicle::cargo_cap, Vehicle::cargo_type, Vehicle::cur_image, Vehicle::date_of_last_service, DC_EXEC, Engine::DetermineCapacity(), Vehicle::direction, ENGINE_EXCLUSIVE_PREVIEW, Vehicle::engine_type, Engine::flags, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Engine::GetDefaultCargoType(), Engine::GetLifeLengthInDays(), GetShipDepotNorthTile(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::InvalidateNewGRFCacheOfChain(), Vehicle::last_loading_station, Vehicle::last_station_visited, Vehicle::max_age, Vehicle::owner, Vehicle::random_bits, Vehicle::refit_cap, Engine::reliability, Vehicle::reliability, Engine::reliability_spd_dec, Vehicle::reliability_spd_dec, SetBit(), Vehicle::spritenum, Ship::state, Vehicle::tile, TILE_SIZE, TileX(), TileY(), TRACK_BIT_DEPOT, Ship::UpdateCache(), Ship::UpdateDeltaXY(), Vehicle::UpdatePosition(), BaseConsist::vehicle_flags, VehicleRandomBits(), Vehicle::vehstatus, VF_BUILT_AS_PROTOTYPE, VS_DEFPAL, VS_HIDDEN, VS_STOPPED, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.

Referenced by CmdBuildVehicle().

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

Build a vehicle.

Parameters
tiletile of depot where the vehicle is built
flagsfor command
p1various bitstuffed data bits 0-15: vehicle type being built. bits 16-31: vehicle type specific bits passed on to the vehicle build functions.
p2User
textunused
Returns
the cost of this operation or an error

Definition at line 85 of file vehicle_cmd.cpp.

References _current_company, AIR_CTOL, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::CanAllocateItem(), CMD_ERROR, CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRoadVehicle(), CmdBuildShip(), CountArticulatedParts(), GroupStatistics::CountEngine(), GroupStatistics::CountVehicle(), CT_INVALID, DC_AUTOREPLACE, DC_EXEC, Vehicle::engine_type, EXPENSES_NEW_VEHICLES, GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Engine::GetCost(), Engine::GetDefaultCargoType(), GetDepotVehicleType(), GetFreeUnitNumber(), GetWindowClassForVehicleType(), Vehicle::group_id, InvalidateAutoreplaceWindow(), InvalidateWindowClassesData(), InvalidateWindowData(), IsDepotTile(), IsEngineBuildable(), IsLocalCompany(), Vehicle::IsPrimaryVehicle(), IsTileOwner(), RAILVEH_MULTIHEAD, RAILVEH_WAGON, OrderBackup::Restore(), return_cmd_error, SetWindowDirty(), AircraftVehicleInfo::subtype, Vehicle::tile, Vehicle::unitnumber, GroupStatistics::UpdateAutoreplace(), Vehicle::value, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, WC_COMPANY, and WC_VEHICLE_DEPOT.

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

Change the service interval of a vehicle.

Parameters
tileunused
flagstype of operation
p1vehicle ID that is being service-interval-changed
p2bitmask
  • p2 = (bit 0-15) - new service interval
  • p2 = (bit 16) - service interval is custom flag
  • p2 = (bit 17) - service interval is percentage flag
textunused
Returns
the cost of this operation or an error

Definition at line 1062 of file vehicle_cmd.cpp.

References CheckOwnership(), CMD_ERROR, CompanyServiceInterval(), DC_EXEC, CommandCost::Failed(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), GetServiceIntervalClamped(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::IsPrimaryVehicle(), Vehicle::owner, VehicleDefaultSettings::servint_ispercent, Company::settings, SetWindowDirty(), BaseVehicle::type, CompanySettings::vehicle, and WC_VEHICLE_DETAILS.

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
tiletile of the depot where the cloned vehicle is build
flagstype of operation
p1the original vehicle's index
p21 = shared orders, else copied orders
textunused
Returns
the cost of this operation or an error

Definition at line 780 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_ADD_VEHICLE_GROUP, CMD_CLONE_ORDER, CMD_ERROR, CMD_MOVE_RAIL_VEHICLE, Train::crash_anim_pos, CT_INVALID, DC_AUTOREPLACE, DC_EXEC, DoCommand(), Vehicle::engine_type, EXPENSES_NEW_VEHICLES, CommandCost::Failed(), SpecializedVehicle< Train, 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, Vehicle::IsFrontEngine(), Vehicle::IsGroundVehicle(), Vehicle::IsPrimaryVehicle(), GroundVehicle< T, Type >::IsRearDualheaded(), BaseConsist::name, Vehicle::Next(), Vehicle::owner, return_cmd_error, BaseConsist::service_interval, SetBit(), CommandCost::Succeeded(), Vehicle::tile, BaseVehicle::type, VEH_TRAIN, and VRF_REVERSE_DIRECTION.

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

Autoreplace all vehicles in the depot.

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

Definition at line 680 of file vehicle_cmd.cpp.

References _current_company, CommandCost::AddCost(), BuildDepotVehicleList(), CMD_AUTOREPLACE_VEHICLE, CMD_ERROR, DoCommand(), EXPENSES_NEW_VEHICLES, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::IsChainInDepot(), IsCompanyBuildableVehicleType(), IsDepotTile(), IsTileOwner(), SmallVector< T, S >::Length(), and CommandCost::Succeeded().

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

Sells all vehicles in a depot.

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

Definition at line 642 of file vehicle_cmd.cpp.

References CommandCost::AddCost(), BuildDepotVehicleList(), CMD_ERROR, DoCommand(), EXPENSES_NEW_VEHICLES, IsCompanyBuildableVehicleType(), SmallVector< T, S >::Length(), and CommandCost::Succeeded().

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

Starts or stops a lot of vehicles.

Parameters
tileTile of the depot where the vehicles are started/stopped (only used for depots)
flagstype of operation
p1bitmask
  • bit 0 set = start vehicles, unset = stop vehicles
  • bit 1 if set, then it's a vehicle list window, not a depot and Tile is ignored in this case
p2packed VehicleListIdentifier
textunused
Returns
the cost of this operation or an error

Definition at line 602 of file vehicle_cmd.cpp.

References BuildDepotVehicleList(), CMD_ERROR, CMD_START_STOP_VEHICLE, DoCommand(), GenerateVehicleSortList(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::IsChainInDepot(), IsCompanyBuildableVehicleType(), SmallVector< T, S >::Length(), VehicleListIdentifier::Unpack(), Vehicle::vehstatus, VS_STOPPED, and VehicleListIdentifier::vtype.

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

Refits a vehicle to the specified cargo type.

Parameters
tileunused
flagstype of operation
p1vehicle ID to refit
p2various bitstuffed elements
  • p2 = (bit 0-4) - New cargo type to refit to.
  • p2 = (bit 6) - Automatic refitting.
  • p2 = (bit 7) - Refit only this vehicle. Used only for cloning vehicles.
  • p2 = (bit 8-15) - New cargo subtype to refit to. 0xFF means to try keeping the same subtype according to GetBestFittingSubType().
  • p2 = (bit 16-23) - Number of vehicles to refit (not counting articulated parts). Zero means all vehicles. Only used if "refit only this vehicle" is false.
textunused
Returns
the cost of this operation or an error

Definition at line 432 of file vehicle_cmd.cpp.

References _settings_game, GroundVehicle< T, Type >::CargoChanged(), CCF_AUTOREFIT, CCF_REFIT, CheckOwnership(), CMD_ERROR, Train::ConsistChanged(), Vehicle::current_order, DC_EXEC, DC_QUERY_COST, CommandCost::Failed(), Vehicle::First(), SpecializedVehicle< Ship, VEH_SHIP >::From(), SpecializedVehicle< Train, Type >::From(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedVehicle< RoadVehicle, Type >::From(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), GetWindowClassForVehicleType(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::InvalidateNewGRFCacheOfChain(), InvalidateWindowClassesData(), InvalidateWindowData(), IsCompanyBuildableVehicleType(), GroundVehicle< T, Type >::IsFreeWagon(), Vehicle::IsStoppedInDepot(), Order::IsType(), Vehicle::MarkDirty(), NUM_CARGO, Vehicle::owner, RefitVehicle(), return_cmd_error, 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.

CommandCost CmdRenameVehicle ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)
CommandCost CmdSellRailWagon ( DoCommandFlag  flags,
Vehicle t,
uint16  data,
uint32  user 
)

Sell a (single) train wagon/engine.

Parameters
flagstype of operation
tthe train wagon to sell
datathe selling mode
  • data = 0: only sell the single dragged wagon/engine (and any belonging rear-engines)
  • data = 1: sell the vehicle and all vehicles following it in the chain if the wagon is dragged, don't delete the possibly belonging rear-engine to some front
userthe user for the order backup.
Returns
the cost of this operation or an error

Definition at line 1359 of file train_cmd.cpp.

References CommandCost::AddCost(), Vehicle::AddToShared(), ArrangeTrains(), OrderBackup::Backup(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool >::CanAllocateItem(), Vehicle::CopyVehicleConfigAndStatistics(), GroupStatistics::CountVehicle(), DC_AUTOREPLACE, DC_EXEC, DeleteVehicleOrders(), EXPENSES_NEW_VEHICLES, CommandCost::Failed(), Vehicle::first, SpecializedVehicle< T, Type >::First(), SpecializedVehicle< Train, Type >::From(), SpecializedVehicle< T, Type >::GetFirstEnginePart(), HasBit(), InvalidateWindowClassesData(), InvalidateWindowData(), GroundVehicle< T, Type >::IsEngine(), Vehicle::IsFrontEngine(), Train::IsPrimaryVehicle(), GroundVehicle< T, Type >::IsRearDualheaded(), Vehicle::list, MAKE_ORDER_BACKUP_FLAG, MakeTrainBackup(), Vehicle::Next(), NormaliseSubtypes(), NormaliseTrainHead(), Vehicle::orders, RestoreTrainBackup(), return_cmd_error, Vehicle::tile, ValidateTrains(), Vehicle::value, WC_TRAINS_LIST, and WC_VEHICLE_DEPOT.

Referenced by CmdSellVehicle().

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

Sell a vehicle.

Parameters
tileunused.
flagsfor command.
p1various bitstuffed data. bits 0-19: vehicle ID being sold. bits 20-30: vehicle type specific bits passed on to the vehicle build functions. bit 31: make a backup of the vehicle's order (if an engine).
p2User.
textunused.
Returns
the cost of this operation or an error.

Definition at line 165 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(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), OrderList::GetNumOrders(), Vehicle::IsPrimaryVehicle(), OrderList::IsShared(), Vehicle::IsStoppedInDepot(), Vehicle::list, MAKE_ORDER_BACKUP_FLAG, Vehicle::orders, Vehicle::owner, return_cmd_error, BaseVehicle::type, Vehicle::value, VEH_TRAIN, Vehicle::vehstatus, and VS_CRASHED.

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

Send a vehicle to the depot.

Parameters
tileunused
flagsfor command type
p1bitmask
  • p1 0-20: bitvehicle ID to send to the depot
  • p1 bits 25-8 - DEPOT_ flags (see vehicle_type.h)
p2packed VehicleListIdentifier.
textunused
Returns
the cost of this operation or an error

Definition at line 999 of file vehicle_cmd.cpp.

References CMD_ERROR, DEPOT_MASS_SEND, DEPOT_SERVICE, GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Vehicle::IsPrimaryVehicle(), SendAllVehiclesToDepot(), Vehicle::SendToDepot(), and VehicleListIdentifier::Unpack().

CommandCost CmdStartStopVehicle ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)
static CommandCost GetRefitCost ( const Vehicle v,
EngineID  engine_type,
CargoID  new_cid,
byte  new_subtype,
bool *  auto_refit_allowed 
)
static

Learn the price of refitting a certain engine.

Parameters
vThe vehicle we are refitting, can be NULL.
engine_typeWhich engine to refit
new_cidCargo type we are refitting to.
new_subtypeNew cargo subtype.
[out]auto_refit_allowedThe refit is allowed as an auto-refit.
Returns
Price for refitting

Definition at line 244 of file vehicle_cmd.cpp.

References EXPENSES_AIRCRAFT_RUN, EXPENSES_ROADVEH_RUN, EXPENSES_SHIP_RUN, EXPENSES_TRAIN_RUN, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Engine::GetGRF(), GetPrice(), GetRefitCostFactor(), RAILVEH_WAGON, Engine::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by CmdCloneVehicle(), and RefitVehicle().

static int GetRefitCostFactor ( const Vehicle v,
EngineID  engine_type,
CargoID  new_cid,
byte  new_subtype,
bool *  auto_refit_allowed 
)
static

Helper to run the refit cost callback.

Parameters
vThe vehicle we are refitting, can be NULL.
engine_typeWhich engine to refit
new_cidCargo type we are refitting to.
new_subtypeNew cargo subtype.
[out]auto_refit_allowedThe refit is allowed as an auto-refit.
Returns
Price for refitting

Definition at line 212 of file vehicle_cmd.cpp.

References CALLBACK_FAILED, GRFFile::cargo_map, Vehicle::cargo_type, CBID_VEHICLE_REFIT_COST, CargoSpec::classes, GB(), CargoSpec::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Engine::GetGRF(), GetVehicleCallback(), and HasBit().

Referenced by GetRefitCost().

static bool IsUniqueVehicleName ( const char *  name)
static

Test if a name is unique among vehicle names.

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

Definition at line 710 of file vehicle_cmd.cpp.

References FOR_ALL_VEHICLES, and BaseConsist::name.

Referenced by CloneVehicleName(), and CmdRenameVehicle().

static CommandCost RefitVehicle ( Vehicle v,
bool  only_this,
uint8  num_vehicles,
CargoID  new_cid,
byte  new_subtype,
DoCommandFlag  flags,
bool  auto_refit 
)
static

Refits a vehicle (chain).

This is the vehicle-type independent part of the CmdRefitXXX functions.

Parameters
vThe vehicle to refit.
only_thisWhether to only refit this vehicle, or to check the rest of them.
num_vehiclesNumber of vehicles to refit (not counting articulated parts). Zero means the whole chain.
new_cidCargotype to refit to
new_subtypeCargo subtype to refit to. 0xFF means to try keeping the same subtype according to GetBestFittingSubType().
flagsCommand flags
auto_refitRefitting is done as automatic refitting outside a depot.
Returns
Refit cost.

Definition at line 301 of file vehicle_cmd.cpp.

References _returned_mail_refit_capacity, _returned_refit_capacity, SmallVector< T, S >::Append(), SmallVector< T, S >::Begin(), Engine::CanCarryCargo(), RefitResult::capacity, Vehicle::cargo, Vehicle::cargo_cap, Vehicle::cargo_subtype, Vehicle::cargo_type, SmallVector< T, S >::Clear(), SmallVector< T, S >::Contains(), DC_EXEC, DC_QUERY_COST, Engine::DetermineCapacity(), EF_AUTO_REFIT, SmallVector< T, S >::End(), Vehicle::engine_type, Vehicle::First(), GetBestFittingSubType(), Vehicle::GetEngine(), Vehicle::GetExpenseType(), GetRefitCost(), GetVehicleSet(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::InvalidateNewGRFCacheOfChain(), Vehicle::IsArticulatedPart(), RefitResult::mail_capacity, min(), EngineInfo::misc_flags, Vehicle::Next(), Vehicle::refit_cap, RefitResult::subtype, VehicleCargoList::TotalCount(), VehicleCargoList::Truncate(), BaseVehicle::type, RefitResult::v, VEH_AIRCRAFT, and VEH_TRAIN.

Referenced by CmdRefitVehicle().

static CommandCost SendAllVehiclesToDepot ( DoCommandFlag  flags,
bool  service,
const VehicleListIdentifier vli 
)
static

Send all vehicles of type to depots.

Parameters
flagsthe flags used for DoCommand()
serviceshould the vehicles only get service in the depots
vliidentifier of the vehicle list
Returns
0 for success and CMD_ERROR if no vehicle is able to go to depot

Definition at line 962 of file vehicle_cmd.cpp.

References CMD_ERROR, DC_EXEC, DEPOT_DONT_CANCEL, DEPOT_SERVICE, DoCommand(), GenerateVehicleSortList(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, SmallVector< T, S >::Length(), CommandCost::Succeeded(), Vehicle::tile, and VehicleListIdentifier::vtype.

Referenced by CmdSendVehicleToDepot().

Variable Documentation

const uint32 _send_to_depot_proc_table[]
Initial value:
{
CMD_SEND_VEHICLE_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_TRAIN_TO_DEPOT),
CMD_SEND_VEHICLE_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_ROAD_VEHICLE_TO_DEPOT),
CMD_SEND_VEHICLE_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_SHIP_TO_DEPOT),
CMD_SEND_VEHICLE_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_AIRCRAFT_TO_HANGAR),
}

Definition at line 61 of file vehicle_cmd.cpp.

const uint32 _veh_build_proc_table[]
Initial value:
{
CMD_BUILD_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_TRAIN),
CMD_BUILD_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_ROAD_VEHICLE),
CMD_BUILD_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_SHIP),
CMD_BUILD_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_AIRCRAFT),
}

Definition at line 40 of file vehicle_cmd.cpp.

const uint32 _veh_refit_proc_table[]
Initial value:
{
CMD_REFIT_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_REFIT_TRAIN),
CMD_REFIT_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_REFIT_ROAD_VEHICLE),
CMD_REFIT_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_REFIT_SHIP),
CMD_REFIT_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_REFIT_AIRCRAFT),
}

Definition at line 54 of file vehicle_cmd.cpp.

const uint32 _veh_sell_proc_table[]
Initial value:
{
CMD_SELL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_SELL_TRAIN),
CMD_SELL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_SELL_ROAD_VEHICLE),
CMD_SELL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_SELL_SHIP),
CMD_SELL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_SELL_AIRCRAFT),
}

Definition at line 47 of file vehicle_cmd.cpp.