OpenTTD Source: src/command_func.h File Reference

OpenTTD Source 15.0-beta1

Data Structures | Typedefs | Functions | Variables
command_func.h File Reference

Functions related to commands. More...

`#include "command_type.h"`
`#include "network/network_type.h"`
`#include "company_type.h"`
`#include "company_func.h"`
`#include "core/backup_type.hpp"`
`#include "misc/endian_buffer.hpp"`
`#include "tile_map.h"`

Go to the source code of this file.

## Data Structures
struct | RecursiveCommandCounter
| Helper class to keep track of command nesting level. More...
class | CommandHelperBase
struct | CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >
| Templated wrapper that exposes the command parameter arguments for the various Command::Do/Post calls. More...
struct | CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), false >
| Overload for CommandHelper that exposes additional `Post` variants for commands that don't take a TileIndex themselves. More...

## Typedefs
template<Commands Tcmd>
using | Command = CommandHelper< Tcmd, typename CommandTraits< Tcmd >::ProcType,(GetCommandFlags< Tcmd >() &CMD_LOCATION)==0 >

## Functions
void | NetworkSendCommand (Commands cmd, StringID err_message, CommandCallback *callback, CompanyID company, const CommandDataBuffer &cmd_data)
| Prepare a DoCommand to be send over the network.
bool | IsValidCommand (Commands cmd)
| This function range-checks a cmd.
CommandFlags | GetCommandFlags (Commands cmd)
| This function mask the parameter with CMD_ID_MASK and returns the flags which belongs to the given command.
const char * | GetCommandName (Commands cmd)
| This function mask the parameter with CMD_ID_MASK and returns the name which belongs to the given command.
bool | IsCommandAllowedWhilePaused (Commands cmd)
| Returns whether the command is allowed while the game is paused.
template<Commands Tcmd>
constexpr CommandFlags | GetCommandFlags ()
static constexpr DoCommandFlag | CommandFlagsToDCFlags (CommandFlags 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.

## Detailed Description

Functions related to commands.

Definition in file command_func.h.

## Typedef Documentation

## ◆ Command

template<Commands Tcmd>

using Command = CommandHelper<Tcmd, typename CommandTraits<Tcmd>::ProcType, (GetCommandFlags<Tcmd>() & CMD_LOCATION) == 0>

Definition at line 476 of file command_func.h.

## Function Documentation

## ◆ CommandFlagsToDCFlags()

static constexpr DoCommandFlag CommandFlagsToDCFlags | ( | CommandFlags | cmd_flags | ) |
| inlinestaticconstexpr

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 48 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 GrowTownWithBridge(), GrowTownWithTunnel(), BuildRailToolbarWindow::OnPlaceMouseUp(), BuildRoadToolbarWindow::OnPlaceMouseUp(), BuildDocksToolbarWindow::OnPlaceObject(), PlaceAirport(), PlaceRail_Station(), PlaceRoadStop(), and ShowBuildBridgeWindow().

## ◆ GetCommandFlags() [1/2]

template<Commands Tcmd>

constexpr CommandFlags GetCommandFlags | ( |  | ) |
| constexpr

Definition at line 38 of file command_func.h.

## ◆ GetCommandFlags() [2/2]

CommandFlags GetCommandFlags | ( | Commands | cmd | ) |

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 118 of file command.cpp.

References _command_proc_table, GetCommandFlags(), and IsValidCommand().

Referenced by GetCommandFlags(), ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(), and NetworkGameSocketHandler::ReceiveCommand().

## ◆ GetCommandName()

const char * GetCommandName | ( | Commands | cmd | ) |

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

Parameters

  cmd | The integer value of the command

Returns
  The name for this command

Definition at line 132 of file command.cpp.

References _command_proc_table, and IsValidCommand().

Referenced by CommandHelperBase::LogCommandExecution(), and ServerNetworkAdminSocketHandler::SendCmdNames().

## ◆ IsCommandAllowedWhilePaused()

bool IsCommandAllowedWhilePaused | ( | Commands | cmd | ) |

Returns whether the command is allowed while the game is paused.

Parameters

  cmd | The command to check.

Returns
  True if the command is allowed while paused, false otherwise.

< CMDT_LANDSCAPE_CONSTRUCTION

< CMDT_VEHICLE_CONSTRUCTION

< CMDT_MONEY_MANAGEMENT

< CMDT_VEHICLE_MANAGEMENT

< CMDT_ROUTE_MANAGEMENT

< CMDT_OTHER_MANAGEMENT

< CMDT_COMPANY_SETTING

< CMDT_SERVER_SETTING

< CMDT_CHEAT

Definition at line 144 of file command.cpp.

References _command_proc_table, _settings_game, CMDPL_ALL_ACTIONS, CMDPL_NO_ACTIONS, CMDPL_NO_CONSTRUCTION, CMDPL_NO_LANDSCAPING, CMDT_END, ConstructionSettings::command_pause_level, GameSettings::construction, IsValidCommand(), and lengthof.

Referenced by DistributeQueue(), and CommandHelperBase::InternalPostBefore().

## ◆ IsValidCommand()

bool IsValidCommand | ( | Commands | cmd | ) |

This function range-checks a cmd.

Parameters

  cmd | The integer value of a command

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

Definition at line 106 of file command.cpp.

References _command_proc_table.

Referenced by GetCommandFlags(), GetCommandName(), IsCommandAllowedWhilePaused(), and NetworkGameSocketHandler::ReceiveCommand().

## ◆ NetworkSendCommand()

void NetworkSendCommand | ( | Commands | cmd,
|  | StringID | err_message,
|  | CommandCallback * | callback,
|  | CompanyID | company,
|  | const CommandDataBuffer & | cmd_data
| ) |  |

Prepare a DoCommand to be send over the network.

Parameters

  cmd | The command to execute (a CMD_* value)
  err_message | Message prefix to show on error
  callback | A callback function to call after the command is finished
  company | The company that wants to send the command
  cmd_data | The command proc arguments.

Definition at line 196 of file network_command.cpp.

References _frame_counter_max, _local_wait_queue, _network_server, CommandPacket::callback, CommandPacket::cmd, CommandPacket::company, CommandPacket::data, CommandPacket::err_msg, CommandPacket::frame, CommandPacket::my_cmd, and ClientNetworkGameSocketHandler::SendCommand().

Referenced by CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::SendNet().

## Variable Documentation

## ◆ CMD_ERROR

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 28 of file command_func.h.

Referenced by AddEngineReplacement(), BuildStationPart(), CheckBridgeAvailability(), CheckBridgeSlope(), CheckRoadSlope(), ClearTile_Station(), ClearTile_Town(), CmdAddSharedVehicleGroup(), CmdAddVehicleGroup(), CmdAlterGroup(), CmdAutofillTimetable(), CmdAutoreplaceVehicle(), CmdBuildAircraft(), CmdBuildAirport(), CmdBuildBridge(), CmdBuildCanal(), CmdBuildDock(), CmdBuildIndustry(), CmdBuildLongRoad(), CmdBuildObject(), CmdBuildObjectArea(), CmdBuildRailStation(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRailWaypoint(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildRoadStop(), CmdBuildRoadWaypoint(), CmdBuildShipDepot(), CmdBuildSingleRail(), CmdBuildSingleSignal(), CmdBuildTrainDepot(), CmdBuildTunnel(), CmdBuildVehicle(), CmdBulkChangeTimetable(), CmdBuyCompany(), CmdChangeBankBalance(), CmdChangeCompanySetting(), CmdChangeServiceInt(), CmdChangeSetting(), CmdChangeTimetable(), CmdClearArea(), CmdCloneOrder(), CmdCloneVehicle(), CmdCompanyAllowListCtrl(), CmdCompanyCtrl(), CmdConvertRail(), CmdConvertRoad(), CmdCreateGoal(), CmdCreateGroup(), CmdCreateLeagueTable(), CmdCreateLeagueTableElement(), CmdCreateStoryPage(), CmdCreateStoryPageElement(), CmdCreateSubsidy(), CmdCustomNewsItem(), CmdDecreaseLoan(), CmdDeleteGroup(), CmdDeleteOrder(), CmdDeleteTown(), CmdDepotMassAutoReplace(), CmdDepotSellAllVehicles(), CmdDoTownAction(), CmdEngineCtrl(), CmdExpandTown(), CmdForceTrainProceed(), CmdFoundTown(), CmdGiveMoney(), CmdGoalQuestion(), CmdGoalQuestionAnswer(), CmdIncreaseLoan(), CmdIndustrySetExclusivity(), CmdIndustrySetFlags(), CmdIndustrySetProduction(), CmdIndustrySetText(), CmdInsertOrder(), CmdLevelLand(), CmdMassStartStopVehicle(), CmdModifyOrder(), CmdMoveOrder(), CmdMoveRailVehicle(), CmdOpenCloseAirport(), CmdOrderRefit(), CmdPause(), CmdPlaceSign(), CmdPlantTree(), CmdRailTrackHelper(), CmdRefitVehicle(), CmdRemoveAllVehiclesGroup(), CmdRemoveFromRailStation(), CmdRemoveFromRailWaypoint(), CmdRemoveFromRoadWaypoint(), CmdRemoveGoal(), CmdRemoveLeagueTableElement(), CmdRemoveLongRoad(), CmdRemoveRoadStop(), CmdRemoveSingleRail(), CmdRemoveStoryPage(), CmdRemoveStoryPageElement(), CmdRenameCompany(), CmdRenameDepot(), CmdRenameEngine(), CmdRenamePresident(), CmdRenameSign(), CmdRenameStation(), CmdRenameTown(), CmdRenameVehicle(), CmdRenameWaypoint(), CmdReverseTrainDirection(), CmdScrollViewport(), CmdSellVehicle(), CmdSendVehicleToDepot(), CmdSetAutoReplace(), CmdSetCompanyColour(), CmdSetCompanyManagerFace(), CmdSetCompanyMaxLoan(), CmdSetGoalCompleted(), CmdSetGoalDestination(), CmdSetGoalProgress(), CmdSetGoalText(), CmdSetGroupFlag(), CmdSetGroupLivery(), CmdSetStoryPageDate(), CmdSetStoryPageTitle(), CmdSetTimetableStart(), CmdSetVehicleOnTime(), CmdSetVehicleVisibility(), CmdShowStoryPage(), CmdSignalTrackHelper(), CmdSkipToOrder(), CmdStartStopVehicle(), CmdStoryPageButton(), CmdTownCargoGoal(), CmdTownGrowthRate(), CmdTownRating(), CmdTownSetText(), CmdTurnRoadVeh(), CmdUpdateLeagueTableElementData(), CmdUpdateLeagueTableElementScore(), CmdUpdateStoryPageElement(), CmdWantEnginePreview(), CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::Do(), IsRoadAllowedHere(), RemoveDock(), RemoveEngineReplacement(), RemoveRoad(), SendAllVehiclesToDepot(), Vehicle::SendToDepot(), TerraformTileHeight(), TownActionBuyRights(), TownActionFundBuildings(), and TownActionRoadRebuild().