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:
SyncIt21
2025-12-12 12:23:22 -05:00
committed by nevimer
parent fc809d7687
commit f640a0e972
54 changed files with 228 additions and 139 deletions
+1 -1
View File
@@ -217,7 +217,7 @@
setDir(dir)
if(abs(offset_old) != APC_PIXEL_OFFSET)
log_mapping("APC: ([src]) at [AREACOORD(src)] with dir ([dir] | [uppertext(dir2text(dir))]) has pixel_[dir & (WEST|EAST) ? "x" : "y"] value [offset_old] - should be [dir & (SOUTH|EAST) ? "-" : ""][APC_PIXEL_OFFSET]. Use the directional/ helpers!")
find_and_hang_on_atom()
find_and_mount_on_atom()
// For apcs created during the round players need to configure them from scratch
else
opened = APC_COVER_OPENED
+23 -9
View File
@@ -84,11 +84,6 @@
///break if moved, if false also makes it ignore if the wall its on breaks
var/break_if_moved = TRUE
/obj/machinery/light/Move()
if(status != LIGHT_BROKEN && break_if_moved)
break_light_tube(TRUE)
return ..()
// create a new lighting fixture
/obj/machinery/light/Initialize(mapload)
. = ..()
@@ -121,9 +116,12 @@
AddElement(/datum/element/atmos_sensitive, mapload)
AddElement(/datum/element/contextual_screentip_bare_hands, rmb_text = "Remove bulb")
if(mapload)
find_and_hang_on_atom(mark_for_late_init = TRUE)
find_and_mount_on_atom(mark_for_late_init = TRUE)
/obj/machinery/light/find_and_hang_on_atom(mark_for_late_init = FALSE, late_init = FALSE)
/obj/machinery/light/get_turfs_to_mount_on()
return list(get_step(src, dir))
/obj/machinery/light/find_and_mount_on_atom(mark_for_late_init, late_init)
if(break_if_moved)
return ..()
@@ -147,6 +145,11 @@
QDEL_NULL(cell)
return ..()
/obj/machinery/light/Move()
if(status != LIGHT_BROKEN && break_if_moved)
break_light_tube(TRUE)
return ..()
/obj/machinery/light/Exited(atom/movable/gone, direction)
. = ..()
if(gone == cell)
@@ -753,8 +756,19 @@
nightshift_brightness = 4
fire_brightness = 4.5
/obj/machinery/light/floor/find_and_hang_on_atom(mark_for_late_init = FALSE, late_init = FALSE)
return //its a floor light not a wall light
/obj/machinery/light/floor/get_turfs_to_mount_on()
return list(get_turf(src))
/obj/machinery/light/floor/is_mountable_turf(turf/target)
return !isgroundlessturf(target)
/obj/machinery/light/floor/get_moutable_objects()
var/static/list/attachables = list(
/obj/structure/thermoplastic,
/obj/structure/lattice/catwalk,
)
return attachables
/obj/machinery/light/floor/get_light_offset()
return list(0, 0)
@@ -30,16 +30,19 @@
/obj/structure/light_construct/Initialize(mapload)
. = ..()
if(mapload && !find_and_hang_on_atom(mark_for_late_init = TRUE))
if(mapload && !find_and_mount_on_atom(mark_for_late_init = TRUE))
return INITIALIZE_HINT_LATELOAD
/obj/structure/light_construct/LateInitialize()
find_and_hang_on_atom(late_init = TRUE)
find_and_mount_on_atom(late_init = TRUE)
/obj/structure/light_construct/Destroy()
QDEL_NULL(cell)
return ..()
/obj/structure/light_construct/get_turfs_to_mount_on()
return list(get_step(src, dir))
/obj/structure/light_construct/get_cell()
return cell
@@ -150,7 +153,7 @@
if("floor")
new_light = new /obj/machinery/light/floor/empty(loc)
new_light.setDir(dir)
new_light.find_and_hang_on_atom()
new_light.find_and_mount_on_atom()
transfer_fingerprints_to(new_light)
if(!QDELETED(cell))
new_light.cell = cell