public void setWaypoint(EWaypointType waypointType, ShortPoint2D position) { if (waypointType != EWaypointType.DESTINATION && !isTargetSet()) { waypointType = EWaypointType.DESTINATION; } if (isSelected()) { drawWaypointLine(false); } if (waypointType == EWaypointType.DESTINATION) { Arrays.fill(waypoints, null); } ShortPoint2D closestReachableLocation = findClosestReachablePosition(waypointType, position); if (closestReachableLocation == null || !isWaypointFulfillingPreconditions(waypointType, closestReachableLocation)) { return; } waypoints[waypointType.ordinal()] = closestReachableLocation; if (isSelected()) { drawWaypointLine(true); } }
@Override protected void serializeTask(DataOutputStream dos) throws IOException { super.serializeTask(dos); dos.writeByte(waypointType.ordinal()); serializePosition(dos, position); }
private ShortPoint2D findClosestReachablePosition(EWaypointType waypointType, ShortPoint2D targetPosition) { ShortPoint2D waypointBefore = getWaypointsStartPosition(); for (int index = waypointType.ordinal() - 1; index >= 0; index--) { if (waypoints[index] != null) { waypointBefore = waypoints[index]; break; } } return grid.getClosestReachablePosition(waypointBefore, targetPosition, false, this.isSeaTrading(), null, WAYPOINT_SEARCH_RADIUS); }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((position == null) ? 0 : position.hashCode()); result = prime * result + ((waypointType == null) ? 0 : waypointType.hashCode()); return result; }