anchor.diff:          end;
         end;
       end;
  -    if GetPlan(aHT, aLoc, aIdx) then // Plans are taking from the latest so there is not need to edit this function in case that we want the latest added element
  -      Output := True;
  +    Output := GetPlan(aHT, aLoc, aIdx);// Plans are taking from the latest so there is not need to edit this function in case that we want the latest added element
     end;
     Result := Output;
   end;
  
positive.code:     Result := Output;
    end;
  
    function DistFromClosestQuarry(aLoc: TKMPoint): Integer;
    var
      I,Dist,Output: Integer;
    begin
      Output := High(Integer);
      for I := 0 to fPlannedHouses[htQuary].Count - 1 do
      begin
        Dist := KMDistanceAbs(aLoc, fPlannedHouses[htQuary].Plans[I].Loc);
        if (Dist < Output) then
          Output := Dist;
      end;
      if (Output = High(Integer)) then
        Output := 0;
      Result := Output;
    end;
  
    // Quarry planner (constants in this function are critical and will not be set by CA)
    function FindPlaceForQuary(): Boolean;
    const
      OVERFLOW = 10;
      OWNER_PENALIZATION = 50;
      SCAN_RAD = 5;
      USED_TILES_PER_A_MINE = 5;
      USED_TILE_PRICE = 5;
    var
      X,Y,I: Integer;
      Bid, BestBid: Single;
      Loc, BestLoc: TKMPoint;
      Output: Boolean;
      //BidArr: array [0..MAX_LOCS-1] of Integer;
      Locs: TKMPointTagList;
    begin
      Output := False;
      if (fPerfIdx >= 255) then
        ClearPerfArr();
      fPerfIdx := fPerfIdx + 1;
  
      Locs := gAIFields.Eye.GetStoneLocs();
      try
        // Calculate criterium = ownership + actual Tag2 (= used by other miners) + owner criterium
        for I := 0 to Locs.Count - 1 do
          Locs.Tag[I] := Max(0, 100000 - Locs.Tag[I]
                                       + gAIFields.Influences.GetOtherOwnerships(fOwner,Locs.Items[I].X,Locs.Items[I].Y)
                                       - Round(DistCrit(htQuary, Locs.Items[I])) * 50);
        Locs.SortByTag();
        // Find best loc for a Quary
        BestBid := -100000;
        for I := 0 to Locs.Count - 1 do
        begin
          for Y := Max(1,Locs.Items[I].Y-SCAN_RAD) to Min(Locs.Items[I].Y+SCAN_RAD,gTerrain.MapY-1) do
            for X := Max(1,Locs.Items[I].X-SCAN_RAD) to Min(Locs.Items[I].X+SCAN_RAD,gTerrain.MapX-1) do
              if (fPerfArr[Y,X] <> fPerfIdx) then
              begin
                fPerfArr[Y,X] := fPerfIdx;
                Loc := KMPoint(X,Y);
                if gAIFields.Eye.CanAddHousePlan(Loc, htQuary, True, False) then
                begin
                  Bid := + DistCrit(htQuary, Loc) * 40 + SnapCrit(htQuary, Loc);
                  if (Bid > BestBid) then
                  begin
                    BestBid := Bid;
                    BestLoc := Loc;
                    Output := True;
                  end;
                end;
              end;
          if Output AND (I >= min(5,Locs.Count-1)) then // Do several points
          begin
            AddPlan(aHT, BestLoc);
            gHands[fOwner].AI.CityManagement.Builder.LockHouseLoc(aHT, BestLoc);
            break;
          end;
        end;
      finally
        Locs.Free;
      end;
      Result := Output;
    end;
  
  var
    Output: Boolean;
  begin
    case aHT of
      htGoldMine:  Output := FindPlaceForMine(htGoldMine);
      htIronMine:  Output := FindPlaceForMine(htIronMine);
      htCoalMine:  Output := FindPlaceForCoalMine();
      htQuary:     Output := FindPlaceForQuary();
      else          Output := False;
    end;
    Result := Output;
  end;
  
  
  // Find place for woodcutter
  function TKMCityPlanner.FindPlaceForWoodcutter(aCenter: TKMPoint; aChopOnly: Boolean = False): Boolean;
  const
    RADIUS = 5;
    MIN_BID = -100000;
  var
    Output, Check: Boolean;
    I,X,Y: Integer;
    Bid, BestBid: Single;
    Loc, BestLoc, Point: TKMPoint;
    HMA: THouseMappingArray;
  begin
    Output := False;
    HMA := gAIFields.Eye.HousesMapping;
    BestBid := MIN_BID;
    for Y := Max(1, aCenter.Y - RADIUS) to Min(gTerrain.MapY, aCenter.Y + RADIUS) do
    for X := Max(1, aCenter.X - RADIUS) to Min(gTerrain.MapX, aCenter.X + RADIUS) do
    begin
      Loc := KMPoint(X,Y);
      if gAIFields.Eye.CanAddHousePlan(Loc, htWoodcutters, not aChopOnly, False, False) then
      //if gAIFields.Eye.CanAddHousePlan(Loc, ht_Woodcutters, True, False, False) then
      begin
        Bid := - GA_PLANNER_PlaceWoodcutter_DistFromForest * KMDistanceAbs(aCenter, Loc)
               + DistCrit(htWoodcutters, Loc)
               + SnapCrit(htWoodcutters, Loc);
               //- Byte(gAIFields.Influences.AvoidBuilding[Loc.Y, Loc.X] >= AVOID_BUILDING_COAL_TILE) * 100000; // Try not to place woodcutter into full forest or coal tile
        if (Bid > BestBid) then
        begin
          Check := True;
          for I := Low(HMA[htWoodcutters].Tiles) to High(HMA[htWoodcutters].Tiles) do
          begin
            Point := KMPointAdd( Loc, HMA[htWoodcutters].Tiles[I] );
            if (gTerrain.TileIsCoal(Point.X, Point.Y) <> 0) then
            begin
              Check := False;
              break;
            end;
          end;
          if Check then
          begin
            BestBid := Bid;
            BestLoc := Loc;
          end;
        end;
      end;
    end;
    if (BestBid <> MIN_BID) then
    begin
      Output := True;
  
negative.code:       Result := Result + Byte(tpWalk in gTerrain.Land[aLoc.Y+2,aLoc.X+I].Passability) * OBSTACLE_COEF;
    end;
  
    procedure EvaluateLoc(aLoc: TKMPoint);
    var
      L: Integer;
      Bid: Double;
    begin
      Bid := //- InitBid * GA_PLANNER_FindPlaceForHouse_CloseWorker
             + SnapCrit(aHT, aLoc) * GA_PLANNER_FindPlaceForHouse_SnapCrit
             + DistCrit(aHT, aLoc) * GA_PLANNER_FindPlaceForHouse_DistCrit
             - KMDistanceSqr(CityCenter, aLoc) * GA_PLANNER_FindPlaceForHouse_CityCenter
  