From ebe0b82bb0b3412d62fb809ccdee20ed235df244 Mon Sep 17 00:00:00 2001 From: Fox McCloud Date: Mon, 23 Jul 2018 01:28:58 -0400 Subject: [PATCH] Species Refactor Fixes --- code/__HELPERS/global_lists.dm | 7 +++---- code/__HELPERS/mobs.dm | 2 +- code/_globalvars/lists/mobs.dm | 2 +- code/datums/datumvars.dm | 4 ++-- code/modules/client/preference/preferences.dm | 14 +++++++------- .../client/preference/preferences_mysql.dm | 2 +- .../modules/mob/living/carbon/human/appearance.dm | 15 ++------------- code/modules/mob/new_player/new_player.dm | 2 +- code/modules/mob/new_player/preferences_setup.dm | 6 +++--- code/modules/nano/modules/human_appearance.dm | 4 ++-- 10 files changed, 23 insertions(+), 35 deletions(-) diff --git a/code/__HELPERS/global_lists.dm b/code/__HELPERS/global_lists.dm index 2a81cca7045..a068bb8604e 100644 --- a/code/__HELPERS/global_lists.dm +++ b/code/__HELPERS/global_lists.dm @@ -38,12 +38,11 @@ language_keys[".[lowertext(L.key)]"] = L language_keys["#[lowertext(L.key)]"] = L - var/list/paths = subtypesof(/datum/species) var/rkey = 0 - for(var/T in paths) - var/datum/species/S = new T + for(var/spath in subtypesof(/datum/species)) + var/datum/species/S = new spath() S.race_key = ++rkey //Used in mob icon caching. - all_species[S.name] = S + GLOB.all_species[S.name] = S if(IS_WHITELISTED in S.species_traits) whitelisted_species += S.name diff --git a/code/__HELPERS/mobs.dm b/code/__HELPERS/mobs.dm index 3a6e8be62ac..3d495964cb0 100644 --- a/code/__HELPERS/mobs.dm +++ b/code/__HELPERS/mobs.dm @@ -178,7 +178,7 @@ proc/random_name(gender, species = "Human") var/datum/species/current_species if(species) - current_species = all_species[species] + current_species = GLOB.all_species[species] if(!current_species || current_species.name == "Human") if(gender==FEMALE) diff --git a/code/_globalvars/lists/mobs.dm b/code/_globalvars/lists/mobs.dm index 28ebfca6b1b..7cc456f9440 100644 --- a/code/_globalvars/lists/mobs.dm +++ b/code/_globalvars/lists/mobs.dm @@ -1,5 +1,5 @@ //Languages/species/whitelist. //Languages and species fit with mobs right -var/global/list/all_species[0] +GLOBAL_LIST_EMPTY(all_species) var/global/list/all_languages[0] var/global/list/language_keys[0] // Table of say codes for all languages var/global/list/all_superheroes[0] diff --git a/code/datums/datumvars.dm b/code/datums/datumvars.dm index 18d80b40e21..27d92b085fd 100644 --- a/code/datums/datumvars.dm +++ b/code/datums/datumvars.dm @@ -1010,13 +1010,13 @@ to_chat(usr, "This can only be done to instances of type /mob/living/carbon/human") return - var/new_species = input("Please choose a new species.","Species",null) as null|anything in all_species + var/new_species = input("Please choose a new species.","Species",null) as null|anything in GLOB.all_species if(!H) to_chat(usr, "Mob doesn't exist anymore") return - var/datum/species/S = all_species[new_species] + var/datum/species/S = GLOB.all_species[new_species] if(H.set_species(S.type)) to_chat(usr, "Set species of [H] to [H.dna.species].") H.regenerate_icons() diff --git a/code/modules/client/preference/preferences.dm b/code/modules/client/preference/preferences.dm index 8edec3a7b29..f3919c2ba27 100644 --- a/code/modules/client/preference/preferences.dm +++ b/code/modules/client/preference/preferences.dm @@ -246,10 +246,10 @@ var/global/list/special_role_times = list( //minimum age (in days) for accounts switch(current_tab) if(TAB_CHAR) // Character Settings - var/datum/species/S = all_species[species] + var/datum/species/S = GLOB.all_species[species] if(!istype(S)) //The species was invalid. Set the species to the default, fetch the datum for that species and generate a random character. species = initial(species) - S = all_species[species] + S = GLOB.all_species[species] random_character() dat += "
" @@ -828,7 +828,7 @@ var/global/list/special_role_times = list( //minimum age (in days) for accounts return 1 /datum/preferences/proc/ShowDisabilityState(mob/user,flag,label) - var/datum/species/S = all_species[species] + var/datum/species/S = GLOB.all_species[species] if(flag==DISABILITY_FLAG_FAT && !(CAN_BE_FAT in S.species_traits)) return "
  • [species] cannot be fat.
  • " return "
  • [label]: [disabilities & flag ? "Yes" : "No"]
  • " @@ -1053,7 +1053,7 @@ var/global/list/special_role_times = list( //minimum age (in days) for accounts /datum/preferences/proc/process_link(mob/user, list/href_list) if(!user) return - var/datum/species/S = all_species[species] + var/datum/species/S = GLOB.all_species[species] if(href_list["preference"] == "job") switch(href_list["task"]) if("close") @@ -1291,7 +1291,7 @@ var/global/list/special_role_times = list( //minimum age (in days) for accounts new_species += whitelisted_species species = input("Please select a species", "Character Generation", null) in new_species - var/datum/species/NS = all_species[species] + var/datum/species/NS = GLOB.all_species[species] if(!istype(NS)) //The species was invalid. Notify the user and fail out. species = prev_species to_chat(user, "Invalid species, please pick something else.") @@ -2083,8 +2083,8 @@ var/global/list/special_role_times = list( //minimum age (in days) for accounts return 1 /datum/preferences/proc/copy_to(mob/living/carbon/human/character) - var/datum/species/S = all_species[species] - character.change_species(S.type) // Yell at me if this causes everything to melt + var/datum/species/S = GLOB.all_species[species] + character.set_species(S.type) // Yell at me if this causes everything to melt if(be_random_name) real_name = random_name(gender,species) diff --git a/code/modules/client/preference/preferences_mysql.dm b/code/modules/client/preference/preferences_mysql.dm index a175e39bc71..318cf8fb0bb 100644 --- a/code/modules/client/preference/preferences_mysql.dm +++ b/code/modules/client/preference/preferences_mysql.dm @@ -252,7 +252,7 @@ autohiss_mode = text2num(query.item[52]) //Sanitize - var/datum/species/SP = all_species[species] + var/datum/species/SP = GLOB.all_species[species] metadata = sanitize_text(metadata, initial(metadata)) real_name = reject_bad_name(real_name, 1) if(isnull(species)) species = "Human" diff --git a/code/modules/mob/living/carbon/human/appearance.dm b/code/modules/mob/living/carbon/human/appearance.dm index 3f79b90628d..d19051692ca 100644 --- a/code/modules/mob/living/carbon/human/appearance.dm +++ b/code/modules/mob/living/carbon/human/appearance.dm @@ -3,17 +3,6 @@ AC.flags = flags AC.ui_interact(user, state = state) -/mob/living/carbon/human/proc/change_species(datum/species/new_species) - if(!new_species || dna.species.type == new_species || !ispath(new_species, /datum/species)) - return FALSE - - set_species(new_species, null, TRUE) - reset_hair() - if(dna.species.bodyflags & HAS_MARKINGS) - reset_markings() - - return TRUE - /mob/living/carbon/human/proc/change_gender(var/new_gender, var/update_dna = 1) var/obj/item/organ/external/head/H = bodyparts_by_name["head"] if(gender == new_gender || (gender == PLURAL && dna.species.has_gender)) @@ -321,8 +310,8 @@ /mob/living/carbon/human/proc/generate_valid_species(var/check_whitelist = 1, var/list/whitelist = list(), var/list/blacklist = list()) var/list/valid_species = new() - for(var/current_species_name in all_species) - var/datum/species/current_species = all_species[current_species_name] + for(var/current_species_name in GLOB.all_species) + var/datum/species/current_species = GLOB.all_species[current_species_name] if(check_whitelist && config.usealienwhitelist && !check_rights(R_ADMIN, 0, src)) //If we're using the whitelist, make sure to check it! if(whitelist.len && !(current_species_name in whitelist)) diff --git a/code/modules/mob/new_player/new_player.dm b/code/modules/mob/new_player/new_player.dm index d8bfb77e725..a2586dd65a1 100644 --- a/code/modules/mob/new_player/new_player.dm +++ b/code/modules/mob/new_player/new_player.dm @@ -549,7 +549,7 @@ /mob/new_player/proc/check_prefs_are_sane() var/datum/species/chosen_species if(client.prefs.species) - chosen_species = all_species[client.prefs.species] + chosen_species = GLOB.all_species[client.prefs.species] if(!(chosen_species && (is_species_whitelisted(chosen_species) || has_admin_rights()))) // Have to recheck admin due to no usr at roundstart. Latejoins are fine though. log_runtime(EXCEPTION("[src] had species [client.prefs.species], though they weren't supposed to. Setting to Human."), src) diff --git a/code/modules/mob/new_player/preferences_setup.dm b/code/modules/mob/new_player/preferences_setup.dm index 511816124f7..fc97658896f 100644 --- a/code/modules/mob/new_player/preferences_setup.dm +++ b/code/modules/mob/new_player/preferences_setup.dm @@ -1,10 +1,10 @@ /datum/preferences //The mob should have a gender you want before running this proc. Will run fine without H /datum/preferences/proc/random_character(gender_override) - var/datum/species/S = all_species[species] + var/datum/species/S = GLOB.all_species[species] if(!istype(S)) //The species was invalid. Set the species to the default, fetch the datum for that species and generate a random character. species = initial(species) - S = all_species[species] + S = GLOB.all_species[species] var/datum/robolimb/robohead if(S.bodyflags & ALL_RPARTS) @@ -216,7 +216,7 @@ if(gender == FEMALE) g = "f" var/icon/icobase - var/datum/species/current_species = all_species[species] + var/datum/species/current_species = GLOB.all_species[species] //Icon-based species colour. var/coloured_tail diff --git a/code/modules/nano/modules/human_appearance.dm b/code/modules/nano/modules/human_appearance.dm index 880553a63bc..07810eb92a0 100644 --- a/code/modules/nano/modules/human_appearance.dm +++ b/code/modules/nano/modules/human_appearance.dm @@ -31,8 +31,8 @@ if(href_list["race"]) if(can_change(APPEARANCE_RACE) && (href_list["race"] in valid_species)) - var/datum/species/S = all_species[href_list["race"]] - if(owner.change_species(S.type)) + var/datum/species/S = GLOB.all_species[href_list["race"]] + if(owner.set_species(S.type)) cut_and_generate_data() // Species change creates new organs - runtimes ahoy if we forget this head_organ = owner.get_organ("head")