Iamadam
2011-03-29 22:43:59
Heya.
So, I'm sick of our current, laggy walk path function, so I made my own.
Comment, test, rant etc.
It should work much better, and use far less cpu.
So, I'm sick of our current, laggy walk path function, so I made my own.
{*******************************************************************************
function walkPathEx(path: TTileArray; acceptableDistance, clickRandomness, waitTime: Integer) : boolean;
By: Iamadam
Description: Walks a tile path with minimum lag.
Variables:
path : The path to walk (as an array of TTiles)
acceptableDistance : The minimum distance from the destination to return true
tileRandomness: The amount of randomness (in tiles) to add to minimap clicks
waitTime: the amount of time to wait after a click, before searching for the next tile.
*******************************************************************************}
function walkPathEx(path: TTileArray; acceptableDistance, tileRandomness, waitTime: Integer) : boolean;
var index, lastClick, lastClickTime: Integer;
clickPoint : TPoint;
clickTile : TTile;
begin
if(not loggedIn) then
begin
result:= false;
exit;
end;
lastClickTime := getSystemTime;
while (distanceFrom(path[high(path)]) > acceptableDistance) do
begin
for index := high(path) downto 0 do
begin
if(tileOnMM(path[index])) then
break;
end;
//click the point
if(lastClick <> index) then //make sure we havn't already clicked there...
begin
if((index = 0) and (not tileOnMM(path[0]))) then //none of the tiles are on the minimap, return false
begin
result := false;
exit;
end;
lastClick := index;
clickTile := randomizeTile(path[index], tileRandomness, tileRandomness);
while (not tileOnMM(clickTile)) do
clickTile := randomizeTile(path[index], tileRandomness, tileRandomness); //Make sure the random tile is on the mmap.
clickPoint := tileToMM(clickTile);
Mouse(clickPoint.x, clickPoint.y, 1, 1, true);
lastClickTime := GetSystemTime;
wait(waitTime + random(500) + random(random(500)));
end else
begin
if(GetSystemTime - lastClickTime > 1000 * 20) then //its been 20 seconds since the last click... walking has failed.
begin
writeln('Please check your path. The tile at index ' + toStr(index) + ' is too far from the next tile');
result := false;
exit;
end
else
wait(random(500) + random(random(500))); //so, we already clicked the best tile, now we wait a little bit.
end;
end;
if(not loggedIn) then
result := false
else
result := true;
end;
function walkPath(path: TTileArray) : boolean;
begin
result := walkPathEx(path, 5, 1, 1000);
end;
Comment, test, rant etc.
It should work much better, and use far less cpu.