boberman
2009-01-27 11:27:09
Well, I always feel that many walking functions are, frankly, pretty ugly looking. So I wrote this function which I believe should be pretty useful for someone.
How it should be called.
*edit* I guess I should add some credit as well :)
*edit2* added a check for if a radial walk instance fails. Should help keep the walking sane.
function RWArray(colors : array of function : integer; startAngles, endAngles, dists, tols : array of integer) : boolean;
var
tpa : TPointArray;
i, j, Xmod, Ymod : integer;
begin
Result := False;
if not (LoggedIn) then
exit;
// ensure that the data is sane. These arrays should all be the same size.
if (high(startAngles) <> high(dists)) then
exit;
MakeCompass('n');
for i := 0 to High(dists) do
begin
Xmod := Random(4) - 2;
Ymod := Random(4) - 2;
// The code below was copied from RadialWalk by Nielsie95
if RadialWalkEx(tpa, MMCX, MMCY, colors[i](), tols[i], startAngles[i], endAngles[i], dists[i]) then
begin
for j to High(tpa) do
if MFNF(tpa[j].x, tpa[j].y, Xmod, Ymod) then
begin
FFlag(10);
Result := True;
Break;
end;
end else
break; // Radial Walk failed somewhere
end;
end;How it should be called.
procedure WalkSomewhere;
startAngles, endAngles, distances, tolerances : array[0..5] of integer;
funcs : array[0..5] of function : integer;
begin
startAngles := [20, 30, 40, 50, 90, 38];
endAngles := [32, 40, 45, 55, 92, 40];
dists := [30, 50, 40, 60, 30, 25];
tolerances := [3, 5, 10, 8, 9, 6];
funcs := [@FindVarrockRoadColor, @FindRockColor, @FindStoneColor, @FindSandColor, SomeCustomColorFinder, SuperColorFinder];
if (RWArray(funcs, startAngles, endAngles, dists, tolerances)) then
begin
writeln('Win!');
end else
writeln('phail :(');
end;*edit* I guess I should add some credit as well :)
*edit2* added a check for if a radial walk instance fails. Should help keep the walking sane.