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=75712In 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;