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 "vehicle_gui.h"
#include "train.h"
#include "aircraft.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 "engine_base.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. | |
static CommandCost | GetRefitCost (EngineID engine_type) |
Learn the price of refitting a certain engine. | |
CommandCost | RefitVehicle (Vehicle *v, bool only_this, CargoID new_cid, byte new_subtype, DoCommandFlag flags) |
Refits a vehicle (chain). | |
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 [] |
Commands for vehicles.
Definition in file vehicle_cmd.cpp.
Clone the custom name of a vehicle, adding or incrementing a number.
src | Source vehicle, with a custom name. | |
dst | Destination vehicle. |
Definition at line 345 of file vehicle_cmd.cpp.
References IsUniqueVehicleName(), lastof, Vehicle::name, 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.
tile | unused | |
flags | type of operation | |
p1 | vehicle ID that is being service-interval-changed | |
p2 | new service interval | |
text | unused |
Definition at line 647 of file vehicle_cmd.cpp.
References CheckOwnership(), CMD_ERROR, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), GetServiceIntervalClamped(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::IsPrimaryVehicle(), and SetWindowDirty().
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
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 | |
text | unused |
Definition at line 398 of file vehicle_cmd.cpp.
References CommandCost::AddCost(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::CanAllocateItem(), Engine::CanCarryCargo(), Vehicle::cargo_subtype, Vehicle::cargo_type, CheckOwnership(), CloneVehicleName(), CMD_ADD_VEHICLE_GROUP, CMD_CLONE_ORDER, CMD_ERROR, CMD_MOVE_RAIL_VEHICLE, CT_INVALID, DC_AUTOREPLACE, DC_EXEC, DoCommand(), EXPENSES_NEW_VEHICLES, CommandCost::Failed(), SpecializedVehicle< RoadVehicle, VEH_ROAD >::From(), SpecializedVehicle< Train, VEH_TRAIN >::From(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), GetBestFittingSubType(), Engine::GetDefaultCargoType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Train::GetNextArticPart(), Train::GetNextVehicle(), GetRefitCost(), Vehicle::group_id, RoadVehicle::HasArticulatedPart(), Train::HasArticulatedPart(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, Train::IsFrontEngine(), Vehicle::IsPrimaryVehicle(), Train::IsRearDualheaded(), Vehicle::name, Vehicle::Next(), return_cmd_error, SetBit(), CommandCost::Succeeded(), Vehicle::tile, BaseVehicle::type, VEH_ROAD, and VEH_TRAIN.
CommandCost CmdDepotMassAutoReplace | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Autoreplace all vehicles in the depot.
tile | Tile of the depot where the vehicles are | |
flags | type of operation | |
p1 | Type of vehicle | |
p2 | unused | |
text | unused |
Definition at line 209 of file vehicle_cmd.cpp.
References CommandCost::AddCost(), BuildDepotVehicleList(), CMD_AUTOREPLACE_VEHICLE, CMD_ERROR, DoCommand(), EXPENSES_NEW_VEHICLES, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, IsDepotTile(), Vehicle::IsInDepot(), 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.
tile | Tile of the depot where the depot is | |
flags | type of operation | |
p1 | Vehicle type | |
p2 | unused | |
text | unused |
Definition at line 178 of file vehicle_cmd.cpp.
References CommandCost::AddCost(), BuildDepotVehicleList(), CMD_ERROR, DoCommand(), EXPENSES_NEW_VEHICLES, CommandCost::GetCost(), 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.
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 | |
text | unused |
Definition at line 131 of file vehicle_cmd.cpp.
References BuildDepotVehicleList(), CMD_ERROR, CMD_START_STOP_VEHICLE, DoCommand(), SpecializedVehicle< Train, VEH_TRAIN >::From(), GenerateVehicleSortList(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, Train::IsInDepot(), SmallVector< T, S >::Length(), VEH_TRAIN, and Vehicle::vehstatus.
CommandCost CmdRenameVehicle | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Give a custom name to your vehicle.
tile | unused | |
flags | type of operation | |
p1 | vehicle ID to name | |
p2 | unused | |
text | the new name or an empty string when resetting to the default |
Definition at line 616 of file vehicle_cmd.cpp.
References CheckOwnership(), CMD_ERROR, DC_AUTOREPLACE, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), InvalidateWindowClassesData(), Vehicle::IsPrimaryVehicle(), IsUniqueVehicleName(), MarkWholeScreenDirty(), MAX_LENGTH_VEHICLE_NAME_BYTES, Vehicle::name, return_cmd_error, and StrEmpty().
CommandCost CmdStartStopVehicle | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Start/Stop a vehicle.
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) | |
text | unused |
Definition at line 72 of file vehicle_cmd.cpp.
References AccelerationCache::cached_power, CALLBACK_FAILED, CBID_VEHICLE_START_STOP_CHECK, CheckOwnership(), CMD_ERROR, Vehicle::cur_speed, DC_AUTOREPLACE, DC_EXEC, DeleteVehicleNews(), error(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedVehicle< Train, VEH_TRAIN >::From(), GB(), GetEngineGRFID(), GetGRFStringID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), GetVehicleCallback(), GetWindowClassForVehicleType(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::IsPrimaryVehicle(), Vehicle::IsStoppedInDepot(), Vehicle::MarkDirty(), return_cmd_error, SetBit(), SetWindowClassesDirty(), SetWindowDirty(), SetWindowWidgetDirty(), Vehicle::tile, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, and Vehicle::vehstatus.
static CommandCost GetRefitCost | ( | EngineID | engine_type | ) | [static] |
Learn the price of refitting a certain engine.
engine_type | Which engine to refit |
Definition at line 238 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, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetPrice(), RAILVEH_WAGON, Engine::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.
Referenced by CmdCloneVehicle(), and RefitVehicle().
static bool IsUniqueVehicleName | ( | const char * | name | ) | [static] |
Test if a name is unique among vehicle names.
name | Name to test. |
Definition at line 330 of file vehicle_cmd.cpp.
References Vehicle::name.
Referenced by CloneVehicleName(), and CmdRenameVehicle().
CommandCost RefitVehicle | ( | Vehicle * | v, | |
bool | only_this, | |||
CargoID | new_cid, | |||
byte | new_subtype, | |||
DoCommandFlag | flags | |||
) |
Refits a vehicle (chain).
This is the vehicle-type independent part of the CmdRefitXXX functions.
v | The vehicle to refit. | |
only_this | Whether to only refit this vehicle, or the whole chain. | |
new_cid | Cargotype to refit to | |
new_subtype | Cargo subtype to refit to | |
flags | Command flags |
Definition at line 281 of file vehicle_cmd.cpp.
References Engine::CanCarryCargo(), Vehicle::cargo, Vehicle::cargo_cap, Vehicle::cargo_subtype, Vehicle::cargo_type, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Vehicle::GetExpenseType(), GetRefitCost(), GetVehicleCapacity(), HasBit(), Vehicle::InvalidateNewGRFCacheOfChain(), Vehicle::Next(), CargoList< Tinst >::Truncate(), BaseVehicle::type, and VEH_AIRCRAFT.
Referenced by CmdRefitAircraft(), CmdRefitRailVehicle(), CmdRefitRoadVeh(), and CmdRefitShip().
CommandCost SendAllVehiclesToDepot | ( | VehicleType | type, | |
DoCommandFlag | flags, | |||
bool | service, | |||
Owner | owner, | |||
uint16 | vlw_flag, | |||
uint32 | id | |||
) |
Send all vehicles of type to depots.
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 | |
id | general purpose id whoms meaning is given by vlw_flag ; e.g. StationID for station lists |
Definition at line 585 of file vehicle_cmd.cpp.
References CMD_ERROR, DC_EXEC, DEPOT_DONT_CANCEL, DoCommand(), GenerateVehicleSortList(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, SmallVector< T, S >::Length(), CommandCost::Succeeded(), and Vehicle::tile.
Referenced by CmdSendAircraftToHangar(), CmdSendRoadVehToDepot(), CmdSendShipToDepot(), and CmdSendTrainToDepot().
const uint32 _send_to_depot_proc_table[] |
{ CMD_SEND_TRAIN_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_TRAIN_TO_DEPOT) | CMD_NO_TEST_IF_IN_NETWORK, CMD_SEND_ROADVEH_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_ROAD_VEHICLE_TO_DEPOT), CMD_SEND_SHIP_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_SHIP_TO_DEPOT), CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_MSG(STR_ERROR_CAN_T_SEND_AIRCRAFT_TO_HANGAR), }
Definition at line 56 of file vehicle_cmd.cpp.
const uint32 _veh_build_proc_table[] |
{ CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_TRAIN), CMD_BUILD_ROAD_VEH | CMD_MSG(STR_ERROR_CAN_T_BUY_ROAD_VEHICLE), CMD_BUILD_SHIP | CMD_MSG(STR_ERROR_CAN_T_BUY_SHIP), CMD_BUILD_AIRCRAFT | CMD_MSG(STR_ERROR_CAN_T_BUY_AIRCRAFT), }
Definition at line 35 of file vehicle_cmd.cpp.
const uint32 _veh_refit_proc_table[] |
{ CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_REFIT_TRAIN), CMD_REFIT_ROAD_VEH | CMD_MSG(STR_ERROR_CAN_T_REFIT_ROAD_VEHICLE), CMD_REFIT_SHIP | CMD_MSG(STR_ERROR_CAN_T_REFIT_SHIP), CMD_REFIT_AIRCRAFT | CMD_MSG(STR_ERROR_CAN_T_REFIT_AIRCRAFT), }
Definition at line 49 of file vehicle_cmd.cpp.
const uint32 _veh_sell_proc_table[] |
{ CMD_SELL_RAIL_WAGON | CMD_MSG(STR_ERROR_CAN_T_SELL_TRAIN), CMD_SELL_ROAD_VEH | CMD_MSG(STR_ERROR_CAN_T_SELL_ROAD_VEHICLE), CMD_SELL_SHIP | CMD_MSG(STR_ERROR_CAN_T_SELL_SHIP), CMD_SELL_AIRCRAFT | CMD_MSG(STR_ERROR_CAN_T_SELL_AIRCRAFT), }
Definition at line 42 of file vehicle_cmd.cpp.