def is_object_valid(self, obj):
     if not obj.is_terrain:
         return False
     routing_surface = obj.routing_surface
     if routing_surface.type in self.disallowed_surfaces:
         return False
     elif not routing.test_point_placement_in_navmesh(
             routing_surface, obj.position):
         return False
     return True
Beispiel #2
0
    def can_position_be_routed_to(
            position: CommonVector3,
            surface_identifier: CommonSurfaceIdentifier) -> bool:
        """can_position_be_routed_to(position, surface_identifier)

        Determine if a position and surface can be routed to by a Sim.

        :param position: The position to check.
        :type position: CommonVector3
        :param surface_identifier: The surface to check.
        :type surface_identifier: CommonSurfaceIdentifier
        :return: True, if the position can be routed to by a Sim. False, it not.
        :rtype: bool
        """
        from routing import test_point_placement_in_navmesh
        return test_point_placement_in_navmesh(surface_identifier, position)
 def choose_cancellation_time(self):
     path_duration = self.path.duration()
     if path_duration > 0:
         server_delay = (services.time_service().sim_timeline.future - services.time_service().sim_now).in_real_world_seconds()
         min_time = self.ROUTE_MINIMUM_TIME_REMAINING_FOR_CANCELLATION + server_delay
         current_time = (services.time_service().sim_now - self.start_time).in_real_world_seconds() - self._time_offset
         while path_duration - current_time > min_time:
             cancellation_time = current_time + min_time
             cancel_node = self.path.node_at_time(cancellation_time)
             if cancel_node is None:
                 return
             if cancel_node.index > 0:
                 cancel_node = self.path.nodes[cancel_node.index - 1]
             while cancel_node.action != PathNodeAction.PATH_NODE_WALK_ACTION:
                 cancel_node = self.path.nodes[cancel_node.index + 1]
                 cancellation_time = cancel_node.time
             routing_surface_id = cancel_node.routing_surface_id
             position = sims4.math.Vector3(*self.path.position_at_time(cancellation_time))
             nearby = placement.get_nearby_sims(position, routing_surface_id.secondary_id, radius=routing.get_default_agent_radius(), exclude=[self.actor], stop_at_first_result=True, only_sim_position=False, only_sim_intended_position=False)
             if len(nearby) == 0 and routing.test_point_placement_in_navmesh(routing_surface_id, position):
                 return (cancellation_time, self.ROUTE_CANCELLATION_APPROX_STOP_ACTION_TIME + (cancellation_time - current_time))
             current_time = cancellation_time
