SRL Archive - OSR Help

Parsing TPointArrays


serajin

2012-05-12 02:14:29

Is there a function to automatically parse "similar" tpoint coordinates inside an array, or do I need to write a custom one to look and decide?

Thanks!

Brandon

2012-05-12 02:21:14

What do you mean parse Similar TPoints inside an array..

Do you mean search an array for a tpoint? if so then:
PointInTPA will work..


Here's a couple others:

Function TPAPointInTPABounds(Search, EntireTPA: TPointArray): Boolean;
var
I, L: Integer;
Bounds: TBox;
begin
Result := True;
Bounds := GetTPABounds(EntireTPA);
L:= High(Search);
for I:= 0 To L do
if (PointInBox(Search[I], Bounds)) then
Exit;
Result := False;
end;

Function TPAInTPABounds(Search, EntireTPA: TPointArray): Boolean;
var
I, L: Integer;
Bounds: TBox;
begin
Result:= False;
Bounds:= GetTPABounds(EntireTPA);
L:= High(Search);
For I:= 0 To L do
if (Not PointInBox(Search[I], Bounds)) then
Exit;
Result:= True;
end;

Function TPAInTPAMajority(Search, EntireTPA: TPointArray): Boolean;
var
I, L, Found, NotFound: Integer;
Bounds: TBox;
begin
Bounds:= GetTPABounds(EntireTPA);
L:= High(Search);
For I:= 0 To L do
if (PointInBox(Search[I], Bounds)) then
Inc(Found)
else
Inc(NotFound);
Result:= Found >= NotFound;
end;

serajin

2012-05-12 02:23:36

Well, I am grabbing a lot of data on screen. I am grabbing all the "Grey", but I want to remove any 2 points that are too close, as I want to then search within this "grey" for another color (The gold of a bank symbol).

So I figured, if I grab all the grey on screen into an array. I can then parse the array so I have less points, and then use another findcolorsspiral function around each of these grey pixels to look for my gold.

Should I just use FindSymbol? Would that be easier..lol

Brandon

2012-05-12 02:28:44

From: serajin
Well, I am grabbing a lot of data on screen. I am grabbing all the "Grey", but I want to remove any 2 points that are too close, as I want to then search within this "grey" for another color (The gold of a bank symbol).

So I figured, if I grab all the grey on screen into an array. I can then parse the array so I have less points, and then use another findcolorsspiral function around each of these grey pixels to look for my gold.

Should I just use FindSymbol? Would that be easier..lol



These two could help you:

//FoundSymbol By Flight:
Function FoundSymbol(Ident: Integer; var X, Y, Dist: Integer): Boolean;
var
B: TBox;
TPA: TPointArray;
L,i,CTS: Integer;
ATPA,ATPA2: T2DPointArray;
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
FindColorsTolerance(TPA, 12632256, MMX1, MMY1, MMX2, MMY2, 5);
FilterPointsPie(TPA, 0.0, 360.0, 0.0, 70.0, MMCX, MMCY);
ColorToleranceSpeed(CTS);
if Length(TPA) < 1 then
Exit;
ATPA := TPAtoATPAEx(TPA, 10, 10);
L := High(ATPA);
SetArrayLength(ATPA2, L+1);
for i := 0 to L do
begin
B := GetTPABounds(ATPA[i]);
with B do
begin
if (Ident = 1) then
FindColorsTolerance(ATPA2[i], 4672833, B.X1, B.Y1, B.X2, B.Y2, 10) //Transporter Symbol.
else if(Ident = 2) then
FindColorsTolerance(ATPA2[i], 16279333, B.X1, B.Y1, B.X2, B.Y2, 10) //Water Symbol..
else if (Ident = 3) then
FindColorsTolerance(ATPA2[i], 2413294, B.X1, B.Y1, B.X2, B.Y2, 5); //Bank Symbol..
FFinder:= 'Found Symbol';
Result := (Length(ATPA2[i]) > 0);
if Result then
begin
MiddleTPAEx(ATPA2[i], X, Y);
Dist := Distance(MMCX, MMCY, X, Y);
Exit;
end;
end;
end;
end;

And the one by me:

Function FindObjectInObject(TPA: TPointArray; Color, Width, Height, Tolerance: Integer; Speed: TExtendedArray): TPointArray;
var
CTS, L, I: Integer;
TPACopy: TPointArray;
ATPA, ATPA2: T2DPointArray;
B: TBox;
begin
CTS:= GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Speed[0], Speed[1]);

