-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathsci_bombardment.dm
256 lines (244 loc) · 8.94 KB
/
sci_bombardment.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
/**
* A machine used for Toxins scientists. Accepts tank transfer valves (TTVs),
* then shoots (and detonates) them at Lavaland Z-level GPS coordinates provided.
*
* Five primary variables are used to operate the machine:
* lavaland - setup during Init(), defines Z-level of lavaland for GPS checks
* locked - Locks/Unlocks all interactions w/ LAM, except for loading a TTV into it.
* dest - Turf that is selected as a target for the TTV to be shot at. Does not change unless a new target is chosen.
* targetdest - Name of the GPS selected at the same time as var/dest.
* tcoords - X, Y, Z coordinates selected at the same time as var/dest.
* scibomb - Variable that stores the TTV.
*
* Additional secondary variables:
* radio_freq - Restricts machine to only speak on Science radio channel. This allows Miners to hear the LAM
* announcements as well.
* countdown - Adjustable value used to determine the time until the TTV is deployed to Lavaland.
* stopcount - Variable affected by ui_act("launch"). Used during countdown() to maintain or break the loop.
* mincount - Value that restricts var/countdown from being less than it.
* tick - Value that uses var/countdown when starting the countdown() proc.
* target_delay - Variable used in reset_lam(), limits targetting/firing actions in short succession.
*/
/obj/machinery/sci_bombardment
name = "Lavaland Artillery Mainframe"
desc = "A machine consisting of bluespace relays and a targeting mechanism, the L.A.M. tracks signals visible on nearby planetary bodies. Modern advancements to the bluespace guidance system makes it significantly more accurate than its predecessor, the Lavaland Missile Firing Abomination Obliterator.\n"
icon = 'icons/obj/machines/lam.dmi'
icon_state = "LAM_Base"
light_color = LIGHT_COLOR_PINK
use_power = IDLE_POWER_USE
idle_power_usage = 500
active_power_usage = 5000
power_channel = AREA_USAGE_EQUIP
density = TRUE
verb_say = "states coldly"
var/countdown = 30
var/mincount = 15
var/target_delay = FALSE
var/locked = TRUE
var/stopcount = TRUE
var/tick = 0
var/obj/item/transfer_valve/scibomb //Right here, JC
var/turf/dest
var/obj/item/radio/radio
var/radio_freq = FREQ_SCIENCE
var/lavaland
var/tcoords
var/targetdest = "None"
/obj/machinery/sci_bombardment/Initialize(mapload)
. = ..()
for(var/Z in 1 to world.maxz) //define Lavaland Z-level
if(is_mining_level(Z))
lavaland = Z
break
radio = new /obj/item/radio/(src)
radio.frequency = radio_freq
update_appearance()
/obj/machinery/sci_bombardment/Destroy()
QDEL_NULL(radio)
return ..()
/obj/machinery/sci_bombardment/update_overlays()
. = ..()
if(!powered(power_channel))
. += "LAM_radar0"
set_light(0)
else
. += "LAM_screen[dest && !locked && !target_delay ? "Targ" : "Idle"]"
. += "LAM_radar[target_delay || locked ? "0" : "1"]"
set_light(2)
if(scibomb)
. += "LAM_hatch"
/obj/machinery/sci_bombardment/attackby(obj/item/transfer_valve/B, mob/user, params)
if(istype(B, /obj/item/transfer_valve) && B.tank_one && B.tank_two)
if(!user.transferItemToLoc(B, src))
return
if(!scibomb)
scibomb = B
playsound(src, 'sound/effects/bin_close.ogg', 100, 1)
to_chat(usr, span_notice("You load [B] into the firing mechanism."))
update_appearance()
else
to_chat(usr, span_warning("There is already a transfer valve loaded in the firing mechanism!"))
else
to_chat(usr, span_warning("[B] is refused, as it is invalid or incomplete."))
return
/**
* Starts countdown sequence for firing the TTV
*
* Subtracts 1 from var/tick every second silently until reaching
* the last 5 seconds. Spawn(10) loops back to the beginning by
* triggering the proc again after 10 deciseconds.
*/
/obj/machinery/sci_bombardment/proc/countdown()
if(stopcount) //Abort launch
tick = countdown
return
tick -= 1
if(tick == 0)
stopcount = TRUE
tick = countdown
fire_ttv()
radio.talk_into(src, "Payload successfully deployed.",)
use_power = 1
return
else if(tick <= 5)
use_power = 2
radio.talk_into(src, "[tick]...",)
playsound(src, 'sound/effects/clock_tick.ogg', 80, 0)
spawn(10)
countdown()
/**
* Launches TTV from LAM to turf
*
* Triggered after being called in the last step of countdown().
* Sends the loaded TTV to the Turf selected during ui_act("target"),
* triggers toggle_valve(), and last resets variables to initial state.
*/
/obj/machinery/sci_bombardment/proc/fire_ttv()
if(!scibomb || !dest)
return
playsound(src, 'sound/effects/gravhit.ogg', 80, 0.25)
playsound(src, 'sound/effects/podwoosh.ogg', 80, 0.25)
scibomb.forceMove(dest)
playsound(scibomb, 'sound/effects/bamf.ogg', 95, 0.25, 75, 1, 0, 0, FALSE, TRUE) //Minimum impact sound in the odd event Toxins doesn't send a bomb
scibomb.toggle_valve()
dest = initial(dest)
targetdest = initial(dest)
tcoords = initial(tcoords)
scibomb = initial(scibomb)
update_appearance()
. = TRUE
/**
* Visual proc, temporarily disables interacting
*
* Triggered after the ui_act's "target" and "abort" to
* add a delay between selecting GPS coordinates and
* cancelling a TTV launch.
*/
/obj/machinery/sci_bombardment/proc/reset_lam()
target_delay = !target_delay
update_appearance()
if(target_delay)
spawn(100)
reset_lam()
else
playsound(src, 'sound/items/scanner_match.ogg', 100, 1)
return
/obj/machinery/sci_bombardment/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "Lam", name)
ui.open()
/obj/machinery/sci_bombardment/ui_data(mob/user)
var/list/data = list()
data["tcoords"] = tcoords
data["countdown"] = countdown
data["locked"] = locked
data["loaded"] = scibomb
data["stopcount"] = stopcount
if(locked)
return data
if(tcoords)
data["tcoords"] = tcoords
data["targetdest"] = targetdest
var/list/signals = list()
data["signals"] = list()
for(var/datum/component/gps/G in GLOB.GPS_list) //nulls on the list somehow
var/turf/pos = get_turf_global(G) // yogs - get_turf_global instead of get_turf
if(G.emped || !G.tracking || pos.z != lavaland)
continue
var/list/signal = list()
signal["entrytag"] = G.gpstag //GPS name
signal["coords"] = "[pos.x], [pos.y], [pos.z]"
signals += list(signal)
data["signals"] = signals
return data
/obj/machinery/sci_bombardment/ui_act(action, params)
if(..())
return
switch(action)
if("lock")//Check for RD/Silicon access. Lock/Unlock console if valid
if(iscyborg(usr) || isAI(usr))
locked = !locked
radio.talk_into(src, "Controls [locked ? "locked" : "unlocked"] by [usr].",)
else
var/mob/M = usr
var/obj/item/card/id/I = M.get_idcard(TRUE)
if(check_access(I) && ("rd" in I.access))
locked = !locked
radio.talk_into(src, "Controls [locked ? "locked" : "unlocked"] by [I.registered_name].",)
else
to_chat(usr, span_warning("Access denied. Please seek assistance from station AI or Research Director."))
update_appearance()
. = TRUE
if("count")//Prompts user to change countdown timer (Minimum based on mincount)
if(locked)
return
var/a = text2num(stripped_input(usr, "Set a new countdown timer. (Minimum [mincount])", name, mincount))
countdown = max(a, mincount)
to_chat(usr, span_notice("Countdown set to [countdown] seconds."))
. = TRUE
if("unload")//If unlocked, allows user to remove TTV from the machine, if present
if(!scibomb || locked)
return
if(!stopcount)
playsound(src, 'sound/misc/box_deploy.ogg', 80, 0.5)
to_chat(usr, span_warning("It's too late to do that now! There's only [tick] seconds remaining! Abort!"))
return
playsound(src, 'sound/machines/blastdoor.ogg', 75, 0)
to_chat(usr, span_notice("[scibomb] is ejected from the loading chamber."))
scibomb.forceMove(drop_location())
scibomb = null
update_appearance()
. = TRUE
if("launch")//Transfers var/countdown to var/tick before proc'ing countdown()
if(locked || target_delay || !scibomb || !dest)
return
stopcount = !stopcount
if (!stopcount)
radio.talk_into(src, "Beginning launch on coordinates [tcoords]. ETA: [countdown] seconds.",)
tick = countdown + 1
countdown()
else
radio.talk_into(src, "Launch sequence aborted by [usr]. Adjusting mainframe...",)
reset_lam()
. = TRUE
if("target")//Acknowledges GPS signal selected by user and saves it as place to send TTV
if(locked || target_delay || !stopcount)
return
targetdest = params["targetdest"]
tcoords = params["tcoords"]
for(var/gps in GLOB.GPS_list)
var/obj/item/gps/T = gps
var/turf/pos = get_turf_global(T) // yogs - get_turf_global instead of get_turf
if(T.gpstag == targetdest && "[pos.x], [pos.y], [pos.z]" == tcoords)
dest = pos
break
if(!dest)
radio.talk_into(src, "ERROR: Telemetry mismatch. Isolation of [targetdest] required before trying again. Adjusting mainframe...",)
targetdest = initial(targetdest)
tcoords = initial(tcoords)
. = TRUE
radio.talk_into(src, "Target set to [targetdest] at coordinates [tcoords]. [tcoords ? "Adjusting mainframe..." : ""]",)
playsound(src, 'sound/effects/servostep.ogg', 100, 1)
reset_lam()
. = TRUE