Skip to content

Commit

Permalink
refactor: Unified Blood Adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoonij authored Nov 15, 2024
1 parent b5a1273 commit d8d87a3
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 11 deletions.
6 changes: 6 additions & 0 deletions code/__DEFINES/dcs/signals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,12 @@
#define COMSIG_LIVING_CAN_TRACK "mob_cantrack"
#define COMPONENT_CANT_TRACK (1<<0)

/// Source: /mob/living/adjustBloodLoss(amount)
#define COMSIG_LIVING_BLOOD_ADJUST "living_blood_adjust"
#define COMPONENT_PREVENT_BLOODLOSS (1<<0)
/// Source: /mob/living/adjustBloodLoss(amount)
#define COMSIG_LIVING_BLOOD_ADJUSTED "living_blood_adjusted"

/// From /mob/add_language() (language_name)
#define COMSIG_MOB_LANGUAGE_ADD "mob_language_add"
/// From /mob/remove_language() (language_name)
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/aura_healing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
animal_candidate.adjustHealth(-simple_heal * seconds_per_tick, updating_health = FALSE)

if(!HAS_TRAIT(candidate, TRAIT_NO_BLOOD_RESTORE) && candidate.blood_volume < BLOOD_VOLUME_NORMAL)
candidate.blood_volume += blood_heal * seconds_per_tick
candidate.adjustBloodLoss(-(blood_heal * seconds_per_tick))

var/external_organ_heal_done = FALSE
if(ishuman(candidate))
Expand Down
2 changes: 1 addition & 1 deletion code/datums/diseases/viruses/advance/symptoms/blood.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ Bonus
if(prob(10))
to_chat(affected, span_notice("You can hear own heartbeat"))
if(!HAS_TRAIT(affected, TRAIT_NO_BLOOD) && !HAS_TRAIT(affected, TRAIT_NO_BLOOD_RESTORE) && affected.blood_volume < BLOOD_VOLUME_NORMAL)
affected.blood_volume += 0.4
affected.adjustBloodLoss(-0.4)
affected.adjust_nutrition(-2)

2 changes: 1 addition & 1 deletion code/datums/rituals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@
LAZYADD(invokers, invoker)

for(var/mob/living/carbon/human/summoner as anything in invokers)
summoner.blood_volume -= (summoner.blood_volume * 0.20)
summoner.adjustBloodLoss(summoner.blood_volume * 0.20)
summoner.apply_damage(25, def_zone = pick(BODY_ZONE_L_ARM, BODY_ZONE_R_ARM))

human.forceMove(ritual_object)
Expand Down
2 changes: 1 addition & 1 deletion code/game/gamemodes/clockwork/clockwork_structures.dm
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
M.adjustHealth(-8)

if(ishuman(L) && !HAS_TRAIT(L, TRAIT_NO_BLOOD_RESTORE) && L.blood_volume < BLOOD_VOLUME_NORMAL)
L.blood_volume += 1
L.adjustBloodLoss(-1)


/obj/structure/clockwork/functional/beacon/Destroy()
Expand Down
2 changes: 1 addition & 1 deletion code/game/gamemodes/cult/blood_magic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@
if(H.blood_volume < BLOOD_VOLUME_SAFE)
var/restore_blood = BLOOD_VOLUME_SAFE - H.blood_volume
if(uses * 2 < restore_blood)
H.blood_volume += uses * 2
H.adjustBloodLoss(-(uses * 2))
to_chat(user, "<span class='danger'>You use the last of your charges to restore what blood you could, and the spell dissipates!</span>")
uses = 0
return ..()
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/carbon/human/species/diona.dm
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
if(update)
H.updatehealth()
if(H.blood_volume < BLOOD_VOLUME_NORMAL)
H.blood_volume += 0.5
H.adjustBloodLoss(-0.5)

