def _do_route_gen(timeline):
     location = routing.Location(Vector3(x, y, z),
                                 routing_surface=obj.routing_surface)
     goal = routing.Goal(location)
     routing_context = obj.get_routing_context()
     route = routing.Route(obj.routing_location, (goal, ),
                           routing_context=routing_context)
     plan_primitive = PlanRoute(route, obj)
     result = yield from element_utils.run_child(timeline, plan_primitive)
     if not result:
         return result
         yield
     nodes = plan_primitive.path.nodes
     if not (nodes and nodes.plan_success):
         return False
         yield
     else:
         follow_path_element = FollowPath(obj, plan_primitive.path)
         result = yield from element_utils.run_child(
             timeline, follow_path_element)
         if not result:
             return result
             yield
     return True
     yield
Beispiel #2
0
 def create_goal(self, location, full_cost, tag, group_id):
     return routing.Goal(location,
                         cost=full_cost,
                         tag=tag,
                         group=group_id,
                         requires_los_check=self.los_reference_point
                         is not None,
                         connectivity_handle=self)
Beispiel #3
0
 def _create_constraint_set(self, sim, timeline):
     orient = sims4.math.Quaternion.IDENTITY()
     positions = services.current_zone().lot.corners
     position = positions[0]
     routing_surface = self._privacy.constraint.get_world_routing_surface(
         force_world=True)
     if self._privacy._routing_surface_only:
         routing_surfaces = (routing_surface, )
     else:
         routing_surfaces = self._privacy.constraint.get_all_valid_routing_surfaces(
         )
     goals = []
     center_pos = services.current_zone().lot.position
     for pos in positions:
         plex_service = services.get_plex_service()
         if plex_service.is_active_zone_a_plex():
             towards_center_vec = sims4.math.vector_normalize(center_pos -
                                                              pos)
             pos = pos + towards_center_vec * self.PLEX_LOT_CORNER_ADJUSTMENT
             pos.y = services.terrain_service.terrain_object(
             ).get_routing_surface_height_at(pos.x, pos.z, routing_surface)
         if not sims4.geometry.test_point_in_compound_polygon(
                 pos, self._privacy.constraint.geometry.polygon):
             for surface in routing_surfaces:
                 goals.append(
                     routing.Goal(routing.Location(pos, orient, surface)))
     obj_pos = self._privacy.central_object.position
     for offset in self._privacy.additional_exit_offsets:
         goals.append(
             routing.Goal(
                 routing.Location(obj_pos + Vector3(offset.x, 0, offset.y),
                                  orient, surface)))
     if not goals:
         return Nowhere(
             'BuildAndForceSatisfyShooConstraintInteraction, Could not generate goals to exit a privacy region, Sim: {} Privacy Region: {}',
             sim, self._privacy.constraint.geometry.polygon)
         yield
     route = routing.Route(sim.routing_location,
                           goals,
                           routing_context=sim.routing_context)
     plan_primitive = PlanRoute(route,
                                sim,
                                reserve_final_location=False,
                                interaction=self)
     yield from element_utils.run_child(timeline, plan_primitive)
     max_distance = self._privacy._max_line_of_sight_radius * self._privacy._max_line_of_sight_radius * 4
     nodes = []
     path = plan_primitive.path
     while path is not None:
         nodes.extend(path.nodes)
         path = path.next_path
     if nodes:
         previous_node = nodes[0]
         for node in nodes:
             node_vector = sims4.math.Vector3(node.position[0],
                                              node.position[1],
                                              node.position[2])
             if not sims4.geometry.test_point_in_compound_polygon(
                     node_vector,
                     self._privacy.constraint.geometry.polygon):
                 position = node_vector
                 if node.portal_id != 0:
                     continue
                 circle_constraint = interactions.constraints.Circle(
                     position, self.TRIVIAL_SHOO_RADIUS,
                     node.routing_surface_id)
                 if circle_constraint.intersect(
                         self._privacy.constraint).valid:
                     continue
                 break
             previous_node = node
         position2 = sims4.math.Vector3(previous_node.position[0],
                                        previous_node.position[1],
                                        previous_node.position[2])
         if (position - position2).magnitude_2d_squared() > max_distance:
             position = self._find_close_position(position, position2)
     elif (position - sim.position).magnitude_2d_squared() > max_distance:
         position = self._find_close_position(position, sim.position)
     p1 = position
     p2 = self._privacy.central_object.position
     forward = sims4.math.vector_normalize(p1 - p2)
     radius_min = 0
     radius_max = self._privacy.shoo_constraint_radius
     angle = sims4.math.PI
     (cone_geometry,
      cost_functions) = build_weighted_cone(position,
                                            forward,
                                            radius_min,
                                            radius_max,
                                            angle,
                                            ideal_radius_min=0,
                                            ideal_radius_max=0,
                                            ideal_angle=1)
     subtracted_cone_polygon_list = []
     for cone_polygon in cone_geometry.polygon:
         for privacy_polygon in self._privacy.constraint.geometry.polygon:
             subtracted_cone_polygons = cone_polygon.subtract(
                 privacy_polygon)
             if subtracted_cone_polygons:
                 subtracted_cone_polygon_list.extend(
                     subtracted_cone_polygons)
     compound_subtracted_cone_polygon = sims4.geometry.CompoundPolygon(
         subtracted_cone_polygon_list)
     subtracted_cone_geometry = sims4.geometry.RestrictedPolygon(
         compound_subtracted_cone_polygon, [])
     subtracted_cone_constraint = Constraint(
         geometry=subtracted_cone_geometry,
         scoring_functions=cost_functions,
         routing_surface=routing_surface,
         debug_name='ShooedSimsCone',
         multi_surface=True,
         los_reference_point=position)
     point_cost = 5
     point_constraint = interactions.constraints.Position(
         position, routing_surface=routing_surface, multi_surface=True)
     point_constraint = point_constraint.generate_constraint_with_cost(
         point_cost)
     constraints = (subtracted_cone_constraint, point_constraint)
     return interactions.constraints.create_constraint_set(
         constraints, debug_name='ShooPositions')
     yield
