diff options
author | rubidium <rubidium@openttd.org> | 2007-06-18 19:53:50 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-06-18 19:53:50 +0000 |
commit | 773a7c9cb64856bd2bca11f9c38eea049b353e4e (patch) | |
tree | 62843984493ffedb69f91d7b85cb631ecb61ff3e /src/command.h | |
parent | bcdb89906b06a64c368e89d2f267cd617b2210c1 (diff) | |
download | openttd-773a7c9cb64856bd2bca11f9c38eea049b353e4e.tar.xz |
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
Diffstat (limited to 'src/command.h')
-rw-r--r-- | src/command.h | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/src/command.h b/src/command.h index 177663e0b..c269ed43d 100644 --- a/src/command.h +++ b/src/command.h @@ -164,8 +164,6 @@ enum { DC_AI_BUILDING = 0x20, ///< special building rules for AI DC_NO_TOWN_RATING = 0x40, ///< town rating does not disallow you from building DC_FORCETEST = 0x80, ///< force test too. - - CMD_ERROR = ((int32)0x80000000), }; #define CMD_MSG(x) ((x) << 16) @@ -191,21 +189,12 @@ struct Command { byte flags; }; -//#define return_cmd_error(errcode) do { _error_message=(errcode); return CMD_ERROR; } while(0) -#define return_cmd_error(errcode) do { return CMD_ERROR | (errcode); } while (0) - -/** - * Check the return value of a DoCommand*() function - * @param res the resulting value from the command to be checked - * @return Return true if the command failed, false otherwise - */ -static inline bool CmdFailed(CommandCost res) -{ - /* lower 16bits are the StringID of the possible error */ - return res <= (CMD_ERROR | INVALID_STRING_ID); -} - -static inline bool CmdSucceeded(CommandCost res) { return !CmdFailed(res); } +static inline bool CmdFailed(CommandCost cost) { return cost.Failed(); } +static inline bool CmdSucceeded(CommandCost cost) { return cost.Succeeded(); } + +static const CommandCost CMD_ERROR = CommandCost((StringID)INVALID_STRING_ID); + +#define return_cmd_error(errcode) do { return CommandCost((StringID)(errcode)); } while (0) /* command.cpp */ typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2); |