示例#1
0
 def populate_community_board_op(self, sim_info, op, target_id):
     op.sim_id = sim_info.id
     op.target_id = target_id
     op.influence_points = self.get_influence(sim_info)
     op.title = self.community_board_dialog_title()
     if hasattr(op, 'schedule_text'):
         op.schedule_text = self.get_schedule_text()
     for policy in self._enacted_policies:
         with ProtocolBufferRollback(op.enacted_policies) as enacted_policy:
             enacted_policy.policy_id = policy.guid64
             if policy in self._up_for_repeal_policies:
                 if policy.vote_count_statistic is None:
                     enacted_policy.count = 0
                 else:
                     enacted_policy.count = int(self.get_stat_value(policy.vote_count_statistic))
     for policy in self._balloted_policies:
         with ProtocolBufferRollback(op.balloted_policies) as balloted_policy:
             balloted_policy.policy_id = policy.guid64
             stat = policy.vote_count_statistic
             if stat is None:
                 balloted_policy.count = 0
             else:
                 balloted_policy.count = int(self.get_stat_value(stat))
                 balloted_policy.max_count = stat.max_value
     op.provider_type = self.provider_type_id
     op.new_policy_allowed = self.is_new_policy_allowed(sim_info)
     if not services.street_service().voting_open:
         op.policy_disabled_tooltip = self.COMMUNITY_BOARD_TEXT.voting_closed_policy_tooltip_text()
     if not self.is_eligible_voter(sim_info):
         op.disabled_tooltip = self.COMMUNITY_BOARD_TEXT.ineligible_voter_confirm_tooltip_text(sim_info)
         op.policy_disabled_tooltip = self.COMMUNITY_BOARD_TEXT.ineligible_voter_policy_tooltip_text(sim_info)
 def __call__(self, test_targets=None):
     if not self.gameplay_option.supporting_pack_installed:
         return TestResult(False, '{} option missing required pack',
                           self.gameplay_option, self.tooltip)
     value = None
     if self.gameplay_option == TestableGameOptions.CIVIC_POLICY_NPC_VOTING_ENABLED or self.gameplay_option == TestableGameOptions.ECO_FOOTPRINT_GAMEPLAY:
         street_service = services.street_service()
         if street_service is not None:
             if self.gameplay_option == TestableGameOptions.CIVIC_POLICY_NPC_VOTING_ENABLED:
                 value = street_service.enable_automatic_voting
             else:
                 value = street_service.enable_eco_footprint
     if value is None:
         return TestResult(False,
                           'game option {} is unknown in current pack',
                           self.gameplay_option,
                           tooltip=self.tooltip)
     if self.invert:
         if value:
             return TestResult(False,
                               'test negated, game option {} is set to {}',
                               self.gameplay_option,
                               value,
                               tooltip=self.tooltip)
     elif not value:
         return TestResult(False,
                           'game option {} is set to {}',
                           self.gameplay_option,
                           value,
                           tooltip=self.tooltip)
     return TestResult.TRUE
示例#3
0
def buildbuy_session_end(zone_id):
    services.object_manager(
        zone_id).rebuild_objects_to_ignore_portal_validation_cache()
    for obj in services.object_manager(zone_id).get_all():
        obj.on_buildbuy_exit()
    posture_graph_service = services.current_zone().posture_graph_service
    posture_graph_service.on_exit_buildbuy()
    _build_buy_exit_callbacks()
    pythonutils.try_highwater_gc()
    services.get_zone_modifier_service(
    ).check_for_and_apply_new_zone_modifiers(zone_id)
    if _sync_venue_service_to_zone_venue_type(zone_id):
        zone_director = services.venue_service().get_zone_director()
        if zone_director is not None:
            zone_director.on_exit_buildbuy()
    object_preference_tracker = services.object_preference_tracker()
    if object_preference_tracker is not None:
        object_preference_tracker.validate_objects(zone_id)
    services.business_service().on_build_buy_exit()
    services.current_zone().on_build_buy_exit()
    services.utilities_manager().on_build_buy_exit()
    services.get_reset_and_delete_service().on_build_buy_exit()
    street_service = services.street_service()
    if street_service is not None:
        street = services.current_street()
        if street is not None:
            provider = street_service.get_provider(street)
            if provider is not None:
                provider.on_build_buy_exit()
    services.object_manager().clear_objects_to_ignore_portal_validation_cache()
 def is_eligible_voter(self, sim_info):
     household = sim_info.household
     if household is None:
         return False
     street = services.street_service().get_street(self)
     return street is world.street.get_street_instance_from_world_id(
         household.get_home_world_id())
