SCAR Code:
Procedure CopyTBox(Origin, var BoxTo: TBox);
begin
BoxTo := IntToBox(Origin.X1, Origin.Y1, Origin.X2, Origin.Y2);
end;
{******************************************************************************}
{ Function MSI_FindObjectsTPA( ... ): Boolean; }
{ By: marpis }
{ Date: 25 June 2010 }
{ Description: Finds objects in mainscreen, saves co-ords in TPA }
{******************************************************************************}
Function MSI_FindObjectsTPA(Var Objs: TPointArray; ObjInfo: TMSObject; SearchBox: TBox; CheckText: Boolean): Boolean;
Var
TPA, TempTPA: TPointArray;
ATPA: T2DPointArray;
I, II, CTS, TMP, H: Integer;
SelfBox: TBox;
Boxes, NotBoxes: TBoxArray;
Animating2: TBooleanArray;
BadPoint: Boolean;
Begin
If (Not LoggedIn) Then Exit;
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(ObjInfo.Hue, ObjInfo.Sat);
SelfBox := IntToBox(228, 150, 275, 200);
H := High(ObjInfo.Colors);
SetLength(ATPA, H + 1);
For I := 0 To H Do
FindColorsSpiralTolerance(MSCX, MSCY, ATPA[I], ObjInfo.Colors[I], SearchBox.X1, SearchBox.Y1, SearchBox.X2, SearchBox.Y2, ObjInfo.Tol);
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
{ Check if some of the colors was not on MS. }
If ObjInfo.FindAllColors Then
For I := 0 To H Do
If (Length(ATPA) < 1) Then
Begin
MSI_Debug('MSI_FindObjectsTPA', 'All colors weren''t found!', DEBUG_SMALL_DETAILS);
Objs := [];
Exit;
End;
{ Check if we have enough pixels on MS. }
TPA := MergeATPA(ATPA);
//DrawDots(TPA, 1000);
If (Length(TPA) < ObjInfo.Accuracy) Then
Begin
MSI_Debug('MSI_FindObjectsTPA', 'No colors found!', DEBUG_SMALL_DETAILS);
Objs := [];
Exit;
End;
ATPA := TPAtoATPAEx(TPA, ObjInfo.W, ObjInfo.H);
SortATPAFrom(ATPA, Point(MSCX, MSCY));
H := High(ATPA);
SetLength(TPA, H + 1);
For I := 0 To H Do
TPA[I] := MiddleTPA(ATPA[I]);
H := High(TPA);
SetLength(Boxes, H + 1);
For I := 0 To H Do
Begin
Boxes[I].X1 := TPA[I].X - (ObjInfo.W / 2);
Boxes[I].Y1 := TPA[I].Y - (ObjInfo.H / 2);
Boxes[I].X2 := TPA[I].X + (ObjInfo.W / 2);
Boxes[I].Y2 := TPA[I].Y + (ObjInfo.H / 2);
End;
If ObjInfo.Anim Then
Animating2 := AnimatingMulti(Boxes, 100, 1);
For I := 0 To High(TPA) Do
Begin
BadPoint := False;
//DrawBox(Boxes[I], 200);
{Bad Boxes}
if not BadPoint then
if Length(NotBoxes) > 0 then
begin
TMP := High(NotBoxes);
for II := 0 to TMP do
if PointInBox(TPA[i], NotBoxes[II])) then
begin
MSI_Debug('MSI_FindObjectsTPA', 'Point in bad Box', DEBUG_SMALL_DETAILS);
BadPoint := True;
break;
end;
end;
{ Animation }
If (Not BadPoint) Then
If ObjInfo.Anim Then
If (Not Animating2[I]) Then
Begin
MSI_Debug('MSI_FindObjectsTPA', 'Not animating!', DEBUG_SMALL_DETAILS);
BadPoint := True;
End;
{ Exclude own character }
If (Not BadPoint) Then
If ObjInfo.ExcludeSelf Then
If PointInBox(TPA[I], SelfBox) Then
Begin
MSI_Debug('MSI_FindObjectsTPA', 'Own character!', DEBUG_SMALL_DETAILS);
BadPoint := True;
End;
{ Invalid point }
If (Not BadPoint) Then
If ((TPA[I].X + TPA[I].Y) < 1) Then
Begin
MSI_Debug('MSI_FindObjectsTPA', 'Invalid point!', DEBUG_SMALL_DETAILS);
BadPoint := True;
End;
{ Accuracy }
If (Not BadPoint) Then
If (Length(ATPA[I]) < ObjInfo.Accuracy) Then
Begin
MSI_Debug('MSI_FindObjectsTPA', 'Not enough points!', DEBUG_SMALL_DETAILS);
BadPoint := True;
End;
{ Bad colors }
If (Not BadPoint) Then
For II := 0 To High(ObjInfo.BadColors) Do
Begin
MSI_Debug('MSI_FindObjectsTPA', 'Looking for bad color: '+IntToStr(ObjInfo.BadColors[II]), DEBUG_SMALL_DETAILS);
If FindColorSpiralTolerance(TMP, TMP, ObjInfo.BadColors[II], TPA[I].X - (ObjInfo.W / 2), TPA[I].Y - (ObjInfo.H / 2), TPA[I].X + (ObjInfo.W / 2), TPA[I].Y + (ObjInfo.H / 2), ObjInfo.BadColorTolerance) Then
Begin
MSI_Debug('MSI_FindObjectsTPA', 'Bad color found!', DEBUG_SMALL_DETAILS);
BadPoint := True;
Break;
End;
End;
{ FindAllColors }
If (Not BadPoint) Then
If ObjInfo.FindAllColors Then
For II := 0 To H Do
Begin
TempTPA := MSI_ReturnPointsInBox(ATPA[II], IntToBox(TPA[I].X - (ObjInfo.W / 2), TPA[I].Y - (ObjInfo.H / 2), TPA[I].X + (ObjInfo.W / 2), TPA[I].Y + (ObjInfo.H / 2)));
If (Length(TempTPA) < 1) Then
Begin
MSI_Debug('MSI_FindObjectsTPA', 'All colors weren''t found!', DEBUG_SMALL_DETAILS);
BadPoint := True;
Break;
End;
End;
{ Text Checking }
if not BadPoint then
if CheckText then
begin
end;
{ Valid point! }
If (Not BadPoint) Then
Begin
SetLength(Objs, Length(Objs) + 1);
Objs[High(Objs)] := TPA[I];
{ Avoid it Next time}
End Else Begin
TMP := High(NotBoxes);
SetLength(NotBoxes, TMP + 1);
CopyBox( Boxes[I], NotBoxes[TMP]);
End;
End;
Result := (Length(Objs) > 0);
End;
SCAR Code:
Boxes, NotBoxes: TBoxArray;
{Bad Boxes}
if not BadPoint then
if Length(NotBoxes) > 0 then
begin
TMP := High(NotBoxes);
for II := 0 to TMP do
if PointInBox(TPA[i], NotBoxes[II])) then
begin
MSI_Debug('MSI_FindObjectsTPA', 'Point in bad Box', DEBUG_SMALL_DETAILS);
BadPoint := True;
break;
end;
end;
{ Text Checking }
if not BadPoint then
if CheckText then
begin
end;
{ Valid point! }
If (Not BadPoint) Then
Begin
SetLength(Objs, Length(Objs) + 1);
Objs[High(Objs)] := TPA[I];
{ Avoid it Next time}
End Else Begin
TMP := High(NotBoxes);
SetLength(NotBoxes, TMP + 1);
CopyBox( Boxes[I], NotBoxes[TMP]);
End;