Fix runtime qdeleted organs (#18013)

* Atomization

* sd

---------

Co-authored-by: FluffyGhost <FluffyGhost>
This commit is contained in:
Fluffy
2023-12-24 23:42:46 +00:00
committed by GitHub
co-authored by FluffyGhost <FluffyGhost>
parent 96f44634e6
commit d2179ffb2b
2 changed files with 85 additions and 18 deletions
@@ -31,15 +31,17 @@
/mob/living/carbon/human/adjustBrainLoss(var/amount)
if(status_flags & GODMODE)
return 0 //godmode
if(should_have_organ(BP_BRAIN))
if(should_have_organ(BP_BRAIN) && internal_organs_by_name)
var/obj/item/organ/internal/brain/sponge = internal_organs_by_name[BP_BRAIN]
if(sponge)
sponge.take_internal_damage(amount)
/mob/living/carbon/human/setBrainLoss(var/amount)
/mob/living/carbon/human/setBrainLoss(amount)
if(status_flags & GODMODE)
return 0 //godmode
if(should_have_organ(BP_BRAIN))
if(should_have_organ(BP_BRAIN) && internal_organs_by_name)
var/obj/item/organ/internal/brain/sponge = internal_organs_by_name[BP_BRAIN]
if(sponge)
sponge.damage = min(max(amount, 0),sponge.species.total_health)
@@ -48,8 +50,15 @@
/mob/living/carbon/human/getBrainLoss()
if(status_flags & GODMODE)
return 0 //godmode
if(should_have_organ(BP_BRAIN))
var/obj/item/organ/internal/brain/sponge = internal_organs_by_name[BP_BRAIN]
//Get the brain organ, if it's there
var/obj/item/organ/internal/brain/sponge = null
if(internal_organs_by_name)
sponge = internal_organs_by_name[BP_BRAIN]
if(sponge)
if(sponge.status & ORGAN_DEAD)
return sponge.species.total_health
@@ -148,7 +157,12 @@
if(!need_breathe())
return 0
else
var/obj/item/organ/internal/lungs/breathe_organ = internal_organs_by_name[species.breathing_organ]
//Get the breathe organ, if it's there
var/obj/item/organ/internal/lungs/breathe_organ = null
if(internal_organs_by_name)
breathe_organ = internal_organs_by_name[species.breathing_organ]
if(!breathe_organ)
return maxHealth/2
return breathe_organ.get_oxygen_deprivation()
@@ -163,7 +177,11 @@
if(!need_breathe())
return
var/heal = amount < 0
var/obj/item/organ/internal/lungs/breathe_organ = internal_organs_by_name[species.breathing_organ]
var/obj/item/organ/internal/lungs/breathe_organ = null
if(internal_organs_by_name)
breathe_organ = internal_organs_by_name[species.breathing_organ]
if(breathe_organ)
if(heal)
breathe_organ.remove_oxygen_deprivation(abs(amount))
@@ -198,21 +216,29 @@
var/list/pick_organs = shuffle(internal_organs.Copy())
// Prioritize damaging our filtration organs first.
var/obj/item/organ/internal/kidneys/kidneys = internal_organs_by_name[BP_KIDNEYS]
if(kidneys)
pick_organs -= kidneys
pick_organs.Insert(1, kidneys)
var/obj/item/organ/internal/liver/liver = internal_organs_by_name[BP_LIVER]
if(liver)
pick_organs -= liver
pick_organs.Insert(1, liver)
var/obj/item/organ/internal/kidneys/kidneys = null
if(internal_organs_by_name)
kidneys = internal_organs_by_name[BP_KIDNEYS]
if(kidneys)
pick_organs -= kidneys
pick_organs.Insert(1, kidneys)
var/obj/item/organ/internal/liver/liver = null
if(internal_organs_by_name)
liver = internal_organs_by_name[BP_LIVER]
if(liver)
pick_organs -= liver
pick_organs.Insert(1, liver)
// Move the brain to the very end since damage to it is vastly more dangerous
// (and isn't technically counted as toxloss) than general organ damage.
var/obj/item/organ/internal/brain/brain = internal_organs_by_name[BP_BRAIN]
if(brain)
pick_organs -= brain
pick_organs += brain
var/obj/item/organ/internal/brain/brain = null
if(internal_organs_by_name)
brain = internal_organs_by_name[BP_BRAIN]
if(brain)
pick_organs -= brain
pick_organs += brain
for(var/internal in pick_organs)
var/obj/item/organ/internal/I = internal
@@ -0,0 +1,41 @@
################################
# Example Changelog File
#
# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb.
#
# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.)
# When it is, any changes listed below will disappear.
#
# Valid Prefixes:
# bugfix
# wip (For works in progress)
# tweak
# soundadd
# sounddel
# rscadd (general adding of nice things)
# rscdel (general deleting of nice things)
# imageadd
# imagedel
# maptweak
# spellcheck (typo fixes)
# experiment
# balance
# admin
# backend
# security
# refactor
#################################
# Your name.
author: FluffyGhost
# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again.
delete-after: True
# Any changes you've made. See valid prefix list above.
# INDENT WITH TWO SPACES. NOT TABS. SPACES.
# SCREW THIS UP AND IT WON'T WORK.
# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries.
# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog.
changes:
- bugfix: "Fixed various possible runtimes on qdeleted organs."