Advertisement
Guest User

run

a guest
Jul 22nd, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.23 KB | None | 0 0
  1. -- BigReactors - Basic Reactor Control
  2. -- ----------------------------------------------------------
  3. -- Version 7.0 added button to control reactor
  4. -- Jerotire, Etari_be
  5. -- Based on code by Etari_be
  6.  
  7. -- Initilisation function (run-once)
  8. function init()
  9.   -- Wrap the reactor..
  10.   reactor = peripheral.wrap("BigReactors-Reactor_3")
  11.   mon = peripheral.wrap("monitor_12")
  12.   -- Setup terminal..
  13.   mon.clear()
  14.   mon.setCursorPos(1,2)
  15.   mon.write(" REACTOR CONTROL")
  16.   mon.setCursorPos(1,3)
  17.   mon.write(" -----------------------------")
  18.  
  19.   init_var = {}
  20.   reactorData = {}
  21.   --reactor_E_full = true
  22.   reactor.setActive(true)
  23.  
  24. end
  25.  
  26. function init_monitor()   -- put text on the monitor (is not gonna change while the program runs)
  27.   init_var[1] = "  Reactor Active : "  -- text to type
  28.   init_var[2] = "  Fuel Temp      : "
  29.   init_var[3] = "  Casing Temp    : "
  30.   init_var[4] = "  Energy/Tick    : "
  31.   init_var[5] = "  Fuelusage/Tick : "
  32.   init_var[6] = "  Total Fuel     : "
  33.   init_var[7] = "  Total Waste    : "
  34.   init_var[8] = "  Energy Stored  : "
  35.   init_var[9] = "  ControlRods at : "
  36.   for k = 1,9 do                     -- printing on the monitor
  37.     mon.setCursorPos(1,k + 4)
  38.     mon.write(init_var[k])
  39.   end
  40. end
  41.  
  42. function write_m(var, colum, row) -- print on the screen : var = msg, colum = vertical loc, row = what row to print on
  43.   mon.setCursorPos(colum,row)
  44.   mon.write(var)
  45. end
  46.  
  47. function round(var)
  48.   local roundvar = var*100
  49.   roundvar = math.floor(roundvar + 0.5)
  50.   roundvar = roundvar/100
  51.   return roundvar
  52. end
  53.  
  54. function Read_reactor()
  55.  
  56.   reactorData[1] = tostring(reactor.getActive()).." "
  57.   reactorData[2] = round(reactor.getFuelTemperature())
  58.   reactorData[3] = round(reactor.getCasingTemperature())
  59.   reactorData[4] = round(reactor.getEnergyProducedLastTick())
  60.   reactorData[5] = round(reactor.getFuelConsumedLastTick())
  61.   reactorData[6] = reactor.getFuelAmount() /1000
  62.   reactorData[7] = reactor.getWasteAmount()/1000
  63.   reactorData[8] = reactor.getEnergyStored()
  64.  
  65. end
  66.  
  67.  
  68. function reactorfull(E)        -- check reactor stored energy
  69.   reactor.setAllControlRodLevels(E/100000)
  70.   write_m(tostring(E/100000),20,13)
  71.   --if E > 9000000 then          
  72.   --  reactor.setActive(false)   -- deactivate reactor so no fuel is lost
  73.   --  reactor_E_full = true
  74.   --elseif E < 2000000 then
  75.   --  reactor.setActive(true)    -- activate reactor when charge is below 9M energy
  76.   --  reactor_E_full = false
  77.   --end
  78. end
  79.  
  80. function DrawButton(bolean)
  81.   if bolean == false then
  82.     mon.setBackgroundColor(colors.green)
  83.     mon.setCursorPos(12,16)
  84.     mon.write("            ")
  85.     mon.setCursorPos(12,17)
  86.     mon.write("  Activate  ")
  87.     mon.setCursorPos(12,18)
  88.     mon.write("            ")
  89.   else
  90.     mon.setBackgroundColor(colors.red)
  91.     mon.setCursorPos(12,16)
  92.     mon.write("            ")
  93.     mon.setCursorPos(12,17)
  94.     mon.write(" Deactivate ")
  95.     mon.setCursorPos(12,18)
  96.     mon.write("            ")
  97.   end
  98.   mon.setBackgroundColor(colors.black)
  99. end
  100. function button()
  101.   event, event_mon, xPos, yPos = os.pullEvent("monitor_touch")
  102.   print(event,event_mon,xPos,yPos)
  103.   if (event_mon == "monitor_12" and (xPos > 12 and xPos < 24) and (yPos > 15 and yPos < 19)) then
  104.      reactor.setActive(not(reactor.getActive()))
  105.      DrawButton(reactor.getActive())
  106.      print("screenhit at "..xPos.." "..yPos)
  107.   end
  108. end
  109.  
  110. ------------------------------------------------
  111.           --actual program start--
  112. ------------------------------------------------
  113.  
  114. init()
  115. init_monitor()
  116. DrawButton(true)
  117.  
  118. function autonomus()
  119.  
  120.  -- sleep(0)                 -- so the program will not crash
  121.   Read_reactor()           -- get values from reactor    
  122.   --data = textutils.unserialize(data_m)
  123.  
  124.   for x = 1, 8 do
  125.     mon.setCursorPos(20,x + 4)
  126.     mon.write(reactorData[x])
  127.   end
  128.  
  129. --  write_m(data.Reactoractief.." ",18,1)
  130. --  write_m(data.Fueltemp,18,2)
  131. --  write_m(data.Casingtemp,18,3)
  132. --  write_m(data.EnergyTick.."          ",18,4)
  133. --  write_m(data.FuelTick.."          ",18,5)
  134. --  write_m(data.FuelTotal,18,6)
  135. --  write_m(data.WasteTotal,18,7)
  136. --  write_m(data.Energy.."       ",18,8)
  137.  
  138.   reactorfull(reactorData[8])
  139.   sleep(0.5)
  140. end
  141.  
  142. while true do
  143.   parallel.waitForAny(autonomus,button)
  144.   sleep(0)
  145. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement