View difference between Paste ID: qBr66uGi and S6rzwVnD
SHOW: | | - or go back to the newest paste.
1
os.loadAPI("Button")
2
3
p = peripheral.find("draconic_rf_storage_0")
4
m = peripheral.find("monitor_0")
5
r = peripheral.find("BigReactors-Reactor_0")
6
t = peripheral.find("BigReactors-Turbine")
7
8
--local steamReactor = r.isActivelyCooled()
9
local steamReactor = false
10
local menuType = "Reactor"
11
12
local numCapacitors = 3
13
local turnOnAt = 50
14
local turnOffAt = 90
15
16
local targetSpeed = 1840
17
18
local energy = 0
19
local energyStored = 0
20
local energyMax = 0
21
local energyStoredPercent = 0
22
local timerCode
23
local mode = "Automatic"
24
local RFProduction = 0
25
local fuelUse = 0
26
local coreTemp = 0
27
local reactorOnline = false
28
local rodLevel = 0
29
30
local turbineOnline = false
31
local turbineRotorSpeed = 0
32
local turbineRFGen = 0
33
local turbineFluidRate = 0
34
local turbineInductor = false
35
36
local OptFuelRodLevel = 0
37
38
function autoMenu()
39
   m.setTextScale(1)
40
   button.clearTable()
41
   button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
42
   button.setTable("Manual", manualMode, "", 15, 25, 6, 6)
43
   
44
   if steamReactor then 
45
      button.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
46
      button.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
47
   end
48
   button.screen()
49
   checkMode()
50
   menuMode()
51
end
52
53
function manualMenu()
54
   m.setTextScale(1)
55
   button.clearTable()
56
   button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
57
   button.setTable("Manual", manualMode, "", 15, 25, 6, 6)
58
   button.setTable("Online", online, "", 3, 13, 8, 8)
59
   button.setTable("Offline", offline, "", 15, 25, 8, 8)
60
   button.setTable("0", setRods, 0, 11,14, 10, 10)
61
   button.setTable("10", setRods, 10, 5,8, 12, 12)
62
   button.setTable("20", setRods, 20, 11,14, 12, 12)
63
   button.setTable("30", setRods, 30, 17,20, 12, 12)
64
   button.setTable("40", setRods, 40, 5,8, 14, 14)
65
   button.setTable("50", setRods, 50, 11,14, 14, 14)
66
   button.setTable("60", setRods, 60, 17,20, 14, 14)
67
   button.setTable("70", setRods, 70, 5,8, 16, 16)
68
   button.setTable("80", setRods, 80, 11,14, 16, 16)
69
   button.setTable("90", setRods, 90, 17,20, 16, 16)
70
   button.setTable("+", rodPlus, "", 23, 25, 12, 12)
71
   button.setTable("-", rodMinus, "", 23, 25, 16, 16) 
72
73
   if steamReactor then 
74
      button.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
75
      button.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
76
	  
77
   end
78
   button.screen()
79
   checkMode()
80
   reactorOnOff()
81
   menuMode()
82
end
83
84
function turbineAutoMenu()
85
   m.setTextScale(1)
86
   button.clearTable()
87
   button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
88
   button.setTable("Manual", manualMode, "", 15, 25, 6, 6)
89
   button.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
90
   button.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
91
   button.screen()
92
   checkMode()
93
   menuMode()
94
end
95
96
function turbineManualMenu()
97
   m.setTextScale(1)
98
   button.clearTable()
99
   button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
100
   button.setTable("Manual", manualMode, "", 15, 25, 6, 6)
101
   button.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
102
   button.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
103
   button.setTable("Online", setTurbineOnline, "", 3, 13, 8, 8)
104
   button.setTable("Offline", setTurbineOffline, "", 15, 25, 8, 8)
105
   button.setTable("Coils On", coilsOn, "", 3, 13, 10, 10)
106
   button.setTable("Coils Off", coilsOff, "", 15, 25, 10, 10)
107
   button.screen()
108
   checkMode()
109
   turbineOnOff()
110
   coilsOnOff()
111
   menuMode()
112
end
113
114
function reactorMenu()
115
   menuType = "Reactor"
116
   displayScreen()
117
end
118
119
function turbineMenu()
120
   menuType = "Turbine"
121
   displayScreen()
122
end
123
124
function online()
125
   r.setActive(true)
126
   --button.flash("Online")
127
end
128
129
function offline()
130
   r.setActive(false)
131
   --button.flash("Offline")
132
end
133
134
function setTurbineOnline()
135
   t.setActive(true)
136
   --button.flash("Online")
137
end
138
139
function setTurbineOffline()
140
   t.setActive(false)
141
   --button.flash("Offline")
142
end
143
144
function reactorOnOff()
145
   button.setButton("Online", r.getActive())
146
   button.setButton("Offline", not r.getActive())
147
end
148
149
function turbineOnOff()
150
   button.setButton("Online", t.getActive())
151
   button.setButton("Offline", not t.getActive())
152
end
153
154
function coilsOnOff()
155
   button.setButton("Coils On", t.getInductorEngaged())
156
   button.setButton("Coils Off", not t.getInductorEngaged())
157
end
158
159
function coilsOn()
160
   t.setInductorEngaged(true)
161
end
162
163
function coilsOff()
164
   t.setInductorEngaged(false)
165
end
166
167
function menuMode()
168
   if steamReactor then 
169
   if menuType == "Reactor" then
170
     button.setButton("Reactor", true)
171
     button.setButton("Turbine", false)
172
   else
173
     button.setButton("Reactor", false)
174
     button.setButton("Turbine", true)
175
   end
176
   end
177
end
178
179
function setRods(setLevel)
180
   print("Setting Rod Level: "..setLevel)
181
   button.flash(tostring(setLevel))
182
   r.setAllControlRodLevels(setLevel)
183
   fuelRodLevel()
184
end
185
186
function rodPlus()
187
   button.flash("+")
188
   r.setAllControlRodLevels(rodLevel+1)
189
   fuelRodLevel()
190
end
191
192
function rodMinus()
193
   button.flash("-")
194
   r.setAllControlRodLevels(rodLevel-1)
195
   fuelRodLevel()
196
end
197
198
function checkMode()
199
   button.toggleButton(mode)
200
end
201
   
202
function manualMode()
203
   mode = "Manual"
204
   manualMenu()
205
end
206
207
function autoMode()
208
   mode = "Automatic"
209
   displayScreen()
210
end
211
212
function comma_value(amount)
213
   local formatted = amount
214
   local swap = false
215
   if formatted < 0 then 
216
      formatted = formatted*-1
217
      swap = true
218
   end
219
   while true do
220
      formatted, k = string.gsub(formatted, "^(%d+)(%d%d%d)", '%1,%2')
221
      if k == 0 then
222
         break
223
      end
224
   end
225
   if swap then 
226
     formatted = "-"..formatted
227
   end
228
   return formatted
229
end
230
231
function displayEn()
232
   m.clear()
233
   m.setCursorPos(1,1)
234
   --print("Energy Use: "..energy)
235
   m.write("Energy Use: ")
236
   if energy < 0 then
237
      m.setTextColor(colors.red)
238
   else
239
      m.setTextColor(colors.green)
240
   end
241
   m.write(comma_value(math.floor(energy)).. "RF/t")
242
   m.setTextColor(colors.white)
243
   m.setCursorPos(1,2)
244
   m.write("Energy Stored: "..energyStoredPercent.."%")
245
   if menuType == "Reactor" then
246
      m.setCursorPos(1,3)
247
      m.write("Reactor is: ")
248
      if reactorOnline then 
249
	   m.setTextColor(colors.green) 
250
	   m.write("Online")
251
      else 
252
       m.setTextColor(colors.red) 
253
	   m.write("Offline")
254
      end
255
      m.setTextColor(colors.white)
256
      m.setCursorPos(22,1)
257
      if steamReactor then
258
         m.write("Steam: ")
259
	     m.setTextColor(colors.green)
260
         m.write(comma_value(math.floor(RFProduction)).."MB/t")
261
      else
262
         m.write("RF Gen: ")
263
	     m.setTextColor(colors.green)
264
         m.write(comma_value(math.floor(RFProduction)).."RF/t")
265
      end
266
      m.setTextColor(colors.white)
267
      m.setCursorPos(22,2)
268
      m.write("Core Temp: "..math.floor(coreTemp).."c")
269
      m.setCursorPos(22,3)
