anchor.diff:      fSpeed: Byte;
   
       function BrushAreaTerKindContains(aCell: TKMPoint): Boolean;
  -    function GetVertexCornerTerKinds(X,Y: Word): TKMTerrainKindsArray;
  -    function GetTileOwnCornersTKinds(const aCell: TKMPoint): TKMTerrainKindsArray;
  -    function GetTileLandNodeTKinds(const aCell: TKMPoint): TKMTerrainKindsArray;
  -    function GetTileCornersTKinds(const aCell: TKMPoint; aGetOnlyTileCornersTK: Boolean = False; aGetOnlyLandNodeTK: Boolean = False): TKMTerrainKindsArray;
  +    function GetVertexCornerTerKinds(X,Y: Word; var aCornersTerKinds: TKMTerrainKindCorners): Integer;
  +    procedure GetTileOwnCornersTKinds(const aCell: TKMPoint; var aCornersTerKinds: TKMTerrainKindCorners);
  +    procedure GetTileLandNodeTKinds(const aCell: TKMPoint; var aCornersTerKinds: TKMTerrainKindCorners);
  +    procedure GetTileCornersTKinds(const aCell: TKMPoint; out aCornersTerKinds: TKMTerrainKindCorners;
  +                                   aGetOnlyTileCornersTK: Boolean = False; aGetOnlyLandNodeTK: Boolean = False);
       procedure BrushTile(const X, Y: Integer);
       procedure BrushTerrainTile(const X, Y: Integer; aTerKind: TKMTerrainKind);
       procedure MagicBrush(const X,Y: Integer); overload;
  
positive.code: 
  var
    I,K,M: Integer;
    VertexTKinds: TKMTerrainKindsArray;
    SameTKind, NoCustomTK: Boolean;
    TKCounts, MostTKIs: array[0..3] of Integer;
    MostTKCnt, MostTKI, vrxCnt: Integer;
  begin
    Result := False;
    aEffectiveTKind := tkCustom;
  
    VertexTKinds := GetVertexCornerTerKinds(X,Y);
    vrxCnt := Length(VertexTKinds);
    SameTKind := True;
  
    Assert(vrxCnt > 0, 'Can''t find vertex corners');
  
    for K := 0 to vrxCnt - 1 do
    begin
      TKCounts[K] := 0;
      MostTKIs[K] := 0;
    end;
  
    //Find most popular TerKind
    //Count all TerKinds occurrences first
    for K := 0 to vrxCnt - 1 do
      for M := K + 1 to vrxCnt - 1 do
        if VertexTKinds[K] = VertexTKinds[M] then
          Inc(TKCounts[K]);
  
    //Get Most popular one index
    MostTKCnt := -1;
    I := 0;
    for K := 0 to vrxCnt - 1 do
      if TKCounts[K] > MostTKCnt then
      begin
        I := 0;
        MostTKIs[I] := K;
        MostTKCnt := TKCounts[K];
        Inc(I);
      end
      else
      if TKCounts[K] = MostTKCnt then
      begin
        MostTKIs[I] := K;
        Inc(I);
      end;
  
    MostTKI := MostTKIs[KaMRandom(I, 'TKMTerrainPainter.TryGetVertexEffectiveTerKind')];
  
    NoCustomTK := VertexTKinds[0] <> tkCustom;
    for K := 1 to vrxCnt - 1 do
    begin
      SameTKind := SameTKind and EqualTKinds(VertexTKinds[K], VertexTKinds[K-1]);
      NoCustomTK := NoCustomTK and (VertexTKinds[K] <> tkCustom);
    end;
  
    //Replace TerKind with most popular one if there all TerKinds are equal or if there is no custom TerKinds
    if SameTKind or NoCustomTK then
    begin
      aEffectiveTKind := VertexTKinds[MostTKI];
      Result := True;
    end;
  end;
  
negative.code:     end;
    end;
  
    procedure GetTerKindsAround(aCell: TKMPoint; out aCornersTerKinds: TKMTerrainKindCorners);
    var
      I: Integer;
      TerKind: TKMTerrainKind;
      TerKindFound: array[0..3] of Boolean;
    begin
      //get all 4 terkind for corners
      for I := 0 to 3 do
      begin
        TerKind := GetCornerTerKind(I, aCell, TerKindFound[I]);
        if TerKindFound[I] then
          aCornersTerKinds[I] := TerKind;
      end;
  
      //For corner, where no terkind from around tiles were found - replace it with neighbour corner terkind (there can't be 2 missed terkinds in a row)
      for I := 0 to 3 do
        if not TerKindFound[I] then
          aCornersTerKinds[I] := aCornersTerKinds[(I+1) mod 4];
    end;
  
    function HasCollision(aTerKind1, aTerKind2: TKMTerrainKind): Boolean;
  