View difference between Paste ID: 5PhmpU70 and RCPEHmxs
SHOW: | | - or go back to the newest paste.
1
--  BigReactor Control
2-
--  by jaranvil aka jared314
2+
--  by costantino03
3
--
4
--  feel free to use and/or modify this code
5
--
6
-----------------------------------------------
7
--Reactor Control - Version History
8
--
9-
--  Version 2.3 - April 23/15
9+
--  Version 3.1 - November 2
10
--    - First update in awhile 
11
--    - lots of minor fixes and improvments 
12
--    - New loading and setup search with automated peripheral search 
13
--    - Changes to the update methods
14
--    - Except new updates soon
15
16
17
-----------------------------------------------
18
19-
local version = 2.3
19+
local version = 3.1
20
--is auto power enabled 
21-
local auto_string = false 
21+
local auto_string = true 
22
--auto on value
23-
local on = 0 
23+
local on = 49 
24
--auto off value
25
local off = 99 
26
--is auto control rods enabled 
27
local auto_rods = false 
28
--control rod auto value
29
local auto_rf = 0 
30
31
--peripherals
32
local reactor
33
local mon
34
35
--monitor size
36
local monX
37
local monY
38
39
term.clear()
40
-------------------FORMATTING-------------------------------
41
function clear()
42
  mon.setBackgroundColor(colors.black)
43
  mon.clear()
44
  mon.setCursorPos(1,1)
45
end
46
47
--display text on computer's terminal screen
48
function draw_text_term(x, y, text, text_color, bg_color)
49
  term.setTextColor(text_color)
50
  term.setBackgroundColor(bg_color)
51
  term.setCursorPos(x,y)
52
  write(text)
53
end
54
55
--display text text on monitor, "mon" peripheral
56
function draw_text(x, y, text, text_color, bg_color)
57
  mon.setBackgroundColor(bg_color)
58
  mon.setTextColor(text_color)
59
  mon.setCursorPos(x,y)
60
  mon.write(text)
61
end
62
63
--draw line on computer terminal
64
function draw_line(x, y, length, color)
65
    mon.setBackgroundColor(color)
66
    mon.setCursorPos(x,y)
67
    mon.write(string.rep(" ", length))
68
end
69
70
--draw line on computer terminal
71
function draw_line_term(x, y, length, color)
72
    term.setBackgroundColor(color)
73
    term.setCursorPos(x,y)
74
    term.write(string.rep(" ", length))
75
end
76
77
--create progress bar
78
--draws two overlapping lines
79
--background line of bg_color 
80
--main line of bar_color as a percentage of minVal/maxVal
81
function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
82
  draw_line(x, y, length, bg_color) --backgoround bar
83
  local barSize = math.floor((minVal/maxVal) * length) 
84
  draw_line(x, y, barSize, bar_color) --progress so far
85
end
86
87
--same as above but on the computer terminal
88
function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
89
  draw_line_term(x, y, length, bg_color) --backgoround bar
90
  local barSize = math.floor((minVal/maxVal) * length) 
91
  draw_line_term(x, y, barSize, bar_color)  --progress so far
92
end
93
94
--create button on monitor
95
function button(x, y, length, text, txt_color, bg_color)
96
  draw_line(x, y, length, bg_color)
97
  draw_text((x+2), y, text, txt_color, bg_color)
98
end
99
100
--header and footer bars on monitor
101
function menu_bar()
102
  draw_line(1, 1, monX, colors.blue)
103
  draw_text(2, 1, "Power    Tools    Settings", colors.white, colors.blue)
104
  draw_line(1, 19, monX, colors.blue)
105
  draw_text(2, 19, "     Reactor Control", colors.white, colors.blue)
106
end
107
108
--dropdown menu for power options
109
function power_menu()
110
  draw_line(1, 2, 9, colors.gray)
111
  draw_line(1, 3, 9, colors.gray)
112
  draw_line(1, 4, 9, colors.gray)
113
  if active then 
114
    draw_text(2, 2, "ON", colors.lightGray, colors.gray)
115
    draw_text(2, 3, "OFF", colors.white, colors.gray)
116
  else
117
    draw_text(2, 2, "ON", colors.white, colors.gray)
118
    draw_text(2, 3, "OFF", colors.lightGray, colors.gray)
119
  end
120
  draw_text(2, 4, "Auto", colors.white, colors.gray)
121
end
122
123
--dropbox menu for tools
124
function tools_menu()
125
  draw_line(10, 2, 14, colors.gray)
126
  draw_line(10, 3, 14, colors.gray)
127
  draw_line(10, 4, 14, colors.gray)
128
  draw_line(10, 5, 14, colors.gray)
129
  draw_text(11, 2, "Control Rods", colors.white, colors.gray)
130
  draw_text(11, 3, "Efficiency", colors.white, colors.gray) 
131
  draw_text(11, 4, "Fuel", colors.white, colors.gray)
132
  draw_text(11, 5, "Waste", colors.white, colors.gray)
