anchor.diff:  end;
   
   
  -procedure TKMDefencePosition.SetGroupType(const Value: TGroupType);
  -begin
  -  Assert(gGame.IsMapEditor);
  -  fGroupType := Value;
  +function TKMDefencePosition.GetGroupType(): TGroupType;
  +begin
  +  Result := gt_Melee;
  +  if (Group <> nil) then
  +    Result := Group.GroupType;
   end;
   
   
   function TKMDefencePosition.CanAccept(aGroup: TKMUnitGroup; aMaxUnits: Integer): Boolean;
   begin
  -  Result := (fGroupType = UnitGroups[aGroup.UnitType]) // The right type of group
  -            AND (
  -              (CurrentGroup = nil) OR ( (aGroup.Count = 1) AND (CurrentGroup.Count < aMaxUnits) ) // Empty defence or small group
  +  Result := (Group = nil) OR (  // Empty defence
  +              (GroupType = UnitGroups[aGroup.UnitType]) AND ( (aGroup.Count = 1) AND (Group.Count < aMaxUnits) ) // Same small group
               );
   end;
   
  
positive.code: var
    I, Cnt: Integer;
  begin
    Cnt := 0;
    for I := 0 to Count - 1 do
      if (Positions[I].CurrentGroup <> nil) then
        Cnt := Cnt + 1;
    case Byte(Cnt >= Min(fFirstLineCnt * FIRST_LINE_COEF, Count shr 1)) + Byte(Cnt >= Count * 0.8) of // In case that defence is too long keep max cnt decreased
      0: Result := ds_Empty;
      1: Result := ds_Half;
      2: Result := ds_Full;
    end;
  end;
  
  
  procedure TKMArmyDefence.UpdateDefences();
  const
    GROUPS: array[0..3] of TGroupType = (gt_Melee, gt_AntiHorse, gt_Ranged, gt_Mounted);
  var
    FirstLineCnt: Word;
    I, K: Integer;
    Point: TKMPoint;
    FaceDir: TKMDirection;
    VisitedNewPos, VisitedExistPos: TBooleanArray;
    DefPolygons: TKMWordArray;
    DefPosArr: TKMDefencePosArr;
  begin
    //Get defence Polygons
    FirstLineCnt := 0;
    //if not gAIFields.NavMesh.Defences.FindDefensivePolygons(fOwner, gHands[fOwner].UnitGroups.Count + 10, DefPolygons) then
    if not gAIFields.NavMesh.Defences.FindDefensivePolygons(fOwner, FirstLineCnt, DefPosArr) then
      Exit;
  
    fFirstLineCnt := FirstLineCnt;
    SetLength(VisitedNewPos, Length(DefPolygons));
    for I := 0 to Length(VisitedNewPos) - 1 do
      VisitedNewPos[I] := False;
    SetLength(VisitedExistPos, fPositions.Count);
  
negative.code: begin
    inherited Create;
    LoadStream.ReadAssert('DefencePosition');
    LoadStream.Read(fWeight);
    LoadStream.Read(fPosition);
    LoadStream.Read(fGroup, 4); //Subst on syncload
  end;
  
  
  procedure TKMDefencePosition.SyncLoad();
  begin
    fGroup := gHands.GetGroupByUID(Cardinal(fGroup));
  end;
  
  
  procedure TKMDefencePosition.SetGroup(aGroup: TKMUnitGroup);
  begin
    gHands.CleanUpGroupPointer(fGroup);
    if (aGroup <> nil) then
      fGroup := aGroup.GetGroupPointer;
  end;
  
  
  