-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathRCL.dm
352 lines (301 loc) · 9.97 KB
/
RCL.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/obj/item/rcl
name = "rapid cable layer"
desc = "A device used to rapidly deploy cables. It has screws on the side which can be removed to slide off the cables. Do not use without insulation!"
icon = 'icons/obj/tools.dmi'
icon_state = "rcl-0"
item_state = "rcl-0"
opacity = FALSE
force = 5 //Plastic is soft
throwforce = 5
throw_speed = 1
throw_range = 7
w_class = WEIGHT_CLASS_NORMAL
actions_types = list(/datum/action/item_action/rcl_col,/datum/action/item_action/rcl_gui)
lefthand_file = 'icons/mob/inhands/equipment/tools_lefthand.dmi'
righthand_file = 'icons/mob/inhands/equipment/tools_righthand.dmi'
var/obj/structure/cable/last
var/obj/item/stack/cable_coil/loaded
var/max_amount = 90
var/active = FALSE
var/list/colors = list("red", "yellow", "green", "blue", "pink", "orange", "cyan", "white")
var/current_color_index = 1
var/ghetto = FALSE
var/datum/radial_menu/persistent/wiring_gui_menu
var/mob/listeningTo
/obj/item/rcl/Initialize(mapload)
. = ..()
AddComponent(/datum/component/two_handed, \
wield_callback = CALLBACK(src, PROC_REF(on_wield)), \
unwield_callback = CALLBACK(src, PROC_REF(on_unwield)), \
)
/// triggered on wield of two handed item
/obj/item/rcl/proc/on_wield(obj/item/source, mob/user)
active = TRUE
/// triggered on unwield of two handed item
/obj/item/rcl/proc/on_unwield(obj/item/source, mob/user)
active = FALSE
/obj/item/rcl/attackby(obj/item/W, mob/user)
if(istype(W, /obj/item/stack/cable_coil))
var/obj/item/stack/cable_coil/C = W
if(!loaded)
if(!user.transferItemToLoc(W, src))
to_chat(user, span_warning("[src] is stuck to your hand!"))
return
else
loaded = W //W.loc is src at this point.
loaded.max_amount = max_amount //We store a lot.
return
if(loaded.amount < max_amount)
var/transfer_amount = min(max_amount - loaded.amount, C.amount)
C.use(transfer_amount)
loaded.amount += transfer_amount
else
return
update_appearance(UPDATE_ICON)
to_chat(user, span_notice("You add the cables to [src]. It now contains [loaded.amount]."))
else if(W.tool_behaviour == TOOL_SCREWDRIVER)
if(!loaded)
return
if(ghetto && prob(10)) //Is it a ghetto RCL? If so, give it a 10% chance to fall apart
to_chat(user, span_warning("You attempt to loosen the securing screws on the side, but it falls apart!"))
while(loaded.amount > 30) //There are only two kinds of situations: "nodiff" (60,90), or "diff" (31-59, 61-89)
var/diff = loaded.amount % 30
if(diff)
loaded.use(diff)
new /obj/item/stack/cable_coil(get_turf(user), diff)
else
loaded.use(30)
new /obj/item/stack/cable_coil(get_turf(user), 30)
qdel(src)
return
to_chat(user, span_notice("You loosen the securing screws on the side, allowing you to lower the guiding edge and retrieve the wires."))
while(loaded.amount > 30) //There are only two kinds of situations: "nodiff" (60,90), or "diff" (31-59, 61-89)
var/diff = loaded.amount % 30
if(diff)
loaded.use(diff)
new /obj/item/stack/cable_coil(get_turf(user), diff)
else
loaded.use(30)
new /obj/item/stack/cable_coil(get_turf(user), 30)
loaded.max_amount = initial(loaded.max_amount)
if(!user.put_in_hands(loaded))
loaded.forceMove(get_turf(user))
loaded = null
update_appearance(UPDATE_ICON)
else
..()
/obj/item/rcl/examine(mob/user)
. = ..()
if(loaded)
. += span_info("It contains [loaded.amount]/[max_amount] cables.")
/obj/item/rcl/Destroy()
QDEL_NULL(loaded)
last = null
listeningTo = null
QDEL_NULL(wiring_gui_menu)
return ..()
/obj/item/rcl/update_icon_state()
. = ..()
if(!loaded)
icon_state = "rcl-0"
item_state = "rcl-0"
return
switch(loaded.amount)
if(61 to INFINITY)
icon_state = "rcl-30"
item_state = "rcl"
if(31 to 60)
icon_state = "rcl-20"
item_state = "rcl"
if(1 to 30)
icon_state = "rcl-10"
item_state = "rcl"
else
icon_state = "rcl-0"
item_state = "rcl-0"
/obj/item/rcl/proc/is_empty(mob/user, loud = 1)
update_appearance(UPDATE_ICON)
if(!loaded || !loaded.amount)
if(loud)
to_chat(user, span_notice("The last of the cables unreel from [src]."))
if(loaded)
QDEL_NULL(loaded)
loaded = null
QDEL_NULL(wiring_gui_menu)
return TRUE
return FALSE
/obj/item/rcl/pickup(mob/user)
..()
getMobhook(user)
/obj/item/rcl/dropped(mob/wearer)
..()
UnregisterSignal(wearer, COMSIG_MOVABLE_MOVED)
listeningTo = null
last = null
QDEL_NULL(wiring_gui_menu)
/obj/item/rcl/attack_self(mob/user)
..()
if(!active)
last = null
else if(!last)
for(var/obj/structure/cable/C in get_turf(user))
if(C.d1 == FALSE || C.d2 == FALSE)
last = C
break
/obj/item/rcl/proc/getMobhook(mob/to_hook)
if(listeningTo == to_hook)
return
if(listeningTo)
UnregisterSignal(listeningTo, COMSIG_MOVABLE_MOVED)
listeningTo = to_hook
RegisterSignal(listeningTo, COMSIG_MOVABLE_MOVED, PROC_REF(trigger))
/obj/item/rcl/proc/trigger(mob/user)
if(active)
layCable(user)
if(wiring_gui_menu) //update the wire options as you move
wiringGuiUpdate(user)
//previous contents of trigger(), lays cable each time the player moves
/obj/item/rcl/proc/layCable(mob/user)
if(!isturf(user.loc))
return
if(is_empty(user, 0))
to_chat(user, span_warning("\The [src] is empty!"))
return
if(prob(2) && ghetto) //Give ghetto RCLs a 2% chance to jam, requiring it to be reactviated manually.
to_chat(user, span_warning("[src]'s wires jam!"))
return
else
if(last)
if(get_dist(last, user) == 1) //hacky, but it works
var/turf/T = get_turf(user)
if(T.underfloor_accessibility < UNDERFLOOR_INTERACTABLE || !T.can_have_cabling())
last = null
return
if(get_dir(last, user) == last.d2)
//Did we just walk backwards? Well, that's the one direction we CAN'T complete a stub.
last = null
return
loaded.cable_join(last, user, FALSE)
if(is_empty(user))
return //If we've run out, display message and exit
else
last = null
loaded.color = colors[current_color_index]
last = loaded.place_turf(get_turf(src), user, turn(user.dir, 180))
is_empty(user) //If we've run out, display message
update_appearance(UPDATE_ICON)
//searches the current tile for a stub cable of the same colour
/obj/item/rcl/proc/findLinkingCable(mob/user)
var/turf/T
if(!isturf(user.loc))
return
T = get_turf(user)
if(T.underfloor_accessibility < UNDERFLOOR_INTERACTABLE || !T.can_have_cabling())
return
for(var/obj/structure/cable/C in T)
if(!C)
continue
if(C.cable_color != GLOB.cable_colors[colors[current_color_index]])
continue
if(C.d1 == 0)
return C
return
/obj/item/rcl/proc/wiringGuiGenerateChoices(mob/user)
var/fromdir = 0
var/obj/structure/cable/linkingCable = findLinkingCable(user)
if(linkingCable)
fromdir = linkingCable.d2
var/list/wiredirs = list("1","5","4","6","2","10","8","9")
for(var/icondir in wiredirs)
var/dirnum = text2num(icondir)
var/cablesuffix = "[min(fromdir,dirnum)]-[max(fromdir,dirnum)]"
if(fromdir == dirnum) //cables can't loop back on themselves
cablesuffix = "invalid"
var/image/img = image(icon = 'icons/mob/radial.dmi', icon_state = "cable_[cablesuffix]")
img.color = GLOB.cable_colors[colors[current_color_index]]
wiredirs[icondir] = img
return wiredirs
/obj/item/rcl/proc/showWiringGui(mob/user)
var/list/choices = wiringGuiGenerateChoices(user)
wiring_gui_menu = show_radial_menu_persistent(user, src , choices, select_proc = CALLBACK(src, PROC_REF(wiringGuiReact), user), radius = 42)
/obj/item/rcl/proc/wiringGuiUpdate(mob/user)
if(!wiring_gui_menu)
return
wiring_gui_menu.entry_animation = FALSE //stop the open anim from playing each time we update
var/list/choices = wiringGuiGenerateChoices(user)
wiring_gui_menu.change_choices(choices,FALSE)
//Callback used to respond to interactions with the wiring menu
/obj/item/rcl/proc/wiringGuiReact(mob/living/user,choice)
if(!choice) //close on a null choice (the center button)
QDEL_NULL(wiring_gui_menu)
return
choice = text2num(choice)
if(!isturf(user.loc))
return
if(is_empty(user, 0))
to_chat(user, span_warning("\The [src] is empty!"))
return
var/turf/T = get_turf(user)
if(T.underfloor_accessibility < UNDERFLOOR_INTERACTABLE || !T.can_have_cabling())
return
loaded.color = colors[current_color_index]
var/obj/structure/cable/linkingCable = findLinkingCable(user)
if(linkingCable)
if(choice != linkingCable.d2)
loaded.cable_join(linkingCable, user, FALSE, choice)
last = null
else
last = loaded.place_turf(get_turf(src), user, choice)
is_empty(user) //If we've run out, display message
wiringGuiUpdate(user)
/obj/item/rcl/pre_loaded/Initialize(mapload) //Comes preloaded with cable, for testing stuff
. = ..()
loaded = new(src)
loaded.max_amount = max_amount
loaded.amount = max_amount
update_appearance(UPDATE_ICON)
/obj/item/rcl/Initialize(mapload)
. = ..()
update_appearance(UPDATE_ICON)
/obj/item/rcl/ui_action_click(mob/user, action)
if(istype(action, /datum/action/item_action/rcl_col))
current_color_index++;
if (current_color_index > colors.len)
current_color_index = 1
var/cwname = colors[current_color_index]
to_chat(user, "Color changed to [cwname]!")
if(loaded)
loaded.color = colors[current_color_index]
if(wiring_gui_menu)
wiringGuiUpdate(user)
else if(istype(action, /datum/action/item_action/rcl_gui))
if(wiring_gui_menu) //The menu is already open, close it
QDEL_NULL(wiring_gui_menu)
else //open the menu
showWiringGui(user)
/obj/item/rcl/ghetto
actions_types = list()
max_amount = 30
name = "makeshift rapid cable layer"
ghetto = TRUE
/obj/item/rcl/ghetto/update_icon_state()
. = ..()
if(!loaded)
icon_state = "rclg-0"
item_state = "rclg-0"
return
switch(loaded.amount)
if(1 to INFINITY)
icon_state = "rclg-1"
item_state = "rcl"
else
icon_state = "rclg-1"
item_state = "rclg-1"
/datum/action/item_action/rcl_col
name = "Change Cable Color"
button_icon = 'icons/mob/actions/actions_items.dmi'
button_icon_state = "rcl_rainbow"
/datum/action/item_action/rcl_gui
name = "Toggle Fast Wiring Gui"
button_icon = 'icons/mob/actions/actions_items.dmi'
button_icon_state = "rcl_gui"