def _group_point(point: Point, base_distance) -> Point: distance = random.randint( int(base_distance * SPREAD_DISTANCE_FACTOR[0]), int(base_distance * SPREAD_DISTANCE_FACTOR[1]), ) return point.random_point_within( distance, base_distance * SPREAD_DISTANCE_SIZE_FACTOR)
def find_location(on_ground: bool, near: Point, theater: ConflictTheater, min_range: int, max_range: int, others: List[TheaterGroundObject], is_base_defense: bool = False) -> Optional[Point]: """ Find a valid ground object location :param on_ground: Whether it should be on ground or on sea (True = on ground) :param near: Point :param theater: Theater object :param min_range: Minimal range from point :param max_range: Max range from point :param others: Other already existing ground objects :param is_base_defense: True if the location is for base defense. :return: """ point = None for _ in range(300): # Check if on land or sea p = near.random_point_within(max_range, min_range) if on_ground and theater.is_on_land(p): point = p elif not on_ground and theater.is_in_sea(p): point = p if point: for angle in range(0, 360, 45): p = point.point_from_heading(angle, 2500) if on_ground and not theater.is_on_land(p): point = None break elif not on_ground and not theater.is_in_sea(p): point = None break if point: for other in others: if other.position.distance_to_point(point) < 10000: point = None break if point: for control_point in theater.controlpoints: if is_base_defense: break if control_point.position != near: if point is None: break if control_point.position.distance_to_point(point) < 30000: point = None break for ground_obj in control_point.ground_objects: if ground_obj.position.distance_to_point( point) < 10000: point = None break if point: return point return None