254 uint bits; |
254 uint bits; |
255 int i; |
255 int i; |
256 RememberData rd; |
256 RememberData rd; |
257 TileIndex tile_org = tile; |
257 TileIndex tile_org = tile; |
258 |
258 |
259 if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
259 // check if the old tile can be left at that direction |
260 if (IsTunnel(tile)) { |
260 if (tpf->tracktype == TRANSPORT_ROAD) { |
261 if (GetTunnelDirection(tile) != direction || |
261 // road stops and depots now have a track (r4419) |
262 GetTunnelTransportType(tile) != tpf->tracktype) { |
262 // don't enter road stop from the back |
263 return; |
263 if (IsRoadStopTile(tile) && GetRoadStopDir(tile) != direction) return; |
264 } |
264 // don't enter road depot from the back |
265 tile = SkipToEndOfTunnel(tpf, tile, direction); |
265 if (IsTileDepotType(tile, TRANSPORT_ROAD) && GetRoadDepotDirection(tile) != direction) return; |
266 } else { |
266 } |
267 TileIndex tile_end; |
267 |
268 if (GetBridgeRampDirection(tile) != direction || |
268 if (IsTunnelTile(tile)) { |
269 GetBridgeTransportType(tile) != tpf->tracktype) { |
269 if (GetTunnelDirection(tile) != direction || |
270 return; |
270 GetTunnelTransportType(tile) != tpf->tracktype) { |
271 } |
271 return; |
272 //fprintf(stderr, "%s: Planning over bridge\n", __func__); |
272 } |
273 // TODO doesn't work - WHAT doesn't work? |
273 tile = SkipToEndOfTunnel(tpf, tile, direction); |
274 TPFSetTileBit(tpf, tile, 14); |
|
275 tile_end = GetOtherBridgeEnd(tile); |
|
276 tpf->rd.cur_length += DistanceManhattan(tile, tile_end); |
|
277 tile = tile_end; |
|
278 TPFSetTileBit(tpf, tile, 14); |
|
279 } |
|
280 } |
274 } |
281 tile += TileOffsByDir(direction); |
275 tile += TileOffsByDir(direction); |
282 |
276 |
283 /* Check in case of rail if the owner is the same */ |
277 /* Check in case of rail if the owner is the same */ |
284 if (tpf->tracktype == TRANSPORT_RAIL) { |
278 if (tpf->tracktype == TRANSPORT_RAIL) { |
285 // don't enter train depot from the back |
279 // don't enter train depot from the back |
286 if (IsTileDepotType(tile, TRANSPORT_RAIL) && GetRailDepotDirection(tile) == direction) return; |
280 if (IsTileDepotType(tile, TRANSPORT_RAIL) && GetRailDepotDirection(tile) == direction) return; |
287 |
281 |
288 if (IsTileType(tile_org, MP_RAILWAY) || IsTileType(tile_org, MP_STATION) || IsTileType(tile_org, MP_TUNNELBRIDGE)) |
282 if (IsTileType(tile_org, MP_RAILWAY) || IsTileType(tile_org, MP_STATION) || IsTileType(tile_org, MP_TUNNELBRIDGE)) |
289 if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION) || IsTileType(tile, MP_TUNNELBRIDGE)) |
283 if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION) || IsTileType(tile, MP_TUNNELBRIDGE)) |
290 if (GetTileOwner(tile_org) != GetTileOwner(tile)) return; |
284 /* Check if we are on a bridge (middle parts don't have an owner */ |
|
285 if (!IsBridgeTile(tile) || !IsBridgeMiddle(tile)) |
|
286 if (!IsBridgeTile(tile_org) || !IsBridgeMiddle(tile_org)) |
|
287 if (GetTileOwner(tile_org) != GetTileOwner(tile)) |
|
288 return; |
291 } |
289 } |
292 |
290 |
293 // check if the new tile can be entered from that direction |
291 // check if the new tile can be entered from that direction |
294 if (tpf->tracktype == TRANSPORT_ROAD) { |
292 if (tpf->tracktype == TRANSPORT_ROAD) { |
295 // road stops and depots now have a track (r4419) |
293 // road stops and depots now have a track (r4419) |
710 direction = _tpf_new_direction[si.track]; |
709 direction = _tpf_new_direction[si.track]; |
711 |
710 |
712 start_at: |
711 start_at: |
713 // If the tile is the entry tile of a tunnel, and we're not going out of the tunnel, |
712 // If the tile is the entry tile of a tunnel, and we're not going out of the tunnel, |
714 // need to find the exit of the tunnel. |
713 // need to find the exit of the tunnel. |
715 if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
714 if (IsTunnelTile(tile) && |
716 if (IsTunnel(tile)) { |
715 GetTunnelDirection(tile) != ReverseDiagDir(direction)) { |
717 if (GetTunnelDirection(tile) != ReverseDiagDir(direction)) { |
716 /* We are not just driving out of the tunnel */ |
718 FindLengthOfTunnelResult flotr; |
717 if (GetTunnelDirection(tile) != direction || |
719 |
718 GetTunnelTransportType(tile) != tpf->tracktype) { |
720 /* We are not just driving out of the tunnel */ |
719 // We are not driving into the tunnel, or it is an invalid tunnel |
721 if (GetTunnelDirection(tile) != direction || |
720 continue; |
722 GetTunnelTransportType(tile) != tpf->tracktype) { |
721 } |
723 // We are not driving into the tunnel, or it is an invalid tunnel |
722 if (!HASBIT(tpf->railtypes, GetRailType(tile))) { |
724 continue; |
723 bits = 0; |
725 } |
724 break; |
726 if (!HASBIT(tpf->railtypes, GetRailType(tile))) { |
725 } |
727 bits = 0; |
726 flotr = FindLengthOfTunnel(tile, direction); |
728 break; |
727 si.cur_length += flotr.length * DIAG_FACTOR; |
729 } |
728 tile = flotr.tile; |
730 flotr = FindLengthOfTunnel(tile, direction); |
729 // tile now points to the exit tile of the tunnel |
731 si.cur_length += flotr.length * DIAG_FACTOR; |
|
732 tile = flotr.tile; |
|
733 // tile now points to the exit tile of the tunnel |
|
734 } |
|
735 } else { |
|
736 TileIndex tile_end; |
|
737 if (GetBridgeRampDirection(tile) != ReverseDiagDir(direction)) { |
|
738 // We are not just leaving the bridge |
|
739 if (GetBridgeRampDirection(tile) != direction || |
|
740 GetBridgeTransportType(tile) != tpf->tracktype) { |
|
741 // Not entering the bridge or not compatible |
|
742 continue; |
|
743 } |
|
744 } |
|
745 tile_end = GetOtherBridgeEnd(tile); |
|
746 si.cur_length += DistanceManhattan(tile, tile_end) * DIAG_FACTOR; |
|
747 tile = tile_end; |
|
748 } |
|
749 } |
730 } |
750 |
731 |
751 // This is a special loop used to go through |
732 // This is a special loop used to go through |
752 // a rail net and find the first intersection |
733 // a rail net and find the first intersection |
753 tile_org = tile; |
734 tile_org = tile; |
771 bits = (bits | (bits >> 8)) & 0x3F; |
752 bits = (bits | (bits >> 8)) & 0x3F; |
772 |
753 |
773 // Check that the tile contains exactly one track |
754 // Check that the tile contains exactly one track |
774 if (bits == 0 || KILL_FIRST_BIT(bits) != 0) break; |
755 if (bits == 0 || KILL_FIRST_BIT(bits) != 0) break; |
775 |
756 |
776 if (IsTileType(tile, MP_STREET) ? !HASBIT(tpf->railtypes, GetRailTypeCrossing(tile)) : !HASBIT(tpf->railtypes, GetRailType(tile))) { |
757 /* Check the rail type only if the train is *NOT* on top of |
777 bits = 0; |
758 * a bridge. */ |
778 break; |
759 if (!(IsBridgeTile(tile) && IsBridgeMiddle(tile) && GetBridgeAxis(tile) == DiagDirToAxis(direction))) { |
|
760 if (IsTileType(tile, MP_STREET) ? !HASBIT(tpf->railtypes, GetRailTypeCrossing(tile)) : !HASBIT(tpf->railtypes, GetRailType(tile))) { |
|
761 bits = 0; |
|
762 break; |
|
763 } |
779 } |
764 } |
780 |
765 |
781 /////////////////// |
766 /////////////////// |
782 // If we reach here, the tile has exactly one track. |
767 // If we reach here, the tile has exactly one track. |
783 // tile - index to a tile that is not rail tile, but still straight (with optional signals) |
768 // tile - index to a tile that is not rail tile, but still straight (with optional signals) |