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