tron@2186: /* $Id$ */ tron@2186: rubidium@8612: /** @file command_func.h Functions related to commands. */ rubidium@8056: rubidium@8612: #ifndef COMMAND_FUNC_H rubidium@8612: #define COMMAND_FUNC_H truelight@0: rubidium@8612: #include "command_type.h" Darkvater@1804: rubidium@8055: /** rubidium@8055: * Checks if a command failes. rubidium@8055: * rubidium@8055: * As you see the parameter is not a command but the return value of a command, rubidium@8055: * the CommandCost class. This function checks if the command executed by rubidium@8055: * the CommandProc function failed and returns true if it does. rubidium@8055: * rubidium@8055: * @param cost The return value of a CommandProc call rubidium@8055: * @return true if the command failes rubidium@8055: * @see CmdSucceded rubidium@8055: */ rubidium@7446: static inline bool CmdFailed(CommandCost cost) { return cost.Failed(); } rubidium@8055: rubidium@8055: /** rubidium@8055: * Checks if a command succeeded. rubidium@8055: * rubidium@8055: * As #CmdFailed this function checks if a command succeeded rubidium@8055: * rubidium@8055: * @param cost The return value of a CommandProc call rubidium@8055: * @return true if the command succeeded rubidium@8055: * @see CmdSucceeded rubidium@8055: */ rubidium@7446: static inline bool CmdSucceeded(CommandCost cost) { return cost.Succeeded(); } truelight@0: rubidium@8055: /** rubidium@8055: * Define a default return value for a failed command. rubidium@8055: * rubidium@8055: * This variable contains a CommandCost object with is declared as "failed". rubidium@8055: * Other functions just need to return this error if there is an error, rubidium@8055: * which doesn't need to specific by a StringID. rubidium@8055: */ peter1138@7889: static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID); tron@1691: rubidium@8055: /** rubidium@8055: * Returns from a function with a specific StringID as error. rubidium@8055: * rubidium@8055: * This macro is used to return from a function. The parameter contains the rubidium@8055: * StringID which will be returned. rubidium@8055: * rubidium@8055: * @param errcode The StringID to return rubidium@8055: */ rubidium@8055: #define return_cmd_error(errcode) return CommandCost(errcode); rubidium@7442: rubidium@8055: /** rubidium@8055: * Execute a command rubidium@8055: */ rubidium@8612: CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 procc); rubidium@8055: rubidium@8055: /** rubidium@8055: * Execute a network safe DoCommand function rubidium@8055: */ rubidium@7718: bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd, bool my_cmd = true); Darkvater@4828: Darkvater@4828: #ifdef ENABLE_NETWORK Darkvater@4828: rubidium@8055: /** rubidium@8055: * Send a command over the network rubidium@8055: */ Darkvater@4828: void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback); Darkvater@4828: #endif /* ENABLE_NETWORK */ truelight@0: rubidium@8055: /** rubidium@8055: * Text, which gets sent with a command rubidium@8055: * rubidium@8055: * This variable contains a string (be specific a pointer of the first rubidium@8055: * char of this string) which will be send with a command. This is rubidium@8055: * used for user input data like names or chat messages. rubidium@8055: */ rubidium@8055: extern const char *_cmd_text; rubidium@8615: extern Money _additional_cash_required; rubidium@8771: extern StringID _error_message; tron@1820: rubidium@8055: /** rubidium@8055: * Checks if a integer value belongs to a command. rubidium@8055: */ rubidium@8612: bool IsValidCommand(uint32 cmd); rubidium@8055: /** rubidium@8055: * Returns the flags from a given command. rubidium@8055: */ rubidium@8612: byte GetCommandFlags(uint32 cmd); rubidium@8055: /** rubidium@8055: * Returns the current money available which can be used for a command. rubidium@8055: */ rubidium@7486: Money GetAvailableMoneyForCommand(); truelight@0: rubidium@8612: #endif /* COMMAND_FUNC_H */