17 #include "tile.h" |
17 #include "tile.h" |
18 #include "depot.h" |
18 #include "depot.h" |
19 #include "tunnel_map.h" |
19 #include "tunnel_map.h" |
20 #include "network/network.h" |
20 #include "network/network.h" |
21 #include "water_map.h" |
21 #include "water_map.h" |
|
22 #include "tunnelbridge_map.h" |
22 |
23 |
23 static AyStar _npf_aystar; |
24 static AyStar _npf_aystar; |
24 |
25 |
25 /* The cost of each trackdir. A diagonal piece is the full NPF_TILE_LENGTH, |
26 /* The cost of each trackdir. A diagonal piece is the full NPF_TILE_LENGTH, |
26 * the shorter piece is sqrt(2)/2*NPF_TILE_LENGTH =~ 0.7071 |
27 * the shorter piece is sqrt(2)/2*NPF_TILE_LENGTH =~ 0.7071 |
168 * including the exit tile. Requires that this is a Tunnel tile */ |
169 * including the exit tile. Requires that this is a Tunnel tile */ |
169 static uint NPFTunnelCost(AyStarNode* current) |
170 static uint NPFTunnelCost(AyStarNode* current) |
170 { |
171 { |
171 DiagDirection exitdir = TrackdirToExitdir((Trackdir)current->direction); |
172 DiagDirection exitdir = TrackdirToExitdir((Trackdir)current->direction); |
172 TileIndex tile = current->tile; |
173 TileIndex tile = current->tile; |
173 if (GetTunnelDirection(tile) == ReverseDiagDir(exitdir)) { |
174 if (GetTunnelBridgeDirection(tile) == ReverseDiagDir(exitdir)) { |
174 /* We just popped out if this tunnel, since were |
175 /* We just popped out if this tunnel, since were |
175 * facing the tunnel exit */ |
176 * facing the tunnel exit */ |
176 FindLengthOfTunnelResult flotr; |
177 FindLengthOfTunnelResult flotr; |
177 flotr = FindLengthOfTunnel(tile, ReverseDiagDir(exitdir)); |
178 flotr = FindLengthOfTunnel(tile, ReverseDiagDir(exitdir)); |
178 return flotr.length * NPF_TILE_LENGTH; |
179 return flotr.length * NPF_TILE_LENGTH; |
478 return IsTileOwner(tile, owner); /* Railway needs owner check, while the street is public */ |
479 return IsTileOwner(tile, owner); /* Railway needs owner check, while the street is public */ |
479 } |
480 } |
480 break; |
481 break; |
481 |
482 |
482 case MP_TUNNELBRIDGE: |
483 case MP_TUNNELBRIDGE: |
483 if ((IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) || |
484 if ((IsTunnel(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) || |
484 (IsBridge(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL)) { |
485 (IsBridge(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL)) { |
485 return IsTileOwner(tile, owner); |
486 return IsTileOwner(tile, owner); |
486 } |
487 } |
487 break; |
488 break; |
488 |
489 |
489 default: |
490 default: |
531 /* Initialize to 0, so we can jump out (return) somewhere an have no neighbours */ |
532 /* Initialize to 0, so we can jump out (return) somewhere an have no neighbours */ |
532 aystar->num_neighbours = 0; |
533 aystar->num_neighbours = 0; |
533 DEBUG(npf, 4, "Expanding: (%d, %d, %d) [%d]", TileX(src_tile), TileY(src_tile), src_trackdir, src_tile); |
534 DEBUG(npf, 4, "Expanding: (%d, %d, %d) [%d]", TileX(src_tile), TileY(src_tile), src_trackdir, src_tile); |
534 |
535 |
535 /* Find dest tile */ |
536 /* Find dest tile */ |
536 if (IsTunnelTile(src_tile) && GetTunnelDirection(src_tile) == src_exitdir) { |
537 if (IsTunnelTile(src_tile) && GetTunnelBridgeDirection(src_tile) == src_exitdir) { |
537 /* This is a tunnel. We know this tunnel is our type, |
538 /* This is a tunnel. We know this tunnel is our type, |
538 * otherwise we wouldn't have got here. It is also facing us, |
539 * otherwise we wouldn't have got here. It is also facing us, |
539 * so we should skip it's body */ |
540 * so we should skip it's body */ |
540 dst_tile = GetOtherTunnelEnd(src_tile); |
541 dst_tile = GetOtherTunnelEnd(src_tile); |
541 override_dst_check = true; |
542 override_dst_check = true; |
542 } else if (IsBridgeTile(src_tile) && GetBridgeRampDirection(src_tile) == src_exitdir) { |
543 } else if (IsBridgeTile(src_tile) && GetTunnelBridgeDirection(src_tile) == src_exitdir) { |
543 dst_tile = GetOtherBridgeEnd(src_tile); |
544 dst_tile = GetOtherBridgeEnd(src_tile); |
544 override_dst_check = true; |
545 override_dst_check = true; |
545 } else if (type != TRANSPORT_WATER && (IsStandardRoadStopTile(src_tile) || IsTileDepotType(src_tile, type))) { |
546 } else if (type != TRANSPORT_WATER && (IsStandardRoadStopTile(src_tile) || IsTileDepotType(src_tile, type))) { |
546 /* This is a road station (non drive-through) or a train or road depot. We can enter and exit |
547 /* This is a road station (non drive-through) or a train or road depot. We can enter and exit |
547 * those from one side only. Trackdirs don't support that (yet), so we'll |
548 * those from one side only. Trackdirs don't support that (yet), so we'll |
590 * that I can enter the tunnel from a tile below the tunnel entrance. This |
591 * that I can enter the tunnel from a tile below the tunnel entrance. This |
591 * solves the problem of vehicles wanting to drive off a tunnel entrance */ |
592 * solves the problem of vehicles wanting to drive off a tunnel entrance */ |
592 if (!override_dst_check) { |
593 if (!override_dst_check) { |
593 if (IsTileType(dst_tile, MP_TUNNELBRIDGE)) { |
594 if (IsTileType(dst_tile, MP_TUNNELBRIDGE)) { |
594 if (IsTunnel(dst_tile)) { |
595 if (IsTunnel(dst_tile)) { |
595 if (GetTunnelDirection(dst_tile) != src_exitdir) return; |
596 if (GetTunnelBridgeDirection(dst_tile) != src_exitdir) return; |
596 } else { |
597 } else { |
597 if (GetBridgeRampDirection(dst_tile) != src_exitdir) return; |
598 if (GetTunnelBridgeDirection(dst_tile) != src_exitdir) return; |
598 } |
599 } |
599 } |
600 } |
600 } |
601 } |
601 |
602 |
602 /* check correct rail type (mono, maglev, etc) */ |
603 /* check correct rail type (mono, maglev, etc) */ |