diff --git a/code/__DEFINES/misc.dm b/code/__DEFINES/misc.dm index b83fc3dd39..66c12adc72 100644 --- a/code/__DEFINES/misc.dm +++ b/code/__DEFINES/misc.dm @@ -468,4 +468,6 @@ GLOBAL_LIST_INIT(ghost_others_options, list(GHOST_OTHERS_SIMPLE, GHOST_OTHERS_DE #define DUMMY_HUMAN_SLOT_MANIFEST "dummy_manifest_generation" #define PR_ANNOUNCEMENTS_PER_ROUND 5 //The number of unique PR announcements allowed per round - //This makes sure that a single person can only spam 3 reopens and 3 closes before being ignored \ No newline at end of file + //This makes sure that a single person can only spam 3 reopens and 3 closes before being ignored + +#define MAX_PROC_DEPTH 195 // 200 proc calls deep and shit breaks, this is a bit lower to give some safety room \ No newline at end of file diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index cae42d62e8..75e912dee7 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -503,12 +503,22 @@ Turf and target are separate in case you want to teleport some distance from a t var/y=arcsin(x/sqrt(1+x*x)) return y -/atom/proc/GetAllContents(list/output=list()) +/* +Recursively gets all contents of contents and returns them all in a list. + +recursive_depth is useful if you only want a turf and everything on it (recursive_depth=1) +Do not set recursive depth higher than MAX_PROC_DEPTH as byond breaks when that limit is reached. +*/ +/atom/proc/GetAllContents(list/output=list(), recursive_depth=MAX_PROC_DEPTH, _current_depth=0) . = output output += src + if(_current_depth == recursive_depth) + if(_current_depth == MAX_PROC_DEPTH) + WARNING("Get all contents reached the max recursive depth of [MAX_PROC_DEPTH]. More and we would break shit. Offending atom: [src]") + return for(var/i in 1 to contents.len) var/atom/thing = contents[i] - thing.GetAllContents(output) + thing.GetAllContents(output, recursive_depth, ++_current_depth) //Step-towards method of determining whether one atom can see another. Similar to viewers() /proc/can_see(atom/source, atom/target, length=5) // I couldnt be arsed to do actual raycasting :I This is horribly inaccurate.