OpenTTD Source  20241108-master-g80f628063a
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...
 

Macros

#define return_cmd_error(errcode)   return CommandCost(errcode);
 Returns from a function with a specific StringID as error. 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. More...
 
bool IsValidCommand (Commands cmd)
 This function range-checks a cmd. More...
 
CommandFlags GetCommandFlags (Commands cmd)
 This function mask the parameter with CMD_ID_MASK and returns the flags which belongs to the given command. More...
 
const char * GetCommandName (Commands cmd)
 This function mask the parameter with CMD_ID_MASK and returns the name which belongs to the given command. More...
 
bool IsCommandAllowedWhilePaused (Commands cmd)
 Returns whether the command is allowed while the game is paused. More...
 
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. More...
 

Variables

static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID)
 Define a default return value for a failed command. More...
 

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 38 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_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 GrowTownWithBridge(), GrowTownWithTunnel(), PlaceAirport(), and ShowBuildBridgeWindow().

◆ GetCommandFlags()

CommandFlags GetCommandFlags ( Commands  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 118 of file command.cpp.

References _command_proc_table, and IsValidCommand().

◆ 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
cmdThe 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().

◆ IsCommandAllowedWhilePaused()

bool IsCommandAllowedWhilePaused ( Commands  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 144 of file command.cpp.

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

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

◆ IsValidCommand()

bool IsValidCommand ( Commands  cmd)

This function range-checks a cmd.

Parameters
cmdThe 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(), and IsCommandAllowedWhilePaused().

◆ 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
cmdThe command to execute (a CMD_* value)
err_messageMessage prefix to show on error
callbackA callback function to call after the command is finished
companyThe company that wants to send the command
cmd_dataThe 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(), CheckRoadSlope(), CmdAddSharedVehicleGroup(), CmdAlterGroup(), CmdAutofillTimetable(), CmdAutoreplaceVehicle(), CmdBuildAircraft(), CmdBuildBridge(), CmdBuildCanal(), CmdBuildIndustry(), CmdBuildLongRoad(), CmdBuildObject(), CmdBuildObjectArea(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildShipDepot(), CmdBuildTrainDepot(), CmdBuildTunnel(), CmdBuildVehicle(), CmdBuyCompany(), CmdChangeBankBalance(), CmdChangeCompanySetting(), CmdChangeSetting(), CmdClearArea(), CmdCloneOrder(), CmdCloneVehicle(), CmdCompanyAllowListCtrl(), CmdCompanyCtrl(), CmdConvertRail(), CmdConvertRoad(), CmdCreateGoal(), CmdCreateGroup(), CmdCreateLeagueTable(), CmdCreateLeagueTableElement(), CmdCreateStoryPage(), CmdCreateStoryPageElement(), CmdCreateSubsidy(), CmdCustomNewsItem(), CmdDecreaseLoan(), CmdDeleteGroup(), CmdDeleteOrder(), CmdDepotMassAutoReplace(), CmdDepotSellAllVehicles(), CmdEngineCtrl(), CmdForceTrainProceed(), CmdFoundTown(), CmdGiveMoney(), CmdIncreaseLoan(), CmdIndustrySetExclusivity(), CmdIndustrySetFlags(), CmdIndustrySetProduction(), CmdIndustrySetText(), CmdInsertOrder(), CmdLevelLand(), CmdMassStartStopVehicle(), CmdMoveOrder(), CmdMoveRailVehicle(), CmdOpenCloseAirport(), CmdOrderRefit(), CmdPause(), CmdPlaceSign(), CmdPlantTree(), CmdRefitVehicle(), CmdRemoveAllVehiclesGroup(), CmdRemoveFromRailStation(), CmdRemoveFromRailWaypoint(), CmdRemoveFromRoadWaypoint(), CmdRemoveGoal(), CmdRemoveLeagueTableElement(), CmdRemoveLongRoad(), CmdRemoveRoadStop(), CmdRemoveStoryPage(), CmdRemoveStoryPageElement(), CmdRenameCompany(), CmdRenameDepot(), CmdRenameEngine(), CmdRenamePresident(), CmdRenameSign(), CmdRenameStation(), CmdRenameTown(), CmdRenameVehicle(), CmdRenameWaypoint(), CmdReverseTrainDirection(), CmdScrollViewport(), CmdSellVehicle(), CmdSendVehicleToDepot(), CmdSetAutoReplace(), CmdSetCompanyManagerFace(), CmdSetCompanyMaxLoan(), CmdSetGoalCompleted(), CmdSetGoalDestination(), CmdSetGoalProgress(), CmdSetGoalText(), CmdSetGroupFlag(), CmdSetGroupLivery(), CmdSetStoryPageDate(), CmdSetStoryPageTitle(), CmdSetTimetableStart(), CmdSetVehicleOnTime(), CmdSetVehicleVisibility(), CmdShowStoryPage(), CmdSkipToOrder(), CmdStartStopVehicle(), CmdStoryPageButton(), CmdTownCargoGoal(), CmdTownRating(), CmdTownSetText(), CmdTurnRoadVeh(), CmdUpdateLeagueTableElementData(), CmdUpdateLeagueTableElementScore(), CmdUpdateStoryPageElement(), CmdWantEnginePreview(), CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::Do(), IsRoadAllowedHere(), RemoveDock(), RemoveEngineReplacement(), SendAllVehiclesToDepot(), Vehicle::SendToDepot(), TerraformTileHeight(), TownActionBuyRights(), TownActionFundBuildings(), and TownActionRoadRebuild().