SRL Archive - Senior Scripts and Snippets

Theoretical Webwalker (99% done)


pwnaz0r

2008-10-10 03:59:17


function LoadWebWalker: Boolean;
begin
try
WebWalkerpath := [Point(3222, 3217), Point(3236, 3209), Point(3236, 3200),
Point(3236, 3209), Point(3236, 3223), Point(3252, 3224),
Point(3260, 3235), Point(3267, 3226), Point(3255, 3248),
Point(3251, 3261), Point(3244, 3275), Point(3240, 3289),
Point(3239, 3304), Point(3250, 3315), Point(3262, 3323),
Point(3269, 3330), Point(3254, 3332), Point(3239, 3335),
Point(3226, 3343), Point(3220, 3358), Point(3212, 3372),
Point(3212, 3387), Point(3212, 3400), Point(3211, 3414),
Point(3213, 3428), Point(3197, 3428), Point(3181, 3428),
Point(3167, 3425), Point(3154, 3416), Point(3138, 3416),
Point(3122, 3414), Point(3108, 3420), Point(3098, 3419),
Point(3085, 3420), Point(3071, 3417), Point(3057, 3412),
Point(3042, 3416), Point(3032, 3426), Point(3017, 3426),
Point(3017, 3427), Point(3002, 3430), Point(2988, 3425),
Point(2980, 3415), Point(2967, 3411), Point(2966, 3395),
Point(2965, 3379), Point(2980, 3377), Point(2952, 3380),
Point(2946, 3368), Point(2989, 3370), Point(3001, 3362),
Point(3012, 3362), Point(3013, 3355), Point(3007, 3345),
Point(3006, 3331), Point(3007, 3316), Point(3005, 3301),
Point(3004, 3286), Point(3014, 3275), Point(3030, 3276),
Point(3001, 3277), Point(2987, 3276), Point(2976, 3270),
Point(2969, 3256), Point(2958, 3245), Point(2956, 3230),
Point(2956, 3217), Point(2956, 3208), Point(2972, 3280),
Point(2958, 3286), Point(2949, 3298), Point(2936, 3300),
Point(2933, 3288), Point(3020, 3260), Point(3029, 3269),
Point(3019, 3246), Point(3041, 3274), Point(3055, 3275),
Point(3068, 3276), Point(3076, 3287), Point(3092, 3289),
Point(3106, 3293), Point(3106, 3277), Point(3118, 3295),
Point(3112, 3305), Point(3104, 3265), Point(3104, 3252),
Point(3093, 3241), Point(3105, 3233), Point(3113, 3221),
Point(3115, 3208), Point(3114, 3196), Point(3114, 3180),
Point(3111, 3167), Point(3126, 3221), Point(3140, 3226),
Point(3154, 3232), Point(3167, 3236), Point(3180, 3245),
Point(3195, 3249), Point(3211, 3245), Point(3222, 3236),
Point(3232, 3229), Point(3220, 3246), Point(3217, 3258),
Point(3230, 3260), Point(3244, 3261), Point(3216, 3271),
Point(3204, 3277), Point(3190, 3281), Point(3176, 3285),
Point(3162, 3286), Point(3149, 3294), Point(3138, 3294),
Point(3128, 3295), Point(3280, 3330), Point(3280, 3319),
Point(3277, 3305), Point(3275, 3291), Point(3275, 3276),
Point(3276, 3260), Point(3278, 3247), Point(3278, 3232),
Point(3277, 3216), Point(3275, 3203), Point(3282, 3190),
Point(3279, 3175), Point(3270, 3164)]; result:= true; WebwalkerLoaded:= true;
except
result:= false;
end;
end;

function ClosestPointOnPath(Point: TPoint): TPoint;
begin
if not WebWalkerLoaded then LoadwebWalker;
SortTPAFrom(WebWalkerPath, Point);
result:= WebWalkerPath[0];
end;

function FindGreatestDistIn(var TP1, TP2: TPoint; TPA: TPointArray; StartPoint: TPoint ): boolean;// will return true when finished
var
I, L, M: integer;
Dist: integer;
begin
M:= Distance(3171, 3150, 3166, 3164);
SortTPAFrom(TPA, StartPoint);
for I:= 1 to high(TPA) do
begin
L:= Distance(TPA[(I-1)].X, TPA[(I-1)].Y, TPA[I].X, TPA[I].Y);
if (Dist < L)then
begin
TP1:= TPA[(I-1)];
TP2:= TPA[I];
Dist:= L;
end;
end;
if (Dist <= M)then
result:= true;
end;

procedure RemoveTPA(Var TPA: TpointArray; ThePoint: TPoint);
var
i: integer;
begin
if PointInTPA(ThePoint, TPA)then
begin
for i:= 0 to high(TPA) do
if (TPA[I].X= ThePoint.X) and (TPA[I].Y = ThePoint.Y)then
begin
tSwap(TPA[i], TPa[(high(TPA))]);
SetArrayLength(TPA, GetArrayLength(TPA)-1);
end;
end;
end;

procedure AddPointToWW(var TPA: array of TPoint; ThePoint: TPoint);
begin
SetLength(Points, GetArrayLength(Points)+1);
Points[(High(Points))]:= ThePoint;
RemoveTPA(PossiblePoints, ThePoint);
end ;


function BuildPath(SPoint, EPoint: TPoint): boolean;
var
CtrlP: Array [0..1] of TPoint;
Mdp, P1, P2, Mdpt: TPoint;
MyDis: integer;
begin
CtrlP:=[ SPoint, EPoint ];
Mdp:= MiddleTPA(CtrlP);
MyDis:= Round(max(Distance(mdp.X, mdp.Y, Ctrlp[0].x, Ctrlp[0].Y), Distance(mdp.X, mdp.Y, Ctrlp[1].x, Ctrlp[1].Y)));
PossiblePoints:= RemoveDistTPointArray(mdp.x, mdp.y, MyDis, webWalkerPath, true);
repeat
result:= FindGreatestDistIn(P1, P2, PossiblePoints, Mdp);
if (result = true) then break;
Mdpt := MiddleTPA([P1, P2]);
AddPointToWW(Points, ClosestPointOnPath(Mdpt));
until(false);
SortTPAFrom(Points, SPoint);
end;

procedure WriteAllPoints(TPA: TpointArray);
var
I: integer;
begin
if (GetArraylength(TPA) <= 0) then
Writeln('No Points in TPA');
for I:= 0 to High(Points) do
Writeln('Point['+IntToStr(I)+'] --> ('+IntToStr(Points[I].X)+', '+IntToStr(Points[I].Y)+');');
end;

hey Worked on this a bit tonight. Should work. Only thing left is using a windpath type algorithm to do points under 30 distance, AKA going from start to on path and on path to endpoint.

I will have to make walkign specific functions for this, aka no UIDs at tiles, else find another tile within 3 x 3 square or something.

How it works –> basically, i went with sumillion's walker helper and made points within range of each other on the path all around free world. Then I narrowed down the points that could be in the path by taking the midpoint of the start and end, took the larger distance from mdpt. start and mdpt. end, and removed all that were further away. Then I started at midpoint, worked my way out using find furthest Point in TPA (my own function, would be great if someone could throw these math functions into a plugin), and as I went down finding the midpoints between the largest distance and adding the closest point to the midpoint, I believe it will end up with the path. The end is just sorting from start, which I might need to make a specific function but i think that will work unless there is just a huge curve in the path, (AKharid. not going through gate). So yeah that problem needs to be fixed. Any comments?

Wizzup?

2008-10-10 07:07:30

FindGreatestDistIn:
Couldn't you just make a distance array, once, then get the maximum value out of that array (along with the index)? Would save you a lot of time.

Also, could you not use FilterPointsPie (and SortCircleWise) for this?
EDIT: I now see what you are doing… I think I made that while ago…
program New;

Var
Points: TPointArray;

Procedure LoadPoints;
Begin
Points := [Point(2,2), Point(10, 10), Point(25, 5), Point(30, 20), Point(30, 30)];
End;

Function ReturnPath(sP, eP: TPoint; maxDist: Integer; Const Points: TPointArray): TPointArray;

Var
CurPoint: TPoint;
A: Double;
I, C: Integer;

Begin
SetLength(Result, 0);
C := 0;
CurPoint := sP;
While Distance(CurPoint.X, CurPoint.Y, eP.X, eP.Y) > maxDist Do
Begin
A := ArcTan2(eP.Y - CurPoint.Y, eP.X - CurPoint.X);
SortTPAFrom(Points, Point(CurPoint.X + Round(maxDist * cos(A)), CurPoint.X + Round(maxDist * sin(A))));
For I := Low(Points) To High(Points) Do
Begin
If Distance(CurPoint.X, CurPoint.Y, Points[I].X, Points[I].Y) < maxDist Then
Begin
If ((Points[I].X = CurPoint.X) And (Points[I].Y = CurPoint.Y)) Then
Begin
WriteLn('Stuck.');
SetLength(Result, 0);
Exit;
End;
SetLength(Result, C + 1);
Result[C] := Points[I];
CurPoint := Points[I];
C := C + 1;
Break;
End;
End;
End;
SetLength(Result, C + 1);
Result[C] := eP;
End;

Var
Path: TPointArray;
I: Integer;

begin
LoadPoints;
Path := ReturnPath(Point(0, 0), Point(35, 35), 25, Points);
For I := Low(Path) To High(Path) Do
WriteLn('Path[' + inttostr(i) + ']: (' + inttoStr(Path[i].X) + ', ' + inttostr(Path[i].Y) + ')');
end.

It's a bit shorter… I am not sure if it was perfect though, or how it performs on RuneScape tiles. I quickly wrote it for a small game. Never tested it thoroughly…
EDIT2: I can see it error at some paths, but I think it should overall work nicely.

EDIT3: If you use Dijkstra's Shortest Path Algo, you will be able to make a good Web Walker. There are a lot of Open Source distributions of the Algorithm.

pwnaz0r

2008-10-10 13:08:56

Ok, well not being back for awhile, I just wanted to get the concept in there. If it has any chance of getting into reflection.scar, I will make it, however, if not, I won't bother.

Smartzkid

2008-10-10 15:23:05

http://www.villavu.com/forum/showthread.php?t=34377

Works beautifully :)

I had it running in SCAR a while back, but it had some stability issues. If you like, I could try to dig up the code

mastaraymond

2008-10-10 16:00:12

Currently working on something, should do the path trick..

the scar noob

2008-10-11 09:22:24

From: mastaraymond
Currently working on something, should do the path trick..


Ray's always there to help us:p

-Tsn.

n3ss3s

2008-10-11 10:42:59

Get Ben to make a SmartGetFieldArray2D<typehere> and we can make a real one, that for example would go around a mountain instead of trying to go straight across it which would be theoretically right :)


Good job though, must've been a pain writing all those points…



isTileWalkable = ((getGroundDataArray()[getPlane()].getBlocks()[TileX - BaseX][TileY - BaseY] & 1280102) = 0)

For that we need the 2Ds…

mastaraymond

2008-10-11 12:34:51

http://www.villavu.com/forum/showthread.php?t=36548?p=479354

Currently working on a mix between Path & Graph maker. In the end, it should always get the fastest route to anywhere in the rs world :).