Files
Bubberstation/code/datums/elements/obj_regen.dm
AnturK 4d6a8bc537 515 Compatibility (#71161)
Makes the code compatible with 515.1594+

Few simple changes and one very painful one.
Let's start with the easy:
* puts call behind `LIBCALL` define, so call_ext is properly used in 515
* Adds `NAMEOF_STATIC(_,X)` macro for nameof in static definitions since
src is now invalid there.
* Fixes tgui and devserver. From 515 onward the tmp3333{procid} cache
directory is not appened to base path in browser controls so we don't
check for it in base js and put the dev server dummy window file in
actual directory not the byond root.
* Renames the few things that had /final/ in typepath to ultimate since
final is a new keyword

And the very painful change:
`.proc/whatever` format is no longer valid, so we're replacing it with
new nameof() function. All this wrapped in three new macros.
`PROC_REF(X)`,`TYPE_PROC_REF(TYPE,X)`,`GLOBAL_PROC_REF(X)`. Global is
not actually necessary but if we get nameof that does not allow globals
it would be nice validation.
This is pretty unwieldy but there's no real alternative.
If you notice anything weird in the commits let me know because majority
was done with regex replace.

@tgstation/commit-access Since the .proc/stuff is pretty big change.

Co-authored-by: san7890 <the@san7890.com>
Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
2022-11-15 03:50:11 +00:00

86 lines
2.1 KiB
Plaintext

/** Object integrity regeneration element added by alien alloy.
*/
/datum/element/obj_regen
element_flags = ELEMENT_BESPOKE | ELEMENT_DETACH_ON_HOST_DESTROY
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_ATOM_TAKE_DAMAGE, PROC_REF(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_ATOM_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