mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-27 01:51:50 +00:00
* Makes obj_integrity only updated through procs (#59474) Having things updating integrity directly is just going to cause more problems down the line as more elements and components depend on being notified of integrity changes. It's an easy mistake to make so making it private should deal with the problem. get_integrity() might be useful in the future but is mainly a side effect of making obj_integrity private as that also disallows reads. * Makes obj_integrity private and only updated through procs * Mirror! Co-authored-by: Emmett Gaines <ninjanomnom@gmail.com> Co-authored-by: Funce <funce.973@gmail.com>
85 lines
2.1 KiB
Plaintext
85 lines
2.1 KiB
Plaintext
/** Object integrity regeneration element added by alien alloy.
|
|
*/
|
|
/datum/element/obj_regen
|
|
element_flags = ELEMENT_BESPOKE | ELEMENT_DETACH
|
|
id_arg_index = 2
|
|
/// The rate of regeneration as a function of maximum integrity.
|
|
var/rate
|
|
/// The objects that are regenerating due to this element.
|
|
var/list/processing = list()
|
|
/// The current stack of objects we are processing.
|
|
var/list/currentrun
|
|
/// Whether we stopped processing early the last tick.
|
|
var/resumed = FALSE
|
|
|
|
|
|
/datum/element/obj_regen/Attach(obj/target, _rate=0)
|
|
. = ..()
|
|
if(!istype(target))
|
|
return ELEMENT_INCOMPATIBLE
|
|
if(_rate <= 0)
|
|
return ELEMENT_INCOMPATIBLE
|
|
|
|
rate = _rate
|
|
RegisterSignal(target, COMSIG_OBJ_TAKE_DAMAGE, .proc/on_take_damage)
|
|
if(target.get_integrity() < target.max_integrity)
|
|
if(!length(processing))
|
|
START_PROCESSING(SSobj, src)
|
|
processing |= target
|
|
|
|
/datum/element/obj_regen/Detach(obj/target)
|
|
UnregisterSignal(target, COMSIG_OBJ_TAKE_DAMAGE)
|
|
processing -= target
|
|
if(!length(processing))
|
|
STOP_PROCESSING(SSobj, src)
|
|
|
|
/// 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))
|
|
START_PROCESSING(SSobj, src)
|
|
processing |= target
|
|
|
|
|
|
/// Handle regenerating attached objects.
|
|
/datum/element/obj_regen/process(delta_time)
|
|
set waitfor = FALSE
|
|
|
|
if(!resumed)
|
|
currentrun = processing.Copy()
|
|
|
|
resumed = FALSE
|
|
var/list/cached_run = currentrun
|
|
if(!length(cached_run))
|
|
if(!length(processing))
|
|
STOP_PROCESSING(SSobj, src)
|
|
return
|
|
return
|
|
|
|
var/cached_rate = rate
|
|
while(length(cached_run))
|
|
var/obj/regen_obj = cached_run[cached_run.len]
|
|
cached_run.len--
|
|
|
|
if(QDELETED(regen_obj))
|
|
processing -= regen_obj
|
|
if(!length(processing))
|
|
STOP_PROCESSING(SSobj, src)
|
|
return PROCESS_KILL
|
|
if(CHECK_TICK)
|
|
resumed = TRUE
|
|
return
|
|
continue
|
|
|
|
if(!regen_obj.repair_damage(regen_obj.max_integrity * cached_rate))
|
|
processing -= regen_obj
|
|
if(!length(processing))
|
|
STOP_PROCESSING(SSobj, src)
|
|
return PROCESS_KILL
|
|
|
|
if(CHECK_TICK)
|
|
resumed = TRUE
|
|
return
|