[MIRROR] Fixes chem and addiction scans, null checks for addiction_list (#1826)

* Fixes chem and addiction scans, null checks for addiction_list (#55105)

So #54797 changed addiction_list to instantiate as a null instead of a list. Turns out a few things relied on the list existing!
Things like health analyser/medical kiosk chem and addiction scans broke, and smokers would no longer get addicted!
Made a few places check if addiction_list is null before continuing.

(Lemon's note, refactored some code to make it cleaner/removed some unneeded loop typechecks)

* Fixes chem and addiction scans, null checks for addiction_list

Co-authored-by: prodirus <44090982+prodirus@users.noreply.github.com>
This commit is contained in:
SkyratBot
2020-11-25 13:56:15 +01:00
committed by GitHub
co-authored by prodirus
parent 8cddcf1887
commit 384d439381
4 changed files with 23 additions and 19 deletions
+1 -1
View File
@@ -15,7 +15,7 @@
#define LAZYREMOVE(L, I) if(L) { L -= I; if(!length(L)) { L = null; } }
#define LAZYADD(L, I) if(!L) { L = list(); } L += I;
#define LAZYOR(L, I) if(!L) { L = list(); } L |= I;
#define LAZYFIND(L, V) L ? L.Find(V) : 0
#define LAZYFIND(L, V) (L ? L.Find(V) : 0)
#define LAZYACCESS(L, I) (L ? (isnum(I) ? (I > 0 && I <= length(L) ? L[I] : null) : L[I]) : null)
#define LAZYSET(L, K, V) if(!L) { L = list(); } L[K] = V;
#define LAZYLEN(L) length(L)
+2 -2
View File
@@ -579,7 +579,7 @@
if (!reagent_type)
reagent_type = pick(drug_list)
reagent_instance = new reagent_type()
H.reagents.addiction_list.Add(reagent_instance)
LAZYADD(H.reagents.addiction_list, reagent_instance)
var/current_turf = get_turf(quirk_holder)
if (!drug_container_type)
drug_container_type = /obj/item/storage/pill_bottle
@@ -628,7 +628,7 @@
reagent_instance = new reagent_type()
else
reagent_instance.addiction_stage = 0
H.reagents.addiction_list += reagent_instance
LAZYADD(H.reagents.addiction_list, reagent_instance)
to_chat(quirk_holder, "<span class='danger'>You thought you kicked it, but you suddenly feel like you need [reagent_instance.name] again...</span>")
/datum/quirk/junkie/smoker
+13 -11
View File
@@ -213,16 +213,17 @@
var/brain_status = "Brain patterns normal."
if(LAZYLEN(altPatient.get_traumas()))
var/list/trauma_text = list()
for(var/datum/brain_trauma/B in altPatient.get_traumas())
for(var/t in altPatient.get_traumas())
var/datum/brain_trauma/trauma = t
var/trauma_desc = ""
switch(B.resilience)
switch(trauma.resilience)
if(TRAUMA_RESILIENCE_SURGERY)
trauma_desc += "severe "
if(TRAUMA_RESILIENCE_LOBOTOMY)
trauma_desc += "deep-rooted "
if(TRAUMA_RESILIENCE_MAGIC, TRAUMA_RESILIENCE_ABSOLUTE)
trauma_desc += "permanent "
trauma_desc += B.scan_desc
trauma_desc += trauma.scan_desc
trauma_text += trauma_desc
trauma_status = "Cerebral traumas detected: patient appears to be suffering from [english_list(trauma_text)]."
@@ -231,11 +232,12 @@
var/addict_list = list()
var/hallucination_status = "Patient is not hallucinating."
if(altPatient?.reagents?.reagent_list.len) //Chemical Analysis details.
for(var/datum/reagent/R in altPatient.reagents.reagent_list)
chemical_list += list(list("name" = R.name, "volume" = round(R.volume, 0.01)))
if(R.overdosed)
overdose_list += list(list("name" = R.name))
if(altPatient.reagents.reagent_list.len) //Chemical Analysis details.
for(var/r in altPatient.reagents.reagent_list)
var/datum/reagent/reagent = r
chemical_list += list(list("name" = reagent.name, "volume" = round(reagent.volume, 0.01)))
if(reagent.overdosed)
overdose_list += list(list("name" = reagent.name))
var/obj/item/organ/stomach/belly = altPatient.getorganslot(ORGAN_SLOT_STOMACH)
if(belly?.reagents.reagent_list.len) //include the stomach contents if it exists
for(var/bile in belly.reagents.reagent_list)
@@ -246,9 +248,9 @@
var/bit_vol = bit.volume - belly.food_reagents[bit.type]
if(bit_vol > 0)
chemical_list += list(list("name" = bit.name, "volume" = round(bit_vol, 0.01)))
if(altPatient?.reagents?.addiction_list.len)
for(var/datum/reagent/R in altPatient.reagents.addiction_list)
addict_list += list(list("name" = R.name))
for(var/a in altPatient.reagents.addiction_list)
var/datum/reagent/addiction = a
addict_list += list(list("name" = addiction.name))
if (altPatient.hallucinating())
hallucination_status = "Subject appears to be hallucinating. Suggested treatments: bedrest, mannitol or psicodine."
+7 -5
View File
@@ -428,8 +428,9 @@ GENE SCANNER
var/render_list = list()
if(M.reagents.reagent_list.len)
render_list += "<span class='notice ml-1'>Subject contains the following reagents in their blood:</span>\n"
for(var/datum/reagent/R in M.reagents.reagent_list)
render_list += "<span class='notice ml-2'>[round(R.volume, 0.001)] units of [R.name][R.overdosed ? "</span> - <span class='boldannounce'>OVERDOSING</span>" : ".</span>"]\n"
for(var/r in M.reagents.reagent_list)
var/datum/reagent/reagent = r
render_list += "<span class='notice ml-2'>[round(reagent.volume, 0.001)] units of [reagent.name][reagent.overdosed ? "</span> - <span class='boldannounce'>OVERDOSING</span>" : ".</span>"]\n"
else
render_list += "<span class='notice ml-1'>Subject contains no reagents in their blood.</span>\n"
var/obj/item/organ/stomach/belly = M.getorganslot(ORGAN_SLOT_STOMACH)
@@ -447,10 +448,11 @@ GENE SCANNER
else
render_list += "<span class='notice ml-1'>Subject contains no reagents in their stomach.</span>\n"
if(M.reagents.addiction_list.len)
if(LAZYLEN(M.reagents.addiction_list))
render_list += "<span class='boldannounce ml-1'>Subject is addicted to the following reagents:</span>\n"
for(var/datum/reagent/R in M.reagents.addiction_list)
render_list += "<span class='alert ml-2'>[R.name]</span>\n"
for(var/a in M.reagents.addiction_list)
var/datum/reagent/addiction = a
render_list += "<span class='alert ml-2'>[addiction.name]</span>\n"
else
render_list += "<span class='notice ml-1'>Subject is not addicted to any reagents.</span>\n"