Skip to content

Commit

Permalink
Merge pull request #3336 from out-of-phaze/feature/identity-generaliz…
Browse files Browse the repository at this point in the history
…ation

Move identity and name procs up to mob-level
  • Loading branch information
MistakeNot4892 authored Oct 11, 2023
2 parents d64c4f8 + 6e793af commit 8821b02
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 78 deletions.
7 changes: 1 addition & 6 deletions code/game/jobs/access.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
. = id.GetAccess()

/atom/movable/proc/GetIdCard()
RETURN_TYPE(/obj/item/card/id)
var/list/cards = GetIdCards()
return LAZYACCESS(cards, LAZYLEN(cards))

Expand Down Expand Up @@ -210,12 +211,6 @@ var/global/list/priv_region_access
"Emergency Response Team",
"Emergency Response Team Leader")

/proc/FindNameFromID(var/mob/M, var/missing_id_name = "Unknown")
var/obj/item/card/id/C = M.GetIdCard()
if(C)
return C.registered_name
return missing_id_name

/proc/get_all_job_icons() //For all existing HUD icons
return SSjobs.titles_to_datums + list("Prisoner")

Expand Down
2 changes: 1 addition & 1 deletion code/modules/aspects/aspects_prosthetic_limbs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
if(. && apply_to_limb)
var/obj/item/organ/external/E = GET_EXTERNAL_ORGAN(holder, apply_to_limb)
if(!istype(E))
var/list/organ_data = holder.get_bodytype().has_limbs[apply_to_limb]
var/list/organ_data = holder.should_have_limb(apply_to_limb)
var/limb_path = organ_data["path"]
if("path" in organ_data)
E = new limb_path(holder, null, model || get_base_model(holder.get_species_name()))
Expand Down
10 changes: 7 additions & 3 deletions code/modules/clothing/spacesuits/spacesuits.dm
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,21 @@
set category = "Object"
set src in usr

var/mob/living/user = usr
if(!istype(user))
return

if(ispath(camera))
camera = new camera(src)
camera.set_status(0)

if(camera)
camera.set_status(!camera.status)
if(camera.status)
camera.c_tag = FindNameFromID(usr)
to_chat(usr, "<span class='notice'>User scanned as [camera.c_tag]. Camera activated.</span>")
camera.c_tag = user.get_id_name()
to_chat(user, "<span class='notice'>User scanned as [camera.c_tag]. Camera activated.</span>")
else
to_chat(usr, "<span class='notice'>Camera deactivated.</span>")
to_chat(user, "<span class='notice'>Camera deactivated.</span>")

/obj/item/clothing/head/helmet/space/examine(mob/user, distance)
. = ..()
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mechs/mech.dm
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
/mob/living/exosuit/return_air()
return (body && body.pilot_coverage >= 100 && hatch_closed && body.cockpit) ? body.cockpit : loc.return_air()

/mob/living/exosuit/GetIdCards()
/mob/living/exosuit/GetIdCards(exceptions = null)
. = ..()
if(istype(access_card))
LAZYDISTINCTADD(., access_card)
Expand Down
5 changes: 3 additions & 2 deletions code/modules/mob/examine.dm
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@
show_other_examine_strings(user, distance, infix, suffix, hideflags, pronouns)
to_chat(user, "</quote>")

/mob/living/examine(mob/user, distance, infix, suffix)
. = ..()
// Update our target dolly.
if(user.zone_sel)
var/decl/bodytype/target_bodytype = get_bodytype()
if(target_bodytype && (BP_TAIL in target_bodytype.has_limbs))
if(should_have_limb(BP_TAIL))
user.zone_sel.icon_state = "zone_sel_tail"
else
user.zone_sel.icon_state = "zone_sel"
2 changes: 1 addition & 1 deletion code/modules/mob/living/bot/bot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@
else return !D.check_access(ID) // it's a real, air blocking door
return 0

/mob/living/bot/GetIdCards()
/mob/living/bot/GetIdCards(exceptions = null)
. = ..()
if(istype(botcard))
LAZYDISTINCTADD(., botcard)
62 changes: 5 additions & 57 deletions code/modules/mob/living/carbon/human/human.dm
Original file line number Diff line number Diff line change
Expand Up @@ -136,59 +136,11 @@
LAZYADD(., "<BR><a href='?src=\ref[src];item=\ref[UW]'>Remove \the [UW]</a>")


// Get rank from ID, ID inside PDA, PDA, ID in wallet, etc.
/mob/living/carbon/human/proc/get_authentification_rank(var/if_no_id = "No id", var/if_no_job = "No job")
var/obj/item/card/id/id = GetIdCard()
if(istype(id))
return id.rank ? id.rank : if_no_job
else
return if_no_id

