SRL Archive - Snippets

[Snippets]Walking in the Abyss


Flight

2012-10-21 22:48:43

Heya, so I've stopped (for a while now) working on my Abyssal runecrafting script and I thought maybe someone else would find some of this handy. So here you are.

[SPS map of Abyss + Edgeville (Lodestone, bank, summoning obelisk, path to mage)]


The Abyss was made painfully piece by piece directly from the Minimap, while the Edgeville area was made via an SPS piece (Nebula's updated SPS maps), so it's fully up-to-date AFAIK.

[Inner-Ring SPS points (required)]

IRPoints := [Point(147,95), Point(119,95), Point(99,103), Point(87,119), Point(83,139),
Point(87,155), Point(91,171), Point(107,187), Point(119,195), Point(135,195),
Point(159,191), Point(179,183), Point(191,175), Point(195,159), Point(199,143),
Point(195,127), Point(187,111), Point(175,99), Point(163,95), Point(147,103),
Point(147,119), Point(147,131), Point(151,143), Point(143,147), Point(135,139)];

[Function InInnerRing: Boolean]

Function InInnerRing: Boolean;
var
Me: TPoint;
i: Integer;
InDist: Boolean;
begin
InDist := False;

Me := SPS_GetMyPos();

for i := 0 to High(IRPoints) do
begin
if (Distance(Me.X, Me.Y, IRPoints[i].X, IRPoints[i].Y) <= 16) then
InDist := True;
if InDist then
break;
end;

Result := InDist;
end;

This, obviously, tells you if you're in the inner ring of the Abyss.

[function CalcShortestPath(ArrayIn: TPointArray; Dest: TPoint): TPointArray;]

function CalcShortestPath(ArrayIn: TPointArray; Dest: TPoint): TPointArray;
var
DistA,DistB,h: Integer;
M,P,NP1,NP2: TPoint;
TempTPA,TempTPA2,IRPnts: TPointArray;
begin
M := SPS_GetMyPos();
IRPnts := TPAFromBox(IntToBox(116,104,172,161));

TempTPA := ClearTPAFromTPA(ArrayIn,IRPnts);

SortTPAFrom(TempTPA, M);
Writeln('Distance to target: '+IntToStr(Distance(M.X, M.Y, Dest.X, Dest.Y)));
P := M;

Repeat
SetArrayLength(TempTPA2, Length(TempTPA2)+1);

SortTPAFrom(TempTPA, P);
NP1 := TempTPA[h];
NP2 := TempTPA[h+1];

DistA := Distance(NP1.X, NP1.Y, Dest.X, Dest.Y);
DistB := Distance(NP2.X, NP2.Y, Dest.X, Dest.Y);

if (DistA > DistB) then
TempTPA2[h] := NP2
else
TempTPA2[h] := NP1;

Inc(h);
Until((DistA <= 10) Or (DistB <= 10))

ClearDoubleTPA(TempTPA2);

SortTPAFrom(TempTPA2, M);
Result := TempTPA2;

end;

This little work of art will take a set of pre-defined SPS coordinates, compare it to your player's current SPS coordinate, and calculate the shortest path. It's only useful for so many things, but among those is calculating which path (N/S/E/W) is the shortest to take to get to your target rift in the inner ring.


I have more of the script complete but the rest is personal preference of how objects and such should be located. So I decided just to post the global functions. Anyways, I hope someone finds use out of these, I put quite a bit of time into perfecting them.

Ashaman88

2012-10-21 23:09:14

This is great hopefully someone takes it up! Thanks for all of your work Flight

Nebula

2012-10-22 13:09:06

Looks nice but instead of cycling through every point in the inner ring function, wouldn't it be quicker to just compare it to the distance from the very center of the abyss? Something like this: InRange(Dist, 25, 50).

Also, this can be shortened
NP1 := TempTPA[h];
NP2 := TempTPA[h+1];
DistA := Distance(NP1.X, NP1.Y, Dest.X, Dest.Y);
DistB := Distance(NP2.X, NP2.Y, Dest.X, Dest.Y);
if (DistA > DistB) then
TempTPA2[h] := NP2
else
TempTPA2[h] := NP1;
To:
TempTPA2[h] := TempTPA[h + BoolToInt(Distance(TempTPA[h].X, TempTPA[h].Y, Dest.X, Dest.Y) > Distance(TempTPA[h+1].X,TempTPA[h+1].Y, Dest.X, Dest.Y))];

E: Nvm the above wouldn't work- I thought there was a BoolToInt function.
E2: I'm really puzzled as to why I thought there was a BoolToInt funtion that returned 0 if false, 1 if true.