def get_route_to_position_goals(position, routing_surface, orientation=None):
    goal_location = routing.Location(position, orientation, routing_surface)
    return [routing.Goal(goal_location)]
 def _create_constraint_set(self, sim, timeline):
     orient = sims4.math.Quaternion.IDENTITY()
     positions = services.current_zone().lot.corners
     position = positions[0]
     goals = []
     for pos in positions:
         while not sims4.geometry.test_point_in_compound_polygon(
                 pos, self._privacy.constraint.geometry.polygon):
             goals.append(
                 routing.Goal(
                     routing.Location(pos, orient, sim.routing_surface)))
     if not goals:
         return Nowhere()
     route = routing.Route(sim.routing_location,
                           goals,
                           routing_context=sim.routing_context)
     plan_primitive = PlanRoute(route, sim, reserve_final_location=False)
     yield element_utils.run_child(timeline, plan_primitive)
     max_distance = self._privacy._max_line_of_sight_radius * self._privacy._max_line_of_sight_radius * 4
     nodes = plan_primitive.path.nodes
     if nodes:
         previous_node = nodes[0]
         for node in nodes:
             node_vector = sims4.math.Vector3(node.position[0],
                                              node.position[1],
                                              node.position[2])
             if not sims4.geometry.test_point_in_compound_polygon(
                     node_vector,
                     self._privacy.constraint.geometry.polygon):
                 position = node_vector
                 if node.portal_id != 0:
                     pass
                 circle_constraint = interactions.constraints.Circle(
                     position, self.TRIVIAL_SHOO_RADIUS,
                     node.routing_surface_id)
                 if circle_constraint.intersect(
                         self._privacy.constraint).valid:
                     pass
                 break
             previous_node = node
         position2 = sims4.math.Vector3(previous_node.position[0],
                                        previous_node.position[1],
                                        previous_node.position[2])
         if (position - position2).magnitude_2d_squared() > max_distance:
             position = self._find_close_position(position, position2)
     elif (position - sim.position).magnitude_2d_squared() > max_distance:
         position = self._find_close_position(position, sim.position)
     p1 = position
     p2 = self._privacy.central_object.position
     forward = sims4.math.vector_normalize(p1 - p2)
     radius_min = 0
     radius_max = self._privacy._SHOO_CONSTRAINT_RADIUS
     angle = sims4.math.PI
     (cone_geometry,
      scoring_functions) = build_weighted_cone(position,
                                               forward,
                                               radius_min,
                                               radius_max,
                                               angle,
                                               ideal_radius_min=0,
                                               ideal_radius_max=0,
                                               ideal_angle=1)
     subtracted_cone_polygon_list = []
     for cone_polygon in cone_geometry.polygon:
         for privacy_polygon in self._privacy.constraint.geometry.polygon:
             subtracted_cone_polygons = cone_polygon.subtract(
                 privacy_polygon)
             while subtracted_cone_polygons:
                 subtracted_cone_polygon_list.extend(
                     subtracted_cone_polygons)
     compound_subtracted_cone_polygon = sims4.geometry.CompoundPolygon(
         subtracted_cone_polygon_list)
     subtracted_cone_geometry = sims4.geometry.RestrictedPolygon(
         compound_subtracted_cone_polygon, [])
     subtracted_cone_constraint = Constraint(
         geometry=subtracted_cone_geometry,
         scoring_functions=scoring_functions,
         routing_surface=sim.routing_surface,
         debug_name='ShooedSimsCone',
         los_reference_point=position)
     point_cost = 5
     point_constraint = interactions.constraints.Position(
         position, routing_surface=sim.routing_surface)
     point_constraint = point_constraint.generate_constraint_with_cost(
         point_cost)
     constraints = (subtracted_cone_constraint, point_constraint)
     return interactions.constraints.create_constraint_set(
         constraints, debug_name='ShooPositions')
