|
1 /* $Id$ */ |
|
2 |
|
3 /** @file command_func.h Functions related to commands. */ |
|
4 |
|
5 #ifndef COMMAND_FUNC_H |
|
6 #define COMMAND_FUNC_H |
|
7 |
|
8 #include "command_type.h" |
|
9 |
|
10 /** |
|
11 * Checks if a command failes. |
|
12 * |
|
13 * As you see the parameter is not a command but the return value of a command, |
|
14 * the CommandCost class. This function checks if the command executed by |
|
15 * the CommandProc function failed and returns true if it does. |
|
16 * |
|
17 * @param cost The return value of a CommandProc call |
|
18 * @return true if the command failes |
|
19 * @see CmdSucceded |
|
20 */ |
|
21 static inline bool CmdFailed(CommandCost cost) { return cost.Failed(); } |
|
22 |
|
23 /** |
|
24 * Checks if a command succeeded. |
|
25 * |
|
26 * As #CmdFailed this function checks if a command succeeded |
|
27 * |
|
28 * @param cost The return value of a CommandProc call |
|
29 * @return true if the command succeeded |
|
30 * @see CmdSucceeded |
|
31 */ |
|
32 static inline bool CmdSucceeded(CommandCost cost) { return cost.Succeeded(); } |
|
33 |
|
34 /** |
|
35 * Define a default return value for a failed command. |
|
36 * |
|
37 * This variable contains a CommandCost object with is declared as "failed". |
|
38 * Other functions just need to return this error if there is an error, |
|
39 * which doesn't need to specific by a StringID. |
|
40 */ |
|
41 static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID); |
|
42 |
|
43 /** |
|
44 * Returns from a function with a specific StringID as error. |
|
45 * |
|
46 * This macro is used to return from a function. The parameter contains the |
|
47 * StringID which will be returned. |
|
48 * |
|
49 * @param errcode The StringID to return |
|
50 */ |
|
51 #define return_cmd_error(errcode) return CommandCost(errcode); |
|
52 |
|
53 /** |
|
54 * Execute a command |
|
55 */ |
|
56 CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 procc); |
|
57 |
|
58 /** |
|
59 * Execute a network safe DoCommand function |
|
60 */ |
|
61 bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd, bool my_cmd = true); |
|
62 |
|
63 #ifdef ENABLE_NETWORK |
|
64 |
|
65 /** |
|
66 * Send a command over the network |
|
67 */ |
|
68 void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback); |
|
69 #endif /* ENABLE_NETWORK */ |
|
70 |
|
71 /** |
|
72 * Text, which gets sent with a command |
|
73 * |
|
74 * This variable contains a string (be specific a pointer of the first |
|
75 * char of this string) which will be send with a command. This is |
|
76 * used for user input data like names or chat messages. |
|
77 */ |
|
78 extern const char *_cmd_text; |
|
79 extern Money _additional_cash_required; |
|
80 extern StringID _error_message; |
|
81 |
|
82 /** |
|
83 * Checks if a integer value belongs to a command. |
|
84 */ |
|
85 bool IsValidCommand(uint32 cmd); |
|
86 /** |
|
87 * Returns the flags from a given command. |
|
88 */ |
|
89 byte GetCommandFlags(uint32 cmd); |
|
90 /** |
|
91 * Returns the current money available which can be used for a command. |
|
92 */ |
|
93 Money GetAvailableMoneyForCommand(); |
|
94 |
|
95 #endif /* COMMAND_FUNC_H */ |