Esempio n. 1
0
 def _apply_altitude(self, v, altitude, routing_surface=None):
     if altitude is None or altitude is KEEP_ALTITUDE:
         return v
     final_surface = routing_surface if routing_surface is not None else self.routing_surface
     if final_surface:
         level = final_surface.secondary_id
     else:
         level = 0
     zone_id = services.current_zone_id()
     world_surface = routing.SurfaceIdentifier(
         zone_id, level, routing.SurfaceType.SURFACETYPE_WORLD)
     water_surface = routing.SurfaceIdentifier(
         zone_id, level, routing.SurfaceType.SURFACETYPE_POOL)
     object_surface = routing.SurfaceIdentifier(
         zone_id, level, routing.SurfaceType.SURFACETYPE_OBJECT)
     world_height = get_terrain_height(v.x,
                                       v.z,
                                       routing_surface=world_surface)
     water_height = get_terrain_height(v.x,
                                       v.z,
                                       routing_surface=water_surface)
     object_height = get_terrain_height(v.x,
                                        v.z,
                                        routing_surface=object_surface)
     h = max(world_height, water_height, object_height)
     if h == routing_constants.INVALID_TERRAIN_HEIGHT:
         h = get_terrain_center().y
     return sims4.math.Vector3(v.x, h + altitude, v.z)
 def _on_quadtree_changed(self):
     quadtree = services.sim_quadtree()
     if quadtree is None:
         return
     zone = services.current_zone()
     pos = sims4.math.Vector2(0, 0)
     bounds = sims4.geometry.QtCircle(pos, 10000)
     all_sims_positions = quadtree.query(
         bounds=bounds,
         level=self.ALL_LEVELS,
         filter=placement.ItemType.SIM_POSITION,
         flags=sims4.geometry.ObjectQuadTreeQueryFlag.IGNORE_LEVEL)
     all_intended = quadtree.query(
         bounds=bounds,
         level=self.ALL_LEVELS,
         filter=placement.ItemType.SIM_INTENDED_POSITION,
         flags=sims4.geometry.ObjectQuadTreeQueryFlag.IGNORE_LEVEL)
     all_suppressors = quadtree.query(
         bounds=bounds,
         level=self.ALL_LEVELS,
         filter=placement.ItemType.ROUTE_GOAL_SUPPRESSOR,
         flags=sims4.geometry.ObjectQuadTreeQueryFlag.IGNORE_LEVEL)
     with Context(self.layer) as layer:
         layer.set_color(Color.GREEN)
         for o in all_sims_positions:
             height = terrain.get_lot_level_height(
                 o[2].center.x, o[2].center.y, o[3], zone.id) + 0.1
             pos = sims4.math.Vector3(o[2].center.x, height, o[2].center.y)
             layer.add_circle(pos, o[2].radius, altitude=KEEP_ALTITUDE)
         layer.set_color(Color.YELLOW)
         for o in all_intended:
             if isinstance(o[2], Polygon):
                 routing_surface = routing.SurfaceIdentifier(
                     zone.id, o[3], routing.SURFACETYPE_WORLD)
                 layer.add_polygon(o[2],
                                   altitude=0.1,
                                   routing_surface=routing_surface)
             else:
                 height = terrain.get_lot_level_height(
                     o[2].center.x, o[2].center.y, o[3], zone.id) + 0.1
                 pos = sims4.math.Vector3(o[2].center.x, height,
                                          o[2].center.y)
                 layer.add_circle(pos, o[2].radius, altitude=KEEP_ALTITUDE)
         layer.set_color(Color.RED)
         for o in all_suppressors:
             if isinstance(o[2], Polygon):
                 routing_surface = routing.SurfaceIdentifier(
                     zone.id, o[3], routing.SURFACETYPE_WORLD)
                 layer.add_polygon(o[2],
                                   altitude=0.1,
                                   routing_surface=routing_surface)
             else:
                 height = terrain.get_lot_level_height(
                     o[2].center.x, o[2].center.y, o[3], zone.id) + 0.1
                 pos = sims4.math.Vector3(o[2].center.x, height,
                                          o[2].center.y)
                 layer.add_circle(pos, o[2].radius, altitude=KEEP_ALTITUDE)
 def _get_ladder_portal_locations(self, obj):
     additional_portal_flags = self._get_additional_portal_location_flags()
     blocked_alignment_flags = routing.get_blocked_ladder_portals(
         obj.id, obj.zone_id)
     if blocked_alignment_flags & PortalAlignment.get_bit_flag(
             self.portal_alignment):
         return [(None, None, None, None, PortalFlags.DEFAULT)]
     (top_level, bottom_level,
      _) = routing.get_ladder_levels_and_height(obj.id, obj.zone_id)
     down_start = self.climb_down_locations.location_start(
         obj, override_level=top_level)
     down_end = self.climb_down_locations.location_end(
         obj, override_level=bottom_level)
     down_start_position = down_start.position
     down_start_routing_surface = routing.SurfaceIdentifier(
         obj.zone_id, top_level, down_start.routing_surface.type)
     down_end_routing_surface = routing.SurfaceIdentifier(
         obj.zone_id, bottom_level, down_end.routing_surface.type)
     if self.climb_up_locations is not None:
         up_start = self.climb_up_locations.location_start(
             obj, override_level=bottom_level)
         up_end = self.climb_up_locations.location_end(
             obj, override_level=top_level)
         up_end_position = up_end.position
         up_start_routing_surface = routing.SurfaceIdentifier(
             obj.zone_id, bottom_level, up_start.routing_surface.type)
         up_end_routing_surface = routing.SurfaceIdentifier(
             obj.zone_id, top_level, up_end.routing_surface.type)
         locations = [(Location(up_start.position,
                                orientation=up_start.orientation,
                                routing_surface=up_start_routing_surface),
                       Location(up_end_position,
                                orientation=up_end.orientation,
                                routing_surface=up_end_routing_surface),
                       Location(down_start_position,
                                orientation=down_start.orientation,
                                routing_surface=down_start_routing_surface),
                       Location(down_end.position,
                                orientation=down_end.orientation,
                                routing_surface=down_end_routing_surface),
                       additional_portal_flags)]
     else:
         locations = [(Location(down_start_position,
                                orientation=down_start.orientation,
                                routing_surface=down_start_routing_surface),
                       Location(down_end.position,
                                orientation=down_end.orientation,
                                routing_surface=down_end_routing_surface),
                       None, None, additional_portal_flags)]
     return locations
Esempio n. 4
0
 def _create_automatic_objects(self, venue_tuning):
     zone = services.current_zone()
     for tag_pair in venue_tuning.automatic_objects:
         try:
             existing_objects = set(
                 zone.object_manager.get_objects_with_tag_gen(tag_pair.tag))
             while not existing_objects:
                 obj = create_object(tag_pair.default_value)
                 position = zone.lot.corners[1]
                 position += vector_normalize(zone.lot.position - position)
                 fgl_context = FindGoodLocationContext(
                     starting_position=position,
                     object_id=obj.id,
                     ignored_object_ids=(obj.id, ),
                     search_flags=placement.FGLSearchFlagsDefault
                     | placement.FGLSearchFlag.SHOULD_TEST_BUILDBUY,
                     object_footprints=(obj.get_footprint(), ))
                 (position, orientation) = find_good_location(fgl_context)
                 if position is not None:
                     obj.location = sims4.math.Location(
                         sims4.math.Transform(position, orientation),
                         routing.SurfaceIdentifier(
                             zone.id, 0, routing.SURFACETYPE_WORLD))
                 else:
                     obj.destroy(
                         source=zone,
                         cause=
                         'Failed to place automatic object required by venue.'
                     )
         except:
             logger.error(
                 'Automatic object {} could not be created in venue {} (zone: {}).',
                 obj_definition, venue_tuning, zone)
Esempio n. 5
0
def create_starting_location(position=None,
                             orientation=None,
                             transform=None,
                             routing_surface=None,
                             location=None):
    starting_routing_location = None
    if location is None:
        if routing_surface is None:
            zone_id = services.current_zone_id()
            routing_surface = routing.SurfaceIdentifier(
                zone_id, 0, routing.SurfaceType.SURFACETYPE_WORLD)
        if transform is None:
            if position is None:
                logger.error(
                    'Trying to create a starting location for a FindGoodLocationContext but position is None. If position is going to remain None then either location or transform need to be passed in instead. -trevor'
                )
            if orientation is None:
                orientation = sims4.math.angle_to_yaw_quaternion(0.0)
            starting_routing_location = routing.Location(
                position, orientation, routing_surface)
        else:
            starting_routing_location = routing.Location(
                transform.translation, transform.orientation, routing_surface)
    else:
        starting_routing_location = routing.Location(
            location.transform.translation, location.transform.orientation,
            location.routing_surface or location.world_routing_surface)
    return starting_routing_location
def test_placement(obj_id,
                   x,
                   y,
                   z,
                   rotation,
                   level,
                   parent_obj_id,
                   parent_slot_hash,
                   _connection=None):
    output = sims4.commands.Output(_connection)
    obj = objects.system.find_object(obj_id)
    if obj is None:
        output('Invalid object id')
        return False
    zone_id = sims4.zone_utils.get_zone_id()
    surface = routing.SurfaceIdentifier(zone_id, level,
                                        routing.SURFACETYPE_WORLD)
    position = sims4.math.Vector3(x, y, z)
    orientation = sims4.math.angle_to_yaw_quaternion(rotation)
    parent_obj = objects.system.find_object(parent_obj_id)
    transform = Transform(position, orientation)
    location = Location(transform, surface, parent_obj, parent_slot_hash,
                        parent_slot_hash)
    (result, errors) = test_location_for_object(obj, location=location)
    if result:
        output('Placement is legal')
    else:
        output('Placement is NOT legal')
    if errors:
        for (code, msg) in errors:
            output('  {} ({})'.format(msg, code))
    return result
    def send_to_position(sim_info: SimInfo, location_position: Vector3,
                         level: int) -> Union[EnqueueResult, None]:
        """send_to_position(sim_info, location_position, level)

        Send a Sim to the specified location.

        :param sim_info: The Sim to send.
        :type sim_info: SimInfo
        :param location_position: The position to send the sim to.
        :type location_position: Vector3
        :param level: The level at which the position is.
        :type level: int
        :return: The result of sending the Sim to the specified location or None if they could not go there.
        :rtype: EnqueueResult
        """
        from server_commands.sim_commands import _build_terrain_interaction_target_and_context, CommandTuning
        if location_position is None:
            return None
        sim = CommonSimUtils.get_sim_instance(sim_info)
        # noinspection PyUnresolvedReferences
        pos = sims4.math.Vector3(location_position.x, location_position.y,
                                 location_position.z)
        routing_surface = routing.SurfaceIdentifier(
            CommonLocationUtils.get_current_zone_id(), level,
            routing.SurfaceType.SURFACETYPE_WORLD)
        (target, context) = _build_terrain_interaction_target_and_context(
            sim, pos, routing_surface, PickType.PICK_TERRAIN,
            objects.terrain.TerrainPoint)
        return sim.push_super_affordance(
            CommandTuning.TERRAIN_GOHERE_AFFORDANCE, target, context)
Esempio n. 8
0
 def __init__(self, definition, **kwargs):
     self._ui_metadata_stack = []
     self._ui_metadata_handles = {}
     self._ui_metadata_cache = {}
     super().__init__(definition, **kwargs)
     if definition is not None:
         self.apply_definition(definition, **kwargs)
     self.primitives = distributor.ops.DistributionSet(self)
     self._location = sims4.math.Location(
         sims4.math.Transform(),
         routing.SurfaceIdentifier(sims4.zone_utils.get_zone_id(), 0,
                                   routing.SURFACETYPE_WORLD))
     self._children = WeakSet()
     self._occupied_slot_dict = {}
     self._scale = 1
     self._parent_type = ObjectParentType.PARENT_NONE
     self._parent_location = 0
     self._build_buy_lockout = False
     self._build_buy_lockout_alarm_handler = None
     self._tint = None
     self._opacity = None
     self._censor_state = None
     self._geometry_state = None
     self._visibility = None
     self._material_state = None
     self._reference_arb = None
     self._audio_effects = {}
     self._video_playlist = None
     self._painting_state = None
     self._current_value = definition.price
     self._needs_post_bb_fixup = False
     self._needs_depreciation = False
     self._fade_out_alarm_handle = None
Esempio n. 9
0
 def validate_spawn_points(self):
     if not self._spawner_data and not self._dynamic_spawn_points:
         return
     dest_handles = set()
     lot_center = self.lot.center
     lot_corners = self.lot.corners
     routing_surface = routing.SurfaceIdentifier(self.id, 0,
                                                 routing.SURFACETYPE_WORLD)
     for corner in lot_corners:
         diff = lot_center - corner
         if diff.magnitude_squared() != 0:
             towards_center_vec = sims4.math.vector_normalize(lot_center -
                                                              corner) * 0.1
         else:
             towards_center_vec = sims4.math.Vector3.ZERO()
         new_corner = corner + towards_center_vec
         location = routing.Location(
             new_corner, sims4.math.Quaternion.IDENTITY(), routing_surface)
         dest_handles.add(routing.connectivity.Handle(location))
     for spawn_point in self.spawn_points_gen():
         spawn_point.reset_valid_slots()
         routing_context = routing.PathPlanContext()
         routing_context.set_key_mask(routing.FOOTPRINT_KEY_ON_LOT |
                                      routing.FOOTPRINT_KEY_OFF_LOT)
         if spawn_point.footprint_id is not None:
             routing_context.ignore_footprint_contour(
                 spawn_point.footprint_id)
         spawn_point.validate_slots(dest_handles, routing_context)
Esempio n. 10
0
 def get_center_of_mass_constraint(self):
     if not self:
         logger.warn('No Sims in ensemble when trying to construct constraint.')
         return ANYWHERE
     (level, position) = self.calculate_level_and_center_of_mass()
     routing_surface = routing.SurfaceIdentifier(services.current_zone_id(), level, routing.SurfaceType.SURFACETYPE_WORLD)
     return Circle(position, sqrt(self.max_ensemble_radius), routing_surface)
Esempio n. 11
0
 def routing_location(self):
     lot = services.active_lot()
     return routing.Location(lot.position,
                             orientation=lot.orientation,
                             routing_surface=routing.SurfaceIdentifier(
                                 services.current_zone().id, 0,
                                 routing.SurfaceType.SURFACETYPE_WORLD))
 def _create_floor_feature_constraint_set(cls, inst, sim):
     inst_or_cls = inst if inst is not None else cls
     floor_feature_contraints = []
     floor_features_and_surfaces = []
     zone_id = services.current_zone_id()
     floor_features = build_buy.list_floor_features(inst_or_cls.terrain_feature)
     if floor_features is None:
         return Nowhere('No found floor features.')
     radius_object = None
     if inst_or_cls.radius_filter is not None:
         radius_object = inst_or_cls.get_participant(inst_or_cls.radius_filter.radius_actor)
     if inst_or_cls.radius_filter is not None and radius_object is None:
         return Nowhere('Radius filter is enabled but the radius actor has a None value.')
     for floor_feature in floor_features:
         if inst_or_cls.indoors_only and build_buy.is_location_natural_ground(floor_feature[0], floor_feature[1]):
             continue
         routing_surface = routing.SurfaceIdentifier(zone_id, floor_feature[1], routing.SurfaceType.SURFACETYPE_WORLD)
         floor_feature_location = floor_feature[0]
         if inst_or_cls.radius_filter is not None:
             if (radius_object.position - floor_feature_location).magnitude_squared() <= inst_or_cls.radius_filter.radius:
                 floor_features_and_surfaces.append((floor_feature_location, routing_surface))
                 floor_features_and_surfaces.append((floor_feature_location, routing_surface))
         else:
             floor_features_and_surfaces.append((floor_feature_location, routing_surface))
     if floor_features_and_surfaces:
         for floor_feature_and_surface in floor_features_and_surfaces:
             circle_constraint = inst_or_cls.routing_circle_constraint.create_constraint(sim, None, target_position=floor_feature_and_surface[0], routing_surface=floor_feature_and_surface[1])
             facing_constraint = inst_or_cls.routing_facing_constraint.create_constraint(sim, None, target_position=floor_feature_and_surface[0], routing_surface=floor_feature_and_surface[1])
             constraint = circle_constraint.intersect(facing_constraint)
             floor_feature_contraints.append(constraint)
         return create_constraint_set(floor_feature_contraints)
     return Nowhere('With radius filter enabled, no found floor features are within range.')
Esempio n. 13
0
 def provided_routing_surface(self):
     if self._provided_surface is UNSET:
         self._provided_surface = None
         if self.routing_surface is not None:
             if self.has_component(FOOTPRINT_COMPONENT):
                 if placement.has_object_surface_footprint(self.get_footprint()):
                     self._provided_surface = routing.SurfaceIdentifier(services.current_zone_id(), self.routing_surface.secondary_id, routing.SurfaceType.SURFACETYPE_OBJECT)
     return self._provided_surface
Esempio n. 14
0
def routing_debug_generate_routing_goals_from_geometry(
        *args, obj: OptionalTargetParam = None, _connection=None):
    output = sims4.commands.Output(_connection)
    obj = get_optional_target(obj, _connection=_connection)
    if obj is None:
        return False
    routing_component = obj.get_component(ROUTING_COMPONENT)
    if routing_component is None:
        return False
    total_string = ''.join(args)
    polygon_strs = find_substring_in_repr(total_string, POLYGON_STR,
                                          POLYGON_END_PARAM)
    if not polygon_strs:
        output('No valid polygons. must start with {} and end with {}'.format(
            POLYGON_STR, POLYGON_END_PARAM))
        return
    constraints = []
    routing_surface = routing.SurfaceIdentifier(
        services.current_zone_id(), 0, routing.SurfaceType.SURFACETYPE_OBJECT)
    for poly_str in polygon_strs:
        point_list = extract_floats(poly_str)
        if not point_list or len(point_list) % 2 != 0:
            output('Point list is not valid length. Too few or one too many.')
            return
        vertices = []
        for index in range(0, len(point_list), 2):
            vertices.append(
                sims4.math.Vector3(point_list[index], 0.0,
                                   point_list[index + 1]))
        polygon = sims4.geometry.Polygon(vertices)
        geometry = RestrictedPolygon(polygon, [])
        constraints.append(
            Constraint(geometry=geometry, routing_surface=routing_surface))
    constraint_set = create_constraint_set(constraints)
    if not postures.posture_graph.enable_debug_goals_visualization:
        sims4.commands.execute('debugvis.goals.enable', _connection)
    handles = constraint_set.get_connectivity_handles(obj)
    handles_str = 'Handles: {}'.format(len(handles))
    sims4.commands.output(handles_str, _connection)
    all_goals = []
    for handle in handles:
        goal_list = handle.get_goals()
        goals_str = '\tGoals: {}'.format(len(goal_list))
        sims4.commands.output(goals_str, _connection)
        all_goals.extend(goal_list)
    if postures.posture_graph.enable_debug_goals_visualization:
        for constraint in constraints:
            with debugvis.Context(
                    'goal_scoring',
                    routing_surface=constraint.routing_surface) as layer:
                for polygon in constraint.geometry.polygon:
                    layer.add_polygon(
                        polygon, routing_surface=constraint.routing_surface)
                for goal in all_goals:
                    position = goal.location.transform.translation
                    layer.add_point(position,
                                    routing_surface=constraint.routing_surface)
Esempio n. 15
0
def has_choices(target_id:int=None, pick_type=PickType.PICK_TERRAIN, x:float=0.0, y:float=0.0, z:float=0.0, lot_id:int=0, level:int=0, control:int=0, alt:int=0, shift:int=0, reference_id:int=0, _connection=None):
    if target_id is None:
        return
    zone = services.current_zone()
    client = zone.client_manager.get(_connection)
    if client is None:
        return
    sim = _active_sim(client)
    shift_held = bool(shift)
    if shift_held:
        if client.household.cheats_enabled or __debug__:
            _send_interactable_message(client, target_id, True)
        else:
            _send_interactable_message(client, target_id, False)
        return
    context = None
    pick_type = int(pick_type)
    pick_pos = sims4.math.Vector3(x, y, z)
    routing_surface = routing.SurfaceIdentifier(zone.id, level, routing.SURFACETYPE_WORLD)
    target = zone.find_object(target_id)
    if pick_type in PICK_USE_TERRAIN_OBJECT or lot_id and lot_id != services.active_lot().lot_id:
        location = sims4.math.Location(sims4.math.Transform(pick_pos), routing_surface)
        target = objects.terrain.TerrainPoint(location)
    elif pick_type == PickType.PICK_SIM and target is None:
        target = sim
    elif pick_type == PickType.PICK_OBJECT and target is not None and target.object_routing_surface is not None:
        pick_type = int(pick_type)
        routing_surface = target.object_routing_surface
        location = sims4.math.Location(sims4.math.Transform(pick_pos), routing_surface)
        target = objects.terrain.TerrainPoint(location)
    is_interactable = False
    if target is not None:
        pick = PickInfo(pick_type, target, pick_pos, routing_surface, lot_id, bool(alt), bool(control))
        context = client.create_interaction_context(sim, pick=pick)
        for aop in target.potential_interactions(context):
            result = ChoiceMenu.is_valid_aop(aop, context, False, user_pick_target=target)
            if not result and not result.tooltip:
                pass
            is_interactable = aop.affordance.allow_user_directed
            if not is_interactable:
                is_interactable = aop.affordance.has_pie_menu_sub_interactions(aop.target, context, **aop.interaction_parameters)
            while is_interactable:
                break
        if not is_interactable and sim is not None:
            while True:
                for si in sim.si_state:
                    potential_targets = si.get_potential_mixer_targets()
                    while True:
                        for potential_target in potential_targets:
                            if target is potential_target:
                                break
                            while potential_target.is_part and potential_target.part_owner is target:
                                break
                    while autonomy.content_sets.any_content_set_available(sim, si.super_affordance, si, context, potential_targets=(target,), include_failed_aops_with_tooltip=True):
                        is_interactable = True
                        break
    _send_interactable_message(client, target_id, is_interactable, True)
Esempio n. 16
0
 def __init__(self, lot_id, zone_id, spawn_point_id=None, routing_surface=None):
     self.lot_id = lot_id
     if routing_surface is None:
         routing_surface = routing.SurfaceIdentifier(zone_id, 0, routing.SurfaceType.SURFACETYPE_WORLD)
     self._routing_surface = routing_surface
     if spawn_point_id is None:
         self._spawn_point_id = id_generator.generate_object_id()
     else:
         self._spawn_point_id = spawn_point_id
     self.attractor_point_ids = set()
Esempio n. 17
0
 def __init__(self, lot_id, zone_id, routing_surface=None):
     self.center = None
     self.lot_id = lot_id
     self._tags = set()
     if routing_surface is None:
         routing_surface = routing.SurfaceIdentifier(
             zone_id, 0, routing.SURFACETYPE_WORLD)
     self._routing_surface = routing_surface
     self._valid_slots = 0
     self._on_spawn_points_changed = CallableList()
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     if self._target is None:
         self._start_constraint = Nowhere(
             'No target for _WaypointGeneratorPacing')
         self._los_reference_point = None
         return
     self._los_reference_point = self._target.position
     if self._target.is_terrain:
         self._los_reference_point = None
     water_constraint = self.get_water_constraint(
         self.constraint_parameters.min_water_depth,
         self.constraint_parameters.max_water_depth)
     if self.outside_only:
         self._routing_surface = routing.SurfaceIdentifier(
             services.current_zone_id(), 0,
             routing.SurfaceType.SURFACETYPE_WORLD)
         starting_location = Location(position=self._target.position,
                                      routing_surface=self._routing_surface)
         search_flags = FGLSearchFlagsDefaultForSim | FGLSearchFlag.STAY_OUTSIDE
         fgl_context = placement.FindGoodLocationContext(
             starting_location,
             routing_context=self._context.sim.routing_context,
             additional_avoid_sim_radius=routing.get_default_agent_radius(),
             max_results=1,
             max_steps=10,
             search_flags=search_flags,
             min_water_depth=water_constraint.get_min_water_depth(),
             max_water_depth=water_constraint.get_max_water_depth())
         (trans, _) = placement.find_good_location(fgl_context)
         if trans is not None:
             geometry = sims4.geometry.RestrictedPolygon(
                 sims4.geometry.CompoundPolygon(
                     sims4.geometry.Polygon((trans, ))), ())
             self._start_constraint = SmallAreaConstraint(
                 geometry=geometry,
                 debug_name='WaypointPacingStartingConstraint',
                 routing_surface=self._routing_surface,
                 min_water_depth=water_constraint.get_min_water_depth(),
                 max_water_depth=water_constraint.get_max_water_depth())
         else:
             self._start_constraint = Nowhere(
                 'WaypointGeneratorPacing requires outside, but we failed to find a good location.'
             )
     else:
         self._start_constraint = Circle(
             self._target.position,
             self.constraint_parameters.object_constraint_radius,
             routing_surface=self._routing_surface,
             los_reference_point=self._los_reference_point,
             min_water_depth=water_constraint.get_min_water_depth(),
             max_water_depth=water_constraint.get_max_water_depth())
Esempio n. 19
0
 def snap_to_good_location_on_floor(target,
                                    *args,
                                    starting_transform=None,
                                    starting_routing_surface=None,
                                    **kwargs):
     target.visibility = VisibilityState(True, True, True)
     parent = target.get_parenting_root()
     if starting_transform is None:
         starting_transform = parent.transform
         starting_transform = sims4.math.Transform(
             parent.position + parent.forward * parent.object_radius,
             starting_transform.orientation)
     if starting_routing_surface is None:
         starting_routing_surface = parent.routing_surface
     translation = None
     orientation = None
     is_lot_clearing = services.current_zone().is_active_lot_clearing
     if not is_lot_clearing:
         (translation,
          orientation) = CarryingObject.get_good_location_on_floor(
              target,
              *args,
              starting_transform=starting_transform,
              starting_routing_surface=starting_routing_surface,
              **kwargs)
     if translation is not None:
         target.clear_parent(sims4.math.Transform(translation, orientation),
                             starting_routing_surface)
         return True
     logger.debug(
         'snap_to_good_location_on_floor could not find good location for {}.',
         target)
     clear_transform = starting_transform
     clear_routing_surface = starting_routing_surface
     if not (is_lot_clearing or not build_buy.has_floor_at_location(
             starting_transform.translation,
             starting_routing_surface.secondary_id)):
         clear_routing_surface = routing.SurfaceIdentifier(
             services.current_zone_id(), 0,
             routing.SurfaceType.SURFACETYPE_WORLD)
         ground_position = sims4.math.Vector3(
             starting_transform.translation.x,
             starting_transform.translation.y,
             starting_transform.translation.z)
         ground_position.y = services.terrain_service.terrain_object(
         ).get_routing_surface_height_at(starting_transform.translation.x,
                                         starting_transform.translation.z,
                                         clear_routing_surface)
         clear_transform = sims4.math.Transform(
             ground_position, starting_transform.orientation)
     target.clear_parent(clear_transform, clear_routing_surface)
     return False
Esempio n. 20
0
def create_object(def_id,
                  x: float = 0.0,
                  y: float = 0.0,
                  z: float = 0.0,
                  level: int = 0,
                  _connection=None):
    obj = objects.system.create_object(def_id)
    if obj is not None:
        routing_surface = routing.SurfaceIdentifier(
            sims4.zone_utils.get_zone_id(), level, routing.SURFACETYPE_WORLD)
        obj.move_to(translation=sims4.math.Vector3(x, y, z),
                    routing_surface=routing_surface)
    return obj
Esempio n. 21
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     sim = self._context.sim
     self._routing_surface = routing.SurfaceIdentifier(
         self._routing_surface.primary_id,
         self._routing_surface.secondary_id,
         routing.SurfaceType.SURFACETYPE_POOL)
     position = self._target.position if self._target is not None else sim.position
     level = self._routing_surface.secondary_id
     self._start_constraint = None
     self._master_depth_constraint = None
     self._waypoint_constraints = []
     self.keep_away_constraint = None
     self._location_is_pool = build_buy.is_location_pool(position, level)
     if self._location_is_pool:
         pool_block_id = build_buy.get_block_id(sim.zone_id, position,
                                                level - 1)
         pool = pool_utils.get_pool_by_block_id(pool_block_id)
         if pool is not None:
             pool_edge_constraints = pool.get_edge_constraint(
                 constraint_width=self.constraint_width,
                 inward_dir=True,
                 return_constraint_list=True)
             pool_edge_constraints = [
                 constraint.generate_geometry_only_constraint()
                 for constraint in pool_edge_constraints
             ]
             if self.keep_away_from_edges is not None:
                 bb_polys = build_buy.get_pool_polys(
                     pool_block_id, level - 1)
                 if len(bb_polys) > 0:
                     bb_poly = bb_polys[0]
                     _WaypointGeneratorPool._push_poly_inward(
                         bb_poly, self.keep_away_from_edges)
                     bb_poly.reverse()
                     keep_away_geom = sims4.geometry.RestrictedPolygon(
                         sims4.geometry.Polygon(bb_poly), ())
                     self.keep_away_constraint = Constraint(
                         routing_surface=pool.provided_routing_surface,
                         geometry=keep_away_geom)
                 else:
                     logger.error(
                         f'Pool Waypoint Generator: Pool polygon data unexpectedly empty while ${sim} was routing on a pool with id ${pool_block_id}.',
                         owner='jmorrow')
                 for i in range(len(pool_edge_constraints)):
                     pool_edge_constraints[i] = pool_edge_constraints[
                         i].intersect(self.keep_away_constraint)
             self._start_constraint = create_constraint_set(
                 pool_edge_constraints)
             self._waypoint_constraints = pool_edge_constraints
Esempio n. 22
0
def create_multiple_objects(number, *obj_ids, _connection=None):
    manager = services.object_manager()
    sim = get_optional_target(None, _connection)
    search_flags = placement.FGLSearchFlagsDefault | placement.FGLSearchFlag.SHOULD_TEST_BUILDBUY
    if sim is not None:
        starting_position = sim.position
        routing_surface = sim.routing_surface
    else:
        lot = services.active_lot()
        starting_position = lot.position
        routing_surface = routing.SurfaceIdentifier(services.current_zone().id,
                                                    0,
                                                    routing.SURFACETYPE_WORLD)
    with postures.posture_graph.supress_posture_graph_build():
        for obj_id in obj_ids:
            obj_id = int(obj_id)
            original_obj = None
            if obj_id in manager:
                original_obj = manager.get(obj_id)
            if original_obj is None:
                return
            obj_definition_id = original_obj.definition.id
            created_obj_count = number
            while created_obj_count > 0:
                if original_obj.crafting_component is not None:
                    obj = DebugCreateCraftableInteraction.create_craftable(
                        original_obj.crafting_component._crafting_process.
                        recipe, sim)
                else:
                    obj = objects.system.create_object(obj_definition_id)
                if obj is not None:
                    fgl_context = placement.FindGoodLocationContext(
                        starting_position=starting_position,
                        object_id=obj.id,
                        search_flags=search_flags,
                        object_footprints=(obj.get_footprint(), ))
                    (position,
                     orientation) = placement.find_good_location(fgl_context)
                    if position is not None and orientation is not None:
                        obj.move_to(translation=position,
                                    orientation=orientation,
                                    routing_surface=routing_surface)
                    else:
                        obj.destroy(
                            source=obj,
                            cause=
                            'Failed to find good location for create_multiple_objects'
                        )
                created_obj_count -= 1
Esempio n. 23
0
def footprint_intersection_check(resource_key,
                                 offset,
                                 orientation,
                                 circles,
                                 routing_surface=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:
        zone_id = sims4.zone_utils.get_zone_id()
        routing_surface = routing.SurfaceIdentifier(zone_id, 0,
                                                    routing.SURFACETYPE_WORLD)
    return _placement.test_footprint_intersection(resource_key, offset,
                                                  orientation, routing_surface,
                                                  circles)
 def _on_quadtree_changed(self):
     quadtree = services.sim_quadtree()
     if quadtree is None:
         return
     bounds = QtCircle(Vector2(0, 0), 10000)
     with Context(self.layer) as layer:
         filter_visualizers = ((placement.ItemType.SIM_POSITION, Color.GREEN), (placement.ItemType.SIM_INTENDED_POSITION, Color.YELLOW), (placement.ItemType.ROUTE_GOAL_SUPPRESSOR, Color.RED), (placement.ItemType.ROUTABLE_OBJECT_SURFACE, Color.CYAN))
         for (quadtree_filter, color) in filter_visualizers:
             layer.set_color(color)
             for o in quadtree.query(bounds=bounds, surface_id=routing.SurfaceIdentifier(0, 0, 0), filter=quadtree_filter, flags=ObjectQuadTreeQueryFlag.IGNORE_SURFACE):
                 if isinstance(o[2], Polygon):
                     layer.add_polygon(o[2], altitude=0.1, routing_surface=o[3])
                 else:
                     height = terrain.get_lot_level_height(o[2].center.x, o[2].center.y, o[3].secondary_id, services.current_zone_id()) + 0.1
                     layer.add_circle(sims4.math.Vector3(o[2].center.x, height, o[2].center.y), o[2].radius, altitude=KEEP_ALTITUDE)
Esempio n. 25
0
 def __init__(self, interaction, participant_type, distance_to_participant, tag_set, lot_id, zone_id, allow_spawning_on_non_world_routing_surfaces):
     self._interaction = interaction
     self._participant_type = participant_type
     self._distance_to_participant = distance_to_participant
     self._tags = tag_set
     self._allow_spawning_on_non_world_routing_surfaces = allow_spawning_on_non_world_routing_surfaces
     self._routing_surface_override = None
     routing_surface = None
     participant = self._get_participant()
     if participant is not None:
         if participant.routing_surface.type == routing.SurfaceType.SURFACETYPE_WORLD or allow_spawning_on_non_world_routing_surfaces:
             routing_surface = participant.routing_surface
         else:
             level = participant.routing_surface.secondary_id
             routing_surface = routing.SurfaceIdentifier(services.current_zone().id, level, routing.SurfaceType.SURFACETYPE_WORLD)
     super().__init__(lot_id, zone_id, routing_surface=routing_surface)
Esempio n. 26
0
 def __init__(self, guid, template=None, debug_name=None, parent=None, species=None):
     self.id = guid
     self.template = template
     if species is not None:
         self._species = species
     elif template is not None:
         self._species = template.species
     else:
         self._species = Species.HUMAN
     self.debug_name = debug_name
     self.parent = parent
     self.asm_auto_exit = AsmAutoExitInfo()
     self.routing_context = PathPlanContext()
     zone_id = services.current_zone_id()
     routing_surface = routing.SurfaceIdentifier(zone_id or 0, 0, routing.SurfaceType.SURFACETYPE_WORLD)
     self.routing_location = routing.Location(sims4.math.Vector3.ZERO(), sims4.math.Quaternion.IDENTITY(), routing_surface)
Esempio n. 27
0
 def _get_door_connections_from_arrival(self, doors, is_apartment=False):
     zone = services.current_zone()
     source_point = self._get_arrival_point()
     source_handles = set()
     source_handle = Handle(
         source_point,
         routing.SurfaceIdentifier(zone.id, 0,
                                   routing.SurfaceType.SURFACETYPE_WORLD))
     source_handles.add(source_handle)
     routing_context = routing.PathPlanContext()
     for door in doors:
         for portal_handle in door.get_portal_pairs():
             routing_context.lock_portal(portal_handle.there)
             routing_context.lock_portal(portal_handle.back)
     routing_context.set_key_mask(routing.FOOTPRINT_KEY_ON_LOT
                                  | routing.FOOTPRINT_KEY_OFF_LOT)
     if is_apartment:
         routing_context.set_portal_key_mask(
             DoorService.FRONT_DOOR_ALLOWED_PORTAL_FLAGS
             | DoorService.FRONT_DOOR_ALLOWED_APARTMENT_PORTAL_FLAGS)
     else:
         routing_context.set_portal_key_mask(
             DoorService.FRONT_DOOR_ALLOWED_PORTAL_FLAGS)
     dest_handles = set()
     for door in doors:
         (front_position, back_position) = door.get_door_positions()
         if not front_position is None:
             if back_position is None:
                 continue
             dest_handles.add(
                 DoorConnectivityHandle(front_position,
                                        door.routing_surface,
                                        door=door,
                                        is_front=True))
             dest_handles.add(
                 DoorConnectivityHandle(back_position,
                                        door.routing_surface,
                                        door=door,
                                        is_front=False))
     connections = ()
     if dest_handles:
         connections = routing.estimate_path_batch(
             source_handles, dest_handles, routing_context=routing_context)
         if connections is None:
             connections = ()
     return connections
Esempio n. 28
0
 def __init__(self, definition, **kwargs):
     super().__init__(definition, **kwargs)
     if definition is not None:
         self.apply_definition(definition, **kwargs)
     self._ui_metadata_stack = None
     self._ui_metadata_handles = None
     self._ui_metadata_cache = None
     self.primitives = distributor.ops.DistributionSet(self)
     zone_id = services.current_zone_id()
     self._location = sims4.math.Location(
         sims4.math.Transform(),
         routing.SurfaceIdentifier(zone_id, 0,
                                   routing.SurfaceType.SURFACETYPE_WORLD))
     self._children_objects = None
     self._scale = 1
     self._parent_type = ObjectParentType.PARENT_NONE
     self._parent_location = 0
     self._build_buy_lockout = False
     self._build_buy_lockout_alarm_handler = None
     self._tint = None
     self._opacity = None
     self._censor_state = None
     self._geometry_state = None
     self._geometry_state_overrides = None
     self._standin_model = None
     self._visibility = None
     self._visibility_flags = None
     self._material_state = None
     self._reference_arb = None
     self._audio_effects = None
     self._video_playlist = None
     self._painting_state = None
     self.custom_name = None
     self.custom_description = None
     self._multicolor = None
     self._display_number = None
     self._awareness_scores = None
     self._scratched = False
     self._base_value = definition.price
     self._needs_post_bb_fixup = False
     self._needs_depreciation = False
     self._swapping_to_parent = None
     self._swapping_from_parent = None
     self._on_children_changed = None
     self.allow_opacity_change = True
     self._wind_speed_effect = None
Esempio n. 29
0
 def get_lot_corners_constraint_set(self):
     lot_center = self.lot.center
     lot_corners = services.current_zone().lot.corners
     routing_surface = routing.SurfaceIdentifier(
         services.current_zone().id, 0, routing.SURFACETYPE_WORLD)
     constraint_list = []
     for corner in lot_corners:
         diff = lot_center - corner
         if diff.magnitude_squared() != 0:
             towards_center_vec = sims4.math.vector_normalize(lot_center -
                                                              corner) * 0.1
         else:
             towards_center_vec = sims4.math.Vector3.ZERO()
         new_corner = corner + towards_center_vec
         constraint_list.append(interactions.constraints.Position(
             new_corner, routing_surface=routing_surface))
     return create_constraint_set(constraint_list)
Esempio n. 30
0
def polygon_intersection(*args, _connection=None):
    output = sims4.commands.Output(_connection)
    total_string = ''.join(args)
    polygon_strs = find_substring_in_repr(total_string, POLYGON_STR,
                                          POLYGON_END_PARAM)
    if not polygon_strs:
        output('No valid polygons. must start with {} and end with {}'.format(
            POLYGON_STR, POLYGON_END_PARAM))
        return
    constraints = []
    for poly_str in polygon_strs:
        point_list = extract_floats(poly_str)
        if not point_list or len(point_list) % 2 != 0:
            output('Point list is not valid length. Too few or one too many.')
            return
        vertices = []
        for index in range(0, len(point_list), 2):
            vertices.append(
                sims4.math.Vector3(point_list[index], 0.0,
                                   point_list[index + 1]))
        polygon = sims4.geometry.Polygon(vertices)
        geometry = sims4.geometry.RestrictedPolygon(polygon, [])
        constraint = Constraint(geometry=geometry,
                                routing_surface=routing.SurfaceIdentifier(
                                    services.current_zone_id(), 0,
                                    routing.SurfaceType.SURFACETYPE_WORLD))
        constraints.append(constraint)
    intersection = ANYWHERE
    for constraint in constraints:
        new_intersection = intersection.intersect(constraint)
        if not new_intersection.valid:
            output(
                'Constraint intersection failed. Drawing incompatible geometry. {}'
                .format(new_intersection))
            if intersection.geometry is not None:
                draw_geometry_in_string(str(intersection.geometry),
                                        _connection=_connection)
            draw_geometry_in_string(str(constraint.geometry),
                                    _connection=_connection)
            return
        intersection = new_intersection
    if intersection.valid:
        draw_geometry_in_string(str(intersection.geometry),
                                _connection=_connection)
        output('Intersection valid. Drawing Polygon.')