270
      m.write("Fuel Use: "..fuelUse.."MB/t")  
271
  else
272
      m.setCursorPos(1,3)
273
      m.write("Turbine is: ")
274
      if turbineOnline then 
275
	   m.setTextColor(colors.green) 
276
	   m.write("Online")
277
      else 
278
       m.setTextColor(colors.red) 
279
	   m.write("Offline")
280
      end
281
      m.setCursorPos(1,4)
282
      m.setTextColor(colors.white)
283
      m.write("Reactor is: ")
284
      if reactorOnline then
285
         m.setTextColor(colors.green)
286
         m.write("Online")
287
      else
288
         m.setTextColor(colors.red)
289
         m.write("Offline")
290
      end
291
      m.setTextColor(colors.white)
292
	  m.setCursorPos(22,1)
293
	  m.write("RFGen: ")
294
	  m.setTextColor(colors.green)
295
      m.write(comma_value(math.floor(turbineRFGen)).."RF/t") 
296
	  m.setTextColor(colors.white)
297
	  m.setCursorPos(22,2)
298
      m.write("Rotor: "..comma_value(math.floor(turbineRotorSpeed)).." RPM")
299
	  m.setCursorPos(22,3)
300
      m.write("Steam: "..comma_value(turbineFluidRate).."MB/t")  
301
  end
302
  
303
end
304
305
function checkEn()
306
   local tempEnergy = 0
307
   energyStored = p.getEnergyStored()
308
   energyMax = p.getMaxEnergyStored()
309
   energyStoredPercent = math.floor((energyStored/energyMax)*100)
310
   RFProduction = r.getEnergyProducedLastTick()
311
   fuelUse = r.getFuelConsumedLastTick()
312
   fuelUse = math.floor(fuelUse*100)
313
   fuelUse = fuelUse/100
314
   coreTemp = r.getFuelTemperature()
315
   reactorOnline = r.getActive()
316
   tempEnergy = p.getEnergyStored()
317
   sleep(0.1)
318
   energy = (p.getEnergyStored()-tempEnergy)/3
319
   energy = energy*numCapacitors
320
   if steamReactor then
321
     turbineOnline = t.getActive()
322
     turbineRotorSpeed = t.getRotorSpeed()
323
     turbineRFGen = t.getEnergyProducedLastTick()
324
     turbineFluidRate = t.getFluidFlowRate()
325
   end
326
end
327
328
function fuelRodLevel()
329
   rodLevel = r.getControlRodLevel(0)
330
   --print(rodLevel)
331
   m.setCursorPos(30,5)
332
   m.write(tostring(rodLevel).."%")
333
   m.setBackgroundColor(colors.white)
334
   m.setCursorPos(28,6)
335
   m.write("       ")
336
   for i = 1,10 do
337
      m.setCursorPos(28,i+6)
338
	  m.setBackgroundColor(colors.white)
339
	  m.write(" ")
340
	  m.setBackgroundColor(colors.yellow)
341
	  m.write(" ")
342
	  if rodLevel/10 >= i then
343
	     m.setBackgroundColor(colors.red)
344
	  else
345
	     m.setBackgroundColor(colors.yellow)
346
	  end
347
	  m.write("   ")
348
	  m.setBackgroundColor(colors.yellow)
349
	  m.write(" ")
350
	  m.setBackgroundColor(colors.white)
351
	  m.write(" ")
352
   end
353
   m.setCursorPos(28,17)
354
   m.write("       ")
355
   m.setBackgroundColor(colors.black)
356
end
357
358
function turbineInductorDisplay()
359
   turbineInductor = t.getInductorEngaged()
360
   m.setCursorPos(30,5)
361
   if turbineInductor then
362
      m.write("On")
363
   else
364
      m.write("Off")
365
   end
366
   m.setBackgroundColor(colors.gray)
367
   m.setCursorPos(28,6)
368
   m.write("       ")
369
   for i = 1,7 do
370
      m.setCursorPos(28,i+6)
371
	  m.setBackgroundColor(colors.gray)
372
	  m.write(" ")
373
	  m.setBackgroundColor(colors.lightGray)
374
	  m.write(" ")
375
	  if i % 2 == 0 then
376
	     m.setBackgroundColor(colors.gray)
