Results 1 to 3 of 3

Thread: SmartDrop - Advanced dropping procedure

  1. #1
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default SmartDrop - Advanced dropping procedure

    SCAR Code:
    procedure DTMFromInv(var oDTM: Integer; slot, refPts: Integer);
    var
      Skel: TDTM;
      mainPt: TDTMPointDef;
      subPts: array of TDTMPointDef;
      outPts: TPointArray;
      invBoxC: TBox;
      i, outRat, rI: Integer;
    begin
      invBoxC := InvBox(slot);
      if not FindColorsTolerance(outPts, 65536, invBoxC.x1 + 2, invBoxC.y1 + 2, invBoxC.x2 - 2, invBoxC.y2 - 2, 1) then
      begin
        Writeln('Unable to create DTM from inventory slot');
        Exit;
      end;
      with mainPt do
      begin
        x := (invBoxC.x1 + invBoxC.x2) div 2;
        y := (invBoxC.y1 + invBoxC.y2) div 2;
        areasize:= 0;
        areashape:= 0;
        color:= GetColor(mainPt.x, mainPt.y);
        tolerance:= 422;
      end;
      SetArrayLength(subPts, refPts);
      outRat := GetArrayLength(outPts) div refPts;
      for i := 0 to refPts - 1 do
      begin
        rI := Random(Random(Round(outRat)));
        with subPts[i] do
        begin
          x := outPts[round(i * outRat) + rI].x;
          y := outPts[round(i * outRat) + rI].y;
          areasize:= 0;
          areashape:= 0;
          color:= 65536;
          tolerance:= 1;
        end;
      end;
      Skel.MainPoint := mainPt;
      Skel.SubPoints := subPts;
      oDTM := AddDTM(Skel);
    end;

    { benchmark for five 1000 runs in a row
    DTMFromInv works at 1.375ms
    DTMFromInv works at 1.422ms
    DTMFromInv works at 1.5ms
    DTMFromInv works at 1.515ms
    DTMFromInv works at 1.516ms
    }


    function CompStrWArr(str: string; strArr: array of string): boolean;
    var
      i: Integer;
    begin
      for i := 0 to High(strArr) do
      begin
        Result := str = strArr[i];
        if(Result)then
          Break;
      end;
    end;

    function SmartDrop(var iDtmArr: array of Integer; var sDtmArr: array of string; sItemsArr: array of string; bDropMatched: Boolean): Integer;
    var
      iX, iY, iItemX, iItemY, iItem, iDtm, iStr, iItemOffset: Integer;
      bDir, bDropSet: Boolean;
      tbItem: TBox;
    begin
      bDir := RBool;
      for iItemY := 1 to 7 do
      begin
        for iItemX := 1 to 4 do
        begin
          bDropSet := False;
          if((bDir)and(iItemY mod 2 = 1))or((not(bDir))and(iItemY mod 2 = 0))then
            iItemOffset := 5 - iItemX
          else
            iItemOffset := iItemX;
          iItem := ((iItemY - 1) * 4) + iItemOffset;
          if(not(ExistsItem(iItem)))then
          begin
            Continue;
          end;
          tbItem := InvBox(iItem);
          if(High(iDtmArr) >= 0) then
          begin
            for iDtm := 0 to High(iDtmArr) do
            begin
              if((CompStrWArr(sDtmArr[iDtm], sItemsArr)) and (FindDtm(iDtmArr[iDtm], iX, iY, tbItem.x1, tbItem.y1, tbItem.x2, tbItem.y2))and(not(bDropSet)))then
              begin
                bDropSet := True;
              end;
            end;
          end;
          if(not(bDropSet))then
          begin
            MMouseItem(iItem);
            Wait(250+Random(Random(1000)));
            for iStr := 0 to High(sItemsArr) do
            begin
              if(IsUpText(sItemsArr[iStr])and(not(bDropSet)))then
              begin
                bDropSet := True;
                SetArrayLength(iDtmArr, High(iDtmArr) + 2);
                SetArrayLength(sDtmArr, High(sDtmArr) + 2);
                DTMFromInv(iDtmArr[High(iDtmArr)], iItem, 15);
                sDtmArr[High(sDtmArr)] := sItemsArr[iStr];
              end;
            end;
          end;
          if(not(bDropSet xor bDropMatched))then
          begin
            GetMousePos(iX, iY);
            if(not((iX >= tbItem.x1) and (iX <= tbItem.x2) and (iY >= tbItem.y1) and (iY <= tbItem.y2)))then
              DropItem(iItem)
            else
            begin
              Mouse(iX, iY, 1, 1, False);
              Wait(150 + Random(75));
              if(not(ChooseOption('Drop')))then
                Dec(Result)
              else
                Wait(100 + Random(50));
            end;
            Inc(Result);
            Wait(Random(Random(500)));
          end;
        end;
      end;
    end;

    The top two functions are required for SmartDrop to work. What it does is take in 2 arrays - an integer and string - which store information about DTM's it makes. The next TStringArray stores all of the UpText checks you want to use to check then the last boolean is whether you want to drop matched items or keep matched items.

    The function works by first comparing the item box against all DTM's it has pre-stored, though first checks if the DTM string for that matches one of the inputted strings. If none of them match, then it moves to the item and compares all of the inputted strings against the UpText and if it matches, it will then make a new DTM for it and add it onto the previous list of DTM's. Not only that, but it also drops in a more human fashion by going from checking items 1,2,3,4 then checking 8,7,6,5 which means it goes from right to left, down one, right to left and continues, though it does randomly decide which direction to go in so can go 1,2,3,4 or 4,3,2,1

    This is a second draft function (first draft was the initial design with this one being tested to make sure it works) so hasn't got many failsafes and I really am just posting this for more input into it
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  2. #2
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    If you really care about compiling speed (and neatness), replace all "Array of (vartype)" with "T(Vartype)Array". I don't know if thats just for me, but TStringArray gives a faster compiling speed than an array of string.

    Not only that, but it also drops in a more human fashion by going from checking items 1,2,3,4 then checking 8,7,6,5 which means it goes from right to left, down one, right to left and continues, though it does randomly decide which direction to go in so can go 1,2,3,4 or 4,3,2,1
    YES! Great!

    This really looks like a neat add for SRL, just needs some more failsafes as you said.
    And, I don't know if freeing DDTMs is needed, but you never do that.

  3. #3
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    The main problem is that it dynamically creates the DTM's, so I would have to make a separate free procedure (which I do plan on adding) to be placed at the end. The compiling times I'm not so bothered about, I just had the benchmarks for DTMFromInv because wizzup requested them on the IRC but I'll test it anyway
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 8
    Last Post: 06-05-2008, 05:14 PM
  2. Dropping procedure not working correctly
    By HyperSecret in forum OSR Help
    Replies: 0
    Last Post: 04-17-2008, 05:16 AM
  3. Replies: 13
    Last Post: 04-12-2008, 05:32 PM
  4. need scar procedure for dropping
    By poolikemax in forum OSR Help
    Replies: 2
    Last Post: 02-07-2008, 09:31 AM
  5. Please need dropping procedure
    By RudeBoiAlex in forum OSR Help
    Replies: 11
    Last Post: 03-04-2007, 08:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •