示例#1
0
def create_carry_nothing_constraint(hand, debug_name='CarryNothing'):
    entries = []
    if hand == Hand.LEFT:
        entries = (PostureManifestEntry(None, MATCH_ANY, MATCH_ANY, MATCH_ANY,
                                        MATCH_NONE, MATCH_ANY, MATCH_ANY), )
    else:
        entries = (PostureManifestEntry(None, MATCH_ANY, MATCH_ANY, MATCH_ANY,
                                        MATCH_ANY, MATCH_NONE, MATCH_ANY), )
    carry_posture_manifest = PostureManifest(entries)
    carry_posture_state_spec = PostureStateSpec(carry_posture_manifest,
                                                SlotManifest().intern(),
                                                PostureSpecVariable.ANYTHING)
    return interactions.constraints.Constraint(
        debug_name=debug_name, posture_state_spec=carry_posture_state_spec)
示例#2
0
def _consolidate_carry_info2(posture_manifest):
    if posture_manifest is None:
        return
    result = PostureManifest()
    for p0 in posture_manifest:
        free_hands = set()
        for p1 in posture_manifest:
            if p0.actor == p1.actor:
                if p0.specific == p1.specific:
                    if p0.family == p1.family:
                        if p0.level == p1.level:
                            if p0.surface == p1.surface:
                                if p0.provides == p1.provides:
                                    if p0.left in _NOT_SPECIFIC_ACTOR_OR_NONE:
                                        if p1.left in _NOT_SPECIFIC_ACTOR_OR_NONE:
                                            if p0.right in _NOT_SPECIFIC_ACTOR_OR_NONE:
                                                if p1.right in _NOT_SPECIFIC_ACTOR_OR_NONE:
                                                    free_hands.update(p1.free_hands)
        left = p0.left
        right = p0.right
        left = MATCH_ANY if Hand.LEFT in free_hands else left
        right = MATCH_ANY if Hand.RIGHT in free_hands else right
        entry = PostureManifestEntry(p0.actor, p0.specific, p0.family, p0.level, left, right, p0.surface, p0.provides)
        result.add(entry)
    return result
 def get_access_constraint(self, put, inventory_owner):
     entries = []
     entries.append(PostureManifestEntry(None, MATCH_ANY, MATCH_ANY, MATCH_ANY, MATCH_ANY, MATCH_ANY, inventory_owner))
     surface_posture_manifest = PostureManifest(entries)
     surface_posture_state_spec = PostureStateSpec(surface_posture_manifest, SlotManifest().intern(), PostureSpecVariable.ANYTHING)
     constraint_total = interactions.constraints.Constraint(debug_name='Required Surface For Generic Get Put', posture_state_spec=surface_posture_state_spec)
     for constraint_factory in self.constraints:
         constraint = constraint_factory.create_constraint(None, target=inventory_owner)
         constraint_total = constraint_total.intersect(constraint)
     return constraint_total
示例#4
0
 def get_supported_postures_for_actor(self, actor_name):
     cache_key = (self.state_machine_name, actor_name)
     if cache_key in self._supported_posture_cache:
         manifest = self._supported_posture_cache[cache_key]
     else:
         manifest = PostureManifest(PostureManifestEntry(*entry) for entry in super().get_supported_postures_for_actor(actor_name) or ())
         manifest = _consolidate_carry_info2(manifest)
         manifest = manifest.get_clean_manifest()
         self._supported_posture_cache[cache_key] = manifest.intern()
     manifest = self._apply_posture_manifest_overrides(manifest)
     return manifest
示例#5
0
 def provided_postures(self):
     cache_key = self.state_machine_name
     if cache_key in self._provided_posture_cache:
         manifest = self._provided_posture_cache[cache_key]
     else:
         super_manifest = super().provided_postures
         manifest = PostureManifest(PostureManifestEntry(*entry, provides=True, from_asm=True) for entry in super_manifest)
         manifest = _consolidate_carry_info2(manifest)
         self._provided_posture_cache[cache_key] = manifest.intern()
     manifest = self._apply_posture_manifest_overrides(manifest)
     return manifest
