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)
def __call__(self, obj, posture, routing_surface_start, routing_surface_end, species_overrides): species_portals = [] posture_species = posture.get_animation_species() for species in species_overrides: if species == SpeciesExtended.INVALID: continue if SpeciesExtended.get_species(species) not in posture_species: continue location_entry = self.location_entry(obj).position location_exit = self.location_exit(obj).position back_entry = None back_exit = None if self.bidirectional: exit_x_offset = Vector3(location_entry.x - location_exit.x, 0, 0) location_exit = location_exit + exit_x_offset there_angle = sims4.math.vector3_angle(location_exit - location_entry) there_orientation = sims4.math.angle_to_yaw_quaternion( there_angle) there_entry = Location(location_entry, orientation=there_orientation, routing_surface=routing_surface_start) there_exit = Location(location_exit, orientation=there_orientation, routing_surface=routing_surface_end) back_angle = sims4.math.vector3_angle(location_entry - location_exit) back_orientation = sims4.math.angle_to_yaw_quaternion( back_angle) back_entry_position = location_exit + back_orientation.transform_vector( exit_x_offset) back_entry = Location(back_entry_position, orientation=back_orientation, routing_surface=routing_surface_end) back_exit_position = location_entry + back_orientation.transform_vector( exit_x_offset) back_exit = Location(back_exit_position, orientation=back_orientation, routing_surface=routing_surface_start) else: there_angle = sims4.math.vector3_angle(location_exit - location_entry) there_orientation = sims4.math.angle_to_yaw_quaternion( there_angle) there_entry = Location(location_entry, orientation=there_orientation, routing_surface=routing_surface_start) there_exit = Location(location_exit, orientation=there_orientation, routing_surface=routing_surface_end) species_portals.append( (there_entry, there_exit, back_entry, back_exit, SpeciesExtended.get_portal_flag(species))) return species_portals
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 get_outer_portal_goal(slot_constraint, stub_actor, entry, routing_surface): handles = slot_constraint.get_connectivity_handles( stub_actor, entry=entry, routing_surface_override=routing_surface) if not handles: slot_constraint.get_connectivity_handles( stub_actor, entry=entry, routing_surface_override=routing_surface, log_none_slots_to_params_as_error=True) logger.error( 'PosturePortal: Species {} has no entry boundary conditions for portal posture', species) return species_param = SpeciesExtended.get_animation_species_param( stub_actor.species) for handle in handles: handle_species_param = handle.locked_params.get( ('species', 'x')) if handle_species_param is None: break if handle_species_param == species_param: break else: return return next(iter(handle.get_goals()), None)
def get_last_name(cls, last_name, gender, species=Species.HUMAN) -> str: species = SpeciesExtended.get_species(species) sim_name_type = SimNameType.DEFAULT if species in cls.SPECIES_TO_NAME_TYPE: sim_name_type = cls.SPECIES_TO_NAME_TYPE[species] return cls._get_family_name_for_gender(cls._get_language_for_locale( services.get_locale()), last_name, gender == Gender.FEMALE, sim_name_type=sim_name_type)
def get_random_first_name(cls, gender, species=Species.HUMAN, sim_name_type_override=None) -> str: species = SpeciesExtended.get_species(species) sim_name_type = SimNameType.DEFAULT if sim_name_type_override is not None: sim_name_type = sim_name_type_override elif species in cls.SPECIES_TO_NAME_TYPE: sim_name_type = cls.SPECIES_TO_NAME_TYPE[species] return cls._get_random_first_name(cls._get_language_for_locale( services.get_locale()), gender == Gender.FEMALE, sim_name_type=sim_name_type)
def picker_rows_gen(cls, inst, target, context, **kwargs): if inst is not None: breed_species = [] species = inst.interaction_parameters['species'] for species_extended in SpeciesExtended: if species_extended == SpeciesExtended.INVALID: continue if SpeciesExtended.get_species(species_extended) == species: breed_species.append(species_extended) else: breed_species = (None, ) for _breed_species in breed_species: for breed in all_breeds_gen(species=_breed_species): name = breed.breed_display_name name = LocalizationHelperTuning.NAME_VALUE_PARENTHESIS_PAIR_STRUCTURE( name, cls.species_name[_breed_species]) row = BasePickerRow(name=name, row_description=breed.breed_description, tag=breed) yield row
def __init__(self, *args, sim_id: int = 0, gender: Gender = Gender.MALE, age: Age = Age.ADULT, species: SpeciesExtended = SpeciesExtended.HUMAN, first_name: str = '', last_name: str = '', breed_name: str = '', full_name_key=0, breed_name_key=0, physique: str = '', skin_tone=1, **kwargs): super().__init__(*args, **kwargs) self.sim_id = sim_id or id_generator.generate_object_id() self.primitives = distributor.ops.DistributionSet(self) self.manager = None self._base = BaseSimInfo(sim_id, first_name, last_name, breed_name, full_name_key, breed_name_key, age, gender, species, skin_tone, physique) self._base.voice_pitch = 0.0 self._base.voice_actor = 0 self._base.voice_effect = 0 self._base.facial_attributes = '' self._base.custom_texture = 0 self._base.pelt_layers = '' self._species = SpeciesExtended.get_species(species) self.on_base_characteristic_changed = CallableList() self.on_outfit_changed = CallableList() self.on_outfit_generated = CallableList() self._set_current_outfit_without_distribution( (OutfitCategory.EVERYDAY, 0)) self._previous_outfit = (OutfitCategory.EVERYDAY, 0) self._preload_outfit_list = [] self.on_preload_outfits_changed = CallableList() self.appearance_tracker = AppearanceTracker(self) self.visible_to_client = False
def __init__(self, agent, **kwargs): super().__init__(**kwargs) self._agent = agent self.agent_id = agent.id self.agent_radius = self._agent_radius self.agent_extra_clearance_multiplier = self._agent_extra_clearance_modifier self.agent_goal_radius = self._agent_goal_radius self.footprint_key = agent.definition.get_footprint(0) full_keymask = routing.FOOTPRINT_KEY_ON_LOT | routing.FOOTPRINT_KEY_OFF_LOT if self._allowed_heights is not None: full_keymask |= self._allowed_heights self.set_key_mask(full_keymask) full_portal_keymask = PortalFlags.DEFAULT species = getattr(self._agent, 'extended_species', DEFAULT) full_portal_keymask |= SpeciesExtended.get_portal_flag(species) age = getattr(self._agent, 'age', DEFAULT) full_portal_keymask |= Age.get_portal_flag(age) if self._allowed_portal_flags is not None: full_portal_keymask |= self._allowed_portal_flags self.set_portal_key_mask(full_portal_keymask) portal_discouragement_flags = 0 if self._discouraged_portal_flags is not None: portal_discouragement_flags |= self._discouraged_portal_flags self.set_portal_discourage_key_mask(portal_discouragement_flags)
def extended_species(self): return SpeciesExtended(self._species)
def __call__(self, obj, posture, routing_surface_start, routing_surface_end, species_overrides): species_portals = [] def get_outer_portal_goal(slot_constraint, stub_actor, entry, routing_surface): handles = slot_constraint.get_connectivity_handles( stub_actor, entry=entry, routing_surface_override=routing_surface) if not handles: slot_constraint.get_connectivity_handles( stub_actor, entry=entry, routing_surface_override=routing_surface, log_none_slots_to_params_as_error=True) logger.error( 'PosturePortal: Species {} has no entry boundary conditions for portal posture', species) return species_param = SpeciesExtended.get_animation_species_param( stub_actor.species) for handle in handles: handle_species_param = handle.locked_params.get( ('species', 'x')) if handle_species_param is None: break if handle_species_param == species_param: break else: return return next(iter(handle.get_goals()), None) posture_species = posture.get_animation_species() for species in species_overrides: if species == SpeciesExtended.INVALID: continue if SpeciesExtended.get_species(species) not in posture_species: continue stub_actor = get_global_stub_actor(species) portal_posture = postures.create_posture(posture, stub_actor, obj, is_throwaway=True) slot_constraint = portal_posture.slot_constraint containment_constraint = next(iter(slot_constraint)) there_start = get_outer_portal_goal( slot_constraint, stub_actor, entry=True, routing_surface=routing_surface_start) if there_start is None: continue there_end = containment_constraint.containment_transform there_entry = Location(there_start.position, orientation=there_start.orientation, routing_surface=routing_surface_start) there_exit = Location(there_end.translation, orientation=there_end.orientation, routing_surface=routing_surface_end) back_entry = None back_exit = None if self.bidirectional: back_start = containment_constraint.containment_transform_exit back_end = get_outer_portal_goal( slot_constraint, stub_actor, entry=False, routing_surface=routing_surface_start) if back_end is None: continue back_entry = Location(back_start.translation, orientation=back_start.orientation, routing_surface=routing_surface_end) back_exit = Location(back_end.position, orientation=back_end.orientation, routing_surface=routing_surface_start) species_portals.append( (there_entry, there_exit, back_entry, back_exit, SpeciesExtended.get_portal_flag(species))) return species_portals
def _create_all_transforms_and_portals_for_initial_transforms( self, initial_transforms, lot_transforms=False, prior_lengths=None, store_portal_ids=None): portal_component = self.get_component(PORTAL_COMPONENT) if portal_component is None: return def _store_transforms(species, ages, interval, transforms): for age in ages: key = (species, age, interval) if key in self._constraint_starts: if prior_lengths is not None: prior_lengths[key] = len(self._constraint_starts[key]) self._constraint_starts[key].extend(transforms) else: if prior_lengths is not None: prior_lengths[key] = 0 self._constraint_starts[key] = transforms routing_surface = SurfaceIdentifier(services.current_zone_id(), 0, SurfaceType.SURFACETYPE_WORLD) edge_transforms = adjust_locations_for_coastline(initial_transforms) def _get_water_depth_at_edge(i): transform = edge_transforms[i] translation = transform.translation + transform.orientation.transform_vector( Ocean.EDGE_TEST_POINT_OFFSET) return get_water_depth(translation.x, translation.z) for (species, age_data) in OceanTuning.OCEAN_DATA.items(): required_pack = SpeciesExtended.get_required_pack(species) if required_pack is not None and not is_available_pack( required_pack): continue for age_ocean_data in age_data: ocean_data = age_ocean_data.ocean_data beach_portal = ocean_data.beach_portal_data wading_depth = ocean_data.wading_interval.lower_bound max_wading_depth = wading_depth + ocean_data.water_depth_error swim_depth = ocean_data.wading_interval.upper_bound min_swim_depth = swim_depth - ocean_data.water_depth_error transforms = adjust_locations_for_target_water_depth( wading_depth, ocean_data.water_depth_error, initial_transforms) wading_transforms = [] for i in range(len(transforms) - 1): transform = transforms[i] if transform.translation == VECTOR3_ZERO: depth = _get_water_depth_at_edge(i) if depth <= max_wading_depth: wading_transforms.append(edge_transforms[i]) wading_transforms.append(transform) else: wading_transforms.append(transform) transforms = adjust_locations_for_target_water_depth( swim_depth, ocean_data.water_depth_error, initial_transforms) portal_transforms = [] for i in range(len(transforms) - 1): transform = transforms[i] if transform.translation == VECTOR3_ZERO: depth = _get_water_depth_at_edge(i) if min_swim_depth <= depth: edge_transform = edge_transforms[i] translation = edge_transform.translation + edge_transform.orientation.transform_vector( Ocean.EDGE_PORTAL_BACKSET) portal_transforms.append( Transform(translation, edge_transform.orientation)) else: portal_transforms.append(transform) _store_transforms(species, age_ocean_data.ages, WaterDepthIntervals.WET, edge_transforms.copy()) _store_transforms(species, age_ocean_data.ages, WaterDepthIntervals.WADE, wading_transforms) _store_transforms(species, age_ocean_data.ages, WaterDepthIntervals.SWIM, portal_transforms) if beach_portal is None: pass else: if lot_transforms: portal_transforms = self._reorient_lot_transforms( portal_transforms) portal_creation_mask = SpeciesExtended.get_portal_flag( species) for portal_transform in portal_transforms: portal_location = Location( portal_transform, routing_surface=routing_surface) portal_ids = portal_component.add_custom_portal( OceanPoint(portal_location), beach_portal, portal_creation_mask) add_portals = [] remove_portals = [] for portal_id in portal_ids: portal_instance = portal_component.get_portal_by_id( portal_id) if portal_instance is not None: location = None if portal_id == portal_instance.there: location = portal_instance.there_entry elif portal_id == portal_instance.back: location = portal_instance.back_exit if location and build_buy.is_location_natural_ground( location.position, location.routing_surface.secondary_id): add_portals.append(portal_id) else: remove_portals.append(portal_id) if remove_portals: portal_component.remove_custom_portals( remove_portals) if add_portals and store_portal_ids is not None: store_portal_ids.extend(add_portals)
def _get_param_sequences_for_cache(self, actor, actor_name, to_state_name, from_state_name, posture, target_name=None): internal_param_sequence_list = self._get_param_sequences(actor.id, to_state_name, from_state_name, None) internal_param_sequence_list = internal_param_sequence_list or (None,) if posture is None: return internal_param_sequence_list 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: if param_sequence: posture_param_value = param_sequence.get(posture_key) if not (posture_param_value is not None and (posture_param_value.startswith(exact_str) or family_str is None)): if family_str not in posture_param_value: continue actor_age_param = ('age', actor_name) if param_sequence is not None and actor_age_param in param_sequence: age = Age.get_age_from_animation_param(param_sequence[actor_age_param]) actor_available_ages = (age,) else: actor_available_ages = Age.get_ages_for_animation_cache() actor_species_param = ('species', actor_name) if param_sequence is not None and actor_species_param in param_sequence: species = SpeciesExtended.get_species_from_animation_param(param_sequence[actor_species_param]) actor_available_species = (species,) else: actor_available_species = SpeciesExtended if target_name is None: target_available_species = () target_available_ages = () else: target_age_param = ('age', target_name) if param_sequence is not None and target_age_param in param_sequence: age = Age.get_age_from_animation_param(param_sequence[target_age_param]) target_available_ages = (age,) else: target_available_ages = Age.get_ages_for_animation_cache() target_species_param = ('species', target_name) if param_sequence is not None and target_species_param in param_sequence: species = SpeciesExtended.get_species_from_animation_param(param_sequence[target_species_param]) target_available_species = (species,) else: target_available_species = SpeciesExtended for age_species_param_sequence in self._get_param_sequences_for_age_species_gen(param_sequence, actor_name, actor_available_species, actor_available_ages, target_name, target_available_species, target_available_ages): param_sequence_list.append(age_species_param_sequence) else: actor_age_param = ('age', actor_name) if param_sequence is not None and actor_age_param in param_sequence: age = Age.get_age_from_animation_param(param_sequence[actor_age_param]) actor_available_ages = (age,) else: actor_available_ages = Age.get_ages_for_animation_cache() actor_species_param = ('species', actor_name) if param_sequence is not None and actor_species_param in param_sequence: species = SpeciesExtended.get_species_from_animation_param(param_sequence[actor_species_param]) actor_available_species = (species,) else: actor_available_species = SpeciesExtended if target_name is None: target_available_species = () target_available_ages = () else: target_age_param = ('age', target_name) if param_sequence is not None and target_age_param in param_sequence: age = Age.get_age_from_animation_param(param_sequence[target_age_param]) target_available_ages = (age,) else: target_available_ages = Age.get_ages_for_animation_cache() target_species_param = ('species', target_name) if param_sequence is not None and target_species_param in param_sequence: species = SpeciesExtended.get_species_from_animation_param(param_sequence[target_species_param]) target_available_species = (species,) else: target_available_species = SpeciesExtended for age_species_param_sequence in self._get_param_sequences_for_age_species_gen(param_sequence, actor_name, actor_available_species, actor_available_ages, target_name, target_available_species, target_available_ages): param_sequence_list.append(age_species_param_sequence) return param_sequence_list
def extended_species(self, value): self._base.species = value self._species = SpeciesExtended.get_species(value) self.on_base_characteristic_changed()