Skip to content

Commit

Permalink
update-through-procs (#11203)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsar-Salat authored Jul 30, 2024
1 parent 1ad761e commit 94ab73c
Show file tree
Hide file tree
Showing 67 changed files with 157 additions and 107 deletions.
15 changes: 13 additions & 2 deletions code/__DEFINES/dcs/signals/signals_obj/signals_object.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@
#define COMSIG_OBJ_TAKE_DAMAGE "obj_take_damage"
/// Return bitflags for the above signal which prevents the object taking any damage.
#define COMPONENT_NO_TAKE_DAMAGE (1<<0)
#define COMSIG_OBJ_DECONSTRUCT "obj_deconstruct" //! from base of obj/deconstruct(): (disassembled)
///from base of [/obj/proc/update_integrity]: (old_value, new_value)
#define COMSIG_OBJ_INTEGRITY_CHANGED "obj_integrity_changed"
///from base of obj/deconstruct(): (disassembled)
#define COMSIG_OBJ_DECONSTRUCT "obj_deconstruct"
///from base of code/game/machinery
#define COMSIG_OBJ_DEFAULT_UNFASTEN_WRENCH "obj_default_unfasten_wrench"
#define COMSIG_OBJ_HIDE "obj_hide" //from base of /turf/proc/levelupdate(). (intact) true to hide and false to unhide
///from base of /turf/proc/levelupdate(). (intact) true to hide and false to unhide
#define COMSIG_OBJ_HIDE "obj_hide"

/// from /obj/proc/obj_break: ()
#define COMSIG_OBJ_BREAK "obj_break"
/// from base of [/obj/proc/obj_fix]: ()
#define COMSIG_OBJ_FIX "obj_fix"

/// from /obj/proc/make_unfrozen()
#define COMSIG_OBJ_UNFREEZE "obj_unfreeze"
Expand All @@ -21,3 +31,4 @@
#define COMPONENT_OBJ_CANCEL_CHARGE (1<<0)
///Called when a payment component changes value
#define COMSIG_OBJ_ATTEMPT_CHARGE_CHANGE "obj_attempt_simple_charge_change"

4 changes: 2 additions & 2 deletions code/datums/components/dejavu.dm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

else if(isobj(parent))
var/obj/O = parent
integrity = O.obj_integrity
integrity = O.get_integrity()
rewind_type = PROC_REF(rewind_obj)

addtimer(CALLBACK(src, rewind_type), rewind_interval)
Expand Down Expand Up @@ -103,5 +103,5 @@

/datum/component/dejavu/proc/rewind_obj()
var/obj/master = parent
master.obj_integrity = integrity
master.update_integrity(integrity)
rewind()
2 changes: 1 addition & 1 deletion code/datums/elements/art.dm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
var/mult = 1
if(isobj(source))
var/obj/art_piece = source
mult = art_piece.obj_integrity/art_piece.max_integrity
mult = art_piece.get_integrity() / art_piece.max_integrity

apply_moodlet(source, user, impressiveness * mult)
8 changes: 4 additions & 4 deletions code/datums/elements/obj_regen.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** Object integrity regeneration element added by alien alloy.
*/
*/
/datum/element/obj_regen
element_flags = ELEMENT_BESPOKE | ELEMENT_DETACH
id_arg_index = 2
Expand All @@ -22,7 +22,7 @@

rate = _rate
RegisterSignal(target, COMSIG_OBJ_TAKE_DAMAGE, PROC_REF(on_take_damage))
if(target.obj_integrity < target.max_integrity)
if(target.get_integrity() < target.max_integrity)
if(!length(processing))
START_PROCESSING(SSobj, src)
processing |= target
Expand All @@ -35,6 +35,7 @@

/// Handles beginning processing objects.
/datum/element/obj_regen/proc/on_take_damage(obj/target, damage_amt)
SIGNAL_HANDLER
if(!damage_amt)
return
if(!length(processing))
Expand Down Expand Up @@ -72,8 +73,7 @@
return
continue

regen_obj.obj_integrity = clamp(regen_obj.obj_integrity + (regen_obj.max_integrity * cached_rate), 0, regen_obj.max_integrity)
if(regen_obj.obj_integrity == regen_obj.max_integrity)
if(!regen_obj.repair_damage(regen_obj.max_integrity * cached_rate))
processing -= regen_obj
if(!length(processing))
STOP_PROCESSING(SSobj, src)
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/_machinery.dm
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ Class Procs:
. = new_frame
new_frame.set_anchored(TRUE)
if(!disassembled)
new_frame.obj_integrity = new_frame.max_integrity * 0.5 //the frame is already half broken
new_frame.update_integrity(new_frame.max_integrity * 0.5) //the frame is already half broken
transfer_fingerprints_to(new_frame)

/obj/machinery/obj_break(damage_flag)
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/airlock_cycle_control.dm
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@
new /obj/item/stack/sheet/iron(loc, 2)
var/obj/item/I = new /obj/item/electronics/advanced_airlock_controller(loc)
if(!disassembled)
I.obj_integrity = I.max_integrity * 0.5
I.take_damage(I.max_integrity * 0.5, sound_effect = FALSE)
new /obj/item/stack/cable_coil(loc, 3)
qdel(src)

Expand Down
1 change: 0 additions & 1 deletion code/game/machinery/aug_manipulator.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
icon = 'icons/obj/robotics.dmi'
icon_state = "robocolorer"
density = TRUE
obj_integrity = 200
max_integrity = 200
var/obj/item/bodypart/storedpart
var/initial_icon_state
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/camera/camera.dm
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/camera/xray, 0)
assembly_ref = null
else
var/obj/item/I = new /obj/item/wallframe/camera (loc)
I.obj_integrity = I.max_integrity * 0.5
I.update_integrity(I.max_integrity * 0.5)
new /obj/item/stack/cable_coil(loc, 2)
qdel(src)

Expand Down
1 change: 0 additions & 1 deletion code/game/machinery/digital_clock.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
verb_ask = "bloops"
verb_exclaim = "blares"
max_integrity = 250
obj_integrity = 250
density = FALSE
layer = ABOVE_WINDOW_LAYER
var/station_minutes
Expand Down
3 changes: 1 addition & 2 deletions code/game/machinery/doors/airlock.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1451,8 +1451,7 @@
A.update_icon()

if(!disassembled)
if(A)
A.obj_integrity = A.max_integrity * 0.5
A?.update_integrity(A.max_integrity * 0.5)
else
if(user)
to_chat(user, "<span class='notice'>You remove the airlock electronics.</span>")
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/doors/firedoor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@
F.constructionStep = CONSTRUCTION_PANEL_OPEN
else
F.constructionStep = CONSTRUCTION_WIRES_EXPOSED
F.obj_integrity = F.max_integrity * 0.5
F.update_integrity(F.max_integrity * 0.5)
F.update_icon()
qdel(src)

Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/firealarm.dm
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/firealarm, 26)
if(!(machine_stat & BROKEN))
var/obj/item/I = new /obj/item/electronics/firealarm(loc)
if(!disassembled)
I.obj_integrity = I.max_integrity * 0.5
I.update_integrity(I.max_integrity * 0.5)
new /obj/item/stack/cable_coil(loc, 3)
qdel(src)

Expand Down
1 change: 0 additions & 1 deletion code/game/machinery/shuttle/custom_shuttle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
name = "shuttle component"
desc = "Something for shuttles."
density = TRUE
obj_integrity = 250
max_integrity = 250
icon = 'icons/turf/shuttle.dmi'
icon_state = "burst_plasma"
Expand Down
1 change: 0 additions & 1 deletion code/game/machinery/shuttle/shuttle_engine.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
desc = "A thruster for shuttles."
density = TRUE
z_flags = Z_BLOCK_IN_DOWN | Z_BLOCK_IN_UP
obj_integrity = 250
max_integrity = 250
icon = 'icons/turf/shuttle.dmi'
icon_state = "burst_plasma"
Expand Down
1 change: 0 additions & 1 deletion code/game/objects/items/devices/reverse_bear_trap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
flags_1 = CONDUCT_1
resistance_flags = FIRE_PROOF | UNACIDABLE
w_class = WEIGHT_CLASS_NORMAL
obj_integrity = 300
max_integrity = 300
item_state = "rack_parts"
lefthand_file = 'icons/mob/inhands/items_lefthand.dmi'
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/mjolnir.dm
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
if (isobj(target))
var/obj/hit_structure = target
hit_structure.take_damage(120)
if (hit_structure.obj_integrity > 0)
if (hit_structure.get_integrity() > 0)
qdel(src)
if (isliving(target))
var/mob/living/hit_mob = target
Expand Down
41 changes: 37 additions & 4 deletions code/game/objects/obj_defense.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
if(SEND_SIGNAL(src, COMSIG_OBJ_TAKE_DAMAGE, damage_amount, damage_type, damage_flag, sound_effect, attack_dir, armour_penetration) & COMPONENT_NO_TAKE_DAMAGE)
return
. = damage_amount
var/old_integ = obj_integrity
obj_integrity = max(old_integ - damage_amount, 0)