示例#6
0
 def _create_drive_posture_constraint(self, posture_type):
     posture_manifest = PostureManifest()
     entry = PostureManifestEntry(AnimationParticipant.ACTOR,
                                  posture_type.name,
                                  posture_type.family_name, MATCH_ANY,
                                  MATCH_NONE, MATCH_NONE, MATCH_ANY, None)
     posture_manifest.add(entry)
     posture_manifest = posture_manifest.intern()
     posture_state_spec = PostureStateSpec(posture_manifest, SlotManifest(),
                                           PostureSpecVariable.ANYTHING)
     return Constraint(posture_state_spec=posture_state_spec,
                       debug_name='VehiclePostureConstraint')
def create_carry_constraint(target,
                            hand=DEFAULT,
                            strict=False,
                            debug_name='CarryGeneric'):
    if strict and target is None:
        target = MATCH_NONE
    entries = []
    if hand is DEFAULT or hand == Hand.LEFT:
        entries.append(
            PostureManifestEntry(None, MATCH_ANY, MATCH_ANY, MATCH_ANY, target,
                                 MATCH_ANY, MATCH_ANY))
    if hand is DEFAULT or hand == Hand.RIGHT:
        entries.append(
            PostureManifestEntry(None, MATCH_ANY, MATCH_ANY, MATCH_ANY,
                                 MATCH_ANY, target, MATCH_ANY))
    carry_posture_manifest = PostureManifest(entries)
    carry_posture_state_spec = PostureStateSpec(carry_posture_manifest,
                                                SlotManifest().intern(),
                                                PostureSpecVariable.ANYTHING)
    return interactions.constraints.Constraint(
        debug_name=debug_name, posture_state_spec=carry_posture_state_spec)
示例#8
0
class GoHereSuperInteraction(TerrainSuperInteraction):
    __qualname__ = 'GoHereSuperInteraction'
    POSTURE_MANIFEST = PostureManifest(
        (PostureManifestEntry(None, 'stand', '', 'FullBody', MATCH_ANY,
                              MATCH_ANY, MATCH_NONE), )).intern()
    POSTURE_STATE_SPEC = PostureStateSpec(POSTURE_MANIFEST,
                                          SlotManifest().intern(), None)
    CONSTRAINT = Constraint(debug_name='GoHere',
                            posture_state_spec=POSTURE_STATE_SPEC,
                            allow_small_intersections=True)
    _ignores_spawn_point_footprints = True

    @classmethod
    def _test(cls, target, context, **kwargs):
        (position, surface) = cls._get_position_and_surface(target, context)
        if position is None:
            return TestResult(False,
                              'Cannot go here without a pick or target.')
        routing_location = routing.Location(position,
                                            sims4.math.Quaternion.IDENTITY(),
                                            surface)
        if not routing.test_connectivity_permissions_for_handle(
                routing.connectivity.Handle(routing_location),
                context.sim.routing_context):
            return TestResult(False, 'Cannot GoHere! Unroutable area.')
        return TestResult.TRUE

    @classmethod
    def potential_interactions(cls, target, context, **kwargs):
        (position, surface) = cls._get_position_and_surface(target, context)
        if position is not None and context is not None and context.sim is not None:
            main_group = context.sim.get_visible_group()
            if main_group is not None and not main_group.is_solo:
                group_constraint = next(
                    iter(main_group.get_constraint(context.sim)))
                if group_constraint is not None and group_constraint.routing_surface == surface:
                    while True:
                        for constraint in group_constraint:
                            group_geometry = constraint.geometry
                            while group_geometry is not None and group_geometry.contains_point(
                                    position):
                                yield AffordanceObjectPair(cls,
                                                           target,
                                                           cls,
                                                           None,
                                                           ignore_party=True,
                                                           **kwargs)
                                return
        if cls._can_rally(context):
            for aop in cls.get_rallyable_aops_gen(target, context, **kwargs):
                yield aop
        yield cls.generate_aop(target, context, **kwargs)
 def get_provided_postures(cls, inst, surface_target=DEFAULT, concrete=False):
     if inst is None:
         return cls._provided_postures
     provided_postures = inst._provided_postures
     surface_target = inst._resolve_surface_target(surface_target)
     if surface_target is None or surface_target == MATCH_NONE:
         surface_restriction = MATCH_NONE
     elif surface_target == MATCH_ANY:
         surface_restriction = surface_target
     else:
         surface_restriction = surface_target if concrete else AnimationParticipant.SURFACE
     if surface_restriction is not None:
         filter_entry = PostureManifestEntry(MATCH_ANY, MATCH_ANY, MATCH_ANY, MATCH_ANY, MATCH_ANY, MATCH_ANY, surface_restriction, True)
         provided_postures = provided_postures.intersection_single(filter_entry)
     return provided_postures
