From b206e50f80607e837bed79fbc46a6aa298a8bfd8 Mon Sep 17 00:00:00 2001
From: smatz <smatz@openttd.org>
Date: Mon, 4 Feb 2008 14:08:02 +0000
Subject: [PATCH] (svn r12055) -Fix: another way to fix AI trying to build road
 through depots

---
 src/pathfind.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/pathfind.cpp b/src/pathfind.cpp
index 06374666ba..9714a2bb04 100644
--- a/src/pathfind.cpp
+++ b/src/pathfind.cpp
@@ -287,7 +287,8 @@ static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi
 				tpf->the_dir = (Trackdir)((_otherdir_mask[direction] & (byte)(1 << i)) ? (i + 8) : i);
 				RememberData rd = tpf->rd;
 
-				if (TPFSetTileBit(tpf, tile, tpf->the_dir) &&
+				/* make sure we are not leaving from invalid side */
+				if (TPFSetTileBit(tpf, tile, tpf->the_dir) && CanAccessTileInDir(tile, TrackdirToExitdir(tpf->the_dir), tpf->tracktype) &&
 						!tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length, &tpf->rd.pft_var6) ) {
 					TPFMode1(tpf, tile, _tpf_new_direction[tpf->the_dir]);
 				}