Files
CHOMPStation2/code/game/atoms_movable_ch.dm
Cadyn b90f7ec922 The 515 MegaPR early downport (#7783)
Co-authored-by: Selis <selis@xynolabs.com>
Co-authored-by: Selis <sirlionfur@hotmail.de>
Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
Co-authored-by: SatinIsle <thesatinisle@gmail.com>
Co-authored-by: Heroman <alesha3000@list.ru>
Co-authored-by: Casey <a.roaming.shadow@gmail.com>
Co-authored-by: Raeschen <rycoop29@gmail.com>
2024-02-27 20:17:32 +01:00

63 lines
2.0 KiB
Plaintext

#define NON_LISTENING_ATOM 0
#define LISTENING_ATOM 1
#define LISTENING_PLAYER 2
//gonna be honest this is really just a ripoff of tg's recursive hearing
/atom/movable
var/recursive_listeners
var/listening_recursive = NON_LISTENING_ATOM
/atom/movable/New()
. = ..()
if (listening_recursive)
set_listening(listening_recursive)
/atom/movable/Destroy()
. = ..()
set_listening(NON_LISTENING_ATOM)
/atom/movable/proc/set_listening(var/set_to)
if (listening_recursive && !set_to)
LAZYREMOVE(recursive_listeners, src)
if (!LAZYLEN(recursive_listeners))
for (var/atom/movable/location as anything in get_nested_locs(src))
LAZYREMOVE(location.recursive_listeners, src)
if (!listening_recursive && set_to)
LAZYOR(recursive_listeners, src)
for (var/atom/movable/location as anything in get_nested_locs(src))
LAZYOR(location.recursive_listeners, src)
listening_recursive = set_to
///Returns a list of all locations (except the area) the movable is within.
/proc/get_nested_locs(atom/movable/atom_on_location, include_turf = FALSE)
. = list()
var/atom/location = atom_on_location.loc
var/turf/our_turf = get_turf(atom_on_location)
while(location && location != our_turf)
. += location
location = location.loc
if(our_turf && include_turf) //At this point, only the turf is left, provided it exists.
. += our_turf
/atom/movable/Exited(atom/movable/gone, atom/new_loc)
. = ..()
if (!LAZYLEN(gone.recursive_listeners))
return
for (var/atom/movable/location as anything in get_nested_locs(src)|src)
LAZYREMOVE(location.recursive_listeners, gone.recursive_listeners)
/atom/movable/Entered(atom/movable/arrived, atom/old_loc)
. = ..()
if (!LAZYLEN(arrived.recursive_listeners))
return
for (var/atom/movable/location as anything in get_nested_locs(src)|src)
LAZYOR(location.recursive_listeners, arrived.recursive_listeners)
// Helper procs called on entering/exiting a belly. Does nothing by default, override on children for special behavior.
/atom/movable/proc/enter_belly(obj/belly/B)
return
/atom/movable/proc/exit_belly(obj/belly/B)
return