author | Tero Marttila <terom@fixme.fi> |
Fri, 18 Jul 2008 21:28:42 +0300 | |
changeset 11175 | 020c61e39c94 |
parent 8771 | f7ad4dba14bf |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8056
diff
changeset
|
3 |
/** @file command_func.h Functions related to commands. */ |
8056
1020455bfd81
(svn r11085) -Fix-ish (r11084): some tabs that did not show up in the diff, which caused a mess of tab and non-tab usage.
rubidium
parents:
8055
diff
changeset
|
4 |
|
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8056
diff
changeset
|
5 |
#ifndef COMMAND_FUNC_H |
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8056
diff
changeset
|
6 |
#define COMMAND_FUNC_H |
0 | 7 |
|
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8056
diff
changeset
|
8 |
#include "command_type.h" |
1804
7810fc0aa941
(svn r2308) - Fix: enforce server-only and/or offline commands by giving them flags in the process table. This also fixes bug "[ 1190944 ] Many commands not checked for security"
Darkvater
parents:
1796
diff
changeset
|
9 |
|
8055
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
10 |
/** |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
11 |
* Checks if a command failes. |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
12 |
* |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
13 |
* As you see the parameter is not a command but the return value of a command, |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
14 |
* the CommandCost class. This function checks if the command executed by |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
15 |
* the CommandProc function failed and returns true if it does. |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
16 |
* |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
17 |
* @param cost The return value of a CommandProc call |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
18 |
* @return true if the command failes |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
19 |
* @see CmdSucceded |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
20 |
*/ |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
21 |
static inline bool CmdFailed(CommandCost cost) { return cost.Failed(); } |
8055
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
22 |
|
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
23 |
/** |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
24 |
* Checks if a command succeeded. |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
25 |
* |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
26 |
* As #CmdFailed this function checks if a command succeeded |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
27 |
* |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
28 |
* @param cost The return value of a CommandProc call |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
29 |
* @return true if the command succeeded |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
30 |
* @see CmdSucceeded |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
31 |
*/ |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
32 |
static inline bool CmdSucceeded(CommandCost cost) { return cost.Succeeded(); } |
0 | 33 |
|
8055
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
34 |
/** |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
35 |
* Define a default return value for a failed command. |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
36 |
* |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
37 |
* This variable contains a CommandCost object with is declared as "failed". |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
38 |
* Other functions just need to return this error if there is an error, |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
39 |
* which doesn't need to specific by a StringID. |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
40 |
*/ |
7889
f167f5959c24
(svn r10762) -Codechange: Change enum StringIDEnum { to static const StringID = for
peter1138
parents:
7718
diff
changeset
|
41 |
static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID); |
1691
fcd9fefaed02
(svn r2195) Add CmdFailed() as the One True Way(tm) to check if a command failed.
tron
parents:
1623
diff
changeset
|
42 |
|
8055
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
43 |
/** |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
44 |
* Returns from a function with a specific StringID as error. |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
45 |
* |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
46 |
* This macro is used to return from a function. The parameter contains the |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
47 |
* StringID which will be returned. |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
48 |
* |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
49 |
* @param errcode The StringID to return |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
50 |
*/ |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
51 |
#define return_cmd_error(errcode) return CommandCost(errcode); |
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
52 |
|
8055
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
53 |
/** |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
54 |
* Execute a command |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
55 |
*/ |
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8056
diff
changeset
|
56 |
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 procc); |
8055
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
57 |
|
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
58 |
/** |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
59 |
* Execute a network safe DoCommand function |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
60 |
*/ |
7718
220603f0122e
(svn r10501) -Fix [FS#1015]: error dialog was sometimes shown on all clients when a command failed instead of only the client that actually did the command.
rubidium
parents:
7562
diff
changeset
|
61 |
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd, bool my_cmd = true); |
4828
9e32eafd4657
(svn r6752) -Codechange: Move command functions from messy functions.h into command.h
Darkvater
parents:
4712
diff
changeset
|
62 |
|
9e32eafd4657
(svn r6752) -Codechange: Move command functions from messy functions.h into command.h
Darkvater
parents:
4712
diff
changeset
|
63 |
#ifdef ENABLE_NETWORK |
9e32eafd4657
(svn r6752) -Codechange: Move command functions from messy functions.h into command.h
Darkvater
parents:
4712
diff
changeset
|
64 |
|
8055
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
65 |
/** |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
66 |
* Send a command over the network |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
67 |
*/ |
4828
9e32eafd4657
(svn r6752) -Codechange: Move command functions from messy functions.h into command.h
Darkvater
parents:
4712
diff
changeset
|
68 |
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback); |
9e32eafd4657
(svn r6752) -Codechange: Move command functions from messy functions.h into command.h
Darkvater
parents:
4712
diff
changeset
|
69 |
#endif /* ENABLE_NETWORK */ |
0 | 70 |
|
8055
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
71 |
/** |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
72 |
* Text, which gets sent with a command |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
73 |
* |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
74 |
* This variable contains a string (be specific a pointer of the first |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
75 |
* char of this string) which will be send with a command. This is |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
76 |
* used for user input data like names or chat messages. |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
77 |
*/ |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
78 |
extern const char *_cmd_text; |
8615
6b91ca653bad
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents:
8612
diff
changeset
|
79 |
extern Money _additional_cash_required; |
8771
f7ad4dba14bf
(svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents:
8615
diff
changeset
|
80 |
extern StringID _error_message; |
1820
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1804
diff
changeset
|
81 |
|
8055
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
82 |
/** |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
83 |
* Checks if a integer value belongs to a command. |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
84 |
*/ |
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8056
diff
changeset
|
85 |
bool IsValidCommand(uint32 cmd); |
8055
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
86 |
/** |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
87 |
* Returns the flags from a given command. |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
88 |
*/ |
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8056
diff
changeset
|
89 |
byte GetCommandFlags(uint32 cmd); |
8055
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
90 |
/** |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
91 |
* Returns the current money available which can be used for a command. |
07697c701048
(svn r11084) -Documentation [FS#1219]: of command.*. Patch by Progman.
rubidium
parents:
8017
diff
changeset
|
92 |
*/ |
7486
d130c10f4dab
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents:
7476
diff
changeset
|
93 |
Money GetAvailableMoneyForCommand(); |
0 | 94 |
|
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8056
diff
changeset
|
95 |
#endif /* COMMAND_FUNC_H */ |