- Joined
- Dec 18, 2014
- Messages
- 398
- Thread Author
- #1
As I've said before, I've been attempting this for 3 days, with a total of about 20 hours burnt on trying to get from Point A to Point B. I would be strongly in your debt if you could help me get past this block.
edit: The problem is that the web.getPathBuilder().buildTo(new Coordinate(2851, 3027, 0)); is returning a null Path. I think I've generated the coordinates correctly, written them down correctly, read them correctly, and assigned them back to the web correctly. I can't find any error.
edit: The problem is that the web.getPathBuilder().buildTo(new Coordinate(2851, 3027, 0)); is returning a null Path. I think I've generated the coordinates correctly, written them down correctly, read them correctly, and assigned them back to the web correctly. I can't find any error.
Code:
// in WebCreator.java
private Web web = new Web();
private FileWeb fileWeb = new FileWeb();
private Player player = Players.getLocal();
//these are Defeat3d's methods in his tutorial
public static List<Coordinate> getSurroundingWeb(final Locatable loc, final int radius, final int divisibleBy) {
final Coordinate[] reachable = loc.getPosition().getReachableCoordinates().toArray(new Coordinate[] {});
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;
}
public void addCoordinate(Coordinate... coordinates) {
final GameObjectQueryBuilder objects = GameObjects.newQuery().types(GameObject.Type.BOUNDARY_OBJECT, GameObject.Type.PRIMARY, GameObject.Type.WALL_DECORATION);
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], c.getPlane());
final Coordinate between = new Coordinate(c.getX() + i[0] / 2, c.getY() + i[1] / 2, c.getPlane());
final WebVertex v = getVertexAt(yes);
if (v != null && objects.on(between).results().isEmpty()) {
cv.addBidirectionalEdge(v);
}
}
}
}
WebVertex getVertexAt(Coordinate coordinate) {
for (WebVertex v : web.getRegularVertices()) {
if (v.getPosition().equals(coordinate)) {
return v;
}
}
return null;
}
//calling Defeat3d's methods with a GUI
onActionPerformed(ActionEvent e)
{
if(e.getActionPerformed.equals("addArea")
// this is being called about every ten steps, encompassing with excess the starting and ending area
addCoordinate(getSurroundingWeb(player, 20, 2).toArray(new Coordinate[] {}));
else if(e.getActionPerformed.equals("write")
write();
}
//my method to write to a file
public void write()
{
FileWeb web = new FileWeb();
web.addVertices(this.web.getVertices());
try(ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("webbie.web")))
{
oos.writeObject(web.toByteArray());
}
catch (Exception e)
{
e.printStackTrace();
}
}
Code:
//in RaysNatRunner.java
private Player player = Players.getLocal();
private Web web = Traversal.getDefaultWeb();
public boolean merge(final File file) {
try(ObjectInputStream input = new ObjectInputStream(new FileInputStream(file)))
{
Object obj = input.readObject();
if(obj != null && obj instanceof byte[])
{
System.out.println("Is an instance of"); //successfully prints this
FileWeb fileWeb = FileWeb.fromByteArray((byte[])obj);
this.web.addVertices(fileWeb.getVertices());
}
else System.out.println("not an instance of");
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
@Override
public void onStart()
{
merge(new File("webbie.web"));
}
@Override
public void onLoop()
{
//prints true, meaning the Path generated is null.
System.out.println(web.getPathBuilder().buildTo(new Coordinate(2851, 3027, 0)) == null);
stop();
}
Last edited: