Skip to content

Commit 96fb8b1

Browse files
committed
feat: experimental but working webwalking with teleports
Teleports need to be manually added for now
1 parent a3d8048 commit 96fb8b1

File tree

4 files changed

+49
-16
lines changed

4 files changed

+49
-16
lines changed

osrs/position/map/mapdebugger.simba

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,14 @@ begin
7676
if Self.Path <> [] then
7777
begin
7878
for i := 0 to High(Self.Path)-1 do
79-
tpa += TPointArray.CreateFromLine(Self.Path[i].Node, Self.Path[i+1].Node);
80-
canvas.DrawPoints(tpa, $FF0000);
79+
begin
80+
tpa := TPointArray.CreateFromLine(Self.Path[i].Node, Self.Path[i+1].Node);
81+
case Self.Path[i+1].Typ of
82+
EGraphNode.TELEPORT: canvas.DrawPoints(tpa.Grow(1), $3388FF);
83+
else canvas.DrawPoints(tpa, $FF0000);
84+
end;
85+
end;
86+
8187
end;
8288
end;
8389
end;
@@ -101,7 +107,7 @@ begin
101107
Self.Coordinate.Caption := Format('[%d, %d]', [g.X, g.Y]);
102108

103109
Self.Path := [];
104-
if (shift = [ELazShiftStates.Shift]) and (Self.Selected > -1) then
110+
if (ELazShiftStates.Shift in shift) and (Self.Selected > -1) then
105111
begin
106112
i := Self.Graph.Nodes.NearestIndex(pt);
107113

osrs/position/map/webgraph_callbacks.simba

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,19 @@ begin
2929
case chunk of
3030
[49,54]:
3131
begin
32-
if Achievements.Diaries.GetLevel(ERSAchievementDiary.VARROCK) > 1 then
33-
graph^.AddTeleport([8565, 36522], @Self.TeleportGrandExchange);
32+
if Stats.GetLevel(ERSSkill.MAGIC) < 25 then
33+
Exit;
34+
if Achievements.Diaries.GetLevel(ERSAchievementDiary.VARROCK) < 2 then
35+
Exit;
36+
37+
//graph^.AddTeleport([8565, 36522], @Self.TeleportGrandExchange);
38+
end;
39+
[50,53]:
40+
begin
41+
if Stats.GetLevel(ERSSkill.MAGIC) < 25 then
42+
Exit;
43+
graph^.AddTeleport([8752, 36716], @Self.TeleportVarrock);
3444
end;
35-
[50,53]: graph^.AddTeleport([8752, 36716], @Self.TeleportVarrock);
3645
end;
3746
end;
3847

osrs/walker.simba

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,12 @@ begin
850850
//Self._Path += path.First;
851851
for i := 0 to High(path)-1 do
852852
begin
853+
if path[i+1].Typ = EGraphNode.TELEPORT then
854+
begin
855+
Self._Path += path[i+1];
856+
Continue;
857+
end;
858+
853859
line := TPointArray.CreateFromLine(path[i].Node, path[i+1].Node);
854860

855861
if path[i].Typ <> EGraphNode.NORMAL then
@@ -889,8 +895,16 @@ begin
889895
previous := index;
890896

891897
nearest := Self._Path.NearestIndex(me);
898+
892899
Self._Index := nearest;
893900

901+
if Self._Path[Self._Index].Typ = EGraphNode.TELEPORT then
902+
begin
903+
index := Self._Index;
904+
Self._Node := EGraphNode.TELEPORT;
905+
Exit(nearest > previous);
906+
end;
907+
894908
while (nearest < High(Self._Path)) and not Self.IsWalkable(Self._Path[nearest+1].Node, me, tmp, angle) do
895909
Inc(nearest);
896910