133
end
134
135
--dropdown menu for settings
136
function settings_menu()
137
  draw_line(12, 2, 18, colors.gray)
138
  draw_line(12, 3, 18, colors.gray)
139
  draw_text(13, 2, "Check for Updates", colors.white, colors.gray)
140
  draw_text(13, 3, "Reset peripherals", colors.white, colors.gray)
141
end
142
143
--basic popup screen with title bar and exit button 
144
function popup_screen(y, title, height)
145
  clear()
146
  menu_bar()
147
148
  draw_line(4, y, 22, colors.blue)
149
  draw_line(25, y, 1, colors.red)
150
151
  for counter = y+1, height+y do
152
    draw_line(4, counter, 22, colors.white)
153
  end
154
155
  draw_text(25, y, "X", colors.white, colors.red)
156
  draw_text(5, y, title, colors.white, colors.blue)
157
end
158
159
--write settings to config file
160
function save_config()
161
  sw = fs.open("config.txt", "w")   
162
    sw.writeLine(version)
163
    sw.writeLine(auto_string)
164
    sw.writeLine(on)
165
    sw.writeLine(off)
166
    sw.writeLine(auto_rods)
167
    sw.writeLine(auto_rf)
168
  sw.close()
169
end
170
171
--read settings from file
172
function load_config()
173
  sr = fs.open("config.txt", "r")
174
    version = tonumber(sr.readLine())
175
    auto_string = sr.readLine()
176
    on = tonumber(sr.readLine())
177
    off = tonumber(sr.readLine())
178
    auto_rods = sr.readLine()
179
    auto_rf = tonumber(sr.readLine())
180
  sr.close()
181
end
182
183
------------------------END FORMATTING--------------------------
184
185
--
186
function homepage()
187
  while true do
188
    clear()
189
    menu_bar()
190
    terminal_screen()
191
192
    energy_stored = reactor.getEnergyStored()
193
    
194
    --------POWER STAT--------------
195
    draw_text(2, 3, "Power:", colors.yellow, colors.black)
196
    active = reactor.getActive()
197
    if active then
198
      draw_text(10, 3, "ONLINE", colors.lime, colors.black)
199
    else
200
      draw_text(10, 3, "OFFLINE", colors.red, colors.black)
201
    end
202
203
    -----------FUEL---------------------
204
    draw_text(2, 5, "Fuel Level:", colors.yellow, colors.black)
205
    local maxVal = reactor.getFuelAmountMax()
206
    local minVal = reactor.getFuelAmount() 
207
    local percent = math.floor((minVal/maxVal)*100)
208
    draw_text(15, 5, percent.."%", colors.white, colors.black)
209
210
    if percent < 25 then
211
    progress_bar(2, 6, monX-2, minVal, maxVal, colors.red, colors.gray)
212
    else if percent < 50 then
213
    progress_bar(2, 6, monX-2, minVal, maxVal, colors.orange, colors.gray)
214
    else if percent < 75 then 
215
    progress_bar(2, 6, monX-2, minVal, maxVal, colors.yellow, colors.gray)
216
    else if percent <= 100 then
217
    progress_bar(2, 6, monX-2, minVal, maxVal, colors.lime, colors.gray)
218
    end
219
    end
220
    end
221
    end
222
223
    -----------ROD HEAT---------------
224
    draw_text(2, 8, "Fuel Temp:", colors.yellow, colors.black)
225
    local maxVal = 2000
226
    local minVal = math.floor(reactor.getFuelTemperature())
227
228
    if minVal < 500 then
229
    progress_bar(2, 9, monX-2, minVal, maxVal, colors.lime, colors.gray)
230
    else if minVal < 1000 then
231
    progress_bar(2, 9, monX-2, minVal, maxVal, colors.yellow, colors.gray)
232
    else if minVal < 1500 then  
233
    progress_bar(2, 9, monX-2, minVal, maxVal, colors.orange, colors.gray)
234
    else if minVal < 2000 then
235
    progress_bar(2, 9, monX-2, minVal, maxVal, colors.red, colors.gray)
236
    else if minVal >= 2000 then
237
      progress_bar(2, 9, monX-2, 2000, maxVal, colors.red, colors.gray)
238
    end
239
    end
240
    end
241
    end
242
    end
243
244
    draw_text(15, 8, math.floor(minVal).."/"..maxVal, colors.white, colors.black)
245
246
    -----------CASING HEAT---------------
247
    draw_text(2, 11, "Casing Temp:", colors.yellow, colors.black)
248
    local maxVal = 2000
249
    local minVal = math.floor(reactor.getCasingTemperature())
250
    if minVal < 500 then
251
    progress_bar(2, 12, monX-2, minVal, maxVal, colors.lime, colors.gray)
252
    else if minVal < 1000 then
253
    progress_bar(2, 12, monX-2, minVal, maxVal, colors.yellow, colors.gray)
254
    else if minVal < 1500 then  
255
    progress_bar(2, 12, monX-2, minVal, maxVal, colors.orange, colors.gray)
256
    else if minVal < 2000 then
