OpenTTD Source  12.0-beta2
command_func.h File Reference
#include "command_type.h"
#include "company_type.h"

Go to the source code of this file.

Macros

#define return_cmd_error(errcode)   return CommandCost(errcode);
 Returns from a function with a specific StringID as error. More...
 

Functions

CommandCost DoCommand (TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const std::string &text={})
 
CommandCost DoCommand (const CommandContainer *container, DoCommandFlag flags)
 Shorthand for calling the long DoCommand with a container. More...
 
bool DoCommandP (TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback=nullptr, const std::string &text={}, bool my_cmd=true)
 
bool DoCommandP (const CommandContainer *container, bool my_cmd=true)
 Shortcut for the long DoCommandP when having a container with the data. More...
 
CommandCost DoCommandPInternal (TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const std::string &text, bool my_cmd, bool estimate_only)
 
void NetworkSendCommand (TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const std::string &text, CompanyID company)
 Prepare a DoCommand to be send over the network. More...
 
bool IsValidCommand (uint32 cmd)
 
CommandFlags GetCommandFlags (uint32 cmd)
 
const char * GetCommandName (uint32 cmd)
 
Money GetAvailableMoneyForCommand ()
 
bool IsCommandAllowedWhilePaused (uint32 cmd)
 Returns whether the command is allowed while the game is paused. More...
 
static DoCommandFlag CommandFlagsToDCFlags (CommandFlags cmd_flags)
 Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags. More...
 

Variables

static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID)
 Define a default return value for a failed command. More...
 
Money _additional_cash_required
 
CommandCallback CcAI
 
CommandCallback CcBuildAirport
 
CommandCallback CcBuildBridge
 
CommandCallback CcBuildDocks
 
CommandCallback CcPlaySound_CONSTRUCTION_WATER
 
CommandCallback CcCloneVehicle
 
CommandCallback CcGame
 
CommandCallback CcCreateGroup
 
CommandCallback CcAddVehicleNewGroup
 
CommandCallback CcBuildIndustry
 
CommandCallback CcPlaySound_EXPLOSION
 
CommandCallback CcPlaceSign
 
CommandCallback CcTerraform
 
CommandCallback CcPlaySound_CONSTRUCTION_RAIL
 
CommandCallback CcRailDepot
 
CommandCallback CcStation
 
CommandCallback CcBuildRailTunnel
 
CommandCallback CcPlaySound_CONSTRUCTION_OTHER
 
CommandCallback CcBuildRoadTunnel
 
CommandCallback CcRoadDepot
 
CommandCallback CcRoadStop
 
CommandCallback CcBuildWagon
 
CommandCallback CcFoundTown
 
CommandCallback CcFoundRandomTown
 
CommandCallback CcBuildPrimaryVehicle
 
CommandCallback CcStartStopVehicle
 

Detailed Description

Functions related to commands.

Definition in file command_func.h.

Macro Definition Documentation

◆ return_cmd_error

#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
errcodeThe StringID to return

Definition at line 33 of file command_func.h.

Function Documentation

◆ CommandFlagsToDCFlags()

static DoCommandFlag CommandFlagsToDCFlags ( CommandFlags  cmd_flags)
inlinestatic

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

Parameters
cmd_flagsFlags from GetCommandFlags
Returns
flags for DoCommand

Definition at line 58 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 ShowBuildBridgeWindow(), and StationJoinerNeeded().

◆ DoCommand() [1/2]

◆ DoCommand() [2/2]

CommandCost DoCommand ( TileIndex  tile,
uint32  p1,
uint32  p2,
DoCommandFlag  flags,
uint32  cmd,
const std::string &  text 
)

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
tileThe tile to apply the command on (for the CommandProc)
p1Additional data for the command (for the CommandProc)
p2Additional data for the command (for the CommandProc)
flagsFlags for the command and how to execute the command
cmdThe command-id to execute (a value of the CMD_* enums)
textThe text to pass
See also
CommandProc
Returns
the cost

Definition at line 468 of file command.cpp.

References _command_proc_table, CMD_ERROR, CMD_ID_MASK, DC_ALL_TILES, IsValidTile(), MapSize(), and Command::proc.

◆ DoCommandP() [1/2]

bool DoCommandP ( const CommandContainer container,
bool  my_cmd 
)

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

Parameters
containerthe container with information.
my_cmdindicator 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 541 of file command.cpp.

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