if (Length(TPA) < 1) then
Exit;

TPACopy:= CopyTPA(TPA);
if (Length(TPACopy) < 1) then
Exit;

ATPA:= TPAToATPAEx(TPACopy, Width, Height);
SortATPASize(ATPA, True);
L := High(ATPA);
SetArrayLength(ATPA2, L+1);

For I:= 0 To L do
begin
B := GetTPABounds(ATPA[I]);
with B do
begin
FindColorsTolerance(ATPA2[I], Color, B.X1, B.Y1, B.X2, B.Y2, Tolerance);
if (Length(ATPA2[I]) < 1) then
Continue;
end;
end;
if (Length(ATPA2) > 0) then
Result:= MergeATPA(ATPA2)
else
Result:= [];

ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.02, 0.02);
end;

Function FoundSymbol(Ident: Integer; var Point: TPoint; var Dist: Integer): Boolean;
var
CTS, I, L: Integer;
TPA, ColorTPA: TPointArray;
ATPA: T2DPointArray;
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
FindColorsTolerance(TPA, 12632256, MMX1, MMY1, MMX2, MMY2, 5);
FilterPointsPie(TPA, 0.0, 360.0, 0.0, 75.0, MMCX, MMCY);
ColorToleranceSpeed(CTS);
if Length(TPA) < 1 then
Exit;

ATPA:= TPAToATPAEx(TPA, 10, 10);
L:= High(ATPA);
For I:= 0 To L Do
begin
case Ident of
1: ColorTPA:= FindObjectInObject(TPA, 1260388, 10, 10, 5, [0.2, 0.2]); //Mining Symbol.
2: ColorTPA:= FindObjectInObject(TPA, 2413294, 10, 10, 5, [0.2, 0.2]); //Bank Symbol.
3: ColorTPA:= FindObjectInObject(TPA, 13679255, 10, 10, 5, [0.2, 0.2]); //Transport Symbol.
4: ColorTPA:= FindObjectInObject(TPA, 2369228, 10, 10, 5, [0.2, 0.2]); //CastleWars Symbol.
5: ColorTPA:= FindObjectInObject(TPA, 9002045, 10, 10, 5, [0.2, 0.2]); //Summoning Symbol.
end;
Result := (Length(ColorTPA) > 0);
if Result then
begin
Point:= MiddleTPA(ColorTPA);
Dist := Distance(MMCX, MMCY, Point.X, Point.Y);
Exit;
end;
end;
end;

serajin

2012-05-12 02:31:22

Oh excellent! I think that's EXACTLY what I need!

Thank you!

Brandon

2012-05-12 02:33:22

From: serajin
Oh excellent! I think that's EXACTLY what I need!

Thank you!


Check the post I edited it.. Maybe mine was too complexed.. I posted a version by Flight which is pretty clean and simple.. It's only one function.

Myself I make things a bit hard.. so you might want to check that last post I made since I edited it. If you use Flight's, don't forget to credit him.

serajin

2012-05-12 02:37:16

Ofcourse! Credit to everyone! I'll go ahead and look at both.

Is there a place where these little helpful functions are already placed? Or is it just like, grabbing them from other scripts, saving them out, and using them later?

Daniel

2012-05-12 03:03:11

…or you could just use the various TPA methods included within Simba:
  • RAaSTPAEx / RAaSTPA / ReArrangeandShortenArrayEx / ReArrangeandShortenArray
  • NearbyPointInArrayEx / NearbyPointInArray
  • SplitTPAEx / SplitTPA / TPAtoATPAEx / TPAtoATPA

See: http://docs.villavu.com/simba/scriptref/tpa.html for more methods as-well as information on each individual function.

Abu

2012-05-12 07:53:15

From: serajin
Ofcourse! Credit to everyone! I'll go ahead and look at both.

Is there a place where these little helpful functions are already placed? Or is it just like, grabbing them from other scripts, saving them out, and using them later?


If you go here you will find a lot of useful functions in the SRL Snippets section as well as some in the Suggestions section.

Also, even though you have found the solution, I think this is EXACTLY what you were looking for: http://villavu.com/forum/showthread.php?t=81393

Joe

2012-05-12 07:56:22

From: Brandon
These two could help you:

