From d8d87a3e8dc90b65a26242bc42dce9450f69ac5e Mon Sep 17 00:00:00 2001 From: Antoonij <42318445+Antoonij@users.noreply.github.com> Date: Fri, 15 Nov 2024 11:21:51 +0100 Subject: [PATCH] refactor: Unified Blood Adjust --- code/__DEFINES/dcs/signals.dm | 6 ++++++ code/datums/components/aura_healing.dm | 2 +- .../viruses/advance/symptoms/blood.dm | 2 +- code/datums/rituals.dm | 2 +- .../clockwork/clockwork_structures.dm | 2 +- code/game/gamemodes/cult/blood_magic.dm | 2 +- .../mob/living/carbon/human/species/diona.dm | 2 +- .../reagents/chemistry/reagents/medicine.dm | 5 +++-- .../reagents/chemistry/reagents/misc.dm | 3 ++- code/modules/surgery/organs/blood.dm | 21 +++++++++++++++++-- 10 files changed, 36 insertions(+), 11 deletions(-) diff --git a/code/__DEFINES/dcs/signals.dm b/code/__DEFINES/dcs/signals.dm index aa521e47314..9b25828c7e7 100644 --- a/code/__DEFINES/dcs/signals.dm +++ b/code/__DEFINES/dcs/signals.dm @@ -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) diff --git a/code/datums/components/aura_healing.dm b/code/datums/components/aura_healing.dm index 42b136bb041..29f039f51d7 100644 --- a/code/datums/components/aura_healing.dm +++ b/code/datums/components/aura_healing.dm @@ -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)) diff --git a/code/datums/diseases/viruses/advance/symptoms/blood.dm b/code/datums/diseases/viruses/advance/symptoms/blood.dm index 1369d0f640b..74ac811d9b5 100644 --- a/code/datums/diseases/viruses/advance/symptoms/blood.dm +++ b/code/datums/diseases/viruses/advance/symptoms/blood.dm @@ -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) diff --git a/code/datums/rituals.dm b/code/datums/rituals.dm index d13dc144be3..c48beea72f1 100644 --- a/code/datums/rituals.dm +++ b/code/datums/rituals.dm @@ -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) diff --git a/code/game/gamemodes/clockwork/clockwork_structures.dm b/code/game/gamemodes/clockwork/clockwork_structures.dm index cefd9609788..b03ff5ed786 100644 --- a/code/game/gamemodes/clockwork/clockwork_structures.dm +++ b/code/game/gamemodes/clockwork/clockwork_structures.dm @@ -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() diff --git a/code/game/gamemodes/cult/blood_magic.dm b/code/game/gamemodes/cult/blood_magic.dm index 51375cb0f5a..ad4bc039e56 100644 --- a/code/game/gamemodes/cult/blood_magic.dm +++ b/code/game/gamemodes/cult/blood_magic.dm @@ -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, "You use the last of your charges to restore what blood you could, and the spell dissipates!") uses = 0 return ..() diff --git a/code/modules/mob/living/carbon/human/species/diona.dm b/code/modules/mob/living/carbon/human/species/diona.dm index 12c74470e67..2b88bda2050 100644 --- a/code/modules/mob/living/carbon/human/species/diona.dm +++ b/code/modules/mob/living/carbon/human/species/diona.dm @@ -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) diff --git a/code/modules/reagents/chemistry/reagents/medicine.dm b/code/modules/reagents/chemistry/reagents/medicine.dm index 6cd40966d6d..02a1f3e2441 100644 --- a/code/modules/reagents/chemistry/reagents/medicine.dm +++ b/code/modules/reagents/chemistry/reagents/medicine.dm @@ -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 @@ -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) diff --git a/code/modules/reagents/chemistry/reagents/misc.dm b/code/modules/reagents/chemistry/reagents/misc.dm index 6380e5ef680..6e26bc80280 100644 --- a/code/modules/reagents/chemistry/reagents/misc.dm +++ b/code/modules/reagents/chemistry/reagents/misc.dm @@ -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) diff --git a/code/modules/surgery/organs/blood.dm b/code/modules/surgery/organs/blood.dm index bc7b2659c91..689cc6663d5 100644 --- a/code/modules/surgery/organs/blood.dm +++ b/code/modules/surgery/organs/blood.dm @@ -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 @@ -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) + return FALSE + + blood_volume = max(round(blood_volume - amount, DAMAGE_PRECISION), 0) + SEND_SIGNAL(src, COMSIG_LIVING_BLOOD_ADJUSTED, amount, 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) @@ -160,7 +177,7 @@ if(!blood_id) return 0 - blood_volume -= amount + adjustBloodLoss(amount) var/list/blood_data = get_blood_data(blood_id)