Ejemplo n.º 1
0
 def operation_overrides(locked_args=frozendict()):
     locked_args = dict(locked_args)
     dynamic_skill_locked_args = dict(locked_args)
     if 'chance' not in locked_args:
         locked_args['chance'] = SuccessChance.ONE
     dynamic_skill_locked_args = dict(dynamic_skill_locked_args)
     if 'chance' not in dynamic_skill_locked_args:
         dynamic_skill_locked_args['chance'] = SuccessChance.ONE
     if 'advertise' not in dynamic_skill_locked_args:
         dynamic_skill_locked_args['advertise'] = False
     return {
         'operations':
         TunableList(
             description=
             '\n                A list of statistic operations that occur at each interval.\n                ',
             tunable=TunableStatisticChange(
                 dynamic_skill=DynamicSkillLootOp.TunableFactory(
                     locked_args=dynamic_skill_locked_args),
                 dynamic_variant_skill=DynamicVariantSkillLootOp.
                 TunableFactory(),
                 locked_args=locked_args,
                 gain_type=GAIN_TYPE_RATE,
                 statistic_override=StatisticOperation.
                 get_statistic_override(pack_safe=True),
                 default='statistic_change'))
     }
Ejemplo n.º 2
0
 def setup_asm_posture(self, asm, sim, target, locked_params=frozendict(), actor_param_name=DEFAULT):
     if actor_param_name is DEFAULT:
         actor_param_name = self._actor_param_name
     if asm is None:
         logger.error('Attempt to setup an asm whose value is None.')
         return False
     if sim is None:
         logger.error('Attempt to setup an asm {0} on a sim whose value is None.', asm)
         return False
     if not asm.set_actor(actor_param_name, sim, actor_participant=AnimationParticipant.ACTOR):
         logger.error('Failed to set actor sim: {0} on asm {1}', actor_param_name, asm)
         return False
     sim.set_mood_asm_parameter(asm, actor_param_name)
     sim.set_trait_asm_parameters(asm, actor_param_name)
     if target.is_part:
         is_mirrored = target.is_mirrored()
         if is_mirrored is not None:
             locked_params += {'isMirrored': is_mirrored}
     part_suffix = self.get_part_suffix()
     if not (target is not None and self._target_name is not None and self._setup_asm_container_parameter(asm, target, actor_param_name, part_suffix)):
         logger.error('Failed to set actor target: {0} on asm {1}', self._target_name, asm)
         return False
     if not PostureTrack.is_body(self.track):
         self._update_non_body_posture_asm()
         sim.on_posture_event.append(self._update_on_posture_event)
     if locked_params:
         virtual_actor_map = {self._target_name: self.target}
         asm.update_locked_params(locked_params, virtual_actor_map)
     self._setup_asm_carry_parameter(asm, target)
     return True
    def append_transition_to_arb(self,
                                 arb,
                                 source_posture,
                                 in_xevt_handler=False,
                                 locked_params=frozendict(),
                                 posture_spec=None,
                                 **kwargs):
        if in_xevt_handler:
            locked_params += {'surfaceHeight': 'from_xevt'}
            super().append_transition_to_arb(arb,
                                             source_posture,
                                             locked_params=locked_params,
                                             in_xevt_handler=in_xevt_handler,
                                             **kwargs)
            return
        carry_system_target = CarrySystemTerrainTarget(self.sim, self.target,
                                                       False,
                                                       self.target.transform)
        if self.target.is_in_inventory():
            if self.target.is_in_sim_inventory():
                obj_with_inventory = self.target.get_inventory().owner
            elif posture_spec is not None:
                surface = posture_spec[SURFACE_INDEX]
                obj_with_inventory = surface[SURFACE_TARGET_INDEX]
            else:
                obj_with_inventory = None
            if obj_with_inventory is None:
                obj_with_inventory = self.target.get_inventory().owner
            carry_system_target = CarrySystemInventoryTarget(
                self.sim, self.target, False, obj_with_inventory)
        else:
            runtime_slot = self.target.parent_slot
            if runtime_slot is not None:
                carry_system_target = CarrySystemRuntimeSlotTarget(
                    self.sim, self.target, False, runtime_slot)
            if self.target.parent is not None:
                self.asm.set_actor('surface', self.target.parent)
        call_super = True
        if carry_system_target.has_custom_animation:

            def normal_carry_callback():
                arb = animation.arb.Arb()
                self.append_transition_to_arb(arb,
                                              source_posture,
                                              locked_params=locked_params,
                                              in_xevt_handler=True)
                ArbElement(arb).distribute()

            carry_system_target.append_custom_animation_to_arb(
                arb, self, normal_carry_callback)
            call_super = False
        arb.register_event_handler(carry_system_target.carry_event_callback,
                                   animation.ClipEventType.Script,
                                   carry.SCRIPT_EVENT_ID_START_CARRY)
        if call_super:
            super().append_transition_to_arb(arb,
                                             source_posture,
                                             locked_params=locked_params,
                                             in_xevt_handler=in_xevt_handler,
                                             **kwargs)
Ejemplo n.º 4
0
 def _get_available_transforms_gen(self, actor, target):
     animation_element = self.canonical_animation
     actor_name = animation_element.actor_name
     target_name = animation_element.target_name
     actor_age = actor.age.age_for_animation_cache
     target_age = target.age.age_for_animation_cache
     locked_params = {
         ('species', actor_name):
         SpeciesExtended.get_animation_species_param(
             actor.extended_species),
         ('age', actor_name):
         actor_age.animation_age_param,
         ('species', target_name):
         SpeciesExtended.get_animation_species_param(
             target.extended_species),
         ('age', target_name):
         target_age.animation_age_param
     }
     for (param_sequences, transform) in self.available_transforms:
         for param_sequence in param_sequences:
             if not do_params_match(param_sequence, locked_params):
                 continue
             jig_params = frozendict({
                 param: value
                 for (param, value) in param_sequence.items()
                 if param not in locked_params
             })
             yield (transform, jig_params)
Ejemplo n.º 5
0
 def _make_boundary_conditions_list(self, actor, to_state_name, from_state_name, locked_params, entry=True, posture=DEFAULT):
     if any(pattern in str(self) for pattern in _verbose_logging_asms):
         verbose_logging = True
     else:
         verbose_logging = False
     if not Asm._bc_cache and should_use_boundary_condition_cache():
         Asm._bc_cache.update(read_bc_cache_from_resource())
     actor_name = self.get_actor_name_from_id(actor.id)
     if verbose_logging:
         logger.warn('Traversing as {} ({} -> {})', actor_name, from_state_name, to_state_name)
     posture = actor.posture if posture is DEFAULT else posture
     key = (self.name, actor_name, from_state_name, to_state_name, posture.name)
     containment_slot_data_list = self._bc_cache.get(key)
     if containment_slot_data_list is None:
         containment_slot_data_list = self._create_containment_slot_data_list(key, actor, actor_name, to_state_name, from_state_name, posture, entry, verbose_logging)
     if not containment_slot_data_list:
         return ()
     if actor.age is not UNSET:
         real_age_param = {('age', actor_name): actor.age.animation_age_param}
         locked_params += {('age', actor_name): actor.age.age_for_animation_cache.animation_age_param}
     else:
         real_age_param = {}
     containment_slot_data_list_filtered = []
     for (containment_slot, slots_to_params) in containment_slot_data_list:
         slots_to_params_valid = []
         for (boundary_condition, param_sequences) in slots_to_params:
             param_sequences_valid = [frozendict(param_sequence, real_age_param) for param_sequence in param_sequences if do_params_match(param_sequence, locked_params)]
             while param_sequences_valid:
                 slots_to_params_valid.append((boundary_condition, tuple(param_sequences_valid)))
         while slots_to_params_valid:
             containment_slot_data_list_filtered.append((containment_slot, tuple(slots_to_params_valid)))
     return tuple(containment_slot_data_list_filtered)
Ejemplo n.º 6
0
 def append_transition_to_arb(self,
                              arb,
                              source_posture,
                              in_xevt_handler=False,
                              locked_params=frozendict(),
                              **kwargs):
     if source_posture is not None:
         target = source_posture.target
         if target is not None:
             target_anim_overrides = target.get_anim_overrides(
                 source_posture.get_target_name())
             locked_params += target_anim_overrides.params
             self.asm.set_actor(source_posture.get_target_name(),
                                source_posture.target)
     objects_to_find = []
     for object_id in arb.actor_ids:
         object_found = services.object_manager().get(object_id)
         if object_found is not None:
             if object_found.carryable_component is not None:
                 objects_to_find.append(object_found)
     for object_found in objects_to_find:
         if in_xevt_handler:
             object_found.carryable_component.on_object_uncarry(self.sim)
         else:
             arb.register_event_handler(
                 lambda *args, **kwargs: object_found.carryable_component.
                 on_object_uncarry(self.sim, *args, **kwargs),
                 animation.ClipEventType.Script, SCRIPT_EVENT_ID_STOP_CARRY)
     super().append_transition_to_arb(arb,
                                      source_posture,
                                      locked_params=locked_params,
                                      in_xevt_handler=in_xevt_handler,
                                      **kwargs)
def get_valid_aops_gen(target,
                       affordance,
                       si_affordance,
                       si,
                       context,
                       include_failed_aops_with_tooltip,
                       push_super_on_prepare=False,
                       considered=None,
                       aop_kwargs=frozendict()):
    if context.source == InteractionContext.SOURCE_PIE_MENU and not affordance.allow_user_directed:
        if considered is not None:
            considered[affordance] = {
                'affordance': str(affordance),
                'target': str(target),
                'test': 'Not allowed user directed'
            }
        return
    potential_interactions = affordance.potential_interactions(
        target,
        si_affordance,
        si,
        push_super_on_prepare=push_super_on_prepare,
        **aop_kwargs)
    for aop in potential_interactions:
        test_result = aop_valid_for_scoring(aop,
                                            affordance,
                                            target,
                                            context,
                                            include_failed_aops_with_tooltip,
                                            considered=considered)
        while test_result is not None:
            yield (aop, test_result)
Ejemplo n.º 8
0
 def _tuning_loaded_callback(cls):
     super()._tuning_loaded_callback()
     incompatibility = defaultdict(list)
     for (clue, incompatible_clues) in cls.clue_incompatibility.items():
         for incompatible_clue in incompatible_clues:
             incompatibility[clue].append(incompatible_clue)
             incompatibility[incompatible_clue].append(clue)
     cls.clue_incompatibility = frozendict(incompatibility)
Ejemplo n.º 9
0
 def append_transition_to_arb(self, arb, source_posture, locked_params=frozendict(), **kwargs):
     if source_posture is not None:
         target = source_posture.target
         if target is not None:
             target_anim_overrides = target.get_anim_overrides(source_posture.target_name)
             locked_params += target_anim_overrides.params
             self.asm.set_actor(source_posture.target_name, source_posture.target)
     super().append_transition_to_arb(arb, source_posture, locked_params=locked_params, **kwargs)
Ejemplo n.º 10
0
def SetLifeSpanMultipliers(
        short: typing.Union[int, float, None] = None,
        normal: typing.Union[int, float, None] = None,
        long: typing.Union[int, float, None] = None) -> None:
    if not isinstance(short, int) and not isinstance(
            short, float) and short is not None:
        raise Exceptions.IncorrectTypeException(short, "short",
                                                (int, float, None))

    if not isinstance(normal, int) and not isinstance(
            normal, float) and normal is not None:
        raise Exceptions.IncorrectTypeException(normal, "normal",
                                                (int, float, None))

    if not isinstance(long, int) and not isinstance(
            long, float) and long is not None:
        raise Exceptions.IncorrectTypeException(long, "long",
                                                (int, float, None))

    currentMultipliers = aging_tuning.AgingTuning.AGE_SPEED_SETTING_MULTIPLIER

    if short is None:
        short = currentMultipliers[aging_tuning.AgeSpeeds.FAST]

    if normal is None:
        normal = currentMultipliers[aging_tuning.AgeSpeeds.NORMAL]

    if long is None:
        long = currentMultipliers[aging_tuning.AgeSpeeds.SLOW]

    if short != currentMultipliers[
            aging_tuning.AgeSpeeds.FAST] and normal != currentMultipliers[
                aging_tuning.AgeSpeeds.NORMAL] and long != currentMultipliers[
                    aging_tuning.AgeSpeeds.SLOW]:
        return

    changingMultipliers = {
        aging_tuning.AgeSpeeds.FAST: short,
        aging_tuning.AgeSpeeds.NORMAL: normal,
        aging_tuning.AgeSpeeds.SLOW: long
    }

    # noinspection PyUnresolvedReferences
    newMultipliers = collections.frozendict(
        currentMultipliers.items(),
        **changingMultipliers)  # TODO way to revert
    aging_tuning.AgingTuning.AGE_SPEED_SETTING_MULTIPLIER = newMultipliers

    agingService = None  # type: typing.Optional[aging_service.AgingService]

    try:
        agingService = services.get_aging_service(
        )  # type: aging_service.AgingService
    except Exception:
        pass

    if agingService is not None:
        agingService.set_aging_speed(agingService.aging_speed)
Ejemplo n.º 11
0
 def _destination_filter(surfaces_and_var_maps, dest_spec, var_map):
     for (surface, slot_var_map) in surfaces_and_var_maps:
         combo_var_map = frozendict(var_map, slot_var_map)
         if PostureSpecVariable.SURFACE_TARGET in combo_var_map:
             surface = combo_var_map[PostureSpecVariable.SURFACE_TARGET]
         else:
             slot_child = combo_var_map[PostureSpecVariable.CARRY_TARGET]
             surface = slot_child.parent
         op = PostureOperation.TargetAlreadyInSlot(PostureSpecVariable.CARRY_TARGET, surface, PostureSpecVariable.SLOT)
         while not op.validate(None, None, combo_var_map):
             return False
     return True
Ejemplo n.º 12
0
 def _get_param_sequences_for_cache(self, actor, actor_name, to_state_name, from_state_name, posture):
     internal_param_sequence_list = self._get_param_sequences(actor.id, to_state_name, from_state_name, None)
     param_sequence_list = []
     posture_key = ('posture', actor_name)
     exact_str = posture.name + '-'
     family_str = posture.family_name
     if family_str is not None:
         family_str = '-' + family_str + '-'
     for param_sequence in internal_param_sequence_list or (None,):
         if param_sequence:
             posture_param_value = param_sequence.get(posture_key)
             if posture_param_value is not None:
                 if not posture_param_value.startswith(exact_str):
                     while not family_str is None:
                         if family_str not in posture_param_value:
                             pass
                         for age in Age.get_ages_for_animation_cache():
                             new_sequence = frozendict(param_sequence, {('age', actor_name): age.animation_age_param})
                             param_sequence_list.append(new_sequence)
         for age in Age.get_ages_for_animation_cache():
             new_sequence = frozendict(param_sequence, {('age', actor_name): age.animation_age_param})
             param_sequence_list.append(new_sequence)
     return param_sequence_list
Ejemplo n.º 13
0
class TestableGameOptions(enum.IntFlags):
    CIVIC_POLICY_NPC_VOTING_ENABLED = ...
    ECO_FOOTPRINT_GAMEPLAY = ...
    REQUIRED_PACK_BY_OPTION = frozendict({
        CIVIC_POLICY_NPC_VOTING_ENABLED:
        Pack.EP09,
        ECO_FOOTPRINT_GAMEPLAY:
        Pack.EP09
    })

    @property
    def supporting_pack_installed(self):
        pack = TestableGameOptions.REQUIRED_PACK_BY_OPTION.get(self, None)
        return pack is None or is_available_pack(pack)
Ejemplo n.º 14
0
 def _destination_filter(surfaces_and_var_maps, dest_spec, var_map):
     for (surface, slot_var_map) in surfaces_and_var_maps:
         combo_var_map = frozendict(var_map, slot_var_map)
         if PostureSpecVariable.SURFACE_TARGET in combo_var_map:
             surface = combo_var_map[PostureSpecVariable.SURFACE_TARGET]
         else:
             slot_child = combo_var_map[PostureSpecVariable.CARRY_TARGET]
             surface = slot_child.parent
         op = PostureOperation.TargetAlreadyInSlot(
             PostureSpecVariable.CARRY_TARGET, surface,
             PostureSpecVariable.SLOT)
         if not op.validate(None, None, combo_var_map):
             return False
     return True
Ejemplo n.º 15
0
 def _get_param_sequences_for_age_species_gen(self, param_sequence, actor_name, actor_species, actor_ages, target_name, target_species, target_ages):
     if target_name is None:
         params = itertools.product(actor_species, actor_ages)
     else:
         params = itertools.product(actor_species, actor_ages, target_species, target_ages)
     for (_actor_species, _actor_age, *target_params) in params:
         if not SpeciesExtended.is_age_valid_for_animation_cache(_actor_species, _actor_age):
             continue
         age_species_locked_args = {('species', actor_name): SpeciesExtended.get_animation_species_param(_actor_species), ('age', actor_name): _actor_age.animation_age_param}
         if target_name is not None:
             (_target_species, _target_age) = target_params
             if not SpeciesExtended.is_age_valid_for_animation_cache(_target_species, _target_age):
                 continue
             age_species_locked_args.update({('species', target_name): SpeciesExtended.get_animation_species_param(_target_species), ('age', target_name): _target_age.animation_age_param})
         yield frozendict(param_sequence, age_species_locked_args)
 def append_transition_to_arb(self,
                              arb,
                              source_posture,
                              locked_params=frozendict(),
                              **kwargs):
     if source_posture is not None:
         target = source_posture.target
         if target is not None:
             target_anim_overrides = target.get_anim_overrides(
                 source_posture.target_name)
             locked_params += target_anim_overrides.params
             self.asm.set_actor(source_posture.target_name,
                                source_posture.target)
     super().append_transition_to_arb(arb,
                                      source_posture,
                                      locked_params=locked_params,
                                      **kwargs)
Ejemplo n.º 17
0
 def append_transition_to_arb(self, arb, source_posture, locked_params=frozendict(), **kwargs):
     if not self._entry_anim_complete:
         locked_params += self.get_locked_params(source_posture)
         if source_posture is not None:
             locked_params += {TRANSITION_POSTURE_PARAM_NAME: source_posture.name}
         if not self.setup_asm_posture(self.asm, self.sim, self.target, locked_params=locked_params):
             logger.error('Failed to setup the asm for the posture {}', self)
             return
         self._setup_asm_target_for_transition(source_posture)
         self.asm.request(self._enter_state_name, arb)
         linked_posture = self.linked_posture
         if linked_posture is not None:
             locked_params = linked_posture.get_locked_params(source_posture)
             linked_posture.setup_asm_posture(linked_posture._asm, linked_posture.sim, linked_posture.target, locked_params=locked_params)
             if not self.multi_sim:
                 linked_posture._asm.request(linked_posture._enter_state_name, arb)
         self._entry_anim_complete = True
Ejemplo n.º 18
0
 def __init__(self, definition, tuned_native_components=frozendict(), **kwargs):
     super().__init__()
     self.id = 0
     self.manager = None
     self.definition = definition
     self._visible_to_client = False
     self._interaction_refs = None
     self._parts = None
     self.content_source = ContentSource.DEFAULT
     self.wall_or_fence_placement = self._has_placement_flag(build_buy.PlacementFlags.WALL_GRAPH_PLACEMENT)
     if definition is not None:
         services.definition_manager().register_definition(definition.id, self)
         for component_id in definition.components:
             comp = objects.components.native_component_id_to_class[component_id]
             if not comp.has_server_component():
                 continue
             factory = getattr(tuned_native_components, comp.CNAME, None) or comp.create_component
             self.add_component(factory(self))