def handle_community_board(community_board_response: str, _connection=None):
    proto = UI_pb2.CommunityBoardResponse()
    text_format.Merge(community_board_response, proto)
    sim_info = services.sim_info_manager().get(proto.sim_id)
    if sim_info is None:
        return
    if proto.provider_type == StreetProvider.provider_type_id:
        street_civic_policy_service = services.street_service()
        if street_civic_policy_service is None:
            sims4.commands.automation_output('Pack not loaded', _connection)
            sims4.commands.cheat_output('Pack not loaded', _connection)
            return
        world_id = sim_info.household.get_home_world_id()
        street = world.street.get_street_instance_from_world_id(world_id)
        provider = street_civic_policy_service.get_provider(street)
    else:
        source_venue = services.venue_service().source_venue
        if source_venue is None:
            return
        provider = source_venue.civic_policy_provider
    if provider is not None:
        for policy in proto.balloted_policies:
            policy_instance = provider.get_policy_instance_for_tuning(
                policy.policy_id)
            if policy_instance is None:
                continue
            provider.add_to_ballot(policy_instance)
            provider.vote_by_instance(policy_instance,
                                      policy.count,
                                      user_directed=True)
        provider.modify_influence(sim_info, -proto.influence_points)
        provider.handle_vote_interaction(sim_info, proto.target_id,
                                         bool(proto.balloted_policies))
 def _get_civic_policy_provider(self, *args, **kwargs):
     street_service = services.street_service()
     if street_service is None:
         return
     else:
         street = self._get_street(**kwargs)
         if street is not None:
             return street_service.get_provider(street)
def street_civic_policy_force_daily_vote(_connection=None):
    street_civic_policy_service = services.street_service()
    if street_civic_policy_service is None:
        sims4.commands.automation_output('Pack not loaded', _connection)
        sims4.commands.cheat_output('Pack not loaded', _connection)
        return
    services.get_event_manager().process_event(
        TestEvent.CivicPolicyDailyRandomVoting)
示例#8
0
 def finalize_startup(self, policy):
     self._policy = policy
     street_service = services.street_service()
     self._street = None if street_service is None else street_service.get_street(
         self.policy.provider)
     if self._street is None:
         logger.error('{} failed to get street from {}', self,
                      self.policy.provider)
 def get_street(self, *, subjects):
     street_service = services.street_service()
     if street_service is None:
         return
     if not subjects:
         logger.error(
             'Failed to resolve participant ParticipantType.Street.')
         return
     return street_service.get_street(subjects[0])
 def _save_street_eco_footprint_data(self, eco_footprint_data):
     eco_footprint_data.current_eco_footprint_state = self._curr_state_type
     eco_footprint_data.effects_are_simulated = self._simulating_eco_footprint_on_street
     street = services.street_service().get_street(self)
     if street is services.current_street(
     ) and not self._street_convergence_fully_computed:
         self._fully_compute_street_convergence()
     eco_footprint_data.convergence = self.get_street_footprint_convergence_value(
     )
示例#11
0
    def finalize_startup(self, policy):
        super().finalize_startup(policy)
        if self._street is None:
            return

        def handle_moved_sim_info(sim_info, old_street, new_street):
            if not self.policy.enacted:
                return
            if old_street is self._street and self.repeal_loot is not None:
                self._repeal_for_sim_info(sim_info)
            if new_street is self._street and self.enact_loot is not None:
                self._enact_for_sim_info(sim_info)

        services.street_service(
        ).register_sim_info_home_street_change_callback(
            self._street, handle_moved_sim_info)
        if self.policy.enacted:
            self._start_schedule()
示例#12
0
 def repeal(self):
     super().repeal()
     for effect in self._civic_policy_effects:
         effect.repeal()
     street_service = services.street_service()
     street = None if street_service is None else street_service.get_street(
         self.provider)
     services.get_event_manager().process_event(
         TestEvent.CivicPoliciesChanged,
         custom_keys=((street, type(self)), ))
 def get_world_description_id(self):
     street_service = services.street_service()
     if street_service is not None:
         world_description_id = world.street.get_world_description_id_from_street(
             street_service.get_street(self))
         if world_description_id is None:
             return 0
         else:
             return world_description_id
     return 0
def set_npc_voting_enabled(enabled: bool = False, _connection=None):
    street_civic_policy_service = services.street_service()
    if street_civic_policy_service is None:
        sims4.commands.automation_output('Pack not loaded', _connection)
        sims4.commands.cheat_output('Pack not loaded', _connection)
        return
    street_civic_policy_service.enable_automatic_voting = enabled
    services.get_event_manager().process_event(
        TestEvent.TestedGameOptionChanged,
        custom_keys=(TestableGameOptions.CIVIC_POLICY_NPC_VOTING_ENABLED, ))
示例#15
0
    def vote_by_instance(self, policy_instance, count=1, user_directed=False, lobby_interaction=False):
        if policy_instance.vote_count_statistic is not None:
            policy_list = None

            def get_current_rank():
                policy_list.sort(key=lambda policy: (self.get_stat_value(policy.vote_count_statistic), policy.guid64), reverse=True)
                return policy_list.index(policy_instance)

            if user_directed:
                factor = 0
                if policy_instance in self._balloted_policies:
                    policy_list = list(self._balloted_policies)
                    factor = 1
                elif policy_instance in self._up_for_repeal_policies:
                    policy_list = list(self._up_for_repeal_policies)
                    factor = -1
                orig_rank = get_current_rank()
            elif lobby_interaction:
                factor = 0
                if policy_instance in self._balloted_policies:
                    factor = 1
                elif policy_instance in self._up_for_repeal_policies:
                    factor = -1
            value = self.get_stat_value(policy_instance.vote_count_statistic) + count
            self.set_stat_value(policy_instance.vote_count_statistic, value)
            services.street_service().update_community_board_tooltip(self)
            if user_directed:
                if policy_list is not None:
                    with telemetry_helper.begin_hook(civic_policy_telemetry_writer, TELEMETRY_HOOK_CIVIC_POLICY_VOTE) as hook:
                        hook.write_guid(TELEMETRY_FIELD_NEIGHBORHOOD, self.get_world_description_id())
                        hook.write_guid(TELEMETRY_FIELD_POLICY, policy_instance.guid64)
                        hook.write_guid(TELEMETRY_FIELD_VOTES, factor*value)
                        hook.write_guid(TELEMETRY_FIELD_PLAYER_VOTES, factor*count)
                        hook.write_guid(TELEMETRY_FIELD_OLD_RANK, orig_rank)
                        hook.write_guid(TELEMETRY_FIELD_NEW_RANK, get_current_rank())
            if lobby_interaction:
                with telemetry_helper.begin_hook(civic_policy_telemetry_writer, TELEMETRY_HOOK_CIVIC_POLICY_LOBBY) as hook:
                    hook.write_guid(TELEMETRY_FIELD_NEIGHBORHOOD, self.get_world_description_id())
                    hook.write_guid(TELEMETRY_FIELD_POLICY, policy_instance.guid64)
                    hook.write_guid(TELEMETRY_FIELD_VOTES, factor*value)
            return True
        return False
示例#16
0
def set_eco_footprint_state(state: EcoFootprintStateType,
                            update_lot_footprint_values: bool = True,
                            _connection=None):
    street_service = services.street_service()
    if street_service is None:
        sims4.commands.automation_output('Pack not loaded', _connection)
        sims4.commands.cheat_output('Pack not loaded', _connection)
        return
    street_provider = street_service.get_provider(services.current_street())
    street_provider.force_set_eco_footprint_state(state,
                                                  update_lot_footprint_values)
示例#17
0
def set_eco_footprint_enabled(enabled: bool = True, _connection=None):
    street_service = services.street_service()
    if street_service is None:
        sims4.commands.automation_output('Pack not loaded', _connection)
        sims4.commands.cheat_output('Pack not loaded', _connection)
        return
    street_service.enable_eco_footprint = enabled
    services.get_event_manager().process_event(
        TestEvent.TestedGameOptionChanged,
        custom_keys=(TestableGameOptions.ECO_FOOTPRINT_GAMEPLAY, ))
    return True
示例#18
0
 def get_participants(self, participant_type, **kwargs):
     if participant_type == ParticipantType.Street:
         street_service = services.street_service()
         if street_service is None:
             return ()
         street_civic_policy_provider = street_service.get_provider(
             self._street)
         if street_civic_policy_provider is None:
             return ()
         return (street_civic_policy_provider, )
     return super().get_participants(participant_type, **kwargs)
 def run_auto_voting_tests(self, test_set):
     if not services.street_service().enable_automatic_voting:
         return False
     if not test_set:
         return True
     resolvers = list(self.open_close_voting_loot_resolver_list)
     resolvers.append(VenuePolicyProviderResolver(self))
     for resolver in resolvers:
         if test_set.run_tests(resolver):
             return True
     return False
 def _recompute_street_convergence(self, *args):
     street_footprint_stat = self.get_street_footprint()
     street_service = services.street_service()
     lot = services.active_lot()
     lot_footprint_value = lot.commodity_tracker.get_value(
         EcoFootprintTunables.LOT_FOOTPRINT)
     aggregate = self.inactive_lots_total + self.active_lot_weight * lot_footprint_value
     aggregate *= EcoFootprintTunables.get_product_of_tested_modifiers(
         street_service.get_street(self))
     street_footprint_stat.convergence_value = aggregate
     self._update_street_decay_rate()
     self._update_eco_footprint_effects()
def street_civic_policy_force_daily_vote(open_voting: bool = True,
                                         _connection=None):
    street_civic_policy_service = services.street_service()
    if street_civic_policy_service is None:
        sims4.commands.automation_output('Pack not loaded', _connection)
        sims4.commands.cheat_output('Pack not loaded', _connection)
        return
    street_civic_policy_service._force_voting_open = open_voting
    if open_voting:
        msg = 'Voting open, vote counts reset to 0'
        sims4.commands.automation_output(msg, _connection)
        sims4.commands.cheat_output(msg, _connection)
        street_civic_policy_service._open_voting()
示例#22
0
 def enact(self):
     street_service = services.street_service()
     if street_service is None:
         return
     (neighborhood_proto,
      street_data) = street_service.get_neighborhood_proto(self._street)
     if neighborhood_proto is None:
         logger.error('{} failed to find neighborhood data street info',
                      self)
         return
     if self.map_overlay not in street_data.map_overlays:
         street_data.map_overlays.append(self.map_overlay)
         self._send_update_msg(neighborhood_proto)
 def run_test(self, provider, tooltip):
     street_service = services.street_service()
     voting_open = street_service is not None and street_service.voting_open
     if voting_open:
         if self.negate:
             return TestResult(
                 False,
                 'Civic Policy Provider failed negated voting open',
                 tooltip=tooltip)
     elif not self.negate:
         return TestResult(False,
                           'Civic Policy Provider failed voting open',
                           tooltip=tooltip)
     return TestResult.TRUE
 def send_update_message(self):
     repeal_policy_id = 0
     repeal_sigs = 0
     for policy in self._up_for_repeal_policies:
         if policy.vote_count_statistic is None:
             repeal_sigs = 0
         else:
             repeal_sigs = int(
                 self.get_stat_value(policy.vote_count_statistic))
         repeal_policy_id = policy.guid64
     op = CivicPolicyPanelUpdate(services.street_service().voting_open,
                                 repeal_policy_id, repeal_sigs,
                                 self.get_schedule_text())
     Distributor.instance().add_op_with_no_owner(op)
示例#25
0
 def repeal(self):
     if self.map_overlay == MapOverlayEnum.NONE:
         logger.warn('{} tuned to an invalid map overlay {}', self,
                     self.map_overlay)
         return
     street_service = services.street_service()
     if street_service is None:
         return
     (neighborhood_proto,
      street_data) = street_service.get_neighborhood_proto(self._street,
                                                           add=False)
     if neighborhood_proto is None:
         return
     if self.map_overlay in street_data.map_overlays:
         street_data.map_overlays.remove(self.map_overlay)
         self._send_update_msg(neighborhood_proto)
 def finalize_startup(self):
     street_service = services.street_service()
     street = street_service.get_street(self)
     for (state_type, state) in self._eco_footprint_states.items():
         is_active = state_type == self._curr_state_type
         state.finalize_startup(is_active)
     if not self._is_eco_footprint_compatible:
         return
     if street is services.current_street():
         self._fully_compute_street_convergence()
         self.update_simulation_if_stale(
             street_service.enable_eco_footprint)
     elif self._simulating_eco_footprint_on_street:
         if self._persisted_convergence is not None:
             footprint_stat = self.get_street_footprint()
             footprint_stat.convergence_value = self._persisted_convergence
 def force_set_eco_footprint_value(self, new_value, update_lot_values=True):
     if not self._is_eco_footprint_compatible:
         return
     street = services.street_service().get_street(self)
     street_footprint = self.get_street_footprint()
     street_footprint.set_value(new_value)
     if update_lot_values:
         zone_manager = services.get_zone_manager()
         for (lot_id, zone_ids
              ) in world.street.get_lot_id_to_zone_ids_dict(street).items():
             zone = zone_manager.get(zone_ids[0],
                                     allow_uninstantiated_zones=True)
             if zone is not None:
                 zone.lot.commodity_tracker.set_value(
                     EcoFootprintTunables.LOT_FOOTPRINT, new_value)
         self._fully_compute_street_convergence()
     self._update_eco_footprint_effects(skip_nudge=True)
 def run_test(self, provider, tooltip):
     street_service = services.street_service()
     voting_open = street_service is not None and street_service.voting_open
     if voting_open:
         time_of_change = street_service.voting_close_time
     else:
         time_of_change = street_service.voting_open_time
     now = services.time_service().sim_now
     time_left = time_of_change - now
     if callable(self.threshold.value):
         self.threshold.value = self.threshold.value()
     result = self.threshold.compare(time_left)
     if not result:
         return TestResult(
             False,
             'Civic Policy Provider failed voting time until change test',
             tooltip=tooltip)
     return TestResult.TRUE
def street_civic_policy_repeal(policy: TunableInstanceParam(
    sims4.resources.Types.SNIPPET),
                               opt_target: OptionalSimInfoParam = None,
                               _connection=None):
    street_service = services.street_service()
    if street_service is None:
        sims4.commands.automation_output('Pack not loaded', _connection)
        sims4.commands.cheat_output('Pack not loaded', _connection)
        return
    sim = get_optional_target(opt_target,
                              _connection,
                              target_type=OptionalSimInfoParam)
    world_id = sim.household.get_home_world_id()
    street = world.street.get_street_instance_from_world_id(world_id)
    if not street_service.repeal(street, policy):
        sims4.commands.automation_output('{} not repealed'.format(policy),
                                         _connection)
        sims4.commands.cheat_output('{} not repealed'.format(policy),
                                    _connection)
def street_civic_policy_add_influence(count: int = 1,
                                      opt_target: OptionalSimInfoParam = None,
                                      _connection=None):
    street_civic_policy_service = services.street_service()
    if street_civic_policy_service is None:
        sims4.commands.automation_output('Pack not loaded', _connection)
        sims4.commands.cheat_output('Pack not loaded', _connection)
        return
    sim = get_optional_target(opt_target,
                              _connection,
                              target_type=OptionalSimInfoParam)
    world_id = sim.household.get_home_world_id()
    street = world.street.get_street_instance_from_world_id(world_id)
    provider = street_civic_policy_service.get_provider(street)
    if provider is None:
        sims4.commands.automation_output('Street has no provider', _connection)
        sims4.commands.cheat_output('Street has no provider', _connection)
        return
    provider.modify_influence(sim.sim_info, count)