// 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()