tunnel_map.cpp

Go to the documentation of this file.
00001 /* $Id: tunnel_map.cpp 15299 2009-01-31 20:16:06Z smatz $ */
00002 
00005 #include "stdafx.h"
00006 #include "tunnelbridge_map.h"
00007 
00008 
00015 TileIndex GetOtherTunnelEnd(TileIndex tile)
00016 {
00017   DiagDirection dir = GetTunnelBridgeDirection(tile);
00018   TileIndexDiff delta = TileOffsByDiagDir(dir);
00019   uint z = GetTileZ(tile);
00020 
00021   dir = ReverseDiagDir(dir);
00022   do {
00023     tile += delta;
00024   } while (
00025     !IsTunnelTile(tile) ||
00026     GetTunnelBridgeDirection(tile) != dir ||
00027     GetTileZ(tile) != z
00028   );
00029 
00030   return tile;
00031 }
00032 
00033 
00041 bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir)
00042 {
00043   TileIndexDiff delta = TileOffsByDiagDir(dir);
00044   uint height;
00045 
00046   do {
00047     tile -= delta;
00048     if (!IsValidTile(tile)) return false;
00049     height = GetTileZ(tile);
00050   } while (z < height);
00051 
00052   return
00053     z == height &&
00054     IsTunnelTile(tile) &&
00055     GetTunnelBridgeDirection(tile) == dir;
00056 }
00057 
00064 bool IsTunnelInWay(TileIndex tile, uint z)
00065 {
00066   return
00067     IsTunnelInWayDir(tile, z, (TileX(tile) > (MapMaxX() / 2)) ? DIAGDIR_NE : DIAGDIR_SW) ||
00068     IsTunnelInWayDir(tile, z, (TileY(tile) > (MapMaxY() / 2)) ? DIAGDIR_NW : DIAGDIR_SE);
00069 }

Generated on Tue Dec 1 00:06:21 2009 for OpenTTD by  doxygen 1.5.6