Originally Posted by
KilKof
Here is what i managed to make now:
Code:
procedure Attack();
var
TPA: TPointArray;
ATPA: T2DPointArray;
foundPnt: TPoint;
CTS: integer;
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
setcolorspeed2modifiers(0.28, 1.43);
FindColorsSpiralTolerance(272, 191, TPA, 10791822, 1, 1, 518, 338, 15);
ColorToleranceSpeed(CTS);
ATPA := FloodFillTPA(TPA);
SortATPASize(ATPA, false);
foundPnt := MiddleTPA(ATPA[0]);
begin
HumanMMouse(FoundPnt, 0, 0);
if waitUptext('Whirlpool', 250) then
begin
fastclick(mouse_left);
wait(4000);
end;
end;
end;
I know it's tempting, especially when you just want to do something quick, but don't try and put everything into one function/procedure. It feels like it's not worth the time because you just need something basic but you'll pour more time into it overall this way than if you take 10 mins to separate everything out.
Using the AeroLib functions were fine and didn't cause any of your problems. Those functions use findColorsTolerance as well, it's just in a neat wrapper that handles the CTS setting and resetting for you. Also gives a more object oriented feel when you can use TColEx, as using findColorsTolerance yourself with a bunch of meaningless numbers isn't any help a week from now when you look at the script again.
When you split everything out it allows you to try different aproaches a lot easier. Have a single function that just finds the whirlpools, now you can use this in other functions where you try and work out which pool is which.
I went ahead and done a few functions on how I'd go about finding the pools. I used your image as my 'game screen' so you'll need to open the image and target it. If you want to use any of them in-game then you'll need to first decide how you want your camera to be, then adjust the functions where needed as these are based on the view from your image.
Open the image in something that doesn't distort the real colors. Chrome or Paint work fine. Windows image preview doesn't.
Simba Code:
program whirlpoolExtravaganza;
{$i AeroLib/AeroLib.Simba}
function getClientBox: TBox;
var
cW, cH: Integer;
begin
GetClientDimensions(cW, cH);
Result := ToBox(0,0,cW-1,cH-1);
end;
function findWhirlpools(Size: Integer = 5): T2DPointArray; //Optional size param, default is 5
var //we use this later but can be avoided
colWhirlpool: TColEx;
poolPoints: TPointArray;
begin
colWhirlpool.create(14143913,12,0.05,1.08);
colWhirlpool.findAllIn(getClientBox, poolPoints);
Result := ClusterTPA(poolPoints, Size);
debugATPA(Result, '');
end;
procedure debugPoolSizes;
var
allPools: T2DPointArray;
i: Integer;
begin
allPools := findWhirlpools;
for i := 0 to High(allPools) do
begin
accurateMMouse(MiddleTPA(allPools[i]),0,0);
Writeln(i,': ',Length(allPools[i])); //Will let us know how many points are in the TPA
Wait(1500);
end;
end;
function findSmallPools(Size: Integer = 700): T2DPointArray;
var
allPools, smallPools: T2DPointArray;
i: Integer;
begin
allPools := findWhirlpools;
if Length(allPools) < 1 then //We make sure our ATPA has results in it to avoid access violation
Exit;
for i := 0 to High(allPools) do
if Length(allPools[i]) < Size then //We're only saving the TPAs whose size is below Size param
smallPools := smallPools + allPools[i];
Result := smallPools;
debugATPA(Result, '');
end;
function findLargePool: TPointArray;
var
allPools: T2DPointArray;
begin
allPools := findWhirlpools(30); //We change the default Size param here
//due to the player being in the way in the screenie
//a better camera angle and height would avoid this need
if Length(allPools) < 1 then //We make sure our ATPA has results in it to avoid access violation
Exit;
SortATPASize(allPools, True);
Result := allPools[0]; //Largest TPA is now the first element, so [0]
debugTPA(Result, '');
end;
function findCornerPools: TPointArray;
var
allPools: T2DPointArray;
midPoints: TPointArray;
i: Integer;
begin
allPools := findWhirlpools;
if Length(allPools) < 1 then //We make sure our ATPA has results in it to avoid access violation
Exit;
for i := 0 to High(allPools) do
midPoints := midPoints + MiddleTPA(allPools[i]); //Get a single point for each TPA (Pool)
SetLength(Result, 4);
SortTPAByX(midPoints, True); //Arrange the points by their X positions such that
//points closer to the left are first
//so the first 2 elements will be the 2 small pools on the left
//We could just assign the first two values and the last 2 values
//as those are the small pools, but it'd be nice if we can order
//the pools in the order that you'll attack them as a human would
//In the pic it'd be: top left, bottom left, top right, bottom right.
//You'll need to mess with this function if the camera will be
//from what the pic is at.
case midPoints[0].Y < midPoints[1].Y of //this case statement will sort the left 2 pools so that the
True: //top left pool is first in our returned array
Begin
Result[0] := midPoints[0];
Result[1] := midPoints[1];
end;
False:
Begin
Result[1] := midPoints[0];
Result[0] := midPoints[1];
end;
end;
SortTPAByX(midPoints, False); //same again but we flipped true -> false so the right most
//pools are now first and second in the array
case midPoints[0].Y < midPoints[1].Y of
True:
Begin
Result[2] := midPoints[0];
Result[3] := midPoints[1];
end;
False:
Begin
Result[3] := midPoints[0];
Result[2] := midPoints[1];
end;
end;
debugTPA(Result, '');
for i := 0 to High(Result) do
begin
accurateMMouse(Result[i],0,0);
Wait(1000);
end;
end;
begin
InitAL;
//Try the following one at a time.
findWhirlpools;
//debugPoolSizes;
//findSmallPools;
//findLargePool;
//findCornerPools;
end.