anchor.diff:    Locs := TKMPointDirTagList.Create;
     try
       //Make list of defence positions
  -    for I := 0 to High(Outline2) do
  -    begin
  -      FaceDir := KMGetDirection(KMPointF(Outline2[I].A), KMPerpendecular(Outline2[I].A, Outline2[I].B));
  -
  -      //Longer segments will get several DefencePositions
  -      SegLength := KMLength(Outline2[I].A, Outline2[I].B);
  -      DefCount := Max(Trunc(SegLength / 5), 1); //At least 1, otherwise we might leave a bridge undefended
  -
  -      for K := 0 to DefCount - 1 do
  -      begin
  -        Ratio := (K + 1) / (DefCount + 1);
  -        Loc := KMPointRound(KMLerp(Outline2[I].A, Outline2[I].B, Ratio));
  -        Weight := Round(Outline2[I].Weight * 100);
  -        //Make sure each segment gets 1 defence position before filling others (in the middle of the segment line)
  -        if K = ((DefCount - 1) div 2) then
  -          Weight := Weight + 10000;
  -
  -        Locs.Add(KMPointDir(Loc, FaceDir), Weight);
  -      end;
  -    end;
  +    for I := 0 to High(DefPosArr) do
  +      Locs.Add(DefPosArr[I].DirPoint, DefPosArr[I].Weight);
  +
  +    //for I := 0 to High(Outline2) do
  +    //begin
  +    //  FaceDir := KMGetDirection(KMPointF(Outline2[I].A), KMPerpendecular(Outline2[I].A, Outline2[I].B));
  +    //
  +    //  //Longer segments will get several DefencePositions
  +    //  SegLength := KMLength(Outline2[I].A, Outline2[I].B);
  +    //  DefCount := Max(Trunc(SegLength / 5), 1); //At least 1, otherwise we might leave a bridge undefended
  +    //
  +    //  for K := 0 to DefCount - 1 do
  +    //  begin
  +    //    Ratio := (K + 1) / (DefCount + 1);
  +    //    Loc := KMPointRound(KMLerp(Outline2[I].A, Outline2[I].B, Ratio));
  +    //    Weight := Round(Outline2[I].Weight * 100);
  +    //    //Make sure each segment gets 1 defence position before filling others (in the middle of the segment line)
  +    //    if K = ((DefCount - 1) div 2) then
  +    //      Weight := Weight + 10000;
  +    //
  +    //    Locs.Add(KMPointDir(Loc, FaceDir), Weight);
  +    //  end;
  +    //end;
   
       //Sort according to positions weight
       Locs.SortByTag;
   
  +
       //Add defence positions
       for I := Locs.Count - 1 downto 0 do
       begin
  -      LocI := KMGetPointInDir(Locs[I].Loc, KMAddDirection(Locs[I].Dir, 4), 1);
  +      LocI := KMGetPointInDir(Locs.Items[I].Loc, Locs.Items[I].Dir, 1);
         Loc := gTerrain.EnsureTileInMapCoords(LocI.X, LocI.Y, 3);
         if not EnsureWalkable(Loc) then
           Continue;
  
positive.code:   end;
  
  var
    Outline1, Outline2: TKMWeightSegments;
    I, K: Integer;
    Locs: TKMPointDirTagList;
    Loc: TKMPoint;
    LocI: TKMPoint;
    FaceDir: TKMDirection;
    SegLength, Ratio: Single;
    DefCount: Byte;
    GT: TGroupType;
    DPT: TAIDefencePosType;
    Weight: Cardinal;
    BacklineCount: Integer;
  begin
    //Get defence Outline with weights representing how important each segment is
    //gAIFields.NavMesh.GetDefenceOutline(fOwner, Outline1, Outline2);
  
    fDefencePositions.Clear;
    BacklineCount := 0;
  
negative.code: uses
    KM_AISetup, KM_AIAttacks, KM_AIDefensePos,
    KM_Units, KM_UnitGroups,
    KM_CommonClasses, KM_Defaults, KM_Points,
    KM_NavMeshDefences;
  
  
  type
  