switch72

Untitled

Apr 15th, 2020
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.12 KB | None | 0 0
  1.  
  2. r = require("robot")
  3. component = require("component")
  4. --g = component.generator
  5. inv = component.inventory_controller
  6.  
  7. machine_blocks = {
  8. ["pipe"] = {label = "Fluid Pipe", slot = {} , count = 0, required = 0},
  9. ["steelsheet"] = {label = "Steel Sheetmetal", slot = {} , count = 0, required = 0},
  10. ["HEblock"] = {label = "Heavy Engineering Block", slot = {} , count = 0, required = 0},
  11. ["steelscaff"] = {label = "Steel Scaffolding", slot = {} , count = 0, required = 0},
  12. ["LEblock"] = {label = "Light Engineering Block", slot = {} , count = 0, required = 0},
  13. ["REblock"] = {label = "Redstone Engineering Block", slot = {} , count = 0, required = 0},
  14. ["fence"] = {label = "Treated Wood Fence", slot = {} , count = 0, required = 0},
  15. ["steelblock"] = {label = "Block of Steel", slot = {} , count = 0, required = 0},
  16. ["radiator"] = {label = "Radiator Block", slot = {} , count = 0, required = 0},
  17. ["dirt"] = {label = "Dirt", slot = {} , count = 0, required = 0}
  18. }
  19.  
  20.  
  21. pumpjackBp = {
  22. {
  23. {"steelscaff","steelscaff","steelscaff","pipe","steelscaff"},
  24. {"steelscaff","steelscaff","steelscaff","pipe","pipe","steelscaff"},
  25. {"LEblock","steelscaff","steelscaff","pipe","steelscaff"}
  26. },
  27. {
  28. {"REblock","air","temp","fence"},
  29. {"air","HEblock"},
  30. {"LEblock","air","temp","fence"}
  31. },
  32. {
  33. {"air","air","air","fence"},
  34. {"air","HEblock","temp","temp","temp","steelblock"},
  35. {"air","air","air","fence"}
  36. },
  37. {
  38. {"air","air","air","fence"},
  39. {"air","steelsheet","steelsheet","steelsheet","steelsheet","steelblock"},
  40. {"air","air","air","fence"}
  41. }
  42. }
  43.  
  44. excavatorBp = {
  45. {
  46. {"air"},
  47. {"air","air","air","air","steelblock"}
  48. },
  49. {
  50. {"dirt"},
  51. {"air","air","steelblock","steelscaff","steelscaff","steelscaff","steelblock"}
  52. },
  53. {
  54. {"radiator","steelsheet","steelsheet","steelscaff","steelscaff","steelscaff"},
  55. {"steelsheet","air","steelscaff","steelscaff","steelscaff","steelscaff","steelscaff"},
  56. {"steelsheet","LEblock","steelsheet","steelscaff","steelscaff","steelscaff"}
  57. },
  58. {
  59. {"REblock","steelsheet","steelsheet","LEblock","air","LEblock"},
  60. {"HEblock","steelblock","steelscaff","steelscaff","steelblock","steelscaff","steelscaff","steelblock"},
  61. {"steelsheet","LEblock","steelsheet","HEblock","HEblock","HEblock"}
  62. },
  63. {
  64. {"HEblock","radiator","radiator","LEblock","LEblock","LEblock"},
  65. {"steelsheet","air","steelscaff","steelscaff","steelscaff","steelscaff","steelscaff"},
  66. {"steelsheet","LEblock","steelsheet","steelsheet","steelsheet","steelsheet"}
  67. },
  68. {
  69. {"air"},
  70. {"air","air","steelblock","steelscaff","steelscaff","steelscaff","steelblock"}
  71. },
  72. {
  73. {"air"},
  74. {"air","air","air","air","steelblock"}
  75. }
  76. }
  77.  
  78. function findBedrock()
  79. local moved = 0
  80. while true do
  81. if r.detectDown() then
  82. if not r.swingDown() then
  83. print "Found Bedrock"
  84. break
  85. end
  86. else
  87. r.down()
  88. moved = moved + 1
  89. end
  90. end
  91. return moved
  92. end
  93.  
  94. function checkinventory()
  95. sufficientMaterials = true
  96.  
  97. for slot = 1, r.inventorySize(), 1 do
  98. r.select(slot)
  99. if r.count() > 0 then
  100. for block, blockinfo in pairs(machine_blocks) do
  101. if inv.getStackInInternalSlot().label == blockinfo.label then
  102. table.insert(blockinfo.slot,slot)
  103. blockinfo.count = blockinfo.count + inv.getStackInInternalSlot().size
  104. break
  105. end
  106. end
  107. end
  108. end
  109. for block, blockinfo in pairs(machine_blocks) do
  110. if blockinfo.count < blockinfo.required then
  111. sufficientMaterials = false
  112. print ("Insufficient \"" .. blockinfo.label .. "\" need (" .. blockinfo.required - blockinfo.count .. ") additional blocks.")
  113. end
  114. end
  115.  
  116. return sufficientMaterials
  117. end
  118.  
  119.  
  120. function deploypipe()
  121. moved = findBedrock()
  122. r.select(machine_blocks.pipe.slot)
  123. outofpipe = 0
  124. pipeplaced = 0
  125. for i=1, moved, 1 do
  126. r.up()
  127. if inv.getStackInInternalSlot().size > 0 then
  128. r.placeDown()
  129. pipeplaced = pipeplaced + 1
  130. else
  131. outofpipe = 1
  132. end
  133. end
  134.  
  135. if outofpipe == 1 then
  136. print ("Ran out of pipe")
  137. print ("Require " .. pipeplaced - moved .. " additional pipe.")
  138. end
  139. print ("Used " .. pipeplaced .. " pipe.")
  140. end
  141.  
  142. function build(blueprint)
  143. x = 0
  144. y = 0
  145. z = 0
  146. tempx = {}
  147. for layer, layertable in ipairs(blueprint) do
  148. r.swingUp()
  149. r.up()
  150. y = y + 1
  151. for row, rowtable in ipairs (layertable) do
  152. for index, block in ipairs (rowtable) do
  153. r.swing()
  154. r.forward()
  155. r.swingDown()
  156. x = x + 1
  157. if block == "air" then
  158. else
  159. if block == "temp" then
  160. tempx[x] = true
  161. block = "dirt"
  162. end
  163. r.select(machine_blocks[block].slot[1])
  164. if r.count() < 1 then --check if out of this block type in this slot
  165. table.remove(machine_blocks[block].slot,1) --remove this slot from list of slots with this block type
  166. if machine_blocks[block].slot[1] then
  167. r.select(machine_blocks[block].slot[1]) --change to next slot of this block type
  168. else
  169. print("Error, ran out of materials")
  170. return false
  171. end
  172. end
  173. r.placeDown()
  174.  
  175. end
  176. end
  177. for start = x, 1 , -1 do
  178. if tempx[x] then
  179. r.swingDown()
  180. tempx[x]=nil
  181. end
  182. r.back()
  183. x = x - 1
  184. end
  185. if next(layertable,row) then --check if there are more rows in this layer
  186. r.turnRight()
  187. r.swing()
  188. r.forward()
  189. z = z + 1
  190. r.turnLeft()
  191. end
  192. end
  193. r.turnRight()
  194. for start = z, 1 , -1 do
  195. r.back()
  196. z = z - 1
  197. end
  198. r.turnLeft()
  199. end
  200. for start = y, 1 , -1 do
  201. r.swingDown()
  202. r.down()
  203. y = y - 1
  204. end
  205. return true
  206. end
  207.  
  208. function deconstruct(blueprint)
  209. x = 0
  210. y = 0
  211. z = 0
  212. for layer, layertable in ipairs(blueprint) do
  213. r.up()
  214. y = y + 1
  215. for row, rowtable in ipairs (layertable) do
  216. for index, block in ipairs (rowtable) do
  217. r.swing()
  218. r.forward()
  219. r.swingDown()
  220. x = x + 1
  221. end
  222. for start = x, 1 , -1 do
  223. r.back()
  224. x = x - 1
  225. end
  226. if next(layertable,row) then --check if there are more rows in this layer
  227. r.turnRight()
  228. r.swing()
  229. r.forward()
  230. z = z + 1
  231. r.turnLeft()
  232. end
  233. end
  234. r.turnRight()
  235. for start = z, 1 , -1 do
  236. r.back()
  237. z = z - 1
  238. end
  239. r.turnLeft()
  240. end
  241. for start = y, 1 , -1 do
  242. r.down()
  243. y = y - 1
  244. end
  245. print("X="..x.."Y="..y.."Z="..z)
  246. end
  247.  
  248.  
  249.  
  250. function buildpumpjack()
  251. machine_blocks.pipe.required = 4
  252. machine_blocks.steelsheet.required = 4
  253. machine_blocks.HEblock.required = 2
  254. machine_blocks.steelscaff.required = 11
  255. machine_blocks.LEblock.required = 2
  256. machine_blocks.REblock.required = 1
  257. machine_blocks.fence.required = 6
  258. machine_blocks.steelblock.required = 2
  259. machine_blocks.dirt.required = 3
  260. if checkinventory() then
  261. print ("There is sufficient inventory to build the pumpjack.")
  262.  
  263.  
  264. build(pumpjackBp)
  265.  
  266. r.up()
  267. r.turnRight()
  268. r.forward()
  269. r.turnLeft()
  270. r.forward()
  271. r.use()
  272. r.back()
  273. r.turnRight()
  274. r.back()
  275. r.turnLeft()
  276. r.down()
  277.  
  278.  
  279. else
  280. print ("There are not enough materials to build the pumpjack.")
  281. end
  282.  
  283. end
  284.  
  285. function buildexcavator()
  286. machine_blocks.pipe.required = 0
  287. machine_blocks.steelsheet.required = 15
  288. machine_blocks.HEblock.required = 5
  289. machine_blocks.steelscaff.required = 26
  290. machine_blocks.LEblock.required = 9
  291. machine_blocks.REblock.required = 1
  292. machine_blocks.fence.required = 0
  293. machine_blocks.radiator.required = 3
  294. machine_blocks.steelblock.required = 9
  295. machine_blocks.dirt.required = 1
  296. if checkinventory() then
  297. r.swingDown()
  298. r.down()
  299. r.swingDown()
  300. r.down()
  301. build(excavatorBp)
  302. r.up()
  303. r.up()
  304.  
  305. r.turnLeft()
  306. r.swing()
  307. r.forward()
  308. r.turnRight()
  309. r.up()
  310. r.forward()
  311. r.forward()
  312. r.forward()
  313. r.forward()
  314. r.forward()
  315. r.turnRight()
  316. r.forward()
  317. r.use()
  318. r.back()
  319. r.select(machine_blocks.LEblock.slot[1])
  320. r.place()
  321. r.back()
  322. r.turnLeft()
  323. r.back()
  324. r.back()
  325. r.back()
  326. r.back()
  327. r.back()
  328. r.down()
  329. r.down()
  330. r.turnRight()
  331. r.forward()
  332. r.forward()
  333. r.forward()
  334. r.turnLeft()
  335. r.use()
  336.  
  337. end
  338.  
  339.  
  340. end
  341.  
  342. function main()
  343. runmenu = true
  344.  
  345. while runmenu do
  346. print("Select BLueprint:")
  347. print("1. Pumpjack")
  348. print("2. Excavator")
  349. print("0. Exit")
  350. selectedbp = math.floor(math.abs(tonumber(io.read())))
  351. if selectedbp == 1 then
  352. print("Select Action:")
  353. print("1. Construct")
  354. print("2. Deconstruct")
  355. print("0. Return")
  356. selectedaction = math.floor(math.abs(tonumber(io.read())))
  357. if selectedaction == 1 then
  358. buildpumpjack()
  359. elseif selectedaction == 2 then
  360. deconstruct(pumpjackBp)
  361. end
  362. elseif selectedbp == 2 then
  363. print("Select Action:")
  364. print("1. Construct")
  365. print("2. Deconstruct")
  366. print("0. Return")
  367. selectedaction = math.floor(math.abs(tonumber(io.read())))
  368. if selectedaction == 1 then
  369. buildexcavator()
  370. elseif selectedaction == 2 then
  371. r.swingDown()
  372. r.down()
  373. r.swingDown()
  374. r.down()
  375. deconstruct(excavatorBp)
  376. r.up()
  377. r.up()
  378. end
  379. elseif selectedbp == 0 then
  380. runmenu = false
  381. else
  382. print("Invalid selection, enter the number of your choice.")
  383. end
  384. end
  385. end
  386.  
  387. main()
Advertisement
Add Comment
Please, Sign In to add comment