Runaway
2012-05-17 12:19:09
This is a function similar to function FindTPACluster(): array of TPointArray, but it's actually quite different. That is a slower, but more precise version.
You can input as many colors as you need and it will only return clusters it finds where ALL colors specified are within the given distance of the "primary" color (which is the color declared first in the Colors array). This is done by using the NearbyPointInArray function, and a point is only added to the result array if it's within the specified distance of every other color found. Very useful for Map walking, and object finding since you can specify which color to click, but still use the color comparison advantage that this function supplies.
I'll be updating this thread with extensive testing as soon as I get to it. I've used this function in my Rimmington Tele-Banker script for item-finding, map walking, and npc-finding if you want to see it in action.
Usage:
It's 100% failsafe'd, and it's got a great debug if you have any problems. It currently takes between 100-300 ms to find and parse all of the colors/points. I'd love to see some people test this out in scripts and see how it goes :)
Descripton:
Function:
Example Debug:
If you want to test it out for yourself, I've attached a testing script with debug, paint, and all sorts of options all set up and ready to go. All you have to do is select the area, colors, etc. :)
function FindTPointCluster(Colors: TIntegerArray; Tol: Integer; SortFrom: TPoint; Filter, Trim, MaxDist: Integer; Strict: Boolean; x1, y1, x2, y2: Integer): TPointArray;You can input as many colors as you need and it will only return clusters it finds where ALL colors specified are within the given distance of the "primary" color (which is the color declared first in the Colors array). This is done by using the NearbyPointInArray function, and a point is only added to the result array if it's within the specified distance of every other color found. Very useful for Map walking, and object finding since you can specify which color to click, but still use the color comparison advantage that this function supplies.
I'll be updating this thread with extensive testing as soon as I get to it. I've used this function in my Rimmington Tele-Banker script for item-finding, map walking, and npc-finding if you want to see it in action.
Usage:
Arr := FindTPACluster(Colors, Tol, SortFrom, FilterArr, TrimArr, 0, MaxDist, True, Area[0], Area[1], Area[2], Area[3]);
SplitTPAWrap(Arr, MaxDist, aArr);
SMART_ClearCanvas;
for a := 0 to High(aArr) do
SMART_DrawCircle(False, MiddleTPA(Arr[a]), MaxDist, False, clred);
It's 100% failsafe'd, and it's got a great debug if you have any problems. It currently takes between 100-300 ms to find and parse all of the colors/points. I'd love to see some people test this out in scripts and see how it goes :)
Descripton:
(*
FindTPointCluster
~~~~~~~
.. code-block:: pascal
function FindTPointCluster(Colors: TIntegerArray; Tol: Integer; SortFrom: TPoint; Filter, Trim, MaxDist: Integer; Strict: Boolean; x1, y1, x2, y2: Integer): TPointArray;
Results a TPointArray which holds "clusters" of the the first specified color in
each TPoint. It can search for an unlimited number of colors in x1, y1, x2, y2.
* Colors: The colors to be found and grouped depending on proximity. Enter the
main color first in the array.
* Tol: The tolerance on each color.
* SortFrom: The point to sort each TPoint from.
* Filter: The maximum distance between SortFrom and each TPoint. -1 to not use.
* Trim: The maximum length of each TPointArray. -1 to not use.
* MaxDist: The maximum distance between each color can be in each cluster.
* Strict: True to exit the function if not all of the specified colors are found.
.. note::
by Runaway
Example:
.. code-block:: pascal
Colors := [16514558, 5062187, 4664874];
Arr := FindTPointCluster(Colors, 20, Point(MMCX, MMCY), -1, 200, 30, True, MMX1, MMY1, MMX2, MMY2);
SplitTPAWrap(Arr, 30, aArr);
for i := 0 to High(aArr) do
begin
x := MiddleTPA(aArr[i]).x;
y := MiddleTPA(aArr[i]).y;
if (not rs_OnMinimap(x, y)) then
Continue;
Mouse(x, y, 3, 3, mouse_left);
if DidClick(True, RandomRange(750, 1250)) then
Break;
end;
*)
Function:
function FindTPointCluster(Colors: TIntegerArray; Tol: Integer; SortFrom: TPoint; Filter, Trim, MaxDist: Integer; Strict: Boolean; x1, y1, x2, y2: Integer): TPointArray;
var
TPA: TPointArray;
aPoints: array of TPointArray;
hPoints, hColors: Integer;
Error, Len, Match: Integer;
t, r, i, ii: Integer;
begin
MarkTime(t);
SetLength(aPoints, Length(Colors));
hColors := High(Colors);
Error := 0;
r := 0;
for i := 0 to hColors do
begin
if (FindColorsTolerance(TPA, Colors[i], x1, y1, x2, y2, Tol)) then
begin
SortTPAFrom(TPA, SortFrom);
if (Filter <> -1) then
FilterPointsDist(TPA, 0, Filter, SortFrom.x, SortFrom.y);
if (Trim <> -1) and (Length(TPA) > Trim) then
SetLength(TPA, Trim);
aPoints[i - Error] := TPA;
end else
begin
if Strict then
begin
Writeln('Error: not enough colors found!');
Exit;
end;
Len := Length(aPoints) - 1;
SetLength(aPoints, Len);
Inc(Error);
end;
if (Error >= hColors) then
begin
Writeln('Error: not enough colors found!');
Exit;
end;
end;
hPoints := High(aPoints);
for i := 0 to High(aPoints[0]) do
begin
Match := 0;
for ii := 1 to hPoints do
begin
if NearbyPointInArray(aPoints[0][i], MaxDist, aPoints[ii]) then
begin
Inc(Match);
if (Match >= hPoints) then
begin
SetLength(Result, r + 1);
Result[r] := aPoints[0][i];
Inc(r);
end;
end else
Break;
end;
end;
SortTPAFrom(Result, SortFrom);
Writeln('Took: '+IntToStr(TimeFromMark(t))+' ms, found '+IntToStr(Length(Result))+' point(s)');
end;
Example Debug:
Searching: color 1 of 3...
Found: 584 point(s) of color 8083520
Using: first 500 point(s) of color 8083520
Searching: color 2 of 3...
Found: 1314 point(s) of color 16777215
Using: first 500 point(s) of color 16777215
Searching: color 3 of 3...
Found: 327 point(s) of color 15326682
Using: first 327 point(s) of color 15326682
Searching... done
Sorting...
Sorting... done
Took: 218 ms, found 445 point(s)
Successfully executed.
If you want to test it out for yourself, I've attached a testing script with debug, paint, and all sorts of options all set up and ready to go. All you have to do is select the area, colors, etc. :)