mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r2195) Add CmdFailed() as the One True Way(tm) to check if a command failed.
This commit is contained in:
parent
3b9931fcba
commit
cada1e24b5
10
command.c
10
command.c
|
@ -349,7 +349,7 @@ int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc)
|
||||||
// only execute the test call if it's toplevel, or we're not execing.
|
// only execute the test call if it's toplevel, or we're not execing.
|
||||||
if (_docommand_recursive == 1 || !(flags & DC_EXEC) || (flags & DC_FORCETEST) ) {
|
if (_docommand_recursive == 1 || !(flags & DC_EXEC) || (flags & DC_FORCETEST) ) {
|
||||||
res = proc(x, y, flags&~DC_EXEC, p1, p2);
|
res = proc(x, y, flags&~DC_EXEC, p1, p2);
|
||||||
if ((uint32)res >> 16 == 0x8000) {
|
if (CmdFailed(res)) {
|
||||||
if (res & 0xFFFF) _error_message = res & 0xFFFF;
|
if (res & 0xFFFF) _error_message = res & 0xFFFF;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -368,7 +368,7 @@ int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc)
|
||||||
/* Execute the command here. All cost-relevant functions set the expenses type
|
/* Execute the command here. All cost-relevant functions set the expenses type
|
||||||
* themselves with "SET_EXPENSES_TYPE(...);" at the beginning of the function */
|
* themselves with "SET_EXPENSES_TYPE(...);" at the beginning of the function */
|
||||||
res = proc(x, y, flags, p1, p2);
|
res = proc(x, y, flags, p1, p2);
|
||||||
if ((uint32)res >> 16 == 0x8000) {
|
if (CmdFailed(res)) {
|
||||||
if (res & 0xFFFF) _error_message = res & 0xFFFF;
|
if (res & 0xFFFF) _error_message = res & 0xFFFF;
|
||||||
error:
|
error:
|
||||||
_docommand_recursive--;
|
_docommand_recursive--;
|
||||||
|
@ -443,7 +443,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
|
||||||
if (_shift_pressed && _current_player == _local_player && !(cmd & (CMD_NETWORK_COMMAND | CMD_SHOW_NO_ERROR))) {
|
if (_shift_pressed && _current_player == _local_player && !(cmd & (CMD_NETWORK_COMMAND | CMD_SHOW_NO_ERROR))) {
|
||||||
// estimate the cost.
|
// estimate the cost.
|
||||||
res = proc(x, y, flags, p1, p2);
|
res = proc(x, y, flags, p1, p2);
|
||||||
if ((uint32)res >> 16 == 0x8000) {
|
if (CmdFailed(res)) {
|
||||||
if (res & 0xFFFF) _error_message = res & 0xFFFF;
|
if (res & 0xFFFF) _error_message = res & 0xFFFF;
|
||||||
ShowErrorMessage(_error_message, _error_message_2, x, y);
|
ShowErrorMessage(_error_message, _error_message_2, x, y);
|
||||||
} else {
|
} else {
|
||||||
|
@ -458,7 +458,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
|
||||||
if (!((cmd & CMD_NO_TEST_IF_IN_NETWORK) && _networking)) {
|
if (!((cmd & CMD_NO_TEST_IF_IN_NETWORK) && _networking)) {
|
||||||
// first test if the command can be executed.
|
// first test if the command can be executed.
|
||||||
res = proc(x,y, flags, p1, p2);
|
res = proc(x,y, flags, p1, p2);
|
||||||
if ((uint32)res >> 16 == 0x8000) {
|
if (CmdFailed(res)) {
|
||||||
if (res & 0xFFFF) _error_message = res & 0xFFFF;
|
if (res & 0xFFFF) _error_message = res & 0xFFFF;
|
||||||
goto show_error;
|
goto show_error;
|
||||||
}
|
}
|
||||||
|
@ -489,7 +489,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
|
||||||
if (!notest && !((cmd & CMD_NO_TEST_IF_IN_NETWORK) && _networking)) {
|
if (!notest && !((cmd & CMD_NO_TEST_IF_IN_NETWORK) && _networking)) {
|
||||||
assert(res == res2); // sanity check
|
assert(res == res2); // sanity check
|
||||||
} else {
|
} else {
|
||||||
if ((uint32)res2 >> 16 == 0x8000) {
|
if (CmdFailed(res)) {
|
||||||
if (res2 & 0xFFFF) _error_message = res2 & 0xFFFF;
|
if (res2 & 0xFFFF) _error_message = res2 & 0xFFFF;
|
||||||
goto show_error;
|
goto show_error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,6 +177,12 @@ enum {
|
||||||
//#define return_cmd_error(errcode) do { _error_message=(errcode); return CMD_ERROR; } while(0)
|
//#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)
|
#define return_cmd_error(errcode) do { return CMD_ERROR | (errcode); } while (0)
|
||||||
|
|
||||||
|
static inline bool CmdFailed(int32 res)
|
||||||
|
{
|
||||||
|
// lower 16bits are the StringID of the possible error
|
||||||
|
return res <= (CMD_ERROR | INVALID_STRING_ID);
|
||||||
|
}
|
||||||
|
|
||||||
/* command.c */
|
/* command.c */
|
||||||
int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc);
|
int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc);
|
||||||
int32 DoCommandByTile(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
|
int32 DoCommandByTile(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
|
||||||
|
|
|
@ -307,7 +307,7 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags,
|
||||||
switch (m5 & 0x38) { // what's under the bridge?
|
switch (m5 & 0x38) { // what's under the bridge?
|
||||||
case 0x00: // clear land
|
case 0x00: // clear land
|
||||||
ret = CheckRailSlope(tileh, rail_bit, 0, tile);
|
ret = CheckRailSlope(tileh, rail_bit, 0, tile);
|
||||||
if (ret & CMD_ERROR) return ret;
|
if (CmdFailed(ret)) return ret;
|
||||||
cost += ret;
|
cost += ret;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
|
@ -340,7 +340,7 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags,
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = CheckRailSlope(tileh, rail_bit, m5 & RAIL_BIT_MASK, tile);
|
ret = CheckRailSlope(tileh, rail_bit, m5 & RAIL_BIT_MASK, tile);
|
||||||
if (ret & CMD_ERROR) return ret;
|
if (CmdFailed(ret)) return ret;
|
||||||
cost += ret;
|
cost += ret;
|
||||||
|
|
||||||
if (flags & DC_EXEC) _map5[tile] = m5 | rail_bit;
|
if (flags & DC_EXEC) _map5[tile] = m5 | rail_bit;
|
||||||
|
@ -370,11 +370,11 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags,
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ret = CheckRailSlope(tileh, rail_bit, 0, tile);
|
ret = CheckRailSlope(tileh, rail_bit, 0, tile);
|
||||||
if (ret & CMD_ERROR) return ret;
|
if (CmdFailed(ret)) return ret;
|
||||||
cost += ret;
|
cost += ret;
|
||||||
|
|
||||||
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||||
if (ret == CMD_ERROR) return ret;
|
if (CmdFailed(ret)) return ret;
|
||||||
cost += ret;
|
cost += ret;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
|
|
Loading…
Reference in New Issue