-
Notifications
You must be signed in to change notification settings - Fork 555
/
chem_dispenser.dm
336 lines (299 loc) · 9.31 KB
/
chem_dispenser.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
#define DISPENSER_UNHACKABLE -1
#define DISPENSER_NOT_HACKED 0
#define DISPENSER_HACKED 1
/obj/structure/machinery/chem_dispenser
name = "chemical dispenser"
desc = "A complex machine for mixing elements into chemicals. A Wey-Yu product."
density = TRUE
anchored = TRUE
icon = 'icons/obj/structures/machinery/science_machines.dmi'
icon_state = "dispenser"
use_power = USE_POWER_NONE
wrenchable = FALSE
idle_power_usage = 40
layer = BELOW_OBJ_LAYER //So beakers reliably appear above it
var/req_skill = SKILL_MEDICAL
var/req_skill_level = SKILL_MEDICAL_DOCTOR
var/ui_title = "Chem Dispenser 5000"
var/obj/structure/machinery/chem_storage/chem_storage
var/network = "Ground"
var/amount = 30
var/accept_beaker_only = TRUE
var/obj/item/reagent_container/beaker = null
var/ui_check = 0
var/static/list/possible_transfer_amounts = list(5,10,20,30,40)
var/list/dispensable_reagents = list(
"hydrogen",
"lithium",
"carbon",
"nitrogen",
"oxygen",
"fluorine",
"sodium",
"aluminum",
"silicon",
"phosphorus",
"sulfur",
"chlorine",
"potassium",
"iron",
"copper",
"mercury",
"radium",
"water",
"ethanol",
"sugar",
"sulphuric acid",
)
/// Has it been hacked
var/hacked_check = DISPENSER_UNHACKABLE
/// Additional reagents gotten when it is hacked
var/hacked_reagents = list()
/obj/structure/machinery/chem_dispenser/medbay
network = "Medbay"
/obj/structure/machinery/chem_dispenser/research
network = "Research"
/obj/structure/machinery/chem_dispenser/process()
if(!chem_storage)
chem_storage = GLOB.chemical_data.connect_chem_storage(network)
/obj/structure/machinery/chem_dispenser/Initialize()
. = ..()
dispensable_reagents = sortList(dispensable_reagents)
start_processing()
/obj/structure/machinery/chem_dispenser/Destroy()
if(!chem_storage)
chem_storage = GLOB.chemical_data.disconnect_chem_storage(network)
return ..()
/obj/structure/machinery/chem_dispenser/ex_act(severity)
switch(severity)
if(EXPLOSION_THRESHOLD_LOW to EXPLOSION_THRESHOLD_MEDIUM)
if(prob(50))
deconstruct(FALSE)
return
if(EXPLOSION_THRESHOLD_MEDIUM to INFINITY)
deconstruct(FALSE)
return
/obj/structure/machinery/chem_dispenser/update_icon()
. = ..()
overlays.Cut()
if(beaker)
overlays += "+beaker[rand(1, 5)]"
if(!inoperable())
overlays += "+onlight"
/obj/structure/machinery/chem_dispenser/on_stored_atom_del(atom/movable/AM)
if(AM == beaker)
beaker = null
/obj/structure/machinery/chem_dispenser/proc/replace_beaker(mob/living/user, obj/item/reagent_container/new_beaker)
if(beaker)
beaker.forceMove(src.loc)
if(user && Adjacent(user))
user.put_in_hands(beaker)
if(new_beaker)
beaker = new_beaker
else
beaker = null
update_icon()
SStgui.update_uis(src)
return TRUE
/obj/structure/machinery/chem_dispenser/clicked(mob/user, list/mods)
if(mods["alt"])
if(!CAN_PICKUP(user, src))
return ..()
replace_beaker(user)
return ..()
// TGUI \\
/obj/structure/machinery/chem_dispenser/ui_status(mob/user, datum/ui_state/state)
. = ..()
if(inoperable())
return UI_CLOSE
/obj/structure/machinery/chem_dispenser/tgui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "ChemDispenser", name)
ui.open()
/obj/structure/machinery/chem_dispenser/ui_static_data(mob/user)
. = list()
.["beakerTransferAmounts"] = possible_transfer_amounts
/obj/structure/machinery/chem_dispenser/ui_data(mob/user)
. = list()
.["amount"] = amount
.["energy"] = floor(chem_storage.energy)
.["maxEnergy"] = floor(chem_storage.max_energy)
.["isBeakerLoaded"] = beaker ? 1 : 0
var/list/beakerContents = list()
var/beakerCurrentVolume = 0
if(beaker && beaker.reagents && length(beaker.reagents.reagent_list))
for(var/datum/reagent/current_reagent in beaker.reagents.reagent_list)
beakerContents += list(list("name" = current_reagent.name, "volume" = current_reagent.volume)) // list in a list because Byond merges the first list...
beakerCurrentVolume += current_reagent.volume
.["beakerContents"] = beakerContents
if (beaker)
.["beakerCurrentVolume"] = beakerCurrentVolume
.["beakerMaxVolume"] = beaker.volume
else
.["beakerCurrentVolume"] = null
.["beakerMaxVolume"] = null
var/list/chemicals = list()
for(var/re in dispensable_reagents)
var/datum/reagent/temp = GLOB.chemical_reagents_list[re]
if(temp)
var/chemname = temp.name
chemicals.Add(list(list("title" = chemname, "id" = temp.id)))
.["chemicals"] = chemicals
/obj/structure/machinery/chem_dispenser/ui_act(action, list/params)
. = ..()
if(.)
return
switch(action)
if("amount")
if(inoperable() || QDELETED(beaker))
return
var/target = text2num(params["target"])
if(target in possible_transfer_amounts)
amount = target
. = TRUE
if("dispense")
if(inoperable() || QDELETED(beaker))
return
var/reagent_name = params["reagent"]
if(beaker && dispensable_reagents.Find(reagent_name))
var/obj/item/reagent_container/current_beaker = beaker
var/datum/reagents/current_reagent = current_beaker.reagents
var/space = current_reagent.maximum_volume - current_reagent.total_volume
current_reagent.add_reagent(reagent_name, min(amount, chem_storage.energy * 10, space))
chem_storage.energy = max(chem_storage.energy - min(amount, chem_storage.energy * 10, space) / 10, 0)
. = TRUE
if("remove")
if(inoperable())
return
var/amount = text2num(params["amount"])
if(beaker && (amount in possible_transfer_amounts))
beaker.reagents.remove_any(amount)
. = TRUE
if("eject")
replace_beaker(usr)
. = TRUE
/obj/structure/machinery/chem_dispenser/attackby(obj/item/reagent_container/attacking_object, mob/user)
if(istype(attacking_object, /obj/item/reagent_container/glass) || istype(attacking_object, /obj/item/reagent_container/food))
if(accept_beaker_only && istype(attacking_object,/obj/item/reagent_container/food))
to_chat(user, SPAN_NOTICE("This machine only accepts beakers"))
if(user.drop_inv_item_to_loc(attacking_object, src))
var/obj/item/old_beaker = beaker
beaker = attacking_object
if(old_beaker)
to_chat(user, SPAN_NOTICE("You swap out [old_beaker] for [attacking_object]."))
user.put_in_hands(old_beaker)
else
to_chat(user, SPAN_NOTICE("You set [attacking_object] on the machine."))
SStgui.update_uis(src)
update_icon()
return
if(HAS_TRAIT(attacking_object, TRAIT_TOOL_MULTITOOL))
switch(hacked_check)
if(DISPENSER_UNHACKABLE)
to_chat(user, SPAN_NOTICE("[src] cannot be hacked."))
if(DISPENSER_NOT_HACKED)
user.visible_message("[user] modifies [src] with [attacking_object], turning a light on.", "You enable a light in [src].")
dispensable_reagents += hacked_reagents
hacked_check = DISPENSER_HACKED
if(DISPENSER_HACKED)
user.visible_message("[user] modifies [src] with [attacking_object], turning a light off.", "You disable a light in [src].")
dispensable_reagents -= hacked_reagents
hacked_check = DISPENSER_NOT_HACKED
if(HAS_TRAIT(attacking_object, TRAIT_TOOL_WRENCH))
if(!wrenchable)
to_chat(user, "[src] cannot be unwrenched.")
return
if(!do_after(user, 2 SECONDS, INTERRUPT_ALL|BEHAVIOR_IMMOBILE, BUSY_ICON_BUILD))
return
if(!src)
return
playsound(loc, 'sound/items/Ratchet.ogg', 25, 1)
anchored = !anchored
if(anchored)
user.visible_message("[user] tightens the bolts securing [src] to the surface.", "You tighten the bolts securing [src] to the surface.")
return
user.visible_message("[user] unfastens the bolts securing [src] to the surface.", "You unfasten the bolts securing [src] to the surface.")
/obj/structure/machinery/chem_dispenser/attack_remote(mob/user as mob)
return src.attack_hand(user)
/obj/structure/machinery/chem_dispenser/attack_hand(mob/user as mob)
if(stat & BROKEN)
to_chat(user, SPAN_WARNING("[src] is inoperative."))
return
if(req_skill && !skillcheck(user, req_skill, req_skill_level))
to_chat(user, SPAN_WARNING("You don't have the training to use [src]."))
return
tgui_interact(user)
/obj/structure/machinery/chem_dispenser/soda
icon_state = "soda_dispenser"
name = "soda fountain"
desc = "A drink fabricating machine, capable of producing many sugary drinks with just one touch."
ui_title = "Soda Dispens-o-matic"
req_skill = null
req_skill_level = null
accept_beaker_only = FALSE
wrenchable = TRUE
network = "Misc"
hacked_check = DISPENSER_NOT_HACKED
dispensable_reagents = list(
"water",
"ice",
"coffee",
"cream",
"tea",
"cola",
"spacemountainwind",
"dr_gibb",
"space_up",
"tonic",
"sodawater",
"lemon_lime",
"sugar",
"orangejuice",
"limejuice",
"watermelonjuice",
"tomatojuice",
"carrotjuice",
"berryjuice",
"grapejuice",
"lemonjuice",
"banana",
)
hacked_reagents = list(
"milk",
"soymilk",
)
/obj/structure/machinery/chem_dispenser/soda/beer
icon_state = "booze_dispenser"
name = "booze dispenser"
ui_title = "Booze Portal 9001"
desc = "A technological marvel, supposedly able to mix just the mixture you'd like to drink the moment you ask for one."
dispensable_reagents = list(
"water",
"ice",
"sodawater",
"sugar",
"tonic",
"beer",
"kahlua",
"whiskey",
"sake",
"wine",
"vodka",
"gin",
"rum",
"vermouth",
"cognac",
"ale",
"mead",
"thirteenloko",
"tequila",
)
hacked_reagents = list(
"goldschlager",
"patron",
"absinthe",
)
#undef DISPENSER_UNHACKABLE
#undef DISPENSER_NOT_HACKED
#undef DISPENSER_HACKED