Skip to content

Commit

Permalink
Merge pull request #3655 from MistakeNot4892/atomhealth
Browse files Browse the repository at this point in the history
Moves /mob and /obj health vars to /atom.
  • Loading branch information
out-of-phaze authored Mar 7, 2024
2 parents 7891bdd + 8ebe511 commit 2b6c1aa
Show file tree
Hide file tree
Showing 144 changed files with 529 additions and 508 deletions.
6 changes: 6 additions & 0 deletions code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
var/tmp/default_pixel_z
var/tmp/default_pixel_w

// Health vars largely used by obj and mob.
var/current_health
var/max_health

/atom/proc/get_max_health()
return max_health

/**
Adjust variables prior to Initialize() based on the map
Expand Down
18 changes: 10 additions & 8 deletions code/game/gamemodes/cult/runes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,16 @@
/obj/effect/rune/wall/cast(var/mob/living/user)
var/t
if(wall)
if(wall.health >= wall.max_health)
var/wall_max_health = wall.get_max_health()
if(wall.current_health >= wall_max_health)
to_chat(user, "<span class='notice'>The wall doesn't need mending.</span>")
return
t = wall.max_health - wall.health
wall.health += t
t = wall_max_health - wall.current_health
wall.current_health += t
else
wall = new /obj/effect/cultwall(get_turf(src), bcolor)
wall.rune = src
t = wall.health
t = wall.current_health
user.remove_blood_simple(t / 50)
speak_incantation(user, "Khari[pick("'","`")]d! Eske'te tannin!")
to_chat(user, "<span class='warning'>Your blood flows into the rune, and you feel that the very space over the rune thickens.</span>")
Expand Down Expand Up @@ -285,9 +286,10 @@
/obj/effect/cultwall/examine(mob/user)
. = ..()
if(iscultist(user))
if(health == max_health)
var/current_max_health = get_max_health()
if(current_health == current_max_health)
to_chat(user, "<span class='notice'>It is fully intact.</span>")
else if(health > max_health * 0.5)
else if(current_health > current_max_health * 0.5)
to_chat(user, "<span class='warning'>It is damaged.</span>")
else
to_chat(user, "<span class='danger'>It is about to dissipate.</span>")
Expand Down Expand Up @@ -318,8 +320,8 @@
..()

/obj/effect/cultwall/proc/take_damage(var/amount)
health -= amount
if(health <= 0)
current_health -= amount
if(current_health <= 0)
visible_message("<span class='warning'>\The [src] dissipates.</span>")
qdel(src)

Expand Down
4 changes: 2 additions & 2 deletions code/game/gamemodes/godmode/form_items/narsie_structures.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
desc = "This forge gives off no heat, no light, its flames look almost unnatural."
icon_state = "forge"
build_cost = 1000
health = 50
current_health = 50
var/busy = 0
var/recipe_feat_list = "Blood Crafting"
var/text_modifications = list("Cost" = "Blood",
Expand Down Expand Up @@ -74,7 +74,7 @@
name = "bloody stone"
desc = "A jagged stone covered in the various stages of blood, from dried to fresh."
icon_state = "blood_stone"
health = 100 //Its a piece of rock.
current_health = 100 //Its a piece of rock.
build_cost = 700

/obj/structure/deity/blood_stone/attack_hand(var/mob/user)
Expand Down
2 changes: 1 addition & 1 deletion code/game/gamemodes/godmode/god_altar.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/obj/structure/deity/altar
name = "altar"
desc = "A structure made for the express purpose of religion."
health = 50
current_health = 50
power_adjustment = 5
deity_flags = DEITY_STRUCTURE_ALONE
build_cost = 1000
Expand Down
2 changes: 1 addition & 1 deletion code/game/gamemodes/godmode/god_trap.dm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/obj/structure/deity/trap
density = FALSE
health = 1
current_health = 1
var/triggered = 0

/obj/structure/deity/trap/Initialize()
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/_machines_base/machinery.dm
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ Class Procs:
to_chat(user, "<span class='notice'>Following parts detected in the machine:</span>")
for(var/obj/item/C in component_parts)
var/line = "<span class='notice'> [C.name]</span>"
if(!C.health)
if(!C.current_health)
line = "<span class='warning'> [C.name] (destroyed)</span>"
else if(C.get_percent_health() < 75)
line = "<span class='notice'> [C.name] (damaged)</span>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
SetName("broken [name]")

/obj/item/stock_parts/proc/is_functional()
return (!can_take_damage()) || (health > 0)
return (!can_take_damage()) || (current_health > 0)

/obj/item/stock_parts/examine(mob/user)
. = ..()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
if(!req_access)
locked = FALSE
else
var/obj/item/card/id/I = user.GetIdCard()
var/obj/item/card/id/I = user.GetIdCard()
if(!istype(I, /obj/item/card/id))
to_chat(user, SPAN_WARNING("[\src] flashes a yellow LED near the ID scanner. Did you remember to scan your ID or PDA?"))
return TOPIC_HANDLED
Expand Down
8 changes: 4 additions & 4 deletions code/game/machinery/atmoalter/canister.dm
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ update_flag

/obj/machinery/portable_atmospherics/canister/fire_act(datum/gas_mixture/air, exposed_temperature, exposed_volume)
if(exposed_temperature > temperature_resistance)
health -= 5
current_health -= 5
healthcheck()
return ..()

/obj/machinery/portable_atmospherics/canister/proc/healthcheck()
if(destroyed)
return 1

if (src.health <= 10)
if (current_health <= 10)
var/atom/location = src.loc
location.assume_air(air_contents)

Expand Down Expand Up @@ -258,14 +258,14 @@ update_flag
return

if(Proj.damage)
src.health -= round(Proj.damage / 2)
current_health -= round(Proj.damage / 2)
healthcheck()
..()

/obj/machinery/portable_atmospherics/canister/bash(var/obj/item/W, var/mob/user)
. = ..()
if(.)
health -= W.force
current_health -= W.force
healthcheck()

/obj/machinery/portable_atmospherics/canister/attackby(var/obj/item/W, var/mob/user)
Expand Down
23 changes: 12 additions & 11 deletions code/game/machinery/deployable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@
return
return
else if(IS_WRENCH(W))
if (src.health < src.max_health)
src.health = src.max_health
src.emagged = 0
src.req_access = list(access_security)
var/current_max_health = get_max_health()
if (current_health < current_max_health)
current_health = current_max_health
emagged = 0
req_access = list(access_security)
visible_message("<span class='warning'>[user] repairs \the [src]!</span>")
return
else if (src.emagged > 0)
Expand All @@ -53,21 +54,21 @@
else
switch(W.damtype)
if(BURN)
src.health -= W.force * 0.75
current_health -= W.force * 0.75
if(BRUTE)
src.health -= W.force * 0.5
if (src.health <= 0)
src.explode()
current_health -= W.force * 0.5
if (current_health <= 0)
explode()
..()

/obj/machinery/deployable/barrier/explosion_act(severity)
. = ..()
if(. && !QDELETED(src))
if(severity == 1)
health = 0
current_health = 0
else if(severity == 2)
health -= 25
if(health <= 0)
current_health -= 25
if(current_health <= 0)
explode()

/obj/machinery/deployable/barrier/emp_act(severity)
Expand Down
50 changes: 27 additions & 23 deletions code/game/machinery/doors/_door.dm
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
if (turf_hand_priority)
set_extension(src, /datum/extension/turf_hand, turf_hand_priority)

health = max_health
#ifdef UNIT_TEST
if(autoset_access && length(req_access))
PRINT_STACK_TRACE("A door with mapped access restrictions was set to autoinitialize access.")
Expand Down Expand Up @@ -253,15 +252,16 @@
if(reason_broken & MACHINE_BROKEN_GENERIC)
to_chat(user, "<span class='notice'>It looks like \the [src] is pretty busted. It's going to need more than just patching up now.</span>")
return TRUE
if(health >= max_health)
var/current_max_health = get_max_health()
if(current_health >= current_max_health)
to_chat(user, "<span class='notice'>Nothing to fix!</span>")
return TRUE
if(!density)
to_chat(user, "<span class='warning'>\The [src] must be closed before you can repair it.</span>")
return TRUE

//figure out how much metal we need
var/amount_needed = (max_health - health) / DOOR_REPAIR_AMOUNT
var/amount_needed = (current_max_health - current_health) / DOOR_REPAIR_AMOUNT
amount_needed = CEILING(amount_needed)

var/obj/item/stack/stack = I
Expand Down Expand Up @@ -293,7 +293,7 @@
playsound(src, 'sound/items/Welder.ogg', 100, 1)
if(do_after(user, 5 * repairing.amount, src) && welder && welder.isOn())
to_chat(user, "<span class='notice'>You finish repairing the damage to \the [src].</span>")
health = clamp(health, health + repairing.amount*DOOR_REPAIR_AMOUNT, max_health)
current_health = clamp(current_health, current_health + repairing.amount*DOOR_REPAIR_AMOUNT, get_max_health())
update_icon()
qdel(repairing)
repairing = null
Expand Down Expand Up @@ -334,7 +334,7 @@
return FALSE

/obj/machinery/door/take_damage(var/damage, damtype=BRUTE)
if(!health)
if(!current_health)
..(damage, damtype)
update_icon()
return
Expand All @@ -343,39 +343,43 @@
damage -= component_damage

//Part of damage is soaked by our own health
var/initialhealth = health
health = max(0, health - damage)
if(health <= 0 && initialhealth > 0)
var/current_max_health = get_max_health()
var/initialhealth = current_health
current_health = max(0, current_health - damage)
if(current_health <= 0 && initialhealth > 0)
visible_message(SPAN_WARNING("\The [src] breaks down!"))
set_broken(TRUE)
else if(health < max_health / 4 && initialhealth >= max_health / 4)
else if(current_health < current_max_health / 4 && initialhealth >= current_max_health / 4)
visible_message(SPAN_WARNING("\The [src] looks like it's about to break!"))
else if(health < max_health / 2 && initialhealth >= max_health / 2)
else if(current_health < current_max_health / 2 && initialhealth >= current_max_health / 2)
visible_message(SPAN_WARNING("\The [src] looks seriously damaged!"))
else if(health < max_health * 3/4 && initialhealth >= max_health * 3/4)
else if(current_health < current_max_health * 3/4 && initialhealth >= current_max_health * 3/4)
visible_message(SPAN_WARNING("\The [src] shows signs of damage!"))

..(component_damage, damtype)
update_icon()

//How much damage should be passed to components inside even when door health is non zero
/obj/machinery/door/proc/get_damage_leakthrough(var/damage, damtype=BRUTE)
if(health > 0.75 * max_health && damage < 10)
var/current_max_health = get_max_health()
if(current_health > 0.75 * current_max_health && damage < 10)
return 0
. = round((1 - health/max_health) * damage)
. = round((1 - current_health/current_max_health) * damage)

/obj/machinery/door/examine(mob/user)
. = ..()
if(src.health <= 0)
if(current_health <= 0)
to_chat(user, "\The [src] is broken!")
else if(src.health < src.max_health / 4)
to_chat(user, "\The [src] looks like it's about to break!")
else if(src.health < src.max_health / 2)
to_chat(user, "\The [src] looks seriously damaged!")
else if(src.health < src.max_health * 3/4)
to_chat(user, "\The [src] shows signs of damage!")
else if(src.health < src.max_health && get_dist(src, user) <= 1)
to_chat(user, "\The [src] has some minor scuffing.")
else
var/current_max_health = get_max_health()
if(current_health < current_max_health / 4)
to_chat(user, "\The [src] looks like it's about to break!")
else if(current_health < current_max_health / 2)
to_chat(user, "\The [src] looks seriously damaged!")
else if(current_health < current_max_health * 3/4)
to_chat(user, "\The [src] shows signs of damage!")
else if(current_health < current_max_health && get_dist(src, user) <= 1)
to_chat(user, "\The [src] has some minor scuffing.")

var/mob/living/carbon/human/H = user
if (emagged && istype(H) && (H.skill_check(SKILL_COMPUTER, SKILL_ADEPT) || H.skill_check(SKILL_ELECTRICAL, SKILL_ADEPT)))
Expand Down Expand Up @@ -501,7 +505,7 @@
dismantle(TRUE)

/obj/machinery/door/proc/CheckPenetration(var/base_chance, var/damage)
. = damage/max_health*180
. = damage/get_max_health()*180
if(glass)
. *= 2
. = round(.)
Expand Down
10 changes: 5 additions & 5 deletions code/game/machinery/doors/airlock.dm
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ About the new airlock wires panel:

if(stat & BROKEN)
damage_overlay = sparks_broken_file
else if(health < max_health * 3/4)
else if(current_health < get_max_health() * 3/4)
damage_overlay = sparks_damaged_file

if(welded)
Expand Down Expand Up @@ -767,7 +767,7 @@ About the new airlock wires panel:
return TRUE
else if(!repairing)
// Add some minor damage as evidence of forcing.
if(health >= max_health)
if(current_health >= get_max_health())
take_damage(1)
if(arePowerSystemsOn())
to_chat(user, SPAN_WARNING("The airlock's motors resist your efforts to force it."))
Expand Down Expand Up @@ -824,10 +824,10 @@ About the new airlock wires panel:
var/obj/item/twohanded/fireaxe/F = I
if (F.wielded)
playsound(src, 'sound/weapons/smash.ogg', 100, 1)
health -= F.force_wielded * 2
if(health <= 0)
current_health -= F.force_wielded * 2
if(current_health <= 0)
user.visible_message(SPAN_DANGER("[user] smashes \the [I] into the airlock's control panel! It explodes in a shower of sparks!"), SPAN_DANGER("You smash \the [I] into the airlock's control panel! It explodes in a shower of sparks!"))
health = 0
current_health = 0
set_broken(TRUE)
else
user.visible_message(SPAN_DANGER("[user] smashes \the [I] into the airlock's control panel!"))
Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/doors/blast_door.dm
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
to_chat(user, "<span class='notice'>[src]'s motors resist your effort.</span>")
return
if(istype(C, /obj/item/stack/material) && C.get_material_type() == /decl/material/solid/metal/plasteel)
var/amt = CEILING((max_health - health)/150)
var/amt = CEILING((get_max_health() - current_health)/150)
if(!amt)
to_chat(user, "<span class='notice'>\The [src] is already fully functional.</span>")
return
Expand Down Expand Up @@ -209,7 +209,7 @@
// Parameters: None
// Description: Fully repairs the blast door.
/obj/machinery/door/blast/proc/repair()
health = max_health
current_health = get_max_health()
set_broken(FALSE)
queue_icon_update()

Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/doors/braces.dm
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
return
if(C.weld(0,user))
playsound(src, 'sound/items/Welder.ogg', 100, 1)
health = min(health + rand(20,30), max_health)
current_health = min(current_health + rand(20,30), get_max_health())
if(!is_damaged())
to_chat(user, "You repair some dents on \the [src]. It is in perfect condition now.")
else
Expand Down
Loading

0 comments on commit 2b6c1aa

Please sign in to comment.