WebGraph¶
Responsible for handling webwalking or any other graph logic you may need.
It’s partially based on the original webgraph logic by slacky but it was written from scratch by Torwent.
It’s important to note that most types and methods are for internal usage and you shouldn’t really have to interact with it.
type TWebGraph¶
Type representing a webgraph, for more information on what a graph is in this context visit this wikipedia page
TWebGraph.Setup¶
procedure TWebGraph.Setup();
It sets up TWebGraph.Tree, a TKDPointTree used to compare distances between
nodes very fast.
TWebGraph.Copy¶
function TWebGraph.Copy(): TWebGraph;
Performs a unique copy of the TWebGraph which you can modify without modifying the original.
Useful for debugging graphs when you need to keep the original unchanged, e.g.
with the Map Debugger.
TWebGraph.BlockArea¶
procedure TWebGraph.BlockArea(area: TBox; inside: Boolean = True);
Blocks an area of the TWebGraph so no nodes in the specified area are returned
when finding paths.
For example, this is how you could block the space where wintertodt is so you don’t get paths through the chasm:
Map.Setup([ERSChunk.WINTERTODT]);
Map.Loader.Graph.BlockArea([6478, 34358, 6565, 34445]);
TWebGraph.NearNodesIndices¶
function TWebGraph.NearNodesIndices(pt: TPoint; amount: Int32): TIntegerArray;
Returns the indices of the amount of nearest nodes to pt on the webgraph
that can be walked to to and from pt.
The result returned is sorted by shortest distance to pt.
TWebGraph.FindPath¶
function TWebGraph.FindPath(start, finish: Int32; rnd: Double = 0): TIntegerArray;
Finds a path between start and finish with the ability to introduce some
randomness through rnd.
This is basically a weighted BFS algorithm.
For more information on the algorithm read the wikipedia page on breadth-first search.
TWebGraph.PathBetween¶
function TWebGraph.PathBetween(a, b: TPoint; rnd: Double = 0; attempts: Int32 = 3): TPointArray;
Returns a path between a and b with the ability to introduce some randomness
through rnd.
The returned path comes in the form of a TPointArray.
TWebGraph.NearestPathable¶
function TWebGraph.NearestPathable(me: TPoint; destinations: TPointArray): TPoint;
Returns the nearest point in destinations to me that has a valid path in
between.
TWebGraph.AddNode¶
function TWebGraph.AddNode(pt: TPoint; fromNode: Int32): Boolean;
Adds a new node to the TWebGraph with a connection to fromNode.
You can specify it’s coordinate through pt.
TWebGraph.ConnectNodes¶
procedure TWebGraph.ConnectNodes(a,b: Int32);
procedure TWebGraph.ConnectNodes(a,b: TPoint); overload;
procedure TWebGraph.ConnectNodes(a: Int32; b: TPoint); overload;
Connects nodes a and b.
If either a or b are TPoints, they must match exactly the coordinates of a
node in the graph.
Using indices is always better for performance but overtime they may change if the shape of the graph changes.
TWebGraph.ConnectNodesEx¶
procedure TWebGraph.ConnectNodesEx(a,b: TPoint; notEqual: Boolean = False);
Connects the closest node to a to the closest node to b.
This is similar to TWebGraph.ConnectNodes when using TPoints but unlike
it, your points don’t have to be the exact same as the nodes in the graph.
Overall, this is the most flexible and easiest method to use but it might not connect exactly the nodes you want at times.
TWebGraph.DeleteNode¶
function TWebGraph.DeleteNode(node: Int32): Int32;
Deletes a Node from a TWebGraph along with all the connections to it.
TWebGraph.DeleteNodes¶
procedure TWebGraph.DeleteNodes(b: TBox);
It’s very similar to TWebGraph.BlockNodes but unlike it, what this does is permanent. Blocking nodes could be used to selectively toggle nodes on/off, this permanently removes them.
For example, this is how you could block the space where wintertodt is so you don’t get paths through the chasm:
Map.Setup([ERSChunk.WINTERTODT]);
Map.Loader.Graph.DeleteNodes([6478, 34358, 6565, 34445]);
TWebGraph.Merge¶
procedure TWebGraph.Merge(graph: TWebGraph);
Merges graph into the current TWebGraph.
TWebGraph.Draw¶
procedure TWebGraph.Draw(img: TImage);
procedure TWebGraph.Draw(canvas: TImageBoxCanvas); overload;
Used for TWebGraph debugging.