2006-03-06 20:55:24 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "openttd.h"
|
|
|
|
#include "tile.h"
|
|
|
|
#include "tunnel_map.h"
|
|
|
|
|
|
|
|
TileIndex GetOtherTunnelEnd(TileIndex tile)
|
|
|
|
{
|
|
|
|
DiagDirection dir = GetTunnelDirection(tile);
|
2006-09-05 23:21:41 +00:00
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(dir);
|
2006-03-06 20:55:24 +00:00
|
|
|
uint z = GetTileZ(tile);
|
|
|
|
|
|
|
|
dir = ReverseDiagDir(dir);
|
|
|
|
do {
|
|
|
|
tile += delta;
|
|
|
|
} while (
|
2006-03-12 15:04:03 +00:00
|
|
|
!IsTunnelTile(tile) ||
|
2006-03-06 20:55:24 +00:00
|
|
|
GetTunnelDirection(tile) != dir ||
|
|
|
|
GetTileZ(tile) != z
|
|
|
|
);
|
|
|
|
|
|
|
|
return tile;
|
|
|
|
}
|
2006-03-07 07:51:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
static bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir)
|
|
|
|
{
|
2006-09-05 23:21:41 +00:00
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(dir);
|
2006-03-07 07:51:05 +00:00
|
|
|
uint height;
|
|
|
|
|
|
|
|
do {
|
|
|
|
tile -= delta;
|
|
|
|
height = GetTileZ(tile);
|
|
|
|
} while (z < height);
|
|
|
|
|
|
|
|
return
|
|
|
|
z == height &&
|
2006-03-12 15:04:03 +00:00
|
|
|
IsTunnelTile(tile) &&
|
2006-03-07 07:51:05 +00:00
|
|
|
GetTunnelDirection(tile) == dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|