Mercurial > hg > openttd
view src/tunnel_map.cpp @ 10480:649ba332458f draft
(svn r14735) -Codechange: remove a bit of bit-waste in the map array (without changing the map array) and make the CompanyIDs contiguous.
-Note: 15 should be enough for now... making it any more means adding more bytes to the map array and thus wasting more bits instead of reducing the bit waste.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 24 Dec 2008 09:53:15 +0000 |
parents | d48433370037 |
children | 7881d9cd55ab |
line wrap: on
line source
/* $Id$ */ /** @file tunnel_map.cpp Map accessors for tunnels. */ #include "stdafx.h" #include "openttd.h" #include "tunnel_map.h" #include "tunnelbridge_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 = GetTunnelBridgeDirection(tile); TileIndexDiff delta = TileOffsByDiagDir(dir); uint z = GetTileZ(tile); dir = ReverseDiagDir(dir); do { tile += delta; } while ( !IsTunnelTile(tile) || GetTunnelBridgeDirection(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. */ 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) && GetTunnelBridgeDirection(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, (TileX(tile) > (MapMaxX() / 2)) ? DIAGDIR_NE : DIAGDIR_SW) || IsTunnelInWayDir(tile, z, (TileY(tile) > (MapMaxY() / 2)) ? DIAGDIR_NW : DIAGDIR_SE); }