-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAGSS.lua
1389 lines (1336 loc) · 41.8 KB
/
AGSS.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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
comp = require("component")
term = require("term")
math = require("math")
pc = require("computer")
event = require("event")
serial = require("serialization")
local gpu
if (comp.isAvailable("gpu")) then
gpu = comp.gpu
if(gpu.maxDepth() < 4) then
gpu.set(1,10,"Please, install Graphics Card tier 2 or higher")
pc.beep(40, 0.5)
pc.beep(40, 0.5)
os.sleep(2)
os.exit(false)
end
else
pc.beep(40, 1)
os.exit(false)
end
local modem
local mod = comp.isAvailable("modem")
if (mod) then
modem = comp.modem
if(comp.modem.isWireless() == false) then
pc.beep(40, 0.5)
pc.beep(40, 0.5)
gpu.set(1,10,"Please, install Wireless Card level 2")
os.sleep(2)
os.exit(false)
elseif (comp.modem.setStrength(400) == 16) then
pc.beep(40, 0.5)
pc.beep(40, 0.5)
gpu.set(1,10,"Please, install Wireless Card level 2")
os.sleep(2)
os.exit(false)
end
else
pc.beep(40, 1)
os.exit(false)
end
local gate
local gch = comp.isAvailable("stargate")
if (gch) then
pc.beep(40, 0.5)
pc.beep(40, 0.5)
gate = comp.stargate
else
gpu.set(1,10,"Stargate not connected")
pc.beep(40, 1)
os.exit(false)
end
modem.setStrength(50)
modem.open(1001)
local addx = 0
local addy = 0
local pmode
local x1, x2, x3, y1, y2, y3, z1, z2, z3
local addmod = 0
sortmode = -1
local glmass = {}
local add = {}
local linktest = false
local srec = ""
sladd = {}
slmod = {}
local slnum = 0
local tloop = true
local slener = {}
--local slaveonly = false
local ener = 0
local mwfcode = {"Andromeda", "Aquarius", "Aries", "Auriga", "Bootes", "Cancer", "Canis Minor", "Capricornus", "Centaurus", "Cetus", "Corona Australis", "Crater", "Equuleus", "Eridanus", "Gemini", "Hydra", "Leo", "Leo Minor", "Libra", "Lynx", "Microscopium", "Monoceros", "Norma", "Orion", "Pegasus", "Perseus", "Pisces", "Piscis Austrinus", "Sagittarius", "Scorpius", "Sculptor", "Scutum", "Serpens Caput", "Sextans", "Taurus", "Triangulum", "Virgo", ""}
local unf = {"Glyph 1", "Glyph 2", "Glyph 3", "Glyph 4", "Glyph 5", "Glyph 6", "Glyph 7", "Glyph 8", "Glyph 9", "Glyph 10", "Glyph 11", "Glyph 12", "Glyph 13", "Glyph 14", "Glyph 15", "Glyph 16", "Glyph 18", "Glyph 19", "Glyph 20", "Glyph 21", "Glyph 22", "Glyph 23", "Glyph 24", "Glyph 25", "Glyph 26", "Glyph 27", "Glyph 28", "Glyph 29", "Glyph 30", "Glyph 31", "Glyph 32", "Glyph 33", "Glyph 34", "Glyph 35", "Glyph 36", ""}
local pgf = {"Acjesis", "Lenchan", "Alura", "Ca Po", "Laylox", "Ecrumig", "Avoniv", "Bydo", "Aaxel", "Aldeni", "Setas", "Arami", "Danami", "Poco Re", "Robandus", "Recktic", "Zamilloz", "Dawnre", "Salma", "Hamlinto", "Elenami", "Tahnan", "Zeo", "Roehi", "Once El", "Baselai", "Sandovi", "Illume", "Amiwill", "Sibbron", "Gilltin", "Abrin", "Ramnon", "Olavii", "Hacemill", ""}
--local pbalph = {"⣏","⣉","⣹","⣿"}
local pbe = "⣏⣉⣉⣉⣹"
--local pbf = "⣿⣿⣿⣿⣿"
--dial--
function dial(addr, int)
local pos = 28
if int == nil then int = 0 else gpu.set(9, pos+4*(int-1), "Starting dial ") end
for i, val in ipairs(addr) do
while(gate.getGateStatus() ~= "idle") do
if int == 0 then
os.sleep(0)
else
os.sleep(0.2)
gpu.set(1,43, string.format("Current: %u RF", gate.getEnergyStored()))
end
end
os.sleep(0.16)
gate.engageSymbol(val)
if int > 0 and i > 1 then
gpu.set(9, pos+4*(int-1), string.format("Shevron %u - engaged", i-1))
pc.beep(150, 0.1)
gpu.setForeground(0xFFFFFF)
gpu.setBackground(0xAAAAAA)
gpu.set(1+5*(i-2), pos+1+4*(int-1), pbe)
gpu.setForeground(0xFFFFFF)
gpu.setBackground(0x000000)
end
end
while(gate.getGateStatus() ~= "idle") do os.sleep(0) end
gpu.set(9, pos+4*(int-1), "Shevron 7 - locked ")
pc.beep(180, 0.1)
gpu.setForeground(0xFFFFFF)
gpu.setBackground(0xAAAAAA)
gpu.set(31, pos+1+4*(int-1), pbe)
gpu.setForeground(0xFFFFFF)
gpu.setBackground(0x000000)
os.sleep(0.16)
end
--dial--
--calculation functions--
function vround(vec)
local new = {}
new = valtround(vec.x, vec.y, vec.z)
return new
end
function valtround(vx, vy, vz)
local new = {}
new.x = vx
new.y = vy
new.z = vz
local t1, t2 = 0
t1, t2 = math.modf(vx)
t2 = t2 - math.fmod(t2*rounder, 1)/rounder
new.x = t1+t2
t1, t2 = math.modf(vy)
t2 = t2 - math.fmod(t2*rounder, 1)/rounder
new.y = t1+t2
t1, t2 = math.modf(vz)
t2 = t2 - math.fmod(t2*rounder, 1)/rounder
new.z = t1+t2
return new
end
function vprojxy(vec)
local new = {}
new = valtprojxy(vec.x, vec.y, vec.z)
return new
end
function valtprojxy (vx, vy, vz)
local new = {}
new.x = vx
new.y = vy
new.z = 0
return new
end
function vprojyz(vec)
local new = {}
new = valtprojyz(vec.x, vec.y, vec.z)
return new
end
function valtprojyz (vx, vy, vz)
local new = {}
new.y = vy
new.z = vz
new.x = 0
return new
end
function vprojxz(vec)
local new = {}
new = valtprojxz(vec.x, vec.y, vec.z)
return new
end
function valtprojxz (vx, vy, vz)
local new = {}
new.x = vx
new.z = vz
new.y = 0
return new
end
function vlen(vec)
local new = 0
new = valtlen(vec.x, vec.y, vec.z)
return new
end
function valtlen(vx, vy, vz)
local new
new = math.sqrt(vx*vx+vy*vy+vz*vz)
return new
end
function vmulvec(a, b)
local new = {}
new = valtmulvec(a.x, a.y, a.z, b.x, b.y, b.z)
return new
end
function valtmulvec(ax, ay, az, bx, by, bz)
local new = {}
new.x = ax*bx
new.y = ay*by
new.z = az*bz
return new
end
function vcosab(a, b)
local new = 0
new = valtcosab(a.x, a.y, a.z, b.x, b.y, b.z)
return new
end
function valtcosab (ax, ay, az, bx, by, bz)
local cos
cos = (ax*bx+ay*by+az*bz)/(valtlen(ax, ay, az)*valtlen(bx, by, bz))
return cos
end
function vsinab(a, b)
local new = 0
new = valtsinab(a.x, a.y, a.z, b.x, b.y, b.z)
return new
end
function valtsinab (ax, ay, az, bx, by, bz)
local sin
sin = math.sqrt(1 - valtcosab(ax, ay, az, bx, by, bz)*valtcosab(ax, ay, az, bx, by, bz))
if (bx == 1 and ay < 0) or (by == 1 and az < 0) or (bz == 1 and ax < 0) then sin = 0-sin end
return sin
end
function vadd(a, b)
local new = {}
new = valtadd(a.x, a.y, a.z, b.x, b.y, b.z)
return new
end
function valtadd (ax, ay, az, bx, by, bz)
local new = {}
new.x = ax + bx
new.y = ay + by
new.z = az + bz
return new
end
function vsub(a, b)
local new = {}
new = valtsub(a.x, a.y, a.z, b.x, b.y, b.z)
return new
end
function valtsub (ax, ay, az, bx, by, bz)
local new = {}
new.x = ax - bx
new.y = ay - by
new.z = az - bz
return new
end
function vmul(vec, num)
local new = {}
new = valtmul(vec.x, vec.y, vec.z, num)
return new
end
function valtmul (vx, vy, vz, num)
local vec = {}
vec.x = vx
vec.y = vy
vec.z = vz
local new = {}
new.x = vec.x * num
new.y = vec.y * num
new.z = vec.z * num
return new
end
function vdiv(vec, num)
local new = {}
new = valtdiv(vec.x, vec.y, vec.z, num)
return new
end
function valtdiv (vx, vy, vz, num)
local vec = {}
vec.x = vx
vec.y = vy
vec.z = vz
local new = {}
new.x = vec.x / num
new.y = vec.y / num
new.z = vec.z / num
return new
end
function vrotx(vec)
local new = {}
local sinang, cosang = 0
if (vec.y == 0) then
new = vec
sinang = 0
cosang = 1
else
new.x = vec.x
new.y = 0
new.z = math.sqrt(vec.y*vec.y+vec.z*vec.z)
cosang = vec.z/(math.sqrt(vec.y*vec.y+vec.z*vec.z))
sinang = math.sqrt(1 - cosang*cosang) * (vec.y/math.abs(vec.y))
end
return new, cosang, sinang
end
function vangrotx(vec, cos, sin)
local new = {}
new.x = vec.x
new.y = vec.y*cos - vec.z*sin
new.z = vec.y*sin + vec.z*cos
return new
end
function vrerotx(vec, cos, sin)
local new = {}
new.x = vec.x
new.y = vec.z * sin + vec.y * cos
new.z = vec.z * cos - vec.y * sin
return new
end
function vroty(vec)
local new = {}
local sinang, cosang = 0
if (vec.z == 0) then
new = vec
sinang = 0
cosang = 1
else
new.x = math.sqrt(vec.x*vec.x+vec.z*vec.z)
new.y = vec.y
new.z = 0
cosang = vec.x/(math.sqrt(vec.x*vec.x+vec.z*vec.z))
sinang = math.sqrt(1 - cosang*cosang) * (vec.z/math.abs(vec.z))
end
return new, cosang, sinang
end
function vangroty(vec, cos, sin)
local new = {}
new.x = vec.z * sin + vec.x * cos
new.y = vec.y
new.z = vec.z * cos - vec.x * sin
return new
end
function vreroty(vec, cos, sin)
local new = {}
new.x = vec.x * cos - vec.z * sin
new.y = vec.y
new.z = vec.x * sin + vec.z * cos
return new
end
function vrotz(vec)
local new = {}
local sinang, cosang = 0
if (vec.x == 0) then
new = vec
sinang = 0
cosang = 1
else
new.x = 0
new.y = math.sqrt(vec.y*vec.y+vec.x*vec.x)
new.z = vec.z
cosang = vec.y/(math.sqrt(vec.y*vec.y+vec.x*vec.x))
sinang = math.sqrt(1 - cosang*cosang) * (vec.x/math.abs(vec.x))
end
return new, cosang, sinang
end
function vangrotz(vec, cos, sin)
local new = {}
new.x = vec.x * cos - vec.y * sin
new.y = vec.x * sin + vec.y * cos
new.z = vec.z
return new
end
function vrerotz(vec, cos, sin)
local new = {}
new.x = vec.y * sin + vec.x * cos
new.y = vec.y * cos - vec.x * sin
new.z = vec.z
return new
end
function trilateration (v1, v2, v3, v4, e1, e2, e3, e4)
local vi = {}
local vj = {}
vi.x = 1
vi.y = 0
vi.z = 0
vj.x = 0
vj.y = 1
vj.z = 0
local s1, s2, s3, s4 = 0
if e1/4608 > 4000 then s1 = math.pow(5000, (e1/4608/5000)) else s1 = e1/4608 / (0.8) end
if e2/4608 > 4000 then s2 = math.pow(5000, (e2/4608/5000)) else s2 = e2/4608 / (0.8) end
if e3/4608 > 4000 then s3 = math.pow(5000, (e3/4608/5000)) else s3 = e3/4608 / (0.8) end
if e4/4608 > 4000 then s4 = math.pow(5000, (e4/4608/5000)) else s4 = e4/4608 / (0.8) end
local new = {}
local v11 = vsub(v1, v1) -- make a sphere with 0.0.0 center
local v21 = vsub(v2, v1)
local v31 = vsub(v3, v1)
local v41 = vsub(v4, v1)
local v22, tricos1, trisin1 = vroty(v21) -- make a sphere with x.0.0 center
local v32 = vangroty(v31, tricos1, trisin1)
local v42 = vangroty(v41, tricos1, trisin1)
local tricos2 = vcosab(vprojxy(v22), vi)
local trisin2 = vsinab(vprojxy(v22), vi)
local v23 = vrerotz(v22, tricos2, trisin2)
local v33 = vrerotz(v32, tricos2, trisin2)
local v43 = vrerotz(v42, tricos2, trisin2)
local vectimed = vprojyz(v33)
local tricos3 = vcosab(vectimed, vj)
local trisin3 = vsinab(vectimed, vj)
local v34 = vrerotx(v33, tricos3, trisin3) -- make a sphere with x.y.0 center
local v44 = vrerotx(v43, tricos3, trisin3)
new.x = (s1*s1-s2*s2+v23.x*v23.x)/(2*v23.x)
local xrot = new.x/(math.modf(new.x*2)/2)
s1 = s1/xrot
new.x = new.x / xrot
new.y = (s1*s1 - s3*s3 + (v34.x*v34.x+v34.y*v34.y)-2*v34.x*new.x) / (2*v34.y)
local mayz = math.sqrt(math.abs(s1*s1-(new.x*new.x+new.y*new.y)))
if (math.abs(s4-math.sqrt(math.pow((new.x-v44.x), 2)+math.pow((new.y-v44.y), 2)+math.pow((mayz-v44.z),2))) <= math.abs(s4-math.sqrt(math.pow((new.x-v44.x), 2)+math.pow((new.y-v44.y), 2)+math.pow(((0-mayz)-v44.z),2)))) then
new.z = mayz
else
new.z = 0-mayz
end
local newx = vangrotx(new, tricos3, trisin3)
local newxz = vangrotz(newx, tricos2, trisin2)
local newxyz = vreroty(newxz, tricos1, trisin1)
local newtarg = vadd(newxyz, v1)
return newtarg
end
--calculation functions--
--split--
function split(pString, pPattern)
local Table = {}
local fpat = "(.-)" .. pPattern
local last_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table,cap)
end
last_end = e+1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
--split--
--Milkyway glyph sorting method choose--
function sortchoose()
term.clear()
sortmode = io.open("sort.ff", "r")
if (sortmode == nil or sortmode:seek("end") == 0) then
sortmode = io.open("sort.ff", "w")
term.write("Milkyway glyph sorting.\nChoose one: 1 - gate clockwise sorting, 2 - DHD clockwise sorting, 3 - alphabet sorting.\n")
while (true) do
local _, choose = pcall(io.read)
if (choose == "1" or choose == "2" or choose == "3") then
sortmode:write(string.format("sort = %s", choose))
sortmode:close()
break
else
term.write("Wrong value!\n")
end
end
else
sortmode:seek("set")
end
sortmode:close()
dofile("sort.ff")
end
sortchoose()
if(sort == 1) then dofile("MWGS.ff") elseif(sort == 2) then dofile("MWDS.ff") else dofile("MWAS.ff") end
--Milkyway glyph sorting method choose--
--test link--
function testlink(_, _, rec, _, _, msg)
if msg == "link" then
linktest = true
srec = rec
end
end
--test link--
--slave add screen touch--
function slavetouch(_, _, x, y)
local num = 0
if (x > 161-addx and y > 5 and y < addy+5 and x ~= 160-addx+addmod and #add<6) then
pc.beep(150, 0.1)
if (x < 160-addx+addmod and glmass[y-5] ~= "") then
num = y-5
local check = true
if #add > 0 then
for i = 1, #add do
if add[i] == glmass[num] then check = false break end
end
if check then
add[#add+1] = glmass[num]
gpu.setBackground(0x666666)
gpu.setForeground(0xFFC400)
local str = glmass[num]
while #str < addmod-2 do str = string.format("%s%s", str, " ") end
gpu.set(162-addx, y, str)
gpu.setBackground(0x000000)
gpu.setForeground(0xFFFFFF)
end
else
add[1] = glmass[num]
gpu.setBackground(0x666666)
gpu.setForeground(0xFFC400)
local str = glmass[num]
while #str < addmod-2 do str = string.format("%s%s", str, " ") end
gpu.set(162-addx, y, str)
gpu.setBackground(0x000000)
gpu.setForeground(0xFFFFFF)
end
elseif (glmass[y-6+addy] ~= "") then
num = y-6+addy
local check = true
if #add > 0 then
for i = 1, #add do
if add[i] == glmass[num] then check = false break end
end
if check then
add[#add+1] = glmass[num]
gpu.setBackground(0x666666)
gpu.setForeground(0xFFC400)
local str = glmass[num]
while #str < addmod-2 do str = string.format("%s%s", str, " ") end
gpu.set(161-addx+addmod, y, str)
gpu.setBackground(0x000000)
gpu.setForeground(0xFFFFFF)
end
else
add[1] = glmass[num]
gpu.setBackground(0x666666)
gpu.setForeground(0xFFC400)
local str = glmass[num]
while #str < addmod-2 do str = string.format("%s%s", str, " ") end
gpu.set(161-addx+addmod, y, str)
gpu.setBackground(0x000000)
gpu.setForeground(0xFFFFFF)
end
end
local l = 0
gpu.setForeground(0xFFFFFF)
for line in GlyphImages[add[#add]]:gmatch("[^\r\n]+") do
gpu.set((#add-1)*(addmod-2)+2, 6+l, line)
l = l+1
end
elseif (x > 141 and x < 149 and y == addy+6) then
pc.beep(120, 0.05)
pc.beep(150, 0.05)
add = {}
gpu.setBackground(0x000000)
gpu.setForeground(0xFFFFFF)
if gate.getGateType() == "MILKYWAY" then
addx = 34 addy = 20 addmod = 18 glmass = mwf
elseif gate.getGateType() == "UNIVERSE" then
addx = 18 addy = 19 addmod = 10 glmass = unf
end
for i = 0, addy do
local str = ""
if i == 0 then
for j = 1, addx do
if j == 1 then str = "┌" elseif j == addmod then str = string.format("%s%s", str, "┬") else str = string.format("%s%s", str, "─") end end
elseif i == addy then
for j = 1, addx do
if j == 1 then str = "└" elseif j == addmod then str = string.format("%s%s", str, "┴") else str = string.format("%s%s", str, "─") end end
else
str = string.format("%s%s", "│", glmass[i]) while #str < addmod+1 do str = string.format("%s%s", str, " ") end str = string.format("%s%s%s", str, "│", glmass[i+addy-1]) while #str < addx+4 do str = string.format("%s%s", str, " ") end
end
gpu.set(161-addx,i+5, str)
end
local adx, ady, admod
if gate.getGateType() == "MILKYWAY" then
adx = 9 ady = 97 admod = 16 dofile("MWG.ff")
elseif gate.getGateType() == "UNIVERSE" then
adx = 19 ady = 49 admod = 8 dofile("UNG.ff")
end
for i = 0, adx do
local str = ""
for j = 1, ady do
if math.fmod(j-1, admod) == 0 then
if i == 0 then
if j == 1 then str = "┌" elseif j == ady then str = string.format("%s%s", str, "┐") else str = string.format("%s%s", str, "┬") end
elseif i == adx then
if j == 1 then str = "└" elseif j == ady then str = string.format("%s%s", str, "┘") else str = string.format("%s%s", str, "┴") end
else
str = string.format("%s%s", str, "│")
end
else
if i == 0 or i == adx then str = string.format("%s%s", str, "─") else str = string.format("%s%s", str, " ") end
end
end
gpu.set(1,i+5, str)
end
elseif (x > 152 and y == addy+6) then
pc.beep(180, 0.1)
if #add == 6 then
if (gate.getEnergyRequiredToDial(add) ~= "address_malformed" and gate.getEnergyRequiredToDial(add) ~= "not_merged") then
if (gate.getEnergyRequiredToDial(add).open + gate.getEnergyRequiredToDial(add).keepAlive*10 < gate.getEnergyStored()) then
gpu.set(9, 28, "Prepare for dialing")
gate.disengageGate()
gate.engageGate()
if gate.getGateType() == "MILKYWAY" then
add[7] = "Point of Origin"
elseif gate.getGateType() == "UNIVERSE" then
add[7] = "Glyph 17"
end
while(gate.getGateStatus() ~= "idle") do os.sleep(0.2) gpu.set(1,42, string.format("Address: %u RF", gate.getEnergyRequiredToDial(add).open + gate.getEnergyRequiredToDial(add).keepAlive*10)) end
os.sleep(0.25)
dial(add, 1)
gate.engageGate()
while(gate.getGateStatus() ~= "open") do os.sleep(0.2) gpu.set(1,42, string.format("Address: %u RF", gate.getEnergyRequiredToDial(add).open + gate.getEnergyRequiredToDial(add).keepAlive*10)) end
os.sleep(0.25)
gpu.set(9, 28, "Data transmission ")
linktest = false
srec = ""
event.ignore("modem_message", testlink)
event.listen("modem_message", testlink)
modem.broadcast(1001, "link")
for i = 1,10 do os.sleep(0.2) gpu.set(1,42, string.format("Address: %u RF", gate.getEnergyRequiredToDial(add).open + gate.getEnergyRequiredToDial(add).keepAlive*10)) end
event.ignore("modem_message", testlink)
if (linktest) then
gpu.set(9, 28, "Data received ")
gate.disengageGate()
slmod[slnum] = srec
sladd[slnum] = add
add = {}
if gate.getGateType() == "MILKYWAY" then
sladd[slnum][7] = "Point of Origin"
elseif gate.getGateType() == "UNIVERSE" then
sladd[slnum][7] = "Glyph 17"
end
tloop = false
else
gpu.set(1,50,"PC not found. Please install PC/Server with this program and wireless card on the other side of gate link or close wormhole.")
os.sleep(1)
gpu.fill(1,50,160,1," ")
end
else
gpu.set(1,50,string.format("Not enough energy. You need at least %u RF.", gate.getEnergyRequiredToDial(add).open + gate.getEnergyRequiredToDial(add).keepAlive*10))
os.sleep(1)
gpu.fill(1,50,160,1," ")
end
else
add = {}
local adx, ady, admod
if gate.getGateType() == "MILKYWAY" then
adx = 9 ady = 97 admod = 16 dofile("MWG.ff")
elseif gate.getGateType() == "UNIVERSE" then
adx = 19 ady = 49 admod = 8 dofile("UNG.ff")
end
for i = 0, adx do
local str = ""
for j = 1, ady do
if math.fmod(j-1, admod) == 0 then
if i == 0 then
if j == 1 then str = "┌" elseif j == ady then str = string.format("%s%s", str, "┐") else str = string.format("%s%s", str, "┬") end
elseif i == adx then
if j == 1 then str = "└" elseif j == ady then str = string.format("%s%s", str, "┘") else str = string.format("%s%s", str, "┴") end
else
str = string.format("%s%s", str, "│")
end
else
if i == 0 or i == adx then str = string.format("%s%s", str, "─") else str = string.format("%s%s", str, " ") end
end
end
gpu.set(1,i+5, str)
end
gpu.set(1,50,"Wrong address")
os.sleep(1)
gpu.fill(1,50,60,1," ")
end
else
add = {}
local adx, ady, admod
if gate.getGateType() == "MILKYWAY" then
adx = 9 ady = 97 admod = 16 dofile("MWG.ff")
elseif gate.getGateType() == "UNIVERSE" then
adx = 19 ady = 49 admod = 8 dofile("UNG.ff")
end
for i = 0, adx do
local str = ""
for j = 1, ady do
if math.fmod(j-1, admod) == 0 then
if i == 0 then
if j == 1 then str = "┌" elseif j == ady then str = string.format("%s%s", str, "┐") else str = string.format("%s%s", str, "┬") end
elseif i == adx then
if j == 1 then str = "└" elseif j == ady then str = string.format("%s%s", str, "┘") else str = string.format("%s%s", str, "┴") end
else
str = string.format("%s%s", str, "│")
end
else
if i == 0 or i == adx then str = string.format("%s%s", str, "─") else str = string.format("%s%s", str, " ") end
end
end
gpu.set(1,i+5, str)
end
gpu.set(1,50,"Wrong address")
os.sleep(1)
gpu.fill(1,50,60,1," ")
end
end
end
--slave add screen touch--
--coordinates check--
function coordchk(check)
local book
local coo = {}
book = io.open("coord.ff", "r")
if (book == nil or book:seek("end") == 0 or check) then
term.clear()
book = io.open("coord.ff", "w")
print("Please enter the coordinates of the gate core:\n1) Press F3.\n2) Look at the gate core.\n3) Find the line \"Looking at:\".\n4) Add 0.5 to each coordinate (4 + 0.5 = 4.5, -25 + 0.5 = -24.5).\n5) Enter the resulting coordinates in \"x, y, z\" format. The separator \", \" is mandatory.\nExample: -25.5, 14.5, 6.5")
local str = io.read()
coo = split(str, ", ")
book:write(string.format("x = %s\n", coo[1]))
book:write(string.format("y = %s\n", coo[2]))
book:write(string.format("z = %s\n", coo[3]))
book:close()
end
book:close()
dofile("coord.ff")
end
coordchk(false)
--coordinates check--
--slaves check--
function slvchk(flag)
local book
if gate.getGateType() == "MILKYWAY" then
book = io.open("MWslaves.ff", "r")
elseif gate.getGateType() == "UNIVERSE" then
book = io.open("UNslaves.ff", "r")
end
if (book == nil or book:seek("end") == 0 or flag) then
if gate.getGateType() == "MILKYWAY" then
book = io.open("MWslaves.ff", "w")
elseif gate.getGateType() == "UNIVERSE" then
book = io.open("UNslaves.ff", "w")
end
for i = 1, 3 do
term.clear()
os.sleep(0.5)
gpu.setForeground(0xFFFFFF)
term.setCursor(1,1)
term.write("Please, write address of slave gates (without PoO or G17).")
term.setCursor(1,4)
term.write(string.format("Slave #%u address:", i))
gpu.set(1, 27, "Current gate")
gpu.set(1, 28, "Status: Idle")
gpu.set(1, 29, string.format("%s%s%s%s%s%s%s", pbe, pbe, pbe, pbe, pbe, pbe, pbe))
gpu.fill(1,26,50,1,"─")
gpu.fill(1,30,50,1,"─")
gpu.fill(51,27,1,3,"│")
gpu.set(51,26,"┐")
gpu.set(51,30,"┘")
gpu.set(61,48,"┐")
gpu.fill(1,48,60,1,"─")
gpu.fill(61,49,1,2,"│")
gpu.set(51,40,"┐")
gpu.set(51,44,"┘")
gpu.fill(1,40,50,1,"─")
gpu.fill(1,44,50,1,"─")
gpu.fill(51,41,1,3,"│")
gpu.set(1,41, "Energy requirements:")
gpu.set(1,42, "Address: Unknown")
gpu.set(1,49,"System message:")
local adx, ady, admod
if gate.getGateType() == "MILKYWAY" then
adx = 9 ady = 97 admod = 16 dofile("MWG.ff")
elseif gate.getGateType() == "UNIVERSE" then
adx = 19 ady = 49 admod = 8 dofile("UNG.ff")
end
for i = 0, adx do
local str = ""
for j = 1, ady do
if math.fmod(j-1, admod) == 0 then
if i == 0 then
if j == 1 then str = "┌" elseif j == ady then str = string.format("%s%s", str, "┐") else str = string.format("%s%s", str, "┬") end
elseif i == adx then
if j == 1 then str = "└" elseif j == ady then str = string.format("%s%s", str, "┘") else str = string.format("%s%s", str, "┴") end
else
str = string.format("%s%s", str, "│")
end
else
if i == 0 or i == adx then str = string.format("%s%s", str, "─") else str = string.format("%s%s", str, " ") end
end
end
gpu.set(1,i+5, str)
end
if gate.getGateType() == "MILKYWAY" then
addx = 34 addy = 20 addmod = 18 glmass = mwf
elseif gate.getGateType() == "UNIVERSE" then
addx = 18 addy = 19 addmod = 10 glmass = unf
end
for i = 0, addy do
local str = ""
if i == 0 then
for j = 1, addx do
if j == 1 then str = "┌" elseif j == addmod then str = string.format("%s%s", str, "┬") else str = string.format("%s%s", str, "─") end end
elseif i == addy then
for j = 1, addx do
if j == 1 then str = "└" elseif j == addmod then str = string.format("%s%s", str, "┴") else str = string.format("%s%s", str, "─") end end
else
str = string.format("%s%s", "│", glmass[i]) while #str < addmod+1 do str = string.format("%s%s", str, " ") end str = string.format("%s%s%s", str, "│", glmass[i+addy-1])
end
gpu.set(161-addx,i+5, str)
end
gpu.set(142,addy+6,"[CLEAR] [ DIAL ]")
slnum = i
local ignor = true
while ignor do
ignor = event.ignore("touch", slavetouch)
end
event.listen("touch", slavetouch)
tloop = true
while tloop do os.sleep(0.2) gpu.set(1,43, string.format("Current: %u RF", gate.getEnergyStored())) end
end
book:write(string.format("slmod = {\"%s\", \"%s\", \"%s\"}\n", slmod[1], slmod[2], slmod[3]))
for i = 1, 3 do
local str = string.format("sladd[%u] = {", i)
for int, val in ipairs(sladd[i]) do
if int == 1 then str = string.format("%s\"%s\"", str, val) else str = string.format("%s, \"%s\"", str, val) end
end
str = string.format("%s}\n", str)
book:write(str)
end
goto slaveend
else goto slaveend
end
::slaveend::
book:close()
if gate.getGateType() == "MILKYWAY" then
dofile("MWslaves.ff")
elseif gate.getGateType() == "UNIVERSE" then
dofile("UNslaves.ff")
end
end
--slaves check--
--mode choose--
function modechoose()
term.clear()
book = io.open("pmode.ff", "r")
if (book == nil or book:seek("end") == 0) then
book = io.open("pmode.ff", "w")
term.write("Please select an operating mode:\nMASTER MODE - in this mode the computer will connect the gate to the gate in \"SLAVE MODE\" mode, receive data from it and perform calculations.\nEnergy is mandatory for both the computer and the gate.\nIt is not necessary to load the chunk, as the chunks around the player will be loaded automatically.\nSLAVE MODE - in this mode the computer will operate as a \"calculating beacon\" and will only transmit data to the computer in MASTER MODE.\nThe computer will transmit data by itself in the background mode, so therefore no further control of the computer is possible.\nEnergy for the computer is mandatory, but for the gate it is not. These computers should be at least in 3 instances.\nBoth the gate and the computer should be in a loaded chunk.\n1 - Master mode, 0 - Slave mode.\nYou cannot change it until you delete file /AGSS/mode.ff\n")
while (true) do
local _, choose = pcall(io.read)
if (choose == "1" or choose == "0") then
book:write(string.format("%s", choose))
book:close()
break
else
term.write("Wrong value!\n")
end
end
else
book:seek("set")
end
book:close()
book = io.open("pmode.ff", "r")
pmode = book:read()
book:close()
term.clear()
end
--mode choose--
--main screen touch--
function maintouch(_, _, sx, sy)
local s1st = 0
local s2st = 0
local s3st = 0
local num = 0
dofile("coord.ff")
if (sx > 161-addx and sy > 5 and sy < addy+5 and sx ~= 160-addx+addmod and #add<6) then
if #add == 0 then
gpu.setBackground(0x000000)
gpu.setForeground(0xFFFFFF)
if gate.getGateType() == "MILKYWAY" then
addx = 34 addy = 20 addmod = 18 glmass = mwf
elseif gate.getGateType() == "UNIVERSE" then
addx = 18 addy = 19 addmod = 10 glmass = unf
end
for i = 0, addy do
local str = ""
if i == 0 then
for j = 1, addx do
if j == 1 then str = "┌" elseif j == addmod then str = string.format("%s%s", str, "┬") else str = string.format("%s%s", str, "─") end
end
elseif i == addy then
for j = 1, addx do
if j == 1 then str = "└" elseif j == addmod then str = string.format("%s%s", str, "┴") else str = string.format("%s%s", str, "─") end
end
else
str = string.format("%s%s", "│", glmass[i]) while #str < addmod+1 do str = string.format("%s%s", str, " ") end str = string.format("%s%s%s", str, "│", glmass[i+addy-1]) while #str < addx+4 do str = string.format("%s%s", str, " ") end
end
gpu.set(161-addx,i+5, str)
end
end
pc.beep(150, 0.1)
if (sx < 160-addx+addmod and glmass[sy-5] ~= "") then
num = sy-5
local check = true
if #add > 0 then
for i = 1, #add do
if add[i] == glmass[num] then check = false break end
end
if check then
add[#add+1] = glmass[num]
gpu.setBackground(0x666666)
gpu.setForeground(0xFFC400)
local str = glmass[num]
while #str < addmod-2 do str = string.format("%s%s", str, " ") end
gpu.set(162-addx, sy, str)
gpu.setBackground(0x000000)
gpu.setForeground(0xFFFFFF)
end
else
add[1] = glmass[num]
gpu.setBackground(0x666666)
gpu.setForeground(0xFFC400)
local str = glmass[num]
while #str < addmod-2 do str = string.format("%s%s", str, " ") end
gpu.set(162-addx, sy, str)
gpu.setBackground(0x000000)
gpu.setForeground(0xFFFFFF)
end
elseif (glmass[sy-6+addy] ~= "") then
num = sy-6+addy
local check = true
if #add > 0 then
for i = 1, #add do
if add[i] == glmass[num] then check = false break end
end
if check then
add[#add+1] = glmass[num]
gpu.setBackground(0x666666)
gpu.setForeground(0xFFC400)
local str = glmass[num]
while #str < addmod-2 do str = string.format("%s%s", str, " ") end
gpu.set(161-addx+addmod, sy, str)
gpu.setBackground(0x000000)
gpu.setForeground(0xFFFFFF)
end
else
add[1] = glmass[num]
gpu.setBackground(0x666666)
gpu.setForeground(0xFFC400)
local str = glmass[num]
while #str < addmod-2 do str = string.format("%s%s", str, " ") end
gpu.set(161-addx+addmod, sy, str)
gpu.setBackground(0x000000)
gpu.setForeground(0xFFFFFF)
end
end
local l = 0
gpu.setForeground(0xFFFFFF)
for line in GlyphImages[add[#add]]:gmatch("[^\r\n]+") do
gpu.set((#add-1)*(addmod-2)+2, 6+l, line)
l = l+1
end
elseif (sx > 152 and sy == addy+6) then
pc.beep(120, 0.05)
pc.beep(180, 0.05)
gpu.fill(123,48,60,3," ")
for i = 1, 3 do
local bool = {0, 0, 0, 0, 0, 0}
for j = 1, 6 do
if add[j] == sladd[i][j] then bool[j] = 1 end
end