anchor.diff:    end;
   
     function RequiredServCount(): Integer;
  -  const
  -    HOUSE_COEF = 0.5;
     var
  -    I: Integer;
  -  begin
  -    Result := Max(0, gHands[fOwner].Stats.GetUnitQty(ut_Worker) + Round(gHands[fOwner].Stats.GetHouseTotal(htAny) * HOUSE_COEF) - gHands[fOwner].Stats.GetUnitQty(ut_Serf));
  -    //Result := Max(0, gHands[fOwner].Stats.GetUnitQty(ut_Worker) - gHands[fOwner].Stats.GetUnitQty(ut_Serf));
  +    I,Serfs, Cnt: Integer;
  +  begin
  +    Serfs := gHands[fOwner].Stats.GetUnitQty(ut_Serf);
  +    Result := Max(0, Round(gHands[fOwner].Stats.GetUnitQty(ut_Worker) - Serfs));
  +    Cnt := 0;
       for I := 0 to P.Units.Count - 1 do
         if not P.Units[I].IsDeadOrDying
            AND (P.Units[I] is TKMUnitSerf)
  -         AND (P.Units[I].UnitTask = nil) then
  -           Exit;
  -    // Increase count of serfs carefully
  -    Result := Max( 1 + Byte(gHands[fOwner].Stats.GetUnitQty(ut_Serf) < 80)*2, Result);
  +         AND (P.Units[I].IsIdle) then
  +        Cnt := Cnt + 1;
  +    // Increase count of serfs carefully (compute fraction of serfs who does not have job)
  +    if (Cnt / (Serfs*1.0) < GA_MANAGER_CheckUnitCount_SerfCoef) then
  +      Result := Max( 1 + Byte(Serfs < 40) + Byte(Serfs < 60), Result);
     end;
   
   const
  
positive.code:       // Materials
        S.NotAcceptFlag[wt_Trunk] := (aTick > TRUNK_STORE_DELAY); // Trunk should not be blocked because of forest cleaning
        S.NotAcceptFlag[wt_Wood] := (aTick > WOOD_STORE_DELAY);// AND (Predictor.WareBalance[wt_Wood].Exhaustion > 40);
        S.NotAcceptFlag[wt_Stone] := (aTick > STONE_STORE_DELAY) OR (S.CheckResIn(wt_Stone) > gHands[fOwner].Stats.GetUnitQty(ut_Worker));
        S.NotAcceptFlag[wt_Gold] := S.CheckResIn(wt_Gold) > 400; // Everyone needs as much gold as possible
  
        // Food - don't store food when we have enought (it will cause trafic before storehouse)
  
negative.code:       S.NotAcceptFlag[wt_Fish] := gHands[fOwner].Stats.GetWareBalance(wt_Fish) > 100;
  
        // Others
        S.NotAcceptFlag[wt_GoldOre] := True;
        S.NotAcceptFlag[wt_Coal] := True;
        S.NotAcceptFlag[wt_IronOre] := gHands[fOwner].Stats.GetHouseQty(htIronSmithy) > 0;
        S.NotAcceptFlag[wt_Steel] := gHands[fOwner].Stats.GetHouseQty(htWeaponSmithy) +
                                     gHands[fOwner].Stats.GetHouseQty(htArmorSmithy) > 0;
        S.NotAcceptFlag[wt_Corn] := (aTick > CORN_STORE_DELAY);
        S.NotAcceptFlag[wt_Leather] := True;
        S.NotAcceptFlag[wt_Flour] := True;
        //Pigs and skin cannot be blocked since if swinefarm is full of one it stops working (blocks other)
        //S.NotAcceptFlag[wt_Skin] := gHands[fOwner].Stats.GetHouseQty(htTannery) > 0;
        //S.NotAcceptFlag[wt_Pig] := gHands[fOwner].Stats.GetHouseQty(htButchers) > 0;
      end;
  end;
  
  