OpenTTD Source: src/command.cpp File Reference

OpenTTD Source 15.0-RC2

Data Structures | Functions | Variables
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 cmd.
CommandFlags | GetCommandFlags (Commands cmd)
| This function mask the parameter with CMD_ID_MASK and returns the flags which belongs to the given command.
std::string_view | 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.
CommandCost | CommandCostWithParam (StringID str, uint64_t value)
| Return an error status, with string and parameter.

## Variables
static constexpr auto | _command_proc_table = MakeCommandsFromTraits(std::make_integer_sequence<std::underlying_type_t<Commands>, CMD_END>{})
| The master command table.

## Detailed Description

Handling of commands.

Handling of NewGRF road stops.

Definition in file command.cpp.

## Function Documentation

## ◆ CommandCostWithParam()

CommandCost CommandCostWithParam | ( | StringID | str,
|  | uint64_t | value
| ) |  |

Return an error status, with string and parameter.

Parameters

  str | StringID of error.
  value | Single parameter for error.

Returns
  CommandCost representing the error.

Definition at line 417 of file command.cpp.

References GetEncodedString(), IsLocalCompany(), and CommandCost::SetEncodedMessage().

Referenced by CheckAllowRemoveRoad(), CheckforTownRating(), CheckIfAuthorityAllowsNewStation(), ClearTile_Station(), ClearTile_Town(), CmdBuildAirport(), CmdBuildBridge(), CmdDecreaseLoan(), CmdIncreaseLoan(), DoBuildLock(), CommandHelperBase::InternalExecuteProcessResult(), and IsStationBridgeAboveOk().

## ◆ CommandFromTrait()

template<typename T >

constexpr CommandInfo CommandFromTrait | ( |  | ) |
| inlineconstexprnoexcept

Definition at line 83 of file command.cpp.

## ◆ 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

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

std::string_view 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.

Definition at line 144 of file command.cpp.

References _command_proc_table, _settings_game, AllActions, ConstructionSettings::command_pause_level, GameSettings::construction, End, IsValidCommand(), NoActions, NoConstruction, NoLandscaping, and to_underlying().

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

## ◆ MakeCommandsFromTraits()

template<typename T , T... i>

constexpr auto MakeCommandsFromTraits | ( | std::integer_sequence< T, i... > |  | ) |
| inlineconstexprnoexcept

Definition at line 86 of file command.cpp.

## Variable Documentation

## ◆ _command_proc_table

constexpr auto _command_proc_table = MakeCommandsFromTraits(std::make_integer_sequence<std::underlying_type_t<Commands>, CMD_END>{})
| staticconstexpr

The master command table.

This table contains all possible CommandProc functions with the flags which belongs to it. The indices are the same as the value from the CMD_* enums.

Definition at line 97 of file command.cpp.

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