def _get_household_templates_and_bed_data(self, zone_id, household_population_data): total_beds = 0 lot_has_double_bed = False lot_has_kid_bed = False persistence_service = services.get_persistence_service() zone_data = persistence_service.get_zone_proto_buff(zone_id) if zone_data.gameplay_zone_data.HasField('bed_info_data'): world_description_id = services.get_world_description_id( zone_data.world_id) household_templates = household_population_data.street_description_to_templates.get( world_description_id) total_beds = zone_data.gameplay_zone_data.bed_info_data.num_beds lot_has_double_bed = zone_data.gameplay_zone_data.bed_info_data.double_bed_exist lot_has_kid_bed = zone_data.gameplay_zone_data.bed_info_data.kid_bed_exist if total_beds == 0: total_beds = zone_data.gameplay_zone_data.bed_info_data.alternative_sleeping_spots else: house_description_id = persistence_service.get_house_description_id( zone_id) household_templates = household_population_data.household_description_to_templates.get( house_description_id) if household_templates: household_template = household_templates[0].household_template total_beds = household_template.get_number_of_guaranteed_members( ) return (household_templates, total_beds, lot_has_double_bed, lot_has_kid_bed)
def get_hide_from_lot_picker(_connection=None): current_zone = services.current_zone() world_desc_id = services.get_world_description_id(current_zone.world_id) lot = current_zone.lot b = services.get_hide_from_lot_picker(lot.lot_id, world_desc_id) output = sims4.commands.Output(_connection) output('c_api returned {} for lot {} and world {}'.format(b, lot.lot_id, current_zone.world_id))
def _set_exterior_house_description(self, house_descriptions): if not house_descriptions: return zone_ids = get_zone_ids_from_street(self._street) if not zone_ids: return distributor = Distributor.instance() persistence_service = services.get_persistence_service() for zone_id in zone_ids: zone_data = persistence_service.get_zone_proto_buff(zone_id) zone_world_description_id = services.get_world_description_id( zone_data.world_id) zone_lot_description_id = services.get_lot_description_id( zone_data.lot_id, zone_world_description_id) for (lot_description_id, house_description_id) in house_descriptions.items(): if lot_description_id == zone_lot_description_id: zone_data.pending_plex_exterior_house_desc_id = house_description_id plex_update_msg = Lot_pb2.LotPlexExteriorUpdate() plex_update_msg.zone_id = zone_id plex_update_msg.plex_exterior_house_desc_id = house_description_id distributor.add_event( Consts_pb2.MSG_SET_PLEX_EXTERIOR_HOUSE_DESC, plex_update_msg) break
def print_venues(_connection=None): current_zone = services.current_zone() lot = current_zone.lot neighborhood_id = current_zone.neighborhood_id lot_description_id = services.get_lot_description_id(lot.lot_id) world_description_id = services.get_world_description_id( current_zone.world_id) neighborhood_description_id = services.get_persistence_service( ).get_neighborhood_proto_buff(neighborhood_id).region_id def print_line(): sims4.commands.output('-' * 150, _connection) print_line() sims4.commands.output( 'Current Game Stats: \nLot: {}\nWorld/Street: {}\nRegion/Neighborhood: {}' .format(lot_description_id, world_description_id, neighborhood_description_id), _connection) print_line() venue_manager = services.get_instance_manager(sims4.resources.Types.VENUE) venues = [] for neighborhood_proto in services.get_persistence_service( ).get_neighborhoods_proto_buf_gen(): for lot_owner_info in neighborhood_proto.lots: zone_id = lot_owner_info.zone_instance_id while zone_id is not None: venue_type_id = build_buy.get_current_venue(zone_id) venue_type = venue_manager.get(venue_type_id) if venue_type is not None: log = PrintVenueLog._make( (neighborhood_proto.name, neighborhood_proto.region_id, lot_owner_info.lot_description_id, zone_id, venue_type.__name__, lot_owner_info.lot_name)) venues.append(log) str_format = '{:20} ({:{center}15}) {:{center}20} {:15} ({:{center}20}) {:20}' def print_columns(): sims4.commands.output( str_format.format('Neighborhood_Name', 'Neighborhood_ID', 'Lot_Description_ID', 'Zone_Instance_ID', 'Venue_Tuning_Name', 'Lot_Name', center='^'), _connection) print_columns() print_line() for venue in sorted(venues): sims4.commands.output( str_format.format(venue.Neighborhood_Name, venue.Neighborhood_ID, venue.Lot_Description_ID, venue.Zone_Instance_ID, venue.Venue_Tuning_Name, venue.Lot_Name, center='^'), _connection) print_line() print_columns()
def get_hide_from_lot_picker(_connection=None): current_zone = services.current_zone() world_desc_id = services.get_world_description_id(current_zone.world_id) lot = current_zone.lot b = services.get_hide_from_lot_picker(lot.lot_id, world_desc_id) output = sims4.commands.Output(_connection) output('c_api returned {} for lot {} and world {}'.format( b, lot.lot_id, current_zone.world_id))
def update_community_board_tooltip(self, provider=None): if provider is not None: current_zone = services.current_zone() if current_zone is None: return if provider.get_world_description_id() != services.get_world_description_id(current_zone.world_id): return for board in services.object_manager().get_objects_with_tag_gen(BaseCivicPolicyProvider.COMMUNITY_BOARD_TAG): board.update_object_tooltip()
def get_zone_world_description_id(zone_id: int) -> int: """get_zone_world_description_id(zone_id) Retrieve the world description id of the a Zone. :param zone_id: The decimal identifier of a Zone. :type zone_id: int :return: The world description id of the the specified Zone. :rtype: int """ return services.get_world_description_id( CommonLocationUtils.get_zone_world_id(zone_id))
def change_state(self, new_state_type, skip_nudge=False): if self._curr_state_type is not new_state_type: old_state_type = self._curr_state_type self._eco_footprint_states[old_state_type].exit() self._eco_footprint_states[new_state_type].enter() self._curr_state_type = new_state_type if not skip_nudge: moving_toward_green = new_state_type < old_state_type nudge_amt = EcoFootprintTunables.ECO_FOOTPRINT_STATE_DATA.additional_footprint_change_on_state_change footprint = self.get_street_footprint() if moving_toward_green: footprint.add_value(-nudge_amt) else: footprint.add_value(nudge_amt) send_eco_footprint_state_change_telemetry( services.get_world_description_id( services.current_zone().world_id), old_state_type, new_state_type, self.get_street_footprint_convergence_value())
def generate_lot_info_data(*args, zone_id:int=None, filter=None, **kwargs): lot_infos = [] current_zone = services.current_zone() lot = current_zone.lot neighborhood_id = current_zone.neighborhood_id lot_description_id = services.get_lot_description_id(lot.lot_id) world_description_id = services.get_world_description_id(current_zone.world_id) neighborhood_description_id = services.get_persistence_service().get_neighborhood_proto_buff(neighborhood_id).region_id venue_manager = services.get_instance_manager(sims4.resources.Types.VENUE) for neighborhood_proto in services.get_persistence_service().get_neighborhoods_proto_buf_gen(): for lot_owner_info in neighborhood_proto.lots: zone_id = lot_owner_info.zone_instance_id while zone_id is not None: venue_type_id = build_buy.get_current_venue(zone_id) venue_type = venue_manager.get(venue_type_id) if venue_type is not None: cur_info = {'neighborhood': neighborhood_proto.name, 'region_id': neighborhood_proto.region_id, 'lot_desc_id': lot_owner_info.lot_description_id, 'zone_id': zone_id, 'venue_type': venue_type.__name__, 'lot_name': lot_owner_info.lot_name, 'cur_lot': 'X' if lot_owner_info.zone_instance_id == lot.zone_id else ''} lot_infos.append(cur_info) return lot_infos
def get_plex_door_infos(self, force_refresh=False): if self._plex_door_infos and not force_refresh: return self._plex_door_infos plex_service = services.get_plex_service() doors = self._get_doors() plex_door_infos = set() for door in doors: (front_position, back_position) = door.get_door_positions() if front_position is None or back_position is None: logger.error("Door '{}' has broken portals.", door) else: front_zone_id = plex_service.get_plex_zone_at_position( front_position, door.level) back_zone_id = plex_service.get_plex_zone_at_position( back_position, door.level) if front_zone_id is None and back_zone_id is None: current_zone = services.current_zone() lot = current_zone.lot world_description_id = services.get_world_description_id( current_zone.world_id) lot_description_id = services.get_lot_description_id( lot.lot_id, world_description_id) neighborhood_id = current_zone.neighborhood_id neighborhood_data = services.get_persistence_service( ).get_neighborhood_proto_buff(neighborhood_id) if False and EXEMPT_DOOR_WORLD_DESCRIPTION_ID == world_description_id and EXEMPT_DOOR_LOT_DESCRIPTION_ID == lot_description_id: continue logger.error( "Door isn't part of any plex. This will require WB fix. Door: {}, Lot desc id: {}, World desc id: {}. Neighborhood id: {}, Neighborhood Name: {}", door, lot_description_id, world_description_id, neighborhood_id, neighborhood_data.name) else: if front_zone_id == back_zone_id: continue zone_id = front_zone_id or back_zone_id is_backwards = front_zone_id is not None info = PlexDoorInfo(door_id=door.id, zone_id=zone_id, is_backwards=is_backwards) plex_door_infos.add(info) self._plex_door_infos = frozenset(plex_door_infos) return self._plex_door_infos
def _get_household_templates_and_bed_data(self, zone_id, household_population_data): total_beds = 0 lot_has_double_bed = False lot_has_kid_bed = False zone_data = services.get_persistence_service().get_zone_proto_buff(zone_id) if zone_data.gameplay_zone_data.HasField('bed_info_data'): world_description_id = services.get_world_description_id(zone_data.world_id) household_templates = household_population_data.street_description_to_templates.get(world_description_id) total_beds = zone_data.gameplay_zone_data.bed_info_data.num_beds lot_has_double_bed = zone_data.gameplay_zone_data.bed_info_data.double_bed_exist lot_has_kid_bed = zone_data.gameplay_zone_data.bed_info_data.kid_bed_exist if total_beds == 0: total_beds = zone_data.gameplay_zone_data.bed_info_data.alternative_sleeping_spots else: house_description_id = services.get_house_description_id(zone_data.lot_template_id, zone_data.lot_description_id) household_templates = household_population_data.household_description_to_templates.get(house_description_id) if household_templates: household_template = household_templates[0].household_template total_beds = household_template.num_members return (household_templates, total_beds, lot_has_double_bed, lot_has_kid_bed)
def __call__(self, *args, **kwargs): zone_id = self.zone_source.get_zone_id(**kwargs) if not zone_id: return TestResult(False, "ZoneTest couldn't find a zone to test.", tooltip=self.tooltip) if self.zone_tests.venue_type is not None: venue_service = services.venue_service() if self.zone_tests.use_source_venue: venue_tuning = type(venue_service.source_venue) else: venue_tuning = type(venue_service.active_venue) venue_tunings = (venue_tuning,) if venue_tuning is not None else () if not self.zone_tests.venue_type.test_collection(venue_tunings): return TestResult(False, 'Zone failed venue white or black list {}', venue_tuning, tooltip=self.tooltip) if self.zone_tests.venue_tier is not None: venue_tier_index = build_buy.get_venue_tier(zone_id) if self.zone_tests.venue_tier != venue_tier_index: return TestResult(False, 'Zone has tier {} but {} was required', venue_tier_index, self.zone_tests.venue_tier, tooltip=self.tooltip) if self.zone_tests.is_apartment is not None: plex_service = services.get_plex_service() if self.zone_tests.is_apartment.is_apartment != plex_service.is_zone_an_apartment(zone_id, consider_penthouse_an_apartment=self.zone_tests.is_apartment.consider_penthouse_an_apartment): return TestResult(False, 'Zone failed apartment test', tooltip=self.tooltip) if self.zone_tests.is_penthouse is not None: plex_service = services.get_plex_service() is_penthouse = plex_service.get_plex_building_type(zone_id) == PlexBuildingType.PENTHOUSE_PLEX if is_penthouse != self.zone_tests.is_penthouse: return TestResult(False, 'Zone failed penthouse test', tooltip=self.tooltip) if self.zone_tests.zone_modifiers is not None: zone_modifier_service = services.get_zone_modifier_service() zone_modifiers = zone_modifier_service.get_zone_modifiers(zone_id) if not self.zone_tests.zone_modifiers.test_collection(zone_modifiers): return TestResult(False, 'Zone failed to meet whitelist/blacklist for zone modifiers. ZoneId: {}, Mods: {}', zone_id, zone_modifiers, tooltip=self.tooltip) if self.zone_tests.world_tests is not None: world_id = services.get_persistence_service().get_world_id_from_zone(zone_id) world_desc_id = services.get_world_description_id(world_id) if world_desc_id == 0: return TestResult(False, 'Unable to determine world for Zone {}', zone_id) if not self.zone_tests.world_tests.test_item(world_desc_id): return TestResult(False, 'Zone {} failed to meet world requirements, is in {}, fails tests for {}', zone_id, world_desc_id, self.zone_tests.world_tests, tooltip=self.tooltip) if self.zone_tests.business_tests is not None: return self.zone_tests.business_tests(zone_id) return TestResult.TRUE
def increment_data(self, objective, resolver, event_data_tracker, result, additional_result): data_object = event_data_tracker.data_object if result and additional_result: zone_id = resolver.sim_info.zone_id world_id = services.get_persistence_service( ).get_world_id_from_zone(zone_id) world_desc_id = services.get_world_description_id(world_id) if world_desc_id == 0: return results.TestResult( False, 'Unable to determine world for Zone {}', zone_id) if world_desc_id is not None: data_object.add_objective_value(objective, world_id) self.on_increment_objective_data(event_data_tracker) count = data_object.get_objective_count(objective) if count < self.unique_worlds_required_to_pass: return results.TestResultNumeric( False, 'Objective: not enough matching world iterations.', current_value=count, goal_value=self.unique_worlds_required_to_pass, is_money=False) return results.TestResult.TRUE
def print_venues(_connection=None): current_zone = services.current_zone() lot = current_zone.lot neighborhood_id = current_zone.neighborhood_id lot_description_id = services.get_lot_description_id(lot.lot_id) world_description_id = services.get_world_description_id(current_zone.world_id) neighborhood_description_id = services.get_persistence_service().get_neighborhood_proto_buff(neighborhood_id).region_id def print_line(): sims4.commands.output('-'*150, _connection) print_line() sims4.commands.output('Current Game Stats: \nLot: {}\nWorld/Street: {}\nRegion/Neighborhood: {}'.format(lot_description_id, world_description_id, neighborhood_description_id), _connection) print_line() venue_manager = services.get_instance_manager(sims4.resources.Types.VENUE) venues = [] for neighborhood_proto in services.get_persistence_service().get_neighborhoods_proto_buf_gen(): for lot_owner_info in neighborhood_proto.lots: zone_id = lot_owner_info.zone_instance_id while zone_id is not None: venue_type_id = build_buy.get_current_venue(zone_id) venue_type = venue_manager.get(venue_type_id) if venue_type is not None: log = PrintVenueLog._make((neighborhood_proto.name, neighborhood_proto.region_id, lot_owner_info.lot_description_id, zone_id, venue_type.__name__, lot_owner_info.lot_name)) venues.append(log) str_format = '{:20} ({:{center}15}) {:{center}20} {:15} ({:{center}20}) {:20}' def print_columns(): sims4.commands.output(str_format.format('Neighborhood_Name', 'Neighborhood_ID', 'Lot_Description_ID', 'Zone_Instance_ID', 'Venue_Tuning_Name', 'Lot_Name', center='^'), _connection) print_columns() print_line() for venue in sorted(venues): sims4.commands.output(str_format.format(venue.Neighborhood_Name, venue.Neighborhood_ID, venue.Lot_Description_ID, venue.Zone_Instance_ID, venue.Venue_Tuning_Name, venue.Lot_Name, center='^'), _connection) print_line() print_columns()
def _fix_up_for_apartments(self): plex_door_infos = self.get_plex_door_infos(force_refresh=True) backward_doors = set() active_zone_id = services.current_zone_id() object_manager = services.object_manager() plex_doors = [] for info in plex_door_infos: household_id = services.get_persistence_service( ).get_household_id_from_zone_id(info.zone_id) door = object_manager.get(info.door_id) if door is None: logger.error('Plex Door {} does not exist.', info.door_id, owner='rmccord') else: if info.is_backwards: backward_doors.add(door) current_zone = services.current_zone() lot = current_zone.lot world_description_id = services.get_world_description_id( current_zone.world_id) lot_description_id = services.get_lot_description_id( lot.lot_id, world_description_id) neighborhood_id = current_zone.neighborhood_id neighborhood_data = services.get_persistence_service( ).get_neighborhood_proto_buff(neighborhood_id) logger.error( 'For WB: An apartment door facing the common area needs to be flipped. Lot desc id: {}, World desc id: {}. Neighborhood id: {}, Neighborhood Name: {}', lot_description_id, world_description_id, neighborhood_id, neighborhood_data.name) door.set_household_owner_id(household_id) if info.zone_id == active_zone_id: plex_doors.append(door) else: door.set_inactive_apartment_door_status(True) self._flip_backward_doors(backward_doors) if not plex_doors: return if len(plex_doors) == 1: self.set_as_front_door(plex_doors[0]) return logger.warn( "plex zone_id: {} has multiple potential front doors: {}, can lead to sims able to access areas they shouldn't", active_zone_id, plex_doors) best_door = None best_distance = None connections = self._get_door_connections_from_arrival( plex_doors, is_apartment=True) for (_, handle, distance) in connections: if not best_distance is None: if best_distance < distance: best_door = handle.door best_distance = distance best_door = handle.door best_distance = distance if best_door is None: logger.error( 'Unable to route to plex doors in zone_id: {} potential doors: {}', active_zone_id, plex_doors) self.set_as_front_door(plex_doors[0]) return self.set_as_front_door(best_door)
def get_street_instance_from_world_id(world_id): world_description_id = services.get_world_description_id(world_id) return Street.WORLD_DESCRIPTION_TUNING_MAP.get(world_description_id, None)
def get_world_description_id_from_zone_id(zone_id): zone_data = services.get_persistence_service().get_zone_proto_buff(zone_id) return services.get_world_description_id(zone_data.world_id)