OpenTTD Source  13.0-beta1
command_func.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef COMMAND_FUNC_H
11 #define COMMAND_FUNC_H
12 
13 #include "command_type.h"
14 #include "network/network_type.h"
15 #include "company_type.h"
16 #include "company_func.h"
17 #include "core/backup_type.hpp"
18 #include "misc/endian_buffer.hpp"
19 #include "tile_map.h"
20 
29 
38 #define return_cmd_error(errcode) return CommandCost(errcode);
39 
40 void NetworkSendCommand(Commands cmd, StringID err_message, CommandCallback *callback, CompanyID company, TileIndex location, const CommandDataBuffer &cmd_data);
41 
42 bool IsValidCommand(Commands cmd);
44 const char *GetCommandName(Commands cmd);
47 
48 template <Commands Tcmd>
49 constexpr CommandFlags GetCommandFlags()
50 {
52 }
53 
59 static constexpr inline DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
60 {
61  DoCommandFlag flags = DC_NONE;
62  if (cmd_flags & CMD_NO_WATER) flags |= DC_NO_WATER;
63  if (cmd_flags & CMD_AUTO) flags |= DC_AUTO;
64  if (cmd_flags & CMD_ALL_TILES) flags |= DC_ALL_TILES;
65  return flags;
66 }
67 
70  RecursiveCommandCounter() noexcept { _counter++; }
71  ~RecursiveCommandCounter() noexcept { _counter--; }
72 
74  bool IsTopLevel() const { return _counter == 1; }
75 private:
76  static int _counter;
77 };
78 
79 #if defined(__GNUC__) && !defined(__clang__)
80 /*
81  * We cast specialized function pointers to a generic one, but don't use the
82  * converted value to call the function, which is safe, except that GCC
83  * helpfully thinks it is not.
84  *
85  * "Any pointer to function can be converted to a pointer to a different function type.
86  * Calling the function through a pointer to a different function type is undefined,
87  * but converting such pointer back to pointer to the original function type yields
88  * the pointer to the original function." */
89 # pragma GCC diagnostic push
90 # pragma GCC diagnostic ignored "-Wcast-function-type"
91 # define SILENCE_GCC_FUNCTION_POINTER_CAST
92 #endif
93 
94 template<Commands TCmd, typename T, bool THasTile> struct CommandHelper;
95 
97 protected:
98  static void InternalDoBefore(bool top_level, bool test);
99  static void InternalDoAfter(CommandCost &res, DoCommandFlag flags, bool top_level, bool test);
100  static std::tuple<bool, bool, bool> InternalPostBefore(Commands cmd, CommandFlags flags, TileIndex tile, StringID err_message, bool network_command);
101  static void InternalPostResult(const CommandCost &res, TileIndex tile, bool estimate_only, bool only_sending, StringID err_message, bool my_cmd);
102  static bool InternalExecutePrepTest(CommandFlags cmd_flags, TileIndex tile, Backup<CompanyID> &cur_company);
103  static std::tuple<bool, bool, bool> InternalExecuteValidateTestAndPrepExec(CommandCost &res, CommandFlags cmd_flags, bool estimate_only, bool network_command, Backup<CompanyID> &cur_company);
104  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);
105  static void LogCommandExecution(Commands cmd, StringID err_message, TileIndex tile, const CommandDataBuffer &args, bool failed);
106 };
107 
115 template <Commands Tcmd, typename Tret, typename... Targs>
116 struct CommandHelper<Tcmd, Tret(*)(DoCommandFlag, Targs...), true> : protected CommandHelperBase {
117 private:
119  static inline CommandCost &ExtractCommandCost(Tret &ret)
120  {
121  if constexpr (std::is_same_v<Tret, CommandCost>) {
122  return ret;
123  } else {
124  return std::get<0>(ret);
125  }
126  }
127 
129  static inline Tret MakeResult(const CommandCost &cost)
130  {
131  Tret ret{};
132  ExtractCommandCost(ret) = cost;
133  return ret;
134  }
135 
136 public:
150  static Tret Do(DoCommandFlag flags, Targs... args)
151  {
152  if constexpr (std::is_same_v<TileIndex, std::tuple_element_t<0, std::tuple<Targs...>>>) {
153  /* Do not even think about executing out-of-bounds tile-commands. */
154  TileIndex tile = std::get<0>(std::make_tuple(args...));
155  if (tile != 0 && (tile >= MapSize() || (!IsValidTile(tile) && (flags & DC_ALL_TILES) == 0))) return MakeResult(CMD_ERROR);
156  }
157 
158  RecursiveCommandCounter counter{};
159 
160  /* Only execute the test call if it's toplevel, or we're not execing. */
161  if (counter.IsTopLevel() || !(flags & DC_EXEC)) {
162  InternalDoBefore(counter.IsTopLevel(), true);
163  Tret res = CommandTraits<Tcmd>::proc(flags & ~DC_EXEC, args...);
164  InternalDoAfter(ExtractCommandCost(res), flags, counter.IsTopLevel(), true); // Can modify res.
165 
166  if (ExtractCommandCost(res).Failed() || !(flags & DC_EXEC)) return res;
167  }
168 
169  /* Execute the command here. All cost-relevant functions set the expenses type
170  * themselves to the cost object at some point. */
171  InternalDoBefore(counter.IsTopLevel(), false);
172  Tret res = CommandTraits<Tcmd>::proc(flags, args...);
173  InternalDoAfter(ExtractCommandCost(res), flags, counter.IsTopLevel(), false);
174 
175  return res;
176  }
177 
183  static inline bool Post(StringID err_message, Targs... args) { return Post<CommandCallback>(err_message, nullptr, std::forward<Targs>(args)...); }
189  template <typename Tcallback>
190  static inline bool Post(Tcallback *callback, Targs... args) { return Post((StringID)0, callback, std::forward<Targs>(args)...); }
195  static inline bool Post(Targs... args) { return Post<CommandCallback>((StringID)0, nullptr, std::forward<Targs>(args)...); }
196 
207  template <typename Tcallback>
208  static bool Post(StringID err_message, Tcallback *callback, Targs... args)
209  {
210  return InternalPost(err_message, callback, true, false, std::forward_as_tuple(args...));
211  }
212 
222  template <typename Tcallback>
223  static bool PostFromNet(StringID err_message, Tcallback *callback, bool my_cmd, TileIndex location, std::tuple<Targs...> args)
224  {
225  if constexpr (std::is_same_v<TileIndex, std::tuple_element_t<0, decltype(args)>>) {
226  /* Do not even think about executing out-of-bounds tile-commands. */
227  TileIndex tile = std::get<0>(args);
228  if (tile != 0 && (tile >= MapSize() || (!IsValidTile(tile) && (GetCommandFlags<Tcmd>() & CMD_ALL_TILES) == 0))) return false;
229  }
230 
231  return InternalPost(err_message, callback, my_cmd, true, location, std::move(args));
232  }
233 
241  static void SendNet(StringID err_message, CompanyID company, Targs... args)
242  {
243  auto args_tuple = std::forward_as_tuple(args...);
244 
245  TileIndex tile{};
246  if constexpr (std::is_same_v<TileIndex, std::tuple_element_t<0, decltype(args_tuple)>>) {
247  tile = std::get<0>(args_tuple);
248  }
249 
250  ::NetworkSendCommand(Tcmd, err_message, nullptr, _current_company, tile, EndianBufferWriter<CommandDataBuffer>::FromValue(args_tuple));
251  }
252 
263  template <typename Tcallback>
264  static Tret Unsafe(StringID err_message, Tcallback *callback, bool my_cmd, bool estimate_only, TileIndex location, std::tuple<Targs...> args)
265  {
266  return Execute(err_message, reinterpret_cast<CommandCallback *>(callback), my_cmd, estimate_only, false, location, std::move(args));
267  }
268 
269 protected:
271  template <class T>
272  static inline void SetClientIdHelper(T &data)
273  {
274  if constexpr (std::is_same_v<ClientID, T>) {
275  if (data == INVALID_CLIENT_ID) data = CLIENT_ID_SERVER;
276  }
277  }
278 
280  template<class Ttuple, size_t... Tindices>
281  static inline void SetClientIds(Ttuple &values, std::index_sequence<Tindices...>)
282  {
283  ((SetClientIdHelper(std::get<Tindices>(values))), ...);
284  }
285 
287  template <template <typename...> typename Tt, typename T1, typename... Ts>
288  static inline Tt<Ts...> RemoveFirstTupleElement(const Tt<T1, Ts...> &tuple)
289  {
290  return std::apply([](auto &&, const auto&... args) { return std::tie(args...); }, tuple);
291  }
292 
293  template <typename Tcallback>
294  static bool InternalPost(StringID err_message, Tcallback *callback, bool my_cmd, bool network_command, std::tuple<Targs...> args)
295  {
296  /* Where to show the message? */
297  TileIndex tile{};
298  if constexpr (std::is_same_v<TileIndex, std::tuple_element_t<0, decltype(args)>>) {
299  tile = std::get<0>(args);
300  }
301 
302  return InternalPost(err_message, callback, my_cmd, network_command, tile, std::move(args));
303  }
304 
305  template <typename Tcallback>
306  static bool InternalPost(StringID err_message, Tcallback *callback, bool my_cmd, bool network_command, TileIndex tile, std::tuple<Targs...> args)
307  {
308  /* Do not even think about executing out-of-bounds tile-commands. */
309  if (tile != 0 && (tile >= MapSize() || (!IsValidTile(tile) && (GetCommandFlags<Tcmd>() & CMD_ALL_TILES) == 0))) return false;
310 
311  auto [err, estimate_only, only_sending] = InternalPostBefore(Tcmd, GetCommandFlags<Tcmd>(), tile, err_message, network_command);
312  if (err) return false;
313 
314  /* Only set client IDs when the command does not come from the network. */
315  if (!network_command && GetCommandFlags<Tcmd>() & CMD_CLIENT_ID) SetClientIds(args, std::index_sequence_for<Targs...>{});
316 
317  Tret res = Execute(err_message, reinterpret_cast<CommandCallback *>(callback), my_cmd, estimate_only, network_command, tile, args);
318  InternalPostResult(ExtractCommandCost(res), tile, estimate_only, only_sending, err_message, my_cmd);
319 
320  if (!estimate_only && !only_sending && callback != nullptr) {
321  if constexpr (std::is_same_v<Tcallback, CommandCallback>) {
322  /* Callback that doesn't need any command arguments. */
323  callback(Tcmd, ExtractCommandCost(res), tile);
324  } else if constexpr (std::is_same_v<Tcallback, CommandCallbackData>) {
325  /* Generic callback that takes packed arguments as a buffer. */
326  if constexpr (std::is_same_v<Tret, CommandCost>) {
327  callback(Tcmd, ExtractCommandCost(res), tile, EndianBufferWriter<CommandDataBuffer>::FromValue(args), {});
328  } else {
329  callback(Tcmd, ExtractCommandCost(res), tile, EndianBufferWriter<CommandDataBuffer>::FromValue(args), EndianBufferWriter<CommandDataBuffer>::FromValue(RemoveFirstTupleElement(res)));
330  }
331  } else if constexpr (!std::is_same_v<Tret, CommandCost> && std::is_same_v<Tcallback *, typename CommandTraits<Tcmd>::RetCallbackProc>) {
332  std::apply(callback, std::tuple_cat(std::make_tuple(Tcmd), res));
333  } else {
334  /* Callback with arguments. We assume that the tile is only interesting if it actually is in the command arguments. */
335  if constexpr (std::is_same_v<Tret, CommandCost>) {
336  std::apply(callback, std::tuple_cat(std::make_tuple(Tcmd, res), args));
337  } else {
338  std::apply(callback, std::tuple_cat(std::make_tuple(Tcmd), res, args));
339  }
340  }
341  }
342 
343  return ExtractCommandCost(res).Succeeded();
344  }
345 
347  template <class T>
348  static inline bool ClientIdIsSet(T &data)
349  {
350  if constexpr (std::is_same_v<ClientID, T>) {
351  return data != INVALID_CLIENT_ID;
352  } else {
353  return true;
354  }
355  }
356 
358  template<class Ttuple, size_t... Tindices>
359  static inline bool AllClientIdsSet(Ttuple &values, std::index_sequence<Tindices...>)
360  {
361  return (ClientIdIsSet(std::get<Tindices>(values)) && ...);
362  }
363 
364  template<class Ttuple>
365  static inline Money ExtractAdditionalMoney(Ttuple &values)
366  {
367  if constexpr (std::is_same_v<std::tuple_element_t<1, Tret>, Money>) {
368  return std::get<1>(values);
369  } else {
370  return {};
371  }
372  }
373 
374  static Tret Execute(StringID err_message, CommandCallback *callback, bool my_cmd, bool estimate_only, bool network_command, TileIndex tile, std::tuple<Targs...> args)
375  {
376  /* Prevent recursion; it gives a mess over the network */
377  RecursiveCommandCounter counter{};
378  assert(counter.IsTopLevel());
379 
380  /* Command flags are used internally */
381  constexpr CommandFlags cmd_flags = GetCommandFlags<Tcmd>();
382 
383  if constexpr ((cmd_flags & CMD_CLIENT_ID) != 0) {
384  /* Make sure arguments are properly set to a ClientID also when processing external commands. */
385  assert(AllClientIdsSet(args, std::index_sequence_for<Targs...>{}));
386  }
387 
388  Backup<CompanyID> cur_company(_current_company, FILE_LINE);
389  if (!InternalExecutePrepTest(cmd_flags, tile, cur_company)) {
390  cur_company.Trash();
391  return MakeResult(CMD_ERROR);
392  }
393 
394  /* Test the command. */
395  DoCommandFlag flags = CommandFlagsToDCFlags(cmd_flags);
396  Tret res = std::apply(CommandTraits<Tcmd>::proc, std::tuple_cat(std::make_tuple(flags), args));
397 
398  auto [exit_test, desync_log, send_net] = InternalExecuteValidateTestAndPrepExec(ExtractCommandCost(res), cmd_flags, estimate_only, network_command, cur_company);
399  if (exit_test) {
400  if (desync_log) LogCommandExecution(Tcmd, err_message, tile, EndianBufferWriter<CommandDataBuffer>::FromValue(args), true);
401  cur_company.Restore();
402  return res;
403  }
404 
405  /* If we are in network, and the command is not from the network
406  * send it to the command-queue and abort execution. */
407  if (send_net) {
409  cur_company.Restore();
410 
411  /* Don't return anything special here; no error, no costs.
412  * This way it's not handled by DoCommand and only the
413  * actual execution of the command causes messages. Also
414  * reset the storages as we've not executed the command. */
415  return {};
416  }
417 
418  if (desync_log) LogCommandExecution(Tcmd, err_message, tile, EndianBufferWriter<CommandDataBuffer>::FromValue(args), false);
419 
420  /* Actually try and execute the command. */
421  Tret res2 = std::apply(CommandTraits<Tcmd>::proc, std::tuple_cat(std::make_tuple(flags | DC_EXEC), args));
422 
423  /* Convention: If the second result element is of type Money,
424  * this is the additional cash required for the command. */
425  Money additional_money{};
426  if constexpr (!std::is_same_v<Tret, CommandCost>) { // No short-circuiting for 'if constexpr'.
427  additional_money = ExtractAdditionalMoney(res2);
428  }
429 
430  if constexpr (std::is_same_v<Tret, CommandCost>) {
431  return InternalExecuteProcessResult(Tcmd, cmd_flags, res, res2, additional_money, tile, cur_company);
432  } else {
433  std::get<0>(res2) = InternalExecuteProcessResult(Tcmd, cmd_flags, ExtractCommandCost(res), ExtractCommandCost(res2), additional_money, tile, cur_company);
434  return res2;
435  }
436  }
437 };
438 
446 template <Commands Tcmd, typename Tret, typename... Targs>
447 struct CommandHelper<Tcmd, Tret(*)(DoCommandFlag, Targs...), false> : CommandHelper<Tcmd, Tret(*)(DoCommandFlag, Targs...), true>
448 {
449  /* Import Post overloads from our base class. */
450  using CommandHelper<Tcmd, Tret(*)(DoCommandFlag, Targs...), true>::Post;
451 
458  static inline bool Post(StringID err_message, TileIndex location, Targs... args) { return Post<CommandCallback>(err_message, nullptr, location, std::forward<Targs>(args)...); }
465  template <typename Tcallback>
466  static inline bool Post(Tcallback *callback, TileIndex location, Targs... args) { return Post((StringID)0, callback, location, std::forward<Targs>(args)...); }
472  static inline bool Post(TileIndex location, Targs... args) { return Post<CommandCallback>((StringID)0, nullptr, location, std::forward<Targs>(args)...); }
473 
483  template <typename Tcallback>
484  static inline bool Post(StringID err_message, Tcallback *callback, TileIndex location, Targs... args)
485  {
486  return CommandHelper<Tcmd, Tret(*)(DoCommandFlag, Targs...), true>::InternalPost(err_message, callback, true, false, location, std::forward_as_tuple(args...));
487  }
488 };
489 
490 #ifdef SILENCE_GCC_FUNCTION_POINTER_CAST
491 # pragma GCC diagnostic pop
492 #endif
493 
494 template <Commands Tcmd>
495 using Command = CommandHelper<Tcmd, typename CommandTraits<Tcmd>::ProcType, std::is_same_v<TileIndex, std::tuple_element_t<0, typename CommandTraits<Tcmd>::Args>>>;
496 
497 #endif /* COMMAND_FUNC_H */
SetClientIdHelper
static void SetClientIdHelper(T &data, [[maybe_unused]] ClientID client_id)
Helper to process a single ClientID argument.
Definition: network_command.cpp:464
GetCommandName
const char * GetCommandName(Commands cmd)
Definition: command.cpp:133
GetCommandFlags
CommandFlags GetCommandFlags(Commands cmd)
Definition: command.cpp:119
INVALID_CLIENT_ID
@ INVALID_CLIENT_ID
Client is not part of anything.
Definition: network_type.h:48
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), false >::Post
static bool Post(TileIndex location, Targs... args)
Shortcut for Post when not using a callback or an error message.
Definition: command_func.h:472
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
Commands
Commands
List of commands.
Definition: command_type.h:176
IsCommandAllowedWhilePaused
bool IsCommandAllowedWhilePaused(Commands cmd)
Returns whether the command is allowed while the game is paused.
Definition: command.cpp:145
CommandDataBuffer
std::vector< byte > CommandDataBuffer
Storage buffer for serialized command data.
Definition: command_type.h:443
IsValidCommand
bool IsValidCommand(Commands cmd)
Definition: command.cpp:107
Backup
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:21
CommandFlagsToDCFlags
static constexpr DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
Definition: command_func.h:59
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::MakeResult
static Tret MakeResult(const CommandCost &cost)
Make a command proc result from a CommandCost.
Definition: command_func.h:129
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::SetClientIds
static void SetClientIds(Ttuple &values, std::index_sequence< Tindices... >)
Set all invalid ClientID's to the proper value.
Definition: command_func.h:281
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::AllClientIdsSet
static bool AllClientIdsSet(Ttuple &values, std::index_sequence< Tindices... >)
Check if all ClientID arguments are set to valid values.
Definition: command_func.h:359
CommandHelperBase::InternalExecuteValidateTestAndPrepExec
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.
Definition: command.cpp:318
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
CommandHelperBase::InternalDoBefore
static void InternalDoBefore(bool top_level, bool test)
Prepare for calling a command proc.
Definition: command.cpp:185
DC_NO_WATER
@ DC_NO_WATER
don't allow building on water
Definition: command_type.h:353
DC_ALL_TILES
@ DC_ALL_TILES
allow this command also on MP_VOID tiles
Definition: command_type.h:359
CommandCallback
void CommandCallback(Commands cmd, const CommandCost &result, TileIndex tile)
Define a callback function for the client, after the command is finished.
Definition: command_type.h:457
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:350
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:348
CommandTraits
Defines the traits of a command.
Definition: command_type.h:426
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::RemoveFirstTupleElement
static Tt< Ts... > RemoveFirstTupleElement(const Tt< T1, Ts... > &tuple)
Remove the first element of a tuple.
Definition: command_func.h:288
endian_buffer.hpp
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), false >::Post
static bool Post(StringID err_message, Tcallback *callback, TileIndex location, Targs... args)
Post variant that takes a TileIndex (for error window location and text effects) for commands that do...
Definition: command_func.h:484
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::Post
static bool Post(StringID err_message, Targs... args)
Shortcut for the long Post when not using a callback.
Definition: command_func.h:183
CommandFlags
CommandFlags
Command flags for the command table _command_proc_table.
Definition: command_type.h:370
tile_map.h
MapSize
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
CommandHelperBase::InternalExecutePrepTest
static bool InternalExecutePrepTest(CommandFlags cmd_flags, TileIndex tile, Backup< CompanyID > &cur_company)
Prepare for the test run of a command proc call.
Definition: command.cpp:288
CommandCost
Common return value for all commands.
Definition: command_type.h:24
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::SendNet
static void SendNet(StringID err_message, CompanyID company, Targs... args)
Prepare a command to be send over the network.
Definition: command_func.h:241
CMD_AUTO
@ CMD_AUTO
set the DC_AUTO flag on this command
Definition: command_type.h:374
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::ClientIdIsSet
static bool ClientIdIsSet(T &data)
Helper to process a single ClientID argument.
Definition: command_func.h:348
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::Post
static bool Post(StringID err_message, Tcallback *callback, Targs... args)
Top-level network safe command execution for the current company.
Definition: command_func.h:208
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), false >::Post
static bool Post(StringID err_message, TileIndex location, Targs... args)
Shortcut for Post when not using an error message.
Definition: command_func.h:458
CMD_CLIENT_ID
@ CMD_CLIENT_ID
set p2 with the ClientID of the sending client.
Definition: command_type.h:378
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::ExtractCommandCost
static CommandCost & ExtractCommandCost(Tret &ret)
Extract the CommandCost from a command proc result.
Definition: command_func.h:119
IsValidTile
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:161
CLIENT_ID_SERVER
@ CLIENT_ID_SERVER
Servers always have this ID.
Definition: network_type.h:49
NetworkSendCommand
void NetworkSendCommand(Commands cmd, StringID err_message, CommandCallback *callback, CompanyID company, TileIndex location, const CommandDataBuffer &cmd_data)
Prepare a DoCommand to be send over the network.
Definition: network_command.cpp:266
CommandHelperBase::InternalDoAfter
static void InternalDoAfter(CommandCost &res, DoCommandFlag flags, bool top_level, bool test)
Process result after calling a command proc.
Definition: command.cpp:198
CommandHelperBase::InternalPostBefore
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.
Definition: command.cpp:223
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::Unsafe
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.
Definition: command_func.h:264
RecursiveCommandCounter::IsTopLevel
bool IsTopLevel() const
Are we in the top-level command execution?
Definition: command_func.h:74
command_type.h
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), false >::Post
static bool Post(Tcallback *callback, TileIndex location, Targs... args)
Shortcut for Post when not using a callback.
Definition: command_func.h:466
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::Do
static Tret Do(DoCommandFlag flags, Targs... args)
This function executes a given command with the parameters from the #CommandProc parameter list.
Definition: command_func.h:150
CommandHelperBase::InternalPostResult
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.
Definition: command.cpp:253
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
CommandHelperBase::InternalExecuteProcessResult
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.
Definition: command.cpp:358
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
CMD_NO_WATER
@ CMD_NO_WATER
set the DC_NO_WATER flag on this command
Definition: command_type.h:377
CMD_ALL_TILES
@ CMD_ALL_TILES
allow this command also on MP_VOID tiles
Definition: command_type.h:375
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::SetClientIdHelper
static void SetClientIdHelper(T &data)
Helper to process a single ClientID argument.
Definition: command_func.h:272
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::PostFromNet
static bool PostFromNet(StringID err_message, Tcallback *callback, bool my_cmd, TileIndex location, std::tuple< Targs... > args)
Execute a command coming from the network.
Definition: command_func.h:223
CommandHelperBase::LogCommandExecution
static void LogCommandExecution(Commands cmd, StringID err_message, TileIndex tile, const CommandDataBuffer &args, bool failed)
Helper to make a desync log for a command.
Definition: command.cpp:276
DC_AUTO
@ DC_AUTO
don't allow building on structures
Definition: command_type.h:351
company_func.h
CommandHelper
Definition: command_func.h:94
OverflowSafeInt< int64 >
GetAvailableMoneyForCommand
Money GetAvailableMoneyForCommand()
Definition: command.cpp:172
EndianBufferWriter
Endian-aware buffer adapter that always writes values in little endian order.
Definition: endian_buffer.hpp:28
DC_NONE
@ DC_NONE
no flag is set
Definition: command_type.h:349
CommandHelperBase
Definition: command_func.h:96
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::Post
static bool Post(Tcallback *callback, Targs... args)
Shortcut for the long Post when not using an error message.
Definition: command_func.h:190
company_type.h
RecursiveCommandCounter
Helper class to keep track of command nesting level.
Definition: command_func.h:69
SetClientIds
static void SetClientIds(Ttuple &values, ClientID client_id, std::index_sequence< Tindices... >)
Set all invalid ClientID's to the proper value.
Definition: network_command.cpp:473
CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::Post
static bool Post(Targs... args)
Shortcut for the long Post when not using a callback or an error message.
Definition: command_func.h:195
network_type.h
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
backup_type.hpp