Skip to content

Commit

Permalink
Porting some species infrastructure from Neb.
Browse files Browse the repository at this point in the history
  • Loading branch information
MistakeNot4892 committed Jul 19, 2023
1 parent d059070 commit fcf5154
Show file tree
Hide file tree
Showing 38 changed files with 215 additions and 299 deletions.
3 changes: 0 additions & 3 deletions code/_global_vars/lists/species.dm
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//Languages/species/whitelist.
GLOBAL_LIST_EMPTY_TYPED(all_species, /datum/species)
GLOBAL_LIST_EMPTY_TYPED(all_languages, /datum/language)
GLOBAL_LIST_INIT(language_name_conflicts, list())
GLOBAL_LIST_INIT(language_keys, list()) // Table of say codes for all languages
GLOBAL_LIST_INIT(language_key_conflicts, list())
GLOBAL_LIST_INIT(whitelisted_species, list(SPECIES_HUMAN)) // Species that require a whitelist check.
GLOBAL_LIST_INIT(playable_species, list(SPECIES_HUMAN)) // A list of ALL playable species, whitelisted, latejoin or otherwise.
94 changes: 42 additions & 52 deletions code/_helpers/global_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -188,26 +188,6 @@ var/global/list/string_slot_flags = list(
GLOB.language_key_conflicts[L.key] = list(GLOB.language_keys[L.key])
GLOB.language_key_conflicts[L.key] += L

//Species
var/rkey = 0
paths = typesof(/datum/species)
for(var/T in paths)

rkey++

var/datum/species/S = T
if(!initial(S.name))
continue

S = new T
S.race_key = rkey //Used in mob icon caching.
GLOB.all_species[S.name] = S

if(!(S.spawn_flags & SPECIES_IS_RESTRICTED))
GLOB.playable_species += S.name
if(S.spawn_flags & SPECIES_IS_WHITELISTED)
GLOB.whitelisted_species += S.name

//Ores
paths = subtypesof(/ore)
for(var/oretype in paths)
Expand Down Expand Up @@ -237,38 +217,6 @@ var/global/list/string_slot_flags = list(

init_crafting_recipes(GLOB.crafting_recipes)

/*
// Custom species traits
paths = typesof(/datum/trait) - /datum/trait
for(var/path in paths)
var/datum/trait/instance = new path()
if(!instance.name)
continue //A prototype or something
var/cost = instance.cost
traits_costs[path] = cost
all_traits[path] = instance
switch(cost)
if(-INFINITY to -0.1)
negative_traits[path] = instance
if(0)
neutral_traits[path] = instance
if(0.1 to INFINITY)
positive_traits[path] = instance
*/

// Custom species icon bases
var/list/blacklisted_icons = list(/*SPECIES_CUSTOM,*/SPECIES_PROMETHEAN) //Just ones that won't work well.
var/list/whitelisted_icons = list(/*SPECIES_FENNEC,SPECIES_XENOHYBRID*/) //Include these anyway
for(var/species_name in GLOB.playable_species)
if(species_name in blacklisted_icons)
continue
var/datum/species/S = GLOB.all_species[species_name]
if(S.spawn_flags & SPECIES_IS_WHITELISTED)
continue
GLOB.custom_species_bases += species_name
for(var/species_name in whitelisted_icons)
GLOB.custom_species_bases += species_name

return 1 // Hooks must return 1


Expand All @@ -292,3 +240,45 @@ var/global/list/string_slot_flags = list(
*/
//Hexidecimal numbers
var/global/list/hexNums = list("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F")

// This is all placeholder procs for an eventual PR to change them to use decls.
var/global/list/all_species
var/global/list/playable_species // A list of ALL playable species, whitelisted, latejoin or otherwise.
/proc/build_species_lists()
if(global.all_species)
return
global.all_species = list()
global.playable_species = list()
for(var/species_type in subtypesof(/datum/species))
var/datum/species/species = species_type
if(!initial(species.name))
continue
species = new species
global.all_species[species.name] = species
if(!(species.spawn_flags & SPECIES_IS_RESTRICTED))
global.playable_species += species.name
global.playable_species |= SPECIES_HUMAN

/proc/get_species_by_key(var/species_key)
build_species_lists()
. = global.all_species[species_key]
/proc/get_all_species()
build_species_lists()
. = global.all_species
/proc/get_playable_species()
build_species_lists()
. = global.playable_species
/proc/get_custom_species_icon_bases()
// Custom species icon bases
build_species_lists()
var/list/blacklisted_icons = list(/*SPECIES_CUSTOM,*/SPECIES_PROMETHEAN) //Just ones that won't work well.
var/list/whitelisted_icons = list(/*SPECIES_FENNEC,SPECIES_XENOHYBRID*/) //Include these anyway
for(var/species_name in global.playable_species)
if(species_name in blacklisted_icons)
continue
var/datum/species/S = global.all_species[species_name]
if(S.spawn_flags & SPECIES_IS_WHITELISTED)
continue
GLOB.custom_species_bases += species_name
for(var/species_name in whitelisted_icons)
GLOB.custom_species_bases += species_name
4 changes: 2 additions & 2 deletions code/_helpers/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
/proc/sanitize_name(name, species = SPECIES_HUMAN, robot = 0)
var/datum/species/current_species
if(species)
current_species = GLOB.all_species[species]
current_species = get_species_by_key(species)

return current_species ? current_species.sanitize_name(name, robot) : sanitizeName(name, MAX_NAME_LEN, robot)

/proc/random_name(gender, species = SPECIES_HUMAN)

var/datum/species/current_species
if(species)
current_species = GLOB.all_species[species]
current_species = get_species_by_key(species)

if(!current_species || current_species.name_language == null)
if(gender==FEMALE)
Expand Down
16 changes: 10 additions & 6 deletions code/datums/datacore.dm
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,16 @@ var/global/list/PDA_Manifest = list()
G.fields["m_stat"] = "Stable"
G.fields["sex"] = gender2text(H.gender)
G.fields["species"] = H.get_species_name()
/*
G.fields["home_system"] = H.home_system
G.fields["citizenship"] = H.citizenship
G.fields["faction"] = H.personal_faction
G.fields["religion"] = H.religion
*/

var/decl/cultural_info/culture = GET_DECL(H.client.prefs.cultural_info[TAG_HOMEWORLD])
G.fields["home_system"] = culture.name
culture = GET_DECL(H.client.prefs.cultural_info[TAG_CULTURE])
G.fields["citizenship"] = culture.name
culture = GET_DECL(H.client.prefs.cultural_info[TAG_FACTION])
G.fields["faction"] = culture.name
culture = GET_DECL(H.client.prefs.cultural_info[TAG_RELIGION])
G.fields["religion"] = culture.name

if(H.gen_record && !jobban_isbanned(H, "Records"))
G.fields["notes"] = H.gen_record

Expand Down
4 changes: 2 additions & 2 deletions code/game/gamemodes/technomancer/spells/aura/fire_aura.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
var/list/nearby_things = range(round(calculate_spell_power(4)),owner)

var/temp_change = calculate_spell_power(25)
var/datum/species/baseline = GLOB.all_species["Human"]
var/datum/species/baseline = get_species_by_key(SPECIES_HUMAN)
var/temp_cap = baseline.heat_level_3 * 1.5
var/fire_power = calculate_spell_power(2)

Expand Down Expand Up @@ -51,4 +51,4 @@
T.hotspot_expose(500, 50, 1)
T.create_fire(fire_power)

adjust_instability(3)
adjust_instability(3)
4 changes: 2 additions & 2 deletions code/game/gamemodes/technomancer/spells/aura/frost_aura.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
var/list/nearby_mobs = range(round(calculate_spell_power(4)),owner)

var/temp_change = calculate_spell_power(40)
var/datum/species/baseline = GLOB.all_species["Human"]
var/datum/species/baseline = get_species_by_key(SPECIES_HUMAN)
var/temp_cap = baseline.cold_level_2 - 5

if(check_for_scepter())
Expand All @@ -40,4 +40,4 @@
temp_change *= cold_factor
H.bodytemperature = max(H.bodytemperature - temp_change, temp_cap)

adjust_instability(1)
adjust_instability(1)
2 changes: 1 addition & 1 deletion code/game/jobs/job_controller.dm
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ var/global/datum/controller/occupations/job_master
permitted = TRUE

// Check if they're whitelisted for this gear (in alien whitelist? seriously?)
if(permitted && G.whitelisted && !is_alien_whitelisted(H, GLOB.all_species[G.whitelisted]))
if(permitted && G.whitelisted && !is_alien_whitelisted(H, get_species_by_key(G.whitelisted)))
permitted = FALSE

if(permitted && length(G.available_to_backgrounds))
Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/bioprinter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@
malfunctioned = TRUE
var/possible_species = list(SPECIES_HUMAN, SPECIES_VOX, SPECIES_SKRELL, SPECIES_ZADDAT, SPECIES_UNATHI, SPECIES_GOLEM, SPECIES_SHADOW)
var/new_species = pick(possible_species)
if (!GLOB.all_species[new_species])
if (!get_species_by_key(new_species))
new_species = SPECIES_HUMAN
O.species = GLOB.all_species[new_species]
O.species = get_species_by_key(new_species)

if (istype(O, /obj/item/organ/external) && !malfunctioned)
var/obj/item/organ/external/E = O
Expand Down
2 changes: 1 addition & 1 deletion code/game/mecha/mech_prosthetics.dm
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@

if(istype(I,/obj/item/disk/species))
var/obj/item/disk/species/D = I
if(!D.species || !(D.species in GLOB.all_species))
if(!D.species || !(D.species in get_all_species()))
to_chat(user, "<span class='warning'>This disk seems to be corrupted!</span>")
else
to_chat(user, "<span class='notice'>Uploading modification files for [D.species]...</span>")
Expand Down
4 changes: 2 additions & 2 deletions code/modules/admin/secrets/fun_secrets/paintball_mode.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
if(!.)
return

for(var/species in GLOB.all_species)
var/datum/species/S = GLOB.all_species[species]
for(var/species in get_all_species())
var/datum/species/S = get_species_by_key(species)
S.blood_color = "rainbow"
for(var/obj/effect/decal/cleanable/blood/B in world)
B.basecolor = "rainbow"
Expand Down
3 changes: 1 addition & 2 deletions code/modules/admin/view_variables/topic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
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 GLOB.all_species
var/new_species = input("Please choose a new species.","Species",null) as null|anything in get_all_species()

if(!H)
to_chat(usr, "Mob doesn't exist anymore")
Expand Down Expand Up @@ -523,4 +523,3 @@
var/datum/DAT = locate(href_list["datumrefresh"])
if(istype(DAT, /datum) || istype(DAT, /client) || islist(DAT))
debug_variables(DAT)

2 changes: 1 addition & 1 deletion code/modules/antagonist/station/changeling.dm
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
return 1
else if(isnewplayer(player.current))
if(player.current.client && player.current.client.prefs)
var/datum/species/S = GLOB.all_species[player.current.client.prefs.species]
var/datum/species/S = get_species_by_key(player.current.client.prefs.species)
if(S && (S.flags & NO_SCAN))
return 0
if(player.current.client.prefs.organ_data["torso"] == "cyborg") // Full synthetic.
Expand Down
2 changes: 1 addition & 1 deletion code/modules/blob2/overmind/types/cryogenic_goo.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
var/protection = H.get_cold_protection(50)
if(protection < 1)
var/temp_change = 80 // Each hit can reduce temperature by up to 80 kelvin.
var/datum/species/baseline = GLOB.all_species["Human"]
var/datum/species/baseline = get_species_by_key(SPECIES_HUMAN)
var/temp_cap = baseline.cold_level_3 - 5 // Can't go lower than this.

var/cold_factor = abs(protection - 1)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/client/preference_setup/general/01_basic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@
/datum/category_item/player_setup_item/general/basic/proc/get_genders()
var/datum/species/S
if(pref.species)
S = GLOB.all_species[pref.species]
S = get_species_by_key(pref.species)
else
S = GLOB.all_species[SPECIES_HUMAN]
S = get_species_by_key(SPECIES_HUMAN)
var/list/possible_genders = S.genders
if(!pref.organ_data || pref.organ_data[BP_TORSO] != "cyborg")
return possible_genders
Expand Down
6 changes: 3 additions & 3 deletions code/modules/client/preference_setup/general/02_language.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/datum/category_item/player_setup_item/general/language/sanitize_character()
if(!islist(pref.alternate_languages)) pref.alternate_languages = list()
if(pref.species)
var/datum/species/S = GLOB.all_species[pref.species]
var/datum/species/S = get_species_by_key(pref.species)
if(!istype(S))
return

Expand All @@ -31,7 +31,7 @@

/datum/category_item/player_setup_item/general/language/content()
. += "<b>Languages</b><br>"
var/datum/species/S = GLOB.all_species[pref.species]
var/datum/species/S = get_species_by_key(pref.species)
if(S.language)
. += "- [S.language]<br>"
if(S.default_language && S.default_language != S.language)
Expand All @@ -56,7 +56,7 @@
pref.alternate_languages.Cut(index, index+1)
return TOPIC_REFRESH
else if(href_list["add_language"])
var/datum/species/S = GLOB.all_species[pref.species]
var/datum/species/S = get_species_by_key(pref.species)
if(pref.alternate_languages.len >= S.num_alternate_languages)
alert(user, "You have already selected the maximum number of alternate languages for this species!")
else
Expand Down
24 changes: 12 additions & 12 deletions code/modules/client/preference_setup/general/03_body.dm
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ var/global/list/valid_bloodtypes = list("A+", "A-", "B+", "B-", "AB+", "AB-", "O
S["b_wing3"] << pref.b_wing3

/datum/category_item/player_setup_item/general/body/sanitize_character(var/savefile/S)
if(!pref.species || !(pref.species in GLOB.playable_species))
if(!pref.species || !(pref.species in get_playable_species()))
pref.species = SPECIES_HUMAN
pref.r_hair = sanitize_integer(pref.r_hair, 0, 255, initial(pref.r_hair))
pref.g_hair = sanitize_integer(pref.g_hair, 0, 255, initial(pref.g_hair))
Expand Down Expand Up @@ -416,7 +416,7 @@ var/global/list/valid_bloodtypes = list("A+", "A-", "B+", "B-", "AB+", "AB-", "O
last_descriptors = pref.body_descriptors.Copy()
pref.body_descriptors = list()

var/datum/species/mob_species = GLOB.all_species[pref.species]
var/datum/species/mob_species = get_species_by_key(pref.species)
if(LAZYLEN(mob_species.descriptors))
for(var/entry in mob_species.descriptors)
var/datum/mob_descriptor/descriptor = mob_species.descriptors[entry]
Expand All @@ -429,7 +429,7 @@ var/global/list/valid_bloodtypes = list("A+", "A-", "B+", "B-", "AB+", "AB-", "O
/datum/category_item/player_setup_item/general/body/content(var/mob/user)
. = list()

var/datum/species/mob_species = GLOB.all_species[pref.species]
var/datum/species/mob_species = get_species_by_key(pref.species)
. += "<table><tr style='vertical-align:top'><td><b>Body</b> "
. += "(<a href='?src=\ref[src];random=1'>&reg;</A>)"
. += "<br>"
Expand Down Expand Up @@ -640,7 +640,7 @@ var/global/list/valid_bloodtypes = list("A+", "A-", "B+", "B-", "AB+", "AB-", "O
return mob_species && (mob_species.appearance_flags & flag)

/datum/category_item/player_setup_item/general/body/OnTopic(var/href,var/list/href_list, var/mob/user)
var/datum/species/mob_species = GLOB.all_species[pref.species]
var/datum/species/mob_species = get_species_by_key(pref.species)

if(href_list["random"])
pref.randomize_appearance_and_body_for()
Expand All @@ -664,7 +664,7 @@ var/global/list/valid_bloodtypes = list("A+", "A-", "B+", "B-", "AB+", "AB-", "O

else if(href_list["show_species"])
// Actual whitelist checks are handled elsewhere, this is just for accessing the preview window.
var/choice = input("Which species would you like to look at?") as null|anything in GLOB.playable_species
var/choice = input("Which species would you like to look at?") as null|anything in get_playable_species()
if(!choice) return
pref.species_preview = choice
SetSpecies(preference_mob())
Expand All @@ -673,13 +673,13 @@ var/global/list/valid_bloodtypes = list("A+", "A-", "B+", "B-", "AB+", "AB-", "O

else if(href_list["set_species"])
user << browse(null, "window=species")
if(!pref.species_preview || !(pref.species_preview in GLOB.all_species))
if(!pref.species_preview || !(pref.species_preview in get_all_species()))
return TOPIC_NOACTION

var/datum/species/setting_species

if(GLOB.all_species[href_list["set_species"]])
setting_species = GLOB.all_species[href_list["set_species"]]
if(get_species_by_key(href_list["set_species"]))
setting_species = get_species_by_key(href_list["set_species"])
else
return TOPIC_NOACTION

Expand Down Expand Up @@ -929,7 +929,7 @@ var/global/list/valid_bloodtypes = list("A+", "A-", "B+", "B-", "AB+", "AB-", "O
var/list/limb_selection_list = list("Left Leg","Right Leg","Left Arm","Right Arm","Left Foot","Right Foot","Left Hand","Right Hand","Full Body")

// Full prosthetic bodies without a brain are borderline unkillable so make sure they have a brain to remove/destroy.
var/datum/species/current_species = GLOB.all_species[pref.species]
var/datum/species/current_species = get_species_by_key(pref.species)
if(!current_species.has_organ["brain"])
limb_selection_list -= "Full Body"
else if(pref.organ_data[BP_TORSO] == "cyborg")
Expand Down Expand Up @@ -1075,7 +1075,7 @@ var/global/list/valid_bloodtypes = list("A+", "A-", "B+", "B-", "AB+", "AB-", "O
return
organ = "brain"

var/datum/species/current_species = GLOB.all_species[pref.species]
var/datum/species/current_species = get_species_by_key(pref.species)
var/list/organ_choices = list("Normal")
if(pref.organ_data[BP_TORSO] == "cyborg")
organ_choices -= "Normal"
Expand Down Expand Up @@ -1265,9 +1265,9 @@ var/global/list/valid_bloodtypes = list("A+", "A-", "B+", "B-", "AB+", "AB-", "O
pref.real_name = random_name(pref.identifying_gender, pref.species)

/datum/category_item/player_setup_item/general/body/proc/SetSpecies(mob/user)
if(!pref.species_preview || !(pref.species_preview in GLOB.all_species))
if(!pref.species_preview || !(pref.species_preview in get_all_species()))
pref.species_preview = SPECIES_HUMAN
var/datum/species/current_species = GLOB.all_species[pref.species_preview]
var/datum/species/current_species = get_species_by_key(pref.species_preview)
var/dat = "<body>"
dat += "<center><h2>[current_species.name] \[<a href='?src=\ref[src];show_species=1'>change</a>\]</h2></center><hr/>"
dat += "<table padding='8px'>"
Expand Down
Loading

0 comments on commit fcf5154

Please sign in to comment.