Skip to content

Commit 54982c0

Browse files
committed
fix: read notes
- WebGraphCallbacks renamed to Transporter - fixed some more bugs in path finding - Added a rangechecks check to warn myself if I accidentally leave them on in webgraph - Added Lumbridge and Falador teleports to Transporter
1 parent d8a44b9 commit 54982c0

File tree

6 files changed

+177
-84
lines changed

6 files changed

+177
-84
lines changed

osrs.simba

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ less confusing way.
1717
{$DEFINE WL_DEBUG_UPTEXT}
1818
{$DEFINE WL_DEBUG_INTERFACES}
1919
{$DEFINE WL_GENERATE_GRAPH_ALWAYS}
20+
{$DEFINE WL_TRANSPORTER_DEBUG}
2021
```
2122
These are the main compiler directives available in the library.
2223

@@ -162,7 +163,7 @@ Summary: It includes this file until the current file is reached.
162163
{$IFNDEF WL_INVENTORY_FORM_INCLUDED} {$INCLUDE_ONCE osrs/interfaces/handlers/inventory_form.simba}
163164
{$IFNDEF WL_PRAYER_FORM_INCLUDED} {$INCLUDE_ONCE osrs/interfaces/handlers/prayer_form.simba}
164165
{$IFNDEF WL_CONSUMABLES_INCLUDED} {$INCLUDE_ONCE osrs/interfaces/handlers/consumables.simba}
165-
{$IFNDEF WL_WEBGRAPH_CALLBACKS_INCLUDED} {$INCLUDE_ONCE osrs/position/map/webgraph_callbacks.simba}
166+
{$IFNDEF WL_TRANSPORTER_INCLUDED} {$INCLUDE_ONCE osrs/position/map/transporter.simba}
166167

167168

168169
{$IFNDEF WL_ANTIBAN_TASKS_INCLUDED} {$INCLUDE_ONCE osrs/antiban/antibantasks.simba}

osrs/position/map/map.simba

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ begin
118118
@Self.Loader.Graph, Self.Loader.Map
119119
);
120120
Self.Walker.Name := 'Map.Walker';
121+
121122
Self.IsSetup := True;
122123
end;
123124
end;
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
(*
2+
# Transporter
3+
Responsible for transporting you from one place to another.
4+
This is not meant to be used directly but through {ref}`TRSWalker` WebWalking.
5+
*)
6+
7+
{$DEFINE WL_TRANSPORTER_INCLUDED}
8+
{$INCLUDE_ONCE WaspLib/osrs.simba}
9+
10+
{.$DEFINE WL_TRANSPORTER_DEBUG}
11+
12+
type
13+
(*
14+
## TTransporter type
15+
Main record responsible for transporting the player from one place to another.
16+
*)
17+
TTransporter = record
18+
Position: TWalkerPositionFunction;
19+
end;
20+
21+
function TTransporter.CheckTeleportGrandExchange(): Boolean;
22+
begin
23+
{$IFDEF WL_TRANSPORTER_DEBUG}
24+
WriteLn GetDebugLn('Transporter', 'Checking teleport to Grand Exchange spell.');
25+
{$ENDIF}
26+
if Stats.GetLevel(ERSSkill.MAGIC) < 25 then Exit;
27+
if Achievements.Diaries.GetLevel(ERSAchievementDiary.VARROCK) < 2 then Exit;
28+
Result := Magic.ContainsSpell(ERSSpell.VARROCK_TELEPORT);
29+
end;
30+
31+
function TTransporter.DoTeleportGrandExchange(): Boolean;
32+
begin
33+
{$IFDEF WL_TRANSPORTER_DEBUG}
34+
WriteLn GetDebugLn('Transporter', 'Casting teleport to Grand Exchange.');
35+
{$ENDIF}
36+
if Magic.CastSpell(ERSSpell.VARROCK_TELEPORT, 'Grand Exchange') then
37+
Result := SleepUntil(Self.Position().InRange([8565, 36522], 60), 300, 5000);
38+
end;
39+
40+
41+
function TTransporter.CheckTeleportVarrock(): Boolean;
42+
begin
43+
{$IFDEF WL_TRANSPORTER_DEBUG}
44+
WriteLn GetDebugLn('Transporter', 'Checking teleport to Varrock spell.');
45+
{$ENDIF}
46+
if Stats.GetLevel(ERSSkill.MAGIC) < 25 then Exit;
47+
Result := Magic.Open() and Magic.ContainsSpell(ERSSpell.VARROCK_TELEPORT);
48+
end;
49+
50+
function TTransporter.DoTeleportVarrock(): Boolean;
51+
begin
52+
{$IFDEF WL_TRANSPORTER_DEBUG}
53+
WriteLn GetDebugLn('Transporter', 'Casting teleport to Varrock.');
54+
{$ENDIF}
55+
if Magic.CastSpell(ERSSpell.VARROCK_TELEPORT, 'Cast') then
56+
Result := SleepUntil(Self.Position().InRange([8752, 36716], 60), 300, 5000);
57+
end;
58+
59+
60+
function TTransporter.CheckTeleportLumbridge(): Boolean;
61+
begin
62+
{$IFDEF WL_TRANSPORTER_DEBUG}
63+
WriteLn GetDebugLn('Transporter', 'Checking teleport to Lumbridge spell.');
64+
{$ENDIF}
65+
if Stats.GetLevel(ERSSkill.MAGIC) < 31 then Exit;
66+
Result := Magic.Open() and Magic.ContainsSpell(ERSSpell.LUMBRIDGE_TELEPORT);
67+
end;
68+
69+
function TTransporter.DoTeleportLumbridge(): Boolean;
70+
begin
71+
{$IFDEF WL_TRANSPORTER_DEBUG}
72+
WriteLn GetDebugLn('Transporter', 'Casting teleport to Lumbridge.');
73+
{$ENDIF}
74+
if Magic.CastSpell(ERSSpell.LUMBRIDGE_TELEPORT, 'Cast') then
75+
Result := SleepUntil(Self.Position().InRange([8752, 36716], 60), 300, 5000);
76+
end;
77+
78+
79+
function TTransporter.CheckTeleportFalador(): Boolean;
80+
begin
81+
{$IFDEF WL_TRANSPORTER_DEBUG}
82+
WriteLn GetDebugLn('Transporter', 'Checking teleport to Falador spell.');
83+
{$ENDIF}
84+
if Stats.GetLevel(ERSSkill.MAGIC) < 31 then Exit;
85+
Result := Magic.Open() and Magic.ContainsSpell(ERSSpell.FALADOR_TELEPORT);
86+
end;
87+
88+
function TTransporter.DoTeleportFalador(): Boolean;
89+
begin
90+
{$IFDEF WL_TRANSPORTER_DEBUG}
91+
WriteLn GetDebugLn('Transporter', 'Casting teleport to Falador.');
92+
{$ENDIF}
93+
if Magic.CastSpell(ERSSpell.FALADOR_TELEPORT, 'Cast') then
94+
Result := SleepUntil(Self.Position().InRange([8752, 36716], 60), 300, 5000);
95+
end;
96+
97+
98+
99+
procedure TTransporter.AddTeleports(graph: PWebGraph; chunk: TPoint);
100+
begin
101+
case chunk of
102+
[46,52]:
103+
begin
104+
graph^.AddTeleport([7764, 36906], @Self.CheckTeleportFalador, @Self.DoTeleportFalador);
105+
end;
106+
107+
[49,54]:
108+
begin
109+
graph^.AddTeleport([8565, 36522], @Self.CheckTeleportGrandExchange, @Self.DoTeleportGrandExchange);
110+
end;
111+
112+
[50,50]:
113+
begin
114+
graph^.AddTeleport([8792, 37554], @Self.CheckTeleportLumbridge, @Self.DoTeleportLumbridge);
115+
end;
116+
117+
[50,53]:
118+
begin
119+
graph^.AddTeleport([8752, 36716], @Self.CheckTeleportVarrock, @Self.DoTeleportVarrock);
120+
end;
121+
end;
122+
end;
123+
124+
procedure TTransporter.Setup(position: TWalkerPositionFunction; mapLoader: PRSMapLoader);
125+
var
126+
chunk: TPoint;
127+
region: TRSMapRegion;
128+
begin
129+
Self.Position := @position;
130+
131+
for region in mapLoader^.Regions do
132+
for chunk in region.Chunks do
133+
begin
134+
Self.AddTeleports(@mapLoader^.Graph, chunk);
135+
//Self.AddShortcuts(graph, chunk);
136+
//Self.AddWhatever(graph, chunk);
137+
end;
138+
end;
139+
140+
{$H-}
141+
var
142+
(*
143+
## Transporter variable
144+
Global {ref}`TTransporter` variable.
145+
*)
146+
Transporter: TTransporter;
147+
{$H+}

osrs/position/map/webgraph_callbacks.simba

Lines changed: 0 additions & 74 deletions
This file was deleted.

utils/webgraph.simba

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ but it was written from scratch by Torwent.
1010
{$INCLUDE_ONCE WaspLib/utils.simba}
1111

1212
{$R-}
13+
14+
{$IFDEF RANGECHECKS}
15+
begin
16+
WriteLn GetDebugLn('WebGraph', 'Range checks are enabled for webgraphs, these should be disabled in production!', ELogLevel.WARN);
17+
end;
18+
{$ENDIF}
19+
1320
type
1421
(*
1522
## EGraphNode
@@ -166,7 +173,6 @@ begin
166173
Result.Sort(weights, True);
167174
end;
168175

169-
{.$R+}
170176

171177
function TWebGraph.FindPath(start, finish: Integer; rnd: Double = 0): TIntegerArray;
172178
type TNode = record Indices: TIntegerArray; Score: Double; end;
@@ -187,14 +193,15 @@ var queue: array of TNode;
187193
end;
188194

189195
var
190-
visited: TBooleanArray;
196+
visited, checked: TBooleanArray;
191197
cIdx, pathIdx, i: Integer;
192198
current, node: TNode;
193199
p, q: TPoint;
194200
hyp: Double;
195201
begin
196202
queue := [[[start],0]];
197203
SetLength(visited, Length(Self.Nodes));
204+
SetLength(checked, Length(Self.Nodes));
198205

199206
for i := 0 to High(Self.Nodes) do
200207
visited[i] := Self.Nodes[i].Typ = EGraphNode.BLOCKED;
@@ -203,14 +210,17 @@ begin
203210
begin
204211
current := GetNextShortest();
205212
cIdx := current.Indices[High(current.Indices)];
213+
206214
if visited[cIdx] then
207215
Continue;
216+
208217
visited[cIdx] := True;
209218

210-
if (cIdx = finish) then
219+
if cIdx = finish then
211220
Exit(current.Indices);
212221

213222
p := Self.Nodes[cIdx].Node;
223+
214224
for pathIdx in Self.Paths[cIdx] do
215225
begin
216226
if visited[pathIdx] then
@@ -232,17 +242,19 @@ begin
232242
Continue;
233243
end;
234244

235-
if not Self.Nodes[pathIdx].Check() then
236-
node.Score := current.Score + hyp + (hyp*Random()*rnd-rnd/2) + 100
237-
else
245+
if checked[pathIdx] or Self.Nodes[pathIdx].Check() then
238246
begin
247+
checked[pathIdx] := True;
239248
case Self.Nodes[pathIdx].Typ of
240249
EGraphNode.DOOR: node.Score := current.Score + hyp + (hyp*Random()*rnd-rnd/2) + 10;
241-
EGraphNode.TELEPORT, EGraphNode.FAIRYRING: node.Score := current.Score + hyp*0.9 + 5;
250+
EGraphNode.TELEPORT, EGraphNode.FAIRYRING: node.Score := current.Score + hyp*0.8 + 5;
242251
else node.Score := current.Score + hyp + (hyp*Random()*rnd-rnd/2) + 10;
243252
end;
253+
queue += node;
254+
Continue;
244255
end;
245-
queue += node;
256+
257+
visited[pathIdx] := True;
246258
end;
247259
end;
248260
end;
@@ -621,7 +633,6 @@ begin
621633
Self.ObjectClusters += graph.ObjectClusters;
622634
end;
623635

624-
{$R-}
625636
procedure TWebGraph.Draw(img: TImage);
626637
var
627638
i,j: Integer;

utils/webgraphgen.simba

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ script **BEFORE INCLUDING WASPLIB**:
1212

1313
{$DEFINE WL_WEBGRAPHGEN_INCLUDED}
1414
{$INCLUDE_ONCE WaspLib/utils.simba}
15+
1516
{$R-}
17+
{$IFDEF RANGECHECKS}
18+
begin
19+
WriteLn GetDebugLn('WebGraphGenerator', 'Range checks are enabled for webgraph generator, these should be disabled in production!', ELogLevel.WARN);
20+
end;
21+
{$ENDIF}
22+
1623
{.$DEFINE WL_GENERATE_GRAPH_ALWAYS}
1724

1825
type

0 commit comments

Comments
 (0)