Skip to content

Fix Brain Math #20711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
69 changes: 50 additions & 19 deletions code/modules/organs/internal/brain.dm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,39 @@
var/healed_threshold = 1
var/oxygen_reserve = 6

//brain damage speed modifiers. All except safe include modifiers for "Stabilized with Inaprovaline" vs Not Stabilized.
//damage per second is this value times deltaTime, such that no matter frametime, this will be your baseline damage.
//it's also directly 1:1 with your brain's numerical healthbar. If your brain has 200hp, consider that it has "200 seconds" of budget.

//think of it like, "If a perfectly healthy crewman suddenly has a heart attack that cuts off 100% of blood flow to the brain", that crewman
//will lose 2s of his 200s budget, every second. Keeping this in mind, it might come up in testing that we'll want to look at tweaking these numbers for some
//desired time budget that feels right. Setting the BDPS to 0.5 will turn the 200s budget into 400s. While setting it to 2 will make it a 100s budget.
var/brain_damage_per_second = 1

//85% blood volume and up
//this one is actually used for the passive healing rate mainly.
var/safe_damage_modifier = 1

//70% to 85%
var/okay_damage_modifier = 1
var/okay_stabilized_mod = 0.3
var/okay_unstable_mod = 0.6

//60% to 70%
var/bad_damage_modifier = 1
var/bad_stabilized_mod = 0.4
var/bad_unstable_mod = 0.8

//30% to 60%
var/crit_damage_modifier = 1
var/crit_stabilized_mod = 0.6
var/crit_unstable_mod = 1

//0% to 30%
var/dying_damage_modifier = 2
var/dying_stabilized_mod = 0.8
var/dying_unstable_mod = 1

Comment on lines +30 to +62
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaving this for someone better versed in medical code to review proper, but I'd suggest turning these comments to DMDocs. The documentation section in STYLE.md may be a useful reference.

/obj/item/organ/internal/brain/Initialize(mapload)
. = ..()
if(species)
Expand Down Expand Up @@ -82,7 +115,7 @@
..()
damage_threshold_value = round(max_damage / damage_threshold_count)

/obj/item/organ/internal/brain/process()
/obj/item/organ/internal/brain/process(seconds_per_tick)
if(owner)
if(damage > (max_damage * 0.75) && healed_threshold)
handle_severe_brain_damage()
Expand All @@ -107,44 +140,42 @@
owner.Paralyse(10)

