00001 /* $Id: bridge_map.cpp 21844 2011-01-18 22:17:15Z rubidium $ */ 00002 00003 /* 00004 * This file is part of OpenTTD. 00005 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. 00006 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00007 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. 00008 */ 00009 00012 #include "stdafx.h" 00013 #include "landscape.h" 00014 #include "tunnelbridge_map.h" 00015 00016 00022 static TileIndex GetBridgeEnd(TileIndex tile, DiagDirection dir) 00023 { 00024 TileIndexDiff delta = TileOffsByDiagDir(dir); 00025 00026 dir = ReverseDiagDir(dir); 00027 do { 00028 tile += delta; 00029 } while (!IsBridgeTile(tile) || GetTunnelBridgeDirection(tile) != dir); 00030 00031 return tile; 00032 } 00033 00034 00039 TileIndex GetNorthernBridgeEnd(TileIndex t) 00040 { 00041 return GetBridgeEnd(t, ReverseDiagDir(AxisToDiagDir(GetBridgeAxis(t)))); 00042 } 00043 00044 00049 TileIndex GetSouthernBridgeEnd(TileIndex t) 00050 { 00051 return GetBridgeEnd(t, AxisToDiagDir(GetBridgeAxis(t))); 00052 } 00053 00054 00059 TileIndex GetOtherBridgeEnd(TileIndex tile) 00060 { 00061 assert(IsBridgeTile(tile)); 00062 return GetBridgeEnd(tile, GetTunnelBridgeDirection(tile)); 00063 } 00064 00070 uint GetBridgeHeight(TileIndex t) 00071 { 00072 uint h; 00073 Slope tileh = GetTileSlope(t, &h); 00074 Foundation f = GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(t))); 00075 00076 /* one height level extra for the ramp */ 00077 return h + TILE_HEIGHT + ApplyFoundationToSlope(f, &tileh); 00078 }