mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-21 04:57:57 +01:00
Enhances algorithm for finding an atom mount (#94076)
## About The Pull Request Depends on #94064 for the unit test but offers a better method for finding an atom to mount on - Finding a mount now takes into consideration the objects pixel x & y offsets meaning diagonal mounting is now supported. Gives great flexibility for mappers - If you don't want to use pixel offsets but default back to using the objects direction that behaviour is still preserved. Useful if your object uses directional icon states(lights & cameras for now) AND don't use offsets - If no direction could be specified then as the last resort it defaults back to the objects local turf for mounting ## Changelog 🆑 fix: all mounted objects on tables, fences, windows & walls should fall of correctly when the atom it is placed on is destroyed fix: security telescreen now falls off when their mounted wall is destroyed fix: defib wall mount falls off when their mounted wall is destroyed fix: floor lights are mounted to the ground/catwalk/tram floor they are sitting on meaning destroying it will destroy the light fix: wall mounted plaques now fall off when their mounted wall is destroyed /🆑
This commit is contained in:
@@ -69,6 +69,55 @@
|
||||
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_moutable_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().
|
||||
@@ -78,7 +127,7 @@
|
||||
* * 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_hang_on_atom(mark_for_late_init = FALSE, late_init = FALSE)
|
||||
/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)
|
||||
@@ -92,19 +141,13 @@
|
||||
if(PERFORM_ALL_TESTS(focus_only/atom_mounted) && !mark_for_late_init)
|
||||
msg = "[type] Could not find attachable object at [location.type] "
|
||||
|
||||
var/list/turf/attachable_turfs = list()
|
||||
attachable_turfs += get_step(src, dir)
|
||||
attachable_turfs += get_turf(src)
|
||||
var/list/turf/attachable_turfs = get_turfs_to_mount_on()
|
||||
for(var/turf/target as anything in attachable_turfs)
|
||||
var/atom/attachable_atom
|
||||
if(isclosedturf(target))
|
||||
if(is_mountable_turf(target))
|
||||
attachable_atom = target //your usual wallmount
|
||||
else
|
||||
var/static/list/attachables = list(
|
||||
/obj/structure/table,
|
||||
/obj/structure/window,
|
||||
/obj/structure/fence,
|
||||
) //list of structures to mount on
|
||||
var/list/obj/attachables = get_moutable_objects()
|
||||
for(var/obj/attachable in target)
|
||||
if(is_type_in_list(attachable, attachables))
|
||||
attachable_atom = attachable
|
||||
Reference in New Issue
Block a user