summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-01-07 13:26:48 +0000
committerrubidium <rubidium@openttd.org>2009-01-07 13:26:48 +0000
commit71df085954a3bccfa273eef8bbb7cfe424a12c41 (patch)
tree975aa0e1838e2849c55a2db051d02c37c41e4a54
parent958e2cb9e4d580ce9440fb73a6083054c51de20e (diff)
downloadopenttd-71df085954a3bccfa273eef8bbb7cfe424a12c41.tar.xz
(svn r14889) -Codechange: replace some magic numbers with constants.
-rw-r--r--src/command.cpp22
-rw-r--r--src/command_type.h2
2 files changed, 14 insertions, 10 deletions
diff --git a/src/command.cpp b/src/command.cpp
index 8a21f9d60..8829875a7 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -350,7 +350,7 @@ static const Command _command_proc_table[] = {
*/
bool IsValidCommand(uint32 cmd)
{
- cmd &= 0xFF;
+ cmd &= CMD_ID_MASK;
return
cmd < lengthof(_command_proc_table) &&
@@ -358,7 +358,7 @@ bool IsValidCommand(uint32 cmd)
}
/*!
- * This function mask the parameter with 0xFF and returns
+ * This function mask the parameter with CMD_ID_MASK and returns
* the flags which belongs to the given command.
*
* @param cmd The integer value of the command
@@ -368,7 +368,7 @@ byte GetCommandFlags(uint32 cmd)
{
assert(IsValidCommand(cmd));
- return _command_proc_table[cmd & 0xFF].flags;
+ return _command_proc_table[cmd & CMD_ID_MASK].flags;
}
static int _docommand_recursive = 0;
@@ -503,8 +503,9 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallbac
if (cmd & CMD_NO_WATER) flags |= DC_NO_WATER;
/* get pointer to command handler */
- assert((cmd & 0xFF) < lengthof(_command_proc_table));
- proc = _command_proc_table[cmd & 0xFF].proc;
+ byte cmd_id = cmd & CMD_ID_MASK;
+ assert(cmd_id < lengthof(_command_proc_table));
+ proc = _command_proc_table[cmd_id].proc;
if (proc == NULL) return false;
if (GetCommandFlags(cmd) & CMD_AUTO) flags |= DC_AUTO;
@@ -521,11 +522,12 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallbac
* CMD_CLONE_VEHICLE: Both building new vehicles and refitting them can be
* influenced by newgrf callbacks, which makes it impossible to accurately
* estimate the cost of cloning a vehicle. */
+
notest =
- (cmd & 0xFF) == CMD_CLEAR_AREA ||
- (cmd & 0xFF) == CMD_LEVEL_LAND ||
- (cmd & 0xFF) == CMD_REMOVE_LONG_ROAD ||
- (cmd & 0xFF) == CMD_CLONE_VEHICLE;
+ cmd_id == CMD_CLEAR_AREA ||
+ cmd_id == CMD_LEVEL_LAND ||
+ cmd_id == CMD_REMOVE_LONG_ROAD ||
+ cmd_id == CMD_CLONE_VEHICLE;
_docommand_recursive = 1;
@@ -534,7 +536,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallbac
_shift_pressed &&
IsLocalCompany() &&
!(cmd & (CMD_NETWORK_COMMAND | CMD_SHOW_NO_ERROR)) &&
- (cmd & 0xFF) != CMD_PAUSE) {
+ cmd_id != CMD_PAUSE) {
/* estimate the cost. */
SetTownRatingTestMode(true);
res = proc(tile, flags, p1, p2, text);
diff --git a/src/command_type.h b/src/command_type.h
index 7a9f8a63c..59e472563 100644
--- a/src/command_type.h
+++ b/src/command_type.h
@@ -328,6 +328,8 @@ enum {
CMD_NETWORK_COMMAND = 0x0800, ///< execute the command without sending it on the network
CMD_NO_TEST_IF_IN_NETWORK = 0x1000, ///< When enabled, the command will bypass the no-DC_EXEC round if in network
CMD_SHOW_NO_ERROR = 0x2000, ///< do not show the error message
+ CMD_FLAGS_MASK = 0xFF00, ///< mask for all command flags
+ CMD_ID_MASK = 0x00FF, ///< mask for the command ID
};
/**