tunnel_map.cpp

Go to the documentation of this file.
00001 /* $Id: tunnel_map.cpp 17248 2009-08-21 20:21:05Z 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 "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
00060     z == height &&
00061     IsTunnelTile(tile) &&
00062     GetTunnelBridgeDirection(tile) == dir;
00063 }
00064 
00071 bool IsTunnelInWay(TileIndex tile, uint z)
00072 {
00073   return
00074     IsTunnelInWayDir(tile, z, (TileX(tile) > (MapMaxX() / 2)) ? DIAGDIR_NE : DIAGDIR_SW) ||
00075     IsTunnelInWayDir(tile, z, (TileY(tile) > (MapMaxY() / 2)) ? DIAGDIR_NW : DIAGDIR_SE);
00076 }

Generated on Wed Mar 17 23:50:18 2010 for OpenTTD by  doxygen 1.6.1