377
	  end
378
	  m.write(" ")
379
	  m.setBackgroundColor(colors.gray)
380
	  m.write(" ")
381
	  if i % 2 ~= 0 then
382
	     m.setBackgroundColor(colors.lightGray)
383
	  end
384
	  m.write(" ")
385
	  m.setBackgroundColor(colors.lightGray)
386
	  m.write(" ")
387
	  m.setBackgroundColor(colors.gray)
388
	  m.write(" ")
389
   end
390
   for i = 8,10 do
391
   m.setCursorPos(28,i+6)
392
	  m.setBackgroundColor(colors.gray)
393
	  m.write(" ")
394
	  m.setBackgroundColor(colors.lightGray)
395
	  m.write(" ")
396
	  if turbineInductor then
397
	     m.setBackgroundColor(colors.red)
398
      else
399
	     m.setBackgroundColor(colors.blue)
400
	  end
401
	  m.write(" ")
402
	  m.setBackgroundColor(colors.gray)
403
	  m.write(" ")
404
	  if turbineInductor then
405
	     m.setBackgroundColor(colors.red)
406
      else
407
	     m.setBackgroundColor(colors.blue)
408
	  end
409
	  m.write(" ")
410
	  m.setBackgroundColor(colors.lightGray)
411
	  m.write(" ")
412
	  m.setBackgroundColor(colors.gray)
413
	  m.write(" ")
414
   end
415
   m.setCursorPos(28,17)
416
   m.write("       ")
417
   m.setBackgroundColor(colors.black)
418
end
419
function getClick()
420
   local event, side, x, y = os.pullEvent("monitor_touch")
421
   button.checkxy(x,y)
422
end
423
424
function findOptFuelRods()
425
   m.clear()
426
   r.setActive(false)
427
   checkEn()
428
   displayEn()
429
   fuelRodLevel()
430
   while r.getFuelTemperature() > 99 do
431
      for i= 1,3 do
432
	    checkEn()
433
        displayEn()
434
        fuelRodLevel()
435
		m.setCursorPos(3,6)
436
        m.write("Finding Optimal Rod Level")
437
	    m.setCursorPos(3,7)
438
	    m.write("Core Temp: "..r.getFuelTemperature())
439
		m.setCursorPos(3,8)
440
		m.write("Waiting for 99c")
441
	    sleep(1)
442
	  end
443
   end
444
   while r.getHotFluidAmount() > 10000 do
445
     for i = 1,3 do
446
	    checkEn()
447
        displayEn()
448
        fuelRodLevel()
449
		m.setCursorPos(3,6)
450
        m.write("Finding Optimal Rod Level, please wait....")
451
   	    m.setCursorPos(3,7)
452
   	    m.write("Fluid Amount: "..comma_value(r.getHotFluidAmount()).."mb")
453
		m.setCursorPos(3,8)
454
		m.write("Waiting for 10,000mb")
455
	    sleep(1)
456
	  end
457
   end
458
   r.setAllControlRodLevels(99)
459
   r.setActive(true)
460
   
461
   while r.getFuelTemperature() < 100 do
462
   for i = 1,5 do
463
     checkEn()
464
     displayEn()
465
     fuelRodLevel()
466
	 m.setCursorPos(3,6)
467
	 m.write("Set all rod levels to 99")
468
	 m.setCursorPos(3,7)
469
	 m.write("Waiting 5 seconds...")
470
     sleep(1)
471
   end
472
   end
473
   for i = 1,5 do
474
     checkEn()
475
     displayEn()
476
     fuelRodLevel()
477
	 m.setCursorPos(3,6)
478
	 m.write("Set all rod levels to 99")
479
	 m.setCursorPos(3,7)
480
	 m.write("Waiting 5 seconds...")
481
     sleep(1)
482
   end
483
   local tempMB = r.getEnergyProducedLastTick()
484
   print(tempMB.."MB/t of steam")
485
   local tempRodLevels = math.floor(2000/tempMB)
486
   print("2000/"..tempMB.." = "..tempRodLevels)
487
   tempRodLevels = 100-tempRodLevels+5
488
   print("Adding 5 to Rod Levels: "..math.floor(tempRodLevels))
489
   r.setAllControlRodLevels(math.floor(tempRodLevels))
