Results 1 to 4 of 4

Thread: FindDTMSpiral and FindDTMRotatedSpiral

  1. #1
    Join Date
    Aug 2007
    Posts
    429
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default FindDTMSpiral and FindDTMRotatedSpiral

    I noticed that there were no functions involving finding DTMs in a spiral, so I attempted to make my own version
    Pretty simple.. just uses boxes..

    P.S. if you use please make sure to tell me if they work =]]

    SCAR Code:
    Function FindDTMSpiral(DTM: Integer; var x, y: Integer; x1, y1, x2, y2: Integer; Rotated: Boolean): Boolean;
    //by Derek- (will do a spiral search for a DTM(and a rotated DTM is rotated is True))
    var
      dx, dy : Integer;
      Box : TBox;
      BoxSize, BoxSizeInc : TPoint;
    begin
      Case Rotated of
        True: if not DTMRotated(DTM, x, y, x1, y1, x2, y2) then Exit;
        False: if not FindDTM(DTM, x, y, x1, y1, x2, y2) then Exit;
      end;
      BoxSize.x := (x2 - x1)/10;
      BoxSize.y := (x2 - x1)/10;
      BoxSizeInc.x := BoxSize.x * 2;
      BoxSizeInc.y := BoxSize.y * 2;
      repeat
        Box.x1 := x1 +(((x2 - x1)/2) - BoxSize.x);
        Box.y1 := y1 +(((y2 - y1)/2) - BoxSize.y);
        Box.x2 := x1 +(((x2 - x1)/2) + BoxSize.y);
        Box.y2 := y1 +(((y2 - y1)/2) + BoxSize.x);
        Case Rotated of
          True: if DTMRotated(DTM, dx, dy, Box.x1, Box.y1, Box.x2, Box.y2) then Result := True;
          False: if FindDTM(DTM, dx, dy, Box.x1, Box.y1, Box.x2, Box.y2) then Result := True;
        end;
        if Result then
        begin
          x := dx;
          y := dy;
          Break;
        end else
        begin
          IncEx(BoxSize.x, BoxSizeInc.x);
          IncEx(BoxSize.y, BoxSizeInc.y);
        end;
      until Result or ((BoxSize.x >= (x2 - x1)) and (BoxSize.y >= (y2 - y1)))
    end;


    BEST USAGE
    = I originally made for finding the closest tree to player on Minimap.
    SCAR Code:
    var
      TreeDTM : Integer;
    begin
       TreeDTM := DTMFromString('78DA63FCC0C4C0A0C3C80002EC0C10106521C' +
           'C2007A441A2CC20FA3BA61AEB6411B81A1060FC02546340841A4D' +
           '543546017C7035FF8100007FB40BC1');
       if FindDTMSpiral(TreeDTM, x, y, MMX1, MMY1, MMX2, MMY2, True) then Mouse(x, y, 0, 0, True);
    end;

  2. #2
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Isn't it smarter to first find the DTM, so if its not found, it doesn't have to go trhough the repeat loop?
    Verrekte Koekwous

  3. #3
    Join Date
    Aug 2007
    Posts
    429
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    Guess you're right, good point

    Added.

  4. #4
    Join Date
    Aug 2007
    Posts
    1,404
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Seems ok A regular FindDTM would sometimes be more efficient than FindDTMSpiral, though

    I made something for the mainscreen not so long ago, that used skipboxes Could also work for bitmaps

    -Knives

Thread Information

Users Browsing this Thread

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

Posting Permissions

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