//gets assignment from ID or ID inside PDA or PDA itself
//Useful when player do something with computers
/mob/living/carbon/human/proc/get_assignment(var/if_no_id = "No id", var/if_no_job = "No job")
var/obj/item/card/id/id = GetIdCard()
if(istype(id))
return id.assignment ? id.assignment : if_no_job
else
return if_no_id

//gets name from ID or ID inside PDA or PDA itself
//Useful when player do something with computers
/mob/living/carbon/human/proc/get_authentification_name(var/if_no_id = "Unknown")
var/obj/item/card/id/id = GetIdCard()
if(istype(id))
return id.registered_name
else
return if_no_id

//repurposed proc. Now it combines get_id_name() and get_face_name() to determine a mob's name variable. Made into a seperate proc as it'll be useful elsewhere
/mob/living/carbon/human/proc/get_visible_name()
var/face_name = get_face_name()
var/id_name = get_id_name("")
if((face_name == "Unknown") && id_name && (id_name != face_name))
return "[face_name] (as [id_name])"
return face_name

//Returns "Unknown" if facially disfigured and real_name if not. Useful for setting name when polyacided or when updating a human's name variable
//Also used in AI tracking people by face, so added in checks for head coverings like masks and helmets
/mob/living/carbon/human/proc/get_face_name()
var/obj/item/organ/external/H = GET_EXTERNAL_ORGAN(src, BP_HEAD)
var/obj/item/clothing/mask/mask = get_equipped_item(slot_wear_mask_str)
var/obj/item/head = get_equipped_item(slot_head_str)
if(!H || (H.status & ORGAN_DISFIGURED) || !real_name || is_husked() || (mask && (mask.flags_inv&HIDEFACE)) || (head && (head.flags_inv&HIDEFACE))) //Face is unrecognizeable, use ID if able
if(istype(mask) && mask.visible_name)
return mask.visible_name
return get_rig()?.visible_name || "Unknown"
return real_name

//gets name from ID or PDA itself, ID inside PDA doesn't matter
//Useful when player is being seen by other mobs
/mob/living/carbon/human/proc/get_id_name(var/if_no_id = "Unknown")
. = if_no_id
var/obj/item/card/id/I = GetIdCard(exceptions = list(/obj/item/holder))
if(istype(I))
return I.registered_name
// TODO: remove when is_husked is moved to a parent type (or if husking is removed)
/mob/living/carbon/human/identity_is_visible()
if(is_husked())
return FALSE
return ..()

/mob/living/carbon/human/OnSelfTopic(href_list)
if (href_list["lookitem"])
Expand Down Expand Up @@ -893,10 +845,6 @@
if(stomach)
victim.forceMove(stomach)

/mob/living/carbon/human/should_have_organ(var/organ_check)
var/decl/bodytype/root_bodytype = get_bodytype()
return root_bodytype?.has_organ[organ_check]

/mob/living/carbon/human/get_adjusted_metabolism(metabolism)
return ..() * (species ? species.metabolism_mod : 1)

Expand Down
74 changes: 72 additions & 2 deletions code/modules/mob/living/living.dm
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,15 @@ default behaviour is:
/mob/living/proc/get_ingested_reagents()
return reagents

/mob/living/proc/should_have_organ(var/organ_check)
return FALSE
/mob/living/proc/should_have_organ(organ_to_check)
var/decl/bodytype/root_bodytype = get_bodytype()
return root_bodytype?.has_organ[organ_to_check]

/// Returns null if the mob's bodytype doesn't have a limb tag by default.
/// Otherwise, returns the data of the limb instead.
/mob/living/proc/should_have_limb(limb_to_check)
var/decl/bodytype/root_bodytype = get_bodytype()
return root_bodytype?.has_limbs[limb_to_check]

/mob/living/proc/get_contact_reagents()
return reagents
Expand Down Expand Up @@ -1228,3 +1235,66 @@ default behaviour is:
var/decl/bodytype/bodytype = get_bodytype()
return ..() + bodytype?.antaghud_offset_y

// Get rank from ID, ID inside PDA, PDA, ID in wallet, etc.
/mob/living/proc/get_authentification_rank(if_no_id = "No id", if_no_job = "No job")
var/obj/item/card/id/id = GetIdCard()
if(istype(id))
return id.rank ? id.rank : if_no_job
return if_no_id

//gets assignment from ID or ID inside PDA or PDA itself
//Useful when player do something with computers
/mob/living/proc/get_assignment(if_no_id = "No id", if_no_job = "No job")
var/obj/item/card/id/id = GetIdCard()
if(istype(id))
return id.assignment ? id.assignment : if_no_job
return if_no_id

//gets name from ID or ID inside PDA or PDA itself
//Useful when players do something with computers
/mob/living/proc/get_authentification_name(if_no_id = "Unknown")
var/obj/item/card/id/id = GetIdCard()
if(istype(id))
return id.registered_name
return if_no_id

//repurposed proc. Now it combines get_id_name() and get_face_name() to determine a mob's name variable. Made into a seperate proc as it'll be useful elsewhere
/mob/living/proc/get_visible_name()
var/face_name = get_face_name()
var/id_name = get_id_name("")
if((face_name == "Unknown") && id_name && (id_name != face_name))
return "[face_name] (as [id_name])"
return face_name

//Returns "Unknown" if facially disfigured and real_name if not. Useful for setting name when polyacided or when updating a human's name variable
//Also used in AI tracking people by face, so added in checks for head coverings like masks and helmets
/mob/living/proc/get_face_name()
if(identity_is_visible())
return real_name
var/obj/item/clothing/mask = get_equipped_item(slot_wear_mask_str)
var/obj/item/clothing/head = get_equipped_item(slot_head_str)
if(istype(head) && head.visible_name)
return head.visible_name
else if(istype(mask) && mask.visible_name)
return mask.visible_name
else if(get_rig()?.visible_name)
return get_rig()?.visible_name
return "Unknown"

/mob/living/proc/identity_is_visible()
if(!real_name)
return FALSE
var/obj/item/clothing/mask/mask = get_equipped_item(slot_wear_mask_str)
var/obj/item/head = get_equipped_item(slot_head_str)
if((mask?.flags_inv & HIDEFACE) || (head?.flags_inv & HIDEFACE))
return FALSE
if(should_have_limb(BP_HEAD))
var/obj/item/organ/external/skull = GET_EXTERNAL_ORGAN(src, BP_HEAD)
if(!skull || (skull.status & ORGAN_DISFIGURED)) //Face is unrecognizeable
return FALSE
return TRUE

//gets name from ID or PDA itself, ID inside PDA doesn't matter
//Useful when player is being seen by other mobs
/mob/living/proc/get_id_name(if_no_id = "Unknown")
return GetIdCard(exceptions = list(/obj/item/holder))?.registered_name || if_no_id
2 changes: 1 addition & 1 deletion code/modules/mob/living/simple_animal/crow/crow.dm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
messenger_bag = new(src)
update_icon()

/mob/living/simple_animal/crow/GetIdCards()
/mob/living/simple_animal/crow/GetIdCards(exceptions = null)
. = ..()
if (istype(access_card))
LAZYDISTINCTADD(., access_card)
Expand Down
1 change: 1 addition & 0 deletions code/modules/mob/mob.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,7 @@

// Gets the ID card of a mob, but will not check types in the exceptions list
/mob/GetIdCard(exceptions = null)
RETURN_TYPE(/obj/item/card/id)
return LAZYACCESS(GetIdCards(exceptions), 1)

/mob/get_overhead_text_x_offset()
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/observer/ghost/ghost.dm
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ This is the proc mobs get to turn into a ghost. Forked from ghostize due to comp
M.key = key
log_and_message_admins("has respawned.", M)

/mob/observer/ghost/GetIdCards()
/mob/observer/ghost/GetIdCards(exceptions = null)
. = ..()
if (!is_admin(src))
return .
Expand Down
2 changes: 1 addition & 1 deletion code/modules/surgery/limb_reattach.dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
var/obj/item/organ/external/affected = GET_EXTERNAL_ORGAN(target, target_zone)
if(affected)
return affected
var/list/organ_data = target.get_bodytype()?.has_limbs?["[target_zone]"]
var/list/organ_data = target.should_have_limb(target_zone)
return !isnull(organ_data)

//////////////////////////////////////////////////////////////////
Expand Down
3 changes: 1 addition & 2 deletions code/modules/surgery/organs_internal.dm
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@
CRASH("Target ([target]) of surgery [type] has no bodytype!")
else
var/decl/pronouns/G = O.get_pronouns()
var/decl/bodytype/root_bodytype = target.get_bodytype()
if(O.organ_tag == BP_POSIBRAIN && !root_bodytype.has_organ[BP_POSIBRAIN])
if(O.organ_tag == BP_POSIBRAIN && !target.should_have_organ(BP_POSIBRAIN))
to_chat(user, SPAN_WARNING("There's no place in [target] to fit \the [O.organ_tag]."))
else if(O.damage > (O.max_damage * 0.75))
to_chat(user, SPAN_WARNING("\The [O.name] [G.is] in no state to be transplanted."))
Expand Down

0 comments on commit 8821b02

Please sign in to comment.