Make blood use weakrefs & fix fixblood (#3384)

This commit is contained in:
Lohikar
2017-09-14 20:32:53 +02:00
committed by Werner
parent ff853542b1
commit 1add9088b2
6 changed files with 59 additions and 30 deletions
+18 -10
View File
@@ -12,7 +12,6 @@ var/const/BLOOD_VOLUME_SURVIVE = 122
//Initializes blood vessels
/mob/living/carbon/human/proc/make_blood()
if(vessel)
return
@@ -23,14 +22,24 @@ var/const/BLOOD_VOLUME_SURVIVE = 122
return
vessel.add_reagent("blood",560)
addtimer(CALLBACK(src, .proc/fixblood), 1)
fixblood()
//Resets blood data
/mob/living/carbon/human/proc/fixblood()
for(var/datum/reagent/blood/B in vessel.reagent_list)
if(B.id == "blood")
B.data = list( "donor"=src,"viruses"=null,"species"=species.name,"blood_DNA"=dna.unique_enzymes,"blood_colour"= species.blood_color,"blood_type"=dna.b_type, \
"resistances"=null,"trace_chem"=null, "virus2" = null, "antibodies" = list())
B.data = list(
"donor" = WEAKREF(src),
"viruses" = null,
"species" = species.name,
"blood_DNA" = dna.unique_enzymes,
"blood_colour" = species.blood_color,
"blood_type" = dna.b_type,
"resistances" = null,
"trace_chem" = null,
"virus2" = null,
"antibodies" = list()
)
B.color = B.data["blood_colour"]
// Takes care blood loss and regeneration
@@ -42,16 +51,15 @@ var/const/BLOOD_VOLUME_SURVIVE = 122
return
if(stat != DEAD && bodytemperature >= 170) //Dead or cryosleep people do not pump the blood.
var/blood_volume = round(vessel.get_reagent_amount("blood"))
//Blood regeneration if there is some space
if(blood_volume < 560 && blood_volume)
var/datum/reagent/blood/B = locate() in vessel.reagent_list //Grab some blood
if(B) // Make sure there's some blood at all
if(B.data["donor"] != src) //If it's not theirs, then we look for theirs
if(weakref && B.data["donor"] != weakref) //If it's not theirs, then we look for theirs - donor is a weakref here, but it should be safe to just directly compare it.
for(var/datum/reagent/blood/D in vessel.reagent_list)
if(D.data["donor"] == src)
if(weakref && D.data["donor"] == weakref)
B = D
break
@@ -164,7 +172,7 @@ var/const/BLOOD_VOLUME_SURVIVE = 122
B.volume += amount
//set reagent data
B.data["donor"] = src
B.data["donor"] = WEAKREF(src)
if (!B.data["virus2"])
B.data["virus2"] = list()
B.data["virus2"] |= virus_copylist(src.virus2)
@@ -242,9 +250,9 @@ var/const/BLOOD_VOLUME_SURVIVE = 122
/mob/living/carbon/proc/get_blood(datum/reagents/container)
var/datum/reagent/blood/res = locate() in container.reagent_list //Grab some blood
if(res) // Make sure there's some blood at all
if(res.data["donor"] != src) //If it's not theirs, then we look for theirs
if(weakref && res.data["donor"] != weakref) //If it's not theirs, then we look for theirs
for(var/datum/reagent/blood/D in container.reagent_list)
if(D.data["donor"] == src)
if(D.data["donor"] == weakref)
return D
return res