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
@@ -5,8 +5,7 @@
icon_state = "ammo_loader"
density = TRUE
anchored = TRUE
var/damage = 0
var/max_damage = 1000
maxhealth = 1000
var/obj/machinery/ship_weapon/weapon
var/weapon_id //Used to connect weapon systems to the relevant ammunition loader.
@@ -41,14 +40,6 @@
if(3)
add_damage(10)
/obj/machinery/ammunition_loader/proc/add_damage(var/amount)
damage = max(0, min(damage + amount, max_damage))
update_damage()
/obj/machinery/ammunition_loader/proc/update_damage()
if(damage >= max_damage)
qdel(src)
/obj/machinery/ammunition_loader/attackby(obj/item/attacking_item, mob/user)
if(isliving(user))
var/mob/living/carbon/human/H = user
+21 -24
View File
@@ -6,8 +6,7 @@
active_power_usage = 50000
anchored = TRUE
density = TRUE
var/damage = 0
var/max_damage = 1000
health = 1000
var/heavy_firing_sound = 'sound/weapons/gunshot/ship_weapons/120mm_mortar.ogg' //The sound in the immediate firing area. Very loud.
var/light_firing_sound = 'sound/effects/explosionfar.ogg' //The sound played when you're a few walls away. Kind of loud.
var/projectile_type = /obj/projectile/ship_ammo
@@ -30,25 +29,28 @@
var/list/obj/structure/ship_weapon_dummy/connected_dummies = list()
var/obj/structure/ship_weapon_dummy/barrel
/obj/machinery/ship_weapon/condition_hints(mob/user, distance, is_adjacent)
. += ..()
var/ratio = (damage / max_damage) * 100
/obj/machinery/ship_weapon/Initialize(mapload)
. = ..()
AddComponent(/datum/component/armor, list(MELEE = ARMOR_MELEE_MAJOR, BULLET = ARMOR_BALLISTIC_RIFLE, LASER = ARMOR_LASER_MAJOR))
/obj/machinery/ship_weapon/get_damage_condition_hints(mob/user, distance, is_adjacent)
var/ratio = (health / maxhealth) * 100
switch(ratio)
if(1 to 10)
. += SPAN_NOTICE("It looks to be in tip top shape apart from a few minor scratches and dings.")
. = SPAN_NOTICE("It looks to be in tip top shape apart from a few minor scratches and dings.")
if(10 to 20)
. += SPAN_ALERT("It has some kinks and bends here and there.")
. = SPAN_ALERT("It has some kinks and bends here and there.")
if(20 to 40)
. += SPAN_ALERT("It has a few holes through which you can see some machinery.")
. = SPAN_ALERT("It has a few holes through which you can see some machinery.")
if(40 to 60)
. += SPAN_WARNING("Some fairly important parts are missing... but it should work anyway.")
. = SPAN_WARNING("Some fairly important parts are missing... but it should work anyway.")
if(60 to 80)
. += SPAN_WARNING("It needs repairs direly. Both aiming and firing components are missing or broken. It has a lot of holes, too. It definitely wouldn't \
. = SPAN_WARNING("It needs repairs direly. Both aiming and firing components are missing or broken. It has a lot of holes, too. It definitely wouldn't \
pass inspection.")
if(90 to 100)
. += SPAN_DANGER("It's falling apart! Just touching it might make the whole thing collapse!")
. = SPAN_DANGER("It's falling apart! Just touching it might make the whole thing collapse!")
else //At roundstart, weapons start with 0 damage, so it'd be 0 / 1000 * 100 -> 0
. += SPAN_NOTICE("It looks to be in tip top shape and not damaged at all.")
. = SPAN_NOTICE("It looks to be in tip top shape and not damaged at all.")
/obj/machinery/ship_weapon/mechanics_hints(mob/user, distance, is_adjacent)
. += ..()
@@ -58,9 +60,7 @@
/obj/machinery/ship_weapon/assembly_hints(mob/user, distance, is_adjacent)
. += ..()
var/ratio = (damage / max_damage) * 100
if(ratio > 0)
. += "The damage can be repaired with a <b>welder</b>, but given the size of \the [src] it will take a lot of time and welding fuel."
. += "If damaged, it can be repaired with a <b>welder</b>, but given the size of \the [src] it will take a lot of time and welding fuel."
/obj/machinery/ship_weapon/feedback_hints(mob/user, distance, is_adjacent)
. += ..()
@@ -105,13 +105,10 @@
if(3)
add_damage(10)
/obj/machinery/ship_weapon/proc/add_damage(var/amount)
damage = max(0, min(damage + amount, max_damage))
update_damage()
/obj/machinery/ship_weapon/proc/update_damage()
if(damage >= max_damage)
qdel(src)
/obj/machinery/ship_weapon/on_death(damage, damage_flags, damage_type, armor_penetration, obj/weapon)
visible_message(FONT_LARGE(SPAN_DANGER("\The [src] explodes in a shower of sparks and fire!")))
explosion(get_turf(src), 5, 7, 9)
. = ..()
/obj/machinery/ship_weapon/attackby(obj/item/attacking_item, mob/user)
if(istype(attacking_item, /obj/item/multitool))
@@ -127,13 +124,13 @@
weapon_id = new_id
to_chat(user, SPAN_NOTICE("With some finicking, you change the identification tag to <b>[new_id]</b>."))
return TRUE
if(istype(attacking_item, /obj/item/weldingtool) && damage)
if(istype(attacking_item, /obj/item/weldingtool) && (health < maxhealth))
var/obj/item/weldingtool/WT = attacking_item
if(WT.get_fuel() >= 20)
user.visible_message(SPAN_NOTICE("[user] starts slowly welding kinks and holes in \the [src] back to working shape..."),
SPAN_NOTICE("You start welding kinks and holes back to working shape. This'll take a long while..."))
if(do_after(user, 15 SECONDS))
add_damage(-max_damage)
set_health(maxhealth)
user.visible_message(SPAN_NOTICE("[user] finally finishes patching up \the [src]'s exterior! It's not a pretty job, but it'll do."),
SPAN_NOTICE("You finally finish patching up \the [src]'s exterior! It's not a pretty job, but it'll do."))
WT.use(20)
@@ -4,7 +4,7 @@
icon = 'icons/obj/machinery/ship_guns/leviathan.dmi'
icon_state = "weapon_off"
special_firing_mechanism = TRUE
max_damage = 10000
maxhealth = 10000
projectile_type = /obj/projectile/ship_ammo/leviathan
use_ammunition = FALSE
@@ -130,8 +130,8 @@
if(sensors)
data["on"] = sensors.use_power
data["range"] = sensors.range
data["health"] = sensors.health
data["max_health"] = sensors.max_health
data["integrity"] = sensors.health
data["max_health"] = sensors.maxhealth
data["deep_scan_name"] = sensors.deep_scan_sensor_name
data["deep_scan_range"] = sensors.deep_scan_range
data["deep_scan_toggled"] = sensors.deep_scan_toggled
@@ -401,8 +401,7 @@
icon = 'icons/obj/machinery/sensors.dmi'
icon_state = "sensors"
anchored = 1
var/max_health = 200
var/health = 200
maxhealth = OBJECT_HEALTH_HIGH
var/critical_heat = 50 // sparks and takes damage when active & above this heat
var/heat_reduction = 1.7 // mitigates this much heat per tick - can sustain range 4
var/heat = 0
@@ -438,7 +437,7 @@
return TRUE
if(default_part_replacement(user, attacking_item))
return TRUE
var/damage = max_health - health
var/damage = maxhealth - health
if(damage && attacking_item.tool_behaviour == TOOL_WELDER)
var/obj/item/weldingtool/WT = attacking_item
@@ -496,17 +495,6 @@
if(heat_percentage > 85)
AddOverlays("sensors-effect-hot")
/obj/machinery/shipsensors/condition_hints(mob/user, distance, is_adjacent)
. += ..()
if(health <= 0)
. += "\The [src] is wrecked."
else if(health < max_health * 0.25)
. += SPAN_DANGER("\The [src] looks like it's about to break!")
else if(health < max_health * 0.5)
. += SPAN_ALERT("\The [src] looks seriously damaged!")
else if(health < max_health * 0.75)
. += "\The [src] shows signs of damage!"
/obj/machinery/shipsensors/bullet_act(obj/projectile/hitting_projectile, def_zone, piercing_hit)
. = ..()
if(. != BULLET_ACT_HIT)
@@ -575,7 +563,7 @@
toggle()
/obj/machinery/shipsensors/proc/take_damage(value)
health = min(max(health - value, 0),max_health)
health = min(max(health - value, 0), maxhealth)
if(use_power && health == 0)
toggle()