if(!is_vamp && H.nutrition < NUTRITION_LEVEL_STARVING + 50)
H.adjustBruteLoss(2)
Expand Down
5 changes: 3 additions & 2 deletions code/modules/reagents/chemistry/reagents/medicine.dm
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@
var/mob/living/carbon/human/H = M
//do not restore blood on things with no blood by nature.
if(!HAS_TRAIT(H, TRAIT_NO_BLOOD) && !HAS_TRAIT(H, TRAIT_NO_BLOOD_RESTORE) && H.blood_volume < BLOOD_VOLUME_NORMAL)
H.blood_volume += 1
H.adjustBloodLoss(-1)

return ..() | update_flags

/datum/reagent/medicine/synthflesh
Expand Down Expand Up @@ -1428,7 +1429,7 @@
for(var/obj/item/organ/internal/I as anything in M.internal_organs) // 56 healing to all internal organs.
I.heal_internal_damage(8)
if(!HAS_TRAIT(H, TRAIT_NO_BLOOD_RESTORE) && H.blood_volume < BLOOD_VOLUME_NORMAL * 0.9)// If below 90% blood, regenerate 210 units total
H.blood_volume += 30
H.adjustBloodLoss(-30)
for(var/datum/disease/critical/heart_failure/HF in H.diseases)
HF.cure() //Won't fix a stopped heart, but it will sure fix a critical one. Shock is not fixed as healing will fix it
if(M.health < 40)
Expand Down
3 changes: 2 additions & 1 deletion code/modules/reagents/chemistry/reagents/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@
if(ishuman(M))
var/mob/living/carbon/human/H = M
if(!HAS_TRAIT(H, TRAIT_NO_BLOOD) && !HAS_TRAIT(H, TRAIT_NO_BLOOD_RESTORE) && H.blood_volume < BLOOD_VOLUME_NORMAL)
H.blood_volume += 0.8
H.adjustBloodLoss(-0.8)

return ..()

/datum/reagent/iron/reaction_mob(mob/living/M, method=REAGENT_TOUCH, volume)
Expand Down
21 changes: 19 additions & 2 deletions code/modules/surgery/organs/blood.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

if(bodytemperature >= TCRYO && !HAS_TRAIT(src, TRAIT_NO_CLONE)) //cryosleep or husked people do not pump the blood.
if(!HAS_TRAIT(src, TRAIT_NO_BLOOD_RESTORE) && blood_volume < BLOOD_VOLUME_NORMAL)
blood_volume += 0.1 // regenerate blood VERY slowly
adjustBloodLoss(-0.1) // regenerate blood VERY slowly


//Effects of bloodloss
Expand Down Expand Up @@ -134,6 +134,23 @@
return .
blood_reagent.reaction_turf(loc, amt * EXOTIC_BLEED_MULTIPLIER, dna.species.blood_color)

/mob/living/proc/adjustBloodLoss(amount = 0)
if(HAS_TRAIT(src, TRAIT_NO_BLOOD))
return FALSE

if(SEND_SIGNAL(src, COMSIG_LIVING_BLOOD_ADJUST, amount, bleed_mode_affect) & COMPONENT_PREVENT_BLOODLOSS)

Check failure on line 141 in code/modules/surgery/organs/blood.dm

View workflow job for this annotation

GitHub Actions / Run Linters

undefined var: "bleed_mode_affect"
return FALSE

blood_volume = max(round(blood_volume - amount, DAMAGE_PRECISION), 0)
SEND_SIGNAL(src, COMSIG_LIVING_BLOOD_ADJUSTED, amount, bleed_mode_affect)

Check failure on line 145 in code/modules/surgery/organs/blood.dm

View workflow job for this annotation

GitHub Actions / Run Linters

undefined var: "bleed_mode_affect"

return TRUE

/mob/living/carbon/human/adjustBloodLoss(amount = 0, bleed_mode_affect = FALSE)
if(bleed_mode_affect)
amount *= physiology.bleed_mod

return ..(amount)

/mob/living/proc/restore_blood()
blood_volume = initial(blood_volume)
Expand All @@ -160,7 +177,7 @@
if(!blood_id)
return 0

blood_volume -= amount
adjustBloodLoss(amount)

var/list/blood_data = get_blood_data(blood_id)

Expand Down

0 comments on commit d8d87a3

Please sign in to comment.