257
    progress_bar(2, 12, monX-2, minVal, maxVal, colors.red, colors.gray)
258
    else if minVal >= 2000 then
259
      progress_bar(2, 12, monX-2, 2000, maxVal, colors.red, colors.gray)
260
    end
261
    end
262
    end
263
    end
264
    end
265
    draw_text(15, 11, math.floor(minVal).."/"..maxVal, colors.white, colors.black)
266
267
    -------------OUTPUT-------------------
268
    if reactor.isActivelyCooled() then
269
270
      draw_text(2, 14, "mB/tick:", colors.yellow, colors.black)
271
      mbt = math.floor(reactor.getHotFluidProducedLastTick())
272
      draw_text(13, 14, mbt.." mB/t", colors.white, colors.black)
273
274
    else
275
276
      draw_text(2, 14, "RF/tick:", colors.yellow, colors.black)
277
      rft = math.floor(reactor.getEnergyProducedLastTick())
278
      draw_text(13, 14, rft.." RF/T", colors.white, colors.black)
279
280
    end
281
282
    ------------STORAGE------------
283
    if reactor.isActivelyCooled() then 
284
285
      draw_text(2, 15, "mB Stored:", colors.yellow, colors.black)
286
      fluid_stored = reactor.getHotFluidAmount()
287
      fluid_max = reactor.getHotFluidAmountMax()
288
      fluid_stored_percent = math.floor((fluid_stored/fluid_max)*100)
289
      draw_text(13, 15, fluid_stored_percent.."% ("..fluid_stored.." mB)", colors.white, colors.black)
290
291
    else
292
293
      draw_text(2, 15, "RF Stored:", colors.yellow, colors.black)
294
      energy_stored_percent = math.floor((energy_stored/10000000)*100)
295
      draw_text(13, 15, energy_stored_percent.."% ("..energy_stored.." RF)", colors.white, colors.black)
296
297
298
    end
299
300
    -------------AUTO CONTROL RODS-----------------------
301
    auto_rods_bool = auto_rods == "true"
302
    insertion_percent = reactor.getControlRodLevel(0)
303
304
    if reactor.isActivelyCooled() then
305
      draw_text(2, 16, "Control Rods:", colors.yellow, colors.black)
306
      draw_text(16, 16, insertion_percent.."%", colors.white, colors.black)
307
    else
308
309
      if auto_rods_bool then
310
        if active then
311
          if rft > auto_rf+50 then
312
            reactor.setAllControlRodLevels(insertion_percent+1)
313
          else if rft < auto_rf-50 then
314
            reactor.setAllControlRodLevels(insertion_percent-1)
315
          end
316
          end
317
        end
318
319
        draw_text(2, 16, "Control Rods:", colors.yellow, colors.black)
320
        draw_text(16, 16, insertion_percent.."%", colors.white, colors.black)
321
        draw_text(21, 16, "(Auto)", colors.red, colors.black)
322
      
323
      else
324
        draw_text(2, 16, "Control Rods:", colors.yellow, colors.black)
325
        draw_text(16, 16, insertion_percent.."%", colors.white, colors.black)
326
      end
327
    end
328
329
330
    -------------AUTO SHUTOFF--------------------------
331
    if reactor.isActivelyCooled() then
332
333
      --i dont know what I should do here
334
335
336
    else
337
      auto = auto_string == "true"
338
      if auto then
339
        if active then
340
          draw_text(2, 17, "Auto off:", colors.yellow, colors.black)
341
          draw_text(13, 17, off.."% RF Stored", colors.white, colors.black)
342
          if energy_stored_percent >= off then
343
            reactor.setActive(false)
344
            call_homepage()
345
          end
346
        else
347
          draw_text(2, 17, "Auto on:", colors.yellow, colors.black)
348
          draw_text(13, 17, on.."% RF Stored", colors.white, colors.black)
349
          if energy_stored_percent <= on then
350
            reactor.setActive(true)
351
            call_homepage()
352
          end
353
        end
354
      else
355
        draw_text(2, 17, "Auto power:", colors.yellow, colors.black)
356
        draw_text(14, 17, "disabled", colors.red, colors.black)
357
      end
358
    end
359
360
    sleep(0.5)
361
  end
362
end
363
364
--------------MENU SCREENS--------------
365
366
--auto power menu
367
function auto_off()
368
369
  auto = auto_string == "true"
370
  if auto then --auto power enabled
371
372
    popup_screen(3, "Auto Power", 11)
373
    draw_text(5, 5, "Enabled", colors.lime, colors.white)
374
    draw_text(15, 5, " disable ", colors.white, colors.black)
375
    
376
    draw_text(5, 7, "ON when storage =", colors.gray, colors.white)
377
    draw_text(5, 8, " - ", colors.white, colors.black)
378
    draw_text(13, 8, on.."% RF", colors.black, colors.white)
379
    draw_text(22, 8, " + ", colors.white, colors.black)
380
381
    draw_text(5, 10, "OFF when storage =", colors.gray, colors.white)
382
    draw_text(5, 11, " - ", colors.white, colors.black)
