|
@@ -583,54 +583,62 @@ CommandCost CmdBuildTunnel(TileIndex sta
|
|
|
}
|
|
|
|
|
|
return cost;
|
|
|
}
|
|
|
|
|
|
|
|
|
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: {
|
|
|
RoadTypes rts = GetRoadTypes(tile);
|
|
|
Owner road_owner = _current_company;
|
|
|
Owner tram_owner = _current_company;
|
|
|
|
|
|
if (HasBit(rts, ROADTYPE_ROAD)) road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
|
|
|
if (HasBit(rts, ROADTYPE_TRAM)) tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
|
|
|
|
|
|
/* 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();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
_build_tunnel_endtile = endtile;
|
|
|
|
|
|
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
|
|
@@ -686,17 +694,19 @@ static CommandCost DoClearBridge(TileInd
|
|
|
{
|
|
|
DiagDirection direction;
|
|
|
TileIndexDiff delta;
|
|
|
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;
|
|
|
|
|
|
direction = GetTunnelBridgeDirection(tile);
|
|
|
delta = TileOffsByDiagDir(direction);
|
|
|
|