def routing_debug_waypoints(*waypoint_data, _connection=None):
    obj = get_optional_target(None, _connection=_connection)
    if obj is None:
        return False
    routing_component = obj.get_component(ROUTING_COMPONENT)
    if routing_component is None:
        return False
    object_manager = services.object_manager()
    waypoints = []
    for (is_float, data_points) in itertools.groupby(waypoint_data,
                                                     lambda d: '.' in d):
        while True:
            try:
                if is_float:
                    position = Vector3(float(next(data_points)),
                                       float(next(data_points)),
                                       float(next(data_points)))
                    routing_surface = routing.SurfaceIdentifier(
                        services.current_zone_id(), 0,
                        routing.SurfaceType.SURFACETYPE_WORLD)
                    location = routing.Location(
                        position, routing_surface=routing_surface)
                else:
                    o = object_manager.get(int(next(data_points)))
                    if o is None:
                        continue
                    routing_surface = o.provided_routing_surface
                    if routing_surface is None:
                        continue
                    location = routing.Location(
                        o.position, routing_surface=routing_surface)
                waypoints.append((routing.Goal(location), ))
            except StopIteration:
                break

    def _do_route_gen(timeline):
        routing_context = obj.get_routing_context()
        route = routing.Route(obj.routing_location,
                              waypoints[-1],
                              waypoints=waypoints[:-1],
                              routing_context=routing_context)
        plan_primitive = PlanRoute(route, obj)
        result = yield from element_utils.run_child(timeline, plan_primitive)
        if not result:
            return result
            yield
        nodes = plan_primitive.path.nodes
        if not (nodes and nodes.plan_success):
            return False
            yield
        else:
            follow_path_element = FollowPath(obj, plan_primitive.path)
            result = yield from element_utils.run_child(
                timeline, follow_path_element)
            if not result:
                return result
                yield
        return True
        yield

    timeline = services.time_service().sim_timeline
    timeline.schedule(GeneratorElement(_do_route_gen))
    return True