Ejemplo n.º 19
0
 def __init__(self,
              dest,
              dest_state,
              context,
              var_map,
              transition_spec=None,
              interaction=None,
              constraint=None,
              locked_params=frozendict()):
     super().__init__()
     self._source = None
     self._dest = dest
     self._dest_state = dest_state
     self._context = context
     self._var_map = var_map
     self._status = self.Status.INITIAL
     self._transition_spec = transition_spec
     self._interaction = interaction
     self._constraint = constraint
     self._locked_params = locked_params
Ejemplo n.º 20
0
 def __init__(self,
              sim,
              constraint,
              geometry,
              los_reference_point=None,
              routing_surface_override=None,
              locked_params=frozendict(),
              target=None,
              weight_route_factor=1.0):
     self.routing_surface = sim.routing_surface if constraint.routing_surface is None else constraint.routing_surface
     if routing_surface_override is not None:
         self.routing_surface = routing_surface_override
     self.routing_surface_override = routing_surface_override
     super().__init__(geometry.polygon, self.routing_surface)
     self.locked_params = locked_params
     self.sim = sim
     self.constraint = constraint
     self.geometry = geometry
     self.los_reference_point = los_reference_point
     self.target = target
     self.weight_route_factor = weight_route_factor
Ejemplo n.º 21
0
 def __init__(self,
              definition,
              tuned_native_components=frozendict(),
              **kwargs):
     super().__init__()
     self.id = 0
     self.manager = None
     self.definition = definition
     self.visible_to_client = False
     self.interaction_refs = set()
     if definition is not None:
         services.definition_manager().register_definition(
             definition.id, self)
         for component_id in definition.components:
             comp = objects.components.native_component_id_to_class[
                 component_id]
             if not comp.has_server_component():
                 pass
             factory = tuned_native_components.get(
                 comp.CNAME) or comp.create_component
             self.add_component(factory(self))
Ejemplo n.º 22
0
def create_tuningless_interaction(affordance, **kwargs):
    locked_fields = dict(basic_reserve_object=None,
                         basic_focus=None,
                         _forwarding=None,
                         allow_from_world=True,
                         basic_extras=(),
                         _constraints=frozendict(),
                         tests=TunableTestSet.DEFAULT_LIST,
                         test_globals=TunableGlobalTestSet.DEFAULT_LIST,
                         test_autonomous=TunableTestSet.DEFAULT_LIST,
                         _static_commodities=(),
                         _false_advertisements=(),
                         _hidden_false_advertisements=(),
                         _cancelable_by_user=True,
                         visible=False,
                         simless=False,
                         allow_autonomous=False,
                         allow_user_directed=False,
                         debug=False,
                         outcome=InteractionOutcome())
    if kwargs:
        locked_fields.update(kwargs)
    lock_instance_tunables(affordance, **locked_fields)
Ejemplo n.º 23
0
def get_valid_aops_gen(target,
                       affordance,
                       si_affordance,
                       si,
                       context,
                       include_failed_aops_with_tooltip,
                       push_super_on_prepare=False,
                       considered=None,
                       aop_kwargs=frozendict()):
    potential_interactions = affordance.potential_interactions(
        target,
        si_affordance,
        si,
        push_super_on_prepare=push_super_on_prepare,
        **aop_kwargs)
    for aop in potential_interactions:
        test_result = aop_valid_for_scoring(aop,
                                            affordance,
                                            target,
                                            context,
                                            include_failed_aops_with_tooltip,
                                            considered=considered)
        if test_result is not None:
            yield (aop, test_result)
Ejemplo n.º 24
0
 def _make_boundary_conditions_list(self, actor, to_state_name, from_state_name, locked_params, entry=True, posture=DEFAULT, base_object_name=None, target=None):
     if any(pattern in str(self) for pattern in _verbose_logging_asms):
         verbose_logging = True
     else:
         verbose_logging = False
     actor_name = self.get_actor_name_from_id(actor.id)
     target_name = self.get_actor_name_from_id(target.id) if target is not None else None
     if verbose_logging:
         logger.warn('Traversing as {} ({} -> {})', actor_name, from_state_name, to_state_name)
     if posture is DEFAULT:
         posture = getattr(actor, 'posture', None)
     key = (self.name, actor_name, target_name, from_state_name, to_state_name, posture.name if posture is not None else None)
     if caches.USE_ACC_AND_BCC & caches.AccBccUsage.BCC != caches.AccBccUsage.BCC or self._boundary_condition_dirty and key not in self._bc_cache_localwork_keys[self.name]:
         containment_slot_data_list = None
     else:
         containment_slot_data_list = self._bc_cache.get(key)
     if containment_slot_data_list is None:
         containment_slot_data_list = self._create_containment_slot_data_list(key, actor, actor_name, to_state_name, from_state_name, posture, entry, verbose_logging, base_object_name=base_object_name, target_name=target_name)
     if not containment_slot_data_list:
         return ()
     age = getattr(actor, 'age', UNSET)
     if age is not UNSET:
         real_age_param = {('age', actor_name): age.animation_age_param}
         locked_params += {('age', actor_name): age.age_for_animation_cache.animation_age_param}
     else:
         real_age_param = {}
     containment_slot_data_list_filtered = []
     for (containment_slot, slots_to_params) in containment_slot_data_list:
         slots_to_params_valid = []
         for (boundary_condition, param_sequences) in slots_to_params:
             param_sequences_valid = [frozendict(param_sequence, real_age_param) for param_sequence in param_sequences if do_params_match(param_sequence, locked_params)]
             if param_sequences_valid:
                 slots_to_params_valid.append((boundary_condition, tuple(param_sequences_valid)))
         if slots_to_params_valid:
             containment_slot_data_list_filtered.append((containment_slot, tuple(slots_to_params_valid)))
     return tuple(containment_slot_data_list_filtered)
Ejemplo n.º 25
0
 def append_exit_to_arb(self, arb, dest_state, dest_posture, var_map, locked_params=frozendict()):
     if not self._exit_anim_complete:
         self._setup_asm_target_for_transition(dest_posture)
         locked_params += self.locked_params
         if dest_posture is not None:
             locked_params += {TRANSITION_POSTURE_PARAM_NAME: dest_posture.name}
         if locked_params:
             virtual_actor_map = {self._target_name: self.target}
             self.asm.update_locked_params(locked_params, virtual_actor_map)
         self.asm.request(self._exit_state_name, arb)
         self._exit_anim_complete = True
Ejemplo n.º 26
0
    def append_transition_to_arb(self, arb, source_posture, in_xevt_handler=False, locked_params=frozendict(), posture_spec=None, **kwargs):
        if in_xevt_handler:
            locked_params += {'surfaceHeight': 'from_xevt'}
            super().append_transition_to_arb(arb, source_posture, locked_params=locked_params, in_xevt_handler=in_xevt_handler, **kwargs)
            return
        carry_system_target = CarrySystemTerrainTarget(self.sim, self.target, False, self.target.transform)
        if self.target.is_in_inventory():
            if self.target.is_in_sim_inventory():
                obj_with_inventory = self.target.get_inventory().owner
            elif posture_spec is not None:
                surface = posture_spec[SURFACE_INDEX]
                obj_with_inventory = surface[SURFACE_TARGET_INDEX]
            else:
                obj_with_inventory = None
            if obj_with_inventory is None:
                obj_with_inventory = self.target.get_inventory().owner
            carry_system_target = CarrySystemInventoryTarget(self.sim, self.target, False, obj_with_inventory)
        else:
            runtime_slot = self.target.parent_slot
            if runtime_slot is not None:
                carry_system_target = CarrySystemRuntimeSlotTarget(self.sim, self.target, False, runtime_slot)
            if self.target.parent is not None:
                self.asm.set_actor('surface', self.target.parent)
        call_super = True
        if carry_system_target.has_custom_animation:

            def normal_carry_callback():
                arb = animation.arb.Arb()
                self.append_transition_to_arb(arb, source_posture, locked_params=locked_params, in_xevt_handler=True)
                ArbElement(arb).distribute()

            carry_system_target.append_custom_animation_to_arb(arb, self, normal_carry_callback)
            call_super = False
        arb.register_event_handler(carry_system_target.carry_event_callback, animation.ClipEventType.Script, carry.SCRIPT_EVENT_ID_START_CARRY)
        if call_super:
            super().append_transition_to_arb(arb, source_posture, locked_params=locked_params, in_xevt_handler=in_xevt_handler, **kwargs)
Ejemplo n.º 27
0
def generate_content_set(sim,
                         super_affordance,
                         super_interaction,
                         context,
                         potential_targets=(),
                         include_failed_aops_with_tooltip=False,
                         push_super_on_prepare=False,
                         check_posture_compatibility=False,
                         aop_kwargs=frozendict()):
    si_or_sa = super_interaction if super_interaction is not None else super_affordance
    if not si_or_sa.has_affordances():
        return ()
    yield_to_irq()
    phase_index = None
    if super_interaction and not _mixer_name_list:
        phase_index = super_interaction.phase_index
    valid = collections.defaultdict(list)
    if gsi_handlers.content_set_handlers.archiver.enabled:
        gsi_considered = {}
    else:
        gsi_considered = None
    if check_posture_compatibility and sim is not None and sim.posture.target is not None:
        show_posture_incompatible_icon = True
    else:
        show_posture_incompatible_icon = False
    if not si_or_sa.is_social or potential_targets:
        with sims4.callback_utils.invoke_enter_exit_callbacks(
                sims4.callback_utils.CallbackEvent.CONTENT_SET_GENERATE_ENTER,
                sims4.callback_utils.CallbackEvent.CONTENT_SET_GENERATE_EXIT):
            target_to_posture_icon_info = {}
            for affordance in si_or_sa.all_affordances_gen(
                    phase_index=phase_index):
                if affordance.is_super:
                    logger.error(
                        'Content set contains a super affordance: {} has {}',
                        si_or_sa, affordance)
                targets = _test_affordance_and_get_targets(
                    affordance,
                    potential_targets,
                    sim,
                    considered=gsi_considered)
                if targets is None:
                    pass
                for target in targets:
                    valid_aops_gen = get_valid_aops_gen(
                        target,
                        affordance,
                        super_affordance,
                        super_interaction,
                        context,
                        include_failed_aops_with_tooltip,
                        push_super_on_prepare=push_super_on_prepare,
                        considered=gsi_considered,
                        aop_kwargs=aop_kwargs)
                    for (aop, test_result) in valid_aops_gen:
                        if not aop.affordance.is_super:
                            aop_show_posture_incompatible_icon = False
                            if show_posture_incompatible_icon:
                                aop_show_posture_incompatible_icon = show_posture_incompatible_icon
                                if target not in target_to_posture_icon_info:
                                    if aop.compatible_with_current_posture_state(
                                            sim):
                                        aop_show_posture_incompatible_icon = False
                                    target_to_posture_icon_info[
                                        target] = aop_show_posture_incompatible_icon
                                else:
                                    aop_show_posture_incompatible_icon = target_to_posture_icon_info[
                                        target]
                            aop.show_posture_incompatible_icon = aop_show_posture_incompatible_icon
                            mixer_weight = aop.affordance.calculate_autonomy_weight(
                                sim)
                        else:
                            mixer_weight = 0
                        valid[affordance].append(
                            (mixer_weight, aop, test_result))
    if sim.posture.source_interaction is si_or_sa:
        for buff in sim.Buffs:
            buff_aops = get_buff_aops(sim,
                                      buff,
                                      sim.animation_interaction,
                                      context,
                                      potential_targets=potential_targets,
                                      gsi_considered=gsi_considered)
            while buff_aops:
                valid.update(buff_aops)
    if valid:
        return list(
            _select_affordances_gen(sim, super_affordance, valid,
                                    show_posture_incompatible_icon,
                                    gsi_considered))
    return ()
