} while (p.getDirection() == oldDirection);
oldDirection = p.getDirection(); while (!bestPath.isEmpty()) { pe = (PathExplorer) bestPath.removeFirst(); if (oldDirection != pe.getDirection()) { bestPath.addFirst(pe); break; } p = pe; newp.x = pe.getX(); newp.y = pe.getY(); } }
    public TrainPath findPath(Point start, Point dest) {	Point target = new Point(dest);	TrackTile.deltasToTileCoords(target);	Point startCentre = new Point (start);	TrackTile.deltasToTileCoords(startCentre);		/* "Stupidity" filter... */	if (startCentre.equals(target))	    return new TrainPath(new Point[]{new Point(start.x, start.y),		    TrackTile.tileCoordsToDeltas(startCentre),		    new Point(dest.x, dest.y)});	PathExplorer pe = new TrainPathExplorer(world, startCentre.x,		startCentre.y, CompassPoints.NORTH);	PathFinder pf = new PathFinder(pe, target.x, target.y, 0,		Integer.MAX_VALUE);	LinkedList bestPath = pf.explore();		startCentre = TrackTile.tileCoordsToDeltas(startCentre);	/* all possible paths have been explored, but no route was found */	if (bestPath.isEmpty())	    return null;	/* convert the ArrayList to a TrainPath. bestPath always contains the	 * target tile and the start tile */	Point oldp = new Point();	Point newp = new Point();	byte oldDirection;	PathExplorer p = (PathExplorer) bestPath.removeFirst();	LinkedList intLines = new LinkedList();	boolean firstP = true;	while (!bestPath.isEmpty()) {	    oldp.x = p.getX();	    oldp.y = p.getY();	    oldDirection = p.getDirection();	    do {		p = (PathExplorer) bestPath.removeFirst();		newp.x = p.getX();		newp.y = p.getY();	    } while (p.getDirection() == oldDirection);	    if (firstP) {		oldp.x = startCentre.x;		oldp.y = startCentre.y;		firstP = false;	    } else {		oldp = TrackTile.tileCoordsToDeltas(oldp);	    }	    newp = TrackTile.tileCoordsToDeltas(newp);	    IntLine l = new IntLine(oldp.x, oldp.y, newp.x, newp.y);	    intLines.add(l);	}	fixUpPathEnds(intLines, start, dest);	TrainPath retVal = new TrainPath((IntLine[]) intLines.toArray(new		    IntLine[intLines.size()]));	return retVal;    }