//FoundSymbol By Flight:
Function FoundSymbol(Ident: Integer; var X, Y, Dist: Integer): Boolean;
var
B: TBox;
TPA: TPointArray;
L,i,CTS: Integer;
ATPA,ATPA2: T2DPointArray;
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
FindColorsTolerance(TPA, 12632256, MMX1, MMY1, MMX2, MMY2, 5);
FilterPointsPie(TPA, 0.0, 360.0, 0.0, 70.0, MMCX, MMCY);
ColorToleranceSpeed(CTS);
if Length(TPA) < 1 then
Exit;
ATPA := TPAtoATPAEx(TPA, 10, 10);
L := High(ATPA);
SetArrayLength(ATPA2, L+1);
for i := 0 to L do
begin
B := GetTPABounds(ATPA[i]);
with B do
begin
if (Ident = 1) then
FindColorsTolerance(ATPA2[i], 4672833, B.X1, B.Y1, B.X2, B.Y2, 10) //Transporter Symbol.
else if(Ident = 2) then
FindColorsTolerance(ATPA2[i], 16279333, B.X1, B.Y1, B.X2, B.Y2, 10) //Water Symbol..
else if (Ident = 3) then
FindColorsTolerance(ATPA2[i], 2413294, B.X1, B.Y1, B.X2, B.Y2, 5); //Bank Symbol..
FFinder:= 'Found Symbol';
Result := (Length(ATPA2[i]) > 0);
if Result then
begin
MiddleTPAEx(ATPA2[i], X, Y);
Dist := Distance(MMCX, MMCY, X, Y);
Exit;
end;
end;
end;
end;

And the one by me:

Function FindObjectInObject(TPA: TPointArray; Color, Width, Height, Tolerance: Integer; Speed: TExtendedArray): TPointArray;
var
CTS, L, I: Integer;
TPACopy: TPointArray;
ATPA, ATPA2: T2DPointArray;
B: TBox;
begin
CTS:= GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Speed[0], Speed[1]);

if (Length(TPA) < 1) then
Exit;

TPACopy:= CopyTPA(TPA);
if (Length(TPACopy) < 1) then
Exit;

ATPA:= TPAToATPAEx(TPACopy, Width, Height);
SortATPASize(ATPA, True);
L := High(ATPA);
SetArrayLength(ATPA2, L+1);

For I:= 0 To L do
begin
B := GetTPABounds(ATPA[I]);
with B do
begin
FindColorsTolerance(ATPA2[I], Color, B.X1, B.Y1, B.X2, B.Y2, Tolerance);
if (Length(ATPA2[I]) < 1) then
Continue;
end;
end;
if (Length(ATPA2) > 0) then
Result:= MergeATPA(ATPA2)
else
Result:= [];

ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.02, 0.02);
end;

Function FoundSymbol(Ident: Integer; var Point: TPoint; var Dist: Integer): Boolean;
var
CTS, I, L: Integer;
TPA, ColorTPA: TPointArray;
ATPA: T2DPointArray;
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
FindColorsTolerance(TPA, 12632256, MMX1, MMY1, MMX2, MMY2, 5);
FilterPointsPie(TPA, 0.0, 360.0, 0.0, 75.0, MMCX, MMCY);
ColorToleranceSpeed(CTS);
if Length(TPA) < 1 then
Exit;

ATPA:= TPAToATPAEx(TPA, 10, 10);
L:= High(ATPA);
For I:= 0 To L Do
begin
case Ident of
1: ColorTPA:= FindObjectInObject(TPA, 1260388, 10, 10, 5, [0.2, 0.2]); //Mining Symbol.
2: ColorTPA:= FindObjectInObject(TPA, 2413294, 10, 10, 5, [0.2, 0.2]); //Bank Symbol.
3: ColorTPA:= FindObjectInObject(TPA, 13679255, 10, 10, 5, [0.2, 0.2]); //Transport Symbol.
4: ColorTPA:= FindObjectInObject(TPA, 2369228, 10, 10, 5, [0.2, 0.2]); //CastleWars Symbol.
5: ColorTPA:= FindObjectInObject(TPA, 9002045, 10, 10, 5, [0.2, 0.2]); //Summoning Symbol.
end;
Result := (Length(ColorTPA) > 0);
if Result then
begin
Point:= MiddleTPA(ColorTPA);
Dist := Distance(MMCX, MMCY, Point.X, Point.Y);
Exit;
end;
end;
end;


why not just
 findsymbol('bank');
? I don't see why you need a TPA for that…