Repository navigation
Expand file tree
/
Copy pathdercc.lua
More file actions
1224 lines (1128 loc) · 37.6 KB
/
Copy pathdercc.lua
File metadata and controls
1224 lines (1128 loc) · 37.6 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
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
--dercc (Draconic Evolution Reactor Complete Control) V1.1
--Official Stamper (c) Aug 2018
--Changelog V1.0.1 added maxFuel = 10368 to use as factor in getOutFlux function
-- V1.0.2 added tempDrainFactor to info. and fuelUseRate to getOutFlux, but made no difference to low fuel calcs :(
-- V1.1.0 added OpenComputers layer
-- *** REQUIRED *** --
local modemTx = 21 -- Must be a unique channel not used by any other computer on the server and MUST be the same as the reactor modem channel(s)
local modemRx = 21 -- Must be a unique channel not used by any other computer on the server and MUST be the same as the reactor modem channel(s)
-- *** REQUIRED FOR COMPUTERCRAFT *** --
local modemSide = 'back'
local monitorSide = 'top'
local inFluxSide = 'right' -- required for CC (ComputerCraft) only, Side of the Flux Gate used as Input into the reactor to power the Containment Field and warm up the reactor
local outFluxSide = 'left' -- required for CC (ComputerCraft) only, Side of the Flux Gate used as Output of RF from reactor into your RF Storeage solution
-- *** REQUIRED FOR OPENCOMPUTERS *** --
local inFluxAddr = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' -- required for OC (OpenComputers) only, Address of the Flux Gate used as Input into the reactor to power the Containment Field and warm up the reactor
local outFluxAddr = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' -- required for OC (OpenComputers) only, Address of the Flux Gate used as Output of RF from reactor into your RF Storage solution
-- *** STARTUP VALUES *** --
local reqTemp = 6000 -- Default starting required temperature (this is used if error caused reboot or server restarts)
local reqField = 10 -- Default starting required field (this is used if error caused reboot or server restarts)
-- Recommended no other values below are changed
-- Debug only
local skip = 0
-- Startup Values
local waitTime = 0.15 -- time/ticks between event operations (0.05 = 1 tick @ 20TPS) - time to wait for modem to respond, recommended value 0.10
local minTemp = 2500 -- minimum temperature allowed (also used for fail-safe, do not change)
local maxTemp = 8000 -- maximum temperature allowed
local cutoffTemp = 8100 -- shutdown reactor if temp exceeds this value
local warmUpRF = 20000000 -- how much RF/t to inject to warm reactor up to get to over 2000C
local minField = 1 -- minimum field percentage allowed
local maxField = 90 -- maximum field percentaged allowed
local inFluxRF = 0 -- default value for offline, cooling or cold
local outFluxRF = 20 -- default value for offline, cooling or cold
local graphLen = 44 -- width graphs will take on screen
local screenWidth = 50 -- width of screen
-- Tweaks
local outTrimPct = 1 -- 2 = 200%, 1 = 100%, 0.5 = 50% the percentage of the genRate difference to trim the outFluxRF
-- other variable initialisation (do not change these values as declare and/or constants only)
local info = {} -- table for holding reactor.info
local debugMode = false -- flag used to indicate if the monitor is on the debug screen or normal screen array
local msg = '' -- for sending adhoc messages to screen
local timerId = 0 -- event timer
local oc_id = 0 -- because OpenComputers timer Id's do not work
local maxId = 65535 -- maximun number that can be sent as a modem id
local maxFuel = 10368 -- maximum possible fuel
local maxInteger = 2147483647 -- maximun integer allowed (math.maxInteger doesn't seem to work here)
--Peripherals and components (do not initialise to values)
local monitor
local modem
local outFlux = {}
local inFlux = {}
local serialization
local fileIO
--check os version
local OSVer = ""
local OC = false
local CC = false
if _OSVERSION then
OSVer = _OSVERSION
OC = true
elseif os.version() then
OSVer = os.version()
CC = true
else
print("OS not supported!")
return
end
print("OSVer: "..OSVer)
print("OpenComputers: "..tostring(OC))
print("ComputerCraft: "..tostring(CC))
--ComputerCraft - wrap the peripherals
if CC then
fileIO = fs
monitor = peripheral.wrap(monitorSide)
modem = peripheral.wrap(modemSide)
if not modem then print("No modem found, please attach an 'Ender Modem'"); return; end
outFlux = peripheral.wrap(outFluxSide)
if not outFlux then print("No Flux Gate found for side '"..outFluxSide.."', please attach a Flux Gate"); return; end
inFlux = peripheral.wrap(inFluxSide)
if not inFlux then print("No Flux Gate found for side '"..inFluxSide.."', please attach a Flux Gate"); return; end
print('inFlux='..inFluxSide)
print('outFlux='..outFluxSide)
end
--OpenComputers - Override ComputerCraft API's to make compatable with OpenComputers
if OC then
local component = require("component")
local computer = require("computer")
local event = require("event")
local term = require("term")
fileIO = require("filesystem")
serialization = require("serialization")
--GPU check
if not component.gpu or component.gpu.getDepth() ~= 8 then
print("No GPU or incorrect Tier GPU present, please install Graphics Card (Tier 3)")
os.exit()
end
local gpu = component.gpu
--Modem Check
if not component.modem or not component.modem.isWireless() then
print("No wireless modem present, please install Wireless Network Card (Tier 2)")
os.exit()
end
modem = component.modem
--Flux gate checks
for i, v in pairs(component.list("flux_gate")) do
print("Found: "..v.." : "..i)
if i == inFluxAddr then inFlux = component.proxy(inFluxAddr) end
if i == outFluxAddr then outFlux = component.proxy(outFluxAddr) end
end
if not inFlux.address or not outFlux.address then
print("Flux Gate(s) are not present or incorrect address specified, please check flux gates and address(s) specified")
print("inFluxAddr: "..inFluxAddr.." Found: "..tostring(inFlux.address))
print("outFluxAddr: "..outFluxAddr.." Found: "..tostring(outFlux.address))
os.exit()
end
-- Overrides
modem.transmit = modem.broadcast
colors = {
white =0xF0F0F0,
orange =0xF2B233,
magenta =0xE57FD8,
lightBlue =0x99B2F2,
yellow =0xDEDE6C,
lime =0x7FCC19,
pink =0xF2B2CC,
gray =0x4C4C4C,
lightGray =0x999999,
cyan =0x4C99B2,
purple =0xB266E5,
blue =0x3366CC,
brown =0x7F664C,
green =0x57A64E,
red =0xCC4C4C,
black =0x191919,
['0'] =0xF0F0F0,
['1'] =0xF2B233,
['2'] =0xE57FD8,
['3'] =0x99B2F2,
['4'] =0xDEDE6C,
['5'] =0x7FCC19,
['6'] =0xF2B2CC,
['7'] =0x4C4C4C,
['8'] =0x999999,
['9'] =0x4C99B2,
a =0xB266E5,
b =0x3366CC,
c =0x7F664C,
d =0x57A64E,
e =0xCC4C4C,
f =0x191919
}
monitor = {
setResolution = function(inX, inY) gpu.setResolution(inX, inY) end,
resetResolution = function() local rx, ry = gpu.maxResolution(); gpu.setResolution(rx, ry) end,
setBackgroundColor = function(inCol) gpu.setBackground(inCol) end,
setTextColor = function(inCol) gpu.setForeground(inCol) end,
setCursorPos = function(inX, inY) term.setCursor(inX, inY) end,
write = function(inStr) term.write(inStr, false) end,
blit = function(inStr, fCol, bCol)
local _f = string.sub(fCol, 1, 1)
local _b = string.sub(bCol, 1, 1)
local _p = 1
local _l = string.len(inStr)
for i = 1, _l do
if string.sub(fCol, i, i) ~= _f or string.sub(bCol, i, i) ~= _b or i == _l then
gpu.setBackground(colors[_b])
gpu.setForeground(colors[_f])
term.write(string.sub(inStr, _p, i - 1 + ((i == _l) and 1 or 0)))
_f = string.sub(fCol, i, i)
_b = string.sub(bCol, i, i)
_p = i
end
end
end,
clear = function() term.clear() end
}
os.getComputerID = computer.address
os.pullEvent = event.pull
os.queueEvent = event.push
local function ocTimer()
event.push('timer', timerId)
end
os.startTimer = function(inWaitTime)
--OpenComputers does not return a unique Event Id, so have to manage our own
local _id = timerId + 1
if _id >= maxInteger - 1 then _id = 1 end
oc_id = event.timer(inWaitTime, ocTimer)
return _id
end
os.cancelTimer = function()
event.cancel(oc_id)
end
os.reboot = function()
computer.shutdown(true)
end
end
local function modTemp(val)
reqTemp = reqTemp + val
if reqTemp > maxTemp then reqTemp = maxTemp end
if reqTemp < minTemp then reqTemp = minTemp end
end
local function modField(val)
reqField = reqField + val
if reqField > maxField then reqField = maxField end
if reqField < minField then reqField = minField end
end
local state = {
active = "active",
disabled = "disabled",
enabled = "enabled",
off = "off"
}
local buttonColors = {
active = function()
monitor.setBackgroundColor(colors.green)
monitor.setTextColor(colors.white)
end,
disabled = function()
monitor.setBackgroundColor(colors.gray)
monitor.setTextColor(colors.black)
end,
enabled = function()
monitor.setBackgroundColor(colors.lightGray)
monitor.setTextColor(colors.white)
end,
off = function()
monitor.setBackgroundColor(colors.black)
monitor.setTextColor(colors.lightGray)
end
}
local buttonType = {
label = {
id = 'label',
setColors = function()
monitor.setBackgroundColor(colors.black)
monitor.setTextColor(colors.white)
end
},
button = {
id = 'button',
setColors = function(inState)
buttonColors[inState]()
end
},
val1 = {
id = 'val1',
setColors = function()
monitor.setBackgroundColor(colors.gray)
monitor.setTextColor(colors.white)
end
},
val10 = {
id = 'val10',
setColors = function()
monitor.setBackgroundColor(colors.lightGray)
monitor.setTextColor(colors.white)
end
}
}
local function printStatic(inTable)
monitor.clear()
monitor.setBackgroundColor(inTable.bCol)
monitor.setTextColor(inTable.fCol)
for i, v in pairs(inTable.array) do
monitor.setCursorPos(1, i)
monitor.write(v)
end
monitor.setCursorPos(1,2) --display any std out on line 2
end
local function printUpdates(inTable)
for i, v in pairs(inTable) do
monitor.setCursorPos(v.x, v.y)
if v.blit then
monitor.blit(v.txt(), v.fCol(), v.bCol())
else
if v.bCol then monitor.setBackgroundColor(v.bCol()) end
if v.fCol then monitor.setTextColor(v.fCol()) end
monitor.write(v.txt())
end
end
monitor.setCursorPos(1,2) --display any std out on line 2
end
local function printButtons(inTable)
for n, b in pairs(inTable) do
if b.depressed then
monitor.setBackgroundColor(colors.green)
monitor.setTextColor(colors.red)
b.depressed = b.depressed - 1
if b.depressed == 0 then b.depressed = nil; end
else
buttonType[b.type].setColors(b.state)
end
monitor.setCursorPos(b.x,b.y)
monitor.write(b.txt)
end
monitor.setCursorPos(1,2) --display any std out on line 2
end
local infoStatus = {
['cold'] = function() return colors.lightBlue; end,
['running'] = function() return colors.green; end,
['stopping'] = function() return colors.yellow; end,
['warming_up'] = function() return colors.yellow; end,
['beyond_hope'] = function() return colors.red; end,
['cooling'] = function() return colors.orange; end
}
local function callReactor(request)
if request == 'getReactorInfo' then
timerId = os.startTimer(waitTime)
end
local int, _ = math.modf(timerId / maxId)
local _id = timerId - (maxId * int)
-- Transmit variables for use by a.n.other computer sniffing the wifi to monitor taffic and/or reactor(s)
local tRequest = {req = request, inRF = inFluxRF, outRF = outFluxRF, reqTemp = reqTemp, reqField = reqField}
if OC then tRequest = serialization.serialize(tRequest) end --stupid OpenComputers can't handle tables, have to serialize
modem.transmit(modemTx, _id, tRequest)
end
local function getInFlux()
-- Field(shield) Calculation
local reqFieldStrength = (info.maxFieldStrength / 100) * reqField
if info.temperature > 8000 then
info.tempDrainFactor = 1 + ((info.temperature - 8000)^2 * 0.0000025)
elseif info.temperature > 2000 then
info.tempDrainFactor = 1
elseif info.temperature > 1000 then
info.tempDrainFactor = (info.temperature - 1000) / 1000
else
info.tempDrainFactor = 0
end
--fieldDrainRate calculation needs to be calculated on startup, else we can use info.fieldDrainRate
if not info.fieldDrainRate or info.fieldDrainRate == 0 then
local baseMaxRFt = (3 * info.maxEnergySaturation) / 2000 -- converted for integer maths
local drainMax = math.max(0.01, (1 - info.satPct))
info.fieldDrainRate = math.ceil(math.min(info.tempDrainFactor * drainMax * (baseMaxRFt / 10.923556), maxInteger)) -- 2147483647 = math.maxinteger which doesnt work here :(
else
--info.fieldDrainRate = info.fieldDrainRate
end
--fieldCharge calculation based on the required field strength
local fieldNegPercent = 1 - (reqFieldStrength / info.maxFieldStrength)
local fieldInputRate = info.fieldDrainRate / fieldNegPercent
info.fieldCharge = reqFieldStrength - math.min(info.fieldDrainRate , reqFieldStrength)
-- injectEnergy (happens after update)
local tempFactor = 1
if info.temperature > 15000 then
tempFactor = 1 - math.min(1, (info.temperature - 15000) / 10000)
end
local rf = inFluxRF
if inFluxRF == 0 then rf = 1 end
info.fieldCharge = info.fieldCharge + math.min(rf * (1 - (info.fieldCharge / info.maxFieldStrength)) , info.maxFieldStrength - info.fieldCharge) * tempFactor
info.reqInDiff = reqFieldStrength - info.fieldCharge
local inFlux = rf + ((info.maxFieldStrength * info.reqInDiff) / (info.maxFieldStrength - info.fieldCharge))
--to speed things up, subtract the current field from the reqField and add the difference to the rf (divided by 10)
inFlux = inFlux + ((reqFieldStrength - info.fieldStrength) / 10)
if inFlux < 0 then inFlux = 0 end
return inFlux
end
local function getRiseAmt()
-- Calculate the current resist and expo(nential)
local t50 = info.temperature / 10000 * 50
local tResist = (t50^4) / (100 - t50)
local tfResist = ((1.3 * info.fuelPct * tResist) + (1300 * info.fuelPct) - (1.3 * tResist) - 300) / 10000
local negCSat = (1 - info.satPct) * 99
local tExpo = (((negCSat^3) / (100 - negCSat)) + 444.7) / 10000
local tRiseAmt = (tfResist + tExpo) * 100 --correct format for display on debug screen
return tRiseAmt
end
local function getOutFlux()
--fuel use rate
if info.fuelPct > 0 then
local fuelUseRate = info.tempDrainFactor * (1 - info.satPct) * 0.001
info.fuelPct = (info.fuelConversion + fuelUseRate) / info.maxFuelConversion
end
-- RF out calculation
info.outDiff = reqTemp - info.temperature
--calculate the required resist
local reqTResist = -(reqTemp^4 / (8000000 * (reqTemp - 20000)))
local reqResist = ((1.3 * info.fuelPct * reqTResist) + (1300 * info.fuelPct) - (1.3 * reqTResist) - 300) / 10000
-- The required Expo will be a reversed sign of reqResist
local reqExpo = ((reqResist * -1) * 10000) - 444.7
local _E = reqExpo
--reverse the expo to get the expected required saturation%
local revNegCSat =(((math.sqrt(3)*(math.sqrt((_E^3)+(67500*(_E^2)))))+(450*_E))^(1/3))/(3^(2/3))-(_E/((3^(1/3))*(((math.sqrt(3)*(math.sqrt((_E^3)+(67500*(_E^2)))))+(450*_E))^(1/3))))
--calculate the required genRate
info.reqGenRate = (revNegCSat / 99) * (((info.maxEnergySaturation / 1000) * 1.5) * (1 + (((info.fuelPct * 1.3) - 0.3) * 2)))
--subtract the current genRate from the required genRate to get the new outGenRate
info.outGenRate = info.reqGenRate - info.generationRate
if math.abs(info.outDiff) > 1 then
info.outSpeed = info.outDiff * (info.temperature / reqTemp ) * 10 * (info.maxFuelConversion / maxFuel)
info.outIncrease = info.outGenRate + info.outSpeed
info.outGenRateTrim = 0
elseif math.abs(info.outDiff) == 1 then
info.outSpeed = 0
info.outIncrease = info.outGenRate
info.outGenRateTrim = info.outGenRate * outTrimPct
else
info.outSpeed = 0
info.outIncrease = 0
info.outGenRateTrim = info.outGenRate * outTrimPct
end
local outFlux = info.reqGenRate + info.outIncrease + info.outSpeed + info.outGenRateTrim
if outFlux < 0 or info.generationRate == 0 or outFlux == (1 / 0) or outFlux ~= outFlux then outFlux = 1000 end
return outFlux
end
local function getGraph(inVal, inMax, inSize)
local strGraph = ''
local val = (((inVal / inMax) * inSize) - 1) --divide the width of screen by the colored chunks required
for i = 1, val do -- build the '='
strGraph = strGraph.."="
end
strGraph = strGraph..">" -- concat the '>'
for i = val, inSize do -- set the remaining width to spaces
strGraph = strGraph.." "
end
--In case we have a divide by zero, thus no data, pad the string out with spaces
strGraph = strGraph..string.rep(" ",inSize)
strGraph = string.sub(strGraph,1,inSize)
return strGraph
end
local function fmtNum( inVal, inWidth, inDec, boolC )
--because string.format is broken in ComputerCraft, need own format function
local rtn = inVal
if type(rtn) == 'number' then
--Round and get the modulus padded with zeros
local mod
if inDec > 0 then -- number of decimal places
inVal = (math.floor(inVal * (10^(inDec)) + 0.5) / 10^(inDec)) -- round to the specified decimal places
-- multiply by 10 to the power of decimals places
mod = math.floor((inVal % 1) * ( 10 ^ (inDec) ))
-- pad the decimal with zeros
mod = string.rep(
"0",(
( (inDec-string.len(mod)>=0) and 1 or 0)
* (inDec-string.len(mod))
)
)..mod
end
-- get the integral part
local int = math.floor(inVal)
-- add the commas
while boolC do
local k
int, k = string.gsub(int, "^(-?%d+)(%d%d%d)", '%1,%2')
if (k==0) then
break
end
end
if mod then
-- concatonate integral with modulus and decimal point
rtn = int.."."..mod
else
rtn = int
end
-- pad with leading spaces
local pad = inWidth - string.len(rtn)
if pad > 0 then rtn = string.rep(" ",(pad) )..rtn end
else
rtn = tostring(rtn)
rtn = string.rep(" ",inWidth - string.len(rtn))..rtn
end
rtn = string.sub(rtn,1,inWidth)
return rtn
end
local scrnStatic = {
main = {
bCol = colors.black,
fCol = colors.lightBlue,
x = 1,
y = 1,
array = {
' ',
' ',
'Temp: ',
' ',
'Fld: ',
' ',
'Satn: ',
' ',
'Fuel: ',
' ',
'FldDrainRate: GenRate: ',
'In(Field): Gain: Out: '
}
},
debug = {
bCol = colors.black,
fCol = colors.lightBlue,
x = 1,
y = 1,
array = {
'Status Debug Screen ',
' ',
'Fld: Temp: ',
'FldChrg: outDiff: ',
' riseAmt: ',
' reqInDiff: tRiseAmt: ',
' reqGenRate: ',
' outGenRate: ',
' outIncrease: ',
'fieldDrain: speed/trim: ',
'fldDrnRate: GenRate: ',
'In(Field): Gain: Out: '
}
}
}
local scrnDynamic = {
main = {
[1] = { --status = {
x = 8,
y = 1,
fCol = function() return infoStatus[info.status](); end,
bCol = function() return colors.black; end,
txt = function() return string.sub(info.status..' ',1,10) end
},
[2] = { --tempVal = {
x = 7,
y = 3,
fCol = function()
if math.floor(info.temperature) > reqTemp and info.temperature > 2500 then
return colors.red
else
return colors.white
end
end,
bCol = function() return colors.black; end,
txt = function() return fmtNum(math.floor(info.temperature),4,0,false).."C" end
},
[3] = { --reqTemp = {
x = 37,
y = 3,
fCol = function() return colors.blue; end,
bCol = function() return colors.black; end,
txt = function() return fmtNum(reqTemp,4,0,false).."C" end
},
[4] = { --tempVal2 = {
x = 1,
y = 4,
fCol = function()
if math.floor(info.temperature) > reqTemp and info.temperature > 2500 then
return colors.red
else
return colors.white
end
end,
bCol = function() return colors.black; end,
txt = function() return fmtNum(math.floor(info.temperature),5,0,false).."C" end
},
[5] = { --tempBar = {
x = 7,
y = 4,
blit = true,
fCol = function() return string.rep("f",graphLen); end,
bCol = function() return "eeeeeeeeeee111111111114444444444400000000000"; end,
txt = function() return getGraph(info.temperature, cutoffTemp, graphLen) end
},
[6] = { --field = {
x = 7,
y = 5,
fCol = function() return colors.white; end,
bCol = function() return colors.black; end,
txt = function() return fmtNum(math.floor(info.fieldStrength),9,0,false).."/"..fmtNum(info.maxFieldStrength,9,0,false) end
},
[7] = { --reqField = {
x = 37,
y = 5,
fCol = function() return colors.blue; end,
bCol = function() return colors.black; end,
txt = function() return fmtNum(reqField,3,0,false).."%" end
},
[8] = { --fieldPct = {
x = 1,
y = 6,
fCol = function()
if info.status == 'cold' or info.status == 'offline' or info.status == 'cooling' then
return colors.white;
else
local fieldPct = info.fieldPct * 100
if fieldPct < reqField - 0.5 then return colors.red;
elseif fieldPct < reqField - 0.2 then return colors.orange;
elseif fieldPct < reqField - 0.1 then return colors.yellow;
else return colors.white;
end
end
end,
bCol = function() return colors.black; end,
txt = function() return fmtNum(info.fieldPct*100,5,2,false).."%" end
},
[9] = { --fieldBar = {
x = 7,
y = 6,
blit = true,
fCol = function() return string.rep("f",graphLen); end,
bCol = function() return "eeeeeeeeeaaaaaaaaa222222222bbbbbbbbb99999999"; end,
txt = function() return getGraph(info.fieldStrength, info.maxFieldStrength, graphLen) end
},
[10] = { --sat = {
x = 7,
y = 7,
fCol = function() return colors.white; end,
bCol = function() return colors.black; end,
txt = function() return fmtNum(math.floor(info.energySaturation),9,0,false).."/"..fmtNum(info.maxEnergySaturation,10,0,false) end
},
[11] = { --satPct = {
x = 1,
y = 8,
fCol = function()
local satPct = info.satPct*100
if satPct > 99 then return colors.red;
elseif satPct > 95 then return colors.orange;
elseif satPct > 90 then return colors.yellow;
else return colors.white;
end
end,
bCol = function() return colors.black; end,
txt = function() return fmtNum(info.satPct*100,5,2,false).."%" end
},
[12] = { --satBar = {
x = 7,
y = 8,
blit = true,
fCol = function() return string.rep("f",graphLen); end,
bCol = function() return "eeeeeeeeeeeeeeeddddddddddddddd99999999999999"; end,
txt = function() return getGraph(info.energySaturation, info.maxEnergySaturation, graphLen) end
},
[13] = { --fuel = {
x = 7,
y = 9,
fCol = function() return colors.white; end,
bCol = function() return colors.black; end,
txt = function() return fmtNum(info.fuelConversion,9,3,false).."/"..fmtNum(info.maxFuelConversion,5,0,false) end
},
[14] = { --fuelPct = {
x = 1,
y = 10,
fCol = function()
local fuelPct = info.fuelPct*100
if fuelPct > 95 then return colors.red;
elseif fuelPct > 90 then return colors.orange;
elseif fuelPct > 85 then return colors.yellow;
else return colors.white;
end
end,
bCol = function() return colors.black; end,
txt = function() return fmtNum(info.fuelPct*100,5,2,false).."%" end
},
[15] = { --fuelBar = {
x = 7,
y = 10,
blit = true,
fCol = function() return string.rep("f",graphLen); end,
bCol = function() return "44444444444ddddddddddd22222222222eeeeeeeeeee"; end,
txt = function() return getGraph(info.fuelConversion, info.maxFuelConversion, graphLen) end
},
[16] = { --fieldDrainRate = {
x = 14,
y = 11,
fCol = function() return colors.white; end,
bCol = function() return colors.black; end,
txt = function() return fmtNum(info.fieldDrainRate,9,0,false) end
},
[17] = { --generationRate = {
x = 34,
y = 11,
fCol = function() return colors.white; end,
bCol = function() return colors.black; end,
txt = function() return fmtNum(info.generationRate,9,0,false) end
},
[18] = { --inFluxRF = {
x = 11,
y = 12,
fCol = function() return colors.white; end,
bCol = function() return colors.black; end,
txt = function() return fmtNum(inFluxRF,8,0,false) end
},
[19] = { --gain = {
x = 28,
y = 12,
fCol = function() return colors.white; end,
bCol = function() return colors.black; end,
txt = function() return fmtNum(outFluxRF-inFluxRF,8,0,false) end
},
[20] = { --outFluxRF = {
x = 43,
y = 12,
fCol = function() return colors.white; end,
bCol = function() return colors.black; end,
txt = function() return fmtNum(outFluxRF,8,0,false) end
}
},
debug = {
[1] = { --skip = {
x = 1,
y = 2,
txt = function() return 'Ticks lost: '..skip.." TimerId: "..timerId; end
},
[2] = { --status = {
x = 8,
y = 1,
txt = function() return string.sub(info.status..' ',1,10); end
},
[3] = { --fldPct = {
x = 5,
y = 3,
txt = function() return fmtNum(info.fieldPct*100,5,2,false); end
},
[4] = { --field = {
x = 12,
y = 3,
txt = function() return fmtNum(info.fieldStrength,9,0,false).."/"; end
},
[5] = { --maxField = {
x = 22,
y = 3,
txt = function() return fmtNum(info.maxFieldStrength,9,0,false); end
},
[6] = { --temperature = {
x = 43,
y = 3,
txt = function() return fmtNum(info.temperature,4,0,false).."C"; end
},
[7] = { --fieldCharge = {
x = 10,
y = 4,
txt = function() return fmtNum(info.fieldCharge,11,0,false); end
},
[8] = { --outDiff = {
x = 35,
y = 4,
txt = function() return fmtNum(info.outDiff,8,0,false); end
},
[9] = { --riseAmount = {
x = 35,
y = 5,
txt = function() if info.riseAmount then return info.riseAmount * 10; else return 'N/A'; end; end
},
[10] = { --tRiseAmount = {
x = 35,
y = 6,
txt = function() return getRiseAmt(); end
},
[11] = { --reqInDiff = {
x = 12,
y = 6,
txt = function() return fmtNum(info.reqInDiff,10,0,false); end
},
[12] = { --reqGenRate = {
x = 35,
y = 7,
txt = function() return fmtNum(info.reqGenRate,11,2,false); end
},
[13] = { --outGenRate = {
x = 35,
y = 8,
txt = function() return fmtNum(info.outGenRate,11,2,false); end
},
[14] = { --outIncrease = {
x = 35,
y = 9,
txt = function() return fmtNum(info.outIncrease,11,2,false) end
},
[15] = { --fieldDrain = {
x = 12,
y = 10,
txt = function() return fmtNum(info.fieldDrain,10,2,false); end
},
[16] = { --speedTrim = {
x = 35,
y = 10,
txt = function() return fmtNum(info.outSpeed,11,2,false).."/"..tostring(info.outGenRateTrim).." "; end
},
[17] = { --fieldDrainRate = {
x = 12,
y = 11,
txt = function() return fmtNum(info.fieldDrainRate,10,2,false); end
},
[18] = { --generationRate = {
x = 35,
y = 11,
txt = function() return fmtNum(info.generationRate,8,0,false); end
},
[19] = { --inFluxRF = {
x = 11,
y = 12,
txt = function() return fmtNum(inFluxRF,8,0,false); end
},
[20] = { --gain = {
x = 28,
y = 12,
txt = function() return fmtNum(outFluxRF-inFluxRF,8,0,false); end
},
[21] = { --outFluxRF = {
x = 43,
y = 12,
txt = function() return fmtNum(outFluxRF,8,0,false); end
}
}
}
local buttons = {
[1] = { --status = {
x = 1,
y = 1,
txt = 'Status',
type = buttonType.label.id,
state = state.enabled,
action = function() debugMode = not debugMode; if debugMode then printStatic(scrnStatic.debug); else printStatic(scrnStatic.main); end; end
},
[2] = { --charge = {
x = 18,
y = 1,
txt = '[Charge]',
type = buttonType.button.id,
state = state.off,
action = function(self) if self.state == state.enabled then callReactor('chargeReactor'); end; end
},
[3] = { --activate = {
x = 28,
y = 1,
txt = '[Activate]',
type = buttonType.button.id,
state = state.off,
action = function(self) if self.state == state.enabled then callReactor('activateReactor'); end; end
},
[4] = { --stop = {
x = 40,
y = 1,
txt = '[Shutdown]',
type = buttonType.button.id,
state = state.off,
action = function(self) if self.state == state.enabled then callReactor('stopReactor'); end; end
},
[5] = { --tempUp1 = {
x = 42,
y = 3,
txt = '[]',
type = buttonType.val1.id,
action=function() modTemp(1); end,
state = state.enabled
},
[6] = { --tempUp10 = {
x = 44,
y = 3,
txt = '[>]',
type = buttonType.val10.id,
action=function() modTemp(10); end,
state = state.enabled
},
[7] = { --tempUp100 = {
x = 47,
y = 3,
txt = '[>>]',
type = buttonType.val1.id,
action=function() modTemp(100); end,
state = state.enabled
},
[8] = { --tempDown1 = {
x = 35,
y = 3,
txt = '[]',
type = buttonType.val1.id,
action=function() modTemp(-1); end,
state = state.enabled
},
[9] = { --tempDown10 = {
x = 32,
y = 3,
txt = '[<]',
type = buttonType.val10.id,
action=function() modTemp(-10); end,
state = state.enabled
},
[10] = { --tempDown100 = {
x = 28,
y = 3,
txt = '[<<]',
type = buttonType.val1.id,
action=function() modTemp(-100); end,
state = state.enabled
},
[11] = { --fieldUp1 = {
x = 42,
y = 5,
txt = '[]',
type = buttonType.val1.id,
action=function() modField(1); end,
state = state.enabled
},
[12] = { --fieldUp10 = {
x = 44,
y = 5,
txt = '[>]',
type = buttonType.val10.id,
action=function() modField(10); end,
state = state.enabled
},
[13] = { --fieldDown1 = {
x = 35,
y = 5,
txt = '[]',
type = buttonType.val1.id,
action=function() modField(-1); end,
state = state.enabled
},
[14] = { --fieldDown10 = {
x = 32,
y = 5,
txt = '[<]',
type = buttonType.val10.id,
action=function() modField(-10); end,
state = state.enabled
}
}
local setStatus = {
["running"] = function()
buttons[2].state = state.disabled
buttons[3].state = state.active
buttons[4].state = state.enabled
end,
["cold"] = function()
buttons[2].state = state.enabled
buttons[3].state = state.disabled
buttons[4].state = state.disabled
end,
["stopping"] = function()
if info.temperature > 2000 then
buttons[2].state = state.disabled
buttons[3].state = state.enabled
else
buttons[2].state = state.enabled
buttons[3].state = state.disabled
end
buttons[4].state = state.active
end,
["warming_up"] = function()
if info.temperature > 2000 then
buttons[2].state = state.active
buttons[3].state = state.enabled
else
buttons[2].state = state.active