anchor.diff:  end;
   //}
   
  -
   end.
  
positive.code: begin
    // Get owner influence and distance from influence
    fDefInfo[aIdx].Influence := gAIFields.Influences.OwnPoly[fOwner, aIdx];
    Distance := aDistance; // Min(fDefInfo[aIdx].Influence shr 2, Distance);
    if (fDefInfo[aIdx].Influence > OWNER_INFLUENCE_LIMIT) then
      Distance := 0;
    inherited MarkAsVisited(aIdx, Distance, aPoint);
    // For special polygons calculate also alliance influence
    if (gAIFields.NavMesh.Polygons[aIdx].NearbyCount = 3) then
    begin
      fDefInfo[aIdx].EnemyInfluence := gAIFields.Influences.GetBestAllianceOwnership(fOwner, aIdx, at_Enemy);
      if (Distance < MAXIMAL_DEFENCE_DISTANCE) then // We dont need to know about ally influence far behind maximal defence distance so save some time and do nothing
        fDefInfo[aIdx].AllyInfluence := gAIFields.Influences.GetBestAllianceOwnership(fOwner, aIdx, at_Ally);
    end;
  end;
  
  
  
negative.code:   end;
  
  
    TBackwardFF = class(TNavMeshFloodFill)
    private
    protected
      fDefLinesRequired: Boolean;
      fOwner: TKMHandIndex;
      fBestEvaluation: Single;
      fDefInfo: TDefInfoArray;
      fFilterFF: TFilterFF;
  
      function CanBeExpanded(const aIdx: Word): Boolean; override;
      procedure BackwardFlood();
      procedure EvaluateDefence(const aIdx: Word);
      function FindDefencePos(var aBaseCnt, aFirstLine: Word; aMinDefeces: Boolean): Boolean;
    public
      //D_INIT_ARR, D_INIT_FLOOD: TKMWordArray;
      BestDefLines: TKMDefenceLines;
      DefPosArr: TKMDefencePosArr;
  
      constructor Create(aSorted: Boolean = False); reintroduce;
      destructor Destroy(); override;
  
      procedure UpdatePointers(var aDefInfo: TDefInfoArray; var aQueueArray: TPolygonsQueueArr);
      procedure NewQueue(aVisitedIdx: Byte);
      procedure AddPolygon(aIdx: Word);
      function FindDefenceLines(aOwner: TKMHandIndex): TKMDefenceLines;
      function FindDefensivePolygons(aOwner: TKMHandIndex; var aBaseCnt, aFirstLine: Word; var aBestDefLines: TKMDefenceLines; aMinDefeces: Boolean; aDefLinesRequired: Boolean): TKMDefencePosArr;
  
      //procedure DEBUG();
    end;
  
  
    TFilterFF = class(TNavMeshFloodFill)
    private
    protected
      procedure InitQueue(const aMaxIdx: Word; aInitIdxArray: TKMWordArray); override;
      function IsVisited(const aIdx: Word): Boolean; override;
    public
      BestDefLines, AllDefLines: TKMDefenceLines;
      procedure FilterDefenceLine(var aAllDefLines: TKMDefenceLines);
    end;
  
  
  const
    OWNER_INFLUENCE_LIMIT = 220; // From this influence limit will be counted distance, it is also the closest line of possible defence
    MAX_ENEMY_INFLUENCE = 200; // Maximal enemy influence in FordwardFF (forward flood fill will not scan futher)
  