vehicle_cmd.cpp File Reference

Commands for vehicles. More...

#include "stdafx.h"
#include "roadveh.h"
#include "gfx_func.h"
#include "news_func.h"
#include "airport.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 "infrastructure_func.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 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 []


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 373 of file vehicle_cmd.cpp.

References 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
text unused
Returns:
the cost of this operation or an error

Definition at line 672 of file vehicle_cmd.cpp.

References CMD_ERROR, DC_EXEC, GetServiceIntervalClamped(), 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

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
text unused
Returns:
the cost of this operation or an error

Definition at line 423 of file vehicle_cmd.cpp.

References CommandCost::AddCost(), CloneVehicleName(), CMD_ADD_VEHICLE_GROUP, CMD_CLONE_ORDER, CMD_ERROR, CMD_MOVE_RAIL_VEHICLE, CmdFailed(), CmdSucceeded(), Train::crash_anim_pos, CT_INVALID, DC_AUTOREPLACE, DC_EXEC, DoCommand(), SpecializedVehicle< RoadVehicle, VEH_ROAD >::From(), SpecializedVehicle< Train, VEH_TRAIN >::From(), GetBestFittingSubType(), Train::GetNextArticPart(), Train::GetNextVehicle(), GetRefitCost(), RoadVehicle::HasArticulatedPart(), Train::HasArticulatedPart(), HasBit(), Train::IsFrontEngine(), Train::IsRearDualheaded(), SpecializedVehicle< T, Type >::Next(), return_cmd_error, SetBit(), VEH_ROAD, and VEH_TRAIN.

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)
text unused
Returns:
the cost of this operation or an error

Definition at line 214 of file vehicle_cmd.cpp.

References CommandCost::AddCost(), BuildDepotVehicleList(), CheckInfraUsageAllowed(), CMD_AUTOREPLACE_VEHICLE, CMD_ERROR, CmdSucceeded(), DC_EXEC, DoCommand(), GB(), CommandCost::GetErrorMessage(), GetTileOwner(), HasBit(), IsDepotTile(), 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
text unused
Returns:
the cost of this operation or an error

Definition at line 183 of file vehicle_cmd.cpp.

References CommandCost::AddCost(), BuildDepotVehicleList(), CMD_ERROR, 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)
text unused
Returns:
the cost of this operation or an error

Definition at line 131 of file vehicle_cmd.cpp.

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

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
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 641 of file vehicle_cmd.cpp.

References CMD_ERROR, DC_AUTOREPLACE, DC_EXEC, InvalidateWindowClassesData(), IsUniqueVehicleName(), 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)
text unused
Returns:
the cost of this operation or an error

Definition at line 72 of file vehicle_cmd.cpp.

References TrainCache::cached_power, CALLBACK_FAILED, CBID_VEHICLE_START_STOP_CHECK, CheckVehicleControlAllowed(), CMD_ERROR, DC_AUTOREPLACE, DC_EXEC, DeleteVehicleNews(), error(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedVehicle< Train, VEH_TRAIN >::From(), GB(), GetEngineGRFID(), GetGRFStringID(), GetVehicleCallback(), GetWindowClassForVehicleType(), HasBit(), return_cmd_error, SetBit(), SetWindowClassesDirty(), SetWindowDirty(), SetWindowWidgetDirty(), Aircraft::state, Train::tcache, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

static CommandCost GetRefitCost ( EngineID  engine_type  )  [static]

Learn the price of refitting a certain engine.

Parameters:
engine_type Which engine to refit
Returns:
Price for refitting

Definition at line 264 of file vehicle_cmd.cpp.

References GetPrice(), RAILVEH_WAGON, 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.

Parameters:
name Name to test.
Returns:
True ifffffff the name is unique.

Definition at line 358 of file vehicle_cmd.cpp.

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.

Parameters:
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
Returns:
refit cost; or CMD_ERROR if no vehicle was actually refitable to the cargo

Definition at line 307 of file vehicle_cmd.cpp.

References CMD_ERROR, DC_EXEC, GetRefitCost(), GetVehicleCapacity(), HasBit(), 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.

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
id general purpose id whoms meaning is given by vlw_flag; e.g. StationID for station lists
Returns:
0 for success and CMD_ERROR if no vehicle is able to go to depot

Definition at line 610 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_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[]

Initial value:

 {
  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[]

Initial value:

 {
  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[]

Initial value:

 {
  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.


Generated on Sat Dec 26 20:06:20 2009 for OpenTTD by  doxygen 1.5.6