Skip to content

Commit

Permalink
Moving organ damage var/procs onto /internal.
Browse files Browse the repository at this point in the history
  • Loading branch information
MistakeNot4892 committed Feb 11, 2025
1 parent 2f3cdd1 commit 1da3735
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 41 deletions.
2 changes: 1 addition & 1 deletion code/datums/ai/human.dm
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
else
H.custom_emote("rubs [pronouns.his] [damaged_organ.name] carefully.")

for(var/obj/item/organ/organ in H.get_internal_organs())
for(var/obj/item/organ/internal/organ in H.get_internal_organs())
if((organ.status & ORGAN_DEAD) || BP_IS_PROSTHETIC(organ))
continue
if(organ.get_organ_damage() > 2 && prob(1))
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/flashlights/_flashlight.dm
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@

return ..()

/obj/item/flashlight/proc/inspect_vision(obj/item/organ/vision, mob/living/user)
/obj/item/flashlight/proc/inspect_vision(obj/item/organ/internal/vision, mob/living/user)
var/mob/living/human/H = vision.owner

if(H == user) //can't look into your own eyes buster
return

if(!BP_IS_PROSTHETIC(vision))
if(istype(vision) && !BP_IS_PROSTHETIC(vision))

if(vision.owner.stat == DEAD || H.is_blind()) //mob is dead or fully blind
to_chat(user, SPAN_WARNING("\The [H]'s pupils do not react to the light!"))
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/stacks/nanopaste.dm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
to_chat(user, SPAN_WARNING("\The [target]'s [affecting.name] is flesh and blood, and cannot be repaired with \the [src]."))
return TRUE

if(affecting.get_organ_damage() >= 30 && affecting.hatch_state != HATCH_OPENED)
if((affecting.brute_dam + affecting.burn_dam) >= 30 && affecting.hatch_state != HATCH_OPENED)
to_chat(user, SPAN_WARNING("The damage to \the [affecting] is too severe to repair without an open maintenance hatch."))
return TRUE

Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/human/examine.dm
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
wound_flavor_text[limb.name] += "[use_His] [limb.name] is irrecoverably damaged!"
else
wound_flavor_text[limb.name] += "[use_His] [limb.name] is grey and necrotic!<br>"
else if(limb.get_organ_damage() >= limb.max_damage && limb.germ_level >= INFECTION_LEVEL_TWO)
else if((limb.brute_dam + limb.burn_dam) >= limb.max_damage && limb.germ_level >= INFECTION_LEVEL_TWO)
wound_flavor_text[limb.name] += "[use_His] [limb.name] is likely beyond saving, and has begun to decay!"

for(var/datum/wound/wound in limb.wounds)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/human/human_attackhand.dm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
. += "irrecoverably damaged"
else
. += "grey and necrotic"
else if(_organ_damage >= max_damage && germ_level >= INFECTION_LEVEL_TWO)
else if((brute_dam + burn_dam) >= max_damage && germ_level >= INFECTION_LEVEL_TWO)
. += "likely beyond saving and decay has set in"

if(!is_usable() || is_dislocated()) // This one is special and has a different message for visible/pain modes.
Expand Down
8 changes: 4 additions & 4 deletions code/modules/mob/living/human/life.dm
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@
SET_HUD_ALERT(src, HUD_PRESSURE, -1)
else
var/list/obj/item/organ/external/parts = get_damageable_organs()
for(var/obj/item/organ/external/organ in parts)
if(QDELETED(organ) || !(organ.owner == src))
for(var/obj/item/organ/external/limb in parts)
if(QDELETED(limb) || !(limb.owner == src))
continue
if(organ.get_organ_damage() + (LOW_PRESSURE_DAMAGE) < organ.min_broken_damage) //vacuum does not break bones
organ.take_damage(LOW_PRESSURE_DAMAGE, inflicter = "Low Pressure")
if(limb.brute_dam + limb.burn_dam + (LOW_PRESSURE_DAMAGE) < limb.min_broken_damage) //vacuum does not break bones
limb.take_damage(LOW_PRESSURE_DAMAGE, inflicter = "Low Pressure")
if(getOxyLossPercent() < 55) // 11 OxyLoss per 4 ticks when wearing internals; unconsciousness in 16 ticks, roughly half a minute
take_damage(4) // 16 OxyLoss per 4 ticks when no internals present; unconsciousness in 13 ticks, OXY, roughly twenty seconds
SET_HUD_ALERT(src, HUD_PRESSURE, -2)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/silicon/robot/analyzer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
to_chat(user, "<hr>")
to_chat(user, SPAN_NOTICE("Internal prosthetics:"))
organ_found = null
for(var/obj/item/organ/organ in H.get_internal_organs())
for(var/obj/item/organ/internal/organ in H.get_internal_organs())
if(!BP_IS_PROSTHETIC(organ))
continue
organ_found = 1
Expand Down
11 changes: 8 additions & 3 deletions code/modules/organs/external/_external.dm
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,10 @@ This function completely restores a damaged organ to perfect condition.
pain = 0
..()

//check if we've hit max_damage
if((brute_dam + burn_dam) >= max_damage)
die()

