Пример #1
0
 def closest_control_point(self, point: Point) -> ControlPoint:
     closest = self.controlpoints[0]
     closest_distance = point.distance_to_point(closest.position)
     for control_point in self.controlpoints[1:]:
         distance = point.distance_to_point(control_point.position)
         if distance < closest_distance:
             closest = control_point
             closest_distance = distance
     return closest
Пример #2
0
def closest_cp(location: Point) -> (int, float):
    global theater
    min_distance, min_cp = None, None

    for cp in theater.controlpoints:
        if not min_distance or location.distance_to_point(cp.position) < min_distance:
            min_distance = location.distance_to_point(cp.position)
            min_cp = cp.id

    assert min_cp is not None
    return min_cp
Пример #3
0
 def closest_control_point(
     self, point: Point, allow_naval: bool = False
 ) -> ControlPoint:
     closest = self.controlpoints[0]
     closest_distance = point.distance_to_point(closest.position)
     for control_point in self.controlpoints[1:]:
         if control_point.is_fleet and not allow_naval:
             continue
         distance = point.distance_to_point(control_point.position)
         if distance < closest_distance:
             closest = control_point
             closest_distance = distance
     return closest
Пример #4
0
 def nearest_land_pos(self, point: Point, extend_dist: int = 50) -> Point:
     """Returns the nearest point inside a land exclusion zone from point
     `extend_dist` determines how far inside the zone the point should be placed"""
     if self.is_on_land(point):
         return point
     point = geometry.Point(point.x, point.y)
     nearest_points = []
     if not self.landmap:
         raise RuntimeError("Landmap not initialized")
     for inclusion_zone in self.landmap[0]:
         nearest_pair = ops.nearest_points(point, inclusion_zone)
         nearest_points.append(nearest_pair[1])
     min_distance = point.distance(
         nearest_points[0])  # type: geometry.Point
     nearest_point = nearest_points[0]  # type: geometry.Point
     for pt in nearest_points[1:]:
         distance = point.distance(pt)
         if distance < min_distance:
             min_distance = distance
             nearest_point = pt
     assert isinstance(nearest_point, geometry.Point)
     point = Point(point.x, point.y)
     nearest_point = Point(nearest_point.x, nearest_point.y)
     new_point = point.point_from_heading(
         point.heading_between_point(nearest_point),
         point.distance_to_point(nearest_point) + extend_dist)
     return new_point
Пример #5
0
 def closest_target(self, point: Point) -> MissionTarget:
     closest: MissionTarget = self.controlpoints[0]
     closest_distance = point.distance_to_point(closest.position)
     for control_point in self.controlpoints[1:]:
         distance = point.distance_to_point(control_point.position)
         if distance < closest_distance:
             closest = control_point
             closest_distance = distance
         for tgo in control_point.ground_objects:
             distance = point.distance_to_point(tgo.position)
             if distance < closest_distance:
                 closest = tgo
                 closest_distance = distance
     for conflict in self.conflicts():
         distance = conflict.position.distance_to_point(point)
         if distance < closest_distance:
             closest = conflict
             closest_distance = distance
     return closest
Пример #6
0
    def _rendezvous_should_retreat(self, attack_transition: Point) -> bool:
        transition_target_distance = attack_transition.distance_to_point(
            self.package.target.position)
        origin_target_distance = self._distance_to_package_airfield(
            self.package.target.position)

        # If the origin point is closer to the target than the ingress point,
        # the rendezvous point should be positioned in a position that retreats
        # from the origin airfield.
        return origin_target_distance < transition_target_distance
Пример #7
0
    def nav_point_prunable(self, previous: Point, current: Point, nxt: Point) -> bool:
        previous_threatened = self.threat_zones.path_threatened(previous, current)
        next_threatened = self.threat_zones.path_threatened(current, nxt)
        pruned_threatened = self.threat_zones.path_threatened(previous, nxt)
        previous_distance = meters(previous.distance_to_point(current))
        distance = meters(current.distance_to_point(nxt))
        distance_without = previous_distance + distance
        if distance > distance_without:
            # Don't prune paths to make them longer.
            return False

        # We could shorten the path by removing the intermediate
        # waypoint. Do so if the new path isn't higher threat.
        if not pruned_threatened:
            # The new path is not threatened, so safe to prune.
            return True

        # The new path is threatened. Only allow if both paths were
        # threatened anyway.
        return previous_threatened and next_threatened
Пример #8
0
    def nearest_airport(self, position: mapping.Point, coalition: str=None) -> Airport:
        airports = [x for x in self.airports.values() if x.coalition.lower() == coalition.lower()] if coalition else self.airports

        dist = sys.float_info.max
        airport = None
        for x in airports:
            d = position.distance_to_point(x.position)
            if d < dist:
                airport = x
                dist = d

        return airport
Пример #9
0
    def nearest_airport(self, position: mapping.Point, coalition: str=None) -> Airport:
        airports = [x for x in self.airports.values() if x.coalition.lower() == coalition.lower()] if coalition else self.airports

        dist = sys.float_info.max
        airport = None
        for x in airports:
            d = position.distance_to_point(x.position)
            if d < dist:
                airport = x
                dist = d

        return airport
Пример #10
0
    def nearest_node(self, position: mapping.Point):
        """Find nearest node to the given point.

        Args:
            position: Point to find the nearest

        Returns:
            The nearest node to the that point
        """
        dist = sys.float_info.max
        node = None
        for x in self.nodes:
            d = position.distance_to_point(x.position)
            if d < dist:
                node = x
                dist = d

        return node
Пример #11
0
    def nearest_node(self, position: mapping.Point):
        """Find nearest node to the given point.

        Args:
            position: Point to find the nearest

        Returns:
            The nearest node to the that point
        """
        dist = sys.float_info.max
        node = None
        for x in self.nodes:
            d = position.distance_to_point(x.position)
            if d < dist:
                node = x
                dist = d

        return node
Пример #12
0
 def between_points(a: Point, b: Point, speed: Speed) -> timedelta:
     error_factor = 1.05
     distance = meters(a.distance_to_point(b))
     return timedelta(hours=distance.nautical_miles / speed.knots *
                      error_factor)
Пример #13
0
 def between_points(a: Point, b: Point, speed: float) -> timedelta:
     error_factor = 1.1
     distance = meter_to_nm(a.distance_to_point(b))
     return timedelta(hours=distance / speed * error_factor)
Пример #14
0
 def destination_in_range(self, destination: Point) -> bool:
     distance = meters(destination.distance_to_point(self.position))
     return distance <= self.max_move_distance