-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathbudgetordering.dm
304 lines (283 loc) · 10.4 KB
/
budgetordering.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
/datum/computer_file/program/budgetorders
filename = "orderapp"
filedesc = "NT IRN"
category = PROGRAM_CATEGORY_SUPPLY
program_icon_state = "bountyboard"
extended_desc = "Nanotrasen Internal Requisition Network interface for supply purchasing using a department budget account."
requires_ntnet = TRUE
usage_flags = PROGRAM_CONSOLE | PROGRAM_LAPTOP | PROGRAM_TABLET | PROGRAM_PHONE | PROGRAM_TELESCREEN | PROGRAM_PDA
size = 12
tgui_id = "NtosCargo"
program_icon = "store"
///Are you actually placing orders with it?
var/requestonly = TRUE
///Can the tablet see or buy illegal stuff?
var/contraband = FALSE
///Is it being bought from a personal account, or is it being done via a budget/cargo?
var/self_paid = FALSE
///Can this console approve purchase requests?
var/can_approve_requests = FALSE
///Can this console see contraband items?
var/emagged = FALSE
///What do we say when the shuttle moves with living beings on it.
var/safety_warning = "For safety reasons, the automated supply shuttle \
cannot transport live organisms, human remains, classified nuclear weaponry, \
homing beacons or machinery housing any form of artificial intelligence."
///If you're being raided by pirates, what do you tell the crew?
var/blockade_warning = "Bluespace instability detected. Shuttle movement impossible."
/// Can send the shuttle **AWAY** from the station
var/can_send = FALSE
///Is it being bought from a departmental budget?
var/budget_order = FALSE
///If this is true, unlock the ability to order through budgets
var/unlock_budget = TRUE
/datum/computer_file/program/budgetorders/proc/get_export_categories()
. = EXPORT_CARGO
/datum/computer_file/program/budgetorders/proc/is_visible_pack(mob/user, paccess_to_check, list/access, contraband)
if(issilicon(user)) //Borgs can't buy things.
return FALSE
if(emagged)
return TRUE
else if(contraband) //Hide contrband when non-emagged.
return FALSE
if(!paccess_to_check) // No required_access, allow it.
return TRUE
//Aquire access from the inserted ID card.
if(!length(access))
var/obj/item/card/id/D
var/obj/item/computer_hardware/card_slot/card_slot
if(computer)
card_slot = computer.all_components[MC_CARD]
D = card_slot?.GetID()
if(!D)
return FALSE
access = D.GetAccess()
if(paccess_to_check in access)
return TRUE
return FALSE
/datum/computer_file/program/budgetorders/run_emag()
if(emagged)
return FALSE
emagged = TRUE
return TRUE
/datum/computer_file/program/budgetorders/ui_data()
. = ..()
var/list/data = get_header_data()
data["location"] = SSshuttle.supply.getStatusText()
var/datum/bank_account/buyer = SSeconomy.get_dep_account(ACCOUNT_CAR)
var/obj/item/computer_hardware/card_slot/card_slot = computer.all_components[MC_CARD]
var/obj/item/card/id/id_card = card_slot?.GetID()
if(id_card?.registered_account)
unlock_budget = TRUE
if(id_card?.registered_account?.account_job?.paycheck_department == ACCOUNT_CAR)
unlock_budget = FALSE //cargo tech is already using the same budget.
if(id_card?.registered_account?.account_job?.paycheck_department && budget_order)
buyer = SSeconomy.get_dep_account(id_card.registered_account.account_job.paycheck_department)
if((ACCESS_COMMAND in id_card.access) || (ACCESS_QM in id_card.access) || (ACCESS_CARGO in id_card.access))
requestonly = FALSE
can_approve_requests = TRUE
can_send = TRUE
else
requestonly = TRUE
can_approve_requests = FALSE
can_send = FALSE
else
requestonly = TRUE
unlock_budget = FALSE //none registered account shouldnt be using budget order
if(buyer)
data["points"] = buyer.account_balance
//Otherwise static data, that is being applied in ui_data as the crates visible and buyable are not static, and are determined by inserted ID.
data["requestonly"] = requestonly
data["supplies"] = list()
for(var/pack in SSshuttle.supply_packs)
var/datum/supply_pack/P = SSshuttle.supply_packs[pack]
if(!is_visible_pack(usr, P.access_view , null, P.contraband) || P.hidden)
continue
if(!data["supplies"][P.group])
data["supplies"][P.group] = list(
"name" = P.group,
"packs" = list()
)
if((P.hidden && (P.contraband && !contraband) || (P.special && !P.special_enabled) || P.DropPodOnly))
continue
data["supplies"][P.group]["packs"] += list(list(
"name" = P.name,
"cost" = P.get_cost(),
"id" = pack,
"desc" = P.desc || P.name, // If there is a description, use it. Otherwise use the pack's name.
"access" = P.access
))
//Data regarding the User's capability to buy things.
data["away"] = SSshuttle.supply.getDockedId() == "supply_away"
data["self_paid"] = self_paid
data["unlock_budget"] = unlock_budget
data["budget_order"] = budget_order
data["docked"] = SSshuttle.supply.mode == SHUTTLE_IDLE
data["loan"] = !!SSshuttle.shuttle_loan
data["loan_dispatched"] = SSshuttle.shuttle_loan && SSshuttle.shuttle_loan.dispatched
data["can_approve_requests"] = can_approve_requests
data["can_send"] = can_send
data["app_cost"] = TRUE
var/message = "Remember to stamp and send back the supply manifests."
if(SSshuttle.centcom_message)
message = SSshuttle.centcom_message
if(SSshuttle.supply_blocked)
message = blockade_warning
data["message"] = message
data["cart"] = list()
for(var/datum/supply_order/SO in SSshuttle.shopping_list)
data["cart"] += list(list(
"object" = SO.pack.name,
"cost" = SO.pack.get_cost(),
"id" = SO.id,
"orderer" = SO.orderer,
"paid" = !isnull(SO.paying_account), //paid by requester
"budget" = SO.budget
))
data["requests"] = list()
for(var/datum/supply_order/SO in SSshuttle.request_list)
data["requests"] += list(list(
"object" = SO.pack.name,
"cost" = SO.pack.get_cost(),
"orderer" = SO.orderer,
"reason" = SO.reason,
"id" = SO.id,
"budget" = SO.budget
))
return data
/datum/computer_file/program/budgetorders/ui_act(action, params, datum/tgui/ui)
if(..())
return
var/obj/item/computer_hardware/card_slot/card_slot = computer.all_components[MC_CARD]
switch(action)
if("send")
if(!SSshuttle.supply.canMove())
computer.say(safety_warning)
return
if(SSshuttle.supply_blocked)
computer.say(blockade_warning)
return
if(SSshuttle.supply.getDockedId() == "supply_home")
SSshuttle.supply.export_categories = get_export_categories()
SSshuttle.moveShuttle("supply", "supply_away", TRUE)
computer.say("The supply shuttle is departing.")
computer.investigate_log("[key_name(usr)] sent the supply shuttle away.", INVESTIGATE_CARGO)
else
computer.investigate_log("[key_name(usr)] called the supply shuttle.", INVESTIGATE_CARGO)
computer.say("The supply shuttle has been called and will arrive in [SSshuttle.supply.timeLeft(600)] minutes.")
SSshuttle.moveShuttle("supply", "supply_home", TRUE)
. = TRUE
if("loan")
if(!SSshuttle.shuttle_loan)
return
if(SSshuttle.supply_blocked)
computer.say(blockade_warning)
return
else if(SSshuttle.supply.mode != SHUTTLE_IDLE)
return
else if(SSshuttle.supply.getDockedId() != "supply_away")
return
else
SSshuttle.shuttle_loan.loan_shuttle()
computer.say("The supply shuttle has been loaned to CentCom.")
computer.investigate_log("[key_name(usr)] accepted a shuttle loan event.", INVESTIGATE_CARGO)
log_game("[key_name(usr)] accepted a shuttle loan event.")
. = TRUE
if("add")
var/id = text2path(params["id"])
var/datum/supply_pack/pack = SSshuttle.supply_packs[id]
if(!istype(pack))
return
if((pack.hidden && (pack.contraband && !contraband) || pack.DropPodOnly))
return
var/name = "*None Provided*"
var/rank = "*None Provided*"
var/ckey = usr.ckey
if(ishuman(usr))
var/mob/living/carbon/human/H = usr
name = H.get_authentification_name()
rank = H.get_assignment(hand_first = TRUE)
else if(issilicon(usr))
name = usr.real_name
rank = "Silicon"
var/datum/bank_account/account
if(self_paid && ishuman(usr))
var/mob/living/carbon/human/H = usr
var/obj/item/card/id/id_card = H.get_idcard(TRUE)
if(!istype(id_card))
computer.say("No ID card detected.")
return
if(istype(id_card, /obj/item/card/id/departmental_budget))
computer.say("The [src] rejects [id_card].")
return
account = id_card.registered_account
if(!istype(account))
computer.say("Invalid bank account.")
return
var/reason = ""
if((requestonly && !self_paid) || !(card_slot?.GetID()))
reason = stripped_input("Reason:", name, "")
if(isnull(reason) || ..())
return
if(!self_paid && ishuman(usr) && !account)
var/obj/item/card/id/id_card = card_slot?.GetID()
if(budget_order)
account = SSeconomy.get_dep_account(id_card?.registered_account?.account_job.paycheck_department)
name = account.account_holder
rank = "*None Provided*"
var/turf/T = get_turf(computer)
var/datum/supply_order/SO = new(pack, name, rank, ckey, reason, account, account?.account_holder)
SO.generateRequisition(T)
if((requestonly && !self_paid) || !(card_slot?.GetID()))
SSshuttle.request_list += SO
else
SSshuttle.shopping_list += SO
if(self_paid || budget_order)
computer.say("Order processed. The price will be charged to [account.account_holder]'s bank account on delivery.")
. = TRUE
if("remove")
var/id = text2num(params["id"])
for(var/datum/supply_order/SO in SSshuttle.shopping_list)
if(SO.id == id)
SSshuttle.shopping_list -= SO
. = TRUE
break
if("clear")
SSshuttle.shopping_list.Cut()
. = TRUE
if("approve")
var/id = text2num(params["id"])
for(var/datum/supply_order/SO in SSshuttle.request_list)
if(SO.id == id)
SSshuttle.request_list -= SO
SSshuttle.shopping_list += SO
. = TRUE
break
if("deny")
var/id = text2num(params["id"])
for(var/datum/supply_order/SO in SSshuttle.request_list)
if(SO.id == id)
SSshuttle.request_list -= SO
. = TRUE
break
if("denyall")
SSshuttle.request_list.Cut()
. = TRUE
if("toggleprivate")
self_paid = !self_paid
if(budget_order)
budget_order = FALSE //incase something fucked
. = TRUE
if("togglebudget")
budget_order = !budget_order
if(self_paid)
self_paid = FALSE //incase something fucked
. = TRUE
if(.)
post_signal("supply")
/datum/computer_file/program/budgetorders/proc/post_signal(command)
var/datum/radio_frequency/frequency = SSradio.return_frequency(FREQ_STATUS_DISPLAYS)
if(!frequency)
return
var/datum/signal/status_signal = new(list("command" = command))
frequency.post_signal(src, status_signal)