-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathwall_mounted.dm
59 lines (53 loc) · 2.66 KB
/
wall_mounted.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// This element should be applied to wall-mounted machines/structures, so that if the wall it's "hanging" from is broken or deconstructed, the wall-hung structure will deconstruct.
/datum/component/wall_mounted
dupe_mode = COMPONENT_DUPE_ALLOWED
/// The wall our object is currently linked to.
var/turf/hanging_wall_turf
/// Callback to the parent's proc to call on the linked object when the wall disappear's or changes.
var/datum/callback/on_drop
/datum/component/wall_mounted/Initialize(target_wall, on_drop_callback)
. = ..()
if(!isobj(parent))
return COMPONENT_INCOMPATIBLE
if(!isturf(target_wall))
return COMPONENT_INCOMPATIBLE
hanging_wall_turf = target_wall
on_drop = on_drop_callback
/datum/component/wall_mounted/RegisterWithParent()
RegisterSignal(hanging_wall_turf, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine))
RegisterSignal(parent, COMSIG_QDELETING, PROC_REF(on_linked_destroyed))
/datum/component/wall_mounted/UnregisterFromParent()
UnregisterSignal(hanging_wall_turf, list(COMSIG_ATOM_EXAMINE, COMSIG_TURF_CHANGE))
UnregisterSignal(parent, list(COMSIG_QDELETING, COMSIG_MOVABLE_MOVED))
hanging_wall_turf = null
/**
* Basic reference handling if the hanging/linked object is destroyed first.
*/
/datum/component/wall_mounted/proc/on_linked_destroyed()
SIGNAL_HANDLER
if(!QDELING(src))
qdel(src)
/**
* When the wall is examined, explains that it's supporting the linked object.
*/
/datum/component/wall_mounted/proc/on_examine(datum/source, mob/user, list/examine_list)
SIGNAL_HANDLER
examine_list += span_notice("\The [hanging_wall_turf] is currently supporting [span_bold("[parent]")]. Deconstruction or excessive damage would cause it to [span_bold("fall to the ground")].")
/**
* Checks object direction and then verifies if there's a wall in that direction. Finally, applies a wall_mounted component to the object.
*
* @param directional If TRUE, will use the direction of the object to determine the wall to attach to. If FALSE, will use the object's loc.
* @param custom_drop_callback If set, will use this callback instead of the default deconstruct callback.
*/
/obj/proc/find_and_hang_on_wall(directional = TRUE, custom_drop_callback)
if(istype(get_area(src), /area/shuttle))
return FALSE //For now, we're going to keep the component off of shuttles to avoid the turf changing issue. We'll hit that later really;
var/turf/attachable_wall
if(directional)
attachable_wall = get_step(src, dir)
else
attachable_wall = loc ///Pull from the curent object loc
if(!iswallturf(attachable_wall))
return FALSE//Nothing to latch onto, or not the right thing.
src.AddComponent(/datum/component/wall_mounted, attachable_wall, custom_drop_callback)
return TRUE