383
    draw_text(13, 11, off.."% RF", colors.black, colors.white)
384
    draw_text(22, 11, " + ", colors.white, colors.black)
385
386
    draw_text(11, 13, " Save ", colors.white, colors.black)
387
388
    local event, side, xPos, yPos = os.pullEvent("monitor_touch")
389
390
    --disable auto
391
    if yPos == 5 then
392
      if xPos >= 15 and xPos <= 21 then
393
        auto_string = "false"
394
        save_config()
395
        auto_off()
396
      else
397
        auto_off()
398
      end
399
    end
400
401
    --increase/decrease auto on %
402
    if yPos == 8 then
403
      if xPos >= 5 and xPos <= 8 then
404
        previous_on = on
405
        on = on-1
406
      end
407
      if xPos >= 22 and xPos <= 25 then
408
        previous_on = on
409
        on = on+1
410
      end
411
    end
412
413
    --increase/decrease auto off %
414
    if yPos == 11 then
415
      if xPos >= 5 and xPos <= 8 then
416
        previous_off = off
417
        off = off-1
418
      end
419
      if xPos >= 22 and xPos <= 25 then
420
        previous_off = off
421
        off = off+1
422
      end
423
    end
424
425
    if on < 0 then on = 0 end
426
    if off >99 then off = 99 end
427
428
    if on == off or on > off then
429
      on = previous_on
430
      off = previous_off
431
      popup_screen(5, "Error", 6)
432
      draw_text(5, 7, "Auto On value must be", colors.black, colors.white)
433
      draw_text(5, 8, "lower then auto off", colors.black, colors.white)
434
      draw_text(11, 10, "Okay", colors.white, colors.black)
435
      local event, side, xPos, yPos = os.pullEvent("monitor_touch")
436
437
      auto_off()
438
    end
439
440
    --Okay button
441
    if yPos == 13 and xPos >= 11 and xPos <= 17 then 
442
      save_config()
443
      call_homepage()
444
    end
445
446
    --Exit button
447
    if yPos == 3 and xPos == 25 then 
448
      call_homepage()
449
    end
450
451
    auto_off()
452
  else
453
    popup_screen(3, "Auto Power", 5)
454
    draw_text(5, 5, "Disabled", colors.red, colors.white)
455
    draw_text(15, 5, " enable ", colors.white, colors.gray)
456
    draw_text(11, 7, "Okay", colors.white, colors.black)
457
458
    local event, side, xPos, yPos = os.pullEvent("monitor_touch")
459
460
    --Okay button
461
    if yPos == 7 and xPos >= 11 and xPos <= 17 then 
462
      call_homepage()
463
    end
464
465
    if yPos == 5 then
466
      if xPos >= 15 and xPos <= 21 then
467
        auto_string = "true"
468
        save_config()
469
        auto_off()
470
      else
471
        auto_off()
472
      end
473
    else
474
      auto_off()
475
    end
476
  end
477
end
478
479
--efficiency menu
480
function efficiency()
481
  popup_screen(3, "Efficiency", 12)
482
  fuel_usage = reactor.getFuelConsumedLastTick()
483
  rft = math.floor(reactor.getEnergyProducedLastTick())
484
485
  rfmb = rft / fuel_usage
486
487
  draw_text(5, 5, "Fuel Consumption: ", colors.lime, colors.white)
488
  draw_text(5, 6, fuel_usage.." mB/t", colors.black, colors.white)
489
  draw_text(5, 8, "Energy per mB: ", colors.lime, colors.white)
490
  draw_text(5, 9, rfmb.." RF/mB", colors.black, colors.white)
491
492
  draw_text(5, 11, "RF/tick:", colors.lime, colors.white)
493
  draw_text(5, 12, rft.." RF/T", colors.black, colors.white)
494
495
  draw_text(11, 14, " Okay ", colors.white, colors.black)
496
497
  local event, side, xPos, yPos = os.pullEvent("monitor_touch")
498
499
  --Okay button
500
  if yPos == 14 and xPos >= 11 and xPos <= 17 then 
501
    call_homepage()
502
  end
503
504
  --Exit button
505
  if yPos == 3 and xPos == 25 then 
506
    call_homepage()
507
  end
508
509
  efficiency()
510
end
511
512
513
function fuel()
514
  popup_screen(3, "Fuel", 9)
515
516
  fuel_max = reactor.getFuelAmountMax()
517
  fuel_level = reactor.getFuelAmount()
518
  fuel_reactivity = math.floor(reactor.getFuelReactivity())
519
520
  draw_text(5, 5, "Fuel Level: ", colors.lime, colors.white)
521
  draw_text(5, 6, fuel_level.."/"..fuel_max, colors.black, colors.white)
522
523
  draw_text(5, 8, "Reactivity: ", colors.lime, colors.white)
524
  draw_text(5, 9, fuel_reactivity.."%", colors.black, colors.white)
525
526
  draw_text(11, 11, " Okay ", colors.white, colors.black)
527
528
  local event, side, xPos, yPos = os.pullEvent("monitor_touch")
