npf.c
changeset 3154 6ab0cb6b7ab3
parent 3147 fc76d566a68e
child 3179 8ef3e8028af5
equal deleted inserted replaced
3153:e83501906eae 3154:6ab0cb6b7ab3
     9 #include "macros.h"
     9 #include "macros.h"
    10 #include "pathfind.h"
    10 #include "pathfind.h"
    11 #include "station.h"
    11 #include "station.h"
    12 #include "tile.h"
    12 #include "tile.h"
    13 #include "depot.h"
    13 #include "depot.h"
       
    14 #include "tunnel_map.h"
    14 
    15 
    15 static AyStar _npf_aystar;
    16 static AyStar _npf_aystar;
    16 
    17 
    17 /* The cost of each trackdir. A diagonal piece is the full NPF_TILE_LENGTH,
    18 /* The cost of each trackdir. A diagonal piece is the full NPF_TILE_LENGTH,
    18  * the shorter piece is sqrt(2)/2*NPF_TILE_LENGTH =~ 0.7071
    19  * the shorter piece is sqrt(2)/2*NPF_TILE_LENGTH =~ 0.7071
   160  * including the exit tile. Requires that this is a Tunnel tile */
   161  * including the exit tile. Requires that this is a Tunnel tile */
   161 static uint NPFTunnelCost(AyStarNode* current)
   162 static uint NPFTunnelCost(AyStarNode* current)
   162 {
   163 {
   163 	DiagDirection exitdir = TrackdirToExitdir((Trackdir)current->direction);
   164 	DiagDirection exitdir = TrackdirToExitdir((Trackdir)current->direction);
   164 	TileIndex tile = current->tile;
   165 	TileIndex tile = current->tile;
   165 	if ((DiagDirection)GB(_m[tile].m5, 0, 2) == ReverseDiagDir(exitdir)) {
   166 	if (GetTunnelDirection(tile) == ReverseDiagDir(exitdir)) {
   166 		/* We just popped out if this tunnel, since were
   167 		/* We just popped out if this tunnel, since were
   167 		 * facing the tunnel exit */
   168 		 * facing the tunnel exit */
   168 		FindLengthOfTunnelResult flotr;
   169 		FindLengthOfTunnelResult flotr;
   169 		flotr = FindLengthOfTunnel(tile, ReverseDiagDir(exitdir));
   170 		flotr = FindLengthOfTunnel(tile, ReverseDiagDir(exitdir));
   170 		return flotr.length * NPF_TILE_LENGTH;
   171 		return flotr.length * NPF_TILE_LENGTH;
   517 	DEBUG(npf, 4)("Expanding: (%d, %d, %d) [%d]", TileX(src_tile), TileY(src_tile), src_trackdir, src_tile);
   518 	DEBUG(npf, 4)("Expanding: (%d, %d, %d) [%d]", TileX(src_tile), TileY(src_tile), src_trackdir, src_tile);
   518 
   519 
   519 	/* Find dest tile */
   520 	/* Find dest tile */
   520 	if (IsTileType(src_tile, MP_TUNNELBRIDGE) &&
   521 	if (IsTileType(src_tile, MP_TUNNELBRIDGE) &&
   521 			GB(_m[src_tile].m5, 4, 4) == 0 &&
   522 			GB(_m[src_tile].m5, 4, 4) == 0 &&
   522 			(DiagDirection)GB(_m[src_tile].m5, 0, 2) == src_exitdir) {
   523 			GetTunnelDirection(src_tile) == src_exitdir) {
   523 		/* This is a tunnel. We know this tunnel is our type,
   524 		/* This is a tunnel. We know this tunnel is our type,
   524 		 * otherwise we wouldn't have got here. It is also facing us,
   525 		 * otherwise we wouldn't have got here. It is also facing us,
   525 		 * so we should skip it's body */
   526 		 * so we should skip it's body */
   526 		flotr = FindLengthOfTunnel(src_tile, src_exitdir);
   527 		flotr = FindLengthOfTunnel(src_tile, src_exitdir);
   527 		dst_tile = flotr.tile;
   528 		dst_tile = flotr.tile;