Beispiel #4
0
def find_good_location_with_generator(search_generator,
                                      polygons=None,
                                      polygon_forwards=None,
                                      routing_surface=None,
                                      context=None):
    raise RuntimeError(
        '[bhill] This function is believed to be dead code and is scheduled for pruning. If this exception has been raised, the code is not dead and this exception should be removed.')
    if routing_surface is None:
        if context is not None:
            routing_surface = context.search_strategy.start_routing_surface
        else:
            zone_id = sims4.zone_utils.get_zone_id()
            routing_surface = routing.SurfaceIdentifier(
                zone_id, 0, routing.SURFACETYPE_WORLD)
    if polygons is None:
        polygons = []
        polygon_forwards = []
        if context is not None:
            if context.search_strategy.object_id != 0:
                obj = objects.system.find_object(
                    context.search_strategy.object_id)
                p = obj.footprint_polygon
                if p is not None:
                    polygons.append(p)
                    polygon_forwards.append(obj.orientation)
                elif context.search_strategy.object_footprints:
                    for fp in context.search_strategy.object_footprints:
                        p = _placement.get_placement_footprint_polygon(
                            context.search_strategy.start_position,
                            context.search_strategy.start_orientation,
                            context.search_strategy.start_routing_surface, fp)
                        polygons.append(p)
                        polygon_forwards.append(
                            context.search_strategy.start_orientation)
                else:
                    nNumPolygons = context.search_strategy.num_polygons
                    if nNumPolygons == 0:
                        return
                    q = sims4.math.angle_to_yaw_quaternion(0.0)
                    for i in range(nNumPolygons):
                        p = context.search_strategy.get_polygon(i)
                        polygons.append(p)
                        polygon_forwards.append(q)
                    return
            elif context.search_strategy.object_footprints:
                for fp in context.search_strategy.object_footprints:
                    p = _placement.get_placement_footprint_polygon(
                        context.search_strategy.start_position,
                        context.search_strategy.start_orientation,
                        context.search_strategy.start_routing_surface, fp)
                    polygons.append(p)
                    polygon_forwards.append(
                        context.search_strategy.start_orientation)
            else:
                nNumPolygons = context.search_strategy.num_polygons
                if nNumPolygons == 0:
                    return
                q = sims4.math.angle_to_yaw_quaternion(0.0)
                for i in range(nNumPolygons):
                    p = context.search_strategy.get_polygon(i)
                    polygons.append(p)
                    polygon_forwards.append(q)
                return
        else:
            return
    elif polygon_forwards is None:
        polygon_forwards = []
        for polygon in polygons:
            polygon_forwards.append(sims4.math.angle_to_yaw_quaternion(0.0))
    polygon_forward_angles = []
    for q in polygon_forwards:
        polygon_forward_angles.append(sims4.math.yaw_quaternion_to_angle(q))
    if context is not None:
        avoid_sims_radius = context.search_strategy.avoid_sim_radius
        zone = services.current_zone()
        quadtree = zone.sim_quadtree
        if context.search_strategy.allow_goals_in_sim_positions:
            query_filter = ItemType.SIM_INTENDED_POSITION
        elif context.search_strategy.allow_goals_in_sim_intended_positions:
            query_filter = ItemType.SIM_POSITION
        else:
            query_filter = (ItemType.SIM_POSITION,
                            ItemType.SIM_INTENDED_POSITION)
    else:
        avoid_sims_radius = PlacementConstants.avoid_sims_radius
        zone = services.current_zone()
        quadtree = zone.sim_quadtree
        query_filter = ItemType.UNKNOWN
    rejected_position = None
    for (pos, ori) in search_generator:
        if pos == rejected_position:
            pass
        if not routing.test_point_placement_in_navmesh(routing_surface, pos):
            rejected_position = pos
        for (polygon, forward_offset_angle) in itertools.product(
                polygons, polygon_forward_angles):
            p = sims4.geometry.Polygon(polygon)
            cur_centroid = p.centroid()
            delta_t = pos - cur_centroid
            p.Translate(delta_t)
            new_angle = sims4.math.yaw_quaternion_to_angle(ori)
            delta_r = new_angle - forward_offset_angle
            p.Rotate(delta_r)
            if not routing.test_polygon_placement_in_navmesh(routing_surface,
                                                             p):
                break
            while quadtree is not None:
                nearby_sims = quadtree.query(
                    bounds=p,
                    level=routing_surface.secondary_id,
                    filter=query_filter,
                    flags=sims4.geometry.ObjectQuadTreeQueryFlag.NONE,
                    additional_radius=avoid_sims_radius)
                if nearby_sims:
                    break
        terrain_instance = services.terrain_service.terrain_object()
        pos.y = terrain_instance.get_routing_surface_height_at(pos.x, pos.z,
                                                               routing_surface)
        return (pos, ori)
 def is_position_routable(routing_surface, position):
     return bool(
         routing.test_point_placement_in_navmesh(
             routing_surface, position))
 def is_location_routable(location):
     return bool(
         routing.test_point_placement_in_navmesh(
             TurboMathUtil.Location.get_location_routing_surface(
                 location),
             TurboMathUtil.Location.get_location_translation(location)))
