SRL Archive - Help and Support

How does radial walk work


m34tcode

2012-05-10 03:32:41

I have a 20 degree limit in radial walk. This is the code, just to test what numbers are best for walking this path:

  repeat
RadialWalkTolerance(2702656,-10,10,70,0,-1,20);
RadialWalkTolerance(3689302,-10,10,70,0,-1,20);
until false;
\

and this is what the code does: http://m34tcode.x10.mx/snaps/2012-05-10_0318.swf

It walks south east at one point… how does that happen?

Line 720 of mapwalk.simba is this:
FilterPointsPie(tpa, SD, ED, 10, Radius, cx, cy);

doesn't that remove all points not between the radials? or does it just sort the points. I wonder because the script was clicking nowhere near between the radials

bg5

2012-05-10 05:03:33

It finds color of tolerance on MM between two angles(StartRadial ,EndRadial)

,so it should walk north ,I have no idea.

doesn't that remove all points not between the radials

No ,it returns all points from tpa in neighberhood (radius)of point.

masterBB

2012-05-10 06:03:47

I argued about it before. But they don't want to chance it.

step1:
sd = -10 to ed = 10

step2: (fixD)
sd = 350 to ed = 10

step3: (swap)
sd = 10 to ed = 350

I hate it, I hate it, I hate it. It's not logical but this is how it works. RadialWalk is broken for some time, don't use it or work around it.

edit:
I will just start the discussion again. Let me steal your thread ;) .

First I will show you the code I plead responsible for this mis behavior:
suspect 1: RadialWalkEx:
function RadialWalkEx(var TPA: TPointArray; cx, cy, TheColor, tol: Integer; StartRadial, EndRadial: Variant; Radius: Integer): Boolean;
var
time: Integer;
SD, ED: extended;
begin
Result := False;
if (not LoggedIn) then Exit;

SD := variantToDirection(StartRadial);
ED := variantToDirection(EndRadial);
if (SD = ED) then
begin
srl_Warn('RadialWalkEx', 'StartRadial = EndRadial, using LinearWalkEx.', warn_Warning);
Result := LinearWalkEx(tpa, cx, cy, TheColor, tol, StartRadial, Radius);
end;
if (SD > ED) then
Swap(SD, ED);

time := 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;
srl_Warn('RadialWalkEx', 'Took ' + IntToStr(GetSystemTime - time) +
' ms, found' + IntToStr(Length(TPA)) + ' points', warn_Debug);
end;

lines that I hate:
  SD := variantToDirection(StartRadial);
ED := variantToDirection(EndRadial);

...

if (SD > ED) then
Swap(SD, ED);

suspect 2: variantToDirection Srl/Srl/core/mapwalk.simba:
function variantToDirection(dir: Variant): Extended;
var
e: Extended;
begin
case (VarType(dir)) of
varInteger, varDouble: Result := FixD(dir + 0.0);
varString:
begin
case LowerCase(dir) of
'n': Result := 0;
'e': Result := 90;
's': Result := 180;
'w': Result := 270;
'random', 'rand': Result := RandomRange(0, 360);
else
begin
e := StrToFloatDef(dir, -1337);
if (e <> -1337) then
Result := FixD(e)
else
begin
srl_Warn('variantToDirection',
'dir [' + toStr(dir) +'] invalid. Returned 0.0 for safety',
warn_AllVersions);
Result := 0.0;
end;
end;
end;
end;
end;
end;

Notice the following:

 Result := FixD(e)

Evidence that FixD(e) changes the angle to unwanted vallues:
function ps_FixD(Degrees : extended) : Extended; extdecl;
begin;
Result := Degrees;
while Result < 0 do
Result := Result + 360;
while Result > 360 do
Result := Result - 360;
end;

It is impossible to walk to the north with 10 degrees tolerance.

Frement

2012-05-10 06:59:33

FixD doesn't really do anything, unless you pass 720 or similar values to the function. And variantToDirection only converts it to float.

masterBB

2012-05-10 07:02:36

From: Frement
FixD doesn't really do anything, unless you pass 720 or similar values to the function. And variantToDirection only converts it to float.


Read it again. Fixd will make -10 degrees 350 degrees. And VariantToDirection calls this. Then swap will swap the angles. And boom you got a shitty function that doesn't function. And if there is on sort of function I don't like it is a non-functional function.

Markus

2012-05-10 07:48:51

From: masterBB
I argued about it before. But they don't want to chance it.


Link please. I'll fix this right away.

masterBB

2012-05-10 07:59:33

From: Markus
Link please. I'll fix this right away.


I've discussed this with daniel on IRC, he agrees that the swap needs to be removed as wall as the fixD, but, there is a but, I also know there is a second problem with FilterPointsPie. The thread were I and nielsie, richard and wizzup discuss that is here: http://villavu.com/forum/showthread.php?t=75712

In short:
srl/core/mapwalk.simba -> RadialWalkEx
function RadialWalkEx(var TPA: TPointArray; cx, cy, TheColor, tol: Integer; StartRadial, EndRadial: Variant; Radius: Integer): Boolean;
var
time: Integer;
SD, ED: extended;
begin
Result := False;
if (not LoggedIn) then Exit;

SD := variantToDirection(StartRadial);
ED := variantToDirection(EndRadial);
if (SD = ED) then
begin
srl_Warn('RadialWalkEx', 'StartRadial = EndRadial, using LinearWalkEx.', warn_Warning);
Result := LinearWalkEx(tpa, cx, cy, TheColor, tol, StartRadial, Radius);
end;
{*if (SD > ED) then
Swap(SD, ED); *} //removed these lines since it isn't needed and wasn't there before.

