This repository was archived by the owner on May 22, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 458
Expand file tree
/
Copy pathmachine_silo.dm
More file actions
257 lines (223 loc) · 8.07 KB
/
machine_silo.dm
File metadata and controls
257 lines (223 loc) · 8.07 KB
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
GLOBAL_DATUM(ore_silo_default, /obj/machinery/ore_silo)
GLOBAL_LIST_EMPTY(silo_access_logs)
/obj/machinery/ore_silo
name = "ore silo"
desc = "An all-in-one bluespace storage and transmission system for the station's mineral distribution needs."
icon = 'icons/obj/mining.dmi'
icon_state = "silo"
density = TRUE
circuit = /obj/item/circuitboard/machine/ore_silo
var/list/holds = list()
var/list/datum/component/remote_materials/connected = list()
var/log_page = 1
/obj/machinery/ore_silo/Initialize(mapload)
. = ..()
var/static/list/materials_list = list(
/datum/material/iron,
/datum/material/glass,
/datum/material/silver,
/datum/material/gold,
/datum/material/diamond,
/datum/material/plasma,
/datum/material/uranium,
/datum/material/bananium,
/datum/material/titanium,
/datum/material/bluespace,
/datum/material/dilithium,
/datum/material/plastic
)
AddComponent(/datum/component/material_container, materials_list, INFINITY, allowed_types=/obj/item/stack, _disable_attackby=TRUE)
if (!GLOB.ore_silo_default && mapload && is_station_level(z))
GLOB.ore_silo_default = src
/obj/machinery/ore_silo/Destroy()
if (GLOB.ore_silo_default == src)
GLOB.ore_silo_default = null
for(var/C in connected)
var/datum/component/remote_materials/mats = C
mats.disconnect_from(src)
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
materials.retrieve_all()
return ..()
/obj/machinery/ore_silo/proc/remote_attackby(obj/machinery/M, mob/living/user, obj/item/stack/I)
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
// stolen from /datum/component/material_container/proc/OnAttackBy
if(user.combat_mode)
return
if(I.item_flags & ABSTRACT)
return
if(!istype(I) || (I.flags_1 & HOLOGRAM_1) || (I.item_flags & NO_MAT_REDEMPTION))
to_chat(user, span_warning("[M] won't accept [I]!"))
return
var/item_mats = I.materials & materials.materials
if(!length(item_mats))
to_chat(user, span_warning("[I] does not contain sufficient materials to be accepted by [M]."))
return
// assumes unlimited space...
var/amount = I.amount
materials.user_insert(I, user)
silo_log(M, "deposited", amount, "sheets", item_mats)
return TRUE
/obj/machinery/ore_silo/attackby(obj/item/W, mob/living/user, params)
if(user.combat_mode) //so we can hit the machine
return ..()
if(default_deconstruction_screwdriver(user, "icon_state", "icon_state", W))
return TRUE
if(default_deconstruction_crowbar(W))
return TRUE
if (istype(W, /obj/item/stack))
return remote_attackby(src, user, W)
return ..()
/obj/machinery/ore_silo/ui_interact(mob/user)
user.set_machine(src)
var/datum/browser/popup = new(user, "ore_silo", null, 600, 550)
popup.set_content(generate_ui())
popup.open()
/obj/machinery/ore_silo/proc/generate_ui()
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
var/list/ui = list("<head><title>Ore Silo</title></head><body><div class='statusDisplay'><h2>Stored Material:</h2>")
var/any = FALSE
for(var/M in materials.materials)
var/datum/material/mat = M
var/amount = materials.materials[M]
var/sheets = round(amount) / MINERAL_MATERIAL_AMOUNT
var/ref = REF(M)
if (sheets)
if (sheets >= 1)
ui += "<a href='byond://?src=[REF(src)];ejectsheet=[ref];eject_amt=1'>Eject</a>"
else
ui += span_linkOff("Eject")
if (sheets >= 20)
ui += "<a href='byond://?src=[REF(src)];ejectsheet=[ref];eject_amt=20'>20x</a>"
else
ui += span_linkOff("20x")
ui += "<b>[mat.name]</b>: [sheets] sheets<br>"
any = TRUE
if(!any)
ui += "Nothing!"
ui += "</div><div class='statusDisplay'><h2>Connected Machines:</h2>"
for(var/C in connected)
var/datum/component/remote_materials/mats = C
var/atom/parent = mats.parent
var/hold_key = "[get_area(parent)]/[mats.category]"
ui += "<a href='byond://?src=[REF(src)];remove=[REF(mats)]'>Remove</a>"
ui += "<a href='byond://?src=[REF(src)];hold[!holds[hold_key]]=[url_encode(hold_key)]'>[holds[hold_key] ? "Allow" : "Hold"]</a>"
ui += " <b>[parent.name]</b> in [get_area_name(parent, TRUE)]<br>"
if(!connected.len)
ui += "Nothing!"
ui += "</div><div class='statusDisplay'><h2>Access Logs:</h2>"
var/list/logs = GLOB.silo_access_logs[REF(src)]
var/len = LAZYLEN(logs)
var/num_pages = 1 + round((len - 1) / 30)
var/page = clamp(log_page, 1, num_pages)
if(num_pages > 1)
for(var/i in 1 to num_pages)
if(i == page)
ui += span_linkOff("[i]")
else
ui += "<a href='byond://?src=[REF(src)];page=[i]'>[i]</a>"
ui += "<ol>"
any = FALSE
for(var/i in (page - 1) * 30 + 1 to min(page * 30, len))
var/datum/ore_silo_log/entry = logs[i]
ui += "<li value=[len + 1 - i]>[entry.formatted]</li>"
any = TRUE
if (!any)
ui += "<li>Nothing!</li>"
ui += "</ol></div>"
return ui.Join()
/obj/machinery/ore_silo/Topic(href, href_list)
if(..())
return
add_fingerprint(usr)
usr.set_machine(src)
if(href_list["remove"])
var/datum/component/remote_materials/mats = locate(href_list["remove"]) in connected
if (mats)
mats.disconnect_from(src)
connected -= mats
updateUsrDialog()
return TRUE
else if(href_list["hold1"])
holds[href_list["hold1"]] = TRUE
updateUsrDialog()
return TRUE
else if(href_list["hold0"])
holds -= href_list["hold0"]
updateUsrDialog()
return TRUE
else if(href_list["ejectsheet"])
var/datum/material/eject_sheet = locate(href_list["ejectsheet"])
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
var/count = materials.retrieve_sheets(text2num(href_list["eject_amt"]), eject_sheet, drop_location())
var/list/matlist = list()
matlist[eject_sheet] = MINERAL_MATERIAL_AMOUNT
silo_log(src, "ejected", -count, "sheets", matlist)
return TRUE
else if(href_list["page"])
log_page = text2num(href_list["page"]) || 1
updateUsrDialog()
return TRUE
/obj/machinery/ore_silo/multitool_act(mob/living/user, obj/item/multitool/I)
to_chat(user, span_notice("You log [src] in the multitool's buffer."))
multitool_set_buffer(user, I, src)
return TRUE
/obj/machinery/ore_silo/proc/silo_log(obj/machinery/M, action, amount, noun, list/mats)
if (!length(mats))
return
var/datum/ore_silo_log/entry = new(M, action, amount, noun, mats)
var/list/datum/ore_silo_log/logs = GLOB.silo_access_logs[REF(src)]
if(!LAZYLEN(logs))
GLOB.silo_access_logs[REF(src)] = logs = list(entry)
else if(!logs[1].merge(entry))
logs.Insert(1, entry)
updateUsrDialog()
flick("silo_active", src)
/obj/machinery/ore_silo/examine(mob/user)
. = ..()
. += span_notice("[src] can be linked to techfabs, circuit printers and protolathes with a multitool.")
/obj/machinery/ore_silo/swarmer_act(mob/living/simple_animal/hostile/swarmer/actor)
actor.dismantle_machine(src, TRUE)
return TRUE
/datum/ore_silo_log
var/name // for VV
var/formatted // for display
var/timestamp
var/machine_name
var/area_name
var/action
var/noun
var/amount
var/list/materials
/datum/ore_silo_log/New(obj/machinery/M, _action, _amount, _noun, list/mats=list())
timestamp = station_time_timestamp()
machine_name = M.name
area_name = get_area_name(M, TRUE)
action = _action
amount = _amount
noun = _noun
materials = mats.Copy()
for(var/each in materials)
materials[each] *= abs(_amount)
format()
/datum/ore_silo_log/proc/merge(datum/ore_silo_log/other)
if (other == src || action != other.action || noun != other.noun)
return FALSE
if (machine_name != other.machine_name || area_name != other.area_name)
return FALSE
timestamp = other.timestamp
amount += other.amount
for(var/each in other.materials)
materials[each] += other.materials[each]
format()
return TRUE
/datum/ore_silo_log/proc/format()
name = "[machine_name]: [action] [amount]x [noun]"
var/list/msg = list("([timestamp]) <b>[machine_name]</b> in [area_name]<br>[action] [abs(amount)]x [noun]<br>")
var/sep = ""
for(var/key in materials)
var/datum/material/M = key
var/val = round(materials[key]) / MINERAL_MATERIAL_AMOUNT
msg += sep
sep = ", "
msg += "[amount < 0 ? "-" : "+"][val] [M.name]"
formatted = msg.Join()