- Joined
- Oct 30, 2014
- Messages
- 3,610
- Thread Author
- #1
So.. Since other people might be interested in how I add areas to the web, I'm writing this tutorial on how I do it. It's probably wrong in many ways, but I'm sure some of you have no clue, and this might help. I'm open for any constructive feedback, I'm in a learning phase, so I'll take it. 
So let's begin..
Content:
1. Getting the coordinates
I created a simple tool that gets the reachable coordinates around you in a web form (skips some of the tiles) within a given radius and logs them. There's also an option to write them to a file.
2. Adding and connecting the vertices
This is the part where I think I might be doing stuff wrong, but here's my logic.
For each coordinate, I look for existing vertices in the web to connect to. If there is, I add a bidirectional edge between the two vertices.
I'm adding/removing 2 from the coordinate's x/y because my web additions have one tile in between each other, if you use more space in between, the code should be fairly easy to adjust.
I'm using a method called "getVertexAt" which simply returns the existing vertex at a position if it's already in the web.
And that's basically my way of adding new areas to the default web. If you have any questions or advice, feel free to comment or contact me in another way. Thanks for reading.
-Defeat3d
So let's begin..
Content:
- Getting the coordinates
- Adding and connecting the vertices
1. Getting the coordinates
I created a simple tool that gets the reachable coordinates around you in a web form (skips some of the tiles) within a given radius and logs them. There's also an option to write them to a file.

Code:
public static List<Coordinate> getSurroundingWeb(final Locatable loc, final int radius, final int divisibleBy) {
final Coordinate[] reachable = (Coordinate[]) loc.getPosition().getReachableCoordinates().toArray();
List<Coordinate> web = new ArrayList<Coordinate>();
for (Coordinate c : reachable) {
if (c.getX() % divisibleBy == 0 && c.getY() % divisibleBy == 0 && c.distanceTo(loc) <= radius) {
web.add(c);
}
}
return web;
}
2. Adding and connecting the vertices
This is the part where I think I might be doing stuff wrong, but here's my logic.
For each coordinate, I look for existing vertices in the web to connect to. If there is, I add a bidirectional edge between the two vertices.
Code:
public void addCoordinate(Coordinate... coordinates) {
for (Coordinate c : coordinates) {
final CoordinateVertex cv = new CoordinateVertex(c);
web.addVertices(cv);
final int[][] add = new int[][]{{-2, +2}, {0, +2}, {+2, +2}, {+2, 0}, {+2, -2}, {0, -2}, {-2, -2}, {-2, 0}};
for (int[] i : add) {
final Coordinate yes = new Coordinate(c.getX() + i[0], c.getY() + i[1], 0);
final WebVertex v = getVertexAt(yes);
if (v != null) {
cv.addBidirectionalEdge(v);
}
}
}
}
I'm adding/removing 2 from the coordinate's x/y because my web additions have one tile in between each other, if you use more space in between, the code should be fairly easy to adjust.
I'm using a method called "getVertexAt" which simply returns the existing vertex at a position if it's already in the web.
Code:
WebVertex getVertexAt(Coordinate coordinate) {
for (WebVertex v : web.getRegularVertices()) {
if (v.getPosition().equals(coordinate)) {
return v;
}
}
return null;
}
And that's basically my way of adding new areas to the default web. If you have any questions or advice, feel free to comment or contact me in another way. Thanks for reading.
-Defeat3d
Last edited: