# command_func.h File Reference

Functions related to commands. More...

`#include "command_type.h"`

Go to the source code of this file.

## Defines
#define | return_cmd_error(errcode) return CommandCost(errcode);
| Returns from a function with a specific StringID as error.
## Functions
static bool | CmdFailed (CommandCost cost)
| Checks if a command failes.
static bool | CmdSucceeded (CommandCost cost)
| Checks if a command succeeded.
CommandCost | DoCommand (TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const char *text=NULL)
| Execute a command.
CommandCost | DoCommand (const CommandContainer *container, DoCommandFlag flags)
| Shorthand for calling the long DoCommand with a container.
bool | DoCommandP (TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback=NULL, const char *text=NULL, bool my_cmd=true)
| Execute a network safe DoCommand function.
bool | DoCommandP (const CommandContainer *container, bool my_cmd=true)
| Shortcut for the long DoCommandP when having a container with the data.
bool | IsValidCommand (uint32 cmd)
| Checks if a integer value belongs to a command.
byte | GetCommandFlags (uint32 cmd)
| Returns the flags from a given command.
Money | GetAvailableMoneyForCommand ()
| Returns the current money available which can be used for a command.
static DoCommandFlag | CommandFlagsToDCFlags (uint cmd_flags)
| Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
## Variables
static const CommandCost | CMD_ERROR = CommandCost(INVALID_STRING_ID)
| Define a default return value for a failed command.
Money | _additional_cash_required
StringID | _error_message

## Detailed Description

Functions related to commands.

Definition in file command_func.h.

## Define Documentation

#define return_cmd_error | ( | errcode |  | ) | return CommandCost(errcode);

Returns from a function with a specific StringID as error.

This macro is used to return from a function. The parameter contains the StringID which will be returned.

Parameters:

  | errcode | The StringID to return

Definition at line 51 of file command_func.h.

