private void setPathIDForRoads(List<Path> paths) { for (Path path : paths) { for (Road road : path) { roadHelper.setPathId(road.getID(), path.getId()); } } }
private Path getNearestPath(Road road, List<Path> paths) { int range = 10000; int minDistance = Integer.MAX_VALUE; EntityID nearestPath = null; while (nearestPath == null) { Collection<StandardEntity> entities = world.getObjectsInRange(road, range); for (StandardEntity entity : entities) { if (entity instanceof Road) { EntityID pathId = roadHelper.getPathId(entity.getID()); if (pathId != null) { int distance = Util.distance((Area) entity, road); if (distance < minDistance) { nearestPath = pathId; minDistance = distance; } } } } range += 10000; } for (Path path : paths) { if (path.getId().equals(nearestPath)) { return path; } } return null; }
private void addToPath(Road road, EntityID pathId, List<Path> paths) { for (Path path : paths) { if (path.getId().equals(pathId)) { adding(road, path); break; } } }
private void adding(Road road, Path path) { roadHelper.setPathId(road.getID(), path.getId()); if (!path.contains(road)) { path.add(road); if (entrances.contains(road)) { path.addEntrance(getEntrance(road)); } } }
private void addEntrances(Path path, Road road) { Entrance entrance; for (Road n : roadHelper.getConnectedRoads(road.getID())) { if (entrances.contains(n)) { roadHelper.setPathId(n.getID(), path.getId()); if (!path.contains(n) && !added.contains(n)) { path.add(n); added.add(n); } entrance = getEntrance(n); if (!path.getEntrances().contains(entrance)) { path.addEntrance(entrance); } } } }