mirror of https://github.com/OpenTTD/OpenTTD
(svn r11965) -Codechange: simplified tunnel/bridge code in TPFMode1
parent
b718cae67d
commit
4cb91fa591
|
@ -220,50 +220,31 @@ FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, DiagDirection dir)
|
||||||
|
|
||||||
static const uint16 _tpfmode1_and[4] = { 0x1009, 0x16, 0x520, 0x2A00 };
|
static const uint16 _tpfmode1_and[4] = { 0x1009, 0x16, 0x520, 0x2A00 };
|
||||||
|
|
||||||
static uint SkipToEndOfTunnel(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
|
|
||||||
{
|
|
||||||
FindLengthOfTunnelResult flotr;
|
|
||||||
TPFSetTileBit(tpf, tile, 14);
|
|
||||||
flotr = FindLengthOfTunnel(tile, direction);
|
|
||||||
tpf->rd.cur_length += flotr.length;
|
|
||||||
TPFSetTileBit(tpf, flotr.tile, 14);
|
|
||||||
return flotr.tile;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
|
static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
|
||||||
{
|
{
|
||||||
TileIndex tile_org = tile;
|
const TileIndex tile_org = tile;
|
||||||
|
|
||||||
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
||||||
if (IsTunnel(tile)) {
|
/* wrong track type */
|
||||||
if (GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
|
if (GetTunnelBridgeTransportType(tile) != tpf->tracktype) return;
|
||||||
return;
|
|
||||||
}
|
DiagDirection dir = GetTunnelBridgeDirection(tile);
|
||||||
/* Only skip through the tunnel if heading inwards. We can
|
/* entering tunnel / bridge? */
|
||||||
* be headed outwards if our starting position was in a
|
if (dir == direction) {
|
||||||
* tunnel and we're pathfinding backwards */
|
TileIndex endtile = GetOtherTunnelBridgeEnd(tile);
|
||||||
if (GetTunnelBridgeDirection(tile) == direction) {
|
|
||||||
tile = SkipToEndOfTunnel(tpf, tile, direction);
|
tpf->rd.cur_length += DistanceManhattan(tile, endtile);
|
||||||
} else if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) {
|
|
||||||
/* We don't support moving through the sides of a tunnel
|
|
||||||
* entrance :-) */
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else { // IsBridge(tile)
|
|
||||||
TileIndex tile_end;
|
|
||||||
if (GetTunnelBridgeDirection(tile) != direction ||
|
|
||||||
GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//fprintf(stderr, "%s: Planning over bridge\n", __func__);
|
|
||||||
// TODO doesn't work - WHAT doesn't work?
|
|
||||||
TPFSetTileBit(tpf, tile, 14);
|
|
||||||
tile_end = GetOtherBridgeEnd(tile);
|
|
||||||
tpf->rd.cur_length += DistanceManhattan(tile, tile_end);
|
|
||||||
tile = tile_end;
|
|
||||||
TPFSetTileBit(tpf, tile, 14);
|
TPFSetTileBit(tpf, tile, 14);
|
||||||
|
TPFSetTileBit(tpf, endtile, 14);
|
||||||
|
|
||||||
|
tile = endtile;
|
||||||
|
} else {
|
||||||
|
/* leaving tunnel / bridge? */
|
||||||
|
if (ReverseDiagDir(dir) != direction) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tile += TileOffsByDiagDir(direction);
|
tile += TileOffsByDiagDir(direction);
|
||||||
|
|
||||||
/* Check in case of rail if the owner is the same */
|
/* Check in case of rail if the owner is the same */
|
||||||
|
|
Loading…
Reference in New Issue