Referenced by AdminCompanyResetCallback(), AskUnsafeUnpauseCallback(), CcBuildWagon(), ChangeTimetableStartCallback(), CheckPauseHelper(), CheckTrainsLengths(), ClickMoneyCheat(), EndGameWindow::Close(), DoCommandP(), GUIPlaceProcDragXY(), MaybeStartNewCompany(), NetworkAutoCleanCompanies(), NetworkExecuteLocalCommandQueue(), EnginePreviewWindow::OnClick(), GoalQuestionWindow::OnClick(), CompanyFinancesWindow::OnClick(), AIDebugWindow::OnClick(), BuildVehicleWindow::OnClick(), SelectCompanyManagerFaceWindow::OnClick(), StationViewWindow::OnClick(), VehicleDetailsWindow::OnClick(), BuyCompanyWindow::OnClick(), VehicleViewWindow::OnClick(), NetworkClientListWindow::OnClickCompanyNew(), DepotWindow::OnDragDrop(), OrdersWindow::OnDragDrop(), VehicleGroupWindow::OnDropdownSelect(), VehicleListWindow::OnDropdownSelect(), VehicleDetailsWindow::OnDropdownSelect(), AIDebugWindow::OnInvalidateData(), StoryBookWindow::OnPageElementClick(), BuildDocksToolbarWindow::OnPlaceMouseUp(), TerraformToolbarWindow::OnPlaceObject(), BuildObjectWindow::OnPlaceObject(), BuildRailToolbarWindow::OnPlaceObject(), StoryBookWindow::OnPlaceObject(), CompanyWindow::OnPlaceObject(), WaypointWindow::OnQueryTextFinished(), TownViewWindow::OnQueryTextFinished(), DepotWindow::OnQueryTextFinished(), VehicleGroupWindow::OnQueryTextFinished(), OrdersWindow::OnQueryTextFinished(), BuildVehicleWindow::OnQueryTextFinished(), StationViewWindow::OnQueryTextFinished(), VehicleViewWindow::OnQueryTextFinished(), DepotWindow::OnVehicleSelect(), OrdersWindow::OrderClick_Delete(), OrdersWindow::OrderClick_FullLoad(), OrdersWindow::OrderClick_NearestDepot(), OrdersWindow::OrderClick_Nonstop(), OrdersWindow::OrderClick_Refit(), OrdersWindow::OrderClick_Service(), OrdersWindow::OrderClick_Skip(), OrdersWindow::OrderClick_StopSharing(), OrdersWindow::OrderClick_Unload(), PlaceExtraDepotRail(), PlaceProc_Sign(), RenameSign(), ReplaceVehicleWindow::ReplaceClick_StartReplace(), OrderBackup::ResetUser(), ShowBuildBridgeWindow(), StartStopVehicle(), and StateGameLoop_LinkGraphPauseControl().

◆ DoCommandP() [2/2]

bool DoCommandP ( TileIndex  tile,
uint32  p1,
uint32  p2,
uint32  cmd,
CommandCallback callback,
const std::string &  text,
bool  my_cmd 
)

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 parameter 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
tileThe tile to perform a command on (see CommandProc)
p1Additional data for the command (see CommandProc)
p2Additional data for the command (see CommandProc)
cmdThe command to execute (a CMD_* value)
callbackA callback function to call after the command is finished
textThe text to pass
my_cmdindicator 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 561 of file command.cpp.

References _generating_world, _networking, _shift_pressed, CMD_NETWORK_COMMAND, CMD_NO_EST, GetCommandFlags(), and IsLocalCompany().

◆ DoCommandPInternal()

CommandCost DoCommandPInternal ( TileIndex  tile,
uint32  p1,
uint32  p2,
uint32  cmd,
CommandCallback callback,
const std::string &  text,
bool  my_cmd,
bool  estimate_only 
)

Helper function for the toplevel network safe docommand function for the current company.

Parameters
tileThe tile to perform a command on (see CommandProc)
p1Additional data for the command (see CommandProc)
p2Additional data for the command (see CommandProc)
cmdThe command to execute (a CMD_* value)
callbackA callback function to call after the command is finished
textThe text to pass
my_cmdindicator if the command is from a company or server (to display error messages for a user)
estimate_onlywhether to give only the estimate or also execute the command
Returns
the command cost of this function.

Definition at line 634 of file command.cpp.

Referenced by OrderBackup::Reset().

◆ GetAvailableMoneyForCommand()

Money GetAvailableMoneyForCommand ( )

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

References _current_company, and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID().

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

◆ GetCommandFlags()

CommandFlags GetCommandFlags ( uint32  cmd)

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

Parameters
cmdThe integer value of the command
Returns
The flags for this command

Definition at line 393 of file command.cpp.

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

Referenced by DoCommandP(), ShowBuildBridgeWindow(), and StationJoinerNeeded().

◆ GetCommandName()

const char* GetCommandName ( uint32  cmd)

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

Parameters
cmdThe integer value of the command
Returns
The name for this command

Definition at line 407 of file command.cpp.

References _command_proc_table, CMD_ID_MASK, IsValidCommand(), and Command::name.

Referenced by ServerNetworkAdminSocketHandler::SendCmdNames().

◆ IsCommandAllowedWhilePaused()

bool IsCommandAllowedWhilePaused ( uint32  cmd)

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

Parameters
cmdThe 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 419 of file command.cpp.

References CMDPL_ALL_ACTIONS, CMDPL_NO_ACTIONS, CMDPL_NO_CONSTRUCTION, CMDPL_NO_LANDSCAPING, CMDT_END, IsValidCommand(), and lengthof.

