Macro_FTW
2009-06-19 04:44:41
FindObjectATPA is kind of like FindObjTPA, but it uses ATPAs. I have also added a version that takes a TIntegerArray of colors.
With its variant, which takes an array of colors, as opposed to a single color.
Comments, questions, suggestions, criticism, etc. please feel free to post. :)
~Macro
{*******************************************************************************
function FindObjectATPA(var x, y: Integer; Color, Tol: Integer; Area: (MS, MI, MM); Radius: Integer; UpText: TStringArray): Boolean;
By: Macro_FTW
Description: Attempts to find an object with UpText using the color given and
ATPAs. Uses Tolerance and Spiral colorfinding. Returns true if found, false if
not.
x, y: Where the object is
Color: Color to search for
Tol: Tolerance of that color
Area: MS for Main Screen, MI for Inventory, MM for Minimap
Radius: The 'Radius' parameter for ATPAs
UpText: The uptext the object should have.
*******************************************************************************}
function FindObjectATPA(var x, y: Integer; Color, Tol: Integer; Area: (MS, MI, MM); Radius: Integer; UpText: TStringArray): Boolean;
var
CPoint: TPoint;
InitTPA: TPointArray;
InitATPA: T2DPointArray;
SArea: TBox;
i, MaxIndex, OldCTS: Integer;
begin
OldCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(1); //Not sure if I should do 2 because I'm using RGB tolerance as an arg.
case Area of
MS: begin
SArea.x1 := MSx1;
SArea.y1 := MSy1;
SArea.x2 := MSx2;
SArea.y2 := MSy2;
end;
MI: begin
SArea.x1 := MIx1;
SArea.y1 := MIy1;
SArea.x2 := MIx2;
SArea.y2 := MIy2;
end;
MM: begin
SArea.x1 := MMx1;
SArea.y1 := MMy1;
SArea.x2 := MMx2;
SArea.y2 := MMy2;
end;
end;
FindColorsSpiralTolerance(x, y, InitTPA, Color, SArea.x1, SArea.y1, SArea.x2, SArea.y2, Tol);
InitATPA := TPAtoATPA(InitTPA, Radius);
MaxIndex := High(InitATPA);
for i:=0 to MaxIndex do
begin
CPoint := MiddleTPA(InitATPA[i]);
MMouse(x, y, 5, 5);
wait(100+random(300));
if(IsUpTextMultiCustom(UpText))then
begin
Result := True;
Exit;
end;
end;
ColorToleranceSpeed(OldCTS);
Result := False;
end;
With its variant, which takes an array of colors, as opposed to a single color.
{*******************************************************************************
function FindObjectATPAMC(var x, y: Integer; Colors: TIntegerArray; Tol: Integer; Area: (MS, MI, MM); Radius: Integer; UpText: TStringArray): Boolean;
By: Macro_FTW
Description: Attempts to find an object with UpText using the colors given and
ATPAs. Uses Tolerance and Spiral colorfinding. Returns true if found, false if
not.
x, y: Where the object is post-search
Colors: Colors to search for
Tol: Tolerance of that color
Area: MS for Main Screen, MI for Inventory, MM for Minimap
Radius: The 'Radius' parameter for ATPAs
UpText: The uptext the object should have.
*******************************************************************************}
function FindObjectATPAMC(var x, y: Integer; Colors: TIntegerArray; Tol: Integer; Area: (MS, MI, MM); Radius: Integer; UpText: TStringArray): Boolean;
var
CPoint: TPoint;
InitTPA, ConcatTPA: TPointArray;
InitATPA: T2DPointArray;
SArea: TBox;
i, MaxIndex, OldCTS: Integer;
begin
OldCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(1);
case Area of
MS: begin
SArea.x1 := MSx1;
SArea.y1 := MSy1;
SArea.x2 := MSx2;
SArea.y2 := MSy2;
end;
MI: begin
SArea.x1 := MIx1;
SArea.y1 := MIy1;
SArea.x2 := MIx2;
SArea.y2 := MIy2;
end;
MM: begin
SArea.x1 := MMx1;
SArea.y1 := MMy1;
SArea.x2 := MMx2;
SArea.y2 := MMy2;
end;
end;
MaxIndex := High(Colors);
for i:=0 to MaxIndex do
begin
FindColorsSpiralTolerance(x, y, InitTPA, Colors[i], SArea.x1, SArea.y1, SArea.x2, SArea.y2, Tol);
ConcatTPA := CombineTPA(ConcatTPA, InitTPA);
end;
InitATPA := TPAtoATPA(ConcatTPA, Radius);
MaxIndex := High(InitATPA);
for i:=0 to MaxIndex do
begin
CPoint := MiddleTPA(InitATPA[i]);
MMouse(x, y, 5, 5);
wait(100+random(300));
if(IsUpTextMultiCustom(UpText))then
begin
Result := True;
ColorToleranceSpeed(OldCTS);
Exit;
end;
end;
ColorToleranceSpeed(OldCTS);
Result := False;
end;Comments, questions, suggestions, criticism, etc. please feel free to post. :)
~Macro