anchor.diff:  
     AvaiableCnt := 0;
     SetLength(AvaiableWares, RequiedCnt);
  -  for L := Low(SOLD_ORDER) to High(SOLD_ORDER) do
  -    if gHands[fOwner].Stats.GetWareBalance( SOLD_ORDER[L] ) > SELL_LIMIT then
  -    begin
  -      if L >= RequiedCnt then
  -         break;
  -      AddWare(SOLD_ORDER[L], False);
  -    end;
  -
  -  for L := 0 to RequiedCnt do
  -   if L < AvaiableCnt then
  -     TryBuyItem(AvaiableWares[L], RequiredWares[L])
  -   else
  -     break;
  +  for I := 0 to Length(SOLD_ORDER) - 1 do
  +    if (AvaiableCnt < RequiedCnt) then
  +    begin
  +      WareCnt := gHands[fOwner].Stats.GetWareBalance( SOLD_ORDER[I] );
  +      if (  (SOLD_ORDER[I] in [WARFARE_MIN..WARFARE_MAX]) AND (WareCnt > WARFARE_SELL_LIMIT)  )
  +         OR (WareCnt > SELL_LIMIT) then
  +        AddWare(SOLD_ORDER[I], False);
  +    end;
  +
  +  for I := 0 to RequiedCnt - 1 do
  +    if (I < AvaiableCnt) then
  +      TryBuyItem(AvaiableWares[I], RequiredWares[I])
  +  else
  +    break;
   end;
   
   
  
positive.code:     wt_Horse,        wt_Corn,     wt_Flour,
      wt_Steel,        wt_Gold,     wt_IronOre,    wt_Coal,     wt_GoldOre
    );
  var
    MarketCnt, RequiedCnt, AvaiableCnt, L: Word;
    RequiredWares, AvaiableWares: array of TWareType;
  
    procedure AddWare(aWare: TWareType; IsRequired: Boolean = True);
    begin
      if IsRequired then
      begin
        RequiredWares[RequiedCnt] := aWare;
        RequiedCnt := RequiedCnt + 1;
      end
      else
      begin
        AvaiableWares[AvaiableCnt] := aWare;
        AvaiableCnt := AvaiableCnt + 1;
      end;
    end;
  
    procedure TryBuyItem(aResFrom, aResTo: TWareType);
    var
      M: Integer;
      Houses: TKMHousesCollection;
      H: TKMHouseMarket;
    begin
      Houses := gHands[fOwner].Houses;
      for M := 0 to Houses.Count - 1 do
        if (Houses[M].HouseType = ht_Marketplace)
          AND Houses[M].IsComplete
          AND not Houses[M].IsDestroyed then
        begin
          H := TKMHouseMarket(Houses[M]);
          if (TKMHouseMarket(H).ResOrder[0] <> 0)
            AND (H.ResTo = aResTo) then
            Exit;
        end;
      for M := 0 to Houses.Count - 1 do
        if (Houses[M].HouseType = ht_Marketplace)
          AND Houses[M].IsComplete
          AND not Houses[M].IsDestroyed then
        begin
          H := TKMHouseMarket(Houses[M]);
          if H.AllowedToTrade(aResFrom)
            AND H.AllowedToTrade(aResTo)
            AND (TKMHouseMarket(H).ResOrder[0] = 0) then
          begin
            if (H.ResFrom <> aResFrom) or (H.ResTo <> aResTo) then
            begin
              //H.ResOrder[0] := 0; //First we must cancel the current trade
              H.ResFrom := aResFrom;
              H.ResTo := aResTo;
              H.ResOrder[0] := 20; //Set the new trade
              break;
            end;
          end;
        end;
    end;
  const
    MIN_GOLD_AMOUNT = LACK_OF_GOLD * 3;
    LACK_OF_STONE = 50;
    SELL_LIMIT = 100;
  begin
  
    MarketCnt := gHands[fOwner].Stats.GetHouseQty(ht_Marketplace);
  
negative.code:     Exit;
  
    RequiedCnt := 0;
    SetLength(RequiredWares,4);
    with gHands[fOwner].Stats do
    begin
      // Gold
      if (GetHouseQty(ht_Metallurgists) = 0)
         AND (GetWareBalance(wt_Gold) <= LACK_OF_GOLD) then
         AddWare(wt_Gold);
  