@@ -977,7 +991,7 @@ Walker.WalkPath([[100,100],[120,120],[140,140],[160,160],[180,180]]);
977991
function TRSWalker.WalkPath(path: TGraphNodeArray; minDist: Integer = 0; debug: Boolean = False): Boolean;
978992
var
979993
me: TPoint;
980-
idx, fails: Integer;
994+
i, idx, fails: Integer;
981995
radians: Double;
982996
begin
983997
Self._WalkPathSetup(path);

utils/webgraph.simba

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ Enum representing the type of nodes in a `TWebGraph`.
2626
BLOCKED
2727
);
2828

29+
TGraphNodeHandler = function (): Boolean of object;
30+
2931
TGraphNode = record
3032
Node: TPoint;
3133
Typ: EGraphNode;
32-
Handle: function (): Boolean of object;
34+
Handle: TGraphNodeHandler;
3335
end;
3436

35-
function TGraphNode.Create(pt: TPoint; typ: EGraphNode = EGraphNode.NORMAL; handle: function (): Boolean of object = nil): TGraphNode; static;
37+
function TGraphNode.Create(pt: TPoint; typ: EGraphNode = EGraphNode.NORMAL; handle: TGraphNodeHandler = nil): TGraphNode; static;
3638
begin
3739
Result.Node := pt;
3840
Result.Typ := typ;
@@ -216,9 +218,11 @@ begin
216218
node.Indices := current.Indices + pathIdx;
217219

218220
hyp := Hypot(p.X-q.X, p.Y-q.Y);
219-
node.Score := current.Score + hyp + (hyp*Random()*Rnd-Rnd/2);
220-
if Self.Nodes[pathIdx].Typ <> EGraphNode.NORMAL then
221-
node.Score += 10;
221+
case Self.Nodes[pathIdx].Typ of
222+
EGraphNode.NORMAL: node.Score := current.Score + hyp + (hyp*Random()*rnd-rnd/2) + 1;
223+
EGraphNode.TELEPORT, EGraphNode.FAIRYRING: node.Score := current.Score + hyp*0.9 + 5;
224+
else node.Score := current.Score + hyp + (hyp*Random()*rnd-rnd/2) + 10;
225+
end;
222226
queue += node;
223227
end;
224228
end;
@@ -409,7 +413,7 @@ begin
409413
end;
410414

411415

412-
procedure TWebGraph.AddLink(a, b: TPoint; typ: EGraphNode; handle: function (): Boolean of object);
416+
procedure TWebGraph.AddLink(a, b: TPoint; typ: EGraphNode; handle: TGraphNodeHandler);
413417
var
414418
i, j, n: Integer;
415419
tpa: TPointArray;
@@ -447,7 +451,7 @@ begin
447451
end;
448452
end;
449453

450-
procedure TWebGraph.AddLink(a, b: TPoint; typ: EGraphNode; handleA, handleB: function (): Boolean of object); overload;
454+
procedure TWebGraph.AddLink(a, b: TPoint; typ: EGraphNode; handleA, handleB: TGraphNodeHandler); overload;
451455
var
452456
i, j, n: Integer;
453457
tpa: TPointArray;
@@ -485,7 +489,7 @@ begin
485489
end;
486490
end;
487491

488-
procedure TWebGraph.AddLink(pt, a, b: TPoint; typ: EGraphNode; handle: function (): Boolean of object); overload;
492+
procedure TWebGraph.AddLink(pt, a, b: TPoint; typ: EGraphNode; handle: TGraphNodeHandler); overload;
489493
var
490494
i, j, n: Integer;
491495
tpa: TPointArray;
@@ -521,7 +525,7 @@ begin
521525
Self.Nodes[i] := TGraphNode.Create(pt, typ, @handle);
522526
end;
523527

524-
procedure TWebGraph.AddTeleport(pt: TPoint; handle: function (): Boolean of object);
528+
procedure TWebGraph.AddTeleport(pt: TPoint; handle: TGraphNodeHandler);
525529
var
526530
i, j, n: Integer;
527531
tpa: TPointArray;

0 commit comments

Comments
 (0)