diff options
author | smatz <smatz@openttd.org> | 2008-01-23 19:31:11 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2008-01-23 19:31:11 +0000 |
commit | c19fd4fcdea6bd33c525f5517d501eb7ca3e4562 (patch) | |
tree | 3b0f8c935461dedb76fabcde796e157446bd9485 /src/pathfind.cpp | |
parent | 75784655b706aca2b2afdc8b73dbed7d46b4a72f (diff) | |
download | openttd-c19fd4fcdea6bd33c525f5517d501eb7ca3e4562.tar.xz |
(svn r11966) -Fix: OPF was searching through depots and normal road stops
In effect, it also fixes old AI bugs like FS#1403 and FS#1506
Diffstat (limited to 'src/pathfind.cpp')
-rw-r--r-- | src/pathfind.cpp | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/src/pathfind.cpp b/src/pathfind.cpp index 91f059be6..88700cfc3 100644 --- a/src/pathfind.cpp +++ b/src/pathfind.cpp @@ -218,6 +218,30 @@ FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, DiagDirection dir) return flotr; } +/** + * Checks if any vehicle can enter/leave tile in given diagdir + * Checks only for rail/road depots and road non-drivethrough stations + * @param tile tile to check + * @param side side of tile we are trying to leave/enter + * @param tracktype type of transport + * @pre tile has trackbit at that diagdir + * @return true iff vehicle can enter/leve the tile in given side + */ +static inline bool CanAccessTileInDir(TileIndex tile, DiagDirection side, TransportType tracktype) +{ + if (tracktype == TRANSPORT_RAIL) { + /* depot from wrong side */ + if (IsTileDepotType(tile, TRANSPORT_RAIL) && GetRailDepotDirection(tile) != side) return false; + } else if (tracktype == TRANSPORT_ROAD) { + /* depot from wrong side */ + if (IsTileDepotType(tile, TRANSPORT_ROAD) && GetRoadDepotDirection(tile) != side) return false; + /* non-driverthrough road station from wrong side */ + if (IsStandardRoadStopTile(tile) && GetRoadStopDir(tile) != side) return false; + } + + return true; +} + static const uint16 _tpfmode1_and[4] = { 0x1009, 0x16, 0x520, 0x2A00 }; static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction) @@ -243,29 +267,23 @@ static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi /* leaving tunnel / bridge? */ if (ReverseDiagDir(dir) != direction) return; } + } else { + /* can we leave tile in this dir? */ + if (!CanAccessTileInDir(tile, direction, tpf->tracktype)) return; } tile += TileOffsByDiagDir(direction); + /* can we enter tile in this dir? */ + if (!CanAccessTileInDir(tile, ReverseDiagDir(direction), tpf->tracktype)) return; + /* Check in case of rail if the owner is the same */ if (tpf->tracktype == TRANSPORT_RAIL) { - /* don't enter train depot from the back */ - if (IsTileDepotType(tile, TRANSPORT_RAIL) && GetRailDepotDirection(tile) == direction) return; - if (IsTileType(tile_org, MP_RAILWAY) || IsTileType(tile_org, MP_STATION) || IsTileType(tile_org, MP_TUNNELBRIDGE)) if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION) || IsTileType(tile, MP_TUNNELBRIDGE)) if (GetTileOwner(tile_org) != GetTileOwner(tile)) return; } - /* check if the new tile can be entered from that direction */ - if (tpf->tracktype == TRANSPORT_ROAD) { - /* road stops and depots now have a track (r4419) - * don't enter road stop from the back */ - if (IsStandardRoadStopTile(tile) && ReverseDiagDir(GetRoadStopDir(tile)) != direction) return; - /* don't enter road depot from the back */ - if (IsTileDepotType(tile, TRANSPORT_ROAD) && ReverseDiagDir(GetRoadDepotDirection(tile)) != direction) return; - } - /* Check if the new tile is a tunnel or bridge head and that the direction * and transport type match */ if (IsTileType(tile, MP_TUNNELBRIDGE)) { |