490
   print("Waiting 10 seconds to confirm...")
491
   for i = 1,10 do
492
     checkEn()
493
     displayEn()
494
     fuelRodLevel()
495
	 m.setCursorPos(3,6)
496
	 m.write("Estimated Level: "..tempRodLevels)
497
	 m.setCursorPos(3,7)
498
	 m.write("Waiting 10 seconds...")
499
     sleep(1)
500
   end
501
   tempMB = r.getEnergyProducedLastTick()
502
   while tempMB > 2000 do
503
	  tempRodLevels = tempRodLevels+1
504
	  r.setAllControlRodLevels(math.floor(tempRodLevels))
505
	  print("Setting Rod Levels to: "..tempRodLevels)
506
	  for i = 1,5 do
507
	   checkEn()
508
       displayEn()
509
       fuelRodLevel()
510
	   m.setCursorPos(3,6)
511
       m.write("Getting below 2000mb/t")
512
	   m.setCursorPos(3,7)
513
	   m.write("Currently at: "..tempMB)
514
       sleep(1)
515
	  end
516
	  tempMB = r.getEnergyProducedLastTick()
517
   end
518
   while tempMB < 2000 do
519
      tempRodLevels = tempRodLevels -1
520
	  r.setAllControlRodLevels(math.floor(tempRodLevels))
521
	  print("Setting Rod Levels to: "..tempRodLevels)
522
	  for i = 1,5 do
523
	   checkEn()
524
       displayEn()
525
       fuelRodLevel()
526
	   m.setCursorPos(3,6)
527
	   m.write("Getting Above 2000mb/t")
528
	   m.setCursorPos(3,7)
529
	   m.write("Currently at: "..tempMB)
530
       sleep(1)
531
	  end
532
	  tempMB = r.getEnergyProducedLastTick()
533
   end
534
   OptFuelRodLevel = tempRodLevels
535
end
536
   
537
538
function autoReactor()
539
   if not steamReactor then
540
      r.setAllControlRodLevels(0)
541
      if energyStoredPercent < turnOnAt then
542
       if not reactorOnline then
543
	     online()
544
  	   end
545
      end
546
      if energyStoredPercent > turnOffAt then
547
       if reactorOnline then
548
	     offline()
549
	   end
550
	  end
551
	else
552
	   r.setAllControlRodLevels(OptFuelRodLevel)
553
	   if energyStoredPercent < turnOnAt then
554
         --online()
555
      		 setTurbineOnline()
556
      		 coilsOn()
557
	   end
558
	   if energyStoredPercent > turnOffAt then
559
	     --if turbineRotorSpeed > 1800 then
560
	     --   offline()
561
	     --else
562
		    --   online()
563
	     --end
564
   		 setTurbineOnline()
565
   		 coilsOff()
566
	   end
567
    if turbineRotorSpeed > targetSpeed then
568
       offline()
569
    else
570
       online()
571
    end
572
	end
573
end
574
575
function displayScreen()
576
 --  repeat
577
	  checkEn()
578
	  displayEn()
579
	  if menuType == "Reactor" then
580
	    fuelRodLevel()
581
	    if mode == "Automatic" then
582
	       autoMenu()
583
		   autoReactor()
584
	    else
585
	       manualMenu()
586
		end
587
		
588
	  else
589
	    turbineInductorDisplay()
590
		if mode == "Automatic" then
591
	       turbineAutoMenu()
592
		   autoReactor()
593
	    else
594
	       turbineManualMenu()
595
		end
596
	    
597
	  end
598
      
599
	  timerCode = os.startTimer(1)
600
	  local event, side, x, y
601
	  repeat 
602
		event, side, x, y = os.pullEvent()
603
		print(event)
604
		if event == "timer" then
605
		   print(timerCode..":"..side)
606
		   if timerCode ~= side then
607
		      print("Wrong Code")
608
			else
609
			  print("Right Code")
610
			end
611
		end
612
	   until event~= "timer" or timerCode == side
613
	   if event == "monitor_touch" then
614
	        print(x..":"..y)
615
			button.checkxy(x,y)
616
		end
617
 --  until event ~= "timer"
618
end
619
620
if steamReactor then
621
   findOptFuelRods()
622
end
623
624
while true do
625
   displayScreen()
626
end