//Updating germ levels. Handles organ germ levels and necrosis.
/*
The INFECTION_LEVEL values defined in setup.dm control the time it takes to reach the different
Expand Down Expand Up @@ -952,7 +956,6 @@ Note that amputating the affected organ does in fact remove the infection from t
clamped |= wound.clamped
number_wounds += wound.amount

_organ_damage = brute_dam + burn_dam
update_damage_ratios()

/obj/item/organ/external/proc/update_damage_ratios()
Expand Down Expand Up @@ -1548,7 +1551,7 @@ Note that amputating the affected organ does in fact remove the infection from t
else if(status & ORGAN_BROKEN)
. += max_delay * 3/8
else if(BP_IS_PROSTHETIC(src))
. += max_delay * CLAMP01(_organ_damage/max_damage)
. += max_delay * CLAMP01((brute_dam + burn_dam) / max_damage)

/obj/item/organ/external/proc/is_robotic()
return bodytype.is_robotic
Expand All @@ -1563,7 +1566,7 @@ Note that amputating the affected organ does in fact remove the infection from t

/obj/item/organ/external/die() //External organs dying on a dime causes some real issues in combat
if(!BP_IS_PROSTHETIC(src) && !BP_IS_CRYSTAL(src))
var/decay_rate = _organ_damage/(max_damage*2)
var/decay_rate = (brute_dam + burn_dam) / (max_damage*2)
germ_level += round(rand(decay_rate,decay_rate*1.5)) //So instead, we're going to say the damage is so severe its functions are slowly failing due to the extensive damage
else //TODO: more advanced system for synths
if(istype(src,/obj/item/organ/external/chest) || istype(src,/obj/item/organ/external/groin))
Expand Down Expand Up @@ -1639,3 +1642,5 @@ Note that amputating the affected organ does in fact remove the infection from t
_sprite_accessories = null
update_icon()

/obj/item/organ/external/is_broken()
return (brute_dam + burn_dam) >= min_broken_damage || ..()
33 changes: 33 additions & 0 deletions code/modules/organs/internal/_internal.dm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
/// Whether or not we should try to transfer a brainmob when removed or replaced in a mob.
var/transfer_brainmob_with_organ = FALSE

// Current damage to the organ
VAR_PRIVATE/_organ_damage = 0

/obj/item/organ/internal/Initialize(mapload, material_key, datum/mob_snapshot/supplied_appearance, decl/bodytype/new_bodytype)
if(!alive_icon)
alive_icon = initial(icon_state)
Expand Down Expand Up @@ -160,6 +163,9 @@
/obj/item/organ/internal/Process()
SHOULD_CALL_PARENT(TRUE)
..()
//check if we've hit max_damage
if(_organ_damage >= max_damage)
die()
if(owner && _organ_damage && !(status & ORGAN_DEAD))
handle_damage_effects()

Expand Down Expand Up @@ -295,3 +301,30 @@
/obj/item/organ/internal/preserve_in_cryopod(var/obj/machinery/cryopod/pod)
var/mob/living/brainmob = get_brainmob()
return brainmob?.key

/obj/item/organ/internal/proc/set_organ_damage(amt)
_organ_damage = amt

/obj/item/organ/internal/proc/adjust_organ_damage(amt)
_organ_damage = clamp(_organ_damage + amt, 0, max_damage)

/obj/item/organ/internal/proc/get_organ_damage()
return _organ_damage // TODO: get_max_health() - current_health, unify organ/item damage handling.

/obj/item/organ/internal/is_broken()
return _organ_damage >= min_broken_damage || ..()

/obj/item/organ/internal/die()
_organ_damage = max_damage
return ..()

/obj/item/organ/internal/rejuvenate(var/ignore_organ_traits)
_organ_damage = 0
return ..()

/obj/item/organ/internal/heal_damage(amount)
if(can_recover())
_organ_damage = clamp(_organ_damage - round(amount, 0.1), 0, max_damage)
if(owner)
owner.update_health()

23 changes: 2 additions & 21 deletions code/modules/organs/organ.dm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
var/meat_name // Taken from first owner.

// Damage vars.
VAR_PRIVATE/_organ_damage = 0 // Current damage to the organ
var/min_broken_damage = 30 // Damage before becoming broken
var/max_damage = 30 // Damage cap, including scarring
var/absolute_max_damage = 0 // Lifetime damage cap, ignoring scarring.
Expand Down Expand Up @@ -63,17 +62,8 @@
/obj/item/organ/attack_self(var/mob/user)
return (owner && loc == owner && owner == user)

/obj/item/organ/proc/set_organ_damage(amt)
_organ_damage = amt

/obj/item/organ/proc/adjust_organ_damage(amt)
_organ_damage = clamp(_organ_damage + amt, 0, max_damage)

/obj/item/organ/proc/get_organ_damage()
return _organ_damage // TODO: get_max_health() - current_health, unify organ/item damage handling.

/obj/item/organ/proc/is_broken()
return (get_organ_damage() >= min_broken_damage || (status & ORGAN_CUT_AWAY) || (status & ORGAN_BROKEN) || (status & ORGAN_DEAD))
return (status & ORGAN_CUT_AWAY) || (status & ORGAN_BROKEN) || (status & ORGAN_DEAD)

//Third argument may be a dna datum; if null will be set to holder's dna.
/obj/item/organ/Initialize(mapload, material_key, datum/mob_snapshot/supplied_appearance)
Expand Down Expand Up @@ -206,7 +196,6 @@
reset_status()

/obj/item/organ/proc/die()
_organ_damage = max_damage
status |= ORGAN_DEAD
STOP_PROCESSING(SSobj, src)
QDEL_NULL_LIST(ailments)
Expand Down Expand Up @@ -253,10 +242,6 @@
for(var/datum/ailment/ailment in ailments)
handle_ailment(ailment)

//check if we've hit max_damage
if(get_organ_damage() >= max_damage)
die()

/obj/item/organ/proc/handle_ailment(var/datum/ailment/ailment)
if(ailment.treated_by_reagent_type)
for(var/datum/reagents/source as anything in owner.get_metabolizing_reagent_holders())
Expand Down Expand Up @@ -360,7 +345,6 @@
SHOULD_CALL_PARENT(TRUE)
if(!owner)
PRINT_STACK_TRACE("rejuvenate() called on organ of type [type] with no owner.")
_organ_damage = 0
reset_status()
QDEL_NULL_LIST(ailments)
if(!ignore_organ_traits)
Expand Down Expand Up @@ -400,10 +384,7 @@
return ..()

/obj/item/organ/proc/heal_damage(amount)
if(can_recover())
_organ_damage = clamp(_organ_damage - round(amount, 0.1), 0, max_damage)
if(owner)
owner.update_health()
return

/obj/item/organ/use_on_mob(mob/living/target, mob/living/user, animate = TRUE)
if(BP_IS_PROSTHETIC(src) || !istype(target) || !istype(user) || (user != target && user.check_intent(I_FLAG_HELP)))
Expand Down
2 changes: 1 addition & 1 deletion code/modules/organs/organ_prosthetics.dm
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

// Checks if an organ (or the parent of one) is in a fit state for modular limb stuff to happen.
/obj/item/organ/external/proc/check_modular_limb_damage(var/mob/living/human/user)
. = _organ_damage >= min_broken_damage || (status & ORGAN_BROKEN) // can't use is_broken() as the limb has ORGAN_CUT_AWAY
. = (brute_dam + burn_dam) >= min_broken_damage || (status & ORGAN_BROKEN) // can't use is_broken() as the limb has ORGAN_CUT_AWAY

// Human mob procs:
// Checks the organ list for limbs meeting a predicate. Way overengineered for such a limited use
Expand Down
4 changes: 2 additions & 2 deletions code/modules/surgery/robotics.dm
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@

/decl/surgery_step/robotics/fix_organ_robotic/begin_step(mob/user, mob/living/target, target_zone, obj/item/tool)
var/obj/item/organ/external/affected = GET_EXTERNAL_ORGAN(target, target_zone)
for(var/obj/item/organ/organ in affected.internal_organs)
for(var/obj/item/organ/internal/organ in affected.internal_organs)
if(organ.get_organ_damage() > 0)
if(BP_IS_PROSTHETIC(organ))
user.visible_message("[user] starts mending the damage to [target]'s [organ.name]'s mechanisms.", \
Expand All @@ -378,7 +378,7 @@

/decl/surgery_step/robotics/fix_organ_robotic/end_step(mob/living/user, mob/living/target, target_zone, obj/item/tool)
var/obj/item/organ/external/affected = GET_EXTERNAL_ORGAN(target, target_zone)
for(var/obj/item/organ/organ in affected.internal_organs)
for(var/obj/item/organ/internal/organ in affected.internal_organs)
if(organ.get_organ_damage() > 0)
if(BP_IS_PROSTHETIC(organ))
user.visible_message("<span class='notice'>[user] repairs [target]'s [organ.name] with [tool].</span>", \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@

// Heal organ damage.
if(heal_internal)
for(var/obj/item/organ/organ in H.get_internal_organs())
for(var/obj/item/organ/internal/organ in H.get_internal_organs())

if(BP_IS_PROSTHETIC(organ) || BP_IS_CRYSTAL(organ))
continue
Expand Down
4 changes: 2 additions & 2 deletions mods/gamemodes/cult/runes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -576,13 +576,13 @@
if(!charges)
return statuses
var/list/obj/item/organ/damaged = list()
for(var/obj/item/organ/organ in user.internal_organs)
for(var/obj/item/organ/internal/organ in user.internal_organs)
if(organ.get_organ_damage())
damaged += organ
if(damaged.len)
statuses += "you feel pain inside for a moment that passes quickly"
while(charges && damaged.len)
var/obj/item/organ/fix = pick(damaged)
var/obj/item/organ/internal/fix = pick(damaged)
fix.adjust_organ_damage(-(min(charges, 1)))
charges = max(charges - 1, 0)
if(fix.get_organ_damage() <= 0)
Expand Down

0 comments on commit 1da3735

Please sign in to comment.