def find_good_location_with_generator(search_generator,
                                      polygons=None,
                                      polygon_forwards=None,
                                      routing_surface=None,
                                      context=None):
    raise RuntimeError(
        '[bhill] This function is believed to be dead code and is scheduled for pruning. If this exception has been raised, the code is not dead and this exception should be removed.'
    )
    if routing_surface is None:
        if context is not None:
            routing_surface = context.search_strategy.start_routing_surface
        else:
            zone_id = sims4.zone_utils.get_zone_id()
            routing_surface = routing.SurfaceIdentifier(
                zone_id, 0, routing.SURFACETYPE_WORLD)
    if polygons is None:
        polygons = []
        polygon_forwards = []
        if context is not None:
            if context.search_strategy.object_id != 0:
                obj = objects.system.find_object(
                    context.search_strategy.object_id)
                p = obj.footprint_polygon
                if p is not None:
                    polygons.append(p)
                    polygon_forwards.append(obj.orientation)
                elif context.search_strategy.object_footprints:
                    for fp in context.search_strategy.object_footprints:
                        p = _placement.get_placement_footprint_polygon(
                            context.search_strategy.start_position,
                            context.search_strategy.start_orientation,
                            context.search_strategy.start_routing_surface, fp)
                        polygons.append(p)
                        polygon_forwards.append(
                            context.search_strategy.start_orientation)
                else:
                    nNumPolygons = context.search_strategy.num_polygons
                    if nNumPolygons == 0:
                        return
                    q = sims4.math.angle_to_yaw_quaternion(0.0)
                    for i in range(nNumPolygons):
                        p = context.search_strategy.get_polygon(i)
                        polygons.append(p)
                        polygon_forwards.append(q)
                    return
            elif context.search_strategy.object_footprints:
                for fp in context.search_strategy.object_footprints:
                    p = _placement.get_placement_footprint_polygon(
                        context.search_strategy.start_position,
                        context.search_strategy.start_orientation,
                        context.search_strategy.start_routing_surface, fp)
                    polygons.append(p)
                    polygon_forwards.append(
                        context.search_strategy.start_orientation)
            else:
                nNumPolygons = context.search_strategy.num_polygons
                if nNumPolygons == 0:
                    return
                q = sims4.math.angle_to_yaw_quaternion(0.0)
                for i in range(nNumPolygons):
                    p = context.search_strategy.get_polygon(i)
                    polygons.append(p)
                    polygon_forwards.append(q)
                return
        else:
            return
    elif polygon_forwards is None:
        polygon_forwards = []
        for polygon in polygons:
            polygon_forwards.append(sims4.math.angle_to_yaw_quaternion(0.0))
    polygon_forward_angles = []
    for q in polygon_forwards:
        polygon_forward_angles.append(sims4.math.yaw_quaternion_to_angle(q))
    if context is not None:
        avoid_sims_radius = context.search_strategy.avoid_sim_radius
        zone = services.current_zone()
        quadtree = zone.sim_quadtree
        if context.search_strategy.allow_goals_in_sim_positions:
            query_filter = ItemType.SIM_INTENDED_POSITION
        elif context.search_strategy.allow_goals_in_sim_intended_positions:
            query_filter = ItemType.SIM_POSITION
        else:
            query_filter = (ItemType.SIM_POSITION,
                            ItemType.SIM_INTENDED_POSITION)
    else:
        avoid_sims_radius = PlacementConstants.avoid_sims_radius
        zone = services.current_zone()
        quadtree = zone.sim_quadtree
        query_filter = ItemType.UNKNOWN
    rejected_position = None
    for (pos, ori) in search_generator:
        if pos == rejected_position:
            pass
        if not routing.test_point_placement_in_navmesh(routing_surface, pos):
            rejected_position = pos
        for (polygon, forward_offset_angle) in itertools.product(
                polygons, polygon_forward_angles):
            p = sims4.geometry.Polygon(polygon)
            cur_centroid = p.centroid()
            delta_t = pos - cur_centroid
            p.Translate(delta_t)
            new_angle = sims4.math.yaw_quaternion_to_angle(ori)
            delta_r = new_angle - forward_offset_angle
            p.Rotate(delta_r)
            if not routing.test_polygon_placement_in_navmesh(
                    routing_surface, p):
                break
            while quadtree is not None:
                nearby_sims = quadtree.query(
                    bounds=p,
                    level=routing_surface.secondary_id,
                    filter=query_filter,
                    flags=sims4.geometry.ObjectQuadTreeQueryFlag.NONE,
                    additional_radius=avoid_sims_radius)
                if nearby_sims:
                    break
        terrain_instance = services.terrain_service.terrain_object()
        pos.y = terrain_instance.get_routing_surface_height_at(
            pos.x, pos.z, routing_surface)
        return (pos, ori)