Referenced by CommandQueue::Peek(), and CommandQueue::Pop().

◆ IsValidCommand()

bool IsValidCommand ( uint32  cmd)

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

Parameters
cmdThe integer value of a command
Returns
true if the command is valid (and got a CommandProc function)

Definition at line 379 of file command.cpp.

References _command_proc_table, CMD_ID_MASK, lengthof, and Command::proc.

Referenced by GetCommandFlags(), GetCommandName(), and IsCommandAllowedWhilePaused().

◆ NetworkSendCommand()

void NetworkSendCommand ( TileIndex  tile,
uint32  p1,
uint32  p2,
uint32  cmd,
CommandCallback callback,
const std::string &  text,
CompanyID  company 
)

Prepare a DoCommand to be send over the network.

Parameters
tileThe tile to perform a command on (see CommandProc)
p1Additional data for the command (see CommandProc)
p2Additional data for the command (see CommandProc)
cmdThe command to execute (a CMD_* value)
callbackA callback function to call after the command is finished
textThe text to pass
companyThe company that wants to send the command

Definition at line 136 of file network_command.cpp.

References _frame_counter_max, _local_wait_queue, _network_server, CommandQueue::Append(), CommandContainer::callback, CommandContainer::cmd, CMD_FLAGS_MASK, CommandPacket::company, CommandPacket::frame, CommandPacket::my_cmd, CommandContainer::p1, CommandContainer::p2, ClientNetworkGameSocketHandler::SendCommand(), CommandContainer::text, and CommandContainer::tile.

Referenced by NetworkServerNewCompany(), and NetworkClientListWindow::OnClickCompanyNew().

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

Referenced by AddEngineReplacement(), BuildStationPart(), CheckBridgeAvailability(), CheckRoadSlope(), CmdAddSharedVehicleGroup(), CmdAlterGroup(), CmdAutofillTimetable(), CmdAutoreplaceVehicle(), CmdBuildAircraft(), CmdBuildBridge(), CmdBuildCanal(), CmdBuildIndustry(), CmdBuildLongRoad(), CmdBuildObject(), CmdBuildRailStation(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRailWaypoint(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildRoadStop(), CmdBuildShipDepot(), CmdBuildTrainDepot(), CmdBuildTunnel(), CmdBuildVehicle(), CmdChangeCompanySetting(), CmdChangeServiceInt(), CmdChangeSetting(), CmdChangeTimetable(), CmdClearArea(), CmdCloneOrder(), CmdCloneVehicle(), CmdConvertRail(), CmdConvertRoad(), CmdCreateGoal(), CmdCreateGroup(), CmdCreateStoryPage(), CmdCreateStoryPageElement(), CmdCreateSubsidy(), CmdCustomNewsItem(), CmdDecreaseLoan(), CmdDeleteGroup(), CmdDeleteOrder(), CmdDepotMassAutoReplace(), CmdDepotSellAllVehicles(), CmdEngineCtrl(), CmdForceTrainProceed(), CmdFoundTown(), CmdGiveMoney(), CmdIndustryCtrl(), CmdInsertOrder(), CmdLevelLand(), CmdMassStartStopVehicle(), CmdMoveOrder(), CmdMoveRailVehicle(), CmdOpenCloseAirport(), CmdOrderRefit(), CmdPause(), CmdPlaceSign(), CmdPlantTree(), CmdRefitVehicle(), CmdRemoveAllVehiclesGroup(), CmdRemoveFromRailStation(), CmdRemoveFromRailWaypoint(), CmdRemoveGoal(), CmdRemoveLongRoad(), CmdRemoveStoryPage(), CmdRemoveStoryPageElement(), CmdRenameCompany(), CmdRenameDepot(), CmdRenameEngine(), CmdRenamePresident(), CmdRenameSign(), CmdRenameStation(), CmdRenameTown(), CmdRenameVehicle(), CmdRenameWaypoint(), CmdReverseTrainDirection(), CmdScrollViewport(), CmdSellVehicle(), CmdSendVehicleToDepot(), CmdSetAutoReplace(), CmdSetCompanyManagerFace(), CmdSetGoalCompleted(), CmdSetGoalProgress(), CmdSetGoalText(), CmdSetGroupFlag(), CmdSetGroupLivery(), CmdSetStoryPageDate(), CmdSetStoryPageTitle(), CmdSetTimetableStart(), CmdSetVehicleOnTime(), CmdSetVehicleVisibility(), CmdShowStoryPage(), CmdSkipToOrder(), CmdStartStopVehicle(), CmdStoryPageButton(), CmdTownCargoGoal(), CmdTownGrowthRate(), CmdTownRating(), CmdTownSetText(), CmdTurnRoadVeh(), CmdUpdateStoryPageElement(), CmdWantEnginePreview(), DoCommand(), RemoveDock(), RemoveEngineReplacement(), SendAllVehiclesToDepot(), Vehicle::SendToDepot(), and TerraformTileHeight().