Ejemplo n.º 28
0
 def get_posture_specs_gen(self, interaction=None):
     for posture_manifest_entry in self.posture_manifest:
         var_map = {}
         (hand, carry_target) = posture_manifest_entry.carry_hand_and_target
         if hand is not None:
             allowed_hands = None
             if posture_manifest_entry.actor in _NOT_SPECIFIC_ACTOR:
                 carry_actor = interaction.sim if interaction is not None else None
             else:
                 carry_actor = posture_manifest_entry.actor
             if isinstance(
                     carry_target,
                 (str, Definition
                  )) or carry_target == AnimationParticipant.CREATE_TARGET:
                 carry = PostureAspectCarry(
                     (PostureSpecVariable.POSTURE_TYPE_CARRY_NOTHING, None,
                      PostureSpecVariable.HAND))
                 allowed_hands = carry_target.get_allowed_hands(carry_actor)
             else:
                 carry = PostureAspectCarry(
                     (PostureSpecVariable.POSTURE_TYPE_CARRY_OBJECT,
                      PostureSpecVariable.CARRY_TARGET,
                      PostureSpecVariable.HAND))
                 allowed_hands = carry_target.get_allowed_hands(carry_actor)
                 var_map[PostureSpecVariable.CARRY_TARGET] = carry_target
             if not not allowed_hands is not None and hand not in allowed_hands:
                 continue
             var_map[PostureSpecVariable.HAND] = hand
         else:
             carry = None
         surface_target = posture_manifest_entry.surface_target
         if surface_target is not None:
             surface_target = ANIMATION_PARTICIPANT_TO_POSTURE_SPEC_VARIABLE_MAP.get(
                 surface_target, PostureSpecVariable.SURFACE_TARGET)
         elif posture_manifest_entry.allow_surface:
             surface_target = PostureSpecVariable.ANYTHING
         else:
             surface_target = None
         carryable_surfaces = []
         other_surfaces = []
         for slot_manifest_entry in self.slot_manifest:
             slot_var_map = {}
             slot_var_map[PostureSpecVariable.SLOT] = slot_manifest_entry
             slot_type = PostureSpecVariable.SLOT
             slot_child = slot_manifest_entry.actor
             slot_parent = slot_manifest_entry.target
             slot_child_is_carryable = False
             slot_target = None
             if isinstance(slot_child, str):
                 slot_target = None
             elif isinstance(
                     slot_child, Definition
             ) or slot_child == AnimationParticipant.CREATE_TARGET:
                 slot_target = None
                 slot_var_map[
                     PostureSpecVariable.SLOT_TEST_DEFINITION] = slot_child
             elif hasattr(slot_child, 'manager'):
                 included_sis = []
                 if interaction.transition is not None:
                     included_sis = interaction.transition.get_included_sis(
                     ).union((interaction, ))
                 else:
                     included_sis = (interaction, )
                 slot_child_is_carryable = True if not interaction is not None or slot_child.has_component(
                     CARRYABLE_COMPONENT) else False
                 if slot_child_is_carryable and any(
                         included_si.carry_target is slot_child
                         for included_si in included_sis):
                     slot_var_map[
                         PostureSpecVariable.CARRY_TARGET] = slot_child
                     slot_target = ANIMATION_PARTICIPANT_TO_POSTURE_SPEC_VARIABLE_MAP.get(
                         slot_child, PostureSpecVariable.CARRY_TARGET)
                 elif any(included_si.target is slot_child
                          for included_si in included_sis):
                     slot_var_map[
                         PostureSpecVariable.SLOT_TARGET] = slot_child
                     slot_target = ANIMATION_PARTICIPANT_TO_POSTURE_SPEC_VARIABLE_MAP.get(
                         slot_child, PostureSpecVariable.SLOT_TARGET)
                 else:
                     logger.error(
                         "Interaction {} has a slot_manifest_entry {} with a slot_child {} that doesn't appear to be a carry target or an interaction target. Please grab Tom Astle and show this to him.",
                         interaction,
                         slot_manifest_entry,
                         slot_child,
                         owner='tastle')
             if not variables_match(surface_target, slot_parent):
                 logger.error(
                     "One of the slotting requirements for this posture_state_spec has a target different from the posture manifest's surface target.  This probably won't work: {} vs {} in {}",
                     surface_target,
                     slot_parent,
                     posture_manifest_entry,
                     owner='jpollak')
             surface = PostureAspectSurface(
                 (slot_parent, slot_type, slot_target))
             if slot_child_is_carryable:
                 carryable_surfaces.append((surface, slot_var_map))
             else:
                 other_surfaces.append((surface, slot_var_map))
         surface = None
         first_list_with_surfaces = carryable_surfaces or other_surfaces
         if first_list_with_surfaces:
             (surface, slot_var_map) = first_list_with_surfaces.pop()
             if carryable_surfaces:
                 logger.error(
                     'Multiple slot requirements for carryable targets, arbitrarily choosing one to manipulate in transition: {}',
                     posture_manifest_entry,
                     owner='jpollak')
                 other_surfaces.extend(carryable_surfaces)
             var_map.update(slot_var_map)
             var_map[PostureSpecVariable.
                     DESTINATION_FILTER] = functools.partial(
                         self._destination_filter, other_surfaces)
         elif surface_target == PostureSpecVariable.ANYTHING:
             surface = None
         elif surface_target == None:
             surface = PostureAspectSurface((None, None, None))
         else:
             surface = PostureAspectSurface((surface_target, None, None))
         if not posture_manifest_entry.posture_types:
             spec = PostureSpec((None, carry, surface))
             yield (spec, frozendict(var_map))
         else:
             if posture_manifest_entry.specific:
                 posture_types = posture_manifest_entry.posture_types
             elif posture_manifest_entry.family:
                 posture_types = [
                     posture_type for posture_type in
                     services.posture_manager().types.values()
                     if posture_type.family_name ==
                     posture_manifest_entry.family
                 ]
             else:
                 logger.error(
                     'Posture manifest entry has neither specific nor family.',
                     owner='bhill')
             for posture_type in posture_types:
                 target_object_filters = [
                     x.target_object_filter for x in self.posture_manifest
                     if x.target_object_filter is not MATCH_ANY
                 ]
                 if target_object_filters:
                     body = PostureAspectBody(
                         (posture_type,
                          PostureSpecVariable.BODY_TARGET_FILTERED))
                     var_map[
                         PostureSpecVariable.BODY_TARGET_FILTERED] = tuple(
                             target_object_filters)
                 else:
                     body = PostureAspectBody(
                         (posture_type, self.body_target))
                 spec = PostureSpec((body, carry, surface))
                 yield (spec, frozendict(var_map))
Ejemplo n.º 29
0
        self.sim.routing_component.on_slot = None
        result = yield from super()._run_interaction_gen(timeline)
        if not result:
            return False
            yield
        elif self._run_element is not None:
            result = yield from element_utils.run_child(
                timeline, self._run_element)
            return result
            yield
        return True
        yield


lock_instance_tunables(SitOrStandSuperInteraction,
                       _constraints=frozendict(),
                       _constraints_actor=ParticipantType.Object)


class SatisfyConstraintSuperInteraction(SitOrStandSuperInteraction):
    INSTANCE_SUBCLASSES_ONLY = True


create_tuningless_superinteraction(SatisfyConstraintSuperInteraction)


class ForceSatisfyConstraintSuperInteraction(SatisfyConstraintSuperInteraction
                                             ):
    INSTANCE_SUBCLASSES_ONLY = True

    @classmethod
Ejemplo n.º 30
0
 def post_load(cls, manager):
     species_to_provided_postures = {}
     for (species, provided_postures,
          _) in cls._animation_data.get_supported_postures_gen():
         species_to_provided_postures[species] = provided_postures
     cls._provided_postures = frozendict(species_to_provided_postures)
Ejemplo n.º 31
0
 def __init__(self, sim, constraint, geometry, los_reference_point=None, routing_surface_override=None, locked_params=frozendict(), target=None, weight_route_factor=1.0):
     self.routing_surface = sim.routing_surface if constraint.routing_surface is None else constraint.routing_surface
     if routing_surface_override is not None:
         self.routing_surface = routing_surface_override
     self.routing_surface_override = routing_surface_override
     super().__init__(geometry.polygon, self.routing_surface)
     self.locked_params = locked_params
     self.sim = sim
     self.constraint = constraint
     self.geometry = geometry
     self.los_reference_point = los_reference_point
     self.target = target
     self.weight_route_factor = weight_route_factor
Ejemplo n.º 32
0
    def _do_transition(self, timeline) -> bool:
        source = self._source
        dest = self._dest
        sim = dest.sim
        posture_track = dest.track
        starting_position = sim.position

        def do_auto_exit(timeline):
            auto_exit_element = get_auto_exit((sim,), asm=source.asm)
            if auto_exit_element is not None:
                yield element_utils.run_child(timeline, auto_exit_element)

        arb = animation.arb.Arb()
        if dest.external_transition:
            dest_begin = dest.begin(None, self._dest_state, self._context)
            result = yield element_utils.run_child(timeline, must_run(dest_begin))
            return result
        try:
            sim.active_transition = self
            posture_idle_started = False

            def start_posture_idle(*_, **__):
                nonlocal posture_idle_started
                if posture_idle_started:
                    return
                dest.log_info('Idle')
                posture_idle_started = True
                idle_arb = animation.arb.Arb()
                dest.append_idle_to_arb(idle_arb)
                ArbElement(idle_arb, master=sim).distribute()

            arb.register_event_handler(start_posture_idle, handler_id=self.IDLE_TRANSITION_XEVT)
            if sim.posture.mobile and self._transition_spec.path is not None:
                yield element_utils.run_child(timeline, do_auto_exit)
                result = yield self.do_transition_route(timeline, sim, source, dest)
                if not result:
                    return result
            else:
                result = self._transition_spec.do_reservation(sim)
                if not result:
                    return result
            if self._transition_spec is not None and self._transition_spec.portal is not None:
                portal_transition = self._transition_spec.portal.get_portal_element(sim)
                yield element_utils.run_child(timeline, portal_transition)
            if source is dest:
                sim.on_posture_event(PostureEvent.POSTURE_CHANGED, self._dest_state, dest.track, source, dest)
                return TestResult.TRUE
            self._status = self.Status.ANIMATING
            source_locked_params = frozendict()
            dest_locked_params = frozendict()
            dest_posture_spec = None
            if self._transition_spec is not None and dest.track == PostureTrack.BODY:
                if not source.mobile:
                    source_locked_params = self._transition_spec.locked_params
                if not dest.mobile:
                    dest_locked_params = self._transition_spec.locked_params
                    if self._interaction is not None:
                        dest_locked_params += self._interaction.transition_asm_params
                dest_posture_spec = self._transition_spec.posture_spec

            def do_transition_animation(timeline):
                yield element_utils.run_child(timeline, do_auto_exit)
                source.append_exit_to_arb(arb, self._dest_state, dest, self._var_map, locked_params=source_locked_params)
                dest.append_transition_to_arb(arb, source, locked_params=dest_locked_params, posture_spec=dest_posture_spec)
                dest_begin = dest.begin(arb, self._dest_state, self._context)
                result = yield element_utils.run_child(timeline, [do_auto_exit, dest_begin])
                return result

            sequence = (do_transition_animation,)
            from carry import interact_with_carried_object, holster_carried_object
            if dest.track.is_carry(dest.track):
                if dest.target is not None:
                    carry_target = dest.target
                    carry_posture_state = self._dest_state
                    carry_animation_context = dest.asm.context
                else:
                    carry_target = source.target
                    carry_posture_state = sim.posture_state
                    carry_animation_context = source.asm.context
                sequence = interact_with_carried_object(sim, carry_target, posture_state=carry_posture_state, interaction=dest.source_interaction, animation_context=carry_animation_context, sequence=sequence)
            sequence = holster_carried_object(sim, dest.source_interaction, self._get_unholster_predicate(sim, dest.source_interaction), flush_before_sequence=True, sequence=sequence)
            sequence = dest.add_transition_extras(sequence)
            sis = set()
            sis.add(source.source_interaction)
            sis.add(dest.source_interaction)
            sis.update(source.owning_interactions)
            sis.update(dest.owning_interactions)
            for si in sis:
                if si is None:
                    pass
                with si.cancel_deferred(sis):
                    result = yield element_utils.run_child(timeline, must_run(sequence))
                break
            result = yield element_utils.run_child(timeline, must_run(sequence))
            if result:
                start_posture_idle()
            yield sim.si_state.process_gen(timeline)
        finally:
            sim.active_transition = None
            self._status = self.Status.FINISHED
            if self._transition_spec is not None:
                self._transition_spec.release_additional_reservation_handlers()
                self._transition_spec.remove_props_created_to_reserve_slots(sim)
        if sim.posture_state.get_aspect(posture_track) is not dest:
            logger.debug("{}: _do_transition failed: after transition Sim's posture state aspect isn't destination posture.")
            if dest.source_interaction is not None:
                dest.source_interaction.cancel(FinishingType.TRANSITION_FAILURE, cancel_reason_msg='Transition canceled during transition.')
            return TestResult(False, "After transition Sim's posture state aspect isn't destination posture.")
        if not dest.unconstrained and sim.transition_controller is not None and not sims4.math.vector3_almost_equal(sim.position, starting_position, epsilon=sims4.geometry.ANIMATION_SLOT_EPSILON):
            sim.transition_controller.release_stand_slot_reservations((sim,))
        return TestResult.TRUE
Ejemplo n.º 33
0
    def _do_transition(self, timeline) -> bool:
        source = self._source
        dest = self._dest
        sim = dest.sim
        posture_track = dest.track
        starting_position = sim.position

        def do_auto_exit(timeline):
            auto_exit_element = get_auto_exit((sim, ), asm=source.asm)
            if auto_exit_element is not None:
                yield from element_utils.run_child(timeline, auto_exit_element)

        if self._transition_spec is not None and self._transition_spec.portal_obj is not None:
            portal_obj = self._transition_spec.portal_obj
            if self._transition_spec.portal_id is not None:
                new_routing_surface = portal_obj.get_target_surface(
                    self._transition_spec.portal_id)
        elif not dest.unconstrained and dest.target is not None:
            new_routing_surface = dest.target.routing_surface
        elif self._constraint is not None:
            new_routing_surface = self._constraint.routing_surface
        else:
            new_routing_surface = sim.routing_surface
        arb = animation.arb.Arb()
        if dest.external_transition:
            dest_begin = dest.begin(None, self._dest_state, self._context,
                                    new_routing_surface)
            result = yield from element_utils.run_child(
                timeline, must_run(dest_begin))
            return result
            yield
        try:
            sim.active_transition = self
            posture_idle_started = False

            def start_posture_idle(*_, **__):
                nonlocal posture_idle_started
                if posture_idle_started:
                    return
                dest.log_info('Idle')
                posture_idle_started = True
                idle_arb = animation.arb.Arb()
                dest.append_idle_to_arb(idle_arb)
                distribute_arb_element(idle_arb, master=sim)

            arb.register_event_handler(start_posture_idle,
                                       handler_id=self.IDLE_TRANSITION_XEVT)
            if self._transition_spec is not None:
                if sim.posture.mobile and self._transition_spec.path is not None:
                    yield from element_utils.run_child(timeline, do_auto_exit)
                    result = yield from self.do_transition_route(
                        timeline, sim, source, dest)
                    if not result:
                        if self._transition_spec.is_failure_path:
                            (
                                failure_reason, failure_target
                            ) = sim.transition_controller.get_failure_reason_and_target(
                                sim)
                            if failure_reason is not None or failure_target is not None:
                                if self._interaction is not None:
                                    yield from element_utils.run_child(
                                        timeline,
                                        handle_transition_failure(
                                            sim,
                                            self._interaction.target,
                                            self._interaction,
                                            failure_reason=failure_reason,
                                            failure_object_id=failure_target))
                                sim.transition_controller.cancel(
                                    cancel_reason_msg=
                                    'Transition canceled due to successful route failure.'
                                )
                        return result
                        yield
                else:
                    result = self._transition_spec.do_reservation(sim)
                    if not result:
                        return result
                        yield
            if source is dest:
                sim.on_posture_event(PostureEvent.POSTURE_CHANGED,
                                     self._dest_state, dest.track, source,
                                     dest)
                return TestResult.TRUE
                yield
            self._status = self.Status.ANIMATING
            source_locked_params = frozendict()
            dest_locked_params = frozendict()
            if self._transition_spec is not None:
                source_locked_params = self._transition_spec.locked_params
                dest_locked_params = self._transition_spec.locked_params
            dest_posture_spec = None
            import services
            zone = services.current_zone()
            fire_service = services.get_fire_service()
            lot_on_fire = fire_service.fire_is_active
            distance_param = PostureTransition.calculate_distance_param(
                source.target, dest.target)
            if self._transition_spec is not None:
                if dest.track == PostureTrack.BODY:
                    if not source.mobile:
                        source_locked_params += {'onFire': lot_on_fire}
                        if distance_param is not None:
                            source_locked_params += {
                                'distance': distance_param
                            }
                    if not dest.mobile:
                        dest_locked_params += {'onFire': lot_on_fire}
                        if self._interaction is not None:
                            transition_asm_params = sim.get_transition_asm_params(
                            )
                            dest_locked_params += transition_asm_params
                            source_locked_params += transition_asm_params
                        if distance_param is not None:
                            dest_locked_params += {'distance': distance_param}
                    elif self._transition_spec.portal_obj is not None:
                        transition_asm_params = sim.get_transition_asm_params()
                        dest_locked_params += transition_asm_params
                        source_locked_params += transition_asm_params
                    transition_global_asm_params = sim.get_transition_global_asm_params(
                    )
                    dest_locked_params += transition_global_asm_params
                    source_locked_params += transition_global_asm_params
                    dest_posture_spec = self._transition_spec.posture_spec
            source_locked_params += self._locked_params
            dest_locked_params += self._locked_params
            if self._transition_spec is not None and self._transition_spec.portal_obj is not None:
                target_override = self._transition_spec.portal_obj
                portal_params = self._transition_spec.portal_obj.get_portal_asm_params(
                    self._transition_spec.portal_id, sim)
                source_locked_params += portal_params
                dest_locked_params += portal_params
            else:
                target_override = None

            def do_transition_animation(timeline):
                yield from element_utils.run_child(timeline, do_auto_exit)
                if PostureTrack.is_carry(
                        dest.track
                ) and dest.target is not None and dest.target.is_sim:
                    auto_exit_element = get_auto_exit((dest.target, ),
                                                      asm=source.asm)
                    if auto_exit_element is not None:
                        yield from element_utils.run_child(
                            timeline, auto_exit_element)
                source.append_exit_to_arb(arb,
                                          self._dest_state,
                                          dest,
                                          self._var_map,
                                          locked_params=source_locked_params,
                                          target_override=target_override)
                dest.append_transition_to_arb(arb,
                                              source,
                                              locked_params=dest_locked_params,
                                              posture_spec=dest_posture_spec,
                                              target_override=target_override)
                dest_begin = dest.begin(arb, self._dest_state, self._context,
                                        new_routing_surface)
                result = yield from element_utils.run_child(
                    timeline, [do_auto_exit, dest_begin])
                return result
                yield

            sequence = (do_transition_animation, )
            from carry.carry_utils import interact_with_carried_object, holster_carried_object, maybe_holster_objects_through_sequence
            if dest.track.is_carry(dest.track):
                if dest.target is not None:
                    carry_target = dest.target
                    carry_posture_state = self._dest_state
                    carry_animation_context = dest.asm.context
                else:
                    carry_target = source.target
                    carry_posture_state = sim.posture_state
                    carry_animation_context = source.asm.context
                sequence = interact_with_carried_object(
                    sim,
                    carry_target,
                    posture_state=carry_posture_state,
                    interaction=dest.source_interaction,
                    animation_context=carry_animation_context,
                    sequence=sequence)
            if sim.is_required_to_holster_for_transition(source, dest):
                sequence = maybe_holster_objects_through_sequence(
                    sim,
                    sequence=sequence,
                    unholster_after_predicate=self.
                    _get_unholster_after_predicate(sim,
                                                   dest.source_interaction))
            else:
                sequence = holster_carried_object(
                    sim,
                    dest.source_interaction,
                    self._get_unholster_predicate(sim,
                                                  dest.source_interaction),
                    flush_before_sequence=True,
                    sequence=sequence)
            sequence = dest.add_transition_extras(sequence, arb=arb)
            mutex_key = self.get_entry_exit_mutex_key()
            if mutex_key is not None:
                sequence = mutex.with_mutex(
                    mutex_key, element_utils.build_element(sequence))
            sis = set()
            sis.add(source.source_interaction)
            sis.add(dest.source_interaction)
            sis.update(source.owning_interactions)
            sis.update(dest.owning_interactions)
            for si in sis:
                if si is None:
                    continue
                with si.cancel_deferred(sis):
                    result = yield from element_utils.run_child(
                        timeline, must_run(sequence))
                break
            else:
                result = yield from element_utils.run_child(
                    timeline, must_run(sequence))
            if result:
                start_posture_idle()
            yield from sim.si_state.process_gen(timeline)
        finally:
            sim.active_transition = None
            self._status = self.Status.FINISHED
            if self._transition_spec is not None:
                self._transition_spec.release_additional_reservation_handlers()
                self._transition_spec.remove_props_created_to_reserve_slots(
                    sim)
                if self._transition_spec.portal_obj is not None:
                    self._transition_spec.portal_obj.clear_portal_cost_override(
                        self._transition_spec.portal_id, sim=sim)
        if sim.posture_state.get_aspect(posture_track) is not dest:
            logger.debug(
                "{}: _do_transition failed: after transition Sim's posture state aspect isn't destination posture."
            )
            if dest.source_interaction is not None:
                dest.source_interaction.cancel(
                    FinishingType.TRANSITION_FAILURE,
                    cancel_reason_msg='Transition canceled during transition.')
            return TestResult(
                False,
                "After transition Sim's posture state aspect isn't destination posture."
            )
            yield
        if not dest.unconstrained and not not (
                sim.transition_controller is not None
                and sims4.math.vector3_almost_equal(
                    sim.position,
                    starting_position,
                    epsilon=sims4.geometry.ANIMATION_SLOT_EPSILON)):
            sim.transition_controller.release_stand_slot_reservations((sim, ))
        return TestResult.TRUE
        yield
Ejemplo n.º 34
0
 def _create_containment_slot_data_list(self, key, actor, actor_name, to_state_name, from_state_name, posture, entry, verbose_logging):
     cache_containment_slot_data_list = True
     param_sequence_list = self._get_param_sequences_for_cache(actor, actor_name, to_state_name, from_state_name, posture)
     boundary_to_params = {}
     for param_sequence in param_sequence_list:
         self.set_param_sequence(param_sequence)
         yield_to_irq()
         if verbose_logging:
             logger.warn('  Setting parameter list on ASM:')
             for (key, value) in param_sequence.items():
                 logger.warn('    {}:\t{}', key, value)
         boundary = self.get_boundary_conditions(actor, to_state_name, from_state_name)
         boundary.debug_info = None
         pre_condition_reference_object_name = self.get_actor_name_from_id(boundary.pre_condition_reference_object_id)
         post_condition_reference_object_name = self.get_actor_name_from_id(boundary.post_condition_reference_object_id)
         if verbose_logging:
             logger.warn('    Pre conditions')
             logger.warn('      Object: {}', pre_condition_reference_object_name)
             logger.warn('      Translation: {}', boundary.pre_condition_transform.translation)
             logger.warn('      Orientation: {}', boundary.pre_condition_transform.orientation)
             logger.warn('    Post conditions')
             logger.warn('      Object: {}', post_condition_reference_object_name)
             logger.warn('      Translation: {}', boundary.post_condition_transform.translation)
             logger.warn('      Orientation: {}', boundary.post_condition_transform.orientation)
         required_slots = []
         currently_set_actor_names = self._get_all_set_actor_names()
         if boundary.required_slots:
             for required_slot in boundary.required_slots:
                 pre_condition_surface_child_id = required_slot[0]
                 pre_condition_surface_object_id = required_slot[1]
                 pre_condition_surface_child_name = self.get_actor_name_from_id(pre_condition_surface_child_id)
                 pre_condition_surface_object_name = self.get_actor_name_from_id(pre_condition_surface_object_id)
                 if pre_condition_surface_child_name and pre_condition_surface_object_name:
                     required_slots.append((pre_condition_surface_child_name, pre_condition_surface_object_name, required_slot[2]))
                 else:
                     cache_containment_slot_data_list = False
                     self._log_bc_error(logger.error, currently_set_actor_names, key, 'missing parent or child object', "The parent or child in Maya isn't one of the following actors:")
         if not required_slots and boundary.pre_condition_reference_object_id is None:
             pass
         if boundary.pre_condition_reference_object_id is not None and pre_condition_reference_object_name is None:
             pass
         for (boundary_existing, params_list) in boundary_to_params.items():
             while pre_condition_reference_object_name == boundary_existing.pre_condition_reference_object_name and (post_condition_reference_object_name == boundary_existing.post_condition_reference_object_name and (self.transform_almost_equal_2d(boundary.pre_condition_transform, boundary_existing.pre_condition_transform) and self.transform_almost_equal_2d(boundary.post_condition_transform, boundary_existing.post_condition_transform))) and required_slots == boundary_existing.required_slots:
                 params_list.append(param_sequence)
                 break
         boundary_relative = self.BoundaryConditionRelative(pre_condition_reference_object_name, boundary.pre_condition_transform, post_condition_reference_object_name, boundary.post_condition_transform, required_slots, boundary.debug_info)
         boundary_to_params[boundary_relative] = [param_sequence]
     if verbose_logging:
         logger.warn('  Boundary -> Param Sequences')
         for (key, value) in boundary_to_params.items():
             logger.warn('    {}', key)
             for param_sequence in value:
                 logger.warn('      {}', param_sequence)
     boundary_list = []
     if len(boundary_to_params) > 0:
         if len(boundary_to_params) == 1:
             boundary_list.append((boundary_to_params.popitem()[0], [{}]))
         else:
             boundary_param_sets = partition_boundary_on_params(boundary_to_params)
             for (boundary, param_set) in boundary_param_sets.items():
                 boundary_params_list_minimal = {frozendict({k: v for (k, v) in boundary_params.items() if k in param_set}) for boundary_params in boundary_to_params[boundary]}
                 boundary_list.append((boundary, boundary_params_list_minimal))
     relative_object_name = None
     containment_slot_data_list = []
     for (boundary_condition, slot_params_list) in boundary_list:
         relative_object_name_key = boundary_condition.pre_condition_reference_object_name or boundary_condition.post_condition_reference_object_name
         if entry:
             if boundary_condition.post_condition_reference_object_name is not None:
                 containment_transform = boundary_condition.post_condition_transform
             else:
                 containment_transform = boundary_condition.pre_condition_transform
         else:
             containment_transform = boundary_condition.pre_condition_transform
         for (containment_transform_existing, slots_to_params) in containment_slot_data_list:
             while self.transform_almost_equal_2d(containment_transform, containment_transform_existing):
                 slots_to_params.append((boundary_condition, slot_params_list))
                 break
         containment_slot_data_list.append((containment_transform, [(boundary_condition, slot_params_list)]))
     if cache_containment_slot_data_list:
         self._bc_cache[key] = tuple(containment_slot_data_list)
     return containment_slot_data_list
Ejemplo n.º 35
0
def generate_content_set(sim, super_affordance, super_interaction, context, potential_targets=(), include_failed_aops_with_tooltip=False, push_super_on_prepare=False, check_posture_compatibility=False, aop_kwargs=frozendict()):
    si_or_sa = super_interaction if super_interaction is not None else super_affordance
    if not si_or_sa.has_affordances():
        return ()
    yield_to_irq()
    phase_index = None
    if super_interaction and not _mixer_name_list:
        phase_index = super_interaction.phase_index
    valid = collections.defaultdict(list)
    if gsi_handlers.content_set_handlers.archiver.enabled:
        gsi_considered = {}
    else:
        gsi_considered = None
    if check_posture_compatibility and sim is not None and sim.posture.target is not None:
        show_posture_incompatible_icon = True
    else:
        show_posture_incompatible_icon = False
    if not si_or_sa.is_social or potential_targets:
        with sims4.callback_utils.invoke_enter_exit_callbacks(sims4.callback_utils.CallbackEvent.CONTENT_SET_GENERATE_ENTER, sims4.callback_utils.CallbackEvent.CONTENT_SET_GENERATE_EXIT):
            target_to_posture_icon_info = {}
            for affordance in si_or_sa.all_affordances_gen(phase_index=phase_index):
                if affordance.is_super:
                    logger.error('Content set contains a super affordance: {} has {}', si_or_sa, affordance)
                targets = _test_affordance_and_get_targets(affordance, potential_targets, sim, considered=gsi_considered)
                if targets is None:
                    pass
                for target in targets:
                    valid_aops_gen = get_valid_aops_gen(target, affordance, super_affordance, super_interaction, context, include_failed_aops_with_tooltip, push_super_on_prepare=push_super_on_prepare, considered=gsi_considered, aop_kwargs=aop_kwargs)
                    for (aop, test_result) in valid_aops_gen:
                        if not aop.affordance.is_super:
                            aop_show_posture_incompatible_icon = False
                            if show_posture_incompatible_icon:
                                aop_show_posture_incompatible_icon = show_posture_incompatible_icon
                                if target not in target_to_posture_icon_info:
                                    if aop.compatible_with_current_posture_state(sim):
                                        aop_show_posture_incompatible_icon = False
                                    target_to_posture_icon_info[target] = aop_show_posture_incompatible_icon
                                else:
                                    aop_show_posture_incompatible_icon = target_to_posture_icon_info[target]
                            aop.show_posture_incompatible_icon = aop_show_posture_incompatible_icon
                            mixer_weight = aop.affordance.calculate_autonomy_weight(sim)
                        else:
                            mixer_weight = 0
                        valid[affordance].append((mixer_weight, aop, test_result))
    if sim.posture.source_interaction is si_or_sa:
        for buff in sim.Buffs:
            buff_aops = get_buff_aops(sim, buff, sim.animation_interaction, context, potential_targets=potential_targets, gsi_considered=gsi_considered)
            while buff_aops:
                valid.update(buff_aops)
    if valid:
        return list(_select_affordances_gen(sim, super_affordance, valid, show_posture_incompatible_icon, gsi_considered))
    return ()
Ejemplo n.º 36
0
 def get_posture_specs_gen(self):
     for posture_manifest_entry in self.posture_manifest:
         var_map = {}
         if posture_manifest_entry.posture_types:
             posture_type = posture_manifest_entry.posture_types[0]
             body = PostureAspectBody((posture_type, self.body_target))
         else:
             body = None
         (hand, carry_target) = posture_manifest_entry.carry_hand_and_target
         if hand is not None:
             allowed_hands = None
             if isinstance(carry_target, (str, Definition)) or carry_target == AnimationParticipant.CREATE_TARGET:
                 carry = PostureAspectCarry((PostureSpecVariable.POSTURE_TYPE_CARRY_NOTHING, None, PostureSpecVariable.HAND))
                 if isinstance(carry_target, Definition):
                     allowed_hands = carry_target.cls.allowed_hands
             else:
                 carry = PostureAspectCarry((PostureSpecVariable.POSTURE_TYPE_CARRY_OBJECT, PostureSpecVariable.CARRY_TARGET, PostureSpecVariable.HAND))
                 if hasattr(carry_target, 'manager'):
                     allowed_hands = carry_target.allowed_hands
                     var_map[PostureSpecVariable.CARRY_TARGET] = carry_target
             if allowed_hands is not None and hand not in allowed_hands:
                 pass
             var_map[PostureSpecVariable.HAND] = hand
         else:
             carry = None
         surface_target = posture_manifest_entry.surface_target
         if surface_target is not None:
             surface_target = ANIMATION_PARTICIPANT_TO_POSTURE_SPEC_VARIABLE_MAP.get(surface_target, PostureSpecVariable.SURFACE_TARGET)
         elif posture_manifest_entry.allow_surface:
             surface_target = PostureSpecVariable.ANYTHING
         else:
             surface_target = None
         carryable_surfaces = []
         other_surfaces = []
         for slot_manifest_entry in self.slot_manifest:
             slot_var_map = {}
             slot_var_map[PostureSpecVariable.SLOT] = slot_manifest_entry
             slot_type = PostureSpecVariable.SLOT
             slot_child = slot_manifest_entry.actor
             slot_parent = slot_manifest_entry.target
             slot_child_is_carryable = False
             if isinstance(slot_child, str):
                 slot_target = None
             elif isinstance(slot_child, Definition) or slot_child == AnimationParticipant.CREATE_TARGET:
                 slot_target = None
                 slot_var_map[PostureSpecVariable.SLOT_TEST_DEFINITION] = slot_child
             else:
                 slot_target = ANIMATION_PARTICIPANT_TO_POSTURE_SPEC_VARIABLE_MAP.get(slot_child, PostureSpecVariable.CARRY_TARGET)
                 if hasattr(slot_child, 'manager'):
                     slot_var_map[PostureSpecVariable.CARRY_TARGET] = slot_child
                     slot_child_is_carryable = True if slot_child.has_component(CARRYABLE_COMPONENT) else False
             if not variables_match(surface_target, slot_parent):
                 logger.error("One of the slotting requirements for this posture_state_spec has a target different from the posture manifest's surface target.  This probably won't work: {} vs {} in {}", surface_target, slot_parent, posture_manifest_entry, owner='jpollak')
             surface = PostureAspectSurface((slot_parent, slot_type, slot_target))
             if slot_child_is_carryable:
                 carryable_surfaces.append((surface, slot_var_map))
             else:
                 other_surfaces.append((surface, slot_var_map))
         surface = None
         first_list_with_surfaces = carryable_surfaces or other_surfaces
         if first_list_with_surfaces:
             (surface, slot_var_map) = first_list_with_surfaces.pop()
             if carryable_surfaces:
                 logger.error('Multiple slot requirements for carryable targets, arbitrarily choosing one to manipulate in transition: {}', posture_manifest_entry, owner='jpollak')
                 other_surfaces.extend(carryable_surfaces)
             var_map.update(slot_var_map)
             var_map[PostureSpecVariable.DESTINATION_FILTER] = functools.partial(self._destination_filter, other_surfaces)
         elif surface_target == PostureSpecVariable.ANYTHING:
             surface = None
         elif surface_target == None:
             surface = PostureAspectSurface((None, None, None))
         else:
             surface = PostureAspectSurface((surface_target, None, None))
         spec = PostureSpec((body, carry, surface))
         yield (spec, frozendict(var_map))
Ejemplo n.º 37
0
 def get_posture_specs_gen(self):
     for posture_manifest_entry in self.posture_manifest:
         var_map = {}
         if posture_manifest_entry.posture_types:
             posture_type = posture_manifest_entry.posture_types[0]
             body = PostureAspectBody((posture_type, self.body_target))
         else:
             body = None
         (hand, carry_target) = posture_manifest_entry.carry_hand_and_target
         if hand is not None:
             allowed_hands = None
             if isinstance(
                     carry_target,
                 (str, Definition
                  )) or carry_target == AnimationParticipant.CREATE_TARGET:
                 carry = PostureAspectCarry(
                     (PostureSpecVariable.POSTURE_TYPE_CARRY_NOTHING, None,
                      PostureSpecVariable.HAND))
                 if isinstance(carry_target, Definition):
                     allowed_hands = carry_target.cls.allowed_hands
             else:
                 carry = PostureAspectCarry(
                     (PostureSpecVariable.POSTURE_TYPE_CARRY_OBJECT,
                      PostureSpecVariable.CARRY_TARGET,
                      PostureSpecVariable.HAND))
                 if hasattr(carry_target, 'manager'):
                     allowed_hands = carry_target.allowed_hands
                     var_map[
                         PostureSpecVariable.CARRY_TARGET] = carry_target
             if allowed_hands is not None and hand not in allowed_hands:
                 pass
             var_map[PostureSpecVariable.HAND] = hand
         else:
             carry = None
         surface_target = posture_manifest_entry.surface_target
         if surface_target is not None:
             surface_target = ANIMATION_PARTICIPANT_TO_POSTURE_SPEC_VARIABLE_MAP.get(
                 surface_target, PostureSpecVariable.SURFACE_TARGET)
         elif posture_manifest_entry.allow_surface:
             surface_target = PostureSpecVariable.ANYTHING
         else:
             surface_target = None
         carryable_surfaces = []
         other_surfaces = []
         for slot_manifest_entry in self.slot_manifest:
             slot_var_map = {}
             slot_var_map[PostureSpecVariable.SLOT] = slot_manifest_entry
             slot_type = PostureSpecVariable.SLOT
             slot_child = slot_manifest_entry.actor
             slot_parent = slot_manifest_entry.target
             slot_child_is_carryable = False
             if isinstance(slot_child, str):
                 slot_target = None
             elif isinstance(
                     slot_child, Definition
             ) or slot_child == AnimationParticipant.CREATE_TARGET:
                 slot_target = None
                 slot_var_map[
                     PostureSpecVariable.SLOT_TEST_DEFINITION] = slot_child
             else:
                 slot_target = ANIMATION_PARTICIPANT_TO_POSTURE_SPEC_VARIABLE_MAP.get(
                     slot_child, PostureSpecVariable.CARRY_TARGET)
                 if hasattr(slot_child, 'manager'):
                     slot_var_map[
                         PostureSpecVariable.CARRY_TARGET] = slot_child
                     slot_child_is_carryable = True if slot_child.has_component(
                         CARRYABLE_COMPONENT) else False
             if not variables_match(surface_target, slot_parent):
                 logger.error(
                     "One of the slotting requirements for this posture_state_spec has a target different from the posture manifest's surface target.  This probably won't work: {} vs {} in {}",
                     surface_target,
                     slot_parent,
                     posture_manifest_entry,
                     owner='jpollak')
             surface = PostureAspectSurface(
                 (slot_parent, slot_type, slot_target))
             if slot_child_is_carryable:
                 carryable_surfaces.append((surface, slot_var_map))
             else:
                 other_surfaces.append((surface, slot_var_map))
         surface = None
         first_list_with_surfaces = carryable_surfaces or other_surfaces
         if first_list_with_surfaces:
             (surface, slot_var_map) = first_list_with_surfaces.pop()
             if carryable_surfaces:
                 logger.error(
                     'Multiple slot requirements for carryable targets, arbitrarily choosing one to manipulate in transition: {}',
                     posture_manifest_entry,
                     owner='jpollak')
                 other_surfaces.extend(carryable_surfaces)
             var_map.update(slot_var_map)
             var_map[PostureSpecVariable.
                     DESTINATION_FILTER] = functools.partial(
                         self._destination_filter, other_surfaces)
         elif surface_target == PostureSpecVariable.ANYTHING:
             surface = None
         elif surface_target == None:
             surface = PostureAspectSurface((None, None, None))
         else:
             surface = PostureAspectSurface((surface_target, None, None))
         spec = PostureSpec((body, carry, surface))
         yield (spec, frozendict(var_map))
Ejemplo n.º 38
0
 def get_boundary_conditions_list(self, actor, to_state_name, from_state_name=DEFAULT, entry=True, locked_params=frozendict(), posture=DEFAULT):
     if from_state_name is DEFAULT:
         from_state_name = 'entry'
     boundary_list = self._make_boundary_conditions_list(actor, to_state_name, from_state_name, locked_params, entry=entry, posture=posture)
     return boundary_list
Ejemplo n.º 39
0
    def __init__(self,
                 sim,
                 current_posture_state,
                 posture_spec,
                 var_map,
                 invalid_expected=False,
                 body_state_spec_only=False,
                 carry_posture_overrides=frozendict(),
                 is_throwaway=False):
        def _get_default_carry_aspect(track):
            if track in carry_posture_overrides:
                return carry_posture_overrides[track]
            return postures.create_posture(
                CarryPostureStaticTuning.POSTURE_CARRY_NOTHING,
                sim,
                None,
                track=track)

        self._constraint_intersection = None
        self._constraint_intersection_dirty = True
        self._spec = posture_spec
        self._sim_ref = sim.ref()
        self._linked_posture_state = None
        self._valid = True
        self._constraints = {}
        self._invalid_expected = invalid_expected
        self.body_state_spec_only = body_state_spec_only
        self._posture_constraint = None
        self._posture_constraint_strict = None
        body_index = BODY_INDEX
        body_posture_type_index = BODY_POSTURE_TYPE_INDEX
        body_target_index = BODY_TARGET_INDEX
        spec_body = posture_spec[body_index]
        self.body_target = spec_body[body_target_index]
        if current_posture_state is None or spec_body[
                body_posture_type_index] != current_posture_state.body.posture_type or spec_body[
                    body_target_index] != current_posture_state.body.target:
            animation_context = None
            if current_posture_state is not None:
                if not current_posture_state.body.mobile:
                    if not spec_body[body_posture_type_index].mobile:
                        animation_context = current_posture_state.body.animation_context
            self._aspect_body = postures.create_posture(
                spec_body[body_posture_type_index],
                self.sim,
                self.body_target,
                animation_context=animation_context,
                is_throwaway=is_throwaway)
        else:
            self._aspect_body = current_posture_state.body
        posture_manifest = self._aspect_body.get_provided_postures(
            surface_target=self.surface_target, concrete=True)
        posture_manifest = posture_manifest.get_constraint_version(self.sim)
        posture_state_spec = PostureStateSpec(
            posture_manifest, SlotManifest(), self._aspect_body.target
            or PostureSpecVariable.ANYTHING)
        self.body_posture_state_constraint = Constraint(
            debug_name='PostureStateManifestConstraint',
            posture_state_spec=posture_state_spec)
        if body_state_spec_only:
            self._constraints[None] = self.body_posture_state_constraint
            return
        body_slot_constraint = self._aspect_body.slot_constraint
        if not (body_slot_constraint is not None and
                (self._aspect_body.is_vehicle and current_posture_state
                 is not None) and current_posture_state.body.is_vehicle):
            body_posture_constraint = self.body_posture_state_constraint.intersect(
                body_slot_constraint)
        else:
            body_posture_constraint = self.body_posture_state_constraint
        self._constraints[None] = body_posture_constraint
        if current_posture_state is not None:
            curr_spec_carry_target = current_posture_state.get_posture_spec(
                var_map)[CARRY_INDEX][CARRY_TARGET_INDEX]
        spec_carry = posture_spec[CARRY_INDEX]
        spec_carry_target = spec_carry[CARRY_TARGET_INDEX]
        if current_posture_state is not None and spec_carry_target != curr_spec_carry_target:
            if spec_carry_target is None:
                current_carry_target = var_map.get(curr_spec_carry_target)
                current_carry_track = current_posture_state.get_carry_track(
                    current_carry_target)
                if current_carry_track == PostureTrack.RIGHT:
                    self._aspect_carry_right = _get_default_carry_aspect(
                        PostureTrack.RIGHT)
                    self._aspect_carry_left = current_posture_state.left
                else:
                    self._aspect_carry_left = _get_default_carry_aspect(
                        PostureTrack.LEFT)
                    self._aspect_carry_right = current_posture_state.right
            else:
                spec_carry_posture_type = spec_carry[CARRY_POSTURE_TYPE_INDEX]
                if spec_carry_target not in var_map:
                    raise KeyError(
                        'spec_carry_target {} not in var_map:{}. Sim posture state {} and carry aspects {}, '
                        .format(spec_carry_target, var_map,
                                current_posture_state,
                                current_posture_state.carry_aspects))
                if spec_carry_posture_type not in var_map:
                    carry_target = var_map[spec_carry_target]
                    aop = posture_specs.get_carry_posture_aop(
                        sim, carry_target)
                    if aop is None:
                        raise RuntimeError(
                            'Sim {} failed to find carry posture aop for carry target {}.'
                            .format(sim, carry_target))
                    carry_posture_type = aop.affordance._carry_posture_type
                    if carry_posture_type is None:
                        raise KeyError
                    var_map += {
                        PostureSpecVariable.POSTURE_TYPE_CARRY_OBJECT:
                        carry_posture_type
                    }
                carry_target = var_map[spec_carry_target]
                carry_posture_type = var_map[spec_carry_posture_type]
                if spec_carry[CARRY_HAND_INDEX] in var_map:
                    hand = var_map[spec_carry[CARRY_HAND_INDEX]]
                else:
                    for hand in sim.posture_state.get_free_hands():
                        if hand in carry_target.get_allowed_hands(sim):
                            break
                    else:
                        raise RuntimeError('No allowable free hand was empty.')
                new_carry_aspect = postures.create_posture(
                    carry_posture_type,
                    self.sim,
                    carry_target,
                    track=hand_to_track(hand),
                    is_throwaway=is_throwaway)
                if hand == Hand.LEFT:
                    self._aspect_carry_left = new_carry_aspect
                    if current_posture_state is not None:
                        self._aspect_carry_right = current_posture_state.right
                    else:
                        self._aspect_carry_right = _get_default_carry_aspect(
                            PostureTrack.RIGHT)
                elif hand == Hand.RIGHT:
                    self._aspect_carry_right = new_carry_aspect
                    if current_posture_state is not None:
                        self._aspect_carry_left = current_posture_state.left
                    else:
                        self._aspect_carry_right = _get_default_carry_aspect(
                            PostureTrack.LEFT)
                else:
                    raise RuntimeError(
                        'Invalid value specified for hand: {}'.format(hand))
        elif current_posture_state is not None:
            self._aspect_carry_left = current_posture_state.left
            self._aspect_carry_right = current_posture_state.right
        elif spec_carry_target is not None:
            carry_target = var_map[spec_carry_target]
            spec_carry_posture_type = spec_carry[CARRY_POSTURE_TYPE_INDEX]
            carry_posture_type = var_map.get(spec_carry_posture_type)
            if carry_posture_type is None:
                aop = get_carry_posture_aop(sim, carry_target)
                if aop is None and invalid_expected:
                    return
                carry_posture_type = aop.affordance._carry_posture_type
            if spec_carry[CARRY_HAND_INDEX] in var_map:
                hand = var_map[spec_carry[CARRY_HAND_INDEX]]
            else:
                allowed_hands = carry_target.get_allowed_hands(sim)
                hand = allowed_hands[0]
            new_carry_aspect = postures.create_posture(
                carry_posture_type,
                self.sim,
                carry_target,
                track=hand_to_track(hand),
                is_throwaway=is_throwaway)
            if hand == Hand.LEFT:
                self._aspect_carry_left = new_carry_aspect
                self._aspect_carry_right = _get_default_carry_aspect(
                    PostureTrack.RIGHT)
            else:
                self._aspect_carry_right = new_carry_aspect
                self._aspect_carry_left = _get_default_carry_aspect(
                    PostureTrack.LEFT)
        else:
            self._aspect_carry_left = _get_default_carry_aspect(
                PostureTrack.LEFT)
            self._aspect_carry_right = _get_default_carry_aspect(
                PostureTrack.RIGHT)
Ejemplo n.º 40
0
def get_valid_aops_gen(target, affordance, si_affordance, si, context, include_failed_aops_with_tooltip, push_super_on_prepare=False, considered=None, aop_kwargs=frozendict()):
    if context.source == InteractionContext.SOURCE_PIE_MENU and not affordance.allow_user_directed:
        if considered is not None:
            considered[affordance] = {'affordance': str(affordance), 'target': str(target), 'test': 'Not allowed user directed'}
        return
    potential_interactions = affordance.potential_interactions(target, si_affordance, si, push_super_on_prepare=push_super_on_prepare, **aop_kwargs)
    for aop in potential_interactions:
        test_result = aop_valid_for_scoring(aop, affordance, target, context, include_failed_aops_with_tooltip, considered=considered)
        while test_result is not None:
            yield (aop, test_result)