time := 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;
srl_Warn('RadialWalkEx', 'Took ' + IntToStr(GetSystemTime - time) +
' ms, found' + IntToStr(Length(TPA)) + ' points', warn_Debug);
end;

srl/core/mapwalk.simba -> variantToDirection
function variantToDirection(dir: Variant): Extended;
var
e: Extended;
begin
case (VarType(dir)) of
varInteger, varDouble: Result := FixD(dir + 0.0);
varString:
begin
case LowerCase(dir) of
'n': Result := 0;
'e': Result := 90;
's': Result := 180;
'w': Result := 270;
'random', 'rand': Result := RandomRange(0, 360);
else
begin
e := StrToFloatDef(dir, -1337);
if (e <> -1337) then
//Result := FixD(e) removed the FixD since all TPA functions already do this themselves.
Result := e
else
begin
srl_Warn('variantToDirection',
'dir [' + toStr(dir) +'] invalid. Returned 0.0 for safety',
warn_AllVersions);
Result := 0.0;
end;
end;
end;
end;
end;
end;

simba/units/mmlcore/tpa.pas -> FilterPointsPie (with richard his code: http://villavu.com/forum/showthread.php?p=936667#post936667)

procedure FilterPointsPie(var Points: TPointArray; const SD, ED, MinR, MaxR: Extended; Mx, My: Integer);
const
i180Pi = 57.29577951;
var
G: TPointArray;
I, L, T: Integer;
D, StartD, EndD: Extended;
cWise: Boolean;
begin
T := High(Points);
if (T < 0) then Exit;
SetLength(G, T + 1);
L := 0;
StartD := SD;
EndD := ED;
StartD := (Floor(StartD) mod 360.0) + (StartD - Floor(StartD));
StartD := StartD + (Ord(StartD < 0.0) * 360);
EndD := (Floor(EndD) mod 360.0) + (EndD - Floor(EndD));
EndD := EndD + (Ord(EndD < 0.0) * 360);
cWise := StartD > EndD;
if cWise then
SwapE(StartD, EndD);
for I := 0 to T do
begin
D := sqrt(Sqr(Points[I].X - Mx) + Sqr(Points[I].Y - My));
if( D <= MinR) or (D >= MaxR) then
Continue;
D := (ArcTan2(Points[I].Y - My, Points[I].X - Mx) * i180Pi) + 90;
if D < 0.0 then
D := D + 360.0;
if (not ((StartD <= D) and (EndD >= D))) xor CWise then
Continue;
G[L] := Points[I];
Inc(L);
end;
SetLength(G, L);
Points := G;
end;

bg5

2012-05-11 01:00:22

I'm not sure if I agree with variantToDirection ,FixD(e) look harmless in this issue ,but you have 100% right with
  if (SD > ED) then
Swap(SD, ED);
it doesn't handle situation ,when "12 o'clock" is inside searched are.

I don't know ,if swap inside FilterPointsPie is bugged too ,but I'm gonna try.
FilterPointsPie test:
program new;
{$I SRL/srl.simba}
{$I srl/srl/misc/debug.simba}

procedure FPP_test(const SD, ED, MinR, MaxR: Extended);
var
a ,bmp,w,h,radius :integer;
tpa,temp :TPointarray;
M : TPoint;
begin
w := 300;
h := 300;

M := Point (w/2,h/2);
radius := (min(w,h))/2-10;
bmp := CreateBitmap(w,h);
SetTargetBitmap(bmp);
for a:= 0 to radius do
begin
temp := TPAFromCircle(m.x,m.y,a);
tpa := combineTPA(tpa,temp);
end;
DrawTPABitmap(bmp,tpa,clWhite);
FilterPointsPie(tpa,SD, ED, MinR, MaxR,m.x,m.y);
DrawTPABitmap(bmp,tpa,clred);
Debugbitmap(bmp);
end;

begin
FPP_test(330,30,1,60);
//FPP_test(-30,30,1,60);
end.

params : FPP_test(330,30,1,60);

params :FPP_test(-30,30,1,60);

So it needs FixD to work correnctly

Markus

2012-05-11 06:06:36

So removing swap would do the trick?

masterBB

2012-05-11 06:25:35

I agree that with fix'd it will work, but, it shouldn't be needed. Everything fixD does is already done in filterpointspie.

Place this simba.exe in your simba folder and run it. You will see that this one does work with -30,30 and 330,30:
http://www.ancientbb.com/srl/Simba2.exe

So, only remove the swap for a short term solution. Replacing FilterPointsPie and removing fixD can be done some other time.

Joe

2012-05-11 07:35:48

I have never used Radialwalk before- I thought it was just for SCAR. Thanks for this! Rep+

bg5

2012-05-11 07:44:53

http://www.ancientbb.com/srl/Simba2.exe


What Simba version is that? 35 Mb:eek:

Markus

2012-05-11 07:58:45

^ One without stripped debugging symbols I'd say.

edit: masterbb you gotta post them sauces/patches :)

Wizzup?

2012-05-11 08:36:27

From: Markus
^ One without stripped debugging symbols I'd say.

edit: masterbb you gotta post them sauces/patches :)


http://l0.lt/builders/master/builds/166
https://github.com/MerlijnWajer/Simba/commit/56a74cf624463ad4278308103552609cfff755a1

masterBB

2012-05-11 08:39:08

Fixed! :P The FilterPointsPie part, I've not messed with srl.

From: Markus
^ One without stripped debugging symbols I'd say.

edit: masterbb you gotta post them sauces/patches :)


I indeed posted the debug version ;). I finally committed it to simba ;), well wizzup did but I tried.