00001 /* $Id: tunnel_map.cpp 11669 2007-12-19 23:26:02Z rubidium $ */ 00002 00005 #include "stdafx.h" 00006 #include "openttd.h" 00007 #include "tunnel_map.h" 00008 #include "tunnelbridge_map.h" 00009 00010 00017 TileIndex GetOtherTunnelEnd(TileIndex tile) 00018 { 00019 DiagDirection dir = GetTunnelBridgeDirection(tile); 00020 TileIndexDiff delta = TileOffsByDiagDir(dir); 00021 uint z = GetTileZ(tile); 00022 00023 dir = ReverseDiagDir(dir); 00024 do { 00025 tile += delta; 00026 } while ( 00027 !IsTunnelTile(tile) || 00028 GetTunnelBridgeDirection(tile) != dir || 00029 GetTileZ(tile) != z 00030 ); 00031 00032 return tile; 00033 } 00034 00035 00043 bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir) 00044 { 00045 TileIndexDiff delta = TileOffsByDiagDir(dir); 00046 uint height; 00047 00048 do { 00049 tile -= delta; 00050 height = GetTileZ(tile); 00051 } while (z < height); 00052 00053 return 00054 z == height && 00055 IsTunnelTile(tile) && 00056 GetTunnelBridgeDirection(tile) == dir; 00057 } 00058 00065 bool IsTunnelInWay(TileIndex tile, uint z) 00066 { 00067 return 00068 IsTunnelInWayDir(tile, z, (TileX(tile) > (MapMaxX() / 2)) ? DIAGDIR_NE : DIAGDIR_SW) || 00069 IsTunnelInWayDir(tile, z, (TileY(tile) > (MapMaxY() / 2)) ? DIAGDIR_NW : DIAGDIR_SE); 00070 }