MiStAWaFFlEZZ

Genv1

Apr 18th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. local component = require("component")
  2. local gpu = component.gpu
  3. local w,h = gpu.getResolution()
  4.  
  5. print("Initialising...")
  6. local dGenAddr = component.ie_diesel_generator.address
  7. local fermAddr = component.ie_fermenter.address
  8. local squeAddr = component.ie_squeezer.address
  9. local refiAddr = component.ie_refinery.address
  10. --print("Generator address: ", dGenAddr)
  11. local g = component.proxy(dGenAddr)
  12. local f = component.proxy(fermAddr)
  13. local s = component.proxy(squeAddr)
  14. local r = component.proxy(refiAddr)
  15. print("Enabling computer control...")
  16. g.enableComputerControl(true)
  17. f.enableComputerControl(true)
  18. s.enableComputerControl(true)
  19. r.enableComputerControl(true)
  20. g.setEnabled(false)
  21. f.setEnabled(false)
  22. s.setEnabled(false)
  23. r.setEnabled(false)
  24.  
  25. function getInfo()
  26. -- check how much diesel we have
  27. dTank = g.getTankInfo()
  28. -- reset input count
  29. fInputSize = 0
  30. sInputSize = 0
  31. -- get size of each stack in fermenter and squeezer
  32. for i = 1,6 do
  33. fInputSize = fInputSize + f.getInputStack(i)["size"]
  34. sInputSize = sInputSize + s.getInputStack(i)["size"]
  35. gpu.set(1,15,tostring(fInputSize))
  36. end
  37. -- fermenter and squeezer fluid output
  38. fTank = f.getFluid()
  39. sTank = s.getFluid()
  40.  
  41. -- refinery io
  42. rInTank = r.getInputFluidTanks()
  43. rOutTank = r.getOutputTank()
  44. end
  45.  
  46. function updateScreen()
  47. gpu.setBackground(0x000000,false)
  48. gpu.fill(1,1,w,h, " ")
  49.  
  50. gpu.set(1,1,"Generator:")
  51. gpu.set(11,1,tostring(g.isActive()))
  52. gpu.set(1,2,"Tank: ")
  53. gpu.set(7,2,tostring(dTank["amount"]))
  54. gpu.set(14,2,"/")
  55. gpu.set(15,2,tostring(dTank["capacity"]))
  56.  
  57. gpu.set(1,3,"Fermenter")
  58. gpu.set(10,3,tostring(f.isActive()))
  59. gpu.set(1,4,"Ethanol:")
  60. gpu.set(9,4,tostring(fTank["amount"]))
  61. gpu.set(17,4,"/")
  62. gpu.set(19,4,tostring(fTank["capacity"]))
  63. gpu.set(1,5,"Potato:")
  64. gpu.set(9,5,tostring(fInputSize))
  65. gpu.set(14,5,"/")
  66. gpu.set(15,5,"384.0")
  67.  
  68. gpu.set(1,6,"Squeezer")
  69. gpu.set(9,6,tostring(s.isActive()))
  70. gpu.set(1,7,"Plant Oil:")
  71. gpu.set(11,7,tostring(sTank["amount"]))
  72. gpu.set(19,7,"/")
  73. gpu.set(21,7,tostring(sTank["capacity"]))
  74. gpu.set(1,8,"Weed:")
  75. gpu.set(6,8,tostring(sInputSize))
  76. gpu.set(12,8,"/")
  77. gpu.set(13,8,"384.0")
  78.  
  79. gpu.set(1,9,"Fermenter")
  80. gpu.set(9,9,tostring(f.isActive()))
  81. gpu.set(1,10,"Ethanol:")
  82. gpu.set(9,10,tostring(rInTank["input1"]["amount"]))
  83. gpu.set(17,10,"/")
  84. gpu.set(19,10,tostring(rInTank["input1"]["capacity"]))
  85. gpu.set(1,11,"Plant Oil:")
  86. gpu.set(11,11,tostring(rInTank["input2"]["amount"]))
  87. gpu.set(18,11,"/")
  88. gpu.set(19,11,tostring(rInTank["input2"]["capacity"]))
  89. gpu.set(1,12,"Biodiesel:")
  90. gpu.set(11,12,tostring(rOutTank["amount"]))
  91. gpu.set(19,12,"/")
  92. gpu.set(20,12,tostring(rOutTank["capacity"]))
  93. end
  94.  
  95. function logicCheck()
  96. -- if filled by >50% activate the squeezer/fermenter
  97. if fTank["amount"]/fTank["capacity"] >= 0.5 then
  98. f.setEnabled(true)
  99. else
  100. f.setEnabled(false)
  101. end
  102. -- if filled by >50% activate the squeezer/fermenter
  103. if sTank["amount"]/sTank["capacity"] >= 0.5 then
  104. s.setEnabled(true)
  105. else
  106. s.setEnabled(false)
  107. end
  108.  
  109. if rInTank["input1"]["amount"]/rInTank["input1"]["capacity"] > 0.5 and rInTank["input2"]["amount"]/rInTank["input2"]["capacity"] > 0.5 then
  110. r.setEnabled(true)
  111. else
  112. r.setEnabled(false)
  113. end
  114.  
  115. if dTank["amount"]/dTank["capacity"] > 0.5 then
  116. g.setEnabled(true)
  117. else
  118. g.setEnabled(false)
  119. end
  120. end
  121.  
  122. function wait(seconds)
  123. local start = os.time()
  124. repeat until os.time() > start + seconds
  125. end
  126.  
  127. while true do
  128. getInfo()
  129. logicCheck()
  130. updateScreen()
  131. wait(1)
  132. --print(tostring(i))
  133. end
Advertisement
Add Comment
Please, Sign In to add comment