Advertisement
Freeazzy

[IC2E] reactor scheme assembler

Aug 21st, 2019
2,070
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.41 KB | None | 0 0
  1. --[[
  2. для работы нужен реактор с 6-ю реакторными камерами и сундук, поставленный вплотную
  3. к той камере, к которой подключен адаптер, нельзя допускать, чтобы адаптер был подк-
  4. лючен сразу к двум камерам, это дает 50%-й шанс, что программа не увидит сундук.
  5. Я загрузил сюда несколько основных схем на уране и на MOX (возможно будут добавлены еще схемы),
  6. также есть встроенный "нагреватель", но с ним есть нюансы, пользоваться им можно, но осторожно.
  7. Программа сама расскажет чего не хватает в сундуке, для выбранной вами схемы.
  8. Штука удобная, всем рекомендую :)
  9. --]]
  10.  
  11. local com = require("component")
  12. local os = require("os")
  13. local red = com.redstone
  14. local term = require("term")
  15. local reactor = com.getPrimary("reactor_chamber")
  16.  
  17. local rmaxslot = reactor.getInventorySize()
  18. local sides = {}
  19. sides[1] = "DOWN"
  20. sides[2] = "UP"
  21. sides[3] = "NORTH"
  22. sides[4] = "SOUTH"
  23. sides[5] = "WEST"
  24. sides[6] = "EAST"
  25. local chests = {}
  26. chests[1] = "chest"
  27. chests[2] = "diamond"
  28. chests[3] = "crystal"
  29. chests[4] = "gold"
  30. chests[5] = "iron"
  31. chests[6] = "obsidian"
  32.  
  33. local uran = {}
  34. uran["eu420"] = "4oxtxxox  oxxoxx4x x4xx4xxooxxoxxox x4xx4xx4x xo xo xo"
  35. uran["eu230"] = "1111oxsxt1111 oxok1111oxoxs o oxoxoxoxoxoxoxs o oxsxsx"
  36. local mox = {}
  37. mox["eu12001"] = "oddopoddod22dpd22doddopoddooddopoddod22dpd22doddopoddo"
  38. mox["eu12002"] = "4ddoodd4 dttddttd oddooddo oddooddo dttddttd 4ddoodd4 "
  39.  
  40. local function getChest()
  41. local ch = 0
  42. for i=1,#chests do
  43. if pcall(com.getPrimary,chests[i]) then
  44. ch = chests[i]
  45. return ch
  46. end
  47. end
  48. if ch == 0 then
  49. print("Где сундук?")
  50. end
  51. end
  52.  
  53. local chest = com.getPrimary(getChest())
  54. local maxslot = chest.getInventorySize()
  55.  
  56. local function choose()
  57. local choice = 0
  58. print("Выберите тип реактора\n1.Уран\n2.MOX")
  59. local typ = tonumber(term.read())
  60. if typ == 1 then
  61. print("Выберите схему\n1. На счетверенных стержнях, выдает 420 EU/t\n2. на одинарных стержнях, выдает 230 EU/t")
  62. while choice == 0 do
  63. choice = tonumber(term.read())
  64. if choice == 1 then
  65. return uran["eu420"], true
  66. elseif choice == 2 then
  67. return uran["eu230"], true
  68. else
  69. choice = 0
  70. print("Ошибка ввода, повторите попытку")
  71. end
  72. end
  73. elseif typ == 2 then
  74. print("Выберите схему\n1. с теплоёмкими реакт. пластинами, выдает примерно 1200 EU/t\n2. на четверных стержнях, выдает примерно 1200 EU/t")
  75. while choice == 0 do
  76. choice = tonumber(term.read())
  77. if choice == 1 then
  78. return mox["eu12001"], false
  79. elseif choice == 2 then
  80. return mox["eu12002"], false
  81. else
  82. choice = 0
  83. print("Ошибка ввода, повторите попытку")
  84. end
  85. end
  86. end
  87.  
  88. end
  89.  
  90. local function reactorIsEmpty()
  91. local s = reactor.getAllStacks()
  92. local c = 0
  93. for k,v in pairs(s) do
  94. c=c+1
  95. end
  96. if c == 0 then
  97. return true
  98. else
  99. return false
  100. end
  101. end
  102. local function scheme (side,uran,str)
  103. local rvso = {}
  104. local rvsoc=0
  105. local rvgx = {}
  106. local rvgxc=0
  107. local ruq4 = {}
  108. local ruq4c=0
  109. local rhss = {}
  110. local rhssc=0
  111. local rph = {}
  112. local rphc=0
  113. local rvd = {}
  114. local rvdc=0
  115.  
  116. local rv = {}
  117. local rvc=0
  118. local rvk = {}
  119. local rvkc=0
  120. local rhs = {}
  121. local rhsc=0
  122. local rhsk = {}
  123. local rhskc=0
  124. local rus1 = {}
  125. local rus1c=0
  126. local rud2 = {}
  127. local rud2c=0
  128. --"oddopoddod22dpd22doddopoddooddopoddod22dpd22doddopoddo"
  129. --"4ddoodd4 dttddttd oddooddo oddooddo dttddttd 4ddoodd4 "
  130. --reactorMOXSimple reactorMOXDual reactorMOXQuad reactorPlatingHeat
  131. --[[ o = reactorVentSpread(Компонентный ТВод); x = reactorVentGold(Разогнанный ТВод); 4 = reactorUraniumQuad;
  132.  t = reactorHeatSwitchSpread(Компонентный ТОбм); 1 = reactorUraniumSimple; 2 = reactorUraniumDual;
  133.  v = reactorVent (Теплоотвод rv); c = reactorVentCore(Реакт ТВод rvk); s = reactorHeatSwitch(ТОбм rhs)
  134.  k = reactorHeatSwitchCore(Реакт ТОбм rhsk); p = reactorPlatingHeat(Теполёмк реакт пластина); d = reactorVentDiamond(улучш твод)--]]
  135. for i=1,maxslot do
  136. local slot = chest.getStackInSlot(i)
  137. if slot ~= nil then
  138. --print(i.." = "..slot.name.." ("..slot.qty..")")
  139. if slot.name == "reactorVentSpread" then
  140. rvsoc = rvsoc+1
  141. rvso[rvsoc]=i
  142. elseif slot.name == "reactorVentGold" then
  143. rvgxc = rvgxc+1
  144. rvgx[rvgxc]=i
  145. elseif slot.name == "reactorHeatSwitchSpread" then
  146. rhssc = rhssc+1
  147. rhss[rhssc]=i
  148. elseif slot.name == "reactorPlatingHeat" then
  149. rphc = rphc+1
  150. rph[rphc]=i
  151. elseif slot.name == "reactorVentDiamond" then
  152. rvdc = rvdc+1
  153. rvd[rvdc]=i
  154.  
  155. elseif slot.name == "reactorVent" then
  156. rvc = rvc+1
  157. rv[rvc]=i
  158. elseif slot.name == "reactorVentCore" then
  159. rvkc = rvkc+1
  160. rvk[rvkc]=i
  161. elseif slot.name == "reactorHeatSwitch" then
  162. rhsc = rhsc+1
  163. rhs[rhsc]=i
  164. elseif slot.name == "reactorHeatSwitchCore" then
  165. rhskc = rhskc+1
  166. rhsk[rhskc]=i
  167.  
  168. end
  169. if uran then
  170. if slot.name == "reactorUraniumSimple" then
  171. rus1c = rus1c+1
  172. rus1[rus1c]=i
  173. elseif slot.name == "reactorUraniumDual" then
  174. rud2c = rud2c+1
  175. rud2[rud2c]=i
  176. elseif slot.name == "reactorUraniumQuad" then
  177. ruq4c = ruq4c+1
  178. ruq4[ruq4c]=i
  179. end
  180. else
  181. if slot.name == "reactorMOXSimple" then
  182. rus1c = rus1c+1
  183. rus1[rus1c]=i
  184. elseif slot.name == "reactorMOXDual" then
  185. rud2c = rud2c+1
  186. rud2[rud2c]=i
  187. elseif slot.name == "reactorMOXQuad" then
  188. ruq4c = ruq4c+1
  189. ruq4[ruq4c]=i
  190. end
  191.  
  192. end
  193. end
  194. end
  195.  
  196. rvsoc=1
  197. rvgxc=1
  198. ruq4c=1
  199. rhssc=1
  200. rphc=1
  201. rvdc=1
  202.  
  203. rvc=1
  204. rvkc=1
  205. rhsc=1
  206. rhskc=1
  207. rus1c=1
  208. rud2c=1
  209.  
  210. for i=1,rmaxslot do
  211. if string.sub(str,i,i) == "o" then
  212. reactor.pullItem(side,rvso[rvsoc],1,i)
  213. rvsoc=rvsoc+1
  214. elseif string.sub(str,i,i) == "x" then
  215. reactor.pullItem(side,rvgx[rvgxc],1,i)
  216. rvgxc=rvgxc+1
  217. elseif string.sub(str,i,i) == "4" then
  218. reactor.pullItem(side,ruq4[ruq4c],1,i)
  219. if ruq4[2] ~= nil then
  220. if chest.getStackInSlot(ruq4[ruq4c]) == nil then
  221. ruq4c=ruq4c+1
  222. end
  223. end
  224. elseif string.sub(str,i,i) == "t" then
  225. reactor.pullItem(side,rhss[rhssc],1,i)
  226. rhssc=rhssc+1
  227. elseif string.sub(str,i,i) == "p" then
  228. reactor.pullItem(side,rph[rphc],1,i)
  229. if rph[2] ~= nil then
  230. if chest.getStackInSlot(rph[rphc]) == nil then
  231. rphc=rphc+1
  232. end
  233. end
  234. elseif string.sub(str,i,i) == "d" then
  235. reactor.pullItem(side,rvd[rvdc],1,i)
  236. rvdc=rvdc+1
  237.  
  238. elseif string.sub(str,i,i) == "v" then
  239. reactor.pullItem(side,rv[rvc],1,i)
  240. rvc=rvc+1
  241. elseif string.sub(str,i,i) == "c" then
  242. reactor.pullItem(side,rvk[rvkc],1,i)
  243. rvkc=rvkc+1
  244. elseif string.sub(str,i,i) == "s" then
  245. reactor.pullItem(side,rhs[rhsc],1,i)
  246. rhsc=rhsc+1
  247. elseif string.sub(str,i,i) == "k" then
  248. reactor.pullItem(side,rhsk[rhskc],1,i)
  249. rhskc=rhskc+1
  250. elseif string.sub(str,i,i) == "1" then
  251. reactor.pullItem(side,rus1[rus1c],1,i)
  252. if rus1[2] ~= nil then
  253. if chest.getStackInSlot(rus1[rus1c]) == nil then
  254. rus1c=rus1c+1
  255. end
  256. end
  257. elseif string.sub(str,i,i) == "2" then
  258. reactor.pullItem(side,rud2[rud2c],1,i)
  259. if rud2[2] ~= nil then
  260. if chest.getStackInSlot(rud2[rud2c]) == nil then
  261. rud2c=rud2c+1
  262. end
  263. end
  264. end
  265. end
  266. end
  267. --[[local function chestShow()
  268. for i=1,maxslot do
  269. local slot = chest.getStackInSlot(i)
  270. if slot ~= nil then
  271. print(i.." = "..slot.name.." ("..slot.qty..")")
  272. end
  273. end
  274. end]]--
  275.  
  276. local function dCount(str,d)
  277. local c = 0
  278. for i=1,string.len(str) do
  279. if string.sub(str,i,i) == d then
  280. c=c+1
  281. end
  282. end
  283. return c
  284. end
  285.  
  286. local function chestCheck(str,uran)
  287. --ox4tvcskl2
  288. local enough = true
  289. local on=dCount(str,"o")
  290. local xn=dCount(str,"x")
  291. local tn=dCount(str,"t")
  292. local pn=dCount(str,"p")
  293. local dn=dCount(str,"d")
  294. local vn=dCount(str,"v")
  295. local cn=dCount(str,"c")
  296. local sn=dCount(str,"s")
  297. local kn=dCount(str,"k")
  298. local u1n=dCount(str,"1")
  299. local u2n=dCount(str,"2")
  300. local u4n=dCount(str,"4")
  301.  
  302. local oh=0
  303. local xh=0
  304. local u4h=0
  305. local th=0
  306. local ph=0
  307. local dh=0
  308. local vh=0
  309. local ch=0
  310. local sh=0
  311. local kh=0
  312. local u1h=0
  313. local u2h=0
  314.  
  315. for i=1,maxslot do
  316. local slot = chest.getStackInSlot(i)
  317. if slot ~= nil then
  318. --print(i.." = "..slot.name.." ("..slot.qty..")")
  319. if slot.name == "reactorVentSpread" then
  320. oh=oh+1
  321. elseif slot.name == "reactorVentGold" then
  322. xh=xh+1
  323. elseif slot.name == "reactorHeatSwitchSpread" then
  324. th=th+1
  325. elseif slot.name == "reactorPlatingHeat" then
  326. ph=ph+slot.qty
  327. elseif slot.name == "reactorVentDiamond" then
  328. dh=dh+1
  329.  
  330. elseif slot.name == "reactorVent" then
  331. vh=vh+1
  332. elseif slot.name == "reactorVentCore" then
  333. ch=ch+1
  334. elseif slot.name == "reactorHeatSwitch" then
  335. sh=sh+1
  336. elseif slot.name == "reactorHeatSwitchCore" then
  337. kh=kh+1
  338. end
  339. if uran then
  340. if slot.name == "reactorUraniumSimple" then
  341. u1h=u1h+slot.qty
  342. elseif slot.name == "reactorUraniumDual" then
  343. u2h=u2h+slot.qty
  344. elseif slot.name == "reactorUraniumQuad" then
  345. u4h=u4h+slot.qty
  346. end
  347. else
  348. if slot.name == "reactorMOXSimple" then
  349. u1h=u1h+slot.qty
  350. elseif slot.name == "reactorMOXDual" then
  351. u2h=u2h+slot.qty
  352. elseif slot.name == "reactorMOXQuad" then
  353. u4h=u4h+slot.qty
  354. end
  355. end
  356. end
  357. end
  358. if on > oh then
  359. print("нехватает компонента 'Компонентный Теплоотвод' "..on-oh.." шт")
  360. enough = false
  361. end
  362. if xn > xh then
  363. print("нехватает компонента 'Разогнанный Теплоотвод' "..xn-xh.." шт")
  364. enough = false
  365. end
  366. if tn > th then
  367. print("нехватает компонента 'Компонентный Теплообменник' "..tn-th.." шт")
  368. enough = false
  369. end
  370. if pn > ph then
  371. print("нехватает компонента 'Теплоёмкая реакторная пластина' "..pn-ph.." шт")
  372. enough = false
  373. end
  374. if dn > dh then
  375. print("нехватает компонента 'Улучшенный Теплоотвод' "..dn-dh.." шт")
  376. enough = false
  377. end
  378.  
  379. if vn > vh then
  380. print("нехватает компонента 'Теплоотвод' "..vn-vh.." шт")
  381. enough = false
  382. end
  383. if cn > ch then
  384. print("нехватает компонента 'Реакторный Теплоотвод' "..cn-ch.." шт")
  385. enough = false
  386. end
  387. if sn > sh then
  388. print("нехватает компонента 'Теплообменник' "..sn-sh.." шт")
  389. enough = false
  390. end
  391. if kn > kh then
  392. print("нехватает компонента 'Реакторный Теплообменник' "..kn-kh.." шт")
  393. enough = false
  394. end
  395. if uran then
  396. if u1n > u1h then
  397. print("нехватает компонента 'Одинарный урановый стержень' "..u1n-u1h.." шт")
  398. enough = false
  399. end
  400. if u2n > u2h then
  401. print("нехватает компонента 'Сдвоенный урановый стержень' "..u2n-u2h.." шт")
  402. enough = false
  403. end
  404. if u4n > u4h then
  405. print("нехватает компонента 'Счетверенный урановый стержень' "..u4n-u4h.." шт")
  406. enough = false
  407. end
  408. else
  409. if u1n > u1h then
  410. print("нехватает компонента 'Одинарный MOX стержень' "..u1n-u1h.." шт")
  411. enough = false
  412. end
  413. if u2n > u2h then
  414. print("нехватает компонента 'Сдвоенный MOX стержень' "..u2n-u2h.." шт")
  415. enough = false
  416. end
  417. if u4n > u4h then
  418. print("нехватает компонента 'Счетверенный MOX стержень' "..u4n-u4h.." шт")
  419. enough = false
  420. end
  421.  
  422. end
  423. return enough
  424. end
  425. local function sideCheck()
  426. local side = 0
  427. for i=1,#sides do
  428. if pcall(reactor.pullItem,sides[i],1,1,1) then
  429. --print(sides[i])
  430. side=sides[i]
  431. reactor.pushItem(side,1,1,1)
  432. return side
  433. end
  434. end
  435. if side == 0 then
  436. print("где сундук?")
  437. return false
  438. end
  439. end
  440.  
  441. local function heat()
  442. print("Ваш реактор нагрет не до максимума. Запустить программу безопасного нагрева реактора?\n1. Да\n2. Нет")
  443. local yn = tonumber(term.read())
  444. if yn == 1 then
  445. print("Для работы программы, проведите сигнал красного камня от лицевой части системного блока к реактору\nДля безопасности рекомендуется убрать из реактора все лишнее и оставить одинарный урановый стержень\nНажмите ENTER, чтобы продолжить")
  446. term.read()
  447. local maxheat = reactor.getMaxHeat()
  448. local curheat = reactor.getHeat()
  449. local aimheat = maxheat-20
  450. red.setOutput(3,255)
  451.  
  452. while curheat<aimheat do
  453. print("Температура: "..curheat.." / "..maxheat)
  454. curheat = reactor.getHeat()
  455. term.clear()
  456. end
  457. red.setOutput(3,0)
  458. print("Процесс нагрева завершен, очистите реактор, чтобы начать процесс заполнения схемы")
  459.  
  460. while not reactorIsEmpty() do
  461. os.sleep(0)
  462. end
  463. else
  464. print("Программа нагрева отменена")
  465. return
  466. end
  467. end
  468.  
  469. local function heatCheck()
  470. local c = (reactor.getHeat()/reactor.getMaxHeat())*100
  471. if c < 99 then
  472. return false
  473. else
  474. return true
  475. end
  476. end
  477.  
  478. if reactorIsEmpty() then
  479. local side = sideCheck()
  480. if side then
  481. local schm,uran = choose()
  482. if chestCheck(schm,uran) then
  483. if not uran and not heatCheck() then
  484. heat()
  485. end
  486. scheme(side,uran,schm)
  487. end
  488. end
  489. else
  490. print("Очистите реактор")
  491. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement