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!
Thanks!
2012-05-12 02:14:29
2012-05-12 02:21:14
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;
2012-05-12 02:23:36
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
//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;
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;
2012-05-12 02:31:22
2012-05-12 02:33:22
From: serajin
Oh excellent! I think that's EXACTLY what I need!
Thank you!
2012-05-12 02:37:16
2012-05-12 03:03:11
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?
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;
findsymbol('bank');? I don't see why you need a TPA for that…