tunnel_map.cpp

Go to the documentation of this file.
00001 /* $Id: tunnel_map.cpp 21273 2010-11-20 15:44:24Z alberth $ */
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 "tunnelbridge_map.h"
00014 
00015 
00022 TileIndex GetOtherTunnelEnd(TileIndex tile)
00023 {
00024   DiagDirection dir = GetTunnelBridgeDirection(tile);
00025   TileIndexDiff delta = TileOffsByDiagDir(dir);
00026   uint z = GetTileZ(tile);
00027 
00028   dir = ReverseDiagDir(dir);
00029   do {
00030     tile += delta;
00031   } while (
00032     !IsTunnelTile(tile) ||
00033     GetTunnelBridgeDirection(tile) != dir ||
00034     GetTileZ(tile) != z
00035   );
00036 
00037   return tile;
00038 }
00039 
00040 
00048 bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir)
00049 {
00050   TileIndexDiff delta = TileOffsByDiagDir(dir);
00051   uint height;
00052 
00053   do {
00054     tile -= delta;
00055     if (!IsValidTile(tile)) return false;
00056     height = GetTileZ(tile);
00057   } while (z < height);
00058 
00059   return z == height && IsTunnelTile(tile) && GetTunnelBridgeDirection(tile) == dir;
00060 }
00061 
00068 bool IsTunnelInWay(TileIndex tile, uint z)
00069 {
00070   return IsTunnelInWayDir(tile, z, (TileX(tile) > (MapMaxX() / 2)) ? DIAGDIR_NE : DIAGDIR_SW) ||
00071       IsTunnelInWayDir(tile, z, (TileY(tile) > (MapMaxY() / 2)) ? DIAGDIR_NW : DIAGDIR_SE);
00072 }

Generated on Fri Feb 4 20:53:49 2011 for OpenTTD by  doxygen 1.6.1