anchor.diff:    TileIDDiagIndex: array[1..15] of Word = (5,5,6,5,5,6,5,5,6,5,5,6,5,5,5);
     RotIdDiag:       array[1..15] of Byte = (3,0,0,1,3,1,3,2,3,0,0,2,0,0,0);
   
  +  MAX_STEPS = 255; //No steps limit for now
  +
  +var
  +  Visited: TKMPointArray;
  +  fVisitedCnt: Integer;
  +
  +  procedure InitVisited;
  +  begin
  +    SetLength(Visited, 8);
  +    fVisitedCnt := 0;
  +  end;
  +
  +  procedure AddToVisited(X,Y: Word);
  +  begin
  +    if Length(Visited) = fVisitedCnt then
  +      SetLength(Visited, fVisitedCnt + 8);
  +
  +    Visited[fVisitedCnt] := KMPoint(X,Y);
  +    Inc(fVisitedCnt);
  +  end;
  +
     function GetTile(aTransitionType: TStoneTransitionType; aTileIdIndex: Byte): Word;
     begin
       if aTileIdIndex = 0 then
  
positive.code:       Land[Y,X].BaseLayer.Rotation := RotID[Bits];
      end;
      UpdatePassability(KMPoint(X,Y));
    end;
  
  var
  
negative.code:           end;
      end;
      Assert(Result[K] <> TOO_BIG_VALUE, Format('[TileCornerTerrains] Can''t determine tile [%d:%d] terrain at Corner [%d]', [aX, aY, K]));
    end;
  end;
  
  
  //Get tile corners terrain kinds
  function TKMTerrain.TileCornersTerKinds(aX, aY: Word): TKMTerrainKindsArray;
  var
    K, L: Integer;
  begin
    SetLength(Result, 4);
    for K := 0 to 3 do
    begin
      Result[K] := tkCustom;
      with gTerrain.Land[aY,aX] do
      begin
        if K in BaseLayer.Corners then
          Result[K] := TILE_CORNERS_TERRAIN_KINDS[BaseLayer.Terrain, (K + 4 - BaseLayer.Rotation) mod 4]
        else
          for L := 0 to LayersCnt - 1 do
            if K in Layer[L].Corners then
            begin
              Result[K] := gRes.Sprites.GetGenTerrainInfo(Layer[L].Terrain).TerKind;
              Break;
            end;
      end;
    end;
  end;
  
  