anchor.diff:        //If tile is surrounded with other stone tiles no need to change it
         if bits <> 15 then
         begin
  -        Land^[Y,X].BaseLayer.Terrain  := TranTiles[transition, TileIDIndex[bits]];
  -        Land^[Y,X].BaseLayer.Rotation := RotID[bits];
  +        Land^[Y,X].BaseLayer.Terrain  := TRAN_TILES[transition, TILE_ID_INDEX[bits]];
  +        Land^[Y,X].BaseLayer.Rotation := ROT_ID[bits];
         end;
       end;
       UpdatePassability(KMPoint(X,Y));
  
positive.code:     if not TileInMapCoords(X,Y) //Skip for tiles not in map coords
        or (aStep > MAX_STEPS)  //Limit for steps (no limit for now)
        or TileHasStone(X,Y)      //If tile has stone no need to change it
        or ArrayContains(KMPoint(X,Y), Visited, fVisitedCnt) //If we already changed this tile
        or ((aStep <> 0) and not TileHasTerrainKindPart(X, Y, tkStone)) //If tile has no stone parts (except initial step)
        or not TileHasOnlyTerrainKinds(X, Y, [tkStone, tkGrass, tkCoastSand, tkDirt, tkSnow, tkSnowOnDirt]) then //Do not update transitions with other terrains (mountains f.e.)
        Exit;
  
negative.code:                ( 46, 286, 285, 287, 288, 290, 304),
                 ( 47, 294, 293, 295, 296, 298, 305));
  
    TILE_ID_INDEX:      array[1..14] of Word = (1,1,2,1,3,2,4,1,2,3,4,2,4,4);
    ROT_ID:             array[1..14] of Byte = (0,1,0,2,0,1,3,3,3,1,2,2,1,0);
    TILE_ID_DIAG_INDEX: array[1..15] of Word = (5,5,6,5,5,6,5,5,6,5,5,6,5,5,5);
    ROT_ID_DIAG:        array[1..15] of Byte = (3,0,0,1,3,1,3,2,3,0,0,2,0,0,0);
  
    NO_REPL = High(Word);
    WATER_DIAG_REPL: array[TKMStoneTransitionType] of Word =
                       (127, 127, 118, 105, NO_REPL, NO_REPL);
  
    WATER_DIAG_REPL_ROT: array[TKMStoneTransitionType] of Byte =
                           (1, 1, 1, 3, 100, 100);
  
    MAX_STEPS = 5; //steps limit
  
  var
    visited: TKMPointArray;
    visitedCnt: Integer;
  
    procedure InitVisited;
    begin
      SetLength(visited, 8);
      visitedCnt := 0;
    end;
  
    procedure AddToVisited(X,Y: Word);
    begin
      if Length(visited) = visitedCnt then
        SetLength(visited, visitedCnt + 8);
  
      visited[visitedCnt] := KMPoint(X,Y);
      Inc(visitedCnt);
    end;
  
    function GetTile(aTransitionType: TKMStoneTransitionType; aTileIdIndex: Byte): Word;
    begin
      if aTileIdIndex = 0 then
        Result := TKMTerrainPainter.GetRandomTile(TRANSITIONS_TER_KINDS[aTransitionType])
      else
        Result := TRAN_TILES[aTransitionType, aTileIdIndex];
  
    end;
  
    function GetStoneTransitionType(X, Y: Word): TKMStoneTransitionType;
    begin
      Result := sttNone;
      case Land^[Y,X].BaseLayer.Terrain of
  