diff options
author | alberth <alberth@openttd.org> | 2010-03-13 16:38:23 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2010-03-13 16:38:23 +0000 |
commit | 19afc9fdc0f009c93f31ea8fccdf95ce1372cc58 (patch) | |
tree | 066b3900d4023504e1bab14d5aa827d1e36814ca /src | |
parent | ce751804e9988b01124ac9df2d9d4367729f0d35 (diff) | |
download | openttd-19afc9fdc0f009c93f31ea8fccdf95ce1372cc58.tar.xz |
(svn r19404) -Codechange: CheckAllowRemoveTunnelBridge() returns a CommandCost.
Diffstat (limited to 'src')
-rw-r--r-- | src/tunnelbridge_cmd.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index a5d724108..654a5db3e 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -586,10 +586,14 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1, } -static inline bool CheckAllowRemoveTunnelBridge(TileIndex tile) +/** Are we allowed to remove the tunnel or bridge at \a tile? + * @param tile End point of the tunnel or bridge. + * @return A succeeded command if the tunnel or bridge may be removed, a failed command otherwise. + */ +static inline CommandCost CheckAllowRemoveTunnelBridge(TileIndex tile) { /* Floods can remove anything as well as the scenario editor */ - if (_current_company == OWNER_WATER || _game_mode == GM_EDITOR) return true; + if (_current_company == OWNER_WATER || _game_mode == GM_EDITOR) return CommandCost(); switch (GetTunnelBridgeTransportType(tile)) { case TRANSPORT_ROAD: { @@ -602,17 +606,19 @@ static inline bool CheckAllowRemoveTunnelBridge(TileIndex tile) /* We can remove unowned road and if the town allows it */ if (road_owner == OWNER_TOWN && !(_settings_game.construction.extra_dynamite || _cheats.magic_bulldozer.value)) { - return CheckTileOwnership(tile).Succeeded(); + CommandCost ret = CheckTileOwnership(tile); + ret.SetGlobalErrorMessage(); + return ret; } if (road_owner == OWNER_NONE || road_owner == OWNER_TOWN) road_owner = _current_company; if (tram_owner == OWNER_NONE) tram_owner = _current_company; - return CheckOwnership(road_owner, tile) && CheckOwnership(tram_owner, tile); + return (CheckOwnership(road_owner, tile) && CheckOwnership(tram_owner, tile)) ? CommandCost() : CMD_ERROR; } case TRANSPORT_RAIL: case TRANSPORT_WATER: - return CheckOwnership(GetTileOwner(tile)); + return CheckOwnership(GetTileOwner(tile)) ? CommandCost() : CMD_ERROR; default: NOT_REACHED(); } @@ -623,11 +629,13 @@ static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags) Town *t = NULL; TileIndex endtile; - if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR; + CommandCost ret = CheckAllowRemoveTunnelBridge(tile); + ret.SetGlobalErrorMessage(); + if (ret.Failed()) return ret; endtile = GetOtherTunnelEnd(tile); - CommandCost ret = TunnelBridgeIsFree(tile, endtile); + ret = TunnelBridgeIsFree(tile, endtile); ret.SetGlobalErrorMessage(); if (ret.Failed()) return ret; @@ -689,11 +697,13 @@ static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags) TileIndex endtile; Town *t = NULL; - if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR; + CommandCost ret = CheckAllowRemoveTunnelBridge(tile); + ret.SetGlobalErrorMessage(); + if (ret.Failed()) return ret; endtile = GetOtherBridgeEnd(tile); - CommandCost ret = TunnelBridgeIsFree(tile, endtile); + ret = TunnelBridgeIsFree(tile, endtile); ret.SetGlobalErrorMessage(); if (ret.Failed()) return ret; |