Referenced by CheckFlatLandBelow(), CheckRailSlope(), CmdBuildAircraft(), CmdBuildAirport(), CmdBuildBridge(), CmdBuildBuoy(), CmdBuildCanal(), CmdBuildDock(), CmdBuildLock(), CmdBuildRailroadStation(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildRoadStop(), CmdBuildRoadVeh(), CmdBuildShip(), CmdBuildShipDepot(), CmdBuildSingleRail(), CmdBuildSingleSignal(), CmdBuildTown(), CmdBuildTrainDepot(), CmdBuildTrainWaypoint(), CmdBuildTunnel(), CmdBuyShareInCompany(), CmdChangeTimetable(), CmdCloneOrder(), CmdCloneVehicle(), CmdDecreaseLoan(), CmdIncreaseLoan(), CmdInsertOrder(), CmdLevelLand(), CmdMoveRailVehicle(), CmdPlaceSign(), CmdPlantTree(), CmdPurchaseLandArea(), CmdRefitAircraft(), CmdRefitRailVehicle(), CmdRefitRoadVeh(), CmdRefitShip(), CmdRemoveFromRailroadStation(), CmdRenameCompany(), CmdRenameEngine(), CmdRenameGroup(), CmdRenamePresident(), CmdRenameStation(), CmdRenameTown(), CmdRenameVehicle(), CmdRenameWaypoint(), CmdReverseTrainDirection(), CmdSellAircraft(), CmdSellRailWagon(), CmdSellRoadVeh(), CmdSellShip(), CmdStartStopVehicle(), CmdTerraformLand(), DoBuildShiplift(), RemoveRoad(), and TerraformTileHeight().

## Function Documentation

static bool CmdFailed | ( | CommandCost | cost | ) | `[inline, static]`

Checks if a command failes.

As you see the parameter is not a command but the return value of a command, the CommandCost class. This function checks if the command executed by the CommandProc function failed and returns true if it does.

Parameters:

  | cost | The return value of a CommandProc call

Returns:
  true if the command failes

See also:
  CmdSucceded

Definition at line 21 of file command_func.h.

References CommandCost::Failed().

Referenced by CheckFlatLandBelow(), CheckIfCanLevelIndustryPlatform(), CmdBuildAirport(), CmdBuildBridge(), CmdBuildCanal(), CmdBuildCompanyHQ(), CmdBuildDock(), CmdBuildLongRoad(), CmdBuildRailroadStation(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildRoadStop(), CmdBuildShipDepot(), CmdBuildSingleRail(), CmdBuildTrainDepot(), CmdBuildTunnel(), CmdClearArea(), CmdCloneVehicle(), CmdLevelLand(), CmdPlantTree(), CmdPurchaseLandArea(), CmdRailTrackHelper(), CmdSignalTrackHelper(), CmdTerraformLand(), DoBuildShiplift(), DoCommand(), AIObject::DoCommand(), DoCommandP(), FloodHalftile(), IsRoadAllowedHere(), NormalizeTrainVehInDepot(), ShowBuildBridgeWindow(), StationJoinerNeeded(), TerraformTileHeight(), and TestAutoslopeOnRailTile().

static bool CmdSucceeded | ( | CommandCost | cost | ) | `[inline, static]`

Checks if a command succeeded.

As CmdFailed this function checks if a command succeeded

Parameters:

  | cost | The return value of a CommandProc call

Returns:
  true if the command succeeded

See also:
  CmdSucceeded

Definition at line 32 of file command_func.h.

References CommandCost::Succeeded().

Referenced by CanBuildHouseHere(), CanBuildTramTrackOnTile(), ClearMakeHouseTile(), CmdCloneVehicle(), CmdDepotMassAutoReplace(), CmdDepotSellAllVehicles(), CmdMassStartStopVehicle(), CmdRemoveLongRoad(), CmdRemoveRoadStop(), CmdSignalTrackHelper(), DoDryUp(), DoFloodTile(), AIVehicle::GetRefitCapacity(), GrowTown(), GrowTownWithBridge(), GrowTownWithRoad(), and SendAllVehiclesToDepot().

static DoCommandFlag CommandFlagsToDCFlags | ( | uint | cmd_flags | ) | `[inline, static]`

Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.

Parameters:

  | cmd_flags | Flags from GetCommandFlags

Returns:
  flags for DoCommand

Definition at line 94 of file command_func.h.

References CMD_ALL_TILES, CMD_AUTO, CMD_NO_WATER, DC_ALL_TILES, DC_AUTO, DC_NO_WATER, and DC_NONE.

Referenced by AIObject::DoCommand(), DoCommandP(), and StationJoinerNeeded().

CommandCost DoCommand | ( | const CommandContainer * | container,
|  | DoCommandFlag | flags |
| ) |  |  |

Shorthand for calling the long DoCommand with a container.

Parameters:

  | container | Container with (almost) all information
  | flags | Flags for the command and how to execute the command

See also:
  CommandProc

Returns:
  the cost

Definition at line 379 of file command.cpp.

References CommandContainer::cmd, CMD_ID_MASK, DoCommand(), CommandContainer::p1, CommandContainer::p2, CommandContainer::text, and CommandContainer::tile.

Referenced by BuildReplacementVehicle(), CanBuildHouseHere(), CanBuildTramTrackOnTile(), CheckFlatLandBelow(), CheckIfCanLevelIndustryPlatform(), CheckSendAircraftToHangarForReplacement(), ClearMakeHouseTile(), CmdBuildBridge(), CmdBuildCanal(), CmdBuildDock(), CmdBuildLongRoad(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildShipDepot(), CmdBuildSingleRail(), CmdBuildTrainDepot(), CmdBuildTunnel(), CmdClearArea(), CmdCloneVehicle(), CmdDepotMassAutoReplace(), CmdDepotSellAllVehicles(), CmdLevelLand(), CmdMassStartStopVehicle(), CmdPlantTree(), CmdPurchaseLandArea(), CmdRailTrackHelper(), CmdRemoveLongRoad(), CmdRemoveSingleRail(), CmdRenamePresident(), CmdSellRailWagon(), CmdSignalTrackHelper(), CopyHeadSpecificThings(), DoBuildShiplift(), DoCommand(), DoDryUp(), DoFloodTile(), FloodHalftile(), GrowTown(), GrowTownWithBridge(), GrowTownWithRoad(), IsRoadAllowedHere(), MoveVehicle(), NormalizeTrainVehInDepot(), BuildRailToolbarWindow::OnPlacePresize(), RemoveRoad(), ReplaceChain(), ReplaceFreeUnit(), SearchLumberMillTrees(), SendAllVehiclesToDepot(), ShowBuildBridgeWindow(), StartStopVehicle(), StationJoinerNeeded(), and UpdateOrderDest().

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

Execute a command.

This function executes a given command with the parameters from the CommandProc parameter list. Depending on the flags parameter it execute or test a command.

Parameters:

  | tile | The tile to apply the command on (for the CommandProc)
  | p1 | Additional data for the command (for the CommandProc)
  | p2 | Additional data for the command (for the CommandProc)
  | flags | Flags for the command and how to execute the command
  | cmd | The command-id to execute (a value of the CMD_* enums)

See also:
  CommandProc

Returns:
  the cost

Definition at line 396 of file command.cpp.

References CMD_ERROR, CmdFailed(), DC_ALL_TILES, DC_BANKRUPT, DC_EXEC, DC_QUERY_COST, error, CommandCost::GetCost(), INVALID_STRING_ID, IsValidTile(), MapSize(), Command::proc, and CommandCost::SetGlobalErrorMessage().

bool DoCommandP | ( | const CommandContainer * | container,
|  | bool | my_cmd |
| ) |  |  |

Shortcut for the long DoCommandP when having a container with the data.

Parameters:

  | container | the container with information.
  | my_cmd | indicator if the command is from a company or server (to display error messages for a user)

Returns:
  true if the command succeeded, else false

Definition at line 471 of file command.cpp.

References CommandContainer::callback, CommandContainer::cmd, DoCommandP(), CommandContainer::p1, CommandContainer::p2, CommandContainer::text, and CommandContainer::tile.

Referenced by _GenerateWorld(), AskUnsafeUnpauseCallback(), CommonRaiseLowerBigLand(), AIObject::DoCommand(), DoCommandP(), GenerateDesertArea(), GenericPlaceSignals(), GUIPlaceProcDragXY(), HandleAutoSignalPlacement(), VehicleListWindow::OnClick(), CompanyWindow::OnClick(), ReplaceVehicleWindow::OnClick(), VehicleListWindow::OnDropdownSelect(), BuildRailToolbarWindow::OnPlaceMouseUp(), CompanyWindow::OnPlaceObject(), StationViewWindow::OnQueryTextFinished(), CompanyWindow::OnQueryTextFinished(), PlaceExtraDepotRail(), PlaceProc_Sign(), RenameSign(), RestoreVehicleOrders(), SetSettingValue(), ShowBuildBridgeWindow(), ShowSelectStationIfNeeded(), and StartScenario().

bool DoCommandP | ( | TileIndex | tile,
|  | uint32 | p1,
|  | uint32 | p2,
|  | uint32 | cmd,
|  | CommandCallback * | callback,
|  | const char * | text,
|  | bool | my_cmd |
| ) |  |  |

Execute a network safe DoCommand function.

Toplevel network safe docommand function for the current company. Must not be called recursively. The callback is called when the command succeeded or failed. The parameters tile, p1 and p2 are from the CommandProc function. The paramater cmd is the command to execute. The parameter my_cmd is used to indicate if the command is from a company or the server.

Parameters:

  | tile | The tile to perform a command on (see CommandProc)
  | p1 | Additional data for the command (see CommandProc)
  | p2 | Additional data for the command (see CommandProc)
  | cmd | The command to execute (a CMD_* value)
  | callback | A callback function to call after the command is finished
  | text | The text to pass
  | my_cmd | indicator if the command is from a company or server (to display error messages for a user)

Returns:
  true if the command succeeded, else false

Spectator has no rights except for the (dedicated) server which is/can be a spectator but as the server it can do anything

Definition at line 491 of file command.cpp.

References _date, _shift_pressed, ClearStorageChanges(), CMD_ALL_TILES, CMD_COMPANY_CTRL, CMD_FLAGS_MASK, CMD_ID_MASK, CMD_NETWORK_COMMAND, CMD_NO_TEST, CMD_NO_TEST_IF_IN_NETWORK, CMD_PAUSE, CMD_SERVER, CMD_SPECTATOR, CmdFailed(), CommandFlagsToDCFlags(), COMPANY_FIRST, COMPANY_SPECTATOR, DC_EXEC, GB(), GetCommandFlags(), CommandCost::GetCost(), INVALID_STRING_ID, IsGeneratingWorld(), IsValidTile(), lengthof, MapSize(), Command::proc, CommandCost::SetGlobalErrorMessage(), TILE_SIZE, TileX(), TileY(), and UpdateSignalsInBuffer().

Money GetAvailableMoneyForCommand | ( |  | ) |

Returns the current money available which can be used for a command.

This functions returns the money which can be used to execute a command. This is either the money of the current company or INT64_MAX if there is no such a company "at the moment" like the server itself.

Returns:
  The available money of a company or INT64_MAX

Definition at line 458 of file command.cpp.

Referenced by CmdClearArea(), CmdLevelLand(), and CmdRemoveLongRoad().

byte GetCommandFlags | ( | uint32 | cmd | ) |

Returns the flags from a given command.

This function mask the parameter with CMD_ID_MASK and returns the flags which belongs to the given command.

Parameters:

  | cmd | The integer value of the command

Returns:
  The flags for this command

Definition at line 362 of file command.cpp.

References CMD_ID_MASK, Command::flags, and IsValidCommand().

Referenced by AIObject::DoCommand(), DoCommandP(), and StationJoinerNeeded().

bool IsValidCommand | ( | uint32 | cmd | ) |

Checks if a integer value belongs to a command.

This function range-checks a cmd, and checks if the cmd is not NULL

Parameters:

  | cmd | The integervalue of a command

Returns:
  true if the command is valid (and got a CommandProc function)

Definition at line 346 of file command.cpp.

References CMD_ID_MASK, lengthof, and Command::proc.

Referenced by GetCommandFlags().

## Variable Documentation

const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID)`[static]`

Define a default return value for a failed command.

This variable contains a CommandCost object with is declared as "failed". Other functions just need to return this error if there is an error, which doesn't need to specific by a StringID.

Definition at line 41 of file command_func.h.

Referenced by AddEngineReplacement(), CheckBridgeSlopeNorth(), CheckBridgeSlopeSouth(), CheckFlatLandBelow(), CheckRoadSlope(), CmdAddSharedVehicleGroup(), CmdAddVehicleGroup(), CmdAutofillTimetable(), CmdAutoreplaceVehicle(), CmdBuildAircraft(), CmdBuildAirport(), CmdBuildBridge(), CmdBuildCanal(), CmdBuildDock(), CmdBuildIndustry(), CmdBuildLongRoad(), CmdBuildRailroadStation(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildRoadStop(), CmdBuildRoadVeh(), CmdBuildShip(), CmdBuildShipDepot(), CmdBuildSingleRail(), CmdBuildSingleSignal(), CmdBuildTown(), CmdBuildTrainDepot(), CmdBuildTrainWaypoint(), CmdBuildTunnel(), CmdBuyCompany(), CmdBuyShareInCompany(), CmdChangeServiceInt(), CmdChangeSetting(), CmdChangeTimetable(), CmdClearArea(), CmdCloneOrder(), CmdCloneVehicle(), CmdCompanyCtrl(), CmdConvertRail(), CmdCreateGroup(), CmdDecreaseLoan(), CmdDeleteGroup(), CmdDeleteOrder(), CmdDepotMassAutoReplace(), CmdDepotSellAllVehicles(), CmdDoTownAction(), CmdForceTrainProceed(), CmdGiveMoney(), CmdIncreaseLoan(), CmdInsertOrder(), CmdLevelLand(), CmdMassStartStopVehicle(), CmdModifyOrder(), CmdMoneyCheat(), CmdMoveOrder(), CmdMoveRailVehicle(), CmdOrderRefit(), CmdPlaceSign(), CmdPlantTree(), CmdPurchaseLandArea(), CmdRailTrackHelper(), CmdRefitAircraft(), CmdRefitRailVehicle(), CmdRefitRoadVeh(), CmdRefitShip(), CmdRemoveAllVehiclesGroup(), CmdRemoveFromRailroadStation(), CmdRemoveLongRoad(), CmdRemoveRoad(), CmdRemoveRoadStop(), CmdRemoveSingleRail(), CmdRemoveSingleSignal(), CmdRenameCompany(), CmdRenameEngine(), CmdRenameGroup(), CmdRenamePresident(), CmdRenameSign(), CmdRenameStation(), CmdRenameTown(), CmdRenameVehicle(), CmdRenameWaypoint(), CmdRestoreOrderIndex(), CmdReverseTrainDirection(), CmdSellAircraft(), CmdSellLandArea(), CmdSellRailWagon(), CmdSellRoadVeh(), CmdSellShareInCompany(), CmdSellShip(), CmdSendAircraftToHangar(), CmdSendRoadVehToDepot(), CmdSendShipToDepot(), CmdSendTrainToDepot(), CmdSetAutoReplace(), CmdSetCompanyColour(), CmdSetCompanyManagerFace(), CmdSetGroupReplaceProtection(), CmdSetVehicleOnTime(), CmdSignalTrackHelper(), CmdSkipToOrder(), CmdStartStopVehicle(), CmdTurnRoadVeh(), CmdWantEnginePreview(), DoBuildShiplift(), DoCommand(), AIObject::DoCommand(), IsRoadAllowedHere(), RemoveEngineReplacement(), RemoveRoad(), RemoveRoadStop(), RemoveTrainWaypoint(), SendAllVehiclesToDepot(), TerraformTileHeight(), and TestAutoslopeOnRailTile().