Skip to content

Commit

Permalink
Fix bug with damage (#407)
Browse files Browse the repository at this point in the history
* Fix bug with damage

* make it compile

* this is better

* i guess im the minority

* woop

* revert mining tool

* real fix + unit testing

* mech drill fix
  • Loading branch information
Kapu1178 authored Jul 8, 2023
1 parent 68cc1e5 commit e026424
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 10 deletions.
5 changes: 5 additions & 0 deletions code/__DEFINES/stat.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#define HEALTH_THRESHOLD_FULLCRIT -100 //! Hard crit
#define HEALTH_THRESHOLD_DEAD -200

/// The amount of damage a mob can take past that which would kill it, per damage type.
#define HEALTH_OVERKILL_DAMAGE_PER_TYPE 0
/// The maximum amount of damage a mob can take per damage type (carbon brute/burn excluded). This will always result in just enough to kill you if overkill is 0.
#define HEALTH_LOSS_PER_TYPE_CAP(mob) (mob.maxHealth + ((-1 * HEALTH_THRESHOLD_DEAD) + HEALTH_OVERKILL_DAMAGE_PER_TYPE))

#define HEALTH_THRESHOLD_NEARDEATH -150 //Not used mechanically, but to determine if someone is so close to death they hear the other side

//Maximum healthiness an individual can have
Expand Down
4 changes: 2 additions & 2 deletions code/modules/client/verbs/suicide.dm
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
suicide_log()

//put em at -175
adjustOxyLoss(max(maxHealth * 2 - getToxLoss() - getFireLoss() - getBruteLoss() - getOxyLoss(), 0))
adjustOxyLoss(max(HEALTH_LOSS_PER_TYPE_CAP(src) - getToxLoss() - getFireLoss() - getBruteLoss() - getOxyLoss(), 0))
death(FALSE)
ghostize(FALSE) // Disallows reentering body and disassociates mind

Expand All @@ -162,7 +162,7 @@
suicide_log()

//put em at -175
adjustOxyLoss(max(maxHealth * 2 - getToxLoss() - getFireLoss() - getBruteLoss() - getOxyLoss(), 0))
adjustOxyLoss(max(HEALTH_LOSS_PER_TYPE_CAP(src) - getToxLoss() - getFireLoss() - getBruteLoss() - getOxyLoss(), 0))
death(FALSE)
ghostize(FALSE) // Disallows reentering body and disassociates mind

Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/basic/health_adjustment.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/mob/living/basic/proc/adjust_health(amount, updating_health = TRUE, forced = FALSE)
. = FALSE
if(forced || !(status_flags & GODMODE))
bruteloss = round(clamp(bruteloss + amount, 0, maxHealth * 2), DAMAGE_PRECISION)
bruteloss = round(clamp(bruteloss + amount, 0, HEALTH_LOSS_PER_TYPE_CAP(src)), DAMAGE_PRECISION)
if(updating_health)
updatehealth()
. = amount
Expand Down
10 changes: 5 additions & 5 deletions code/modules/mob/living/damage_procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
/mob/living/proc/adjustBruteLoss(amount, updating_health = TRUE, forced = FALSE, required_status)
if(!forced && (status_flags & GODMODE))
return FALSE
bruteloss = clamp((bruteloss + (amount * CONFIG_GET(number/damage_multiplier))), 0, maxHealth * 2)
bruteloss = clamp((bruteloss + (amount * CONFIG_GET(number/damage_multiplier))), 0, HEALTH_LOSS_PER_TYPE_CAP(src))
if(updating_health)
updatehealth()
return amount
Expand All @@ -180,7 +180,7 @@
if(!forced && (status_flags & GODMODE))
return
. = oxyloss
oxyloss = clamp((oxyloss + (amount * CONFIG_GET(number/damage_multiplier))), 0, maxHealth * 2)
oxyloss = clamp((oxyloss + (amount * CONFIG_GET(number/damage_multiplier))), 0, HEALTH_LOSS_PER_TYPE_CAP(src))
if(updating_health)
updatehealth()

Expand All @@ -200,7 +200,7 @@
/mob/living/proc/adjustToxLoss(amount, updating_health = TRUE, forced = FALSE)
if(!forced && (status_flags & GODMODE))
return FALSE
toxloss = clamp((toxloss + (amount * CONFIG_GET(number/damage_multiplier))), 0, maxHealth * 2)
toxloss = clamp((toxloss + (amount * CONFIG_GET(number/damage_multiplier))), 0, HEALTH_LOSS_PER_TYPE_CAP(src))
if(updating_health)
updatehealth()
return amount
Expand All @@ -219,7 +219,7 @@
/mob/living/proc/adjustFireLoss(amount, updating_health = TRUE, forced = FALSE)
if(!forced && (status_flags & GODMODE))
return FALSE
fireloss = clamp((fireloss + (amount * CONFIG_GET(number/damage_multiplier))), 0, maxHealth * 2)
fireloss = clamp((fireloss + (amount * CONFIG_GET(number/damage_multiplier))), 0, HEALTH_LOSS_PER_TYPE_CAP(src))
if(updating_health)
updatehealth()
return amount
Expand All @@ -230,7 +230,7 @@
/mob/living/proc/adjustCloneLoss(amount, updating_health = TRUE, forced = FALSE)
if(!forced && ( (status_flags & GODMODE) || HAS_TRAIT(src, TRAIT_NOCLONELOSS)) )
return FALSE
cloneloss = clamp((cloneloss + (amount * CONFIG_GET(number/damage_multiplier))), 0, maxHealth * 2)
cloneloss = clamp((cloneloss + (amount * CONFIG_GET(number/damage_multiplier))), 0, HEALTH_LOSS_PER_TYPE_CAP(src))
if(updating_health)
updatehealth()
return amount
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/simple_animal/damage_procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/mob/living/simple_animal/proc/adjustHealth(amount, updating_health = TRUE, forced = FALSE)
. = FALSE
if(forced || !(status_flags & GODMODE))
bruteloss = round(clamp(bruteloss + amount, 0, maxHealth * 2), DAMAGE_PRECISION)
bruteloss = round(clamp(bruteloss + amount, 0, HEALTH_LOSS_PER_TYPE_CAP(src)), DAMAGE_PRECISION)
if(updating_health)
updatehealth()
. = amount
Expand Down
17 changes: 17 additions & 0 deletions code/modules/unit_tests/combat.dm
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,20 @@
TEST_ASSERT(pre_attack_hit, "Pre-attack signal was not fired")
TEST_ASSERT(attack_hit, "Attack signal was not fired")
TEST_ASSERT(post_attack_hit, "Post-attack signal was not fired")

/datum/unit_test/non_standard_damage/Run()
var/mob/living/carbon/human/man = allocate(/mob/living/carbon/human)

var/old_dam
man.adjustOxyLoss(HEALTH_LOSS_PER_TYPE_CAP(man))
old_dam = man.getOxyLoss()
TEST_ASSERT(man.stat == DEAD, "Victim did not die when taking [HEALTH_LOSS_PER_TYPE_CAP(man)] oxygen damage.")
man.adjustOxyLoss(1)
TEST_ASSERT(man.getOxyLoss() == old_dam, "Victim took oxygen damage past the cap.")
man.revive(TRUE, TRUE)

man.adjustToxLoss(HEALTH_LOSS_PER_TYPE_CAP(man))
old_dam = man.getOxyLoss()
TEST_ASSERT(man.stat == DEAD, "Victim did not die when taking [HEALTH_LOSS_PER_TYPE_CAP(man)] toxin damage.")
man.adjustToxLoss(1)
TEST_ASSERT(man.getOxyLoss() == old_dam, "Victim took toxin damage past the cap.")
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
target.visible_message(span_danger("[chassis] is drilling [target] with [src]!"), \
span_userdanger("[chassis] is drilling you with [src]!"))
log_combat(user, target, "drilled", "[name]", "Combat mode: [user.combat_mode ? "On" : "Off"])(DAMTYPE: [uppertext(damtype)])")
if(target.stat == DEAD && target.getBruteLoss() >= (target.maxHealth * 2))
if(target.stat == DEAD && target.getBruteLoss() >= HEALTH_LOSS_PER_TYPE_CAP(target))
log_combat(user, target, "gibbed", name)
if(LAZYLEN(target.butcher_results) || LAZYLEN(target.guaranteed_butcher_results))
var/datum/component/butchering/butchering = src.GetComponent(/datum/component/butchering)
Expand Down

0 comments on commit e026424

Please sign in to comment.