Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/__DEFINES/medical.dm
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@

//~brain damage related defines
/// We need to take at least this much brainloss gained at once to roll for brain traumas, any less it won't roll
#define TRAUMA_ROLL_THRESHOLD 4.5
#define TRAUMA_ROLL_THRESHOLD 6
/// Brainloss caused by mildly low blood oxygenation
#define BRAIN_DAMAGE_LOW_OXYGENATION 1.5
/// Brainloss caused by lower than low blood oxygenation
Expand Down
110 changes: 59 additions & 51 deletions code/modules/surgery/organs/internal/brain.dm
Original file line number Diff line number Diff line change
Expand Up @@ -307,75 +307,83 @@
return FLOOR(damage / damage_threshold_value, 1)


/obj/item/organ/brain/check_damage_thresholds(mob/M)
/obj/item/organ/brain/check_damage_thresholds()
. = ..()
// if we're not more injured than before, return without gambling for a trauma
if(damage <= prev_damage)
return

var/damage_delta = damage - prev_damage

// Safeguard to prevent traumas from low damage
if((damage_delta >= TRAUMA_ROLL_THRESHOLD) && (damage >= BRAIN_DAMAGE_MILD))
var/is_boosted = FALSE
var/intelligence_modifier = (owner ? -(GET_MOB_ATTRIBUTE_VALUE(owner, STAT_INTELLIGENCE)-ATTRIBUTE_MIDDLING) : 0)
if(damage_delta >= TRAUMA_ROLL_THRESHOLD && damage >= BRAIN_DAMAGE_MILD)
// Base chance is the hit damage, plus intelligence mod; for every point of damage past the threshold the chance is increased by 1%
var/intelligence_modifier = (owner ? -(GET_MOB_ATTRIBUTE_VALUE(owner, STAT_INTELLIGENCE) - ATTRIBUTE_MIDDLING) : 0)
if(damage >= BRAIN_DAMAGE_SEVERE)
// Base chance is the hit damage, plus intelligence mod; for every point of damage past the threshold the chance is increased by 1%
if(prob((damage_delta+intelligence_modifier) * (1 + max(0, (damage - BRAIN_DAMAGE_SEVERE)/100))))
if(prob(20 + (is_boosted * 30) - (intelligence_modifier * 2)))
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)
else
// Base chance is the hit damage, plus intelligence mod; for every point of damage past the threshold the chance is increased by 1%
if(prob((damage_delta+intelligence_modifier) * (1 + max(0, (damage - BRAIN_DAMAGE_MILD)/100))))
gain_trauma_type(BRAIN_TRAUMA_MILD, natural_gain = TRUE)
if(owner)
if(damage >= BRAIN_DAMAGE_DEATH && prev_damage < BRAIN_DAMAGE_DEATH && (organ_flags & ORGAN_VITAL))
owner.death()
return
var/brain_message
if(prev_damage < BRAIN_DAMAGE_MILD && damage >= BRAIN_DAMAGE_MILD)
brain_message = span_warning("I feel lightheaded.")
else if(prev_damage < BRAIN_DAMAGE_SEVERE && damage >= BRAIN_DAMAGE_SEVERE)
brain_message = span_warning("I feel less in control of my thoughts.")
else if(prev_damage < (BRAIN_DAMAGE_DEATH - 20) && damage >= (BRAIN_DAMAGE_DEATH - 20) && damage < BRAIN_DAMAGE_DEATH)
brain_message = span_warning("I can feel my mind flickering on and off...")
if(.)
. += "\n[brain_message]"
else
return brain_message
if(prob((damage_delta + intelligence_modifier) * (1 + max(0, (damage - BRAIN_DAMAGE_SEVERE) / 100))))
gain_trauma_type(BRAIN_TRAUMA_SEVERE, natural_gain = TRUE)
else if(prob((damage_delta + intelligence_modifier) * (1 + max(0, (damage - BRAIN_DAMAGE_MILD)/100))))
gain_trauma_type(BRAIN_TRAUMA_MILD, natural_gain = TRUE)

if(damage >= BRAIN_DAMAGE_DEATH && prev_damage < BRAIN_DAMAGE_DEATH && (organ_flags & ORGAN_VITAL))
owner.death()
return

var/brain_message
if(prev_damage < BRAIN_DAMAGE_MILD && damage >= BRAIN_DAMAGE_MILD)
brain_message = span_warning("I feel lightheaded.")
else if(prev_damage < BRAIN_DAMAGE_SEVERE && damage >= BRAIN_DAMAGE_SEVERE)
brain_message = span_warning("I feel less in control of my thoughts.")
else if(prev_damage < (BRAIN_DAMAGE_DEATH - 20) && damage >= (BRAIN_DAMAGE_DEATH - 20) && damage < BRAIN_DAMAGE_DEATH)
brain_message = span_warning("I can feel my mind flickering on and off...")
if(.)
. += "\n[brain_message]"
else
return brain_message

/obj/item/organ/brain/applyOrganDamage(amount, maximum = maxHealth, silent = FALSE)
if(!amount) //Micro-optimization.
return

if(maximum < damage)
damage = maximum

if(damage < 0 && owner?.get_chem_effect(CE_BRAIN_REGEN))
damage *= 2

prev_damage = damage
damage = clamp(damage + amount, 0, maximum)

if(!owner)
return

var/mess = check_damage_thresholds(owner)
if(owner)
if(mess && !silent)
to_chat(owner, mess)
if(organ_flags & ORGAN_LIMB_SUPPORTER)
var/obj/item/bodypart/affected = owner.get_bodypart(current_zone)
affected?.update_limb_efficiency()
if(amount >= 10)
var/damage_side_effect = CEILING(amount/2, 1)
if(damage_side_effect >= 1)
//owner.flash_pain(damage_side_effect*4)
owner.adjust_eye_blur(damage_side_effect)
owner.adjust_confusion(damage_side_effect)
switch(rand(1,3))
if(1)
owner.stuttering += damage_side_effect
if(2)
owner.slurring += damage_side_effect
if(3)
owner.cultslurring += damage_side_effect
owner.CombatKnockdown(damage_side_effect*2, damage_side_effect, (damage_side_effect >= 5 ? damage_side_effect : null), damage_side_effect >= 5)
if(!is_failing())
REMOVE_TRAIT(owner, TRAIT_KNOCKEDOUT, CRIT_HEALTH_TRAIT)

if(mess && !silent)
to_chat(owner, mess)

if(organ_flags & ORGAN_LIMB_SUPPORTER)
var/obj/item/bodypart/affected = owner.get_bodypart(current_zone)
affected?.update_limb_efficiency()

if(amount >= 10)
var/damage_side_effect = CEILING(amount/2, 1)
if(damage_side_effect >= 1)
//owner.flash_pain(damage_side_effect*4)
owner.adjust_eye_blur(damage_side_effect)
owner.adjust_confusion(damage_side_effect)
switch(rand(1,3))
if(1)
owner.stuttering += damage_side_effect
if(2)
owner.slurring += damage_side_effect
if(3)
owner.cultslurring += damage_side_effect
owner.CombatKnockdown(damage_side_effect*2, damage_side_effect, (damage_side_effect >= 5 ? damage_side_effect : null), damage_side_effect >= 5)

if(!is_failing())
REMOVE_TRAIT(owner, TRAIT_KNOCKEDOUT, CRIT_HEALTH_TRAIT)

if(damage >= 60)
owner.add_stress(/datum/stress_event/brain_damage)
else
Expand Down
Loading