Mercurial > hg > openttd
view src/tunnel_map.cpp @ 6500:ad8ea1f30c99 draft
(svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Fri, 20 Apr 2007 08:00:30 +0000 |
parents | 5459e8d2dc0d |
children | fa75522e0249 |
line wrap: on
line source
/* $Id$ */ /** @file tunnel_map.cpp */ #include "stdafx.h" #include "openttd.h" #include "tile.h" #include "tunnel_map.h" /** * Gets the other end of the tunnel. Where a vehicle would reappear when it * enters at the given tile. * @param tile the tile to search from. * @return the tile of the other end of the tunnel. */ TileIndex GetOtherTunnelEnd(TileIndex tile) { DiagDirection dir = GetTunnelDirection(tile); TileIndexDiff delta = TileOffsByDiagDir(dir); uint z = GetTileZ(tile); dir = ReverseDiagDir(dir); do { tile += delta; } while ( !IsTunnelTile(tile) || GetTunnelDirection(tile) != dir || GetTileZ(tile) != z ); return tile; } /** * Is there a tunnel in the way in the given direction? * @param tile the tile to search from. * @param z the 'z' to search on. * @param dir the direction to start searching to. * @return true if and only if there is a tunnel. */ static bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir) { TileIndexDiff delta = TileOffsByDiagDir(dir); uint height; do { tile -= delta; height = GetTileZ(tile); } while (z < height); return z == height && IsTunnelTile(tile) && GetTunnelDirection(tile) == dir; } /** * Is there a tunnel in the way in any direction? * @param tile the tile to search from. * @param z the 'z' to search on. * @return true if and only if there is a tunnel. */ bool IsTunnelInWay(TileIndex tile, uint z) { return IsTunnelInWayDir(tile, z, DIAGDIR_NE) || IsTunnelInWayDir(tile, z, DIAGDIR_SE) || IsTunnelInWayDir(tile, z, DIAGDIR_SW) || IsTunnelInWayDir(tile, z, DIAGDIR_NW); }