Organ damage refactor/cleanup (#93436)

## About The Pull Request
So, my original goal was just a refactor for the emissive overlays of
eyes, as a way to implement the specular emissive introduced by smartkar
some time ago, but somehow I found myself dragged into a bigger refactor
or cleanup of organ damage, thresholds, failures. One of the main
problem was that there were no procs called when a organ suffered enough
damage to fail or when recovering from failure. It'd just enable or
disable a bitflag, leaving it up to subtypes to decide how to tackle
organ failure their own ways: diverse, funky and sometimes incompatible.
More often than not relying on their very own "update_thingamajig" kinda
procs that run whenever the organ takes damage, rather than just when
the threshold is reached (low, high, failure. There are however a couple
organs with their own quirky thresholds, I let those slide).

There's also a bit of old code, especially for ears, with the
`AdjustEarDamage` and temporary deafness both predating the framework
for organ damage as far as I know. It really needed a coat of fresh
paint.

Oh, there were also more than a handful of organs that still heavily
relied on some ORGAN_TRAIT source instead of the `organ_traits` list and
the two add/remove procs `add_organ_trait` or `remove_organ_trait`. This
include organs that lose or gain specific traits when failing et
viceversa.

~~Lastly, felinids (and the halloween ghost species) having reflective
eyes. It's just a nod to the tapetum lucidum that animals with night
vision often have (including cats), which is why their eyes are a bit
brighter in the dark. Felinids however, do not have night vision (nor do
ghosts). This is merely cosmetic.~~ Cut out for the time being due to
issues with the specular emissive...

## Why It's Good For The Game
Refactoring / cleaning up old organ code.

## Changelog

🆑
refactor: Refactored organ damage code a little. Hopefully there won't
be issues (otherwise report them).
/🆑
This commit is contained in:
Ghom
2025-10-21 16:52:28 -05:00
committed by GitHub
parent 593fe47c1c
commit ca2cc70322
34 changed files with 422 additions and 388 deletions
@@ -83,8 +83,7 @@
if(HAS_TRAIT(current_target, TRAIT_DEAF))
return
var/obj/item/organ/ears/target_ears = current_target.get_organ_slot(ORGAN_SLOT_EARS)
target_ears?.adjustEarDamage(0, 5)
sound_damage(deafen = 10 SECONDS)
/mob/living/basic/bot/honkbot/ui_data(mob/user)
var/list/data = ..()
@@ -31,14 +31,10 @@
. = ..()
animate_pulse()
/obj/item/organ/legion_tumour/apply_organ_damage(damage_amount, maximum, required_organ_flag)
var/was_failing = organ_flags & ORGAN_FAILING
. = ..()
if (was_failing != (organ_flags & ORGAN_FAILING))
animate_pulse()
/obj/item/organ/legion_tumour/on_begin_failure()
animate_pulse()
/obj/item/organ/legion_tumour/set_organ_damage(damage_amount, required_organ_flag)
. = ..()
/obj/item/organ/legion_tumour/on_failure_recovery()
animate_pulse()
/// Do a heartbeat animation depending on if we're failing or not
+26 -29
View File
@@ -25,8 +25,6 @@
var/mob/living/brain/brainmob = null
/// If it's a fake brain with no brainmob assigned. Feedback messages will be faked as if it does have a brainmob. See changelings & dullahans.
var/decoy_override = FALSE
/// Two variables necessary for calculating whether we get a brain trauma or not
var/damage_delta = 0
var/list/datum/brain_trauma/traumas = list()
@@ -345,34 +343,42 @@
owner.investigate_log("has been killed by brain damage.", INVESTIGATE_DEATHS)
owner.death()
/obj/item/organ/brain/check_damage_thresholds(mob/M)
/obj/item/organ/brain/apply_organ_damage(damage_amount, maximum = maxHealth, required_organ_flag = NONE)
. = ..()
var/delta_dam = . //for the sake of clarity
if(delta_dam <= 0 || damage < BRAIN_DAMAGE_MILD)
return
if(prob(delta_dam * (1 + max(0, (damage - BRAIN_DAMAGE_MILD)/100)))) //Base chance is the hit damage; for every point of damage past the threshold the chance is increased by 1% //learn how to do your bloody math properly goddamnit
gain_trauma_type(BRAIN_TRAUMA_MILD, natural_gain = TRUE)
var/is_boosted = (owner && HAS_TRAIT(owner, TRAIT_SPECIAL_TRAUMA_BOOST))
if(damage < BRAIN_DAMAGE_SEVERE)
return
if(prob(delta_dam * (1 + max(0, (damage - BRAIN_DAMAGE_SEVERE)/100)))) //Base chance is the hit damage; for every point of damage past the threshold the chance is increased by 1%
if(prob(20 + (is_boosted * 30)))
gain_trauma_type(BRAIN_TRAUMA_SPECIAL, is_boosted ? TRAUMA_RESILIENCE_SURGERY : null, natural_gain = TRUE)
else
gain_trauma_type(BRAIN_TRAUMA_SEVERE, natural_gain = TRUE)
/obj/item/organ/brain/check_damage_thresholds()
. = ..()
if(!owner)
return
// If we crossed blinking brain damage thresholds either way, update our blinking
if (owner && ((prev_damage > BRAIN_DAMAGE_ASYNC_BLINKING && damage < BRAIN_DAMAGE_ASYNC_BLINKING) || (prev_damage < BRAIN_DAMAGE_ASYNC_BLINKING && damage > BRAIN_DAMAGE_ASYNC_BLINKING)))
if((prev_damage >= BRAIN_DAMAGE_ASYNC_BLINKING && damage < BRAIN_DAMAGE_ASYNC_BLINKING) || (prev_damage < BRAIN_DAMAGE_ASYNC_BLINKING && damage >= BRAIN_DAMAGE_ASYNC_BLINKING))
var/obj/item/organ/eyes/eyes = owner.get_organ_slot(ORGAN_SLOT_EYES)
if(eyes?.blink_animation)
eyes.animate_eyelids(owner)
if(damage >= 60 && prev_damage < 60)
owner.add_mood_event("brain_damage", /datum/mood_event/brain_damage)
else if(prev_damage >= 60 && damage < 60)
owner.clear_mood_event("brain_damage")
// If we're not more injured than before, return without gambling for a trauma
if(damage <= prev_damage)
return
damage_delta = damage - prev_damage
if(damage > BRAIN_DAMAGE_MILD)
if(prob(damage_delta * (1 + max(0, (damage - BRAIN_DAMAGE_MILD)/100)))) //Base chance is the hit damage; for every point of damage past the threshold the chance is increased by 1% //learn how to do your bloody math properly goddamnit
gain_trauma_type(BRAIN_TRAUMA_MILD, natural_gain = TRUE)
var/is_boosted = (owner && HAS_TRAIT(owner, TRAIT_SPECIAL_TRAUMA_BOOST))
if(damage > BRAIN_DAMAGE_SEVERE)
if(prob(damage_delta * (1 + max(0, (damage - BRAIN_DAMAGE_SEVERE)/100)))) //Base chance is the hit damage; for every point of damage past the threshold the chance is increased by 1%
if(prob(20 + (is_boosted * 30)))
gain_trauma_type(BRAIN_TRAUMA_SPECIAL, is_boosted ? TRAUMA_RESILIENCE_SURGERY : null, natural_gain = TRUE)
else
gain_trauma_type(BRAIN_TRAUMA_SEVERE, natural_gain = TRUE)
if (!owner || owner.stat > UNCONSCIOUS)
return
// Conscious or soft-crit
var/brain_message
if(prev_damage < BRAIN_DAMAGE_MILD && damage >= BRAIN_DAMAGE_MILD)
@@ -665,15 +671,6 @@
amount_cured++
return amount_cured
/obj/item/organ/brain/apply_organ_damage(damage_amount, maximum = maxHealth, required_organ_flag = NONE)
. = ..()
if(!owner)
return FALSE
if(damage >= 60)
owner.add_mood_event("brain_damage", /datum/mood_event/brain_damage)
else
owner.clear_mood_event("brain_damage")
/// This proc lets the mob's brain decide what bodypart to attack with in an unarmed strike.
/obj/item/organ/brain/proc/get_attacking_limb(mob/living/carbon/human/target)
var/obj/item/bodypart/arm/active_hand = owner.get_active_hand()
@@ -71,22 +71,19 @@ In all, this is a lot like the monkey code. /N
if(!. || QDELETED(src))
return FALSE
var/obj/item/organ/ears/ears = get_organ_slot(ORGAN_SLOT_EARS)
switch (severity)
if (EXPLODE_DEVASTATE)
gib(DROP_ALL_REMAINS)
if (EXPLODE_HEAVY)
take_overall_damage(60, 60)
if(ears)
ears.adjustEarDamage(30,120)
sound_damage(30, 240 SECONDS)
if(EXPLODE_LIGHT)
take_overall_damage(30,0)
if(prob(50))
Unconscious(20)
if(ears)
ears.adjustEarDamage(15,60)
sound_damage(15, 120 SECONDS)
return TRUE
@@ -16,6 +16,17 @@
if(isclothing(wear_mask)) //Mask
. += wear_mask.flash_protect
/mob/living/carbon/sound_damage(damage, deafen)
if(HAS_TRAIT(src, TRAIT_GODMODE))
return
var/obj/item/organ/ears/ears = get_organ_slot(ORGAN_SLOT_EARS)
if(QDELETED(ears))
return
if(damage)
ears.apply_organ_damage(damage * ears.damage_multiplier)
if(deafen)
ears.adjust_temporary_deafness(deafen)
/mob/living/carbon/get_ear_protection()
. = ..()
if(HAS_TRAIT(src, TRAIT_DEAF))
@@ -523,8 +534,8 @@
if(ears && (deafen_pwr || damage_pwr))
var/ear_damage = damage_pwr * effect_amount
var/deaf = deafen_pwr * effect_amount
ears.adjustEarDamage(ear_damage,deaf)
var/deaf = deafen_pwr * effect_amount * 2 SECONDS
sound_damage(ear_damage, deaf)
. = effect_amount //how soundbanged we are
SEND_SOUND(src, sound('sound/items/weapons/flash_ring.ogg',0,1,0,250))
@@ -20,7 +20,7 @@
if(OFFSET_HEAD)
update_worn_head()
if(OFFSET_FACE)
dna?.species?.update_face_offset(src) // updates eye and lipstick icon
update_face_offset() // updates eye and lipstick icon
update_worn_mask()
if(OFFSET_BELT)
update_worn_belt()
@@ -49,7 +49,6 @@
SEND_SIGNAL(src, COMSIG_CARBON_REMOVE_OVERLAY, cache_index, I)
/mob/living/carbon/update_body(is_creating = FALSE)
dna?.species.handle_body(src)
update_body_parts(is_creating)
/mob/living/carbon/on_changed_z_level(turf/old_turf, turf/new_turf, same_z_layer, notify_contents)
@@ -504,6 +503,9 @@
apply_overlay(BODYPARTS_LAYER)
/mob/living/carbon/proc/update_face_offset()
return
/////////////////////////
// Limb Icon Cache 2.0 //
/////////////////////////
@@ -485,84 +485,6 @@ GLOBAL_LIST_EMPTY(features_by_species)
human.living_flags &= ~STOP_OVERLAY_UPDATE_BODY_PARTS
/**
* Handles the body of a human
*
* Handles lipstick, having no eyes, eye color, undergarnments like underwear, undershirts, and socks, and body layers.
* Arguments:
* * species_human - Human, whoever we're handling the body for
*/
/datum/species/proc/handle_body(mob/living/carbon/human/species_human)
species_human.remove_overlay(BODY_LAYER)
species_human.remove_overlay(EYES_LAYER)
if(HAS_TRAIT(species_human, TRAIT_INVISIBLE_MAN))
return
if(!HAS_TRAIT(species_human, TRAIT_HUSK))
var/obj/item/bodypart/head/noggin = species_human.get_bodypart(BODY_ZONE_HEAD)
if(noggin?.head_flags & HEAD_EYESPRITES)
// eyes (missing eye sprites get handled by the head itself, but sadly we have to do this stupid shit here, for now)
var/obj/item/organ/eyes/eye_organ = species_human.get_organ_slot(ORGAN_SLOT_EYES)
if(eye_organ)
eye_organ.refresh(call_update = FALSE)
species_human.overlays_standing[EYES_LAYER] = eye_organ.generate_body_overlay(species_human)
species_human.apply_overlay(EYES_LAYER)
if(HAS_TRAIT(species_human, TRAIT_NO_UNDERWEAR))
return
// Underwear, Undershirts & Socks
var/list/standing = list()
if(species_human.underwear)
var/datum/sprite_accessory/underwear/underwear = SSaccessories.underwear_list[species_human.underwear]
var/mutable_appearance/underwear_overlay
if(underwear)
if(species_human.dna.species.sexes && species_human.physique == FEMALE && (underwear.gender == MALE))
underwear_overlay = mutable_appearance(wear_female_version(underwear.icon_state, underwear.icon, FEMALE_UNIFORM_FULL), layer = -BODY_LAYER)
else
underwear_overlay = mutable_appearance(underwear.icon, underwear.icon_state, -BODY_LAYER)
if(!underwear.use_static)
underwear_overlay.color = species_human.underwear_color
standing += underwear_overlay
if(species_human.undershirt)
var/datum/sprite_accessory/undershirt/undershirt = SSaccessories.undershirt_list[species_human.undershirt]
if(undershirt)
var/mutable_appearance/working_shirt
if(species_human.dna.species.sexes && species_human.physique == FEMALE)
working_shirt = mutable_appearance(wear_female_version(undershirt.icon_state, undershirt.icon), layer = -BODY_LAYER)
else
working_shirt = mutable_appearance(undershirt.icon, undershirt.icon_state, layer = -BODY_LAYER)
standing += working_shirt
if(species_human.socks && species_human.num_legs >= 2 && !(species_human.bodyshape & BODYSHAPE_DIGITIGRADE))
var/datum/sprite_accessory/socks/socks = SSaccessories.socks_list[species_human.socks]
if(socks)
standing += mutable_appearance(socks.icon, socks.icon_state, -BODY_LAYER)
if(standing.len)
species_human.overlays_standing[BODY_LAYER] = standing
species_human.apply_overlay(BODY_LAYER)
/// Updates face (as of now, only eye) offsets
/datum/species/proc/update_face_offset(mob/living/carbon/human/species_human)
var/list/eye_overlays = species_human.overlays_standing[EYES_LAYER]
species_human.remove_overlay(EYES_LAYER)
if(HAS_TRAIT(species_human, TRAIT_INVISIBLE_MAN) || HAS_TRAIT(species_human, TRAIT_HUSK) || !length(eye_overlays))
return
var/obj/item/bodypart/head/noggin = species_human.get_bodypart(BODY_ZONE_HEAD)
for (var/mutable_appearance/overlay as anything in eye_overlays)
overlay.pixel_w = 0
overlay.pixel_z = 0
noggin.worn_face_offset.apply_offset(overlay)
species_human.overlays_standing[EYES_LAYER] = eye_overlays
species_human.apply_overlay(EYES_LAYER)
// This exists so sprite accessories can still be per-layer without having to include that layer's
// number in their sprite name, which causes issues when those numbers change.
/datum/species/proc/mutant_bodyparts_layertext(layer)
@@ -271,7 +271,6 @@
//200 max knockdown for EXPLODE_HEAVY
//160 max knockdown for EXPLODE_LIGHT
var/obj/item/organ/ears/ears = get_organ_slot(ORGAN_SLOT_EARS)
switch (severity)
if (EXPLODE_DEVASTATE)
if(bomb_armor < EXPLODE_GIB_THRESHOLD) //gibs the mob if their bomb armor is lower than EXPLODE_GIB_THRESHOLD
@@ -299,8 +298,8 @@
brute_loss = 30*(2 - round(bomb_armor*0.01, 0.05))
burn_loss = brute_loss //damage gets reduced from 120 to up to 60 combined brute+burn
damage_clothes(200 - bomb_armor, BRUTE, BOMB)
if (ears && !HAS_TRAIT_FROM_ONLY(src, TRAIT_DEAF, EAR_DAMAGE))
ears.adjustEarDamage(30, 120)
if (!HAS_TRAIT_FROM(src, TRAIT_DEAF, EAR_DAMAGE))
sound_damage(30, 240 SECONDS)
Unconscious(20) //short amount of time for follow up attacks against elusive enemies like wizards
Knockdown(200 - (bomb_armor * 1.6)) //between ~4 and ~20 seconds of knockdown depending on bomb armor
@@ -309,8 +308,8 @@
if(bomb_armor)
brute_loss = 15*(2 - round(bomb_armor*0.01, 0.05))
damage_clothes(max(50 - bomb_armor, 0), BRUTE, BOMB)
if (ears && !HAS_TRAIT_FROM_ONLY(src, TRAIT_DEAF, EAR_DAMAGE))
ears.adjustEarDamage(15,60)
if (!HAS_TRAIT_FROM(src, TRAIT_DEAF, EAR_DAMAGE))
sound_damage(15, 120 SECONDS)
Knockdown(160 - (bomb_armor * 1.6)) //100 bomb armor will prevent knockdown altogether
take_overall_damage(brute_loss,burn_loss)
@@ -859,6 +859,82 @@ generate/load female uniform sprites matching all previously decided variables
observers = null
break
/mob/living/carbon/human/update_body(is_creating = FALSE)
update_eyes()
update_underwear()
return ..()
/mob/living/carbon/human/proc/update_underwear()
remove_overlay(BODY_LAYER)
if(HAS_TRAIT(src, TRAIT_HUSK) || HAS_TRAIT(src, TRAIT_INVISIBLE_MAN))
return
// Underwear, Undershirts & Socks
var/list/standing = list()
if(underwear)
var/datum/sprite_accessory/underwear/undie_accessory = SSaccessories.underwear_list[underwear]
var/mutable_appearance/underwear_overlay
if(undie_accessory)
if(dna.species.sexes && physique == FEMALE && (undie_accessory.gender == MALE))
underwear_overlay = mutable_appearance(wear_female_version(undie_accessory.icon_state, undie_accessory.icon, FEMALE_UNIFORM_FULL), layer = -BODY_LAYER)
else
underwear_overlay = mutable_appearance(undie_accessory.icon, undie_accessory.icon_state, -BODY_LAYER)
if(!undie_accessory.use_static)
underwear_overlay.color = underwear_color
standing += underwear_overlay
if(undershirt)
var/datum/sprite_accessory/undershirt/undie_accessory = SSaccessories.undershirt_list[undershirt]
if(undie_accessory)
var/mutable_appearance/working_shirt
if(dna.species.sexes && physique == FEMALE)
working_shirt = mutable_appearance(wear_female_version(undie_accessory.icon_state, undie_accessory.icon), layer = -BODY_LAYER)
else
working_shirt = mutable_appearance(undie_accessory.icon, undie_accessory.icon_state, layer = -BODY_LAYER)
standing += working_shirt
if(socks && num_legs >= 2 && !(bodyshape & BODYSHAPE_DIGITIGRADE))
var/datum/sprite_accessory/socks/undie_accessory = SSaccessories.socks_list[socks]
if(undie_accessory)
standing += mutable_appearance(undie_accessory.icon, undie_accessory.icon_state, -BODY_LAYER)
if(standing.len)
overlays_standing[BODY_LAYER] = standing
apply_overlay(BODY_LAYER)
/mob/living/carbon/human/proc/update_eyes()
remove_overlay(EYES_LAYER)
if(HAS_TRAIT(src, TRAIT_HUSK) || HAS_TRAIT(src, TRAIT_INVISIBLE_MAN))
return
var/obj/item/bodypart/head/noggin = get_bodypart(BODY_ZONE_HEAD)
if(!(noggin?.head_flags & HEAD_EYESPRITES))
return
// eyes (missing eye sprites get handled by the head itself, but sadly we have to do this stupid shit here, for now)
var/obj/item/organ/eyes/eye_organ = get_organ_slot(ORGAN_SLOT_EYES)
if(eye_organ)
eye_organ.refresh(call_update = FALSE)
overlays_standing[EYES_LAYER] = eye_organ.generate_body_overlay(src)
apply_overlay(EYES_LAYER)
/// Updates face (as of now, only eye) offsets
/mob/living/carbon/human/update_face_offset()
var/list/eye_overlays = overlays_standing[EYES_LAYER]
if(HAS_TRAIT(src, TRAIT_INVISIBLE_MAN) || HAS_TRAIT(src, TRAIT_HUSK) || !length(eye_overlays))
return
remove_overlay(EYES_LAYER)
var/obj/item/bodypart/head/noggin = get_bodypart(BODY_ZONE_HEAD)
for (var/mutable_appearance/overlay as anything in eye_overlays)
overlay.pixel_w = 0
overlay.pixel_z = 0
noggin.worn_face_offset.apply_offset(overlay)
overlays_standing[EYES_LAYER] = eye_overlays
apply_overlay(EYES_LAYER)
// Only renders the head of the human
/mob/living/carbon/human/proc/update_body_parts_head_only(update_limb_data)
if(!dna?.species)
@@ -6,6 +6,7 @@
mutantbrain = /obj/item/organ/brain/felinid
mutanttongue = /obj/item/organ/tongue/cat
mutantears = /obj/item/organ/ears/cat
mutanteyes = /obj/item/organ/eyes/felinid
mutant_organs = list(
/obj/item/organ/tail/cat = "Cat",
)
@@ -35,6 +35,10 @@
/mob/living/proc/get_eye_protection()
return 0
///A easy to use proc to apply both organ damage and temporary deafness at once, so you don't have to get the ears everytime.
/mob/living/proc/sound_damage(damage, deafen)
return
//this returns the mob's protection against ear damage (0:no protection; 1: some ear protection; 2: has no ears)
/mob/living/proc/get_ear_protection()
var/turf/current_turf = get_turf(src)