OpenTTD Source: CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true > Struct Template Reference

OpenTTD Source 14.0-beta3

Static Public Member Functions | Static Protected Member Functions | Static Private Member Functions
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true > Struct Template Reference

Templated wrapper that exposes the command parameter arguments for the various Command::Do/Post calls. More...

`#include <command_func.h>`

Inheritance diagram for CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >:

## Static Public Member Functions
static Tret | Do (DoCommandFlag flags, Targs... args)
| This function executes a given command with the parameters from the #CommandProc parameter list. More...
static bool | Post (StringID err_message, Targs... args)
| Shortcut for the long Post when not using a callback. More...
template<typename Tcallback >
static bool | Post (Tcallback *callback, Targs... args)
| Shortcut for the long Post when not using an error message. More...
static bool | Post (Targs... args)
| Shortcut for the long Post when not using a callback or an error message. More...
template<typename Tcallback >
static bool | Post (StringID err_message, Tcallback *callback, Targs... args)
| Top-level network safe command execution for the current company. More...
template<typename Tcallback >
static bool | PostFromNet (StringID err_message, Tcallback *callback, bool my_cmd, std::tuple< Targs... > args)
| Execute a command coming from the network. More...
static void | SendNet (StringID err_message, CompanyID company, Targs... args)
| Prepare a command to be send over the network. More...
template<typename Tcallback >
static Tret | Unsafe (StringID err_message, Tcallback *callback, bool my_cmd, bool estimate_only, TileIndex location, std::tuple< Targs... > args)
| Top-level network safe command execution without safety checks. More...

## Static Protected Member Functions
template<class T >
static void | SetClientIdHelper ([[maybe_unused]] T &data)
| Helper to process a single ClientID argument.
template<class Ttuple , size_t... Tindices>
static void | SetClientIds (Ttuple &values, std::index_sequence< Tindices... >)
| Set all invalid ClientID's to the proper value.
template<template< typename... > typename Tt, typename T1 , typename... Ts>
static Tt< Ts... > | RemoveFirstTupleElement (const Tt< T1, Ts... > &tuple)
| Remove the first element of a tuple.
template<typename Tcallback >
static bool | InternalPost (StringID err_message, Tcallback *callback, bool my_cmd, bool network_command, std::tuple< Targs... > args)
template<typename Tcallback >
static bool | InternalPost (StringID err_message, Tcallback *callback, bool my_cmd, bool network_command, TileIndex tile, std::tuple< Targs... > args)
template<class T >
static bool | ClientIdIsSet ([[maybe_unused]] T &data)
| Helper to process a single ClientID argument.
template<class Ttuple , size_t... Tindices>
static bool | AllClientIdsSet (Ttuple &values, std::index_sequence< Tindices... >)
| Check if all ClientID arguments are set to valid values.
template<class Ttuple >
static Money | ExtractAdditionalMoney ([[maybe_unused]] Ttuple &values)
static Tret | Execute (StringID err_message, CommandCallback *callback, bool, bool estimate_only, bool network_command, TileIndex tile, std::tuple< Targs... > args)
Static Protected Member Functions inherited from CommandHelperBase
static void | InternalDoBefore (bool top_level, bool test)
| Prepare for calling a command proc. More...
static void | InternalDoAfter (CommandCost &res, DoCommandFlag flags, bool top_level, bool test)
| Process result after calling a command proc. More...
static std::tuple< bool, bool, bool > | InternalPostBefore (Commands cmd, CommandFlags flags, TileIndex tile, StringID err_message, bool network_command)
| Decide what to do with the command depending on current game state. More...
static void | InternalPostResult (const CommandCost &res, TileIndex tile, bool estimate_only, bool only_sending, StringID err_message, bool my_cmd)
| Process result of executing a command, possibly displaying any error to the player. More...
static bool | InternalExecutePrepTest (CommandFlags cmd_flags, TileIndex tile, Backup< CompanyID > &cur_company)
| Prepare for the test run of a command proc call. More...
static std::tuple< bool, bool, bool > | InternalExecuteValidateTestAndPrepExec (CommandCost &res, CommandFlags cmd_flags, bool estimate_only, bool network_command, Backup< CompanyID > &cur_company)
| Validate result of test run and prepare for real execution. More...
static CommandCost | InternalExecuteProcessResult (Commands cmd, CommandFlags cmd_flags, const CommandCost &res_test, const CommandCost &res_exec, Money extra_cash, TileIndex tile, Backup< CompanyID > &cur_company)
| Process the result of a command test run and execution run. More...
static void | LogCommandExecution (Commands cmd, StringID err_message, const CommandDataBuffer &args, bool failed)
| Helper to make a desync log for a command.

## Static Private Member Functions
static CommandCost & | ExtractCommandCost (Tret &ret)
| Extract the `CommandCost` from a command proc result.
static Tret | MakeResult (const CommandCost &cost)
| Make a command proc result from a `CommandCost`.

## Detailed Description

