SRL Archive - OSR Help

TPA object finding


Wreck

2012-05-28 14:09:43

So today I set myself the task of learning about TPA's and what you can do with them and after hours of reading and tweaking (Massive thanks to Naum for his A low down on WizzyPlugin and TPA's) I have produced a function! :f:
For all who are interested this locates lobster fishing spots on the dock on karamja.
program TPATest;
{$i SRL/SRL.simba}
{$i SRL/srl/misc/debug.simba}

var
x, y: Integer;

function FindSpot: Boolean;
var
TPA: TPointArray;
ATPA: Array of TPointArray;
tmpCTS, i: Integer;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.30, 0.66);

if FindColorsSpiralTolerance(MSCX, MSCY, TPA, 11379612, MSX1, MSY1, MSX2, MSY2, 7) then
begin
SortTPAFrom(TPA, Point(MSCX, MSCY));
ATPA := TPAToATPAEx(TPA, 25, 25);
//ATPA := SplitTPAEx(TPA, 15, 15);
SortATPASize(ATPA, True);

For i := 0 To High(ATPA) Do
begin
MiddleTPAEx(ATPA[i], x, y);
MMouse(x, y, 5, 5);
if WaitUpTextMulti(['Cage', 'ge Fi'], 250) then
begin
Result := True;
GetMousePos(x, y);
Break;
end;
end;
end;

//DebugATPA(ATPA,'');
//DebugATPABounds(ATPA);
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;

begin
SetUpSRL;
ActivateClient;
if FindSpot then
writeln('spot found at: ' + IntToStr(x) + '.' + IntToStr(y));
end.
My problem is that im not entirely sure if i've missed something or put something in the wrong place or if it is working as intended as it doesnt always sorts by closest point properly but other than that it seems to work!
Other suggestions how this can be improved are welcome!

Home

2012-05-28 14:11:18

SortATPASize(ATPA, True);


to

SortATPAFromMidPoint(aTPA, Point(MSCX, MSCY)); 



~Home

Wreck

2012-05-28 14:19:16

From: Home
SortATPASize(ATPA, True);


to

SortATPAFromMidPoint(aTPA, Point(MSCX, MSCY)); 



~Home


Much better thanks, but does that make the
SortTPAFrom(TPA, Point(MSCX, MSCY));
completely pointless or is it still neccessary?

Runaway

2012-05-28 14:43:50

From: Wreck
but does that make the
SortTPAFrom(TPA, Point(MSCX, MSCY));
completely pointless or is it still neccessary?


It was useless from the start :P


if FindColorsSpiralTolerance(MSCX, MSCY, TPA, 11379612, MSX1, MSY1, MSX2, MSY2, 7) then
begin
SortTPAFrom(TPA, Point(MSCX, MSCY));

FindColorsSpiralTolerance does exactly what SortTPAFrom does; you're sorting the TPA from (MSCX, MSCY) twice.

Wreck

2012-05-28 14:57:57

From: Runaway
It was useless from the start :P


if FindColorsSpiralTolerance(MSCX, MSCY, TPA, 11379612, MSX1, MSY1, MSX2, MSY2, 7) then
begin
SortTPAFrom(TPA, Point(MSCX, MSCY));

FindColorsSpiralTolerance does exactly what SortTPAFrom does; you're sorting the TPA from (MSCX, MSCY) twice.


I used FindColorsSpiralTolerance instead of FindColorsTolerance for that exact reason and it never dawned on me that they did the same thing :redface:! Thanks.