示例#10
0
from animation.posture_manifest
import MATCH_ANY, MATCH_NONE, PostureManifestEntry, PostureManifest
from interactions.constraints
import Constraint, create_constraint_set
from postures.posture_state_spec
import create_body_posture_state_spec
STAND_POSTURE_MANIFEST = PostureManifest((PostureManifestEntry(None, '', 'stand', 'FullBody', MATCH_ANY, MATCH_ANY, MATCH_ANY), PostureManifestEntry(None, '', 'stand', 'UpperBody', MATCH_ANY, MATCH_ANY, MATCH_ANY))).intern()
STAND_NO_SURFACE_POSTURE_MANIFEST = PostureManifest((PostureManifestEntry(None, '', 'stand', 'FullBody', MATCH_ANY, MATCH_ANY, MATCH_NONE), PostureManifestEntry(None, '', 'stand', 'UpperBody', MATCH_ANY, MATCH_ANY, MATCH_NONE))).intern()
STAND_NO_CARRY_NO_SURFACE_POSTURE_MANIFEST = PostureManifest((PostureManifestEntry(None, '', 'stand', 'FullBody', MATCH_NONE, MATCH_NONE, MATCH_NONE), PostureManifestEntry(None, '', 'stand', 'UpperBody', MATCH_NONE, MATCH_NONE, MATCH_NONE))).intern()
STAND_POSTURE_STATE_SPEC = create_body_posture_state_spec(STAND_POSTURE_MANIFEST)
STAND_NO_SURFACE_STATE_SPEC = create_body_posture_state_spec(STAND_NO_SURFACE_POSTURE_MANIFEST)
STAND_NO_CARRY_NO_SURFACE_STATE_SPEC = create_body_posture_state_spec(STAND_NO_CARRY_NO_SURFACE_POSTURE_MANIFEST)
STAND_CONSTRAINT = Constraint(debug_name = 'Stand', posture_state_spec = STAND_POSTURE_STATE_SPEC)
STAND_NO_SURFACE_CONSTRAINT = Constraint(debug_name = 'Stand-NoSurface', posture_state_spec = STAND_NO_SURFACE_STATE_SPEC)
STAND_NO_CARRY_NO_SURFACE_CONSTRAINT = Constraint(debug_name = 'Stand-NoCarryNoSurface', posture_state_spec = STAND_NO_CARRY_NO_SURFACE_STATE_SPEC)
STAND_CONSTRAINT_OUTER_PENALTY = Constraint(debug_name = 'Stand', posture_state_spec = STAND_POSTURE_STATE_SPEC, ignore_outer_penalty_threshold = 1.0)
STAND_AT_NONE_POSTURE_STATE_SPEC = create_body_posture_state_spec(STAND_POSTURE_MANIFEST, body_target = None)
STAND_AT_NONE_CONSTRAINT = Constraint(debug_name = 'Stand@None', posture_state_spec = STAND_AT_NONE_POSTURE_STATE_SPEC)
SIT_POSTURE_MANIFEST = PostureManifest((PostureManifestEntry(None, '', 'sit', 'FullBody', MATCH_ANY, MATCH_ANY, MATCH_ANY), PostureManifestEntry(None, '', 'sit', 'UpperBody', MATCH_ANY, MATCH_ANY, MATCH_ANY))).intern()
SIT_NO_CARRY_NO_SURFACE_MANIFEST = PostureManifest((PostureManifestEntry(None, '', 'sit', 'FullBody', MATCH_NONE, MATCH_NONE, MATCH_NONE), PostureManifestEntry(None, '', 'sit', 'UpperBody', MATCH_NONE, MATCH_NONE, MATCH_NONE))).intern()
SIT_POSTURE_STATE_SPEC = create_body_posture_state_spec(SIT_POSTURE_MANIFEST)
SIT_NO_CARRY_NO_SURFACE_STATE_SPEC = create_body_posture_state_spec(SIT_NO_CARRY_NO_SURFACE_MANIFEST)
SIT_CONSTRAINT = Constraint(debug_name = 'Sit', posture_state_spec = SIT_POSTURE_STATE_SPEC)
SIT_NO_CARRY_NO_SURFACE_CONSTRAINT = Constraint(debug_name = 'SitNoCarryNoSurface', posture_state_spec = SIT_NO_CARRY_NO_SURFACE_STATE_SPEC)
SIT_INTIMATE_POSTURE_MANIFEST = PostureManifest((PostureManifestEntry(None, 'sitIntimate', '', 'FullBody', MATCH_NONE, MATCH_NONE, MATCH_NONE), PostureManifestEntry(None, 'sitIntimate', '', 'UpperBody', MATCH_NONE, MATCH_NONE, MATCH_NONE))).intern()
SIT_INTIMATE_POSTURE_STATE_SPEC = create_body_posture_state_spec(SIT_INTIMATE_POSTURE_MANIFEST)
SIT_INTIMATE_CONSTRAINT = Constraint(debug_name = 'SitIntimate', posture_state_spec = SIT_INTIMATE_POSTURE_STATE_SPEC)
STAND_OR_SIT_POSTURE_MANIFEST = PostureManifest(list(STAND_POSTURE_MANIFEST) + list(SIT_POSTURE_MANIFEST)).intern()
STAND_OR_SIT_CONSTRAINT = create_constraint_set((STAND_CONSTRAINT, SIT_CONSTRAINT), debug_name = 'Stand-or-Sit')
STAND_OR_SIT_CONSTRAINT_OUTER_PENALTY = create_constraint_set((STAND_CONSTRAINT_OUTER_PENALTY, SIT_CONSTRAINT), debug_name = 'Stand-or-Sit-Outer-Penalty')
示例#11
0
from animation.posture_manifest import PostureManifest, PostureManifestEntry, AnimationParticipant, MATCH_ANY, SlotManifest
from interactions.base.basic import TunableBasicContentSet
from interactions.base.super_interaction import SuperInteraction
from interactions.constraints import Constraint
from event_testing.results import TestResult
from postures.posture_state_spec import PostureStateSpec
from sims4.tuning.tunable import TunableReference
import services
CARRY_TARGET_POSTURE_MANIFEST = PostureManifest((PostureManifestEntry(None, None, None, None, AnimationParticipant.TARGET, MATCH_ANY, MATCH_ANY), PostureManifestEntry(None, None, None, None, MATCH_ANY, AnimationParticipant.TARGET, MATCH_ANY))).intern()
CARRY_TARGET_POSTURE_STATE_SPEC = PostureStateSpec(CARRY_TARGET_POSTURE_MANIFEST, SlotManifest().intern(), None)

