ID cards now store a weakref to their mob instead of a hard ref. (#13271)

This commit is contained in:
mikomyazaki
2022-02-25 17:33:16 +00:00
committed by GitHub
parent a68d38b970
commit db7eb023bb
4 changed files with 33 additions and 27 deletions

View File

@@ -496,8 +496,9 @@
if( "change_criminal" )
var/obj/item/card/id/C = usr.get_active_hand()
if( istype( C ))
if( incident && C.mob )
incident.criminal = C.mob
var/mob/living/carbon/human/M = C.mob_id.resolve()
if( incident && M )
incident.criminal = WEAKREF(M)
incident.card = WEAKREF(C)
ping( "\The [src] pings, \"Convict [C] verified.\"" )
else if( incident.criminal )
@@ -539,10 +540,11 @@
var/title = href_list["title"]
var/obj/item/card/id/C = usr.get_active_hand()
if( istype( C ))
if( incident && C.mob )
var/mob/living/carbon/human/M = C.mob_id.resolve()
if( incident && M )
var/error = incident.addArbiter( C, title )
if( !error )
ping( "\The [src] pings, \"[title] [C.mob] verified.\"" )
ping( "\The [src] pings, \"[title] [M] verified.\"" )
else
to_chat(usr, "<span class='alert'>\The [src] buzzes, \"[error]\"</span>")
else

View File

@@ -145,7 +145,8 @@
broadcast_security_hud_message("The timer for [id] has expired.", src)
if(istype(incident))
var/datum/record/general/R = SSrecords.find_record("name", incident.criminal.name)
var/mob/living/carbon/human/C = incident.criminal.resolve()
var/datum/record/general/R = SSrecords.find_record("name", C.name)
if(istype(R) && istype(R.security))
if(early == 1)
R.security.criminal = "Parolled"
@@ -346,7 +347,8 @@
if( "activate" )
src.timer_start()
var/datum/record/general/R = SSrecords.find_record("name", incident.criminal.name)
var/mob/living/carbon/human/C = incident.criminal.resolve()
var/datum/record/general/R = SSrecords.find_record("name", C.name)
if(R && R.security)
R.security.criminal = "Incarcerated"

View File

@@ -95,7 +95,7 @@ var/const/NO_EMAG_ACT = -50
var/list/access = list()
var/registered_name = "Unknown" // The name registered_name on the card
var/mob/living/carbon/human/mob
var/datum/weakref/mob_id
slot_flags = SLOT_ID
var/age = "\[UNSET\]"
@@ -125,7 +125,6 @@ var/const/NO_EMAG_ACT = -50
var/iff_faction = IFF_DEFAULT
/obj/item/card/id/Destroy()
mob = null
return ..()
/obj/item/card/id/examine(mob/user)
@@ -173,7 +172,7 @@ var/const/NO_EMAG_ACT = -50
id_card.age = age
id_card.citizenship = citizenship
id_card.religion = SSrecords.get_religion_record_name(religion)
id_card.mob = src
id_card.mob_id = WEAKREF(src)
id_card.employer_faction = employer_faction
/obj/item/card/id/proc/dat()
@@ -203,7 +202,7 @@ var/const/NO_EMAG_ACT = -50
to_chat(user, "<span class='warning'>You cannot imprint [src] while wearing \the [H.gloves].</span>")
return
else
mob = H
mob_id = WEAKREF(H)
blood_type = H.dna.b_type
dna_hash = H.dna.unique_enzymes
fingerprint_hash = md5(H.dna.uni_identity)
@@ -266,7 +265,7 @@ var/const/NO_EMAG_ACT = -50
to_chat(user, "<span class='warning'>They don't have any hands.</span>")
return 1
user.visible_message("[user] imprints [src] with \the [H]'s biometrics.")
mob = H
mob_id = WEAKREF(H)
blood_type = H.dna.b_type
dna_hash = H.dna.unique_enzymes
fingerprint_hash = md5(H.dna.uni_identity)

View File

@@ -7,7 +7,7 @@
var/list/evidence = list() // If its a prison sentence, it'll require evidence
var/list/arbiters = list( "Witness" = list() ) // The person or list of people who were involved in the conviction of the criminal
var/mob/living/carbon/human/criminal // The person who committed the crimes
var/datum/weakref/criminal // The person who committed the crimes
var/datum/weakref/card // The ID of the criminal
var/datetime = "" //When the crime has been commited
@@ -29,20 +29,17 @@
/datum/crime_incident/proc/addArbiter( var/obj/item/card/id/C, var/title )
if( !istype( C ))
return "Invalid ID card!"
if( !C.mob )
var/mob/living/carbon/human/M = C.mob_id.resolve()
if( !M )
return "ID card not tied to a NanoTrasen Employee!"
// if( criminal == C.mob ) //Uncommented because you should be able to give a statement in your case
// return "The criminal cannot hold official court positions in his own trial!"
var/list/same_access // The card requires one of these access codes to become this title
var/minSeverity = 1
switch( title )
if( "Witness" ) // anyone can be a witness
var/list/L = arbiters[title]
L += list( C.mob ) // some reason adding a mob counts as adding a list, so it would add the mob contents
L += list( M ) // some reason adding a mob counts as adding a list, so it would add the mob contents
arbiters[title] = L
return 0
@@ -50,13 +47,14 @@
return "The severity of the incident does not call for a [title]."
if( same_access && same_access.len )
arbiters[title] = C.mob
arbiters[title] = M
return 0
else
return "Could not add [C.mob] as [title]."
return "Could not add [M] as [title]."
/datum/crime_incident/proc/missingSentenceReq()
if( !istype( criminal ))
var/mob/living/carbon/human/C = criminal.resolve()
if( !istype( C ))
return "No criminal selected!"
if( !charges.len )
@@ -136,7 +134,8 @@
//type: 0 - brig sentence, 1 - fine, 2 - prison sentence
/datum/crime_incident/proc/renderGuilty( var/mob/living/user, var/type=0 )
if( !criminal )
var/mob/living/carbon/human/C = criminal.resolve()
if( !C )
return
created_by = "[user.ckey] - [user.real_name]"
@@ -155,12 +154,15 @@
return generateReport()
/datum/crime_incident/proc/generateReport()
var/mob/living/carbon/human/C = criminal.resolve()
if( !C )
return
. = "<center>Security Incident Report</center><hr>"
. += "<br>"
. += "<b>CRIMINAL</b>: <i>[criminal]</i><br><br>"
. += "<b>CRIMINAL</b>: <i>[C]</i><br><br>"
. += "[criminal] was found guilty of the following crimes on [game_year]-[time2text(world.realtime, "MMM-DD")].<br>"
. += "[C] was found guilty of the following crimes on [game_year]-[time2text(world.realtime, "MMM-DD")].<br>"
if( brig_sentence != 0 )
. += "As decided by the arbiter(s), they will serve the following sentence:<br>"
@@ -186,8 +188,9 @@
return .
/datum/crime_incident/proc/saveCharInfraction()
var/mob/living/carbon/human/C = criminal.resolve()
var/datum/record/char_infraction/cinf = new()
cinf.char_id = criminal.character_id
cinf.char_id = C.character_id
cinf.id = UID
cinf.notes = notes
cinf.charges = json_decode(json_encode(charges)) //Thats there to strip all the non-needed values from the data before saving it to the db
@@ -200,9 +203,9 @@
cinf.felony = felony
cinf.created_by = created_by
// Check if player is a antag
if(isnull(criminal.mind.special_role))
if(isnull(C.mind.special_role))
cinf.saveToDB()
var/datum/record/general/R = SSrecords.find_record("name", criminal.name)
var/datum/record/general/R = SSrecords.find_record("name", C.name)
if(istype(R) && istype(R.security))
R.security.incidents += cinf