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