Files
Bubberstation/code/datums/components/areabound.dm
Zonespace f7c26bbf25 515 Compat (#17465)
* ONLY SKYRAT CHANGES

* ACTUALLY SKYRAT CHANGES

* yolo, revert later

* Update alternate_byond_versions.txt

Co-authored-by: AnturK <AnturK@users.noreply.github.com>
2022-11-15 06:59:06 +00:00

32 lines
1.1 KiB
Plaintext

/// Movables with this component will automatically return to their original turf if moved outside their initial area
/datum/component/areabound
var/area/bound_area
var/turf/reset_turf
var/datum/movement_detector/move_tracker
var/moving = FALSE //Used to prevent infinite recursion if your reset turf places you somewhere on enter or something
/datum/component/areabound/Initialize()
if(!ismovable(parent))
return COMPONENT_INCOMPATIBLE
bound_area = get_area(parent)
reset_turf = get_turf(parent)
move_tracker = new(parent,CALLBACK(src, PROC_REF(check_bounds)))
/datum/component/areabound/proc/check_bounds()
var/atom/movable/AM = parent
var/area/current = get_area(AM)
if(current != bound_area)
if(!reset_turf || reset_turf.loc != bound_area)
stack_trace("Invalid areabound configuration") //qdel(src)
return
if(moving)
stack_trace("Moved during a reset move, giving up to prevent infinite recursion. Turf: [reset_turf.type] at [reset_turf.x], [reset_turf.y], [reset_turf.z]")
return
moving = TRUE
AM.forceMove(reset_turf)
moving = FALSE
/datum/component/areabound/Destroy(force, silent)
QDEL_NULL(move_tracker)
. = ..()