From 759d9add4cf965df31ca6bd89124af1e086b3fb3 Mon Sep 17 00:00:00 2001 From: Casey Date: Mon, 11 Apr 2022 15:25:19 -0400 Subject: [PATCH] Merge pull request #12708 from VOREStation/upstream-merge-8511 [MIRROR] updated get_atom_on_turf --- code/_helpers/turfs.dm | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/code/_helpers/turfs.dm b/code/_helpers/turfs.dm index cdca430fb6..690e4f1833 100644 --- a/code/_helpers/turfs.dm +++ b/code/_helpers/turfs.dm @@ -1,10 +1,20 @@ -// Returns the atom sitting on the turf. -// For example, using this on a disk, which is in a bag, on a mob, will return the mob because it's on the turf. -/proc/get_atom_on_turf(var/atom/movable/M) - var/atom/mloc = M - while(mloc && mloc.loc && !istype(mloc.loc, /turf/)) - mloc = mloc.loc - return mloc +/** +* Returns a best attempt at the least-nested containing movable of subject, or subject. +* eg, if subject is an item in a bag on a mob in a locker in the world, returns the locker. +*/ +/proc/get_atom_on_turf(atom/movable/subject) + var/atom/parent = subject?.loc + if (!parent || !ismovable(subject) || isarea(parent)) + return subject + var/atom/current = subject + do + parent = current.loc + if (isturf(parent)) + return current + current = parent + while (current) + return subject + /proc/iswall(turf/T) return (istype(T, /turf/simulated/wall) || istype(T, /turf/unsimulated/wall) || istype(T, /turf/simulated/shuttle/wall))