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-17 01:22:08 +02:00
committed by GitHub
parent 1d2871729f
commit d5931c5ffe
213 changed files with 1448 additions and 1424 deletions
@@ -5,7 +5,7 @@
last_power_usage = 0
return FALSE
if(damage > broken_damage)
if(health <= broken_damage)
shutdown_computer()
return FALSE
@@ -41,7 +41,7 @@
else
enabled_services -= service
working = hard_drive && processor_unit && damage < broken_damage && computer_use_power()
working = hard_drive && processor_unit && health >= broken_damage && computer_use_power()
check_update_ui_need()
if(looping_sound && working && enabled && world.time > ambience_last_played_time + 30 SECONDS && prob(3))
@@ -168,7 +168,7 @@
icon_state = icon_state_unpowered
ClearOverlays()
if(damage >= broken_damage)
if(health <= broken_damage)
icon_state = icon_state_broken
AddOverlays("broken")
return
@@ -264,7 +264,7 @@
if(tesla_link)
tesla_link.enabled = TRUE
var/issynth = issilicon(user) // Robots and AIs get different activation messages.
if(damage > broken_damage)
if(health <= broken_damage)
if(issynth)
to_chat(user, SPAN_WARNING("You send an activation signal to \the [src], but it responds with an error code. It must be damaged."))
else
@@ -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)
@@ -311,14 +311,15 @@
to_chat(user, SPAN_WARNING("\The [attacking_item] is off."))
return TRUE
if(!damage)
if(health >= maxhealth)
to_chat(user, SPAN_WARNING("\The [src] does not require repairs."))
return TRUE
to_chat(user, SPAN_NOTICE("You begin repairing the damage to \the [src]..."))
playsound(get_turf(src), 'sound/items/Welder.ogg', 100, 1)
var/damage = maxhealth - health
if(WT.use(round(damage / 75)) && do_after(user, damage / 10, src, DO_REPAIR_CONSTRUCT))
damage = 0
health = maxhealth
to_chat(user, SPAN_NOTICE("You fully repair \the [src]."))
update_icon()
return TRUE
@@ -354,6 +355,15 @@
if(do_after(user, 1 SECONDS))
visible_message(SPAN_NOTICE("[user] slots \the [access_cable] into \the [src]."))
universal_port.insert_cable(access_cable, user)
if(user?.a_intent == I_HURT && maxhealth)
user.do_attack_animation(src)
user.setClickCooldown(DEFAULT_ATTACK_COOLDOWN)
visible_message(SPAN_DANGER("[user] [pick(attacking_item.attack_verb)] \the [src]!"))
add_damage(attacking_item.force, attacking_item.damage_flags(), attacking_item.damtype, attacking_item.armor_penetration, attacking_item)
playsound(user, 'sound/effects/metalhit.ogg', attacking_item.get_clamped_volume())
return TRUE
return ..()
/obj/item/modular_computer/mouse_drop_dragged(atom/over, mob/user, src_location, over_location, params)
@@ -3,6 +3,8 @@
/obj/item/modular_computer
name = "Modular Computer"
desc = DESC_PARENT
maxhealth = OBJECT_HEALTH_MEDIUM
should_use_health = TRUE
var/lexical_name = "computer"
/// Whether the computer is turned on.
@@ -94,13 +96,8 @@
var/power_has_failed = FALSE
var/is_holographic = FALSE
/// Damage of the chassis. If the chassis takes too much damage it will break apart.
/// Current damage level
var/damage = 0
/// Damage level at which the computer ceases to operate
var/broken_damage = 50
/// Damage level at which the computer breaks apart.
var/max_damage = 100
/// Important hardware (must be installed for computer to work)
/// CPU. Without it the computer won't run. Better CPUs can run more programs at once.
@@ -16,7 +16,7 @@
message_output_range = 1
max_hardware_size = 2
light_range = 3
max_damage = 50
maxhealth = OBJECT_HEALTH_VERY_LOW
broken_damage = 25
var/icon_state_closed = "laptop-closed"
@@ -43,7 +43,7 @@
..()
else
ClearOverlays()
if(damage >= broken_damage)
if(health <= broken_damage)
icon_state = icon_state_broken + "-closed"
else
icon_state = icon_state_closed
@@ -9,7 +9,7 @@
base_idle_power_usage = 5
base_active_power_usage = 25
max_hardware_size = 3
max_damage = 50
maxhealth = OBJECT_HEALTH_LOW
w_class = WEIGHT_CLASS_NORMAL
enrolled = DEVICE_PRIVATE
/// Thing that contains this computer. Used for silicon computers