From 97499a276ef33f57219ffed9719d381bbd92ad49 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Thu, 19 Jan 2023 21:32:47 +0100 Subject: [PATCH] [MIRROR] Limb-based damage descriptions fixes and code improvement [MDB IGNORE] (#18703) * Limb-based damage descriptions fixes and code improvement (#72236) ## About The Pull Request The limb-based damage descriptions added by #71635 didn't work properly, as get_majority_bodypart_damage_desc() didn't return the correct values. I rewrote the proc altogether and changed the format of the damage description vars (formerly burn_damage_desc and brute_damage_desc). They are now a single associative list with each description being indexed by it's respective damage type DEFINE The proc now returns the correct description, avoids the duplicated code between the brute and burn sections and can support any number of damage types. To that end I also added Clone damage support, although no limbs use a special description for the moment. Oh, I also gave the robotic damage descriptions to all the robotic limbs, for some reason only the left robot arm had it. ## Why It's Good For The Game It makes the system function properly and correctly labels robotic limbs. On the side of the proc, it's more flexible this way and avoids the redundancy. I am aware, however, that I'm using a lot of associative lists. I'll rewrite it to reduce them if memory is deemed significant concern in this context. It's, admittedly, probably a bit overengineered for what it is. ## Changelog :cl: fix: the examine text for damage now properly uses the most common examine text out of all the mob's limbs fix: all robotic limbs now have the robotic damage descriptions (charring, denting) code: improved the get_majority_bodypart_damage_desc() proc to reduce redundancies and add support for limb-based cellular damage /:cl: Co-authored-by: Jeremiah <42397676+jlsnow301@ users.noreply.github.com> * Limb-based damage descriptions fixes and code improvement Co-authored-by: A miscellaneous Fern <80640114+FernandoJ8@users.noreply.github.com> Co-authored-by: Jeremiah <42397676+jlsnow301@ users.noreply.github.com> --- .../mob/living/carbon/human/examine.dm | 6 +-- .../mob/living/carbon/human/human_helpers.dm | 38 +++++++++---------- code/modules/surgery/bodyparts/_bodyparts.dm | 4 +- .../surgery/bodyparts/robot_bodyparts.dm | 11 +++++- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/code/modules/mob/living/carbon/human/examine.dm b/code/modules/mob/living/carbon/human/examine.dm index 78ec6382b26..ea513d899e5 100644 --- a/code/modules/mob/living/carbon/human/examine.dm +++ b/code/modules/mob/living/carbon/human/examine.dm @@ -245,11 +245,11 @@ temp = getCloneLoss() if(temp) if(temp < 25) - msg += "[t_He] [t_has] minor [dna.species.cellular_damage_desc].\n" + msg += "[t_He] [t_has] minor [damage_desc[CLONE]].\n" else if(temp < 50) - msg += "[t_He] [t_has] moderate [dna.species.cellular_damage_desc]!\n" + msg += "[t_He] [t_has] moderate [damage_desc[CLONE]]!\n" else - msg += "[t_He] [t_has] severe [dna.species.cellular_damage_desc]!\n" + msg += "[t_He] [t_has] severe [damage_desc[CLONE]]!\n" if(has_status_effect(/datum/status_effect/fire_handler/fire_stacks)) diff --git a/code/modules/mob/living/carbon/human/human_helpers.dm b/code/modules/mob/living/carbon/human/human_helpers.dm index 833c6b10181..edfae450cf7 100644 --- a/code/modules/mob/living/carbon/human/human_helpers.dm +++ b/code/modules/mob/living/carbon/human/human_helpers.dm @@ -7,28 +7,24 @@ ///returns a list of "damtype" => damage description based off of which bodypart description is most common ///used in human examines /mob/living/carbon/human/proc/get_majority_bodypart_damage_desc() - var/most_seen_brute = 0 - var/most_seen_burn = 0 - var/brute_desc = "" - var/burn_desc = "" - var/list/seen_brute = list() - var/list/seen_burn = list() + var/list/seen_damage = list() // This looks like: ({Damage type} = list({Damage description for that damage type} = {number of times it has appeared}, ...), ...) + var/list/most_seen_damage = list() // This looks like: ({Damage type} = {Frequency of the most common description}, ...) + var/list/final_descriptions = list() // This looks like: ({Damage type} = {Most common damage description for that type}, ...) for(var/obj/item/bodypart/part as anything in bodyparts) - //brute - if(!seen_brute[part.brute_damage_desc]) - seen_brute[part.brute_damage_desc] = 1 - else - seen_brute[part.brute_damage_desc] += 1 - if(seen_brute[part.brute_damage_desc] > most_seen_brute) - brute_desc = part.brute_damage_desc - //burn - if(!seen_burn[part.burn_damage_desc]) - seen_burn[part.burn_damage_desc] = 1 - else - seen_burn[part.burn_damage_desc] += 1 - if(seen_burn[part.burn_damage_desc] > most_seen_burn) - burn_desc = part.burn_damage_desc - return list(BRUTE = brute_desc, BURN = burn_desc) + for(var/damage_type in part.damage_examines) + var/damage_desc = part.damage_examines[damage_type] + if(!seen_damage[damage_type]) + seen_damage[damage_type] = list() + + if(!seen_damage[damage_type][damage_desc]) + seen_damage[damage_type][damage_desc] = 1 + else + seen_damage[damage_type][damage_desc] += 1 + + if(seen_damage[damage_type][damage_desc] > most_seen_damage[damage_type]) + most_seen_damage[damage_type] = seen_damage[damage_type][damage_desc] + final_descriptions[damage_type] = damage_desc + return final_descriptions //gets assignment from ID or ID inside PDA or PDA itself //Useful when player do something with computers diff --git a/code/modules/surgery/bodyparts/_bodyparts.dm b/code/modules/surgery/bodyparts/_bodyparts.dm index 0dd25e2ccb2..15360810521 100644 --- a/code/modules/surgery/bodyparts/_bodyparts.dm +++ b/code/modules/surgery/bodyparts/_bodyparts.dm @@ -125,9 +125,7 @@ var/heavy_burn_msg = "peeling away" //Damage messages used by examine(). the desc that is most common accross all bodyparts gets shown - - var/brute_damage_desc = DEFAULT_BRUTE_EXAMINE_TEXT - var/burn_damage_desc = DEFAULT_BURN_EXAMINE_TEXT + var/list/damage_examines = list(BRUTE = DEFAULT_BRUTE_EXAMINE_TEXT, BURN = DEFAULT_BURN_EXAMINE_TEXT, CLONE = DEFAULT_CLONE_EXAMINE_TEXT) // Wounds related variables /// The wounds currently afflicting this body part diff --git a/code/modules/surgery/bodyparts/robot_bodyparts.dm b/code/modules/surgery/bodyparts/robot_bodyparts.dm index a18d86caa23..fa60ed06ee1 100644 --- a/code/modules/surgery/bodyparts/robot_bodyparts.dm +++ b/code/modules/surgery/bodyparts/robot_bodyparts.dm @@ -37,8 +37,7 @@ medium_burn_msg = ROBOTIC_MEDIUM_BURN_MSG heavy_burn_msg = ROBOTIC_HEAVY_BURN_MSG - brute_damage_desc = ROBOTIC_BRUTE_EXAMINE_TEXT - burn_damage_desc = ROBOTIC_BURN_EXAMINE_TEXT + damage_examines = list(BRUTE = ROBOTIC_BRUTE_EXAMINE_TEXT, BURN = ROBOTIC_BURN_EXAMINE_TEXT, CLONE = DEFAULT_CLONE_EXAMINE_TEXT) disabling_threshold_percentage = 1 /obj/item/bodypart/arm/right/robot @@ -69,6 +68,7 @@ medium_burn_msg = ROBOTIC_MEDIUM_BURN_MSG heavy_burn_msg = ROBOTIC_HEAVY_BURN_MSG + damage_examines = list(BRUTE = ROBOTIC_BRUTE_EXAMINE_TEXT, BURN = ROBOTIC_BURN_EXAMINE_TEXT, CLONE = DEFAULT_CLONE_EXAMINE_TEXT) /obj/item/bodypart/leg/left/robot name = "cyborg left leg" @@ -98,6 +98,7 @@ medium_burn_msg = ROBOTIC_MEDIUM_BURN_MSG heavy_burn_msg = ROBOTIC_HEAVY_BURN_MSG + damage_examines = list(BRUTE = ROBOTIC_BRUTE_EXAMINE_TEXT, BURN = ROBOTIC_BURN_EXAMINE_TEXT, CLONE = DEFAULT_CLONE_EXAMINE_TEXT) /obj/item/bodypart/leg/right/robot name = "cyborg right leg" @@ -127,6 +128,8 @@ medium_burn_msg = ROBOTIC_MEDIUM_BURN_MSG heavy_burn_msg = ROBOTIC_HEAVY_BURN_MSG + damage_examines = list(BRUTE = ROBOTIC_BRUTE_EXAMINE_TEXT, BURN = ROBOTIC_BURN_EXAMINE_TEXT, CLONE = DEFAULT_CLONE_EXAMINE_TEXT) + /obj/item/bodypart/chest/robot name = "cyborg torso" desc = "A heavily reinforced case containing cyborg logic boards, with space for a standard power cell." @@ -153,6 +156,8 @@ medium_burn_msg = ROBOTIC_MEDIUM_BURN_MSG heavy_burn_msg = ROBOTIC_HEAVY_BURN_MSG + damage_examines = list(BRUTE = ROBOTIC_BRUTE_EXAMINE_TEXT, BURN = ROBOTIC_BURN_EXAMINE_TEXT, CLONE = DEFAULT_CLONE_EXAMINE_TEXT) + var/wired = FALSE var/obj/item/stock_parts/cell/cell = null @@ -263,6 +268,8 @@ medium_burn_msg = ROBOTIC_MEDIUM_BURN_MSG heavy_burn_msg = ROBOTIC_HEAVY_BURN_MSG + damage_examines = list(BRUTE = ROBOTIC_BRUTE_EXAMINE_TEXT, BURN = ROBOTIC_BURN_EXAMINE_TEXT, CLONE = DEFAULT_CLONE_EXAMINE_TEXT) + var/obj/item/assembly/flash/handheld/flash1 = null var/obj/item/assembly/flash/handheld/flash2 = null