SRL Archive - SRL Archives

LinearWalkEx


Shuttleu

2009-01-28 11:10:49

RWEx
and i found the same problem in LinearWalkEx
LinearWalkEx:

{*******************************************************************************
function LinearWalkEx(var tpa: TPointArray; cx, cy, TheColor, tol: Integer; Direction: Integer; Radius: Integer): Boolean;
By: Nielsie95
Description: Finds TheColor from Radial (scanning outwards) for Radius Distance.
Valid Arguments:
tpa: Result points.
Direction: Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
*******************************************************************************}

function LinearWalkEx(var tpa: TPointArray; cx, cy, TheColor, tol: Integer; Direction: Integer; Radius: Integer): Boolean;
var
i, SD, ED: Integer;
begin
Result := False;
if (not LoggedIn) then Exit;
if Radius > 70 then Radius := 70;
i := GetSystemTime;
Direction := Direction mod 360;
if (Direction < 50) then
SD := ((Direction + 360) - 50)
else
SD := (Direction - 50);
ED := (Direction + 50);
while (SD > 360) do
SD := SD - 360;
while (ED > 360) do
ED := ED - 360;
try
FindColorsTolerance(tpa, TheColor, MMX1, MMY1, MMX2, MMY2, tol);
FilterPointsPie(tpa, SD, ED, 10, Radius, cx, cy);
LinearSort(tpa, cx, cy, Direction, False);
Result := (Length(tpa) > 0);
except srl_Warn('LinearWalkEx', 'LWex error!', warn_AllVersions); Exit; end;
// Uncomment this for debug
// WriteLn('LWex time: '+IntToStr(GetSystemTime - i)+'ms. Found points: '+IntToStr(Length(tpa)));
end;
RadialWalkEx:

{*******************************************************************************
function RadialWalkEx(var tpa: TPointArray; cx, cy, TheColor, tol: Integer; StartRadial, EndRadial: Integer; Radius: Integer): Boolean;
By: Nielsie95
Description: Finds TheColor from StartRadial to EndRadial for Radius Distance.
Valid Arguments:
tpa: Result points.
StartRadial/EndRadial: Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
*******************************************************************************}

function RadialWalkEx(var tpa: TPointArray; cx, cy, TheColor, tol: Integer; StartRadial, EndRadial: Integer; Radius: Integer): Boolean;
var
i, SD, ED: Integer;
begin
Result := False;
SD := StartRadial;
ED := EndRadial;
if Radius > 70 then Radius := 70;
if (SD = ED) then
begin
WriteLn('Using LinearWalkEx, equal values.');
Result := LinearWalkEx(tpa, cx, cy, TheColor, tol, StartRadial, Radius);
end;
if (SD > ED) then
Swap(SD, ED);
while (SD > 360) do
SD := SD - 360;
while (ED > 360) do
ED := ED - 360;
if (not LoggedIn) then Exit;
i := GetSystemTime;
try
FindColorsTolerance(tpa, TheColor, MMX1, MMY1, MMX2, MMY2, tol);
FilterPointsPie(tpa, SD, ED, 10, Radius, cx, cy);
SortCircleWise(tpa, cx, cy, StartRadial, False, StartRadial > EndRadial);
Result := (Length(tpa) > 0);
except srl_Warn('RadialWalkEx', 'An exception has occured', warn_AllVersions); Exit; end;
// Uncomment this for debug
// WriteLn('RWex time: '+IntToStr(GetSystemTime - i)+'ms. Found points: '+IntToStr(Length(tpa)));
end;
so if someone tries to make the radius too large or types in the radius wrong then it wont end up messing up the script
therefore it will change the radius so it wont be too large and mess up the script

~shut

Sir R. M8gic1an

2009-01-28 11:49:37

Nice find;

RWEx only calls LinerWalkEx if SD = ED;

so it will still mess up in RWEx


try
FindColorsTolerance(tpa, TheColor, MMX1, MMY1, MMX2, MMY2, tol);
FilterPointsPie(tpa, SD, ED, 10, Radius, cx, cy);
SortCircleWise(tpa, cx, cy, StartRadial, False, StartRadial > EndRadial);
Result := (Length(tpa) > 0);
except srl_Warn('RadialWalkEx', 'An exception has occured', warn_AllVersions); Exit; end;

and all the scripter wil know is that there was an exception.

maybe we would add
if Radius > 70 then Radius := 70

as it would be pointless to have it any bigger than that?

~RM

Shuttleu

2009-01-28 15:13:49

huh i hadnt noticed that out :p
i have updated the main post with the latest bits

~shut

ZephyrsFury

2009-01-28 23:40:05

RadialWalkEx and LinearWalkEx don't necessarily need to be used on the minimap (hence you must specify the centre of the circle you're searching in (cx, cy)).