### template<Commands Tcmd, typename Tret, typename... Targs>
struct CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >

Templated wrapper that exposes the command parameter arguments for the various Command::Do/Post calls.

Template Parameters

  Tcmd | The command-id to execute.
  Tret | Return type of the command.
  Targs | The command parameter types.

Definition at line 115 of file command_func.h.

## Member Function Documentation

## ◆ Do()

template<Commands Tcmd, typename Tret , typename... Targs>

static Tret CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::Do | ( | DoCommandFlag | flags,
|  | Targs... | args
| ) |  |
| inlinestatic

This function executes a given command with the parameters from the #CommandProc parameter list.

Depending on the flags parameter it executes or tests a command.

Note
  This function is to be called from the StateGameLoop or from within the execution of a Command. This function must not be called from the context of a "player" (real person, AI, game script). Use ::Post for commands directly triggered by "players".

Parameters

  flags | Flags for the command and how to execute the command
  args | Parameters for the command

See also
  CommandProc

Returns
  the cost

Definition at line 149 of file command_func.h.

References CMD_ERROR, DC_ALL_TILES, DC_EXEC, IsValidTile(), and Map::Size().

## ◆ Post() [1/4]

template<Commands Tcmd, typename Tret , typename... Targs>

static bool CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::Post | ( | StringID | err_message,
|  | Targs... | args
| ) |  |
| inlinestatic

Shortcut for the long Post when not using a callback.

Parameters

  err_message | Message prefix to show on error
  args | Parameters for the command

Definition at line 182 of file command_func.h.

## ◆ Post() [2/4]

template<Commands Tcmd, typename Tret , typename... Targs>
template<typename Tcallback >

static bool CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::Post | ( | StringID | err_message,
|  | Tcallback * | callback,
|  | Targs... | args
| ) |  |
| inlinestatic

Top-level network safe command execution for the current company.

Must not be called recursively. The callback is called when the command succeeded or failed.

Parameters

  err_message | Message prefix to show on error
  callback | A callback function to call after the command is finished
  args | Parameters for the command

Returns
  `true` if the command succeeded, else `false`.

Definition at line 207 of file command_func.h.

## ◆ Post() [3/4]

template<Commands Tcmd, typename Tret , typename... Targs>

static bool CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::Post | ( | Targs... | args | ) |
| inlinestatic

Shortcut for the long Post when not using a callback or an error message.

Parameters

  args | Parameters for the command

Definition at line 194 of file command_func.h.

## ◆ Post() [4/4]

template<Commands Tcmd, typename Tret , typename... Targs>
template<typename Tcallback >

static bool CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::Post | ( | Tcallback * | callback,
|  | Targs... | args
| ) |  |
| inlinestatic

Shortcut for the long Post when not using an error message.

Parameters

  callback | A callback function to call after the command is finished
  args | Parameters for the command

Definition at line 189 of file command_func.h.

References Post().

Referenced by Post().

## ◆ PostFromNet()

template<Commands Tcmd, typename Tret , typename... Targs>
template<typename Tcallback >

static bool CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::PostFromNet | ( | StringID | err_message,
|  | Tcallback * | callback,
|  | bool | my_cmd,
|  | std::tuple< Targs... > | args
| ) |  |
| inlinestatic

Execute a command coming from the network.

Parameters

  err_message | Message prefix to show on error
  callback | A callback function to call after the command is finished
  my_cmd | indicator if the command is from a company or server (to display error messages for a user)
  args | Parameters for the command

Returns
  `true` if the command succeeded, else `false`.

Definition at line 221 of file command_func.h.

## ◆ SendNet()

template<Commands Tcmd, typename Tret , typename... Targs>

static void CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::SendNet | ( | StringID | err_message,
|  | CompanyID | company,
|  | Targs... | args
| ) |  |
| inlinestatic

Prepare a command to be send over the network.

Parameters

  cmd | The command to execute (a CMD_* value)
  err_message | Message prefix to show on error
  company | The company that wants to send the command
  args | Parameters for the command

Definition at line 233 of file command_func.h.

References NetworkSendCommand().

## ◆ Unsafe()

template<Commands Tcmd, typename Tret , typename... Targs>
template<typename Tcallback >

static Tret CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::Unsafe | ( | StringID | err_message,
|  | Tcallback * | callback,
|  | bool | my_cmd,
|  | bool | estimate_only,
|  | TileIndex | location,
|  | std::tuple< Targs... > | args
| ) |  |
| inlinestatic

Top-level network safe command execution without safety checks.

Parameters

  err_message | Message prefix to show on error
  callback | A callback function to call after the command is finished
  my_cmd | indicator if the command is from a company or server (to display error messages for a user)
  estimate_only | whether to give only the estimate or also execute the command
  location | Tile location for user feedback.
  args | Parameters for the command

Returns
  the command cost of this function.

Definition at line 251 of file command_func.h.

The documentation for this struct was generated from the following file:

- src/command_func.h