529
530
531
  --Okay button
532
  if yPos == 11 and xPos >= 11 and xPos <= 17 then 
533
    call_homepage()
534
  end
535
536
  --Exit button
537
  if yPos == 3 and xPos == 25 then 
538
    call_homepage()
539
  end
540
541
  fuel()
542
end
543
544
function waste()
545
  popup_screen(3, "Waste", 8)
546
547
  waste_amount = reactor.getWasteAmount()
548
  draw_text(5, 5, "Waste Amount: ", colors.lime, colors.white)
549
  draw_text(5, 6, waste_amount.." mB", colors.black, colors.white)
550
  draw_text(8, 8, " Eject Waste ", colors.white, colors.red)
551
  draw_text(11, 10, " Close ", colors.white, colors.black)
552
553
  local event, side, xPos, yPos = os.pullEvent("monitor_touch")
554
555
  --eject button
556
  if yPos == 8 and xPos >= 8 and xPos <= 21 then 
557
    reactor.doEjectWaste()
558
    popup_screen(5, "Waste Eject", 5)
559
    draw_text(5, 7, "Waste Ejeceted.", colors.black, colors.white)
560
    draw_text(11, 9, " Close ", colors.white, colors.black)
561
    local event, side, xPos, yPos = os.pullEvent("monitor_touch")
562
    --Okay button
563
    if yPos == 7 and xPos >= 11 and xPos <= 17 then 
564
      call_homepage()
565
    end
566
567
    --Exit button
568
    if yPos == 3 and xPos == 25 then 
569
      call_homepage()
570
    end
571
  end
572
573
  --Okay button
574
  if yPos == 10 and xPos >= 11 and xPos <= 17 then 
575
    call_homepage()
576
  end
577
578
  --Exit button
579
  if yPos == 3 and xPos == 25 then 
580
    call_homepage()
581
  end
582
  waste()
583
end
584
585
function set_auto_rf()
586
  popup_screen(5, "Auto Adjust", 11)
587
    draw_text(5, 7, "Try to maintain:", colors.black, colors.white)
588
589
    draw_text(13, 9, " ^ ", colors.white, colors.gray)
590
    draw_text(10, 11, auto_rf.." RF/t", colors.black, colors.white)
591
    draw_text(13, 13, " v ", colors.white, colors.gray)
592
    draw_text(11, 15, " Okay ", colors.white, colors.gray)
593
594
    local event, side, xPos, yPos = os.pullEvent("monitor_touch")
595
596
    --increase button
597
    if yPos == 9 then 
598
      auto_rf = auto_rf + 100
599
      save_config()
600
      set_auto_rf()
601
    end
602
603
    --decrease button
604
    if yPos == 13 then 
605
      auto_rf = auto_rf - 100
606
      if auto_rf < 0 then auto_rf = 0 end
607
      save_config()
608
      set_auto_rf()
609
    end
610
611
    if yPos == 15 then 
612
      control_rods()
613
    end
614
615
    set_auto_rf()
616
end
617
618
function control_rods()
619
620
  if reactor.isActivelyCooled() then 
621
622
    popup_screen(3, "Control Rods", 13)
623
    insertion_percent = reactor.getControlRodLevel(0)
624
625
    draw_text(5, 5, "Inserted: "..insertion_percent.."%", colors.black, colors.white)
626
    progress_bar(5, 7, 20, insertion_percent, 100, colors.yellow, colors.gray)
627
628
    draw_text(5, 9, " << ", colors.white, colors.black)
629
    draw_text(10, 9, " < ", colors.white, colors.black)
630
    draw_text(17, 9, " > ", colors.white, colors.black)
631
    draw_text(21, 9, " >> ", colors.white, colors.black)
632
633
    draw_text(5, 11, "Auto:", colors.black, colors.white)
634
    draw_text(5, 13, "unavilable for", colors.red, colors.white)
635
    draw_text(5, 14, "active cooling", colors.red, colors.white)
636
637
    draw_text(11, 16, " Close ", colors.white, colors.gray)
638
639
    local event, side, xPos, yPos = os.pullEvent("monitor_touch")
640
641
    if yPos == 9 and xPos >= 5 and xPos <= 15 then 
642
      reactor.setAllControlRodLevels(insertion_percent-10)
643
    end
644
645
    if yPos == 9 and xPos >= 10 and xPos <= 13 then 
646
      reactor.setAllControlRodLevels(insertion_percent-1)
647
    end
648
649
    if yPos == 9 and xPos >= 17 and xPos <= 20 then 
650
      reactor.setAllControlRodLevels(insertion_percent+1)
651
    end
652
653
    if yPos == 9 and xPos >= 21 and xPos <= 25 then 
654
      reactor.setAllControlRodLevels(insertion_percent+10)
655
    end
656
657
    ------Close button-------
658
    if yPos == 16 and xPos >= 11 and xPos <= 17 then 
659
      call_homepage()
660
    end
661
662
    ------Exit button------------
663
    if yPos == 5 and xPos == 25 then 
664
      call_homepage()
