src/tunnel_map.cpp
changeset 5835 e0ff603ae0b7
parent 5726 8f399788f6c9
child 6307 f40e88cff863
child 6719 4cc327ad39d5
equal deleted inserted replaced
5834:7bf92d5a5a0f 5835:e0ff603ae0b7
       
     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 }