PDA

View Full Version : FindDTMSpiral and FindDTMRotatedSpiral



Derek-
12-16-2007, 07:52 PM
I noticed that there were no functions involving finding DTMs in a spiral, so I attempted to make my own version :p
Pretty simple.. just uses boxes.. :)

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

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.

var
TreeDTM : Integer;
begin
TreeDTM := DTMFromString('78DA63FCC0C4C0A0C3C80002EC0C1010652 1C' +
'C2007A441A2CC20FA3BA61AEB6411B81A1060FC0254634084 1A4D' +
'543546017C7035FF8100007FB40BC1');
if FindDTMSpiral(TreeDTM, x, y, MMX1, MMY1, MMX2, MMY2, True) then Mouse(x, y, 0, 0, True);
end;

mastaraymond
12-16-2007, 08:32 PM
Isn't it smarter to first find the DTM, so if its not found, it doesn't have to go trhough the repeat loop?

Derek-
12-16-2007, 08:36 PM
Guess you're right, good point :)

Added. :p

King of Knives
12-16-2007, 09:02 PM
Seems ok :p A regular FindDTM would sometimes be more efficient than FindDTMSpiral, though :p

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

-Knives