Exemplo n.º 1
0
 def is_outside(self):
     routing_surface = self.routing_surface
     level = 0 if routing_surface is None else routing_surface.secondary_id
     try:
         return is_location_outside(self.zone_id, self.position, level)
     except RuntimeError:
         pass
Exemplo n.º 2
0
 def is_location_outside(location):
     zone_id = services.current_zone_id()
     try:
         return build_buy.is_location_outside(
             zone_id, location.transform.translation, location.level)
     except RuntimeError:
         return False
Exemplo n.º 3
0
 def is_location_outside_lot(location: Location, lot_id: int) -> bool:
     """
         Determine if a location is outside of the Lot with the specified identifier.
     """
     try:
         return build_buy.is_location_outside(
             lot_id, location.transform.translation, location.level)
     except RuntimeError:
         return False
Exemplo n.º 4
0
 def is_route_event_valid(self, route_event, time, sim, path):
     if not self.enabled:
         return False
     if self._safety_umbrella_putaway_event is route_event:
         location = path.final_location
         if is_location_outside(location.transform.translation,
                                location.routing_surface.secondary_id):
             self._safety_umbrella_putaway_event = None
             return False
         elif not sims4.math.almost_equal(time, path.duration() - 0.5):
             self._safety_umbrella_putaway_event = None
             return False
     return True
Exemplo n.º 5
0
    def is_location_outside_lot(location: Location, lot_id: int) -> bool:
        """is_location_outside_lot(location, lot_id)

        Determine if a location is outside of the Lot with the specified identifier.

        :param location: The Location to check.
        :type location: Location
        :param lot_id: The identifier of the Lot to check for the Location to be outside of.
        :type lot_id: int
        :return: True, if location is outside of the Lot with the specified lot_id. False, if not.
        :rtype: bool
        """
        try:
            return build_buy.is_location_outside(lot_id, location.transform.translation, location.level)
        except RuntimeError:
            return False
Exemplo n.º 6
0
    def _get_terrain_position_and_routing_surface_for_lightning_strike():
        lot_center = services.active_lot().center
        zone = services.current_zone()
        max_dist = math.sqrt(max((lot_center - spawn_point.get_approximate_center()).magnitude_squared() for spawn_point in zone.spawn_points_gen()))

        def _get_random_position_and_routing_surface():
            theta = random.random()*sims4.math.TWO_PI
            scaled_dist = random.random()*max_dist
            x = scaled_dist*math.cos(theta) + lot_center.x
            z = scaled_dist*math.sin(theta) + lot_center.z
            routing_surface = routing.get_routing_surface_at_or_below_position(sims4.math.Vector3(x, sims4.math.MAX_FLOAT, z))
            y = get_terrain_height(x, z, routing_surface=routing_surface)
            return (sims4.math.Vector3(x, y, z), routing_surface)

        count = 20
        (position, routing_surface) = _get_random_position_and_routing_surface()
        while count:
            while not build_buy.is_location_outside(position, routing_surface.secondary_id):
                (position, routing_surface) = _get_random_position_and_routing_surface()
                count -= 1
        if not count:
            return (None, None)
        return (position, routing_surface)
Exemplo n.º 7
0
 def __call__(self, context=None):
     if context is None:
         return TestResult(
             False,
             'Interaction Context is None. Make sure this test is Tuned on an Interaction.'
         )
     pick_info = context.pick
     if pick_info is None:
         return TestResult(
             False,
             'PickTerrainTest cannot run without a valid pick info from the Interaction Context.'
         )
     if pick_info.pick_type not in PICK_TRAVEL:
         return TestResult(
             False,
             'Attempting to run a PickTerrainTest with a pick that has an invalid type.'
         )
     if self.terrain_feature is not None:
         zone_id = services.current_zone_id()
         if not build_buy.find_floor_feature(
                 zone_id, self.terrain_feature, pick_info.location,
                 pick_info.routing_surface.secondary_id,
                 self.terrain_feature_radius):
             return TestResult(
                 False,
                 'Location does not have the required floor feature.')
     if self.terrain_location == PickTerrainType.ANYWHERE:
         return TestResult.TRUE
     on_lot = services.current_zone().lot.is_position_on_lot(
         pick_info.location)
     if self.terrain_location == PickTerrainType.ON_LOT:
         if on_lot:
             return TestResult.TRUE
         return TestResult(False, 'Pick Terrain is not ON_LOT as expected.')
     if self.terrain_location == PickTerrainType.OFF_LOT:
         if not on_lot:
             return TestResult.TRUE
         return TestResult(False,
                           'Pick Terrain is not OFF_LOT as expected.')
     current_zone_id = services.current_zone().id
     other_zone_id = pick_info.get_zone_id_from_pick_location()
     if self.terrain_location == PickTerrainType.ON_OTHER_LOT:
         if not on_lot and other_zone_id is not None and other_zone_id != current_zone_id:
             return TestResult.TRUE
         return TestResult(False,
                           'Pick Terrain is not ON_OTHER_LOT as expected.')
     if self.terrain_location == PickTerrainType.NO_LOT:
         if other_zone_id is None:
             return TestResult.TRUE
         return TestResult(
             False, 'Pick Terrain is is on a valid lot, but not expected.')
     in_street = is_position_in_street(pick_info.location)
     if self.terrain_location == PickTerrainType.IN_STREET:
         if in_street:
             return TestResult.TRUE
         return TestResult(False,
                           'Pick Terrain is not IN_STREET as expected.')
     if self.terrain_location == PickTerrainType.OFF_STREET:
         if not in_street:
             return TestResult.TRUE
         return TestResult(
             False, 'Pick Terrain is in the street, but not expected.')
     if self.terrain_location == PickTerrainType.IS_OUTSIDE:
         is_outside = is_location_outside(pick_info.location,
                                          pick_info.level)
         if is_outside:
             return TestResult.TRUE
         return TestResult(False, 'Pick Terrain is not outside')
     return TestResult.TRUE
Exemplo n.º 8
0
 def is_outside(self):
     return build_buy.is_location_outside(self.position, self.level)
Exemplo n.º 9
0
 def provide_route_events(self,
                          route_event_context,
                          sim,
                          path,
                          start_time=0,
                          end_time=0,
                          **kwargs):
     if not self.enabled:
         return
     if not self._has_routing_events():
         return
     resolver = SingleSimResolver(sim.sim_info)
     can_carry_umbrella = self.umbrella_route_events.enter_carry_event.test(
         resolver)
     added_enter_carry = False
     added_exit_carry = False
     is_prev_point_outside = None
     prev_time = None
     node = None
     prev_node = None
     prev_force_no_carry = False
     for (transform, routing_surface,
          time) in path.get_location_data_along_path_gen(
              time_step=0.5, start_time=start_time, end_time=end_time):
         force_no_carry = routing_surface.type == SurfaceType.SURFACETYPE_POOL
         if not force_no_carry:
             node = path.node_at_time(time)
             if node is prev_node:
                 force_no_carry = prev_force_no_carry
             elif not force_no_carry:
                 if node.portal_object_id != 0:
                     portal_object = services.object_manager(
                         routing_surface.primary_id).get(
                             node.portal_object_id)
                     if portal_object is not None:
                         portal_instance = portal_object.get_portal_by_id(
                             node.portal_id)
                         force_no_carry = portal_instance is not None and (
                             portal_instance.portal_template is not None and
                             (portal_instance.portal_template.required_flags
                              is not None and
                              portal_instance.portal_template.required_flags
                              & PortalFlags.REQUIRE_NO_CARRY
                              == PortalFlags.REQUIRE_NO_CARRY))
         level = 0 if routing_surface is None else routing_surface.secondary_id
         is_curr_point_outside = is_location_outside(
             transform.translation, level)
         if is_prev_point_outside is None:
             is_prev_point_outside = is_curr_point_outside
             prev_time = time
         else:
             if can_carry_umbrella:
                 if not added_enter_carry:
                     if is_curr_point_outside:
                         if not route_event_context.route_event_already_scheduled(
                                 self.umbrella_route_events.
                                 enter_carry_event,
                                 provider=self):
                             route_event_context.add_route_event(
                                 RouteEventType.FIRST_OUTDOOR,
                                 self.umbrella_route_events.
                                 enter_carry_event(provider=self,
                                                   time=time))
                             added_enter_carry = True
             if not added_exit_carry:
                 if is_curr_point_outside or not is_prev_point_outside or force_no_carry:
                     if self._no_regular_put_away_scheduled(
                             route_event_context):
                         route_event_context.add_route_event(
                             RouteEventType.LAST_OUTDOOR,
                             self.umbrella_route_events.exit_carry_event(
                                 provider=self, time=prev_time))
                         added_exit_carry = True
             if not can_carry_umbrella or added_enter_carry:
                 if added_exit_carry:
                     break
             is_prev_point_outside = is_curr_point_outside
             prev_time = time
             prev_node = node
             prev_force_no_carry = force_no_carry
     if self._safety_umbrella_putaway_event is None:
         location = path.final_location
         if not is_location_outside(location.transform.translation,
                                    location.routing_surface.secondary_id):
             self._safety_umbrella_putaway_event = self.umbrella_route_events.exit_carry_event(
                 provider=self, time=path.duration() - 0.5)
             route_event_context.add_route_event(
                 RouteEventType.LAST_OUTDOOR,
                 self._safety_umbrella_putaway_event)
Exemplo n.º 10
0
 def _score_location(self, position):
     if self.location_tests.validate_snowmask is not None and terrain.get_snowmask_value(position) > self.location_tests.validate_snowmask:
         return ThrowingGroupCostFunction.INVALID_GOAL_SCORE
     elif self.location_tests.validate_is_outside is not None and self.location_tests.validate_is_outside != is_location_outside(position, self._sim.level):
         return ThrowingGroupCostFunction.INVALID_GOAL_SCORE
     return 0.0
 def get_waypoint_constraints_gen(self, routing_agent, waypoint_count):
     water_constraint = self.get_water_constraint(
         self.constraint_parameters.min_water_depth,
         self.constraint_parameters.max_water_depth)
     debugvis_constraints = []
     target_position = self._target.position
     object_radius_constraint = Circle(
         target_position,
         self.constraint_parameters.object_constraint_radius,
         routing_surface=self._start_constraint.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())
     debugvis_constraints.append(
         (target_position,
          self.constraint_parameters.object_constraint_radius))
     area_goals = []
     handles = object_radius_constraint.get_connectivity_handles(
         routing_agent)
     for handle in handles:
         area_goals.extend(
             handle.get_goals(relative_object=self._target,
                              always_reject_invalid_goals=True))
     area_goals = [
         goal for goal in area_goals if is_location_outside(
             goal.position, goal.location.routing_surface.secondary_id)
     ]
     if not (self.outside_only and area_goals):
         yield Circle(
             target_position,
             self.constraint_parameters.object_constraint_radius,
             routing_surface=self._start_constraint.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())
         return
     min_dist_sq = self.waypoint_min_distance
     current_point = None
     for _ in range(waypoint_count):
         if current_point is None:
             current_point = random.choice(area_goals)
             debugvis_constraints.append(
                 (current_point.position,
                  self.constraint_parameters.waypoint_constraint_radius))
             yield Circle(
                 current_point.position,
                 self.constraint_parameters.waypoint_constraint_radius,
                 routing_surface=self._start_constraint.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())
         farthest_point = None
         farthest_dist = 0
         for _ in range(self.MAX_WAYPOINT_RANDOM_TRIES):
             try_point = random.choice(area_goals)
             try_dist = (try_point.position -
                         current_point.position).magnitude_squared()
             farthest_point = try_point
             break
             if not (try_dist > min_dist_sq and
                     (farthest_point is None or not farthest_point
                      is not None)) and try_dist > farthest_dist:
                 farthest_point = try_point
                 farthest_dist = try_dist
         current_point = farthest_point
         debugvis_constraints.append(
             (current_point.position,
              self.constraint_parameters.waypoint_constraint_radius))
         yield Circle(
             current_point.position,
             self.constraint_parameters.waypoint_constraint_radius,
             routing_surface=self._start_constraint.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())