class PickUpObjectSuperInteraction(SuperInteraction):
    __qualname__ = 'PickUpObjectSuperInteraction'
    INSTANCE_TUNABLES = {'basic_content': TunableBasicContentSet(one_shot=True, no_content=True, default='no_content'), 'si_to_push': TunableReference(services.affordance_manager(), description='SI to push after picking up the object.')}

    @classmethod
    def _constraint_gen(cls, *args, **kwargs):
        yield Constraint(debug_name='PickUpObjectSuperInteraction({})'.format(cls.si_to_push), posture_state_spec=CARRY_TARGET_POSTURE_STATE_SPEC)

    @classmethod
    def _test(cls, target, context, **kwargs):
        from sims.sim import Sim
        if isinstance(target.parent, Sim):
            return TestResult(False, 'Cannot pick up an object parented to a Sim.')
        if context.source == context.SOURCE_AUTONOMY and context.sim.posture_state.get_carry_track(target.definition.id) is not None:
            return TestResult(False, 'Sims should not autonomously pick up more than one object.')
        return TestResult.TRUE

class CarryCancelInteraction(SuperInteraction):
    __qualname__ = 'CarryCancelInteraction'
from animation.posture_manifest import MATCH_ANY, MATCH_NONE, PostureManifestEntry, PostureManifest
from interactions.constraints import Constraint, create_constraint_set
from postures.posture_state_spec import create_body_posture_state_spec
from sims4.tuning.tunable import TunableReference
import services
import sims4.resources
STAND_POSTURE_MANIFEST = PostureManifest((PostureManifestEntry(None, '', 'stand', 'FullBody', MATCH_ANY, MATCH_ANY, MATCH_ANY), PostureManifestEntry(None, '', 'stand', 'UpperBody', MATCH_ANY, MATCH_ANY, MATCH_ANY))).intern()
STAND_NO_SURFACE_POSTURE_MANIFEST = PostureManifest((PostureManifestEntry(None, '', 'stand', 'FullBody', MATCH_ANY, MATCH_ANY, MATCH_NONE), PostureManifestEntry(None, '', 'stand', 'UpperBody', MATCH_ANY, MATCH_ANY, MATCH_NONE))).intern()
STAND_NO_CARRY_NO_SURFACE_POSTURE_MANIFEST = PostureManifest((PostureManifestEntry(None, '', 'stand', 'FullBody', MATCH_NONE, MATCH_NONE, MATCH_NONE), PostureManifestEntry(None, '', 'stand', 'UpperBody', MATCH_NONE, MATCH_NONE, MATCH_NONE))).intern()
STAND_OR_MOVING_STAND_POSTURE_MANIFEST = PostureManifest((PostureManifestEntry(None, '', 'movingStand', 'FullBody', MATCH_ANY, MATCH_ANY, MATCH_ANY), PostureManifestEntry(None, '', 'movingStand', 'UpperBody', MATCH_ANY, MATCH_ANY, MATCH_ANY), PostureManifestEntry(None, '', 'stand', 'FullBody', MATCH_ANY, MATCH_ANY, MATCH_ANY), PostureManifestEntry(None, '', 'stand', 'UpperBody', MATCH_ANY, MATCH_ANY, MATCH_ANY))).intern()
STAND_POSTURE_STATE_SPEC = create_body_posture_state_spec(STAND_POSTURE_MANIFEST)
STAND_AT_NONE_POSTURE_STATE_SPEC = create_body_posture_state_spec(STAND_POSTURE_MANIFEST, body_target=None)
STAND_NO_SURFACE_STATE_SPEC = create_body_posture_state_spec(STAND_NO_SURFACE_POSTURE_MANIFEST)
STAND_NO_CARRY_NO_SURFACE_STATE_SPEC = create_body_posture_state_spec(STAND_NO_CARRY_NO_SURFACE_POSTURE_MANIFEST)
STAND_OR_MOVING_STAND_STATE_SPEC = create_body_posture_state_spec(STAND_OR_MOVING_STAND_POSTURE_MANIFEST)
STAND_OR_MOVING_STAND_AT_NONE_STATE_SPEC = create_body_posture_state_spec(STAND_OR_MOVING_STAND_POSTURE_MANIFEST, body_target=None)
STAND_CONSTRAINT = Constraint(debug_name='Stand', posture_state_spec=STAND_POSTURE_STATE_SPEC)
STAND_NO_SURFACE_CONSTRAINT = Constraint(debug_name='Stand-NoSurface', posture_state_spec=STAND_NO_SURFACE_STATE_SPEC)
STAND_NO_CARRY_NO_SURFACE_CONSTRAINT = Constraint(debug_name='Stand-NoCarryNoSurface', posture_state_spec=STAND_NO_CARRY_NO_SURFACE_STATE_SPEC)
STAND_CONSTRAINT_OUTER_PENALTY = Constraint(debug_name='Stand', posture_state_spec=STAND_POSTURE_STATE_SPEC, ignore_outer_penalty_threshold=1.0)
STAND_AT_NONE_CONSTRAINT = Constraint(debug_name='Stand@None', posture_state_spec=STAND_AT_NONE_POSTURE_STATE_SPEC)
STAND_OR_MOVING_STAND_CONSTRAINT = Constraint(debug_name='Stand-Or-MovingStand', posture_state_spec=STAND_OR_MOVING_STAND_STATE_SPEC)
STAND_OR_MOVING_STAND_AT_NONE_CONSTRAINT = Constraint(debug_name='Stand-Or-MovingStand@None', posture_state_spec=STAND_OR_MOVING_STAND_AT_NONE_STATE_SPEC)
SIT_POSTURE_MANIFEST = PostureManifest((PostureManifestEntry(None, '', 'sit', 'FullBody', MATCH_ANY, MATCH_ANY, MATCH_ANY), PostureManifestEntry(None, '', 'sit', 'UpperBody', MATCH_ANY, MATCH_ANY, MATCH_ANY))).intern()
SIT_NO_CARRY_ANY_SURFACE_MANIFEST = PostureManifest((PostureManifestEntry(None, '', 'sit', 'FullBody', MATCH_NONE, MATCH_NONE, MATCH_ANY), PostureManifestEntry(None, '', 'sit', 'UpperBody', MATCH_NONE, MATCH_NONE, MATCH_ANY))).intern()
SIT_POSTURE_STATE_SPEC = create_body_posture_state_spec(SIT_POSTURE_MANIFEST)
SIT_NO_CARRY_ANY_SURFACE_STATE_SPEC = create_body_posture_state_spec(SIT_NO_CARRY_ANY_SURFACE_MANIFEST)
SIT_CONSTRAINT = Constraint(debug_name='Sit', posture_state_spec=SIT_POSTURE_STATE_SPEC)
SIT_NO_CARRY_ANY_SURFACE_CONSTRAINT = Constraint(debug_name='SitNoCarryAnySurface', posture_state_spec=SIT_NO_CARRY_ANY_SURFACE_STATE_SPEC)
SWIM_POSTURE_TYPE = 'swim'
SWIM_POSTURE_MANIFEST = PostureManifest((PostureManifestEntry(None, SWIM_POSTURE_TYPE, '', 'FullBody', None, None, MATCH_ANY), PostureManifestEntry(None, SWIM_POSTURE_TYPE, '', 'UpperBody', None, None, MATCH_ANY))).intern()
示例#13
0
from animation.posture_manifest import PostureManifest, PostureManifestEntry, AnimationParticipant, MATCH_ANY, SlotManifest
from interactions.base.basic import TunableBasicContentSet
from interactions.base.super_interaction import SuperInteraction
from interactions.constraints import Constraint
from event_testing.results import TestResult
from postures.posture_state_spec import PostureStateSpec
from sims4.tuning.tunable import TunableReference
import services

CARRY_TARGET_POSTURE_MANIFEST = PostureManifest(
    (PostureManifestEntry(None, None, None, None, AnimationParticipant.TARGET,
                          MATCH_ANY, MATCH_ANY),
     PostureManifestEntry(None, None, None, None, MATCH_ANY,
                          AnimationParticipant.TARGET, MATCH_ANY))).intern()
CARRY_TARGET_POSTURE_STATE_SPEC = PostureStateSpec(
    CARRY_TARGET_POSTURE_MANIFEST,
    SlotManifest().intern(), None)


class PickUpObjectSuperInteraction(SuperInteraction):
    INSTANCE_TUNABLES = {
        'basic_content':
        TunableBasicContentSet(one_shot=True,
                               no_content=True,
                               default='no_content'),
        'si_to_push':
        TunableReference(services.affordance_manager(),
                         allow_none=True,
                         description='SI to push after picking up the object.')
    }