Skip to content

Commit dae1603

Browse files
committed
tetherrrs
1 parent 188ac9b commit dae1603

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

code/datums/components/tether.dm

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
var/datum/movement_detector/parent_tracker
1111
var/datum/beam/beam
1212
var/atom/movable/tether_visual_target
13+
var/tether_name
14+
var/last_movement = 0
1315

14-
/datum/component/tether/Initialize(tethered_atom_movable, range = 2, durability = INFINITY, tether_icon_state = "tether")
16+
/datum/component/tether/Initialize(tethered_atom_movable, range = 2, durability = INFINITY, tether_icon_state = "tether", tether_name = "tether")
1517
. = ..()
1618
if(!isatom(parent) || !ismovable(tethered_atom_movable))
1719
return COMPONENT_INCOMPATIBLE
@@ -20,10 +22,11 @@
2022
src.max_range = range
2123
src.durability = durability // movement is bugged right now. Durability wears out 3 times faster than expected. 1 durability should last 1 tile.
2224
src.tether_icon_state = tether_icon_state
25+
src.tether_name = tether_name
2326

2427
RegisterSignal(parent, COMSIG_MOVABLE_PRE_MOVE, PROC_REF(on_movement))
2528
RegisterSignal(tethered_atom_movable, COMSIG_MOVABLE_PRE_MOVE, PROC_REF(pre_tethered_movement))
26-
RegisterSignal(tethered_atom_movable, COMSIG_ITEM_EQUIPPED, PROC_REF(equipped))
29+
RegisterSignal(tethered_atom_movable, COMSIG_ATOM_ATTACK_HAND, PROC_REF(can_equip))
2730
parent_tracker = new /datum/movement_detector(parent, CALLBACK(src, PROC_REF(parent_check_bounds)))
2831
tether_tracker = new /datum/movement_detector(tethered_atom_movable, CALLBACK(src, PROC_REF(check_bounds)))
2932
parent_tracker.fix_signal()
@@ -61,6 +64,8 @@
6164
// check if the item is in range. If not, try to move it towards the parent.
6265
if(get_dist(get_turf(tethered_to), newloc) <= max_range)
6366
return
67+
if(source.pulledby == tethered_to.loc)
68+
return
6469
if(tether_move_towards_parent(newloc))
6570
return
6671
if(get_dir(parent, newloc) & get_dir(parent, tethered_to))
@@ -82,16 +87,18 @@
8287
to_chat(atom, "<span class='warning'>You can't move in that direction with the [tethered_to] tethered to you!</span>")
8388
return COMPONENT_MOVABLE_BLOCK_PRE_MOVE
8489

85-
// /datum/component/tether/proc/equipped(atom/movable/source, mob/user, slot)
86-
// // Check to make sure we dont go into an inventory outside of our range
87-
// if(get_dist(get_turf(parent), get_turf(user)) <= max_range)
88-
// return
89-
// addtimer(CALLBACK(src, PROC_REF(tether_move_towards_parent)), 1) // let the tick finish first before dropping it
90+
/datum/component/tether/proc/can_equip(atom/source, mob/user)
91+
// Check to make sure we dont go into an inventory outside of our range
92+
if(get_dist(get_turf(parent), get_turf(user)) > max_range)
93+
to_chat(user, "<span class='warning'>You try to pick up [tethered_to], you can't pull it's [tether_name] any farther!</span>")
94+
return COMPONENT_CANCEL_ATTACK_CHAIN
9095

9196
/datum/component/tether/proc/parent_check_bounds(atom/movable/source, atom/mover, atom/old_loc, direction)
9297
// check to see if the parent has moved out of range (while inside another objects contents). If it has, pull the tether towards the parent.
9398
if(get_dist(get_turf(parent), get_turf(tethered_to)) <= max_range)
9499
return
100+
if(source.pulledby == tethered_to.loc)
101+
return
95102
tether_move_towards_parent()
96103

97104
/datum/component/tether/proc/check_bounds(atom/movable/source, atom/mover, atom/old_loc, direction)
@@ -100,13 +107,14 @@
100107
make_beam(mover)
101108
if(get_dist(get_turf(parent), get_turf(tethered_to)) <= max_range)
102109
return
110+
if(ismovable(mover))
111+
var/atom/movable/a_mover = mover
112+
if(a_mover.pulledby == parent || a_mover.pulling == parent)
113+
return
103114
tether_move_towards_parent()
104115

105116
/datum/component/tether/proc/tether_move_towards_parent(parent_newloc)
106-
if(QDELETED(tethered_to) || !istype(tethered_to))
107-
return TRUE
108-
durability_cost()
109-
if(QDELETED(tethered_to) || !istype(tethered_to))
117+
if(QDELETED(tethered_to) || !istype(tethered_to) || last_movement == world.time)
110118
return TRUE
111119
var/atom/current_loc = tethered_to.loc
112120
var/i = 0
@@ -118,28 +126,31 @@
118126
M.drop_item_to_ground(tethered_to)
119127
current_loc = tethered_to.loc
120128
break
121-
else if(istype(current_loc, /obj/item/storage))
129+
if(istype(current_loc, /obj/item/storage))
122130
var/obj/item/storage/S = current_loc
123131
S.remove_from_storage(tethered_to, get_turf(tethered_to))
124132
current_loc = tethered_to.loc
125133
break
126-
else if(istype(current_loc, /obj/structure/closet))
134+
if(istype(current_loc, /obj/structure/closet))
127135
var/obj/structure/closet/C = current_loc
128-
if(!C.can_open())
129-
return
130-
C.open()
131-
current_loc = tethered_to.loc
132-
break
133-
else if(ismovable(current_loc))
136+
if(C.can_open())
137+
C.open()
138+
current_loc = tethered_to.loc
139+
break
140+
if(ismovable(current_loc))
134141
var/atom/movable/AM = current_loc
135142
if(AM.anchored)
136143
return FALSE
137144
if(isturf(AM.loc))
145+
last_movement = world.time
146+
durability_cost()
138147
step_towards(AM, get_turf(parent)) // holy shitcode
139148
return get_dist(get_turf(parent_newloc || parent), get_turf(tethered_to)) <= max_range
140149
current_loc = current_loc.loc
141150
if(get_dist(get_turf(parent), get_turf(tethered_to)) <= max_range)
142151
return TRUE
152+
last_movement = world.time
153+
durability_cost()
143154
if(!step_towards(tethered_to, get_turf(parent))) // shitcode
144155
return durability_cost(2) // use 3 total durability
145156
return TRUE
@@ -154,7 +165,7 @@
154165
return
155166
durability -= cost
156167
if(durability <= 0 && !QDELETED(tethered_to))
157-
tethered_to.visible_message("<span class='warning'>[tethered_to]'s tether wears out and snaps!</span>")
168+
tethered_to.visible_message("<span class='warning'>[tethered_to]'s [tether_name] wears out and snaps back!</span>")
158169
terminate()
159170
return TRUE // it breaks, let the parent move outside of the range again
160171
return FALSE

code/modules/reagents/reagent_containers/iv_bag.dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@
6666
if(!injection_target)
6767
return
6868
if(istype(loc, /obj/machinery/iv_drip))
69-
injection_target.AddComponent(/datum/component/tether, src, 2, 50, "iv_tether")
69+
injection_target.AddComponent(/datum/component/tether, src, 2, 50, "iv_tether", "tubing")
7070
else
71-
injection_target.AddComponent(/datum/component/tether, src, 1, 5, "iv_tether")
71+
injection_target.AddComponent(/datum/component/tether, src, 1, 5, "iv_tether", "tubing")
7272

7373
/obj/item/reagent_containers/iv_bag/proc/end_processing(send_signal = TRUE)
7474
if(injection_target)

0 commit comments

Comments
 (0)