-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy path_wires.dm
354 lines (300 loc) · 9.22 KB
/
_wires.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
353
354
#define MAXIMUM_EMP_WIRES 3
/proc/is_wire_tool(obj/item/I)
if(!I)
return
if(I.tool_behaviour == TOOL_WIRECUTTER || I.tool_behaviour == TOOL_MULTITOOL || I.tool_behaviour == TOOL_WIRING)
return TRUE
if(istype(I, /obj/item/assembly))
var/obj/item/assembly/A = I
if(A.attachable)
return TRUE
/atom/proc/attempt_wire_interaction(mob/user)
if(!wires)
return WIRE_INTERACTION_FAIL
if(!user.CanReach(src))
return WIRE_INTERACTION_FAIL
wires.interact(user)
return WIRE_INTERACTION_BLOCK
/datum/wires
/// The holder (atom that contains these wires).
var/atom/holder = null
/// The holder's typepath (used for sanity checks to make sure the holder is the appropriate type for these wire sets).
var/holder_type = null
/// Key that enables wire assignments to be common across different holders. If null, will use the holder_type as a key.
var/dictionary_key = null
/// The display name for the wire set shown in station blueprints. Not shown in blueprints if randomize is TRUE or it's an item NT wouldn't know about (Explosives/Nuke). Also used in the hacking interface.
var/proper_name = "Unknown"
/// List of all wires.
var/list/wires = list()
/// List of cut wires.
var/list/cut_wires = list() // List of wires that have been cut.
/// Dictionary of colours to wire.
var/list/colors = list()
/// List of attached assemblies.
var/list/assemblies = list()
/// Skill required to identify each wire, EXP_GENIUS if not specified here.
var/static/list/wire_difficulty = list(
WIRE_SHOCK = EXP_MID,
WIRE_RESET_MODULE = EXP_MID,
WIRE_ZAP = EXP_MID,
WIRE_ZAP1 = EXP_HIGH,
WIRE_ZAP2 = EXP_HIGH,
WIRE_LOCKDOWN = EXP_HIGH,
WIRE_CAMERA = EXP_HIGH,
WIRE_POWER = EXP_HIGH,
WIRE_POWER1 = EXP_MASTER,
WIRE_POWER2 = EXP_MASTER,
WIRE_IDSCAN = EXP_MASTER,
WIRE_UNBOLT = EXP_MASTER,
WIRE_BACKUP1 = EXP_MASTER,
WIRE_BACKUP2 = EXP_MASTER,
WIRE_LAWSYNC = EXP_MASTER,
WIRE_PANIC = EXP_MASTER,
WIRE_OPEN = EXP_MASTER,
WIRE_HACK = EXP_MASTER,
WIRE_AI = EXP_MASTER,
)
/// If every instance of these wires should be random. Prevents wires from showing up in station blueprints.
var/randomize = FALSE
/datum/wires/New(atom/holder)
..()
if(!istype(holder, holder_type))
CRASH("Wire holder is not of the expected type!")
src.holder = holder
// If there is a dictionary key set, we'll want to use that. Otherwise, use the holder type.
var/key = dictionary_key ? dictionary_key : holder_type
if(randomize)
randomize()
else
if(!GLOB.wire_color_directory[key])
randomize()
GLOB.wire_color_directory[key] = colors
GLOB.wire_name_directory[key] = proper_name
else
colors = GLOB.wire_color_directory[key]
/datum/wires/Destroy()
holder = null
assemblies = list()
return ..()
/datum/wires/proc/add_duds(duds)
while(duds)
var/dud = WIRE_DUD_PREFIX + "[--duds]"
if(dud in wires)
continue
wires += dud
/datum/wires/proc/randomize()
var/static/list/possible_colors = list(
"blue",
"brown",
"crimson",
"cyan",
"gold",
"grey",
"green",
"magenta",
"orange",
"pink",
"purple",
"red",
"silver",
"violet",
"white",
"yellow"
)
var/list/my_possible_colors = possible_colors.Copy()
for(var/wire in shuffle(wires))
colors[pick_n_take(my_possible_colors)] = wire
/datum/wires/proc/shuffle_wires()
colors.Cut()
randomize()
/datum/wires/proc/repair()
cut_wires.Cut()
/datum/wires/proc/get_wire(color)
return colors[color]
/datum/wires/proc/get_color_of_wire(wire_type)
for(var/color in colors)
var/other_type = colors[color]
if(wire_type == other_type)
return color
/datum/wires/proc/get_attached(color)
if(assemblies[color])
return assemblies[color]
return null
/datum/wires/proc/is_attached(color)
if(assemblies[color])
return TRUE
/datum/wires/proc/is_cut(wire)
return (wire in cut_wires)
/datum/wires/proc/is_color_cut(color)
return is_cut(get_wire(color))
/datum/wires/proc/is_all_cut()
if(cut_wires.len == wires.len)
return TRUE
/datum/wires/proc/is_dud(wire)
return findtext(wire, WIRE_DUD_PREFIX, 1, length(WIRE_DUD_PREFIX) + 1)
/datum/wires/proc/is_dud_color(color)
return is_dud(get_wire(color))
/datum/wires/proc/is_revealed(color, mob/user)
// Admin ghost can see a purpose of each wire.
if(IsAdminGhost(user))
return TRUE
// Same for anyone with an abductor multitool.
else if(user.is_holding_item_of_type(/obj/item/multitool/abductor))
return TRUE
// Station blueprints do that too, but only if the wires are not randomized.
else if(!randomize)
if(user.is_holding_item_of_type(/obj/item/areaeditor/blueprints))
return TRUE
else if(user.is_holding_item_of_type(/obj/item/photo))
var/obj/item/photo/P = user.is_holding_item_of_type(/obj/item/photo)
if(P.picture.has_blueprints) //if the blueprints are in frame
return TRUE
var/skill_required = wire_difficulty[get_wire(color)]
if(skill_required && user.skill_check(SKILL_TECHNICAL, skill_required))
return TRUE
return FALSE
/datum/wires/proc/cut(wire, mob/user)
if(is_cut(wire))
cut_wires -= wire
on_cut(wire, mend = TRUE)
else
cut_wires += wire
on_cut(wire, mend = FALSE)
if(user)
user.add_exp(SKILL_TECHNICAL, 50, "[wire]_[type]")
/datum/wires/proc/cut_color(color)
cut(get_wire(color))
/datum/wires/proc/cut_random()
cut(wires[rand(1, wires.len)])
/datum/wires/proc/cut_all()
for(var/wire in wires)
cut(wire)
/datum/wires/proc/pulse(wire, mob/user)
if(is_cut(wire))
return
on_pulse(wire, user)
if(user)
user.add_exp(SKILL_TECHNICAL, 50, "[wire]_[type]")
/datum/wires/proc/pulse_color(color, mob/living/user)
pulse(get_wire(color), user)
/datum/wires/proc/pulse_assembly(obj/item/assembly/S)
for(var/color in assemblies)
if(S == assemblies[color])
pulse_color(color)
return TRUE
/datum/wires/proc/attach_assembly(color, obj/item/assembly/S)
if(S && istype(S) && S.attachable && !is_attached(color))
assemblies[color] = S
S.forceMove(holder)
S.connected = src
return S
/datum/wires/proc/detach_assembly(color)
var/obj/item/assembly/S = get_attached(color)
if(S && istype(S))
assemblies -= color
S.connected = null
S.forceMove(holder.drop_location())
return S
/datum/wires/proc/emp_pulse()
var/list/possible_wires = shuffle(wires)
var/remaining_pulses = MAXIMUM_EMP_WIRES
for(var/wire in possible_wires)
if(prob(33))
pulse(wire)
remaining_pulses--
if(!remaining_pulses)
break
// Overridable Procs
/datum/wires/proc/interactable(mob/user)
return TRUE
/datum/wires/proc/get_status()
return list()
/datum/wires/proc/on_cut(wire, mend = FALSE)
return
/datum/wires/proc/on_pulse(wire, user)
return
// End Overridable Procs
/datum/wires/proc/interact(mob/user)
if(!interactable(user))
return
ui_interact(user)
for(var/A in assemblies)
var/obj/item/I = assemblies[A]
if(istype(I) && I.on_found(user))
return
/datum/wires/ui_host()
return holder
/datum/wires/ui_status(mob/user)
if(interactable(user))
return ..()
return UI_CLOSE
/datum/wires/ui_state(mob/user)
return GLOB.physical_state
/datum/wires/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if (!ui)
ui = new(user, src, "Wires", "[holder.name] Wires")
ui.open()
/datum/wires/ui_data(mob/user)
var/list/data = list()
var/list/payload = list()
var/colorblind = HAS_TRAIT(user, TRAIT_COLORBLIND)
for(var/color in colors)
payload.Add(list(list(
"color" = color,
"wire" = (!colorblind && !is_dud_color(color) && is_revealed(color, user)) ? get_wire(color) : null,
"cut" = is_color_cut(color),
"attached" = is_attached(color)
)))
data["wires"] = payload
data["status"] = get_status()
data["proper_name"] = (proper_name != "Unknown") ? proper_name : null
data["colorblind"] = colorblind
return data
/datum/wires/ui_act(action, params)
if(..() || !interactable(usr))
return
if(!holder) // wires with no holder makes no sense to exist and probably breaks things, so catch any instances of that
CRASH("[type] has no holder!")
var/target_wire = params["wire"]
var/mob/living/user = usr
var/obj/item/tool
var/tool_delay = max((0.5**user.get_skill(SKILL_TECHNICAL)) SECONDS, 0)
if(tool_delay < 0.2 SECONDS) // effectively already instant
tool_delay = 0
switch(action)
if("cut")
tool = user.is_holding_tool_quality(TOOL_WIRECUTTER)
if(tool?.use_tool(holder, user, tool_delay) || IsAdminGhost(usr))
tool.play_tool_sound(holder, 20)
cut_color(target_wire)
. = TRUE
else if(!tool)
to_chat(user, span_warning("You need wirecutters!"))
if("pulse")
tool = user.is_holding_tool_quality(TOOL_MULTITOOL)
if(tool?.use_tool(holder, user, tool_delay) || IsAdminGhost(usr))
tool.play_tool_sound(holder, 20)
pulse_color(target_wire, user)
. = TRUE
else if(!tool)
to_chat(user, span_warning("You need a multitool!"))
if("attach")
if(is_attached(target_wire))
if(!do_after(user, tool_delay, holder))
return
user.put_in_hands(detach_assembly(target_wire))
. = TRUE
else
tool = user.get_active_held_item()
if(istype(tool, /obj/item/assembly) && tool?.use_tool(holder, user, tool_delay))
var/obj/item/assembly/A = tool
if(A.attachable)
if(!user.temporarilyRemoveItemFromInventory(A))
return
if(!attach_assembly(target_wire, A))
A.forceMove(user.drop_location())
. = TRUE
else
to_chat(user, span_warning("You need an attachable assembly!"))
#undef MAXIMUM_EMP_WIRES