anchor.diff:  end;
   
   
  -// Scan defence positions in first line and try find hostile groups in specific radius
  -procedure TKMArmyDefence.FindEnemyInDefLine(aEnemyGroups: TKMUnitGroupArray);
  -
  +// Find defensive groups around specific loc
  +function TKMArmyDefence.FindGroupsAroundLoc(aMaxCnt: Byte; aLoc: TKMPoint): TKMUnitGroupArray;
  +const
  +  INIT_PRICE = 10000000;
  +  SQR_MAX_DISTANCE = 15*15;
  +var
  +  I, K, Idx, Cnt: Integer;
  +  Price: Single;
  +  Group: TKMUnitGroup;
  +  UGA: TKMUnitGroupArray;
  +  IdxArr: TIntegerArray;
  +  PriceArr: TSingleArray;
  +begin
  +  SetLength(IdxArr, aMaxCnt);
  +  SetLength(PriceArr, aMaxCnt);
  +  for I := 0 to Length(PriceArr) - 1 do
  +    PriceArr[I] := INIT_PRICE;
  +  // Find closest groups
  +  Cnt := 0;
  +  for I := 0 to fPositions.Count - 1 do
  +  begin
  +    Group := Positions[I].Group;
  +    if (Group <> nil) AND not Group.IsDead then
  +    begin
  +      Cnt := Cnt + 1;
  +      Idx := I;
  +      Price := KMDistanceSqr(aLoc, Positions[I].Position.Loc) - Group.Count * 10;
  +      for K := 0 to Length(PriceArr) - 1 do
  +        if (Price < PriceArr[K]) then
  +        begin
  +          KMSwapFloat(Price, PriceArr[K]);
  +          KMSwapInt(Idx, IdxArr[K]);
  +        end
  +        else if (Price = INIT_PRICE) then
  +          break;
  +    end;
  +  end;
  +  // Release groups
  +  Cnt := Min( aMaxCnt, Cnt );
  +  SetLength(UGA, Cnt);
  +  for I := 0 to Cnt - 1 do
  +  begin
  +    UGA[I] := Positions[ IdxArr[I] ].Group;
  +    ReleaseGroup( IdxArr[I] );
  +  end;
  +  Result := UGA;
  +end;
  +
  +
  +// Check if exists company with order to go at target point or create new defensive company
  +function TKMArmyDefence.DefendPoint(aTargetPoint: TKMPoint; aRestockCompany: Boolean = False): Boolean;
  +  // Add more soldiers into company
  +  function RestockCompany(aCompany: TAICompany): Boolean;
  +  const
  +    MIN_GROUPS = 5;
  +    RESERVE = 3;
  +  var
  +    I, SquadCnt: Integer;
  +    Groups: TKMUnitGroupArray;
  +  begin
  +    Result := True;
  +    SquadCnt := aCompany.SquadCnt();
  +    if (SquadCnt < MIN_GROUPS) then
  +    begin
  +      SquadCnt := MIN_GROUPS - SquadCnt + RESERVE;
  +      Groups := FindGroupsAroundLoc(SquadCnt, aCompany.ScanPosition);
  +      for I := 0 to Length(Groups) - 1 do
  +        aCompany.AddSquad( Groups[I] );
  +      Result := (Length(Groups) >= SquadCnt);
  +    end;
  +  end;
  +  // Check if there is company around
     function IsCompanyAround(aLoc: TKMPoint): Boolean;
     const
  -    SQR_MAX_DISTANCE = 20*20;
  +    SQR_MAX_DISTANCE = 10*10;
     var
       I: Integer;
       Company: TAICompany;
  
positive.code: 
      function GetCount: Integer; inline;
      function GetPosition(aIndex: Integer): TKMDefencePosition; inline;
    public
      TroopFormations: array [TKMGroupType] of TKMFormation; //Defines how defending troops will be formatted. 0 means leave unchanged.
  
  
negative.code:     function FindPlaceForGroup(aGroup: TKMUnitGroup): Boolean;
      procedure ReleaseGroup(aGroup: TKMUnitGroup); overload;
      procedure ReleaseGroup(aDefPosIdx: Integer); overload;
      function DefendPoint(aTargetPoint: TKMPoint; aRestockCompany: Boolean = False): Boolean;
      procedure FindEnemyInDefLine(aEnemyGroups: TKMUnitGroupArray; var aDefRequest: TKMDefendRequest);
  
      procedure UpdateState(aTick: Cardinal);
      procedure LogStatus(var aBalanceText: UnicodeString);
  