From 701df43ee01630d78b11df4fee90541a54fa23d8 Mon Sep 17 00:00:00 2001 From: KasparoVy Date: Wed, 18 May 2016 03:08:38 -0400 Subject: [PATCH] Doesn't Rejuvenate Limbs or Organs if ones Exist on Mob... ... with the same limb name (in the case of external organs) or the same slot (in the case of internal organs) to prevent duplication. --- code/modules/mob/living/carbon/human/human.dm | 33 +++++++++++++------ code/modules/mob/living/living.dm | 1 + code/modules/surgery/organs/helpers.dm | 7 +++- code/modules/surgery/organs/organ.dm | 7 +++- code/modules/surgery/organs/organ_external.dm | 6 ++-- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/code/modules/mob/living/carbon/human/human.dm b/code/modules/mob/living/carbon/human/human.dm index 862e52083b1..a4db994cf08 100644 --- a/code/modules/mob/living/carbon/human/human.dm +++ b/code/modules/mob/living/carbon/human/human.dm @@ -1256,9 +1256,9 @@ germ_level += n /mob/living/carbon/human/proc/check_and_regenerate_organs(var/mob/living/carbon/human/H) //Regenerates missing limbs/organs. - var/list/types_of_int_organs = list() + var/list/types_of_int_organs = list() //This will hold all the types of organs in the mob before rejuvenation. for(var/obj/item/organ/internal/I in H.internal_organs) - types_of_int_organs |= I.type + types_of_int_organs |= I.type //Compiling the list of organ types. It is possible for organs to be missing from this list if they are absent from the mob. //Removing stumps. for(var/obj/item/organ/organ in H.contents) @@ -1276,20 +1276,32 @@ H.organs_by_name -= organ_name //Making sure the list entry is removed. //Replacing lost limbs with the species default. + var/mob/living/carbon/human/temp_holder for(var/limb_type in H.species.has_limbs) if(!(limb_type in H.organs_by_name)) var/list/organ_data = H.species.has_limbs[limb_type] var/limb_path = organ_data["path"] - var/obj/item/organ/external/O = new limb_path(H) - O.owner = H - H.organs |= H.organs_by_name[O.limb_name] + var/obj/item/organ/external/O = new limb_path(temp_holder) + if(H.get_limb_by_name(O.name)) //Check to see if the user already has an limb with the same name as the 'missing limb'. If they do, skip regrowth. + continue //In an example, this will prevent duplication of the mob's right arm if the mob is a Human and they have a Diona right arm, since, + //while the limb with the name 'right_arm' the mob has may not be listed in their species' bodyparts definition, it is still viable and has the appropriate limb name. + else + O = new limb_path(H) //Create the limb on the player. + O.owner = H + H.organs |= H.organs_by_name[O.limb_name] //Replacing lost organs with the species default. + temp_holder = new /mob/living/carbon/human() for(var/index in H.species.has_organ) var/organ = H.species.has_organ[index] - if(!(organ in types_of_int_organs)) - var/obj/item/organ/internal/I = new organ(H) - I.insert(H) + if(!(organ in types_of_int_organs)) //If the mob is missing this particular organ... + var/obj/item/organ/internal/I = new organ(temp_holder) //Create the organ inside our holder so we can check it before implantation. + if(H.get_organ_slot(I.slot)) //Check to see if the user already has an organ in the slot the 'missing organ' belongs to. If they do, skip implantation. + continue //In an example, this will prevent duplication of the mob's eyes if the mob is a Human and they have Nucleation eyes, since, + //while the organ in the eyes slot may not be listed in the mob's species' organs definition, it is still viable and fits in the appropriate organ slot. + else + I = new organ(H) //Create the organ inside the player. + I.insert(H) /mob/living/carbon/human/revive() @@ -1299,8 +1311,9 @@ fixblood() //Fix up all organs and replace lost ones. - restore_all_organs() - check_and_regenerate_organs(src) + restore_all_organs() //Rejuvenate and reset all existing organs. + check_and_regenerate_organs(src) //Regenerate limbs and organs only if they're really missing. + surgeries.Cut() //End all surgeries. if(!client || !key) //Don't boot out anyone already in the mob. for (var/obj/item/organ/internal/brain/H in world) diff --git a/code/modules/mob/living/living.dm b/code/modules/mob/living/living.dm index 7c349766d88..e8b52c238c0 100644 --- a/code/modules/mob/living/living.dm +++ b/code/modules/mob/living/living.dm @@ -405,6 +405,7 @@ human_mob.decaylevel = 0 restore_all_organs() + surgeries.Cut() //End all surgeries. if(stat == DEAD) dead_mob_list -= src living_mob_list += src diff --git a/code/modules/surgery/organs/helpers.dm b/code/modules/surgery/organs/helpers.dm index 29bd9801b26..a61537f1985 100644 --- a/code/modules/surgery/organs/helpers.dm +++ b/code/modules/surgery/organs/helpers.dm @@ -40,4 +40,9 @@ return O /proc/is_int_organ(atom/A) - return istype(A, /obj/item/organ/internal) \ No newline at end of file + return istype(A, /obj/item/organ/internal) + +/mob/living/carbon/human/proc/get_limb_by_name(limb_name) //Look for a limb with the given limb name in the source mob, and return it if found. + for(var/obj/item/organ/external/O in organs) + if(limb_name == O.limb_name) + return O diff --git a/code/modules/surgery/organs/organ.dm b/code/modules/surgery/organs/organ.dm index 3bce602694a..9c1398c6405 100644 --- a/code/modules/surgery/organs/organ.dm +++ b/code/modules/surgery/organs/organ.dm @@ -176,7 +176,12 @@ var/list/organ_cache = list() /obj/item/organ/proc/rejuvenate() damage = 0 germ_level = 0 - status &= ~ORGAN_DEAD + if(status & ORGAN_ROBOT) //Robotic organs stay robotic. + status = ORGAN_ROBOT + else if (status & ORGAN_ASSISTED) //Assisted organs stay assisted. + status = ORGAN_ASSISTED + else + status = 0 if(!owner) processing_objects |= src diff --git a/code/modules/surgery/organs/organ_external.dm b/code/modules/surgery/organs/organ_external.dm index d60e12b9e77..d0245c224d9 100644 --- a/code/modules/surgery/organs/organ_external.dm +++ b/code/modules/surgery/organs/organ_external.dm @@ -308,8 +308,10 @@ This function completely restores a damaged organ to perfect condition. */ /obj/item/organ/external/rejuvenate() damage_state = "00" - if(status & 128) //Robotic organs stay robotic. - status = 128 + if(status & ORGAN_ROBOT) //Robotic organs stay robotic. + status = ORGAN_ROBOT + else if (status & ORGAN_ASSISTED) //Assisted organs stay assisted. + status = ORGAN_ASSISTED else status = 0 germ_level = 0