-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathliquid_height.dm
45 lines (39 loc) · 1.36 KB
/
liquid_height.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
/**
* Liquid Height element; for dynamically applying liquid blockages.
*
* Used for reinforced tables, sandbags, and the likes.
*/
/datum/element/liquids_height
element_flags = ELEMENT_BESPOKE
argument_hash_start_idx = 2
///Height applied by this element
var/height_applied
/datum/element/liquids_height/Attach(datum/target, height_applied)
. = ..()
if(!ismovable(target))
return ELEMENT_INCOMPATIBLE
src.height_applied = height_applied
RegisterSignal(target, COMSIG_MOVABLE_MOVED, PROC_REF(on_target_move))
var/atom/movable/movable_target = target
if(isturf(movable_target.loc))
var/turf/turf_loc = movable_target.loc
turf_loc.turf_height += height_applied
turf_loc.reasses_liquids()
/datum/element/liquids_height/Detach(atom/movable/target)
. = ..()
UnregisterSignal(target, list(COMSIG_MOVABLE_MOVED))
var/atom/movable/movable_target = target
if(isturf(movable_target.loc))
var/turf/turf_loc = movable_target.loc
turf_loc.turf_height -= height_applied
turf_loc.reasses_liquids()
/datum/element/liquids_height/proc/on_target_move(atom/movable/source, atom/OldLoc, Dir, Forced = FALSE)
SIGNAL_HANDLER
if(isturf(OldLoc))
var/turf/old_turf = OldLoc
old_turf.turf_height += height_applied
old_turf.reasses_liquids()
if(isturf(source.loc))
var/turf/new_turf = source.loc
new_turf.turf_height -= height_applied
new_turf.reasses_liquids()