Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIRROR] Random Name Generation refactor, generate random names based on languages (for species without name lists, like Felinids and Podpeople) #3268

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions code/__DEFINES/~ff_defines/__HELPERS/names.dm
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,10 @@
if(1)//1 and 2 can only be selected once each to prevent more than two specific names/places/etc.
switch(rand(1,2))//Mainly to add more options later.
if(1)
if(names.len && prob(70))
if(length(names) && prob(70))
. += pick(names)
else
if(prob(10))
. += pick(lizard_name(MALE),lizard_name(FEMALE))
else
var/new_name = pick(pick(GLOB.first_names_male,GLOB.first_names_female))
new_name += " "
new_name += pick(GLOB.last_names)
. += new_name
. += generate_random_name()
if(2)
var/datum/job/job = pick(SSjob.joinable_occupations)
if(job)
Expand Down
8 changes: 0 additions & 8 deletions code/__HELPERS/global_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@
GLOB.blooper_random_list[B.id] = sound_blooper_path
//THE FLUFFY FRONTIER EDIT END

/// Inits GLOB.species_list. Not using GLOBAL_LIST_INIT b/c it depends on GLOB.string_lists
/proc/init_species_list()
for(var/species_path in subtypesof(/datum/species))
var/datum/species/species = new species_path()
GLOB.species_list[species.id] = species_path
sort_list(GLOB.species_list, GLOBAL_PROC_REF(cmp_typepaths_asc))

/// Inits GLOB.surgeries
/proc/init_surgeries()
var/surgeries = list()
Expand All @@ -90,7 +83,6 @@
/proc/make_datum_reference_lists()
// I tried to eliminate this proc but I couldn't untangle their init-order interdependencies -Dominion/Cyberboss
init_sprite_accessories()
init_species_list()
init_hair_gradients()
init_keybindings()
GLOB.emote_list = init_emote_list() // WHY DOES THIS NEED TO GO HERE? IT JUST INITS DATUMS
Expand Down
44 changes: 0 additions & 44 deletions code/__HELPERS/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -134,47 +134,6 @@
else
return pick(GLOB.facial_hairstyles_list)

/proc/random_unique_name(gender, attempts_to_find_unique_name=10)
for(var/i in 1 to attempts_to_find_unique_name)
if(gender == FEMALE)
. = capitalize(pick(GLOB.first_names_female)) + " " + capitalize(pick(GLOB.last_names))
else
. = capitalize(pick(GLOB.first_names_male)) + " " + capitalize(pick(GLOB.last_names))

if(!findname(.))
break

/proc/random_unique_lizard_name(gender, attempts_to_find_unique_name=10)
for(var/i in 1 to attempts_to_find_unique_name)
. = capitalize(lizard_name(gender))

if(!findname(.))
break

/proc/random_unique_plasmaman_name(attempts_to_find_unique_name=10)
for(var/i in 1 to attempts_to_find_unique_name)
. = capitalize(plasmaman_name())

if(!findname(.))
break

/proc/random_unique_ethereal_name(attempts_to_find_unique_name=10)
for(var/i in 1 to attempts_to_find_unique_name)
. = capitalize(ethereal_name())

if(!findname(.))
break

/proc/random_unique_moth_name(attempts_to_find_unique_name=10)
for(var/i in 1 to attempts_to_find_unique_name)
. = capitalize(pick(GLOB.moth_first)) + " " + capitalize(pick(GLOB.moth_last))

if(!findname(.))
break

/proc/random_skin_tone()
return pick(GLOB.skin_tones)