update_integrity(obj_integrity - damage_amount)

//BREAKING FIRST
if(integrity_failure && obj_integrity <= integrity_failure * max_integrity)
obj_break(damage_flag)
Expand All @@ -28,6 +29,32 @@
if(obj_integrity <= 0)
obj_destruction(damage_flag)

/// Proc for recovering obj_integrity. Returns the amount repaired by
/obj/proc/repair_damage(amount)
if(amount <= 0) // We only recover here
return
var/new_integrity = min(max_integrity, obj_integrity + amount)
. = new_integrity - obj_integrity

update_integrity(new_integrity)

if(integrity_failure && obj_integrity > integrity_failure * max_integrity)
obj_fix()

/// Handles the integrity of an object changing. This must be called instead of changing integrity directly.
/obj/proc/update_integrity(new_value)
SHOULD_NOT_OVERRIDE(TRUE)
new_value = max(0, new_value)
if(obj_integrity == new_value)
return
obj_integrity = new_value
SEND_SIGNAL(src, COMSIG_OBJ_INTEGRITY_CHANGED)

/// This mostly exists to keep obj_integrity private. Might be useful in the future.
/obj/proc/get_integrity()
SHOULD_BE_PURE(TRUE)
return obj_integrity

//returns the damage value of the attack after processing the obj's various armor protections
/obj/proc/run_obj_armor(damage_amount, damage_type, damage_flag = 0, attack_dir, armour_penetration = 0)
switch(damage_type)
Expand Down Expand Up @@ -257,9 +284,15 @@ GLOBAL_DATUM_INIT(acid_overlay, /mutable_appearance, mutable_appearance('icons/e
SEND_SIGNAL(src, COMSIG_OBJ_DECONSTRUCT, disassembled)
qdel(src)

//what happens when the obj's health is below integrity_failure level.
/// Called after the obj takes damage and integrity is below integrity_failure level
/obj/proc/obj_break(damage_flag)
return
SHOULD_CALL_PARENT(TRUE)
SEND_SIGNAL(src, COMSIG_OBJ_BREAK)

/// Called when integrity is repaired above the breaking point having been broken before
/obj/proc/obj_fix()
SHOULD_CALL_PARENT(TRUE)
SEND_SIGNAL(src, COMSIG_OBJ_FIX)

//what happens when the obj's integrity reaches zero.
/obj/proc/obj_destruction(damage_flag)
Expand Down
5 changes: 2 additions & 3 deletions code/game/objects/objs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

var/datum/armor/armor
/// The integrity the object starts at. Defaults to max_integrity.
var/obj_integrity
VAR_PRIVATE/obj_integrity //defaults to max_integrity
/// The maximum integrity the object can have.
var/max_integrity = 500
/// The object will break once obj_integrity reaches this amount in take_damage(). 0 if we have no special broken behavior, otherwise is a percentage of at what point the obj breaks. 0.5 being 50%
Expand Down Expand Up @@ -72,8 +72,7 @@
armor = getArmor()
else if (!istype(armor, /datum/armor))
stack_trace("Invalid type [armor.type] found in .armor during /obj Initialize()")
if(obj_integrity == null)
obj_integrity = max_integrity
obj_integrity = max_integrity

. = ..() //Do this after, else mat datums is mad.

Expand Down
1 change: 1 addition & 0 deletions code/game/objects/structures/aliens.dm
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@
break

/obj/structure/alien/egg/obj_break(damage_flag)
. = ..()
if(!(flags_1 & NODECONSTRUCT_1))
if(status != BURST)
Burst(kill=TRUE)
Expand Down
1 change: 1 addition & 0 deletions code/game/objects/structures/barsigns.dm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
return set_sign(new_sign)

/obj/structure/sign/barsign/obj_break(damage_flag)
. = ..()
if(!broken && !(flags_1 & NODECONSTRUCT_1))
broken = TRUE

Expand Down
1 change: 1 addition & 0 deletions code/game/objects/structures/crates_lockers/closets.dm
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@
qdel(src)

/obj/structure/closet/obj_break(damage_flag)
. = ..()
if(!broken && !(flags_1 & NODECONSTRUCT_1))
bust_open()

Expand Down
1 change: 1 addition & 0 deletions code/game/objects/structures/displaycase.dm
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
qdel(src)

/obj/structure/displaycase/obj_break(damage_flag)
. = ..()
if(!broken && !(flags_1 & NODECONSTRUCT_1))
set_density(FALSE)
broken = TRUE
Expand Down
1 change: 1 addition & 0 deletions code/game/objects/structures/extinguisher.dm
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/extinguisher_cabinet, 29)
icon_state = "extinguisher_empty"

/obj/structure/extinguisher_cabinet/obj_break(damage_flag)
. = ..()
if(!broken && !(flags_1 & NODECONSTRUCT_1))
broken = 1
opened = 1
Expand Down
3 changes: 2 additions & 1 deletion code/game/objects/structures/fireaxe.dm
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/fireaxecabinet, 32)
update_appearance()

/obj/structure/fireaxecabinet/obj_break(damage_flag)
. = ..()
if(!broken && !(flags_1 & NODECONSTRUCT_1))
update_appearance()
broken = TRUE
playsound(src, 'sound/effects/glassbr3.ogg', 100, 1)
playsound(src, 'sound/effects/glassbr3.ogg', 100, TRUE)
new /obj/item/shard(loc)
new /obj/item/shard(loc)

Expand Down
6 changes: 5 additions & 1 deletion code/game/objects/structures/grille.dm
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
..()

/obj/structure/grille/obj_break()
. = ..()
if(!broken && !(flags_1 & NODECONSTRUCT_1))
new broken_type(src.loc)
var/drop_loc = drop_location()
Expand Down Expand Up @@ -296,13 +297,16 @@
/obj/structure/grille/broken // Pre-broken grilles for map placement
icon_state = "brokengrille"
density = FALSE
obj_integrity = 20
broken = TRUE
rods_amount = 1
rods_broken = FALSE
grille_type = /obj/structure/grille
broken_type = null

/obj/structure/grille/broken/Initialize(mapload)
. = ..()
take_damage(max_integrity * 0.6)

/obj/structure/grille/prison //grilles that trigger prison lockdown under some circumstances
name = "prison grille"
desc = "a set of rods under current used to protect the prison wing. An alarm will go off if they are breached."
Expand Down
16 changes: 9 additions & 7 deletions code/game/objects/structures/mirror.dm
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/mirror, 28)
return ..()

/obj/structure/mirror/obj_break(damage_flag, mapload)
if(!broken && !(flags_1 & NODECONSTRUCT_1))
icon_state = "mirror_broke"
if(!mapload)
playsound(src, "shatter", 70, 1)
if(desc == initial(desc))
desc = "Oh no, seven years of bad luck!"
broken = TRUE
. = ..()
if(broken || (flags_1 & NODECONSTRUCT_1))
return
icon_state = "mirror_broke"
if(!mapload)
playsound(src, "shatter", 70, 1)
if(desc == initial(desc))
desc = "Oh no, seven years of bad luck!"
broken = TRUE

/obj/structure/mirror/deconstruct(disassembled = TRUE)
if(!(flags_1 & NODECONSTRUCT_1))
Expand Down
2 changes: 1 addition & 1 deletion code/modules/antagonists/blob/blobstrains/_blobstrain.dm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ GLOBAL_LIST_INIT(valid_blobstrains, subtypesof(/datum/blobstrain) - list(/datum/
if(resource_delay <= world.time)
resource_delay = world.time + 10 // 1 second
overmind.add_points(point_rate)
overmind.blob_core.obj_integrity = min(overmind.blob_core.max_integrity, overmind.blob_core.obj_integrity+core_regen)
overmind.blob_core.repair_damage(core_regen)

/datum/blobstrain/proc/attack_living(var/mob/living/L) // When the blob attacks people
send_message(L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
reagent = /datum/reagent/blob/energized_jelly

/datum/blobstrain/reagent/energized_jelly/damage_reaction(obj/structure/blob/B, damage, damage_type, damage_flag)
if((damage_flag == MELEE || damage_flag == BULLET || damage_flag == LASER) && B.obj_integrity - damage <= 0 && prob(10))
if((damage_flag == MELEE || damage_flag == BULLET || damage_flag == LASER) && B.get_integrity() - damage <= 0 && prob(10))
do_sparks(rand(2, 4), FALSE, B)
return ..()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
reagent = /datum/reagent/blob/reactive_spines

/datum/blobstrain/reagent/reactive_spines/damage_reaction(obj/structure/blob/B, damage, damage_type, damage_flag)
if(damage && damage_type == BRUTE && B.obj_integrity - damage > 0) //is there any damage, is it brute, and will we be alive
if(damage && damage_type == BRUTE && B.get_integrity() - damage > 0) //is there any damage, is it brute, and will we be alive
if(damage_flag == MELEE)
B.visible_message("<span class='boldwarning'>The blob retaliates, lashing out!</span>")
for(var/atom/A as() in range(1, B))
Expand Down
Loading

0 comments on commit 94ab73c

Please sign in to comment.