Changeset - r14804:e5dbb4dc2a7e
[Not reviewed]
master
0 1 0
alberth - 14 years ago 2010-03-13 16:38:23
alberth@openttd.org
(svn r19404) -Codechange: CheckAllowRemoveTunnelBridge() returns a CommandCost.
1 file changed with 19 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -586,10 +586,14 @@ CommandCost CmdBuildTunnel(TileIndex sta
 
}
 

	
 

	
 
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 CheckAllowRemoveTunne
 

	
 
			/* 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(TileInd
 
	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(TileInd
 
	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;
 

	
0 comments (0 inline, 0 general)