665
    end
666
    control_rods()
667
668
  else
669
670
    popup_screen(3, "Control Rods", 13)
671
    insertion_percent = reactor.getControlRodLevel(0)
672
673
    draw_text(5, 5, "Inserted: "..insertion_percent.."%", colors.black, colors.white)
674
    progress_bar(5, 7, 20, insertion_percent, 100, colors.yellow, colors.gray)
675
676
    draw_text(5, 9, " << ", colors.white, colors.black)
677
    draw_text(10, 9, " < ", colors.white, colors.black)
678
    draw_text(17, 9, " > ", colors.white, colors.black)
679
    draw_text(21, 9, " >> ", colors.white, colors.black)
680
681
    draw_text(5, 11, "Auto:", colors.black, colors.white)
682
    draw_text(16, 11, " disable ", colors.white, colors.black)
683
684
    auto_rods_bool = auto_rods == "true"
685
    if auto_rods_bool then
686
      
687
      draw_text(5, 13, "RF/t: "..auto_rf, colors.black, colors.white)
688
      draw_text(18, 13, " set ", colors.white, colors.black)
689
    else
690
      draw_text(16, 11, " enable ", colors.white, colors.black)
691
      draw_text(5, 13, "disabled", colors.red, colors.white)
692
    end
693
694
    draw_text(11, 15, " Close ", colors.white, colors.gray)
695
696
    local event, side, xPos, yPos = os.pullEvent("monitor_touch")
697
698
    -----manual adjust buttons------------
699
    if yPos == 9 and xPos >= 5 and xPos <= 15 then 
700
      reactor.setAllControlRodLevels(insertion_percent-10)
701
    end
702
703
    if yPos == 9 and xPos >= 10 and xPos <= 13 then 
704
      reactor.setAllControlRodLevels(insertion_percent-1)
705
    end
706
707
    if yPos == 9 and xPos >= 17 and xPos <= 20 then 
708
      reactor.setAllControlRodLevels(insertion_percent+1)
709
    end
710
711
    if yPos == 9 and xPos >= 21 and xPos <= 25 then 
712
      reactor.setAllControlRodLevels(insertion_percent+10)
713
    end
714
715
716
    ------auto buttons-----------------
717
    if yPos == 11 and xPos >= 16 then 
718
      if auto_rods_bool then
719
        auto_rods = "false"
720
        save_config()
721
        control_rods()
722
      else
723
        auto_rods = "true"
724
        save_config()
725
        control_rods()
726
      end
727
    end
728
729
    if yPos == 13 and xPos >= 18 then 
730
      set_auto_rf()
731
    end
732
733
    ------Close button-------
734
    if yPos == 15 and xPos >= 11 and xPos <= 17 then 
735
      call_homepage()
736
    end
737
738
    ------Exit button------------
739
    if yPos == 5 and xPos == 25 then 
740
      call_homepage()
741
    end
742
    control_rods()
743
744
  end
745
end
746
747
-----------------------Settings--------------------------------
748
749
750
function rf_mode()
751
  wait = read()
752
end
753
754
function steam_mode()
755
  wait = read()
756
end
757
758
function install_update(program, pastebin)
759
    clear()
760
    draw_line(4, 5, 22, colors.blue)
761
762
    for counter = 6, 10 do
763
      draw_line(4, counter, 22, colors.white)
764
    end
765
766
    draw_text(5, 5, "Updating...", colors.white, colors.blue)
767
    draw_text(5, 7, "Open computer", colors.black, colors.white)
768
    draw_text(5, 8, "terminal.", colors.black, colors.white)
769
770
    if fs.exists("install") then fs.delete("install") end
771-
    shell.run("pastebin get p4zeq7Ma install")
771+
    shell.run("pastebin get Xr3K0mdN install")
772
    shell.run("install")
773
end
774
775
function update()
776
  popup_screen(5, "Updates", 4)
777
  draw_text(5, 7, "Connecting to", colors.black, colors.white)
778
  draw_text(5, 8, "pastebin...", colors.black, colors.white)
779
780
  sleep(0.5)
781
  
782
  shell.run("pastebin get MkF2QQjH current_version.txt")
783
  sr = fs.open("current_version.txt", "r")
784
  current_version = tonumber(sr.readLine())
785
  sr.close()
786
  fs.delete("current_version.txt")
787
  terminal_screen()
788
789
  if current_version > version then
790
791
    popup_screen(5, "Updates", 7)
792
    draw_text(5, 7, "Update Available!", colors.black, colors.white)
793
    draw_text(11, 9, " Install ", colors.white, colors.black)
794
    draw_text(11, 11, " Ignore ", colors.white, colors.black)
795
796
    local event, side, xPos, yPos = os.pullEvent("monitor_touch")
797
798
    --Instatll button
799
    if yPos == 9 and xPos >= 11 and xPos <= 17 then 
800
      install_update()
801
    end
802
803
    --Exit button
804
    if yPos == 5 and xPos == 25 then 
805
      call_homepage()
806
    end
807
    call_homepage()
808
809
  else
810
    popup_screen(5, "Updates", 5)
811
    draw_text(5, 7, "You are up to date!", colors.black, colors.white)
812
    draw_text(11, 9, " Okay ", colors.white, colors.black)
813
814
    local event, side, xPos, yPos = os.pullEvent("monitor_touch")
815
816
    --Okay button
817
    if yPos == 9 and xPos >= 11 and xPos <= 17 then 
818
      call_homepage()
819
    end
820
821
    --Exit button
822
    if yPos == 5 and xPos == 25 then 
823
      call_homepage()
824
    end
825
    call_homepage()
826
  end
827
828
  
829
830
end
831
832
function reset_peripherals()
833
  clear()
834
  draw_line(4, 5, 22, colors.blue)
835
836
  for counter = 6, 10 do
837
    draw_line(4, counter, 22, colors.white)
838
  end
839
840
  draw_text(5, 5, "Reset Peripherals", colors.white, colors.blue)
841
  draw_text(5, 7, "Open computer", colors.black, colors.white)
842
  draw_text(5, 8, "terminal.", colors.black, colors.white)
843
  setup_wizard()
844
845
end
846
847
--stop running status screen if monitors was touched
848
function stop()
849
  while true do
850
    local event, side, xPos, yPos = os.pullEvent("monitor_touch")
851
      x = xPos
852
      y = yPos
853
      stop_function = "monitor_touch"
854
    return
855
  end 
856
end
857
858
function mon_touch()
859
  --when the monitor is touch on the homepage
860
  if y == 1 then 
861
      if x < monX/3 then
862
        power_menu()
863
        local event, side, xPos, yPos = os.pullEvent("monitor_touch")
864
        if xPos < 9 then
865
          if yPos == 2 then
866
            reactor.setActive(true)
867
            timer = 0 --reset anytime the reactor is turned on/off
868
            call_homepage()
869
          else if yPos == 3 then
870
            reactor.setActive(false)
871
            timer = 0 --reset anytime the reactor is turned on/off
872
            call_homepage()
873
          else if yPos == 4 then
874
            auto_off()
875
          else
876
            call_homepage()
877
          end
878
          end
879
          end
880
        else
881
          call_homepage()
882
        end
883
        
884
      else if x < 20 then
885
        tools_menu()
886
        local event, side, xPos, yPos = os.pullEvent("monitor_touch")
887
        if xPos < 25 and xPos > 10 then
888
          if yPos == 2 then
889
            control_rods()
890
          else if yPos == 3 then
891
            efficiency()
892
          else if yPos == 4 then
893
            fuel()
894
          else if yPos == 5 then
895
            waste()
896
          else
897
            call_homepage()
898
          end
899
          end
900
          end
901
          end
902
        else
903
          call_homepage()
904
        end
905
      else if x < monX then
906
        settings_menu()
907
        local event, side, xPos, yPos = os.pullEvent("monitor_touch")
908
        if xPos > 13 then
909
          if yPos == 2 then
910
            update()
911
          else if yPos == 3 then
912
            reset_peripherals() 
913
          else
914
            call_homepage()
915
          end
916
          end
917
        else
918
          call_homepage()
919
        end
920
      end
921
      end
922
      end
923
    else
924
      call_homepage()
925
    end
926
end
927
928
function terminal_screen()
929
  term.clear()
930
  draw_line_term(1, 1, 55, colors.blue)
931
  draw_text_term(13, 1, "BigReactor Controls", colors.white, colors.blue)
932
  draw_line_term(1, 19, 55, colors.blue)
933-
  draw_text_term(13, 19, "by jaranvil aka jared314", colors.white, colors.blue)
933+
  draw_text_term(13, 19, "by costantino03", colors.white, colors.blue)
934
935
  draw_text_term(1, 3, "Current program:", colors.white, colors.black)
936
  draw_text_term(1, 4, "Reactor Control v"..version, colors.blue, colors.black)
937
  
938
  draw_text_term(1, 6, "Installer:", colors.white, colors.black)
939-
  draw_text_term(1, 7, "pastebin.com/p4zeq7Ma", colors.blue, colors.black)
939+
  draw_text_term(1, 7, "pastebin.com/Xr3K0mdN", colors.blue, colors.black)
940
941
  draw_text_term(1, 9, "Please give me your feedback, suggestions,", colors.white, colors.black)
942
  draw_text_term(1, 10, "and errors!", colors.white, colors.black)
943
944-
  draw_text_term(1, 11, "reddit.com/r/br_controls", colors.blue, colors.black)
944+
  draw_text_term(1, 11, "telegram: @costantino03", colors.blue, colors.black)
945
end
946
947
--run both homepage() and stop() until one returns
948
function call_homepage()
949
  clear()
950
  parallel.waitForAny(homepage, stop) 
951
952
  if stop_function == "terminal_screen" then 
953
    stop_function = "nothing"
954
    setup_wizard()
955
  else if stop_function == "monitor_touch" then
956
    stop_function = "nothing"
957
    mon_touch()
958
  end
959
  end
