Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Forum Resident
Original Poster
#1 Old 22nd Nov 2018 at 1:22 PM Last edited by Dorsal Axe : 22nd Nov 2018 at 9:43 PM.
Default Fixing the City Living NPC names bug
I've been looking into this since it's been driving me nuts seeing every single NPC Sim get a Japanese name regardless of ethnicity. There's a mod that basically removes all of the ethnic names to force the game to use the originals, but that means that the ethnic Sims from EP03 don't use the names they were intended to generate with. I was pretty interested in figuring out why it happens, so I did a little digging.

Basically City Living introduced a name_type parameter which is used by all of its Sim templates. All of the ethnic names in the master list are categorised by these name types: Japanese, Moroccan, Indian. Later EPs introduce Cat, Dog, Skeleton, Latin and none of these NPCs generate incorrectly. Looking at the original names, they are not classed as any specific name_type and are presumably meant to be the default name set. It seems likely that the game was supposed to fall back to the default names if a specific name_type isn't specified in a template, but the process fails for some reason and defaults to names of the first listed name_type which is Japanese.

I figure that there are three ways to resolve it:
1. Remove all the cultural names so the game can't use them.
This is what No/Less City Living townie names! by simmytime does. Works perfectly fine except that the CL cultural names can never be used.
2. Add a new name_type for the original name list and update existing templates, so that the game uses all names appropriately.
This is doable but there are hundreds of templates to update, so it's a not very efficient way of fixing this.
3. Look at the script that handles name_types and see what's actually borking up the process.

And so I'm at option 3. Unfortunately I'm not very well versed in Python, so I thought I'd ask here if anyone could look at this snippet of code from sim_spawner.py and see what might be amiss. I've bolded the sections that I think might be relevant.

Code:
    @classmethod
    def _get_random_name_tuning(cls, language, sim_name_type=SimNameType.DEFAULT):
        language_mapping = SimSpawner.SIM_NAME_TYPE_TO_LOCALE_NAMES.get(sim_name_type, SimSpawner.RANDOM_NAME_TUNING)
        tuning = language_mapping.get(language)
        if tuning is None:
            tuning = language_mapping.get(Language.ENGLISH)
        return tuning

    @classmethod
    def get_random_first_name(cls, 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_random_first_name(cls._get_language_for_locale(services.get_locale()), gender == Gender.FEMALE, sim_name_type=sim_name_type)

    @classmethod
    def _get_random_first_name(cls, language, is_female, sim_name_type=SimNameType.DEFAULT) -> int:
        tuning = cls._get_random_name_tuning(language, sim_name_type=sim_name_type)
        name_list = tuning.female_first_names if is_female else tuning.male_first_names
        return random.choice(name_list)

    @classmethod
    def _get_random_last_name(cls, language, sim_name_type=SimNameType.DEFAULT) -> int:
        tuning = cls._get_random_name_tuning(language, sim_name_type=sim_name_type)
        return random.choice(tuning.last_names)

    @classmethod
    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)

    @classmethod
    def _get_family_name_for_gender(cls, language, family_name, is_female, sim_name_type=SimNameType.DEFAULT) -> str:
        if sim_name_type in cls.NAME_TYPES_WITH_OPTIONAL_NAMES:
            return ''
        tuning = cls._get_random_name_tuning(language, sim_name_type=sim_name_type)
        if tuning.female_last_names:
            if family_name in tuning.female_last_names:
                if is_female:
                    return family_name
                index = tuning.female_last_names.index(family_name)
                return tuning.last_names[index]
            if family_name in tuning.last_names:
                if not is_female:
                    return family_name
                else:
                    index = tuning.last_names.index(family_name)
                    return tuning.female_last_names[index]
        return family_name

    @classmethod
    def _get_language_for_locale(cls, locale) -> Language:
        language = SimSpawner.LOCALE_MAPPING.get(locale, Language.ENGLISH)
        return language
Back to top