src/tunnel_map.cpp
author maedhros
Mon, 16 Apr 2007 10:59:35 +0000
changeset 6472 f1e70dc23fac
parent 6422 6679df1c05ba
child 6489 511474c82dd3
permissions -rw-r--r--
(svn r9648) -Codechange: Use HASBIT directly rather than shifting and then using it on the first bit.
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
     1
/* $Id$ */
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
     2
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 5584
diff changeset
     3
/** @file tunnel_map.cpp */
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 5584
diff changeset
     4
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
     5
#include "stdafx.h"
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
     6
#include "openttd.h"
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
     7
#include "tile.h"
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
     8
#include "tunnel_map.h"
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
     9
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
    10
TileIndex GetOtherTunnelEnd(TileIndex tile)
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
    11
{
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
    12
	DiagDirection dir = GetTunnelDirection(tile);
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4291
diff changeset
    13
	TileIndexDiff delta = TileOffsByDiagDir(dir);
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
    14
	uint z = GetTileZ(tile);
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
    15
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
    16
	dir = ReverseDiagDir(dir);
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
    17
	do {
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
    18
		tile += delta;
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
    19
	} while (
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3156
diff changeset
    20
		!IsTunnelTile(tile) ||
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
    21
		GetTunnelDirection(tile) != dir ||
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
    22
		GetTileZ(tile) != z
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
    23
	);
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
    24
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
    25
	return tile;
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents:
diff changeset
    26
}
3156
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    27
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    28
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    29
static bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir)
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    30
{
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4291
diff changeset
    31
	TileIndexDiff delta = TileOffsByDiagDir(dir);
3156
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    32
	uint height;
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    33
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    34
	do {
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    35
		tile -= delta;
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    36
		height = GetTileZ(tile);
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    37
	} while (z < height);
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    38
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    39
	return
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    40
		z == height &&
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3156
diff changeset
    41
		IsTunnelTile(tile) &&
3156
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    42
		GetTunnelDirection(tile) == dir;
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    43
}
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    44
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    45
bool IsTunnelInWay(TileIndex tile, uint z)
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    46
{
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    47
	return
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    48
		IsTunnelInWayDir(tile, z, DIAGDIR_NE) ||
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    49
		IsTunnelInWayDir(tile, z, DIAGDIR_SE) ||
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    50
		IsTunnelInWayDir(tile, z, DIAGDIR_SW) ||
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    51
		IsTunnelInWayDir(tile, z, DIAGDIR_NW);
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
    52
}