GLOBAL_LIST_INIT(skin_tones, sort_list(list(
"albino",
"caucasian1",
Expand Down Expand Up @@ -213,9 +172,6 @@ GLOBAL_LIST_INIT(skin_tone_names, list(
"mixed4" = "Macadamia",
))

/// An assoc list of species IDs to type paths
GLOBAL_LIST_EMPTY(species_list)

/proc/age2agedescription(age)
switch(age)
if(0 to 30) //NOVA EDIT CHANGE - NO
Expand Down
94 changes: 72 additions & 22 deletions code/__HELPERS/names.dm
Original file line number Diff line number Diff line change
@@ -1,20 +1,75 @@
/proc/lizard_name(gender)
if(gender == MALE)
return "[pick(GLOB.lizard_names_male)]-[pick(GLOB.lizard_names_male)]"
else
return "[pick(GLOB.lizard_names_female)]-[pick(GLOB.lizard_names_female)]"
/**
* Generate a random name based off of one of the roundstart languages
*
* * gender - What gender to pick from. Picks between male, female if not provided.
* * unique - If the name should be unique, IE, avoid picking names that mobs already have.
* * list/language_weights - A list of language weights to pick from.
* If not provided, it will default to a list of roundstart languages, with common being the most likely.
*/
/proc/generate_random_name(gender, unique, list/language_weights)
if(isnull(language_weights))
language_weights = list()
for(var/lang_type in GLOB.uncommon_roundstart_languages)
language_weights[lang_type] = 1
language_weights[/datum/language/common] = 20

var/datum/language/picked = GLOB.language_datum_instances[pick_weight(language_weights)]
if(unique)
return picked.get_random_unique_name(gender)
return picked.get_random_name(gender)

/**
* Generate a random name based off of a species
* This will pick a name from the species language, and avoid picking common if there are alternatives
*
* * gender - What gender to pick from. Picks between male, female if not provided.
* * unique - If the name should be unique, IE, avoid picking names that mobs already have.
* * datum/species/species_type - The species to pick from
* * include_all - Makes the generated name a mix of all the languages the species can speak rather than just one of them
* Does this on a per-name basis, IE "Lizard first name, uncommon last name".
*/
/proc/generate_random_name_species_based(gender, unique, datum/species/species_type, include_all = FALSE)
ASSERT(ispath(species_type, /datum/species))
var/datum/language_holder/holder = GLOB.prototype_language_holders[species_type::species_language_holder]

/proc/ethereal_name()
var/tempname = "[pick(GLOB.ethereal_names)] [random_capital_letter()]"
if(prob(65))
tempname += random_capital_letter()
return tempname
var/list/languages_to_pick_from = list()
for(var/language in holder.spoken_languages)
languages_to_pick_from[language] = 1

/proc/plasmaman_name()
return "[pick(GLOB.plasmaman_names)] \Roman[rand(1,99)]"
if(length(languages_to_pick_from) >= 2)
// Basically, if we have alternatives, don't pick common it's boring
languages_to_pick_from -= /datum/language/common

/proc/moth_name()
return "[pick(GLOB.moth_first)] [pick(GLOB.moth_last)]"
if(!include_all || length(languages_to_pick_from) <= 1)
return generate_random_name(gender, unique, languages_to_pick_from)

var/list/name_parts = list()
for(var/lang_type in shuffle(languages_to_pick_from))
name_parts += GLOB.language_datum_instances[lang_type].get_random_name(gender, name_count = 1, force_use_syllables = TRUE)
return jointext(name_parts, " ")

/**
* Generates a random name for the mob based on their gender or species (for humans)
*
* * unique - If the name should be unique, IE, avoid picking names that mobs already have.
*/
/mob/proc/generate_random_mob_name(unique)
return generate_random_name_species_based(gender, unique, /datum/species/human)

/mob/living/carbon/generate_random_mob_name(unique)
return generate_random_name_species_based(gender, unique, dna?.species?.type || /datum/species/human)

/mob/living/silicon/generate_random_mob_name(unique)
return generate_random_name(gender, unique, list(/datum/language/machine = 1))

/mob/living/basic/drone/generate_random_mob_name(unique)
return generate_random_name(gender, unique, list(/datum/language/machine = 1))

/mob/living/basic/bot/generate_random_mob_name(unique)
return generate_random_name(gender, unique, list(/datum/language/machine = 1))

/mob/living/simple_animal/bot/generate_random_mob_name(unique)
return generate_random_name(gender, unique, list(/datum/language/machine = 1))

GLOBAL_VAR(command_name)
/proc/command_name()
Expand Down Expand Up @@ -195,16 +250,11 @@ GLOBAL_DATUM(syndicate_code_response_regex, /regex)
if(1)//1 and 2 can only be selected once each to prevent more than two specific names/places/etc.
switch(rand(1,2))//Mainly to add more options later.
if(1)
if(names.len && prob(70))
if(length(names) && prob(70))
. += pick(names)
else
if(prob(10))
. += pick(lizard_name(MALE),lizard_name(FEMALE))
else
var/new_name = pick(pick(GLOB.first_names_male,GLOB.first_names_female))
new_name += " "
new_name += pick(GLOB.last_names)
. += new_name
. += generate_random_name()

if(2)
var/datum/job/job = pick(SSjob.joinable_occupations)
if(job)
Expand Down
51 changes: 47 additions & 4 deletions code/_globalvars/lists/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,54 @@ GLOBAL_LIST_EMPTY(revenant_relay_mobs)

///underages who have been reported to security for trying to buy things they shouldn't, so they can't spam
GLOBAL_LIST_EMPTY(narcd_underages)
/// List of language prototypes to reference, assoc [type] = prototype
GLOBAL_LIST_INIT_TYPED(language_datum_instances, /datum/language, init_language_prototypes())
/// List if all language typepaths learnable, IE, those with keys
GLOBAL_LIST_INIT(all_languages, init_all_languages())
// /List of language prototypes to reference, assoc "name" = typepath
GLOBAL_LIST_INIT(language_types_by_name, init_language_types_by_name())

/proc/init_language_prototypes()
var/list/lang_list = list()
for(var/datum/language/lang_type as anything in typesof(/datum/language))
if(!initial(lang_type.key))
continue

lang_list[lang_type] = new lang_type()
return lang_list

GLOBAL_LIST_EMPTY(language_datum_instances)
GLOBAL_LIST_EMPTY(all_languages)
///List of all languages ("name" = type)
GLOBAL_LIST_EMPTY(language_types_by_name)
/proc/init_all_languages()
var/list/lang_list = list()
for(var/datum/language/lang_type as anything in typesof(/datum/language))
if(!initial(lang_type.key))
continue
lang_list += lang_type
return lang_list

/proc/init_language_types_by_name()
var/list/lang_list = list()
for(var/datum/language/lang_type as anything in typesof(/datum/language))
if(!initial(lang_type.key))
continue
lang_list[initial(lang_type.name)] = lang_type
return lang_list

/// An assoc list of species IDs to type paths
GLOBAL_LIST_INIT(species_list, init_species_list())
/// List of all species prototypes to reference, assoc [type] = prototype
GLOBAL_LIST_INIT_TYPED(species_prototypes, /datum/species, init_species_prototypes())

/proc/init_species_list()
var/list/species_list = list()
for(var/datum/species/species_path as anything in subtypesof(/datum/species))
species_list[initial(species_path.id)] = species_path
return species_list

/proc/init_species_prototypes()
var/list/species_list = list()
for(var/species_type in subtypesof(/datum/species))
species_list[species_type] = new species_type()
return species_list

GLOBAL_LIST_EMPTY(sentient_disease_instances)

Expand Down
4 changes: 2 additions & 2 deletions code/_globalvars/lists/names.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ GLOBAL_LIST_INIT(first_names, world.file2list("strings/names/first.txt"))
GLOBAL_LIST_INIT(first_names_male, world.file2list("strings/names/first_male.txt"))
GLOBAL_LIST_INIT(first_names_female, world.file2list("strings/names/first_female.txt"))
GLOBAL_LIST_INIT(last_names, world.file2list("strings/names/last.txt"))
GLOBAL_LIST_INIT(lizard_names_male, world.file2list("strings/names/lizard_male.txt"))
GLOBAL_LIST_INIT(lizard_names_female, world.file2list("strings/names/lizard_female.txt"))
GLOBAL_LIST_INIT(clown_names, world.file2list("strings/names/clown.txt"))
GLOBAL_LIST_INIT(mime_names, world.file2list("strings/names/mime.txt"))
GLOBAL_LIST_INIT(religion_names, world.file2list("strings/names/religion.txt"))
GLOBAL_LIST_INIT(carp_names, world.file2list("strings/names/carp.txt"))
GLOBAL_LIST_INIT(lizard_names_male, world.file2list("strings/names/lizard_male.txt"))
GLOBAL_LIST_INIT(lizard_names_female, world.file2list("strings/names/lizard_female.txt"))
GLOBAL_LIST_INIT(golem_names, world.file2list("strings/names/golem.txt"))
GLOBAL_LIST_INIT(moth_first, world.file2list("strings/names/moth_first.txt"))
GLOBAL_LIST_INIT(moth_last, world.file2list("strings/names/moth_last.txt"))
Expand Down
16 changes: 0 additions & 16 deletions code/controllers/subsystem/language.dm

This file was deleted.

4 changes: 2 additions & 2 deletions code/datums/brain_damage/imaginary_friend.dm
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@

/// Randomise friend name and appearance
/mob/camera/imaginary_friend/proc/setup_friend()
var/gender = pick(MALE, FEMALE)
real_name = random_unique_name(gender)
gender = pick(MALE, FEMALE)
real_name = generate_random_name_species_based(gender, FALSE, /datum/species/human)
name = real_name
human_image = get_flat_human_icon(null, pick(SSjob.joinable_occupations))
Show()
Expand Down
2 changes: 1 addition & 1 deletion code/datums/diseases/advance/symptoms/voice_change.dm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
else
if(ishuman(M))
var/mob/living/carbon/human/H = M
H.SetSpecialVoice(H.dna.species.random_name(H.gender))
H.SetSpecialVoice(H.generate_random_mob_name())
if(scramble_language && !current_language) // Last part prevents rerolling language with small amounts of cure.
current_language = pick(subtypesof(/datum/language) - /datum/language/common)
H.add_blocked_language(subtypesof(/datum/language) - current_language, LANGUAGE_VOICECHANGE)
Expand Down
4 changes: 2 additions & 2 deletions code/datums/dna.dm
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ GLOBAL_LIST_INIT(total_uf_len_by_block, populate_total_uf_len_by_block())
for(var/species_path in subtypesof(/datum/species))
all_species_protoypes += new species_path()

for(var/datum/species/random_species as anything in all_species_protoypes)
features |= random_species.randomize_features()
for(var/species_type in GLOB.species_prototypes)
features |= GLOB.species_prototypes[species_type].randomize_features()
NOVA EDIT REMOVAL END */

features = species.randomize_features() | features // NOVA EDIT CHANGE - Where applicable, replace features with the features generated by species/randomize_features() - Original: features["mcolor"] = "#[random_color()]"
Expand Down
6 changes: 2 additions & 4 deletions code/game/machinery/computer/records/security.dm
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@
if(prob(10/severity))
switch(rand(1,5))
if(1)
if(prob(10))
target.name = "[pick(lizard_name(MALE),lizard_name(FEMALE))]"
else
target.name = "[pick(pick(GLOB.first_names_male), pick(GLOB.first_names_female))] [pick(GLOB.last_names)]"
target.name = generate_random_name()

if(2)
target.gender = pick("Male", "Female", "Other")
if(3)
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/cardboard_cutouts.dm
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
outfit = /datum/outfit/ashwalker/spear

/datum/cardboard_cutout/ash_walker/get_name()
return lizard_name(pick(MALE, FEMALE))
return generate_random_name_species_based(species_type = /datum/species/lizard)

/datum/cardboard_cutout/death_squad
name = "Deathsquad Officer"
Expand Down
3 changes: 1 addition & 2 deletions code/game/objects/items/debug_items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

/obj/item/debug/human_spawner/attack_self(mob/user)
..()
var/choice = input("Select a species", "Human Spawner", null) in GLOB.species_list
var/choice = input("Select a species", "Human Spawner", null) in sortTim(GLOB.species_list, GLOBAL_PROC_REF(cmp_text_asc))
selected_species = GLOB.species_list[choice]

/obj/item/debug/omnitool
Expand Down Expand Up @@ -168,4 +168,3 @@
var/turf/loc_turf = get_turf(src)
for(var/spawn_atom in (choice == "No" ? typesof(path) : subtypesof(path)))
new spawn_atom(loc_turf)

2 changes: 1 addition & 1 deletion code/game/objects/structures/headpike.dm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
victim = locate() in parts_list
if(!victim) //likely a mapspawned one
victim = new(src)
victim.real_name = random_unique_name(prob(50))
victim.real_name = generate_random_name()
spear = locate(speartype) in parts_list
if(!spear)
spear = new speartype(src)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/admin/create_mob.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
/proc/randomize_human(mob/living/carbon/human/human, randomize_mutations = FALSE)
human.gender = human.dna.species.sexes ? pick(MALE, FEMALE, PLURAL, NEUTER) : PLURAL
human.physique = human.gender
human.real_name = human.dna?.species.random_name(human.gender) || random_unique_name(human.gender)
human.real_name = human.generate_random_mob_name()
human.name = human.get_visible_name()
human.set_hairstyle(random_hairstyle(human.gender), update = FALSE)
human.set_facial_hairstyle(random_facial_hairstyle(human.gender), update = FALSE)
human.set_haircolor("#[random_color()]", update = FALSE)
human.set_facial_haircolor(human.hair_color, update = FALSE)
human.eye_color_left = random_eye_color()
human.eye_color_right = human.eye_color_left
human.skin_tone = random_skin_tone()
human.skin_tone = pick(GLOB.skin_tones)
human.dna.species.randomize_active_underwear_only(human)
// Needs to be called towards the end to update all the UIs just set above
human.dna.initialize_dna(newblood_type = random_blood_type(), create_mutation_blocks = randomize_mutations, randomize_features = TRUE)
Expand Down
Loading
Loading