Files
Bubberstation/code/datums/components/atom_mounted.dm
Alexis 21b4095dfd [MDB IGNORE] [IDB IGNORE] Upstream Sync - 04/17/2026 (#5453)
Upstream 04/17/2026

fixes https://github.com/Bubberstation/Bubberstation/issues/5549

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: tgstation-ci[bot] <179393467+tgstation-ci[bot]@users.noreply.github.com>
Co-authored-by: ArcaneMusic <41715314+ArcaneMusic@users.noreply.github.com>
Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com>
Co-authored-by: Rhials <28870487+Rhials@users.noreply.github.com>
Co-authored-by: rageguy505 <54517726+rageguy505@users.noreply.github.com>
Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com>
Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com>
Co-authored-by: Aliceee2ch <160794176+Aliceee2ch@users.noreply.github.com>
Co-authored-by: Time-Green <7501474+Time-Green@users.noreply.github.com>
Co-authored-by: Tsar-Salat <62388554+Tsar-Salat@users.noreply.github.com>
Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com>
Co-authored-by: Maxipat <108554989+Maxipat112@users.noreply.github.com>
Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com>
Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com>
Co-authored-by: SimplyLogan <47579821+loganuk@users.noreply.github.com>
Co-authored-by: loganuk <fakeemail123@aol.com>
Co-authored-by: Leland Kemble <70413276+lelandkemble@users.noreply.github.com>
Co-authored-by: FalloutFalcon <86381784+FalloutFalcon@users.noreply.github.com>
Co-authored-by: Roxy <75404941+TealSeer@users.noreply.github.com>
Co-authored-by: Lucy <lucy@absolucy.moe>
Co-authored-by: siliconOpossum <138069572+siliconOpossum@users.noreply.github.com>
Co-authored-by: Isratosh <Isratosh@hotmail.com>
Co-authored-by: TheRyeGuyWhoWillNowDie <70169560+TheRyeGuyWhoWillNowDie@users.noreply.github.com>
Co-authored-by: Neocloudy <88008002+Neocloudy@users.noreply.github.com>
Co-authored-by: Alexander V. <volas@ya.ru>
Co-authored-by: ElGitificador <168473461+ElGitificador@users.noreply.github.com>
Co-authored-by: Twaticus <46540570+Twaticus@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com>
Co-authored-by: Cameron Lennox <killer65311@gmail.com>
Co-authored-by: Tim <timothymtorres@gmail.com>
Co-authored-by: Iamgoofball <iamgoofball@gmail.com>
Co-authored-by: Layzu666 <121319428+Layzu666@users.noreply.github.com>
Co-authored-by: Arturlang <24881678+Arturlang@users.noreply.github.com>
Co-authored-by: _0Steven <42909981+00-Steven@users.noreply.github.com>
Co-authored-by: mrmanlikesbt <99309552+mrmanlikesbt@users.noreply.github.com>
Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com>
Co-authored-by: John F. Kennedy <54908920+MacaroniCritter@users.noreply.github.com>
Co-authored-by: Cursor <102828457+theselfish@users.noreply.github.com>
Co-authored-by: Josh <josh.adam.powell@gmail.com>
Co-authored-by: Josh Powell <josh.powell@softwire.com>
Co-authored-by: Yobrocharlie <Charliemiller5617@gmail.com>
Co-authored-by: Hardly3D <66234359+Hardly3D@users.noreply.github.com>
Co-authored-by: shayoki <96078776+shayoki@users.noreply.github.com>
Co-authored-by: LT3 <83487515+lessthnthree@users.noreply.github.com>
2026-05-16 00:56:00 +02:00

209 lines
7.2 KiB
Plaintext

// This element should be applied to wall-mounted machines/structures, so that if the support structure it's "hanging" from is broken or deconstructed, the wall-hung structure will deconstruct.
/datum/component/atom_mounted
/// The closed turf our object is currently linked to.
var/atom/hanging_support_atom
/datum/component/atom_mounted/Initialize(target_structure)
if(!isobj(parent) || !isatom(target_structure))
return COMPONENT_INCOMPATIBLE
. = ..()
hanging_support_atom = target_structure
RegisterSignal(hanging_support_atom, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine))
if(isturf(hanging_support_atom))
RegisterSignal(hanging_support_atom, COMSIG_TURF_CHANGE, PROC_REF(on_turf_changing))
else
RegisterSignal(hanging_support_atom, COMSIG_QDELETING, PROC_REF(on_structure_delete))
/datum/component/atom_mounted/RegisterWithParent()
ADD_TRAIT(parent, TRAIT_WALLMOUNTED, INNATE_TRAIT)
if(is_area_shuttle(get_area(parent)))
RegisterSignal(parent, COMSIG_ATOM_BEFORE_SHUTTLE_MOVE, PROC_REF(detach))
RegisterSignal(parent, COMSIG_MOVABLE_MOVED, PROC_REF(on_move))
/datum/component/atom_mounted/UnregisterFromParent()
REMOVE_TRAIT(parent, TRAIT_WALLMOUNTED, INNATE_TRAIT)
var/list/signals = list(COMSIG_MOVABLE_MOVED)
if(is_area_shuttle(get_area(parent)))
signals += COMSIG_ATOM_BEFORE_SHUTTLE_MOVE
UnregisterSignal(parent, signals)
/datum/component/atom_mounted/Destroy(force)
UnregisterSignal(hanging_support_atom, COMSIG_ATOM_EXAMINE)
hanging_support_atom = null
return ..()
/**
* When the wall is examined, explains that it's supporting the linked object.
*/
/datum/component/atom_mounted/proc/on_examine(datum/source, mob/user, list/examine_list)
SIGNAL_HANDLER
if(parent in view(user.client?.view || world.view, user))
examine_list += span_notice("\The [hanging_support_atom] is currently supporting [span_bold("\the [parent]")]. Deconstruction or excessive damage would cause it to [span_bold("fall to the ground")].")
/// When the type of turf changes, if it is changing into a floor we should drop our contents
/datum/component/atom_mounted/proc/on_turf_changing(turf/source, path, new_baseturfs, flags, post_change_callbacks)
SIGNAL_HANDLER
var/reload = FALSE
//For special effects where we explicitly want to preserve objects after change
if(flags & CHANGETURF_INHERIT_MOUNTS)
reload = TRUE
//if we transforming from open to open turf we can skip deconstruction under some conditions
else if(isopenturf(source) && ispath(path, /turf/open))
//we are transforming from plating into anything that isn't a groundless turf
if(isplatingturf(source) && !isgroundlessturf(path))
reload = TRUE
//we are transforming into plating turf
else if(ispath(LAZYACCESS(source.baseturfs, length(source.baseturfs)), /turf/open/floor/plating))
reload = TRUE
if(reload)
var/obj/target = parent
qdel(src)
post_change_callbacks += CALLBACK(target, TYPE_PROC_REF(/obj, remount))
return
drop_wallmount()
///When the atom the object is mounted on is destroyed deconstruct
/datum/component/atom_mounted/proc/on_structure_delete(datum/source, force)
SIGNAL_HANDLER
PRIVATE_PROC(TRUE)
drop_wallmount()
/// If we get dragged from our wall (by a singulo for instance) we should deconstruct
/datum/component/atom_mounted/proc/on_move(datum/source, atom/old_loc, dir, forced, list/old_locs)
SIGNAL_HANDLER
PRIVATE_PROC(TRUE)
// If we're having our lighting messed with we're likely to get dragged about
// That shouldn't lead to a decon
if(HAS_TRAIT(parent, TRAIT_LIGHTING_DEBUGGED))
return
drop_wallmount()
///Called when the object is about to be shuttle rotated so we have to delete ourself and mount again later
/datum/component/atom_mounted/proc/detach(datum/source, newT, rotation, move_mode, moving_dock)
SIGNAL_HANDLER
PRIVATE_PROC(TRUE)
qdel(src)
/**
* Handles the dropping of the linked object. This is done via deconstruction, as that should be the most sane way to handle it for most objects.
* Except for intercoms, which are handled by creating a new wallframe intercom, as they're apparently items.
*/
/datum/component/atom_mounted/proc/drop_wallmount()
PRIVATE_PROC(TRUE)
var/obj/hanging_parent = parent
hanging_parent.visible_message(message = span_warning("\The [hanging_parent] falls apart!"), vision_distance = 5)
hanging_parent.deconstruct(FALSE)
/// Returns a list of potential turfs to mount on. This should not check if those turfs are valid but only locate them
/obj/proc/get_turfs_to_mount_on()
PROTECTED_PROC(TRUE)
RETURN_TYPE(/list/turf)
//Infer using icon offsets. Can support diagonal mounting
var/pixel_direction = NONE
if(pixel_x > (ICON_SIZE_X / 2))
pixel_direction |= EAST
else if(pixel_x < -(ICON_SIZE_X / 2))
pixel_direction |= WEST
if(pixel_y > (ICON_SIZE_Y / 2))
pixel_direction |= NORTH
else if(pixel_y < -(ICON_SIZE_Y / 2))
pixel_direction |= SOUTH
. = list()
if(pixel_direction != NONE)
. += get_step(src, pixel_direction)
. += get_turf(src)
/**
* Checks if our object can mount on this turf
*
* Arguments
* * turf/target - the turf we are trying to mount on
*/
/obj/proc/is_mountable_turf(turf/target)
PROTECTED_PROC(TRUE)
SHOULD_BE_PURE(TRUE)
return isclosedturf(target)
/// Returns an list of object types we can mount on if the turf is unmountable
/obj/proc/get_mountable_objects()
PROTECTED_PROC(TRUE)
SHOULD_BE_PURE(TRUE)
RETURN_TYPE(/list/obj)
var/static/list/obj/attachables = list(
/obj/structure/table,
/obj/structure/window,
/obj/structure/fence,
/obj/structure/falsewall,
)
return attachables
/**
* Finds an support atom to hang this object on. If you need to mount the object on Late Initialize
* then pass TRUE inside Initialize() but not in LateInitialize().
* The flag is only applied if no support atom could be found during Initialize() as a last resort
*
* Arguments
* * mark_for_late_init - if TRUE will apply the MOUNT_ON_LATE_INITIALIZE which gets cleared on every call
* * late_init - should only be passed as TRUE from inside LateInitialize()
*/
/obj/proc/find_and_mount_on_atom(mark_for_late_init = FALSE, late_init = FALSE)
if(obj_flags & MOUNT_ON_LATE_INITIALIZE)
obj_flags &= ~MOUNT_ON_LATE_INITIALIZE
else if(late_init)
return TRUE
var/area/location = get_area(src)
if(!isarea(location))
return FALSE
var/msg
if(PERFORM_ALL_TESTS(maptest_log_mapping) && !mark_for_late_init)
msg = "[type] Could not find attachable object at [location.type] "
var/list/turf/attachable_turfs = get_turfs_to_mount_on()
for(var/turf/target as anything in attachable_turfs)
var/atom/attachable_atom
if(is_mountable_turf(target))
attachable_atom = target //your usual wallmount
else
var/list/obj/attachables = get_mountable_objects()
for(var/obj/attachable in target)
if(is_type_in_list(attachable, attachables))
attachable_atom = attachable
break
if(attachable_atom)
AddComponent(/datum/component/atom_mounted, attachable_atom)
if(is_area_shuttle(location))
RegisterSignal(src, COMSIG_ATOM_AFTER_SHUTTLE_MOVE, PROC_REF(remount), override = TRUE)
return TRUE
if(msg)
msg += "([target.x],[target.y],[target.z]) "
if(msg)
log_mapping(msg)
if(mark_for_late_init)
obj_flags |= MOUNT_ON_LATE_INITIALIZE
return FALSE
///Used to remount an object in special cases
/obj/proc/remount()
SIGNAL_HANDLER
PRIVATE_PROC(TRUE)
find_and_mount_on_atom()