OpenTTD Source 20260206-master-g4d4e37dbf1
command.cpp File Reference

Handling of commands. More...

#include "stdafx.h"
#include "landscape.h"
#include "error.h"
#include "gui.h"
#include "command_func.h"
#include "network/network_type.h"
#include "network/network.h"
#include "genworld.h"
#include "strings_func.h"
#include "texteff.hpp"
#include "town.h"
#include "timer/timer_game_economy.h"
#include "company_func.h"
#include "company_base.h"
#include "signal_func.h"
#include "core/backup_type.hpp"
#include "object_base.h"
#include "autoreplace_cmd.h"
#include "company_cmd.h"
#include "depot_cmd.h"
#include "economy_cmd.h"
#include "engine_cmd.h"
#include "goal_cmd.h"
#include "group_cmd.h"
#include "industry_cmd.h"
#include "league_cmd.h"
#include "landscape_cmd.h"
#include "misc_cmd.h"
#include "news_cmd.h"
#include "object_cmd.h"
#include "order_cmd.h"
#include "rail_cmd.h"
#include "road_cmd.h"
#include "roadveh_cmd.h"
#include "settings_cmd.h"
#include "signs_cmd.h"
#include "station_cmd.h"
#include "story_cmd.h"
#include "subsidy_cmd.h"
#include "terraform_cmd.h"
#include "timetable_cmd.h"
#include "town_cmd.h"
#include "train_cmd.h"
#include "tree_cmd.h"
#include "tunnelbridge_cmd.h"
#include "vehicle_cmd.h"
#include "viewport_cmd.h"
#include "water_cmd.h"
#include "waypoint_cmd.h"
#include "misc/endian_buffer.hpp"
#include "string_func.h"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  CommandInfo
 Define a command with the flags which belongs to it. More...

Functions

template<typename T>
constexpr CommandInfo CommandFromTrait () noexcept
template<typename T, T... i>
constexpr auto MakeCommandsFromTraits (std::integer_sequence< T, i... >) noexcept
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.
CommandCost CommandCostWithParam (StringID str, uint64_t value)
 Return an error status, with string and parameter.

Variables

static constexpr auto _command_table = MakeCommandsFromTraits(std::make_integer_sequence<std::underlying_type_t<Commands>, to_underlying(Commands::End)>{})
 The master command table.

Detailed Description

Handling of commands.

Definition in file command.cpp.

Function Documentation

◆ CommandCostWithParam()

CommandCost CommandCostWithParam ( StringID str,
uint64_t value )

◆ CommandFromTrait()

template<typename T>
CommandInfo CommandFromTrait ( )
inlineconstexprnoexcept

Definition at line 83 of file command.cpp.

◆ GetCommandFlags()

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

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

◆ MakeCommandsFromTraits()

template<typename T, T... i>
auto MakeCommandsFromTraits ( std::integer_sequence< T, i... > )
inlineconstexprnoexcept

Definition at line 86 of file command.cpp.

Variable Documentation

◆ _command_table

auto _command_table = MakeCommandsFromTraits(std::make_integer_sequence<std::underlying_type_t<Commands>, to_underlying(Commands::End)>{})
staticconstexpr

The master command table.

This contains the CommandInfo for all possible Commands functions.

Definition at line 95 of file command.cpp.

Referenced by GetCommandFlags(), GetCommandName(), CommandHelperBase::InternalExecuteProcessResult(), IsCommandAllowedWhilePaused(), and IsValidCommand().