n3ss3s
01-23-2008, 02:51 PM
FindDucks - a general duckfinder
This function doesn't work, but does compile, and would be /is really slow.
I posted it so people could learn :)
Function FindDuck(Var Dx, Dy: Integer; Safe: Boolean): Boolean;
Var
CTS, I, L, X, Y, z, II, S, Ll: Integer;
TPAA, ATPA : Array of TPointArray;
TPA, dTPA: TPointArray;
TP: TPoint;
TB: TBox;
Begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 11241076, MSX1, MSY1, MSX2, MSY2, 0);
TPAA := SplitTPAEx(TPA, 1, 1);
SortATPASize(TPAA, True);
If GetArrayLength(TPA) < 1 Then
Exit;
SetArrayLength(TPA, 0);
TPA := TPAA[0];
ATPA := TPAToATPAEx(TPA, 40, 40);
Ll := High(ATPA);
For S := 0 To L Do
Begin
TPA := ATPA[s];
TPAA := FindGapsTPA(TPA, 18);
L := High(TPAA);
For I := 0 To L Do
TPA := CombineTPA(TPA, TPAA[i]);
TB := GetTPABounds(TPA);
TP.x := TB.x2 - TB.x1 shr 1;
TP.y := TB.y2 - TB.y1 shr 1;
SetColorSpeed2Modifiers(0.4, 0.4);
FindColorsSpiralTolerance(TP.x, TP.y, dTPA, 8822696, TB.x1, TB.y1, TB.x2, TB.y2, 15);
SetColorSpeed2Modifiers(0.2, 0.2);
SetArrayLength(TPAA, 0);
TPAA := TPAToATPAEx(dTPA, 15, 15);
L := High(TPAA);
For I := 0 To L Do
Begin
TB := GetTPABounds(TPAA[i]);
TP.x := TB.x2 - TB.x1 shr 1;
TP.y := TB.y2 - TB.y1 shr 1;
SortTPAFrom(dTPA, TP);
SetArrayLength(TPA, 64);
For II := 0 To 63 Do
Try
TPA[ii] := dTPA[i];
z := z + 1;
Except
Break;
End;
SetArrayLength(TPA, z);
If Z > 24 Then
Begin
MiddleTPAEx(TPA, Dx, Dy);
If FindColorTolerance(X, Y, 3229752, Dx - 12, Dy - 12, Dx + 12, Dy + 12, 20) Then
Result := True // Male duck, and also a definite duck.
Else
If Safe Then
Begin
MMouse(Dx, Dy, 2, 2);
If Not IsUpTextMulti('Duck', 'Duc', 'uck') Then
Continue;
End;
Result := Not(FindColor(X, Y, 65280, Dx - 15, Dy - 20, Dx + 15, Dy + 10));
If Result Then
Result := Not(FindColor(X, Y, 255, Dx - 15, Dy - 20, Dx + 15, Dy + 10));
If Result Then
Break;
End;
End;
End;
ColorToleranceSpeed(CTS);
End;
This function doesn't work, but does compile, and would be /is really slow.
I posted it so people could learn :)
Function FindDuck(Var Dx, Dy: Integer; Safe: Boolean): Boolean;
Var
CTS, I, L, X, Y, z, II, S, Ll: Integer;
TPAA, ATPA : Array of TPointArray;
TPA, dTPA: TPointArray;
TP: TPoint;
TB: TBox;
Begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 11241076, MSX1, MSY1, MSX2, MSY2, 0);
TPAA := SplitTPAEx(TPA, 1, 1);
SortATPASize(TPAA, True);
If GetArrayLength(TPA) < 1 Then
Exit;
SetArrayLength(TPA, 0);
TPA := TPAA[0];
ATPA := TPAToATPAEx(TPA, 40, 40);
Ll := High(ATPA);
For S := 0 To L Do
Begin
TPA := ATPA[s];
TPAA := FindGapsTPA(TPA, 18);
L := High(TPAA);
For I := 0 To L Do
TPA := CombineTPA(TPA, TPAA[i]);
TB := GetTPABounds(TPA);
TP.x := TB.x2 - TB.x1 shr 1;
TP.y := TB.y2 - TB.y1 shr 1;
SetColorSpeed2Modifiers(0.4, 0.4);
FindColorsSpiralTolerance(TP.x, TP.y, dTPA, 8822696, TB.x1, TB.y1, TB.x2, TB.y2, 15);
SetColorSpeed2Modifiers(0.2, 0.2);
SetArrayLength(TPAA, 0);
TPAA := TPAToATPAEx(dTPA, 15, 15);
L := High(TPAA);
For I := 0 To L Do
Begin
TB := GetTPABounds(TPAA[i]);
TP.x := TB.x2 - TB.x1 shr 1;
TP.y := TB.y2 - TB.y1 shr 1;
SortTPAFrom(dTPA, TP);
SetArrayLength(TPA, 64);
For II := 0 To 63 Do
Try
TPA[ii] := dTPA[i];
z := z + 1;
Except
Break;
End;
SetArrayLength(TPA, z);
If Z > 24 Then
Begin
MiddleTPAEx(TPA, Dx, Dy);
If FindColorTolerance(X, Y, 3229752, Dx - 12, Dy - 12, Dx + 12, Dy + 12, 20) Then
Result := True // Male duck, and also a definite duck.
Else
If Safe Then
Begin
MMouse(Dx, Dy, 2, 2);
If Not IsUpTextMulti('Duck', 'Duc', 'uck') Then
Continue;
End;
Result := Not(FindColor(X, Y, 65280, Dx - 15, Dy - 20, Dx + 15, Dy + 10));
If Result Then
Result := Not(FindColor(X, Y, 255, Dx - 15, Dy - 20, Dx + 15, Dy + 10));
If Result Then
Break;
End;
End;
End;
ColorToleranceSpeed(CTS);
End;