var/can_heal = (damage && damage < max_damage && (damage % damage_threshold_value || owner.chem_effects[CE_BRAIN_REGEN] || (!past_damage_threshold(3) && owner.chem_effects[CE_STABLE]))) && (!(owner.chem_effects[CE_NEUROTOXIC]) || owner.chem_effects[CE_ANTITOXIN])
var/damprob
var/brain_regen_amount = owner.chem_effects[CE_BRAIN_REGEN] / 10
var/dammod
var/brain_regen_amount = owner.chem_effects[CE_BRAIN_REGEN] * seconds_per_tick
var/brain_damage_amount = brain_damage_per_second * seconds_per_tick
//Effects of bloodloss
switch(blood_volume)
if(BLOOD_VOLUME_SAFE to INFINITY)
if(can_heal && owner.chem_effects[CE_BRAIN_REGEN])
damage = max(damage - brain_regen_amount, 0)
damage = max(damage - brain_regen_amount, 0) * safe_damage_modifier
else if(can_heal)
damage = max(damage-1, 0)
damage = max(damage - brain_damage_amount, 0) * safe_damage_modifier
if(BLOOD_VOLUME_OKAY to BLOOD_VOLUME_SAFE)
owner.notify_message(SPAN_WARNING("You feel a bit [pick("lightheaded","dizzy","pale")]..."), rand(20 SECONDS, 40 SECONDS), key = "blood_volume_okay")
damprob = owner.chem_effects[CE_STABLE] ? 30 : 60
if(!past_damage_threshold(2) && prob(damprob))
take_internal_damage(1)
dammod = owner.chem_effects[CE_STABLE] ? okay_stabilized_mod : okay_unstable_mod
if(!past_damage_threshold(2))
take_internal_damage(brain_damage_amount * dammod * okay_damage_modifier)
if(BLOOD_VOLUME_BAD to BLOOD_VOLUME_OKAY)
owner.notify_message(SPAN_WARNING("You feel [pick("weak","disoriented","faint","cold")]."), rand(20 SECONDS, 40 SECONDS), key = "blood_volume_bad")
owner.eye_blurry = max(owner.eye_blurry,6)
damprob = owner.chem_effects[CE_STABLE] ? 40 : 80
if(!past_damage_threshold(4) && prob(damprob))
take_internal_damage(1)
dammod = owner.chem_effects[CE_STABLE] ? bad_stabilized_mod : bad_unstable_mod
if(!past_damage_threshold(4))
take_internal_damage(brain_damage_amount * dammod * bad_damage_modifier)
if(!owner.paralysis && prob(10))
owner.Paralyse(rand(1,3))
if(BLOOD_VOLUME_SURVIVE to BLOOD_VOLUME_BAD)
owner.notify_message(SPAN_WARNING("You feel <b>extremely</b> [pick("cold","woozy","faint","weak","confused","tired","lethargic")]."), rand(20 SECONDS, 40 SECONDS), key = "blood_volume_survive")
owner.eye_blurry = max(owner.eye_blurry,6)
damprob = owner.chem_effects[CE_STABLE] ? 60 : 100
if(!past_damage_threshold(6) && prob(damprob))
take_internal_damage(1)
dammod = owner.chem_effects[CE_STABLE] ? crit_stabilized_mod : crit_unstable_mod
if(!past_damage_threshold(6))
take_internal_damage(brain_damage_amount * dammod * crit_damage_modifier)
if(!owner.paralysis && prob(15))
owner.Paralyse(rand(3, 5))
if(-(INFINITY) to BLOOD_VOLUME_SURVIVE) // Also see heart.dm, being below this point puts you into cardiac arrest.
owner.notify_message(SPAN_DANGER("You feel like death is imminent."), rand(20 SECONDS, 40 SECONDS), key = "blood_volume_dying")
owner.eye_blurry = max(owner.eye_blurry,6)
damprob = owner.chem_effects[CE_STABLE] ? 80 : 100
if(prob(damprob))
take_internal_damage(1)
if(prob(damprob))
take_internal_damage(1)
dammod = owner.chem_effects[CE_STABLE] ? dying_stabilized_mod : dying_unstable_mod
take_internal_damage(brain_damage_amount * dammod * dying_damage_modifier)
..()

/obj/item/organ/internal/brain/proc/handle_severe_brain_damage()
Expand Down
58 changes: 58 additions & 0 deletions html/changelogs/hellfirejag-fixbraindamageinconsistency.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
################################
# Example Changelog File
#
# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb.
#
# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.)
# When it is, any changes listed below will disappear.
#
# Valid Prefixes:
# bugfix
# - (fixes bugs)
# wip
# - (work in progress)
# qol
# - (quality of life)
# soundadd
# - (adds a sound)
# sounddel
# - (removes a sound)
# rscadd
# - (adds a feature)
# rscdel
# - (removes a feature)
# imageadd
# - (adds an image or sprite)
# imagedel
# - (removes an image or sprite)
# spellcheck
# - (fixes spelling or grammar)
# experiment
# - (experimental change)
# balance
# - (balance changes)
# code_imp
# - (misc internal code change)
# refactor
# - (refactors code)
# config
# - (makes a change to the config files)
# admin
# - (makes changes to administrator tools)
# server
# - (miscellaneous changes to server)
#################################

# Your name.
author: hellfirejag

# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again.
delete-after: True

# Any changes you've made. See valid prefix list above.
# INDENT WITH TWO SPACES. NOT TABS. SPACES.
# SCREW THIS UP AND IT WON'T WORK.
# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit.
# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog.
changes:
- bugfix: "Fixed brain damage being inconsistent under high or low server load."