OpenTTD Source 20260206-master-g4d4e37dbf1
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(*)(DoCommandFlags, Targs...), true >
 Templated wrapper that exposes the command parameter arguments for the various Commands::Do/Post calls. More...
struct  CommandHelper< Tcmd, Tret(*)(DoCommandFlags, 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>().Test(CommandFlag::Location)>

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 IsNetworkRegisteredCallback (CommandCallback *callback)
 Helper function to ensure that callbacks used when Posting commands are actually registered for the network calls.
bool IsValidCommand (Commands cmd)
 This function range-checks a Commands.
CommandFlags GetCommandFlags (Commands cmd)
 Get the command flags associated with the given command.
std::string_view GetCommandName (Commands cmd)
 Get the name of 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 DoCommandFlags 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>().Test(CommandFlag::Location)>

Definition at line 477 of file command_func.h.

Function Documentation

◆ CommandFlagsToDCFlags()

constexpr DoCommandFlags 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 49 of file command_func.h.

References AllTiles, Auto, NoWater, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by GrowTownWithBridge(), GrowTownWithTunnel(), BuildRailToolbarWindow::OnPlaceMouseUp(), BuildRoadToolbarWindow::OnPlaceMouseUp(), BuildDocksToolbarWindow::OnPlaceObject(), PlaceAirport(), PlaceRail_Station(), PlaceRoadStop(), and ShowBuildBridgeWindow().

◆ GetCommandFlags() [1/2]

template<Commands Tcmd>
CommandFlags GetCommandFlags ( )
constexpr

Definition at line 39 of file command_func.h.

◆ GetCommandFlags() [2/2]

◆ GetCommandName()

std::string_view GetCommandName ( Commands cmd)

Get the name of the given command.

Parameters
cmdThe command.
Returns
The name for this command

Definition at line 125 of file command.cpp.

References _command_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
cmdThe command to check.
Returns
True if the command is allowed while paused, false otherwise.

Definition at line 137 of file command.cpp.

References _command_table, _settings_game, AllActions, End, IsValidCommand(), NoActions, NoConstruction, NoLandscaping, and to_underlying().

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

◆ IsNetworkRegisteredCallback()

bool IsNetworkRegisteredCallback ( CommandCallback * callback)

Helper function to ensure that callbacks used when Posting commands are actually registered for the network calls.

Parameters
callbackThe callback to check.
Returns
true when the callback is in the callback table, otherwise false.

Definition at line 121 of file network_command.cpp.

References _callback_table.

Referenced by CommandHelper< Tcmd, Tret(*)(DoCommandFlags, Targs...), true >::Post().

◆ IsValidCommand()

bool IsValidCommand ( Commands cmd)

This function range-checks a Commands.

This is primarily for Commands coming from the network.

Parameters
cmdThe command.
Returns
True if the command is valid.

Definition at line 103 of file command.cpp.

References _command_table, and to_underlying().

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
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 207 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(*)(DoCommandFlags, 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(), 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(), CmdMoveSign(), CmdMoveStationName(), CmdMoveWaypointName(), CmdOpenCloseAirport(), CmdOrderRefit(), CmdPause(), CmdPlaceHouse(), CmdPlaceHouseArea(), 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(*)(DoCommandFlags, Targs...), true >::Do(), IsRoadAllowedHere(), RemoveDock(), RemoveEngineReplacement(), RemoveRoad(), SendAllVehiclesToDepot(), Vehicle::SendToDepot(), TerraformTileHeight(), TownActionBuyRights(), TownActionFundBuildings(), and TownActionRoadRebuild().