src/tunnel_map.c
changeset 5475 2e6990a8c7c4
parent 4559 aa0c13e39840
equal deleted inserted replaced
5474:ac55aefc54f3 5475:2e6990a8c7c4
       
     1 /* $Id$ */
       
     2 
       
     3 #include "stdafx.h"
       
     4 #include "openttd.h"
       
     5 #include "tile.h"
       
     6 #include "tunnel_map.h"
       
     7 
       
     8 TileIndex GetOtherTunnelEnd(TileIndex tile)
       
     9 {
       
    10 	DiagDirection dir = GetTunnelDirection(tile);
       
    11 	TileIndexDiff delta = TileOffsByDiagDir(dir);
       
    12 	uint z = GetTileZ(tile);
       
    13 
       
    14 	dir = ReverseDiagDir(dir);
       
    15 	do {
       
    16 		tile += delta;
       
    17 	} while (
       
    18 		!IsTunnelTile(tile) ||
       
    19 		GetTunnelDirection(tile) != dir ||
       
    20 		GetTileZ(tile) != z
       
    21 	);
       
    22 
       
    23 	return tile;
       
    24 }
       
    25 
       
    26 
       
    27 static bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir)
       
    28 {
       
    29 	TileIndexDiff delta = TileOffsByDiagDir(dir);
       
    30 	uint height;
       
    31 
       
    32 	do {
       
    33 		tile -= delta;
       
    34 		height = GetTileZ(tile);
       
    35 	} while (z < height);
       
    36 
       
    37 	return
       
    38 		z == height &&
       
    39 		IsTunnelTile(tile) &&
       
    40 		GetTunnelDirection(tile) == dir;
       
    41 }
       
    42 
       
    43 bool IsTunnelInWay(TileIndex tile, uint z)
       
    44 {
       
    45 	return
       
    46 		IsTunnelInWayDir(tile, z, DIAGDIR_NE) ||
       
    47 		IsTunnelInWayDir(tile, z, DIAGDIR_SE) ||
       
    48 		IsTunnelInWayDir(tile, z, DIAGDIR_SW) ||
       
    49 		IsTunnelInWayDir(tile, z, DIAGDIR_NW);
       
    50 }