示例#1
0
  public Pair<Area, Point2D> getEntrancePoint(Area dest) {
    if (dest == null) {
      log.error("why try to move to " + dest + "?????");
      return null;
    }
    Path path = agent.move.getPathTo(Collections.singleton(dest), PoliceMove.class);
    ArrayList<EntityID> pathArray = path.getIds();
    if (pathArray.isEmpty()) {
      log.error("path is empty. why????");
      return null;
    }

    Edge inComingEdge;
    if (pathArray.size() == 1) {
      inComingEdge = dest.getEdgeTo(agent.location());
    } else {
      inComingEdge = dest.getEdgeTo(pathArray.get(pathArray.size() - 2));
    }
    if (inComingEdge == null) return new Pair<Area, Point2D>(dest, dest.getPositionPoint());
    Line2D wallLine =
        inComingEdge
            .getLine(); // new Line2D(edge.getStartX(), edge.getStartY(), edge.getEndX() -
                        // edge.getStartX(), edge.getEndY() - edge.getStartY());

    Vector2D offset;
    if (AliGeometryTools.havecorrectDirection(dest)) {
      offset = wallLine.getDirection().getNormal().normalised().scale(10);
    } else {
      offset = wallLine.getDirection().getNormal().normalised().scale(-10);
    }
    Point2D destXY = inComingEdge.getMidPoint().plus(offset);
    return new Pair<Area, Point2D>(dest, destXY);
  }
示例#2
0
 public int getTimeToTarget(Path path) {
   if (path.getLenght() < agent.clearDistance) return 0;
   return ((path.getLenght() - agent.clearDistance) / MoveConstants.AVERAGE_MOVE_PER_CYCLE) + 1;
 }