diff options
author | rubidium <rubidium@openttd.org> | 2010-12-07 21:08:35 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-12-07 21:08:35 +0000 |
commit | e170b1d83e0142fdcc4260a2f3d623324de1415f (patch) | |
tree | 066710c1cb2ee5e81b177ca38203c95324149ac5 | |
parent | df410fd7ed6a4ad36d59f4eb9c84138437cb8a0c (diff) | |
download | openttd-e170b1d83e0142fdcc4260a2f3d623324de1415f.tar.xz |
(svn r21427) -Add: helper function to determine whether a command may be executed
-rw-r--r-- | src/command.cpp | 25 | ||||
-rw-r--r-- | src/command_func.h | 2 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/command.cpp b/src/command.cpp index 70717d777..be30d11e6 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -349,6 +349,31 @@ const char *GetCommandName(uint32 cmd) return _command_proc_table[cmd & CMD_ID_MASK].name; } +/** + * Returns whether the command is allowed while the game is paused. + * @param cmd The command to check. + * @return True if the command is allowed while paused, false otherwise. + */ +bool IsCommandAllowedWhilePaused(uint32 cmd) +{ + /* Lookup table for the command types that are allowed for a given pause level setting. */ + static const int command_type_lookup[] = { + CMDPL_ALL_ACTIONS, ///< CMDT_LANDSCAPE_CONSTRUCTION + CMDPL_NO_LANDSCAPING, ///< CMDT_VEHICLE_CONSTRUCTION + CMDPL_NO_LANDSCAPING, ///< CMDT_MONEY_MANAGEMENT + CMDPL_NO_CONSTRUCTION, ///< CMDT_VEHICLE_MANAGEMENT + CMDPL_NO_CONSTRUCTION, ///< CMDT_ROUTE_MANAGEMENT + CMDPL_NO_CONSTRUCTION, ///< CMDT_OTHER_MANAGEMENT + CMDPL_NO_CONSTRUCTION, ///< CMDT_COMPANY_SETTING + CMDPL_NO_ACTIONS, ///< CMDT_SERVER_SETTING + }; + assert_compile(lengthof(command_type_lookup) == CMDT_END); + + assert(IsValidCommand(cmd)); + return command_type_lookup[_command_proc_table[cmd & CMD_ID_MASK].type] <= _settings_game.construction.command_pause_level; +} + + static int _docommand_recursive = 0; /** diff --git a/src/command_func.h b/src/command_func.h index 3ed4d1e60..212e71ddf 100644 --- a/src/command_func.h +++ b/src/command_func.h @@ -75,6 +75,8 @@ const char *GetCommandName(uint32 cmd); */ Money GetAvailableMoneyForCommand(); +bool IsCommandAllowedWhilePaused(uint32 cmd); + /** * Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags * @param cmd_flags Flags from GetCommandFlags |