Adds an universal object health system. (#21266)

https://www.youtube.com/watch?v=ZpUYjpKg9KY

As per title. The goal is to add health to most objects in the game and
thus allow them to be dynamically destructible, while also avoiding
shitcode like each structure having its own snowflake health update
proc.

---------

Signed-off-by: Matt Atlas <mattiathebest2000@hotmail.it>
Co-authored-by: Matt Atlas <liermattia@gmail.com>
Co-authored-by: SleepyGemmy <99297919+SleepyGemmy@users.noreply.github.com>
This commit is contained in:
Matt Atlas
2026-04-16 23:22:08 +00:00
committed by GitHub
co-authored by Matt Atlas SleepyGemmy
parent 1d2871729f
commit d5931c5ffe
213 changed files with 1448 additions and 1424 deletions
@@ -4,50 +4,47 @@
. += FONT_SMALL(SPAN_NOTICE("It contains the following hardware:"))
for(var/obj/CH in get_all_components())
. += FONT_SMALL(SPAN_NOTICE(" - [capitalize_first_letters(CH.name)]"))
if(damage > broken_damage)
if(health <= broken_damage)
. += SPAN_DANGER("It is heavily damaged!")
else if(damage)
else if(health <= maxhealth)
. += SPAN_WARNING("It is damaged.")
/obj/item/modular_computer/proc/break_apart(msg = TRUE)
if(msg)
visible_message(SPAN_WARNING("\The [src] breaks apart!"))
/obj/item/modular_computer/add_damage(damage, damage_flags, damage_type, armor_penetration, obj/weapon)
. = ..()
var/component_probability = 0
switch(damage_type)
if(DAMAGE_BRUTE)
component_probability = damage / 2
if(DAMAGE_BURN)
component_probability = damage / 1.5
if(component_probability)
for(var/obj/item/computer_hardware/H in get_all_components())
if(prob(component_probability))
H.take_damage(round(damage / 2))
update_icon()
/obj/item/modular_computer/on_death()
visible_message(SPAN_WARNING("\The [src] breaks apart!"))
new /obj/item/stack/material/steel(get_turf(src), round(steel_sheet_cost/2))
for(var/obj/item/computer_hardware/H in get_all_components())
uninstall_component(null, H)
H.forceMove(get_turf(src))
if(prob(25))
H.take_damage(rand(10, 30))
qdel(src)
/obj/item/modular_computer/proc/take_damage(var/amount, var/component_probability, var/damage_casing = TRUE, var/randomize = TRUE, msg=TRUE)
if(randomize)
// 75%-125%, rand() works with integers, apparently.
amount *= (rand(75, 125) / 100.0)
amount = round(amount)
if(damage_casing)
damage += amount
damage = between(0, damage, max_damage)
if(component_probability)
for(var/obj/item/computer_hardware/H in get_all_components())
if(prob(component_probability))
H.take_damage(round(amount / 2))
if(damage >= max_damage)
break_apart(msg)
update_icon()
. = ..()
// Stronger explosions cause serious damage to internal components
// Minor explosions are mostly mitigitated by casing.
/obj/item/modular_computer/ex_act(var/severity)
take_damage(rand(125, 200) / severity, 30 / severity, msg = FALSE)
add_damage(rand(125, 200) / severity, 30 / severity)
// EMPs are similar to explosions, but don't cause physical damage to the casing. Instead they screw up the components
/obj/item/modular_computer/emp_act(severity)
. = ..()
take_damage(rand(100, 200) / severity, 50 / severity, FALSE)
add_damage(rand(100, 200) / severity, 50 / severity)
// "Stun" weapons can cause minor damage to components (short-circuits?)
// "Burn" damage is equally strong against internal components and exterior casing
@@ -57,10 +54,4 @@
if(. != BULLET_ACT_HIT)
return .
switch(hitting_projectile.damage_type)
if(DAMAGE_BRUTE)
take_damage(hitting_projectile.damage, hitting_projectile.damage / 2)
if(DAMAGE_PAIN)
take_damage(hitting_projectile.damage, hitting_projectile.damage / 3, 0)
if(DAMAGE_BURN)
take_damage(hitting_projectile.damage, hitting_projectile.damage / 1.5)
add_damage(hitting_projectile, hitting_projectile.damage_flags(), hitting_projectile.damage_type, hitting_projectile.armor_penetration)