-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDangerDialler1.lua
470 lines (418 loc) · 15.5 KB
/
DangerDialler1.lua
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
--NOTE! SGJ and AdvPerph required!
--Danger's Dialler V2.0
-- Global variable declarations
-- Command line arguments
if term.isColour() == false then
error("Advanced Computer or better required for program to initalise...", 0)
end
local arg = {...}
-- Expected values: --verbose, --forcePegasus, --forceMilky, --help, --kripMode
forceMilky = false
bypassAuto = false
forcePegasus = false
verbose = false
terribleMode = false
for _,v in pairs(arg) do
if v == "--help" then
print("Danger\'s Dialler Command-Line Arguments: (Argument / Function)")
print("WARNING! ALL FLAGS ARE FOR TESTING ONLY AND MAY DESTABILISE THE PROGRAM\nUSE AT OWN RISK")
print("--help / Prints this help menu")
print("--verbose / Displays extremely detailed information about the program state")
print("--forcePegasus / Forces the program to assume a Pegasus Stargate")
print("--forceMilky / Forces the program to assume a Milky Way Stargate")
return
elseif v == "--verbose" then
verbose = true
print("Verbose mode on")
elseif v == "--forceMilky" then
forceMilky = true
bypassAuto = true
print("Forcing Milky Way Stargate")
elseif v == "--forcePegasus" then
forcePegasus = true
bypassAuto = true
print("Forcing Pegasus Stargate")
elseif v == "--kripMode" then
terribleMode = true
print("Terrible mode activated!")
elseif v then
print(arg)
error("Program failed to initalise, bad flags", 0)
end
end
if forceMilky == true and forcePegasus == true then
error("You cannot force Milky and Pegasus, please select one or the other", 0)
return
end
function verboseInfo(text)
if verbose == true then
print(text)
end
end
interface = peripheral.find("basic_interface") or peripheral.find("crystal_interface") or peripheral.find("advanced_crystal_interface")
verboseInfo("Interface initalised")
iris = peripheral.find("redstoneIntegrator")
verboseInfo("Iris initalised")
--term.write("Colour mode initalised")
print("Danger\'s Dialler V2.0 Penultimate Update before Rewrite")
print("Initalising... Please wait")
os.sleep(3)
term.clear()
term.setCursorPos(1, 1)
if interface then
verboseInfo("Stargate found!")
sleep(0)
else
error("Stargate not found! Please connect a gate and ensure the interface is connected.", 0)
return
end
if iris then
verboseInfo("Iris found!")
irisPresent = true
else
verboseInfo("Iris not found, iris functionality will be disabled")
irisPresent = false
end
if interface.engageSymbol ~= nil then
verboseInfo("Pegasus / Universe Gate Detected")
if bypassAuto == false then
forcePegasus = true
verboseInfo("No force arguments detected, automatically setting gate type")
end
elseif interface.rotateClockwise ~= nil then
verboseInfo("Milky Gate Detected")
if bypassAuto == false then
forceMilky = true
verboseInfo("No force arguments detected, automatically setting gate type")
end
end
--Stargate dialling function, this basically just lets you dial the gate whenever called
function dial(address)
if verbose == true then
print("Primary dialling function called with value: "..tostring(address))
end
if forceMilky == true then
verboseInfo("Milky dial in progress...")
local addressLength = #address
local start = interface.getChevronsEngaged() + 1
for chevron = start,addressLength,1
do
local symbol = address[chevron]
if chevron % 2 == 0 then
interface.rotateClockwise(symbol)
else
interface.rotateAntiClockwise(symbol)
end
while(not interface.isCurrentSymbol(symbol))
do
sleep(0)
end
sleep(0.5)
interface.raiseChevron()
sleep(0.5)
interface.lowerChevron()
sleep(0.5)
end
elseif forcePegasus == true then
verboseInfo("Pegasus / Universe dial in progress...")
local addressLength = #address
local start = interface.getChevronsEngaged() + 1
for chevron = start,addressLength,1
do
local symbol = address[chevron]
interface.engageSymbol(symbol)
end
end
end
-- Gate reset function, attempts to unjam the gate should it become stuck during a dialling sequence
function resetGate()
clearScreen()
local x = 0
print("Resetting gate...")
if forceMilky == true then
while x ~= 10 do
x = x + 1
interface.lowerChevron()
os.sleep(0.1)
interface.raiseChevron()
os.sleep(0.1)
end
interface.lowerChevron()
interface.rotateClockwise(0)
interface.raiseChevron()
interface.lowerChevron()
interface.disconnectStargate()
if interface.isStargateConnected() == true then
print("Stargate successfully reset")
else
print("Was unable to reset gate")
end
elseif forcePegasus == true then
while x ~= 10 do
x = x + 1
interface.engageSymbol(0)
end
if interface.isStargateConnected() == false then
print("Stargate successfully reset")
else
print("Was unable to reset gate")
end
end
end
-- Address Database (Will be a file in the future)
--Do note, if you're adding an address yourself, YOU MUST APPEND IT WITH A 0 AS THE PoO!
abydosAddress = {26,6,14,31,11,29,0}
chulakAddress = {8,1,22,14,36,19,0}
lanteaAddress = {18,20,1,15,14,7,19,0}
midwayAddress = {8,29,19,11,7,4,23,31,0}
netherAddress = {27,23,4,34,12,28,0}
newAthosAddress = {18,21,14,24,1,26,28,0}
--TODO: Update the follow addresses to remove the long-distance dialling
--NOTE: Ad Astra Addresses
moonAddress = {34,2,17,1,18,3,24,4,0}
marsAddress = {9,12,25,34,20,29,8,27,0}
venusAddress = {32,9,17,16,8,6,21,22,0}
glacioAddress = {14,33,1,7,15,32,31,2,0}
-- CUSTOM ADDRESS DATABASE BELOW!
spawnAddress = {16,26,29,14,25,17,21,35,0}
miningDimAddress = {25,2,15,34,35,11,9,28,0}
endAddress = {13,24,2,19,3,30,0}
-- SEPERATOR
verboseInfo("Address database initalised")
-- Iris sanity check on boot (Useful is the iris was left on and the program reboots, makes sure to set the correct values in memory)
if iris then
if iris.getOutput("back") == true then
irisToggle = 0
verboseInfo("Iris sanity check performed, iris state set to 0")
elseif iris.getOutput("back") == false then
irisToggle = 1
verboseInfo("Iris sanity check performed, iris state set to 1")
end
end
-- Draw the main page whenever a command is issued
function mainPage()
verboseInfo("mainPage function called")
print("TEMPORARY: Stargate Control Interface, please select and input a command below")
print("To reset the stargate should it become stuck, type \"reset\"")
print("To toggle the iris, type \"iris\" or press 1")
print("To terminate the wormhole, type \"shutdown\" or press 2")
print("To enter a custom address, type \"custom\"")
print("\nType \'page\' followed by a number to print a list of addresses to dial, or type the destination name")
print("E.G \'page 1\' for the first page")
print("(Please note, additional addresses are on page 3)")
end
function addressList(page)
verboseInfo("addressList function called with value: not implemented")
page = tonumber(page)
if page == 69 then
clearScreen()
print("Nice")
elseif page == 1 then
clearScreen()
print("Dial Abydos (3)")
print("Dial Chulak (4)")
print("Dial Lantea (5)")
print("Dial The End (6)")
print("Dial Nether (7)")
elseif page == 2 then
clearScreen()
print("Ad Astra and other non-functioning Addresses\n")
print("Dial New Athos (8)")
print("Dial The Moon (9)")
print("Dial Mars (10)")
print("Dial Venus (11)")
print("Dial Glacio (12)")
elseif page == 3 then
clearScreen()
print("Custom addresses:\n")
print("Dial Spawn (13)")
print("Dial Mining Dimension (14)")
print("For more entries, bug Danger")
else
clearScreen()
print("No other entries exist!")
end
end
--Refresh screen
function clearScreen()
term.clear()
term.setCursorPos(1, 1)
mainPage()
verboseInfo("clearScreen function called")
end
-- Gate dialling subroutine, prints relevant information to the console and dials the gate
function startDial(address, name, isIntergalactic, isDirect)
if verbose == true then
print("Secondary dialling subroutine called with the following values: "..tostring(address)..", "..name..", "..tostring(isIntergalactic)..", "..tostring(isDirect))
end
interface.disconnectStargate()
os.sleep(1)
if interface.isStargateConnected() == true then
verboseInfo("Stargate connection check passed")
clearScreen()
print("Cannot dial out, wormhole will not close! (Is the call incoming?)")
else
term.clear()
term.setCursorPos(1, 1)
if address == customAddress then
print("Dialling custom address: "..tostring(customAddress))
dial(address)
sleep(0.5)
else
if isIntergalactic == true then
print("Warning! Intergalactic dialling in progress!")
end
if isDirect == false then
print("Dialling "..name.."...")
dial(address)
sleep(0.5)
elseif isDirect == true then
print("Direct dialling "..name.."...")
dial(address)
sleep(0.5)
end
end
if forcePegasus == true then
local counter = 0
print("Waiting for dialling to complete...")
if counter <= 30 then
while interface.getChevronsEngaged() < 7 do
os.sleep(1)
counter = counter + 1
end
elseif counter == 30 then
clearScreen()
print("Gate failed to respond during timeout period. Dial aborted.")
end
if interface.getChevronsEngaged() >= 7 then
verboseInfo("Greater than or equal to 7 chevrons engaged, starting timer...")
os.sleep(10)
end
if interface.isStargateConnected() == false then
clearScreen()
print("Dialling failed! Destination may be buried, incorrectly entered, or insufficient power to complete dialling procedure.")
elseif interface.isStargateConnected() == true then
clearScreen()
print(name.." dialled!")
end
else
if interface.isStargateConnected() == false then
clearScreen()
print("Dialling failed! Destination may be buried, incorrectly entered, or insufficient power to complete dialling procedure.")
elseif interface.isStargateConnected() == true then
clearScreen()
print(name.." dialled!")
end
end
end
end
--Iris control subroutine
function irisControl()
verboseInfo("irisControl subroutine called")
if iris then
term.clear()
term.setCursorPos(1, 1)
if irisToggle == 1 then
iris.setOutput("back", true)
irisToggle = 0
clearScreen()
verboseInfo("Iris state presently 1, setting 0 and enabling iris")
print("Shield raised!")
elseif irisToggle == 0 then
iris.setOutput("back", false)
irisToggle = 1
clearScreen()
verboseInfo("Iris state presently 0, setting 1 and disabling iris")
print("Shield dropped!")
end
else
clearScreen()
print("Iris not found!")
end
end
--Wormhole termination subroutine
function closeWormhole()
verboseInfo("closeWormhole function called")
if interface.isStargateConnected() == true then
interface.disconnectStargate()
os.sleep(1)
if interface.isStargateConnected() == true then
resetGate()
if interface.isStargateConnected() == true then
clearScreen()
print("Failed to close wormhole!")
end
else
clearScreen()
print("Wormhole closed!")
end
else
clearScreen()
print("Wormhole is not engaged!")
end
end
while terribleMode == true do
resetGate()
print("FIRE IN THE HOLE!")
end
-- Main subroutine to draw the address database (Will be converted into a function of its own)
mainPage()
while true do
os.queueEvent("randomEvent")
os.pullEvent("randomEvent")
local msg = read()
local _, _, pageNumber = string.find(msg, "page%s*(%d+)")
--Format is as follows for the startDial subroutine, Destination first as "xAddress", followed by the display name you wish to show, followed by being whether or not it is a intergalactic dial, then if it a direct dial to a gate
if msg == "" then
clearScreen()
elseif pageNumber then
addressList(pageNumber)
elseif msg == "reset" then
resetGate()
elseif msg == "custom" then
customAddress = {}
term.clear()
term.setCursorPos(1, 1)
print("Custom destination selection:")
print("To dial a custom destination, please type your address in the following format\nBe sure not to include spaces or any other text")
print("\n\nExample address, \"1,2,3,4,5,6,0\", where 0 is the Point of Origin")
print("\nCustom Address: ")
local custom = read()
for value in custom:gmatch("[^,]+") do
table.insert(customAddress, tonumber(value))
end
startDial(customAddress, "Custom Address", false, false)
--CUSTOM ADDRESS DIALLING HERE
elseif msg == "1" or msg == "iris" then
irisControl()
elseif msg == "2" or msg == "shutdown" then
closeWormhole()
elseif msg == "3" or msg == "abydos" then
startDial(abydosAddress, "Abydos", false, false)
elseif msg == "4" or msg == "chulak" then
startDial(chulakAddress, "Chulak", false, false)
elseif msg == "5" or msg == "lantea" then
startDial(lanteaAddress, "Lantea", true, false)
elseif msg == "6" or msg == "midway" or msg == "end" or msg == "the end" then
startDial(endAddress, "The End", false, false)
elseif msg == "7" or msg == "nether" then
startDial(netherAddress, "the Nether", false, true)
elseif msg == "8" or msg == "athos" or msg == "newathos" or msg == "new athos" then
startDial(newAthosAddress, "New Athos", true, false)
elseif msg == "9" or msg == "moon" or msg == "the moon" or msg =="themoon" then
startDial(moonAddress, "The Moon", false, true)
elseif msg == "10" or msg == "mars" then
startDial(marsAddress, "Mars", false, true)
elseif msg == "11" or msg == "venus" then
startDial(venusAddress, "Venus", false, true)
elseif msg == "12" or msg == "glacio" then
startDial(glacioAddress, "Glacio", true, true)
elseif msg == "13" or msg == "spawn" then
startDial(spawnAddress, "Spawn", false, true)
elseif msg == "14" or msg == "mining dim" or msg == "mining" or msg =="miningdim" or msg == "mine" then
startDial(miningDimAddress, "Mining Dimension", false, true)
else
clearScreen()
print("Invalid command! Please check your input or bug Danger about his bad code")
end
end