1
0
Fork 0

(svn r19404) -Codechange: CheckAllowRemoveTunnelBridge() returns a CommandCost.

release/1.1
alberth 2010-03-13 16:38:23 +00:00
parent ce751804e9
commit 19afc9fdc0
1 changed files with 19 additions and 9 deletions

View File

@ -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 */ /* 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)) { switch (GetTunnelBridgeTransportType(tile)) {
case TRANSPORT_ROAD: { case TRANSPORT_ROAD: {
@ -602,17 +606,19 @@ static inline bool CheckAllowRemoveTunnelBridge(TileIndex tile)
/* We can remove unowned road and if the town allows it */ /* 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)) { 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 (road_owner == OWNER_NONE || road_owner == OWNER_TOWN) road_owner = _current_company;
if (tram_owner == OWNER_NONE) tram_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_RAIL:
case TRANSPORT_WATER: case TRANSPORT_WATER:
return CheckOwnership(GetTileOwner(tile)); return CheckOwnership(GetTileOwner(tile)) ? CommandCost() : CMD_ERROR;
default: NOT_REACHED(); default: NOT_REACHED();
} }
@ -623,11 +629,13 @@ static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags)
Town *t = NULL; Town *t = NULL;
TileIndex endtile; TileIndex endtile;
if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR; CommandCost ret = CheckAllowRemoveTunnelBridge(tile);
ret.SetGlobalErrorMessage();
if (ret.Failed()) return ret;
endtile = GetOtherTunnelEnd(tile); endtile = GetOtherTunnelEnd(tile);
CommandCost ret = TunnelBridgeIsFree(tile, endtile); ret = TunnelBridgeIsFree(tile, endtile);
ret.SetGlobalErrorMessage(); ret.SetGlobalErrorMessage();
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
@ -689,11 +697,13 @@ static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags)
TileIndex endtile; TileIndex endtile;
Town *t = NULL; Town *t = NULL;
if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR; CommandCost ret = CheckAllowRemoveTunnelBridge(tile);
ret.SetGlobalErrorMessage();
if (ret.Failed()) return ret;
endtile = GetOtherBridgeEnd(tile); endtile = GetOtherBridgeEnd(tile);
CommandCost ret = TunnelBridgeIsFree(tile, endtile); ret = TunnelBridgeIsFree(tile, endtile);
ret.SetGlobalErrorMessage(); ret.SetGlobalErrorMessage();
if (ret.Failed()) return ret; if (ret.Failed()) return ret;