960
end
961
962
--test if the entered monitor and reactor can be wrapped
963
  function test_configs()
964
  term.clear()
965
966
  draw_line_term(1, 1, 55, colors.blue)
967
  draw_text_term(10, 1, "BigReactors Controls", colors.white, colors.blue)
968
  
969
  draw_line_term(1, 19, 55, colors.blue)
970-
  draw_text_term(10, 19, "by jaranvil aka jared314", colors.white, colors.blue)
970+
  draw_text_term(10, 19, "by costantino03", colors.white, colors.blue)
971
972
  draw_text_term(1, 3, "Searching for a peripherals...", colors.white, colors.black)
973
  sleep(1)
974
975
  reactor = reactorSearch()
976
  mon = monitorSearch()
977
  
978
  
979
  draw_text_term(2, 5, "Connecting to reactor...", colors.white, colors.black)
980
  sleep(0.5)
981
  if reactor == null then
982
      draw_text_term(1, 8, "Error:", colors.red, colors.black)
983
      draw_text_term(1, 9, "Could not connect to reactor", colors.red, colors.black)
984
      draw_text_term(1, 10, "Reactor must be connected with networking cable", colors.white, colors.black)
985
      draw_text_term(1, 11, "and modems or the computer is directly beside", colors.white, colors.black)
986
       draw_text_term(1, 12,"the reactors computer port.", colors.white, colors.black)
987
      draw_text_term(1, 14, "Press Enter to continue...", colors.gray, colors.black)
988
      wait = read()
989
      setup_wizard()
990
  else
991
      draw_text_term(27, 5, "success", colors.lime, colors.black)
992
      sleep(0.5)
993
  end
994
  
995
  draw_text_term(2, 6, "Connecting to monitor...", colors.white, colors.black)
996
  sleep(0.5)
997
  if mon == null then
998
      draw_text_term(1, 7, "Error:", colors.red, colors.black)
999
      draw_text_term(1, 8, "Could not connect to a monitor. Place a 3x3 advanced monitor", colors.red, colors.black)
1000
      draw_text_term(1, 11, "Press Enter to continue...", colors.gray, colors.black)
1001
      wait = read()
1002
      setup_wizard()
1003
  else
1004
      monX, monY = mon.getSize()
1005
      draw_text_term(27, 6, "success", colors.lime, colors.black)
1006
      sleep(0.5)
1007
  end
1008
    draw_text_term(2, 7, "saving configuration...", colors.white, colors.black)  
1009
1010
    save_config()
1011
1012
    sleep(0.1)
1013
    draw_text_term(1, 9, "Setup Complete!", colors.lime, colors.black) 
1014
    sleep(1)
1015
1016
    auto = auto_string == "true"
1017
    call_homepage() 
1018
1019
end
1020
----------------SETUP-------------------------------
1021
1022
function setup_wizard()
1023
  
1024
  term.clear()
1025
1026
  
1027
     draw_text_term(1, 1, "BigReactor Controls v"..version, colors.lime, colors.black)
1028
     draw_text_term(1, 2, "Peripheral setup", colors.white, colors.black)
1029
     draw_text_term(1, 4, "Step 1:", colors.lime, colors.black)
1030
     draw_text_term(1, 5, "-Place 3x3 advanced monitors next to computer.", colors.white, colors.black)
1031
     draw_text_term(1, 7, "Step 2:", colors.lime, colors.black)
1032
     draw_text_term(1, 8, "-Place a wired modem on this computer and on the ", colors.white, colors.black)
1033
     draw_text_term(1, 9, " computer port of the reactor.", colors.white, colors.black)
1034
     draw_text_term(1, 10, "-connect modems with network cable.", colors.white, colors.black)
1035
     draw_text_term(1, 11, "-right click modems to activate.", colors.white, colors.black)
1036
     draw_text_term(1, 13, "Press Enter when ready...", colors.gray, colors.black)
1037
    
1038
     wait = read()
1039
      test_configs()
1040
1041
   
1042
end
1043
1044
-- peripheral searching thanks to /u/kla_sch
1045
-- http://pastebin.com/gTEBHv3D
1046
function reactorSearch()
1047
   local names = peripheral.getNames()
1048
   local i, name
1049
   for i, name in pairs(names) do
1050
      if peripheral.getType(name) == "BigReactors-Reactor" then
1051
         return peripheral.wrap(name)
1052
      else
1053
         --return null
1054
      end
1055
   end
1056
end
1057
1058
function monitorSearch()
1059
   local names = peripheral.getNames()
1060
   local i, name
1061
   for i, name in pairs(names) do
1062
      if peripheral.getType(name) == "monitor" then
1063
        test = name
1064
         return peripheral.wrap(name)
1065
      else
1066
         --return null
1067
      end
1068
   end
1069
end
1070
1071
function start()
1072
  --if configs exists, load values and test
1073
  if fs.exists("config.txt") then
1074
      load_config()
1075
      test_configs()
1076
  else
1077
    setup_wizard()
1078
  end
1079
end
1080
1081
start()