Files
Paradise/code/datums/movement_detector.dm
Qwertytoforty 9b534f3c3f Ports baby watcher from TG* (#22768)
* Ports baby watcher from TG*

* ah. I see. Alphabetical. Should have seen that coming.

* here comes the better mapped boi 🎵

* removes recursive_loc_check, uses get. also removes the debug always place WHOOPS

* fixes arguments, need to update and edit map

* adds bombable turfs

* Apply suggestions from code review

Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com>

* changes

* ///

* R-R-R-RUN IT BACK

* Update code/modules/awaymissions/mob_spawn.dm

Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com>

* oops spacing

* part 1/2

* Update code/modules/awaymissions/mission_code/ruins/watcher_grave.dm

Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com>

* 2 / 2

* Apply suggestions from code review

Co-authored-by: Henri215 <77684085+Henri215@users.noreply.github.com>

---------

Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com>
Co-authored-by: Henri215 <77684085+Henri215@users.noreply.github.com>
2023-12-16 12:03:07 +00:00

57 lines
1.7 KiB
Plaintext

/// A datum to handle the busywork of registering signals to handle in depth tracking of a movable
/datum/movement_detector
var/atom/movable/tracked
/// Listener is whatever callback that will increase the tracking of the movable, usually on stepped.
var/datum/callback/listener
/datum/movement_detector/New(atom/movable/target, datum/callback/listener)
if(target)
track(target, listener)
/datum/movement_detector/Destroy()
untrack()
tracked = null
listener = null
return ..()
/// Sets up tracking of the given movable atom
/datum/movement_detector/proc/track(atom/movable/target, datum/callback/listener)
untrack()
tracked = target
src.listener = listener
if(ismovable(target))
RegisterSignal(target, COMSIG_MOVABLE_MOVED, PROC_REF(move_react))
target = target.loc
/// Stops tracking
/datum/movement_detector/proc/untrack()
if(!tracked)
return
var/atom/movable/target = tracked
if(ismovable(target))
UnregisterSignal(target, COMSIG_MOVABLE_MOVED)
target = target.loc
/**
* Reacts to any movement that would cause a change in coordinates of the tracked movable atom
* This works by detecting movement of either the tracked object, or anything it is inside, recursively
*/
/datum/movement_detector/proc/move_react(atom/movable/mover, atom/oldloc, direction)
SIGNAL_HANDLER
var/turf/newturf = get_turf(tracked)
if(oldloc && !isturf(oldloc))
var/atom/target = oldloc
if(ismovable(target))
UnregisterSignal(target, COMSIG_MOVABLE_MOVED)
target = target.loc
if(tracked.loc != newturf)
var/atom/target = mover.loc
if(ismovable(target))
RegisterSignal(target, COMSIG_MOVABLE_MOVED, PROC_REF(move_react), TRUE)
target = target.loc
listener.Invoke(tracked, mover, oldloc, direction)