diff options
author | tron <tron@openttd.org> | 2006-03-12 12:19:25 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2006-03-12 12:19:25 +0000 |
commit | 7a0071cc531b7c3fe03293360acec28e889a4532 (patch) | |
tree | a2aa298975f3b0ba6fb0889afdfb76c415951aa7 /water_cmd.c | |
parent | 367b09a1f92d4d54c79e0256cff7c86e96bbc3fb (diff) | |
download | openttd-7a0071cc531b7c3fe03293360acec28e889a4532.tar.xz |
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
Diffstat (limited to 'water_cmd.c')
-rw-r--r-- | water_cmd.c | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/water_cmd.c b/water_cmd.c index cd7087e3b..24a08db03 100644 --- a/water_cmd.c +++ b/water_cmd.c @@ -236,43 +236,45 @@ int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2) BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) { if (GetTileSlope(tile, NULL) != 0) return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); - // can't make water of water! - if (IsTileType(tile, MP_WATER)) { - _error_message = STR_1007_ALREADY_BUILT; - } else { - /* is middle piece of a bridge? */ - if (IsTileType(tile, MP_TUNNELBRIDGE) && _m[tile].m5 & 0x40) { /* build under bridge */ - if (_m[tile].m5 & 0x20) // transport route under bridge - return_cmd_error(STR_5800_OBJECT_IN_THE_WAY); - - if (_m[tile].m5 & 0x18) { // already water under bridge - return_cmd_error(STR_1007_ALREADY_BUILT); - } - - if (flags & DC_EXEC) { - // change owner to OWNER_WATER and set land under bridge bit to water - ModifyTile(tile, MP_MAP5 | MP_MAPOWNER, OWNER_WATER, _m[tile].m5 | 0x08); - } - } else { - /* no bridge, try to clear it. */ - int32 ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); - - if (CmdFailed(ret)) return CMD_ERROR; - cost += ret; - - if (flags & DC_EXEC) { - MakeWater(tile); - MarkTileDirtyByTile(tile); - } - } + // can't make water of water! + if (IsTileType(tile, MP_WATER)) continue; - if (flags & DC_EXEC) MarkTilesAroundDirty(tile); + /* is middle piece of a bridge? */ + if (IsTileType(tile, MP_TUNNELBRIDGE) && _m[tile].m5 & 0x40) { /* build under bridge */ + if (_m[tile].m5 & 0x20) // transport route under bridge + return_cmd_error(STR_5800_OBJECT_IN_THE_WAY); + + if (_m[tile].m5 & 0x18) { // already water under bridge + return_cmd_error(STR_1007_ALREADY_BUILT); + } - cost += _price.clear_water; + if (flags & DC_EXEC) { + // change owner to OWNER_WATER and set land under bridge bit to water + ModifyTile(tile, MP_MAP5 | MP_MAPOWNER, OWNER_WATER, _m[tile].m5 | 0x08); } + } else { + /* no bridge, try to clear it. */ + int32 ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); + + if (CmdFailed(ret)) return ret; + cost += ret; + + if (flags & DC_EXEC) { + MakeWater(tile); + MarkTileDirtyByTile(tile); + } + } + + if (flags & DC_EXEC) MarkTilesAroundDirty(tile); + + cost += _price.clear_water; } END_TILE_LOOP(tile, size_x, size_y, 0); - return (cost == 0) ? CMD_ERROR : cost; + if (cost == 0) { + return_cmd_error(STR_1007_ALREADY_BUILT); + } else { + return cost; + } } static int32 ClearTile_Water(TileIndex tile, byte flags) |