Advertisement
darthgustav

dig2.lua

Feb 5th, 2020
1,882
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.29 KB | None | 0 0
  1. --[[
  2. ==============
  3. dig2.lua
  4. v1.1
  5. by Roachy
  6. ==============
  7. ------------
  8. Description
  9. ------------
  10. This is an overhaul of the dig.lua program included with OpenComputers.
  11. ----------
  12. Changelog
  13. ----------
  14. v1.1:
  15. - Added configurable depth/width/height
  16. Use -S option for original behavior (square shaft to bedrock)
  17. Use new -C option for digging a cube
  18. - Added -j option for "jumping to" a layer (skipping higher layers)
  19. - Overhauled and fleshed out failure logic and added text output for relevant occurrences
  20. - Overhauled organization of functions to reduce duplication of code and logic
  21. - Added energy monitoring. Will return to origin when energy drains below a reasonable threshhold.
  22. ------
  23. Plans
  24. ------
  25. - Add option to discard cobble/stone
  26. - Add failure recovery techniques (e.g. can't hover high enough so move to wall)
  27. - Add ability to specify where on the outskirts of the dig the chest and/or charger block are located
  28. - Re-implement logic to continue next layer without returning to origin corner (temporarily removed for simplicity)
  29. - Add/overhaul argument parsing logic
  30. - Add ability to refuel via generator upgrade if present
  31. - Add more compatibility checks for various components and upgrades
  32. - Improve usage message formatting or font size to better fit screen
  33.  
  34. ------
  35. Usage
  36. ------
  37. - Robot is placed in one corner of the dig
  38. - The robot's starting position is y=0, x=0, z=0, f=0
  39. - The starting position is included in volume of the dig
  40. - From there, the robot will dig:
  41. (<depth> - 1) blocks in the +y direction (forward)
  42. (<width> - 1) blocks in the +x direction (right)
  43. (<height> - 1) blocks in the +z direction (down)
  44. y=<depth> +---------------+
  45. ^ | 0 |
  46. | | |
  47. | | ^ |
  48. | | 3 < f > 1 |
  49. | | v |
  50. | | |
  51. | ^ 2 |
  52. y=0 ER---------------+
  53. C
  54.  
  55. x=0 ----------> x=<width>
  56. Legend:
  57. R = Robot starting position
  58. C = Chest behind robot will be used to dump inventory
  59. E = Suggested location for energy source (charger block). Could also be above the robot.
  60. ]]
  61.  
  62. --===========
  63. -- Variables
  64. --===========
  65.  
  66. -----------------------------------------
  67. -- Include libraries/wrappers/components
  68. -----------------------------------------
  69. local component = require("component")
  70. local computer = require("computer")
  71. local robot = require("robot")
  72. local shell = require("shell")
  73. local sides = require("sides")
  74. local r = component.robot
  75.  
  76. local args, options = shell.parse(...)
  77.  
  78. -----------------------
  79. -- Energy calculations
  80. -----------------------
  81.  
  82. -- Max energy the robot can hold
  83. local maxEnergy = computer.maxEnergy()
  84.  
  85. -- These are set in the OpenComputers config
  86. -- May we could pull them programmatically somehow?
  87. local energyUsedPerMove = 15
  88. local energyUsedPerBlockBroken = 2.5
  89. --local energyUsedPerTurn = 2.5
  90. --local energyUserPerTick = 0.25
  91.  
  92. -- avgBlocksBrokenPerMove and minEnergyReserveBuffer are for used for estimating how much energy to keep in reserve for making sure we make it home
  93. -- Raise to be more conservative if we find ourselves running out of energy before making it home
  94. -- Lower to minimize unneccesary trips home
  95.  
  96. -- For estimating how much energy will be spent on breaking blocks on the way home
  97. local avgBlocksBrokenPerMove = 0.2
  98.  
  99. -- How close (in percent of maxEnergy) we want to approach to the minimum energy level to keep
  100. -- (i.e. maxEnergyNeededToReturnHome) before returning home
  101. local minEnergyReserveBuffer = 0.05
  102.  
  103. -- Calculated based on max distance to home, energyUsedPerMove, avgBlocksBrokenPerMove, and energyUsedPerBlockBroken
  104. local maxEnergyNeededToReturnHome
  105.  
  106. -- Calculated based on maxEnergyNeededToReturnHome and minEnergyReserveBuffer
  107. local minEnergyReserve
  108.  
  109. -------------------------------
  110. -- Position/direction tracking
  111. -------------------------------
  112.  
  113. -- y = forward and back (depth)
  114. -- x = left and right (width)
  115. -- z = up and down (height)
  116. -- f = direction we're facing compared to original direction
  117. -- 0 = forward (positive y)
  118. -- 1 = right (positive x)
  119. -- 2 = back (negative y)
  120. -- 3 = left (negative x)
  121. local y, x, z, f = 0, 0, 0, 0
  122. local returningHome = false -- avoid recursing into returnHome()
  123. local delta = {
  124. [0] = function() y = y + 1 end,
  125. [1] = function() x = x + 1 end,
  126. [2] = function() y = y - 1 end,
  127. [3] = function() x = x - 1 end
  128. }
  129.  
  130. -----------------------
  131. -- Dimension arguments
  132. -----------------------
  133. local size, depth, width, height
  134. local jumpTo = 0
  135. local maxHeight = 256 -- Max height of world, for use with options that dig maximum height holes (down to bedrock)
  136.  
  137. --===========
  138. -- Functions
  139. --===========
  140.  
  141. -- Print usage
  142. local function usage()
  143. io.write("Usage:\n")
  144. io.write(" dig [-s] <depth> <width> <height>\n")
  145. io.write(" dig -j <depth> <width> <height> <jump_to>\n")
  146. io.write(" dig -C <cubic_size>\n")
  147. io.write(" dig -S <square_size>\n")
  148. io.write("Arguments:\n")
  149. io.write(" <depth>: The horizontal forward distance to dig (in the direction robot is facing when placed).\n")
  150. io.write(" <width>: The horizontal rightward distance to dig (as seen from above, the robot starts off in the bottom of the leftmost \"column\").\n")
  151. io.write(" <height>: The vertical (x) distance to dig downward (most energy efficient if divisible by 3).\n")
  152. io.write(" <cubic_size>: If option -C is given, this value is used for <depth>, <width>, and <height>.\n")
  153. io.write(" Requires a single argument for <cubic_size>. Not compatible with -S or -j.\n")
  154. io.write(" <square_size>: If option -S is given, this value is used for <depth> and <width>. <height> is set to max.\n")
  155. io.write(" Requires a single argument for <square_size>. Not compatible with -C or -j.\n")
  156. io.write(" <jump_to>: If option -j is given, the robot will move to this layer and start digging from there downward.\n")
  157. io.write(" e.g. if <jump_to> is 5 it will start digging layers 5, 6, and 7 (unless <height> is less than 7).\n")
  158. io.write(" -j requires all 4 dimensions to be given. Not compatible with -C or -S.\n")
  159. io.write("Options:\n")
  160. io.write(" -s: shutdown when done\n")
  161. io.write(" -C: digs a cube of size <cubic_size>\n")
  162. end
  163.  
  164. -- Turn right and track the direction we're facing
  165. local function turnRight()
  166. robot.turnRight()
  167. f = (f + 1) % 4
  168. end
  169.  
  170. -- Turn left and track the direction we're facing
  171. local function turnLeft()
  172. robot.turnLeft()
  173. f = (f - 1) % 4
  174. end
  175.  
  176. local function turnTowards(side)
  177. if f == side - 1 then
  178. turnRight()
  179. else
  180. while f ~= side do
  181. turnLeft()
  182. end
  183. end
  184. end
  185.  
  186. local function turn(i)
  187. if i % 2 == 1 then
  188. turnRight()
  189. else
  190. turnLeft()
  191. end
  192. end
  193.  
  194. local function clearBlock(side, cannotRetry)
  195. while r.suck(side) do
  196. statusCheck()
  197. end
  198. local result, reason = r.swing(side)
  199. if result then
  200. statusCheck()
  201. else
  202. local _, what = r.detect(side)
  203. if cannotRetry then
  204. if what == "air" then
  205. -- io.stderr:write("Error: Could not clear air block from relative position y=" .. y .. ", x=" .. x .. ", z=" .. z .. ", f=" .. f .. ". Are we at the flight height limit?\n")
  206. io.stderr:write("Error: Could not clear air block at " .. sides[side] .. " side. Are we at the flight height limit?\n")
  207. elseif what == "entity" then
  208. io.stderr:write("Error: Could not clear entity at side: " .. side .. ".\n")
  209. else
  210. io.stderr:write("Error: Could not clear block (" .. what .. ") from side: " .. side .. ".\n")
  211. end
  212. return false
  213. end
  214. end
  215. return true
  216. end
  217.  
  218. local function tryMove(side)
  219. side = side or sides.forward
  220. local tries = 5
  221. while not r.move(side) do
  222. tries = tries - 1
  223. if not clearBlock(side, tries < 1) then
  224. return false
  225. end
  226. end
  227. if side == sides.down then
  228. z = z + 1
  229. elseif side == sides.up then
  230. z = z - 1
  231. else
  232. delta[f]()
  233. end
  234. return true
  235. end
  236.  
  237. local function moveTo(ty, tx, tz, backwards)
  238. local axes = {
  239. function()
  240. local direction
  241. if z > tz then
  242. direction = sides.up
  243. elseif z < tz then
  244. direction = sides.down
  245. end
  246. while z ~= tz do
  247. if not tryMove(direction) then
  248. io.stderr:write("Error: Failed to move " .. sides[direction] .. " during moveTo.\n")
  249. return false
  250. end
  251. end
  252. return true
  253. end,
  254. function()
  255. if x > tx then
  256. turnTowards(3)
  257. --repeat tryMove() until x == tx
  258. elseif x < tx then
  259. turnTowards(1)
  260. --repeat tryMove() until x == tx
  261. end
  262. while x ~= tx do
  263. if not tryMove() then
  264. io.stderr:write("Error: Failed to move in x direction during moveTo.\n")
  265. return false
  266. end
  267. end
  268. return true
  269. end,
  270. function()
  271. if y > ty then
  272. turnTowards(2)
  273. --repeat tryMove() until y == ty
  274. elseif y < ty then
  275. turnTowards(0)
  276. --repeat tryMove() until y == ty
  277. end
  278. while y ~= ty do
  279. if not tryMove() then
  280. io.stderr:write("Error: Failed to move in y direction during moveTo.\n")
  281. return false
  282. end
  283. end
  284. return true
  285. end
  286. }
  287. if backwards then
  288. for axis = 3, 1, -1 do
  289. if not axes[axis]() then
  290. return false
  291. end
  292. end
  293. else
  294. for axis = 1, 3 do
  295. if not axes[axis]() then
  296. return false
  297. end
  298. end
  299. end
  300. return true
  301. end
  302.  
  303. local function isEnergyFull()
  304. local energy = computer.energy()
  305. local leeway = 20
  306. if energy < (maxEnergy - leeway) then
  307. return false
  308. end
  309. return true
  310. end
  311.  
  312. local function dropAll()
  313. io.write("Dropping inventory...")
  314. for slot = 1, 16 do
  315. if robot.count(slot) > 0 then
  316. robot.select(slot)
  317. local wait = 1
  318. repeat
  319. if not robot.drop() then
  320. os.sleep(wait)
  321. wait = math.min(10, wait + 1)
  322. end
  323. until robot.count(slot) == 0
  324. end
  325. end
  326. robot.select(1)
  327. io.write(" done.\n")
  328. end
  329.  
  330. local function returnHome()
  331. returningHome = true
  332. io.write("Returning home...\n")
  333.  
  334. if not moveTo(0, 0, 0) then
  335. io.write("Error: Failed returning home.\n")
  336. return false
  337. else
  338. io.write("Finished returning home.\n")
  339. end
  340.  
  341. -- Drop off inventory
  342. turnTowards(2)
  343. dropAll()
  344. turnTowards(0)
  345.  
  346. -- Wait for energy to charge
  347. io.write("Waiting to charge...")
  348. while not isEnergyFull() do
  349. os.sleep(1)
  350. end
  351. io.write(" done.\n")
  352.  
  353. returningHome = false
  354. return true
  355. end
  356.  
  357. function homeAndBack()
  358. -- Save current position
  359. local oy, ox, oz, of = y, x, z, f
  360.  
  361. -- Return Home
  362. if not returnHome() then
  363. return false
  364. end
  365.  
  366. -- Return to mining at saved position
  367. io.write("Returning to y=" .. oy .. ", x=" .. ox .. ", z=" .. oz .. ", f=" .. of .. "...\n")
  368. if not moveTo(oy, ox, oz, true) then
  369. io.stderr:write("Error: Failed to return to position.\n")
  370. return false
  371. else
  372. turnTowards(of)
  373. io.write("Returned to position.\n")
  374. end
  375. return true
  376. end
  377.  
  378. function needDrop()
  379.  
  380. -- Count empty slots
  381. local emptySlots = 0
  382. for slot = 1, 16 do
  383. if robot.count(slot) == 0 then
  384. emptySlots = emptySlots + 1
  385. end
  386. end
  387.  
  388. if (emptySlots < 1) then
  389. io.write("Drop needed, no free inventory slots.\n")
  390. return true
  391. end
  392.  
  393. return false
  394. end
  395.  
  396. function needEnergy()
  397.  
  398. -- Get remaining energy
  399. local energy = math.floor(computer.energy())
  400.  
  401. -- If remaining energy is at or below the minimum amount of energy we want to have in reserve
  402. if(energy <= minEnergyReserve) then
  403. io.write("Energy needed. Current: " .. energy.. "/" .. maxEnergy .. ", needed: " .. maxEnergyNeededToReturnHome .. ", preferred reserve: " .. minEnergyReserve .. ".\n")
  404. return true
  405. end
  406. return false
  407. end
  408.  
  409. function statusCheck()
  410. if not returningHome then
  411. if needEnergy() or needDrop() then
  412. homeAndBack()
  413. end
  414. end
  415. end
  416.  
  417. local function calculateEnergyNeeds()
  418.  
  419. -- Very approximately, we shall assume that every block moved requires
  420. -- using enough energy to:
  421. -- move one block and
  422. -- break 1/Xth of a block on average.
  423. -- This should give us a reasonably conservative estimate for energy required per block move.
  424.  
  425. local maxDistToReturnHome = width + depth + height
  426. io.write("Max distance to home calculated as: " .. maxDistToReturnHome .. ".\n")
  427.  
  428. -- energyUsedToMove should conservatively be the actual maximum,
  429. -- to account for when the robot is at the end of the dig
  430. local energyUsedToMove = energyUsedPerMove * maxDistToReturnHome
  431.  
  432. -- However energyUsedToBreakBlocks can be a percentage, because usually, you're not
  433. -- breaking many blocks on the return trip (unless you use option -j to skip downward)
  434. -- TODO: add logic to modify avgBlocksBrokenPerMove (or energyUsedToBreakBlocks) if -j option was specified
  435. -- to account for more blocks being broken when returning home
  436. local energyUsedToBreakBlocks = energyUsedPerBlockBroken * maxDistToReturnHome
  437. energyUsedToBreakBlocks = energyUsedToBreakBlocks * avgBlocksBrokenPerMove
  438.  
  439. maxEnergyNeededToReturnHome = energyUsedToMove + energyUsedToBreakBlocks
  440. io.write("Max energy needed to return home calculated as: " .. maxEnergyNeededToReturnHome .. "/" .. maxEnergy .. ".\n")
  441.  
  442. minEnergyReserve = (maxEnergy * minEnergyReserveBuffer) + maxEnergyNeededToReturnHome
  443. io.write("Min energy reserve to keep calculated as: " .. minEnergyReserve .. "/" .. maxEnergy .. ".\n")
  444. end
  445.  
  446. -- Advance one space
  447. local function step(thickness)
  448.  
  449. if (thickness > 1) then
  450. -- Clear block below
  451. if not clearBlock(sides.down) then
  452. io.stderr:write("Error: Could not complete step (clearing below).\n")
  453. return false
  454. end
  455. end
  456.  
  457. -- Clear block in front and move forward
  458. if not tryMove() then
  459. io.stderr:write("Error: Could not complete step (moving forward).\n")
  460. return false
  461. end
  462.  
  463. if(thickness > 2) then
  464. -- Clear block above
  465. if not clearBlock(sides.up) then
  466. io.stderr:write("Error: Could not complete step (clearing above).\n")
  467. return false
  468. end
  469. end
  470.  
  471. return true
  472. end
  473.  
  474. local function digLayer(thickness)
  475.  
  476. thickness = thickness or 3
  477.  
  478. -- For each "column"
  479. for col = 1, width do
  480.  
  481. -- For each "row"
  482. for row = 1, depth - 1 do
  483. -- Try moving forward
  484. if not step(thickness) then
  485. return false
  486. end
  487. end
  488. -- At end of column
  489.  
  490. -- If this is not the last column, move to the next column
  491. if col < width then
  492. -- If this is an odd column, turn right, move forward, turn right
  493. if((col % 2) == 1) then
  494. turnRight()
  495. if not step(thickness) then
  496. return false
  497. end
  498. turnRight()
  499. -- If even column, turn left, move forward, turn left
  500. else
  501. turnLeft()
  502. if not step(thickness) then
  503. return false
  504. end
  505. turnLeft()
  506. end
  507.  
  508. -- If this IS the last column, the loop should exit
  509. end
  510. end
  511.  
  512. -- Return to starting position in that layer
  513.  
  514. -- If width is odd, we'll be at the far corner from 0,0 and facing forward
  515. if((width % 2) == 1) then
  516. -- Move to "bottom right" corner
  517. turnRight()
  518. turnRight()
  519. for i = 1, (depth - 1) do
  520. if not step(thickness) then
  521. return false
  522. end
  523. end
  524. end
  525.  
  526. -- If width is even we'll already be at the "bottom right" corner, facing backwards
  527. turnRight()
  528. for i = 1, (width - 1) do
  529. if not step(thickness) then
  530. return false
  531. end
  532. end
  533. turnRight()
  534.  
  535. return true
  536. end
  537.  
  538. local function digLayers()
  539.  
  540. -- Dig layers
  541. local layersLeft = height
  542. local layersDug = 0
  543. local justJumped = false
  544. local currentLayer = 0
  545.  
  546. -- Jump to specified layer
  547. if options.j then
  548. if not moveTo(0, 0, (jumpTo - 1)) then -- (jumpTo - 1) because the layers are 0-indexed
  549. io.stderr:write("Error: Failed jumping to specified layer.\n")
  550. return false
  551. end
  552. layersDug = jumpTo - 1
  553. layersLeft = height - layersDug
  554. justJumped = true
  555. end
  556.  
  557. while (layersLeft > 0) do
  558.  
  559. currentLayer = layersDug + 1
  560.  
  561. -- Move into position for next layer
  562.  
  563. -- If there's only one layer left
  564. if (layersLeft == 1) then
  565.  
  566. -- If this is the first and only layer, or the first layer jumped to via option -j
  567. if((height < 2) or (justJumped)) then
  568. justJumped = false
  569. -- stay in starting position
  570. --io.write("This is the only layer, staying on this layer.\n")
  571. -- If this is not the only layer
  572. else
  573. -- move down into the final layer
  574. --io.write("Only one layer left, moving to last layer.\n")
  575. if not tryMove(sides.down) then
  576. io.stderr:write("Error: Failed to move into position for new layer (1).\n")
  577. return false
  578. end
  579. end
  580.  
  581. -- Dig a 1-tall layer at current height, ignoring layers above and below
  582. io.write("Digging 1-tall layer (#" .. currentLayer .. ")...\n")
  583. if not digLayer(1) then
  584. io.stderr:write("Error: Could not complete 1-tall layer (#" .. currentLayer .. ").\n")
  585. return false
  586. end
  587. layersDug = layersDug + 1
  588.  
  589. -- If there's only two layers left
  590. elseif (layersLeft == 2) then
  591.  
  592. -- If these are the first and only two layers, or first two layers jumped to via option -j
  593. if((height < 3) or (justJumped)) then
  594. justJumped = false
  595. -- stay in starting position
  596. --io.write("These are the only two layers, staying on this layer.\n")
  597.  
  598. -- If these are not the only two layers
  599. else
  600. -- move down into the first of the two final layers
  601. --io.write("Only two layers left, moving to the first of the two layers.\n")
  602. if not tryMove(sides.down) then
  603. io.stderr:write("Error: Failed to move into position for new layer (2).\n")
  604. return false
  605. end
  606. end
  607.  
  608. -- Dig a 2-tall layer at current height, ignoring the layer above
  609. io.write("Digging 2-tall layer (#" .. currentLayer .. "-" .. (currentLayer + 1) .. ")...\n")
  610. if not digLayer(2) then
  611. io.stderr:write("Error: Could not complete 2-tall layer (#" .. currentLayer .. "-" .. (currentLayer + 1) .. ")...\n")
  612. return false
  613. end
  614. layersDug = layersDug + 2
  615.  
  616. -- If there's 3 or more layers left
  617. else
  618. -- If these are the first 3 layers, or the first 3 layers jumped to via option -j
  619. if ((layersDug < 1) or (justJumped)) then
  620. justJumped = false
  621.  
  622. -- move down into the middle layer
  623. --io.write("These are the first three layers, moving to the middle layer.\n")
  624. if not tryMove(sides.down) then
  625. io.stderr:write("Error: Failed to move into position for new layer (3).\n")
  626. return false
  627. end
  628.  
  629. -- If these are not the first 3 layers
  630. else
  631.  
  632. -- move down further into the actual middle layer
  633. --io.write("Three or more layers left, moving to the middle layer.\n")
  634. for i = 1, 3 do
  635. if not tryMove(sides.down) then
  636. io.stderr:write("Error: Failed to move into position for new layer (4).\n")
  637. return false
  638. end
  639. end
  640. end
  641.  
  642. -- Dig a 3-tall layer at current height, including the layers above and below
  643. io.write("Digging 3-tall layer (#" .. currentLayer .. "-" .. (currentLayer + 2) .. ")...\n")
  644. if not digLayer() then
  645. io.stderr:write("Error: Could not complete 3-tall layer (#" .. currentLayer .. "-" .. (currentLayer + 2) .. ")...\n")
  646. return false
  647. end
  648. layersDug = layersDug + 3
  649. end
  650.  
  651. layersLeft = height - layersDug
  652. io.write("Done digging layer(s). " .. layersDug .. " layers dug total. " .. layersLeft .. "/" .. height .. " layers left.\n")
  653. end
  654. return true
  655. end
  656.  
  657. -- Parse arguments and options
  658. -- Print usage and exit if invalid
  659. local function parseArgs()
  660. if #args < 1 then
  661. return false
  662. end
  663.  
  664. -- TODO: add logic for invalid argument combinations
  665.  
  666. if options.C then
  667. size = tonumber(args[1])
  668. if not size then
  669. io.stderr:write("Error: Invalid value for <cubic_size>.\n")
  670. return false
  671. end
  672. depth = size
  673. width= size
  674. height = size
  675. elseif options.S then
  676. size = tonumber(args[1])
  677. if not size then
  678. io.stderr:write("Error: Invalid value for <square_size>.\n")
  679. return false
  680. end
  681. depth = size
  682. width= size
  683. height = maxHeight
  684. else
  685. depth = tonumber(args[1])
  686. if not depth then
  687. io.stderr:write("Error: Invalid value for <depth>.\n")
  688. return false
  689. end
  690. width = tonumber(args[2])
  691. if not width then
  692. io.stderr:write("Error: Invalid value for <width>.\n")
  693. return false
  694. end
  695. height = tonumber(args[3])
  696. if not height then
  697. io.write("Invalid or null value for <height>, setting to max height (" .. maxHeight .. ").\n")
  698. height = maxHeight
  699. else
  700. if options.j then
  701. jumpTo = tonumber(args[4])
  702. if not jumpTo then
  703. io.stderr:write("Error: Invalid value for <jump_to>.\n")
  704. return false
  705. end
  706. end
  707. end
  708.  
  709. end
  710.  
  711. local confirm = "Digging hole of depth=" .. depth .. ", width= " .. width .. ", height=" .. height .. ".\n"
  712. if (options.j) then
  713. confirm = confirm .. " Starting at layer " .. jumpTo .. " (" .. (jumpTo - 1) .. " layers skipped).\n"
  714. end
  715.  
  716. io.write(confirm .. "\n")
  717. return true
  718. end
  719.  
  720. local function checkCompat()
  721.  
  722. if not component.isAvailable("robot") then
  723. io.stderr:write("Error: Can only run on robots.\n")
  724. return false
  725. end
  726.  
  727. -- TODO: Check for generator upgrade
  728.  
  729. return true
  730. end
  731.  
  732. --==============
  733. -- Begin script
  734. --==============
  735.  
  736. -- Check compatibility
  737. if not checkCompat() then
  738. io.stderr:write("Error: Compatibility checks failed.\n")
  739. return
  740. end
  741.  
  742. -- Parse args
  743. if not parseArgs() then
  744. io.stderr:write("Error: Failed to parse arguments.\n")
  745. usage()
  746. return
  747. end
  748.  
  749. calculateEnergyNeeds()
  750.  
  751. -- Dig layers
  752. if not digLayers() then
  753. io.stderr:write("Error: Failed to dig all layers.\n")
  754. end
  755.  
  756. -- Return home
  757. returnHome()
  758.  
  759. -- Shutdown if specified
  760. if options.s then
  761. io.write("Shutting down...\n")
  762. computer.shutdown()
  763. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement