Пример #1
0
def _create_enter_carry_posture(sim, posture_state, carry_target, track):
    var_map = {
        PostureSpecVariable.CARRY_TARGET:
        carry_target,
        PostureSpecVariable.HAND:
        track_to_hand(track),
        PostureSpecVariable.POSTURE_TYPE_CARRY_OBJECT:
        carry_target.get_carry_object_posture()
    }
    pick_up_operation = PostureOperation.PickUpObject(
        PostureSpecVariable.POSTURE_TYPE_CARRY_OBJECT,
        PostureSpecVariable.CARRY_TARGET)
    new_source_aop = pick_up_operation.associated_aop(sim, var_map)
    new_posture_spec = pick_up_operation.apply(
        posture_state.get_posture_spec(var_map),
        enter_carry_while_holding=True)
    if new_posture_spec is None:
        raise RuntimeError(
            '[rmccord] Failed to create new_posture_spec in enter_carry_while_holding!'
        )
    new_posture_state = PostureState(sim, posture_state, new_posture_spec,
                                     var_map)
    new_posture = new_posture_state.get_aspect(track)
    from carry.carry_postures import CarryingNothing
    if new_posture is None or isinstance(new_posture, CarryingNothing):
        raise RuntimeError(
            '[rmccord] Failed to create a valid new_posture ({}) from new_posture_state ({}) in enter_carry_while_holding!'
            .format(new_posture, new_posture_state))
    new_posture.external_transition = True
    return (new_posture_state, new_posture, new_source_aop, var_map)
Пример #2
0
def create_exit_carry_posture(sim, target, interaction, use_posture_animations):
    from postures.posture_state import PostureState
    failure_result = (None, None, None, None, None)
    slot_manifest = interaction.slot_manifest
    old_carry_posture = sim.posture_state.get_carry_posture(target)
    if old_carry_posture is None:
        return failure_result
    spec_surface = sim.posture_state.spec[SURFACE_INDEX]
    if spec_surface is not None and spec_surface[SURFACE_SLOT_TYPE_INDEX] is not None:
        put_down_operation = PostureOperation.PutDownObjectOnSurface(PostureSpecVariable.POSTURE_TYPE_CARRY_NOTHING, spec_surface[SURFACE_TARGET_INDEX], spec_surface[SURFACE_SLOT_TYPE_INDEX], PostureSpecVariable.CARRY_TARGET)
    else:
        put_down_operation = PostureOperation.PutDownObject(PostureSpecVariable.POSTURE_TYPE_CARRY_NOTHING, PostureSpecVariable.CARRY_TARGET)
    var_map = {PostureSpecVariable.CARRY_TARGET: target, PostureSpecVariable.HAND: PostureState.track_to_hand(old_carry_posture.track), PostureSpecVariable.POSTURE_TYPE_CARRY_NOTHING: CarryPostureStaticTuning.POSTURE_CARRY_NOTHING, PostureSpecVariable.SLOT: slot_manifest, PostureSpecVariable.SLOT_TEST_DEFINITION: interaction.create_target}
    current_spec = sim.posture_state.get_posture_spec(var_map)
    if current_spec is None:
        logger.warn('Failed to get posture spec for var_map: {} for {}', sim.posture_state, var_map)
        return failure_result
    new_posture_spec = put_down_operation.apply(current_spec)
    if new_posture_spec is None:
        logger.warn('Failed to apply put_down_operation: {}', put_down_operation)
        return failure_result
    if not new_posture_spec.validate_destination((new_posture_spec,), var_map, interaction.affordance):
        logger.warn('Failed to validate put down spec {}  with var map {}', new_posture_spec, var_map)
        return failure_result
    new_posture_state = PostureState(sim, sim.posture_state, new_posture_spec, var_map)
    new_posture = new_posture_state.get_aspect(old_carry_posture.track)
    new_posture.source_interaction = interaction.super_interaction
    new_posture.external_transition = not use_posture_animations
    posture_context = postures.context.PostureContext(interaction.context.source, interaction.priority, None)
    transition = postures.transition.PostureTransition(new_posture, new_posture_state, posture_context, var_map)
    transition.must_run = True
    return (old_carry_posture, new_posture, new_posture_state, transition, var_map)
Пример #3
0
def create_enter_carry_posture(sim, posture_state, carry_target, track):
    from postures.posture_state import PostureState
    var_map = {PostureSpecVariable.CARRY_TARGET: carry_target, PostureSpecVariable.HAND: PostureState.track_to_hand(track), PostureSpecVariable.POSTURE_TYPE_CARRY_OBJECT: CarryPostureStaticTuning.POSTURE_CARRY_OBJECT}
    pick_up_operation = PostureOperation.PickUpObject(PostureSpecVariable.POSTURE_TYPE_CARRY_OBJECT, PostureSpecVariable.CARRY_TARGET)
    new_source_aop = pick_up_operation.associated_aop(sim, var_map)
    new_posture_spec = pick_up_operation.apply(posture_state.get_posture_spec(var_map), enter_carry_while_holding=True)
    if new_posture_spec is None:
        raise RuntimeError('[jpollak] Failed to create new_posture_spec in enter_carry_while_holding!')
    new_posture_state = PostureState(sim, posture_state, new_posture_spec, var_map)
    new_posture = new_posture_state.get_aspect(track)
    from carry.carry_postures import CarryingNothing
    if new_posture is None or isinstance(new_posture, CarryingNothing):
        raise RuntimeError('[jpollak] Failed to create a valid new_posture ({}) from new_posture_state ({}) in enter_carry_while_holding!'.format(new_posture, new_posture_state))
    new_posture.external_transition = True
    return (new_posture_state, new_posture, new_source_aop, var_map)
Пример #4
0
 def do_transition(timeline):
     result = yield from element_utils.run_child(
         timeline, transition)
     if result:
         if target.is_sim:
             body_posture_type = sim.posture_state.spec.body.posture_type
             if not body_posture_type.multi_sim:
                 post_transition_spec = sim.posture_state.spec.clone(
                     body=PostureAspectBody(
                         (body_posture_type, None)),
                     surface=PostureAspectSurface(
                         (None, None, None)))
                 post_posture_state = PostureState(
                     sim, sim.posture_state,
                     post_transition_spec, var_map)
                 post_posture_state.body.source_interaction = sim.posture.source_interaction
                 post_transition = PostureTransition(
                     post_posture_state.body,
                     post_posture_state,
                     sim.posture.posture_context, var_map)
                 post_transition.must_run = True
                 yield from element_utils.run_child(
                     timeline, post_transition)
         interaction_target_was_target = False
         si_target_was_target = False
         new_posture.source_interaction = None
         return True
         yield
     return False
     yield
Пример #5
0
    def _run_gen(self, timeline):
        dest_state = self._dest_state
        sim = dest_state.sim
        source_state = sim.posture_state
        dest_aspect = None
        if source_state.body != dest_state.body:
            dest_aspect = dest_state.body
        if source_state.left != dest_state.left:
            dest_aspect = dest_state.left
        if source_state.right != dest_state.right:
            dest_aspect = dest_state.right

        def create_transition(dest_aspect):
            reserve_target_interaction = None
            if self._should_reserve:
                reserve_target_interaction = self._reason_interaction_ref()
            return PostureTransition(dest_aspect, dest_state, self._context,
                                     self._var_map, self._transition_spec,
                                     reserve_target_interaction,
                                     self._destination_constraint)

        if dest_aspect is None:
            if source_state.body.mobile and dest_state.body.mobile:
                self._transition = create_transition(dest_state.body)
                transition_result = yield from element_utils.run_child(
                    timeline, self._transition)
                if not transition_result:
                    return transition_result
                    yield
            new_posture_spec = sim.posture_state.get_posture_spec(
                self._var_map)
            self._dest_state = PostureState(sim, sim.posture_state,
                                            new_posture_spec, self._var_map)
            dest_state = self._dest_state
            sim.posture_state = dest_state
            if self._source_interaction is not None:
                dest_state.body.source_interaction = self._source_interaction
            if self._owning_interaction_ref is not None:
                self._owning_interaction_ref().acquire_posture_ownership(
                    dest_state.body)
            yield from sim.si_state.notify_posture_change_and_remove_incompatible_gen(
                timeline, source_state, dest_state)
            return TestResult.TRUE
            yield
        if self._source_interaction is not None:
            dest_aspect.source_interaction = self._source_interaction
        if self._owning_interaction_ref is not None:
            self._owning_interaction_ref().acquire_posture_ownership(
                dest_aspect)
        self._transition = create_transition(dest_aspect)
        result = yield from element_utils.run_child(timeline, self._transition)
        return result
        yield
Пример #6
0
 def set_target_linked_posture_data(self):
     posture_state = PostureState(
         self.target, self._carried_linked_previous_posture_state,
         self._carried_linked_posture_spec,
         {PostureSpecVariable.HAND: (Hand.LEFT, )})
     self._carried_linked_posture = posture_state.body
     self._carried_linked_posture.previous_posture = self._carried_linked_previous_posture_state.body
     self._carried_linked_posture.rebind(
         self.sim, animation_context=self.animation_context)
     self._carried_linked_posture.source_interaction = self._get_carried_linked_source_interaction(
     )
     return posture_state
Пример #7
0
 def _set_posture(self, *args, **kwargs):
     self._xevt_triggered = True
     from postures.posture_state import PostureState
     sim = self.interaction.sim
     self._previous_posture_state = sim.posture_state
     origin_posture_spec = get_origin_spec(self.posture_type)
     sim.posture_state = PostureState(
         sim, None, origin_posture_spec,
         {PostureSpecVariable.HAND: (Hand.LEFT, )})
     sim.posture_state.body.source_interaction = sim.create_default_si()
     idle_arb = animation.arb.Arb()
     sim.posture.append_transition_to_arb(idle_arb, None)
     sim.posture.append_idle_to_arb(idle_arb)
     distribute_arb_element(idle_arb, master=sim)
    def execute(self, actor, path=None):
        previous_posture_state = actor.posture_state
        origin_posture_spec = get_origin_spec(self.posture_type)
        var_map = {PostureSpecVariable.HAND: Hand.LEFT}
        carry_posture_overrides = {previous_posture_state.left.track: previous_posture_state.left, previous_posture_state.right.track: previous_posture_state.right}
        actor.posture_state = PostureState(actor, actor.posture_state, origin_posture_spec, var_map, carry_posture_overrides=carry_posture_overrides)
        actor.posture_state.body.source_interaction = actor.create_default_si()
        final_routing_surface = path.final_location.routing_surface
        idle_arb = animation.arb.Arb()
        actor.posture.append_transition_to_arb(idle_arb, None)
        actor.posture.append_idle_to_arb(idle_arb)
        distribute_arb_element(idle_arb, master=actor)
        running_interaction = actor.queue.running
        if running_interaction is not None:
            running_interaction.satisfied = True

        def kickstart_posture(_timeline):
            result = yield from actor.posture_state.body.kickstart_gen(_timeline, actor.posture_state, final_routing_surface)
            return result
            yield

        def end_body_aspect(_timeline):
            if previous_posture_state.body:
                result = yield from element_utils.run_child(_timeline, previous_posture_state.body.end())
                if not result:
                    return result
                    yield
            return True
            yield

        timeline = services.time_service().sim_timeline.get_sub_timeline()
        element = element_utils.build_element(actor.posture.get_idle_behavior())
        timeline.schedule(element)
        if not timeline.simulate(timeline.now):
            logger.error('Failed trying to run idle behavior on Sim {} during a set posture route event.', actor)
        element = element_utils.build_element(flush_all_animations)
        timeline.schedule(element)
        if not timeline.simulate(timeline.now):
            logger.error('Failed trying to flush animations on Sim {} during a set posture route event.', actor)
        element = element_utils.build_element(kickstart_posture)
        timeline.schedule(element)
        if not timeline.simulate(timeline.now):
            logger.error('Failed trying to kickstart a posture on Sim {} during a set posture route event.', actor)
        element = element_utils.build_element(end_body_aspect)
        timeline.schedule(element)
        if not timeline.simulate(timeline.now):
            logger.error('Failed trying to end previous body aspect on Sim {} during a set posture route event.', actor)
Пример #9
0
def _create_exit_carry_posture(sim,
                               target,
                               interaction,
                               use_posture_animations,
                               preserve_posture=None):
    failure_result = (None, None, None, None, None)
    slot_manifest = interaction.slot_manifest
    old_carry_posture = sim.posture_state.get_carry_posture(target)
    if old_carry_posture is None:
        return failure_result
    spec_surface = sim.posture_state.spec[SURFACE_INDEX]
    has_slot_surface = spec_surface is not None and spec_surface[
        SURFACE_SLOT_TYPE_INDEX] is not None
    if not target.transient and has_slot_surface:
        put_down_operation = PostureOperation.PutDownObjectOnSurface(
            PostureSpecVariable.POSTURE_TYPE_CARRY_NOTHING,
            spec_surface[SURFACE_TARGET_INDEX],
            spec_surface[SURFACE_SLOT_TYPE_INDEX],
            PostureSpecVariable.CARRY_TARGET)
    else:
        put_down_operation = PostureOperation.PutDownObject(
            PostureSpecVariable.POSTURE_TYPE_CARRY_NOTHING,
            PostureSpecVariable.CARRY_TARGET)
    var_map = {
        PostureSpecVariable.CARRY_TARGET: target,
        PostureSpecVariable.HAND: track_to_hand(old_carry_posture.track),
        PostureSpecVariable.POSTURE_TYPE_CARRY_NOTHING:
        CarryPostureStaticTuning.POSTURE_CARRY_NOTHING,
        PostureSpecVariable.SLOT: slot_manifest,
        PostureSpecVariable.SLOT_TEST_DEFINITION: interaction.create_target
    }
    current_spec = sim.posture_state.get_posture_spec(var_map)
    if current_spec is None:
        if preserve_posture is None:
            logger.warn('Failed to get posture spec for var_map: {} for {}',
                        sim.posture_state, var_map)
        return failure_result
    new_posture_spec = put_down_operation.apply(current_spec)
    if new_posture_spec is None:
        if preserve_posture is None:
            logger.warn('Failed to apply put_down_operation: {}',
                        put_down_operation)
        return failure_result
    if not new_posture_spec.validate_destination(
        (new_posture_spec, ), var_map, interaction.affordance, sim):
        if preserve_posture is None:
            logger.warn('Failed to validate put down spec {}  with var map {}',
                        new_posture_spec, var_map)
        return failure_result
    carry_posture_overrides = {}
    if preserve_posture is not None:
        carry_posture_overrides[preserve_posture.track] = preserve_posture
    new_posture_state = PostureState(
        sim,
        sim.posture_state,
        new_posture_spec,
        var_map,
        carry_posture_overrides=carry_posture_overrides)
    new_posture = new_posture_state.get_aspect(old_carry_posture.track)
    new_posture.source_interaction = interaction.super_interaction
    new_posture.external_transition = not use_posture_animations
    posture_context = PostureContext(interaction.context.source,
                                     interaction.priority, None)
    transition = PostureTransition(new_posture,
                                   new_posture_state,
                                   posture_context,
                                   var_map,
                                   locked_params=interaction.locked_params)
    transition.must_run = True
    return (old_carry_posture, new_posture, new_posture_state, transition,
            var_map)
Пример #10
0
    def soft_reset(sim_info: SimInfo,
                   reset_reason: ResetReason = ResetReason.RESET_EXPECTED,
                   hard_reset_on_exception: bool = False,
                   source: Any = None,
                   cause: Any = 'S4CL Soft Reset') -> bool:
        """soft_reset(sim_info, reset_reason=ResetReason.RESET_EXPECTED, hard_reset_on_exception=False, source=None, cause=None)

        Perform a soft reset on a Sim.

        :param sim_info: An instance of an Sim.
        :type sim_info: SimInfo
        :param reset_reason: The reason for the reset. Default is ResetReason.RESET_EXPECTED.
        :type reset_reason: ResetReason, optional
        :param hard_reset_on_exception: If set to True, a hard reset of the Object will be attempted upon an error occurring. If set to False, nothing will occur if the reset failed. Default is False.
        :type hard_reset_on_exception: bool, optional
        :param source: The source of the reset. Default is the GameObject.
        :type source: Any, optional
        :param cause: The cause of the reset. Default is 'S4CL Soft Reset'.
        :type cause: Any, optional
        :return: True, if the reset was successful. False, if not.
        :rtype: bool
        """
        sim = CommonSimUtils.get_sim_instance(sim_info)
        if sim is None:
            return True
        # noinspection PyBroadException
        try:
            # noinspection PyArgumentList
            if sim._should_be_swimming() or _buildbuy.is_location_pool(
                    services.current_zone_id(), sim.position,
                    sim.location.level):
                posture_type = posture_graph.SIM_SWIM_POSTURE_TYPE
            else:
                posture_type = posture_graph.SIM_DEFAULT_POSTURE_TYPE

            if sim.queue is not None:
                for interaction in sim.queue:
                    interaction.cancel(FinishingType.KILLED,
                                       'S4CL soft_reset sim.queue')
                sim.queue.on_reset()
                sim.queue.unlock()

            if sim.si_state is not None:
                for interaction in sim.si_state:
                    interaction.cancel(FinishingType.KILLED,
                                       'S4CL soft_reset sim.si_state')
                # noinspection PyBroadException
                try:
                    sim.si_state.on_reset()
                except:
                    sim._si_state = SIState(sim)
                    sim.si_state.on_reset()
            else:
                sim._si_state = SIState(sim)
                sim.si_state.on_reset()

            if sim.ui_manager is not None:
                sim.ui_manager.remove_all_interactions()

            sim.socials_locked = False
            sim.last_affordance = None
            sim.two_person_social_transforms.clear()
            sim.on_reset_send_op(reset_reason)
            # noinspection PyPropertyAccess
            if sim.posture_state is not None:
                # noinspection PyPropertyAccess
                sim.posture_state.on_reset(reset_reason)

            sim._stop_animation_interaction()
            sim.asm_auto_exit.clear()
            sim._start_animation_interaction()
            # noinspection PyBroadException
            try:
                sim.posture_state = PostureState(
                    sim, None, get_origin_spec(posture_type),
                    {PostureSpecVariable.HAND: (Hand.LEFT, )})
            except:
                sim.posture_state = PostureState(
                    sim, None,
                    get_origin_spec(posture_graph.SIM_DEFAULT_POSTURE_TYPE),
                    {PostureSpecVariable.HAND: (Hand.LEFT, )})

            sim._posture_target_refs.clear()
            sim.run_full_autonomy_next_ping()
            return True
        except:
            if hard_reset_on_exception:
                return CommonSimSpawnUtils.hard_reset(sim_info,
                                                      reset_reason,
                                                      source=source,
                                                      cause=cause)
        return False