Advertisement
Guest User

reac_service.lua

a guest
May 18th, 2015
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.81 KB | None | 0 0
  1. inv = require("component").inventory_controller
  2. sides = require("sides")
  3. fuel_side = sides.bottom
  4. reac_side = sides.front
  5. switch_side = sides.top
  6. charge_side = sides.right
  7. event = require("event")
  8. r = require("robot")
  9. Uran_fuel = {"IC2:reactorUraniumQuad", "IC2:reactorUraniumDual"}
  10. Mox_fuel = {"IC2:reactorMOXQuad", "IC2:reactorMOXDual"}
  11.  
  12.  
  13. function charge()
  14. local comp = require("computer")
  15. while comp.energy() < (comp.maxEnergy()/2) do
  16. local rs = require("component").redstone
  17. rs.setOutput(charge_side, 15)
  18. require("term").clear()
  19. print("Зарядка...")
  20. require("event").pull(5)
  21. rs.setOutput(charge_side, 0)
  22. end
  23. print("Батарея заряжена")
  24. return true
  25. end
  26.  
  27. function use(s)
  28. if s == 1 then r.useUp() else
  29.  if s == 2 then
  30.  r.turnAround()
  31.  r.use()
  32.  r.turnAround()
  33.  else
  34.   if s == 3 then r.use() else
  35.    if s == 4 then
  36.    r.turnRight()
  37.    r.use()
  38.    r.turnRight()
  39.    else
  40.     if s==5 then
  41.   r.turnLeft()
  42.     r.use()
  43.     r.turnLeft()
  44.   else
  45.   r.useDown()
  46.   end
  47.    end
  48.   end
  49.  end
  50. end
  51. end
  52.  
  53. function clear_self()
  54.  for i=1,16 do
  55.  r.select(i)
  56.  inv.dropIntoSlot(fuel_side, 8)
  57.  end
  58.  r.select(1)
  59. end
  60.  
  61. function reac_off()
  62.  
  63. if require("component").redstone.getInput(switch_side) > 0 then
  64.  use(switch_side)
  65. end
  66.  
  67. end
  68.  
  69. function reac_on()
  70.  
  71. if require("component").redstone.getInput(switch_side) == 0 then
  72.  use(switch_side)
  73. end
  74.  
  75. end
  76.  
  77. function clear_reac()
  78. local sl = inv.getStackInSlot(reac_side, 1)
  79. if sl ~= nil then
  80. if sl["maxDamage"] == 0 then
  81. print("Удаляем отработанное топливо.")
  82. reac_off()
  83. inv.suckFromSlot(reac_side, 1)
  84. inv.suckFromSlot(reac_side, 11)
  85. inv.suckFromSlot(reac_side, 2)
  86. inv.suckFromSlot(reac_side, 10)
  87. event.pull(1)
  88. clear_self()
  89. return true
  90. else
  91. return false
  92. end
  93. else
  94. return true
  95. end
  96. end
  97.  
  98. function Fill(fuel)
  99. if clear_reac() then
  100. local size = inv.getInventorySize(fuel_side)
  101. local q = 0
  102. local d = 0
  103. for i=1, size do
  104. local sl = inv.getStackInSlot(fuel_side, i)
  105. if sl ~= nil then
  106. if sl["name"] == fuel[1] and sl["size"] >= 2 then
  107. q = i
  108. end
  109. if sl["name"] == fuel[2] and sl["size"] >= 2 then
  110. d = i
  111. end
  112. end
  113. end
  114. if q > 0 and d > 0 then
  115.  print("Закладка стержней.", fuel[1])
  116.  r.select(1)
  117.  inv.suckFromSlot(fuel_side, q, 2)
  118.  inv.suckFromSlot(fuel_side, d, 2)
  119.  inv.dropIntoSlot(reac_side, 1, 1)
  120.  inv.dropIntoSlot(reac_side, 11, 1)
  121.  r.select(2)
  122.  inv.dropIntoSlot(reac_side, 2, 1)
  123.  inv.dropIntoSlot(reac_side, 10, 1)
  124.  r.select(1)
  125. return true
  126. else
  127. print("Нет топлива")
  128. return false
  129. end
  130. else
  131. print("Реактор не отработал топливо.")
  132. end
  133. end
  134.  
  135. while true do
  136. event.pull(10)
  137. if not Fill(Uran_fuel) then
  138.   if Fill(Mox_fuel) then reac_on()
  139.   else
  140.   print("Режим ожидания поставки топлива.")
  141.   end
  142.   else
  143.   reac_on()  
  144. end
  145. require("term").clear()
  146. print("Уранит онлайн мин:", require("math").floor(require("computer").uptime()/60))
  147. charge()
  148. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement