Advertisement
Ferruccioboss

Minecraft>Dome

May 30th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 61.44 KB | None | 0 0
  1. -- Variable Setup
  2. -- Command Line input Table
  3. local argTable = {...}
  4.  
  5. -- Flag Variables: These are conditions for different features (all flags are named foo_bar, all other variables are named fooBar)
  6. local cmd_line = false
  7. local cmd_line_resume = false
  8. local cmd_line_cost_only = false
  9. local chain_next_shape = false -- This tells goHome() where to end, if true it goes to (0, 0, positionZ) if false it goes to (-1, -1, 0)
  10. local special_chain = false -- For certain shapes that finish where the next chained shape should start, goHome() will  only turn to face 0 if true
  11. local cost_only = false
  12. local sim_mode = false
  13. local resupply = false
  14. local enderchest_refilling = false
  15. local can_use_gps = false
  16. local return_to_home = false -- whether the turtle shall return to start after build
  17.  
  18. -- Record Keeping Variables: These are for recoding the blocks and fuel used
  19. local blocks = 0
  20. local fuel = 0
  21.  
  22. -- Position Tracking Variables: These are for keeping track of the turtle's position
  23. local positionX = 0
  24. local positionY = 0
  25. local positionZ = 0
  26. local facing = 0
  27. local gpsPositionX = 0
  28. local gpsPositionY = 0
  29. local gpsPositionZ = 0
  30. local gpsFacing = 0
  31.  
  32. -- General Variables: Other variables that don't fit in the other categories
  33. local choice = ""
  34.  
  35. -- Progress Table: These variables are the tables that the turtle's progress is tracked in
  36. local tempProgTable = {}
  37. local progTable = {} --This is the LOCAL table!  used for local stuff only, and is ONLY EVER WRITTEN when sim_mode is FALSE
  38. local progFileName = "ShapesProgressFile"
  39.  
  40. -- Utility functions
  41.  
  42. function writeOut(...) -- ... lets writeOut() pass any arguments to print(). so writeOut(1,2,3) is the same as print(1,2,3). previously writeOut(1,2,3) would have been the same as print(1)
  43.     for i, v in ipairs(arg) do
  44.         print(v)
  45.     end
  46. end
  47.  
  48. function getInput(inputType, message, option1, option2)
  49.     local input = ""
  50.     if inputType == "string" then
  51.         writeOut(message.. "(" ..option1 .. " or "..option2..")" )
  52.         while true do
  53.             input = io.read()
  54.             input = string.lower(input)
  55.             if input ~= option1 and input ~= option2 then
  56.                 writeOut("You didn't enter a valid option. Please try again.")
  57.             else
  58.                 return input
  59.             end
  60.         end
  61.     end
  62.     if inputType == "int" then
  63.         writeOut(message)
  64.         while true do
  65.             input = io.read()
  66.             if tonumber(input) ~= nil then
  67.                 return tonumber(input)
  68.             else
  69.                 writeOut("Need a number. Please try again")
  70.             end
  71.         end
  72.     end
  73. end
  74.  
  75. function wrapModules() -- checks for and wraps turtle modules
  76.     local test = 0
  77.     if peripheral.getType("left" )== "resupply" then
  78.         resupplymodule=peripheral.wrap("left")
  79.         resupply = true
  80.     elseif peripheral.getType("right") == "resupply" then
  81.         resupplymodule=peripheral.wrap("right")
  82.         resupply = true
  83.     end
  84.     if peripheral.getType("left") == "modem" then
  85.         modem=peripheral.wrap("left")
  86.         test, _, _ = gps.locate(1)
  87.         if test ~= nil then
  88.             can_use_gps = true
  89.         end
  90.     elseif peripheral.getType("right") == "modem" then
  91.         modem=peripheral.wrap("right")
  92.         test, _, _ = gps.locate(1)
  93.         if test ~= nil then
  94.             can_use_gps = true
  95.         end
  96.     end
  97.     if resupply then
  98.         return "resupply"
  99.     end
  100. end
  101.  
  102. function linkToRSStation() -- Links to resupply station
  103.     if resupplymodule.link() then
  104.         return true
  105.     else
  106.         writeOut("Please put Resupply Station to the left of the turtle and press Enter to continue")
  107.         io.read()
  108.         linkToRSStation()
  109.     end
  110. end
  111.  
  112. function compareResources()
  113.     if (turtle.compareTo(1) == false) then
  114.         turtle.drop()
  115.     end
  116. end
  117.  
  118. function firstFullSlot()
  119.     for i = 1, 16 do
  120.         if (turtle.getItemCount(i) > 1) then
  121.             return i
  122.         end
  123.     end
  124. end
  125.  
  126. function turtleEmpty()
  127.     for i = 1, 16 do
  128.         if (turtle.getItemCount(i) > 1) then
  129.             return false
  130.         end
  131.     end
  132.     return true
  133. end
  134.  
  135. function checkResources()
  136.     if resupply then
  137.         if turtle.getItemCount(activeSlot) <= 1 then
  138.             while not(resupplymodule.resupply(1)) do
  139.                 os.sleep(0.5)
  140.             end
  141.         end
  142.     elseif enderchest_refilling then
  143.         compareResources()
  144.         while (turtle.getItemCount(activeSlot) <= 1) do
  145.             if (activeSlot == 15) and (turtle.getItemCount(activeSlot)<=1) then
  146.                 turtle.select(16)
  147.                 turtle.digUp()
  148.                 for i = 1, 15 do
  149.                     turtle.select(i)
  150.                     turtle.drop()
  151.                 end
  152.                 turtle.select(16)
  153.                 turtle.placeUp()
  154.                 turtle.select(1)               
  155.                 for i = 1, 15 do
  156.                     turtle.suckUp()
  157.                 end
  158.                 turtle.select(16)
  159.                 turtle.digUp()
  160.                 activeSlot = 1
  161.                 turtle.select(activeSlot)
  162.             else
  163.                 activeSlot = activeSlot + 1
  164.                 -- writeOut("Turtle slot empty, trying slot "..activeSlot)
  165.                 turtle.select(activeSlot)
  166.             end
  167.             compareResources()
  168.             os.sleep(0.2)
  169.         end
  170.     else
  171.         compareResources()
  172.         while (turtle.getItemCount(activeSlot) <= 1) do
  173.             if turtleEmpty() then
  174.                 writeOut("Turtle is empty, please put building block in slots and press enter to continue")
  175.                 io.read()
  176.                 activeSlot = 1
  177.                 turtle.select(activeSlot)
  178.             else
  179.                 activeSlot = firstFullSlot()
  180.                 turtle.select(activeSlot)
  181.             end
  182.             compareResources()
  183.         end
  184.     end
  185. end
  186.  
  187. function checkFuel()
  188.     if (not(tonumber(turtle.getFuelLevel()) == nil)) then
  189.         while turtle.getFuelLevel() < 50 do
  190.             writeOut("Turtle almost out of fuel, pausing. Please drop fuel in inventory. And press enter.")
  191.             io.read()
  192.             turtle.refuel()
  193.         end
  194.     end
  195. end
  196.  
  197. function placeBlock()
  198.     blocks = blocks + 1
  199.     simulationCheck()
  200.     if cost_only then
  201.         return
  202.     end
  203.     if turtle.detectDown() and not turtle.compareDown() then
  204.         turtle.digDown()
  205.     end
  206.     checkResources()
  207.     turtle.placeDown()
  208.     progressUpdate()
  209. end
  210.  
  211. function round(toRound, decimalPlace) -- Needed for Polygons
  212.     local mult = 10 ^ (decimalPlace or 0)
  213.     local sign = toRound / math.abs(toRound)
  214.     return sign * math.floor(((math.abs(toRound) * mult) + 0.5)) / mult
  215. end
  216.  
  217. -- Navigation functions
  218. -- Allow the turtle to move while tracking its position
  219. -- This allows us to just give a destination point and have it go there
  220.  
  221. function turnRightTrack()
  222.     simulationCheck()
  223.     facing = facing + 1
  224.     if facing >= 4 then
  225.         facing = 0
  226.     end
  227.     progressUpdate()
  228.     if cost_only then
  229.         return
  230.     end
  231.     turtle.turnRight()
  232. end
  233.  
  234. function turnLeftTrack()
  235.     simulationCheck()
  236.     facing = facing - 1
  237.     if facing < 0 then
  238.         facing = 3
  239.     end
  240.     progressUpdate()
  241.     if cost_only then
  242.         return
  243.     end
  244.     turtle.turnLeft()
  245. end
  246.  
  247. function turnAroundTrack()
  248.     turnLeftTrack()
  249.     turnLeftTrack()
  250. end
  251.  
  252. function turnToFace(direction)
  253.     if (direction < 0) then
  254.         return false
  255.     end
  256.     direction = direction % 4
  257.     while facing ~= direction do
  258.         turnRightTrack()
  259.     end
  260.     return true
  261. end
  262.  
  263. function safeForward()
  264.     simulationCheck()
  265.     if facing == 0 then
  266.         positionY = positionY + 1
  267.     elseif facing == 1 then
  268.         positionX = positionX + 1
  269.     elseif facing == 2 then
  270.         positionY = positionY - 1
  271.     elseif facing == 3 then
  272.         positionX = positionX - 1
  273.     end
  274.     fuel = fuel + 1
  275.     progressUpdate()
  276.     if cost_only then
  277.         return
  278.     end
  279.     checkFuel()
  280.     local success = false
  281.     local tries = 0
  282.     while not success do
  283.         success = turtle.forward()
  284.         if not success then
  285.             while (not success) and tries < 6 do
  286.                 tries = tries + 1
  287.                 turtle.dig()
  288.                 success = turtle.forward()
  289.                 sleep(0.3)
  290.             end
  291.             if not success then
  292.                 writeOut("Blocked attempting to move forward.")
  293.                 writeOut("Please clear and press enter to continue.")
  294.                 io.read()
  295.             end
  296.         end
  297.     end
  298. end
  299.  
  300. function safeBack()
  301.     simulationCheck()
  302.     if facing == 0 then
  303.         positionY = positionY - 1
  304.     elseif facing == 1 then
  305.         positionX = positionX - 1
  306.     elseif facing == 2 then
  307.         positionY = positionY + 1
  308.     elseif facing == 3 then
  309.         positionX = positionX + 1
  310.     end
  311.     fuel = fuel + 1
  312.     progressUpdate()
  313.     if cost_only then
  314.         return
  315.     end
  316.     checkFuel()
  317.     local success = false
  318.     local tries = 0
  319.     while not success do
  320.         success = turtle.back()
  321.         if not success then
  322.             turnAroundTrack()
  323.             while turtle.detect() and tries < 6 do
  324.                 tries = tries + 1
  325.                 if turtle.dig() then
  326.                     break
  327.                 end
  328.                 sleep(0.3)
  329.             end
  330.             turnAroundTrack()
  331.             success = turtle.back()
  332.             if not success then
  333.                 writeOut("Blocked attempting to move back.")
  334.                 writeOut("Please clear and press enter to continue.")
  335.                 io.read()
  336.             end
  337.         end
  338.     end
  339. end
  340.  
  341. function safeUp()
  342.     simulationCheck()
  343.     positionZ = positionZ + 1
  344.     fuel = fuel + 1
  345.     progressUpdate()
  346.     if cost_only then
  347.         return
  348.     end
  349.     checkFuel()
  350.     local success = false
  351.     while not success do
  352.         success = turtle.up()
  353.         if not success then
  354.             while turtle.detectUp() do
  355.                 if not turtle.digUp() then
  356.                     writeOut("Blocked attempting to move up.")
  357.                     writeOut("Please clear and press enter to continue.")
  358.                     io.read()
  359.                 end
  360.             end
  361.         end
  362.     end
  363. end
  364.  
  365. function safeDown()
  366.     simulationCheck()
  367.     positionZ = positionZ - 1
  368.     fuel = fuel + 1
  369.     progressUpdate()
  370.     if cost_only then
  371.         return
  372.     end
  373.     checkFuel()
  374.     local success = false
  375.     while not success do
  376.         success = turtle.down()
  377.         if not success then
  378.             while turtle.detectDown() do
  379.                 if not turtle.digDown() then
  380.                     writeOut("Blocked attempting to move down.")
  381.                     writeOut("Please clear and press enter to continue.")
  382.                     io.read()
  383.                 end
  384.             end
  385.         end
  386.     end
  387. end
  388.  
  389. function moveY(targetY)
  390.     if targetY == positionY then
  391.         return
  392.     end
  393.     if (facing ~= 0 and facing ~= 2) then -- Check axis
  394.         turnRightTrack()
  395.     end
  396.     while targetY > positionY do
  397.         if facing == 0 then
  398.             safeForward()
  399.         else
  400.             safeBack()
  401.         end
  402.     end
  403.     while targetY < positionY do
  404.         if facing == 2 then
  405.             safeForward()
  406.         else
  407.             safeBack()
  408.         end
  409.     end
  410. end
  411.  
  412. function moveX(targetX)
  413.     if targetX == positionX then
  414.         return
  415.     end
  416.     if (facing ~= 1 and facing ~= 3) then -- Check axis
  417.         turnRightTrack()
  418.     end
  419.     while targetX > positionX do
  420.         if facing == 1 then
  421.             safeForward()
  422.         else
  423.             safeBack()
  424.         end
  425.     end
  426.     while targetX < positionX do
  427.         if facing == 3 then
  428.             safeForward()
  429.         else
  430.             safeBack()
  431.         end
  432.     end
  433. end
  434.  
  435. function moveZ(targetZ)
  436.     if targetZ == positionZ then
  437.         return
  438.     end
  439.     while targetZ < positionZ do
  440.         safeDown()
  441.     end
  442.     while targetZ > positionZ do
  443.         safeUp()
  444.     end
  445. end
  446.  
  447. -- I *HIGHLY* suggest formatting all shape subroutines to use the format that dome() uses;  specifically, navigateTo(x,y,[z]) then placeBlock().  This should ensure proper "data recording" and also makes readability better
  448. function navigateTo(targetX, targetY, targetZ, move_z_first)
  449.     targetZ = targetZ or positionZ -- If targetZ isn't used in the function call, it defaults to its current z position, this should make it compatible with all previous implementations of navigateTo()
  450.     move_z_first = move_z_first or false -- Defaults to moving z last, if true is passed as 4th argument, it moves vertically first
  451.    
  452.     if move_z_first then
  453.         moveZ(targetZ)
  454.     end
  455.    
  456.     if facing == 0 or facing == 2 then -- Y axis
  457.         moveY(targetY)
  458.         moveX(targetX)
  459.     else
  460.         moveX(targetX)
  461.         moveY(targetY)
  462.     end
  463.    
  464.     if not move_z_first then
  465.         moveZ(targetZ)
  466.     end
  467. end
  468.  
  469. function goHome()
  470.     if chain_next_shape then
  471.         if not special_chain then
  472.             navigateTo(0, 0) -- So another program can chain multiple shapes together to create bigger structures
  473.         end
  474.     else
  475.         navigateTo(-1, -1, 0) -- So the user can collect the turtle when it is done, not 0,0,0 because some shapes use the 0,0 column
  476.     end
  477.     turnToFace(0)
  478. end
  479.  
  480. -- Shape Building functions
  481.  
  482. function drawLine(endX, endY, startX, startY)
  483.     startX = startX or positionX
  484.     startY = startY or positionY
  485.     deltaX = math.abs(endX - startX)
  486.     deltaY = math.abs(endY - startY)
  487.     errorVar = 0
  488.     if deltaX >= deltaY then
  489.         deltaErr = math.abs(deltaY/deltaX)
  490.         if startX < endX then
  491.             if startY < endY then
  492.                 counterY = startY
  493.                 for counterX = startX, endX do
  494.                     navigateTo(counterX, counterY)
  495.                     placeBlock()
  496.                     errorVar = errorVar + deltaErr
  497.                     if errorVar >= 0.5 then
  498.                         counterY = counterY + 1
  499.                         errorVar = errorVar - 1
  500.                     end
  501.                 end
  502.             else
  503.                 counterY = startY
  504.                 for counterX = startX, endX do
  505.                     navigateTo(counterX, counterY)
  506.                     placeBlock()
  507.                     errorVar = errorVar + deltaErr
  508.                     if errorVar >= 0.5 then
  509.                         counterY = counterY - 1
  510.                         errorVar = errorVar - 1
  511.                     end
  512.                 end
  513.             end
  514.         else
  515.             if startY < endY then
  516.                 counterY = startY
  517.                 for counterX = startX, endX, -1 do
  518.                     navigateTo(counterX, counterY)
  519.                     placeBlock()
  520.                     errorVar = errorVar + deltaErr
  521.                     if errorVar >= 0.5 then
  522.                         counterY = counterY + 1
  523.                         errorVar = errorVar - 1
  524.                     end
  525.                 end
  526.             else
  527.                 counterY = startY
  528.                 for counterX = startX, endX, -1 do
  529.                     navigateTo(counterX, counterY)
  530.                     placeBlock()
  531.                     errorVar = errorVar + deltaErr
  532.                     if errorVar >= 0.5 then
  533.                         counterY = counterY - 1
  534.                         errorVar = errorVar - 1
  535.                     end
  536.                 end
  537.             end
  538.         end
  539.     else
  540.         deltaErr = math.abs(deltaX/deltaY)
  541.         if startY < endY then
  542.             if startX < endX then
  543.                 counterX = startX
  544.                 for counterY = startY, endY do
  545.                     navigateTo(counterX, counterY)
  546.                     placeBlock()
  547.                     errorVar = errorVar + deltaErr
  548.                     if errorVar >= 0.5 then
  549.                         counterX = counterX + 1
  550.                         errorVar = errorVar - 1
  551.                     end
  552.                 end
  553.             else
  554.                 counterX = startX
  555.                 for counterY = startY, endY do
  556.                     navigateTo(counterX, counterY)
  557.                     placeBlock()
  558.                     errorVar = errorVar + deltaErr
  559.                     if errorVar >= 0.5 then
  560.                         counterX = counterX - 1
  561.                         errorVar = errorVar - 1
  562.                     end
  563.                 end
  564.             end
  565.         else
  566.             if startX < endX then
  567.                 counterX = startX
  568.                 for counterY = startY, endY, -1 do
  569.                     navigateTo(counterX, counterY)
  570.                     placeBlock()
  571.                     errorVar = errorVar + deltaErr
  572.                     if errorVar >= 0.5 then
  573.                         counterX = counterX + 1
  574.                         errorVar = errorVar - 1
  575.                     end
  576.                 end
  577.             else
  578.                 counterX = startX
  579.                 for counterY = startY, endY, -1 do
  580.                     navigateTo(counterX, counterY)
  581.                     placeBlock()
  582.                     errorVar = errorVar + deltaErr
  583.                     if errorVar >= 0.5 then
  584.                         counterX = counterX - 1
  585.                         errorVar = errorVar - 1
  586.                     end
  587.                 end
  588.             end
  589.         end
  590.     end
  591. end
  592.  
  593. function rectangle(width, depth, startX, startY)
  594.     startX = startX or positionX
  595.     startY = startY or positionY
  596.     endX = startX + width - 1
  597.     endY = startY + depth - 1
  598.     drawLine(startX, endY, startX, startY)
  599.     drawLine(endX, endY, startX, endY)
  600.     drawLine(endX, startY, endX, endY)
  601.     drawLine(startX, startY, endX, startY)
  602. end
  603.  
  604. function square(length, startX, startY)
  605.     startX = startX or positionX
  606.     startY = startY or positionY
  607.     rectangle(length, length, startX, startY)
  608. end
  609.  
  610. function wall(depth, height)
  611.     for i = 1, depth do
  612.         for j = 1, height do
  613.             placeBlock()
  614.             if j < height then
  615.                 navigateTo(positionX, positionY, positionZ + 1)
  616.             end
  617.         end
  618.         if (i ~= depth) then
  619.             navigateTo(positionX, positionY + 1, 0)
  620.         end
  621.     end
  622. end
  623.  
  624. function platform(width, depth, startX, startY)
  625.     startX = startX or positionX
  626.     startY = startY or positionY
  627.     endX = startX + width - 1
  628.     endY = startY + depth - 1
  629.     forward = true
  630.     for counterY = startY, endY do
  631.         if forward then
  632.             for counterX = startX, endX do
  633.                 navigateTo(counterX, counterY)
  634.                 placeBlock()
  635.             end
  636.         else
  637.             for counterX = endX, startX, -1 do
  638.                 navigateTo(counterX, counterY)
  639.                 placeBlock()
  640.             end
  641.         end
  642.         forward = not forward
  643.     end
  644. end
  645.  
  646. function cuboid(width, depth, height, hollow)
  647.     for i = 0, height - 1 do
  648.         navigateTo(0, 0, i)
  649.         if (hollow == "n") then
  650.             platform(width, depth, 0, 0)
  651.         else
  652.             rectangle(width, depth, 0, 0)
  653.         end
  654.     end
  655. end
  656.  
  657. function pyramid(length, hollow)
  658.     -- local height = math.ceil(length / 2) - 1
  659.     i = 0
  660.     while (length > 0) do
  661.         navigateTo(i, i, i)
  662.         if (hollow == "y") then
  663.             rectangle(length, length, i, i)
  664.         else
  665.             platform(length, length, i, i)
  666.         end
  667.         i = i + 1
  668.         length = length - 2
  669.     end
  670. end
  671.  
  672. function stair(width, height, startX, startY) -- Last two might be able to be used to make a basic home-like shape later?
  673.     startX = startX or positionX
  674.     startY = startY or positionY
  675.     endX = startX + width - 1
  676.     endY = startY + height - 1
  677.     forward = true
  678.     for counterY = startY, endY do
  679.         if forward then
  680.             for counterX = startX, endX do
  681.                 navigateTo(counterX, counterY)
  682.                 placeBlock()
  683.             end
  684.         else
  685.             for counterX = endX, startX, -1 do
  686.                 navigateTo(counterX, counterY)
  687.                 placeBlock()
  688.             end
  689.         end
  690.         if counterY ~= endY then
  691.             navigateTo(positionX, positionY, positionZ + 1)
  692.             forward = not forward
  693.         end
  694.     end
  695. end
  696.  
  697. function circle(diameter)
  698.     odd = not (math.fmod(diameter, 2) == 0)
  699.     radius = diameter / 2
  700.     if odd then
  701.         width = (2 * math.ceil(radius)) + 1
  702.         offset = math.floor(width/2)
  703.     else
  704.         width = (2 * math.ceil(radius)) + 2
  705.         offset = math.floor(width/2) - 0.5     
  706.     end
  707.     --diameter --radius * 2 + 1
  708.     sqrt3 = 3 ^ 0.5
  709.     boundaryRadius = radius + 1.0
  710.     boundary2 = boundaryRadius ^ 2
  711.     radius2 = radius ^ 2
  712.     z = math.floor(radius)
  713.     cz2 = (radius - z) ^ 2
  714.     limitOffsetY = (boundary2 - cz2) ^ 0.5
  715.     maxOffsetY = math.ceil(limitOffsetY)
  716.     -- We do first the +x side, then the -x side to make movement efficient
  717.     for side = 0,1 do
  718.             -- On the right we go from small y to large y, on the left reversed
  719.             -- This makes us travel clockwise (from below) around each layer
  720.             if (side == 0) then
  721.                 yStart = math.floor(radius) - maxOffsetY
  722.                 yEnd = math.floor(radius) + maxOffsetY
  723.                 yStep = 1
  724.             else
  725.                 yStart = math.floor(radius) + maxOffsetY
  726.                 yEnd = math.floor(radius) - maxOffsetY
  727.                 yStep = -1
  728.             end
  729.             for y = yStart,yEnd,yStep do
  730.                 cy2 = (radius - y) ^ 2
  731.                 remainder2 = (boundary2 - cz2 - cy2)
  732.                 if remainder2 >= 0 then
  733.                     -- This is the maximum difference in x from the centre we can be without definitely being outside the radius
  734.                     maxOffsetX = math.ceil((boundary2 - cz2 - cy2) ^ 0.5)
  735.                     -- Only do either the +x or -x side
  736.                     if (side == 0) then
  737.                         -- +x side
  738.                         xStart = math.floor(radius)
  739.                         xEnd = math.floor(radius) + maxOffsetX
  740.                     else
  741.                         -- -x side
  742.                         xStart = math.floor(radius) - maxOffsetX
  743.                         xEnd = math.floor(radius) - 1
  744.                     end
  745.                     -- Reverse direction we traverse xs when in -y side
  746.                     if y > math.floor(radius) then
  747.                         temp = xStart
  748.                         xStart = xEnd
  749.                         xEnd = temp
  750.                         xStep = -1
  751.                     else
  752.                         xStep = 1
  753.                     end
  754.  
  755.                     for x = xStart,xEnd,xStep do
  756.                         -- Only blocks within the radius but still within 1 3d-diagonal block of the edge are eligible
  757.                         if isSphereBorder(offset, x, y, z, radius2) then
  758.                             navigateTo(x, y)
  759.                             placeBlock()
  760.                         end
  761.                     end
  762.                 end
  763.             end
  764.         end
  765. end
  766.  
  767. function blockInSphereIsFull(offset, x, y, z, radiusSq)
  768.     x = x - offset
  769.     y = y - offset
  770.     z = z - offset
  771.     x = x ^ 2
  772.     y = y ^ 2
  773.     z = z ^ 2
  774.     return x + y + z <= radiusSq
  775. end
  776.  
  777. function isSphereBorder(offset, x, y, z, radiusSq)
  778.     spot = blockInSphereIsFull(offset, x, y, z, radiusSq)
  779.     if spot then
  780.         spot = not blockInSphereIsFull(offset, x, y - 1, z, radiusSq) or
  781.             not blockInSphereIsFull(offset, x, y + 1, z, radiusSq) or
  782.             not blockInSphereIsFull(offset, x - 1, y, z, radiusSq) or
  783.             not blockInSphereIsFull(offset, x + 1, y, z, radiusSq) or
  784.             not blockInSphereIsFull(offset, x, y, z - 1, radiusSq) or
  785.             not blockInSphereIsFull(offset, x, y, z + 1, radiusSq)
  786.     end
  787.     return spot
  788. end
  789.  
  790. function dome(typus, diameter)
  791.     -- Main dome and sphere building routine
  792.     odd = not (math.fmod(diameter, 2) == 0)
  793.     radius = diameter / 2
  794.     if odd then
  795.         width = (2 * math.ceil(radius)) + 1
  796.         offset = math.floor(width/2)
  797.     else
  798.         width = (2 * math.ceil(radius)) + 2
  799.         offset = math.floor(width/2) - 0.5     
  800.     end
  801.     --diameter --radius * 2 + 1
  802.     sqrt3 = 3 ^ 0.5
  803.     boundaryRadius = radius + 1.0
  804.     boundary2 = boundaryRadius ^ 2
  805.     radius2 = radius ^ 2
  806.    
  807.     if typus == "dome" then
  808.         zstart = math.ceil(radius)
  809.     elseif typus == "sphere" then
  810.         zstart = 1
  811.     elseif typus == "bowl" then
  812.         zstart = 1
  813.     end
  814.     if typus == "bowl" then
  815.         zend = math.floor(radius)
  816.     else
  817.         zend = width - 1
  818.     end
  819.  
  820.     -- This loop is for each vertical layer through the sphere or dome.
  821.     for z = zstart,zend do
  822.         if not cost_only and z ~= zstart then
  823.             navigateTo(positionX, positionY, positionZ + 1)
  824.         end
  825.         --writeOut("Layer " .. z)
  826.         cz2 = (radius - z) ^ 2
  827.         limitOffsetY = (boundary2 - cz2) ^ 0.5
  828.         maxOffsetY = math.ceil(limitOffsetY)
  829.         -- We do first the +x side, then the -x side to make movement efficient
  830.         for side = 0,1 do
  831.             -- On the right we go from small y to large y, on the left reversed
  832.             -- This makes us travel clockwise (from below) around each layer
  833.             if (side == 0) then
  834.                 yStart = math.floor(radius) - maxOffsetY
  835.                 yEnd = math.floor(radius) + maxOffsetY
  836.                 yStep = 1
  837.             else
  838.                 yStart = math.floor(radius) + maxOffsetY
  839.                 yEnd = math.floor(radius) - maxOffsetY
  840.                 yStep = -1
  841.             end
  842.             for y = yStart,yEnd,yStep do
  843.                 cy2 = (radius - y) ^ 2
  844.                 remainder2 = (boundary2 - cz2 - cy2)
  845.                 if remainder2 >= 0 then
  846.                     -- This is the maximum difference in x from the centre we can be without definitely being outside the radius
  847.                     maxOffsetX = math.ceil((boundary2 - cz2 - cy2) ^ 0.5)
  848.                     -- Only do either the +x or -x side
  849.                     if (side == 0) then
  850.                         -- +x side
  851.                         xStart = math.floor(radius)
  852.                         xEnd = math.floor(radius) + maxOffsetX
  853.                     else
  854.                         -- -x side
  855.                         xStart = math.floor(radius) - maxOffsetX
  856.                         xEnd = math.floor(radius) - 1
  857.                     end
  858.                     -- Reverse direction we traverse xs when in -y side
  859.                     if y > math.floor(radius) then
  860.                         temp = xStart
  861.                         xStart = xEnd
  862.                         xEnd = temp
  863.                         xStep = -1
  864.                     else
  865.                         xStep = 1
  866.                     end
  867.  
  868.                     for x = xStart,xEnd,xStep do
  869.                         -- Only blocks within the radius but still within 1 3d-diagonal block of the edge are eligible
  870.                         if isSphereBorder(offset, x, y, z, radius2) then
  871.                             navigateTo(x, y)
  872.                             placeBlock()
  873.                         end
  874.                     end
  875.                 end
  876.             end
  877.         end
  878.     end
  879. end
  880.  
  881. function cylinder(diameter, height)
  882.     for i = 1, height do
  883.         circle(diameter)
  884.         if i ~= height then
  885.             navigateTo(positionX, positionY, positionZ + 1)
  886.         end
  887.     end
  888. end
  889.  
  890. function isINF(value)
  891.     return (value == math.huge or value == -math.huge)
  892. end
  893.  
  894. function isNAN(value)
  895.     return value ~= value
  896. end
  897.  
  898. polygonCornerList = {} -- Public list of corner coords for n-gons, will be used for hexagons, octagons, and future polygons.
  899. -- It should be a nested list eg. {{x0,y0},{x1,y1},{x2,y2}...}
  900.  
  901. function constructPolygonFromList() -- Uses polygonCornerList to draw sides between each point
  902.     if #polygonCornerList == 0 then
  903.         return false
  904.     end
  905.     for i = 1, #polygonCornerList do
  906.         if (isINF(polygonCornerList[i][1]) or isNAN(polygonCornerList[i][1])) then
  907.             polygonCornerList[i][1] = 0
  908.         end
  909.         if (isINF(polygonCornerList[i][2]) or isNAN(polygonCornerList[i][2])) then
  910.             polygonCornerList[i][2] = 0
  911.         end
  912.     end
  913.     for i = 1, #polygonCornerList do
  914.         startX = polygonCornerList[i][1]
  915.         startY = polygonCornerList[i][2]
  916.         if i == #polygonCornerList then
  917.             j = 1
  918.         else
  919.             j = i + 1
  920.         end
  921.         stopX = polygonCornerList[j][1]
  922.         stopY = polygonCornerList[j][2]
  923.         drawLine(stopX, stopY, startX, startY)
  924.     end
  925.     return true
  926. end
  927.  
  928. function circleLikePolygon(numSides, diameter, offsetAngle) -- works like the circle code, allows building a circle with the same diameter from the same start point to inscribe the polygon. offSetAngle is optional, defaults to 0.
  929.     radius = diameter / 2
  930.     if (numSides % 2 == 1) then -- if numSides is odd
  931.         startAngle = math.pi / 2 -- always have a vertex at 90 deg (+y) and at least one grid aligned edge. Before offSetAngle
  932.     else -- if numSides is even
  933.         startAngle = (math.pi / 2) + (math.pi / numSides) -- always have at least two grid aligned edges. Before offSetAngle
  934.     end
  935.     startAngle = startAngle + (math.rad(offsetAngle or 0)) -- offsetAngle will be in degrees
  936.    
  937.     for i = 1, numSides do
  938.         polygonCornerList[i] = {radius * math.cos(startAngle + ((i - 1) * ((math.pi * 2) / numSides))), radius * math.sin(startAngle + ((i - 1) * ((math.pi * 2) / numSides)))}
  939.     end
  940.  
  941.     for i = 1, #polygonCornerList do
  942.         polygonCornerList[i][1] = round(polygonCornerList[i][1] + radius + 1)
  943.         polygonCornerList[i][2] = round(polygonCornerList[i][2] + radius + 1)
  944.     end
  945.    
  946.     if not constructPolygonFromList() then
  947.         error("This error should never happen.")
  948.     end
  949. end
  950.  
  951. function polygon(numSides, sideLength, offsetAngle) -- offSetAngle is optional, defaults to 0.
  952.     currentAngle = 0 + (math.rad(offsetAngle or 0)) -- start at 0 or offset angle. offsetAngle will be in degrees
  953.     addAngle = ((math.pi * 2) / numSides)
  954.     pointerX, pointerY = 0, 0
  955.     sideLength = sideLength - 1
  956.    
  957.     for i = 1, numSides do
  958.         polygonCornerList[i] = {pointerX, pointerY}
  959.         pointerX = sideLength * math.cos(currentAngle) + pointerX
  960.         pointerY = sideLength * math.sin(currentAngle) + pointerY
  961.         currentAngle = currentAngle + addAngle
  962.     end
  963.    
  964.     minX, minY = 0, 0
  965.     for i = 1, #polygonCornerList do -- find the smallest x and y
  966.         if (polygonCornerList[i][1] <= minX) then
  967.             minX = polygonCornerList[i][1]
  968.         end
  969.         if (polygonCornerList[i][2] <= minY) then
  970.             minY = polygonCornerList[i][2]
  971.         end
  972.     end
  973.     minX = math.abs(minX) -- should eventually calculate the difference between minX and 0
  974.     minY = math.abs(minY) -- should eventually calculate the difference between minY and 0
  975.    
  976.     for i = 1, #polygonCornerList do -- make it bounded to 0, 0
  977.         polygonCornerList[i][1] = round(polygonCornerList[i][1] + minX)
  978.         polygonCornerList[i][2] = round(polygonCornerList[i][2] + minY)
  979.     end
  980.    
  981.     if not constructPolygonFromList() then
  982.         error("This error should never happen.")
  983.     end
  984. end
  985.  
  986. function circleLikePolygonPrism(numSides, diameter, height, offSetAngle)
  987.     offSetAngle = offSetAngle or 0
  988.     for i = 1, height do
  989.         circleLikePolygon(numSides, diameter, offsetAngle)
  990.         if i ~= height then
  991.             navigateTo(positionX, positionY, positionZ + 1)
  992.         end
  993.     end
  994. end
  995.  
  996. function polygonPrism(numSides, sideLength, height, offSetAngle)
  997.     offSetAngle = offSetAngle or 0
  998.     for i = 1, height do
  999.         polygon(numSides, sideLength, offSetAngle)
  1000.         if i ~= height then
  1001.             navigateTo(positionX, positionY, positionZ + 1)
  1002.         end
  1003.     end
  1004. end
  1005.  
  1006. function hexagon(sideLength) -- Deprecated, please use polygon(6, sideLength, 0). Fills out polygonCornerList with the points for a hexagon.
  1007.     sideLength = sideLength - 1
  1008.     local changeX = sideLength / 2
  1009.     local changeY = round(math.sqrt(3) * changeX, 0)
  1010.     changeX = round(changeX, 0)
  1011.     polygonCornerList[1] = {changeX, 0}
  1012.     polygonCornerList[2] = {(changeX + sideLength), 0}
  1013.     polygonCornerList[3] = {((2 * changeX) + sideLength), changeY}
  1014.     polygonCornerList[4] = {(changeX + sideLength), (2 * changeY)}
  1015.     polygonCornerList[5] = {changeX, (2 * changeY)}
  1016.     polygonCornerList[6] = {0, changeY}
  1017.     if not constructPolygonFromList() then
  1018.         error("This error should never happen.")
  1019.     end
  1020. end
  1021.  
  1022. function octagon(sideLength) -- Deprecated, please use polygon(8, sideLength, 0). Fills out polygonCornerList with the points for an octagon
  1023.     sideLength = sideLength - 1
  1024.     local change = round((sideLength - 1) / math.sqrt(2), 0)
  1025.     polygonCornerList[1] = {change, 0}
  1026.     polygonCornerList[2] = {(change + sideLength), 0}
  1027.     polygonCornerList[3] = {((2 * change) + sideLength), change}
  1028.     polygonCornerList[4] = {((2 * change) + sideLength), (change + sideLength)}
  1029.     polygonCornerList[5] = {(change + sideLength), ((2 * change) + sideLength)}
  1030.     polygonCornerList[6] = {change, ((2 * change) + sideLength)}
  1031.     polygonCornerList[7] = {0, (change + sideLength)}
  1032.     polygonCornerList[8] = {0, change}
  1033.     if not constructPolygonFromList() then
  1034.         error("This error should never happen.")
  1035.     end
  1036. end
  1037.  
  1038. function hexagonPrism(length, height) -- Deprecated, please use polygonPrism(6, sideLength, height, 0).
  1039.     for i = 1, height do
  1040.         hexagon(length)
  1041.         if i ~= height then
  1042.             navigateTo(positionX, positionY, positionZ + 1)
  1043.         end
  1044.     end
  1045. end
  1046.  
  1047. function octagonPrism(length, height) -- Deprecated, please use polygonPrism(8, sideLength, height, 0).
  1048.     for i = 1, height do
  1049.         octagon(length)
  1050.         if i ~= height then
  1051.             navigateTo(positionX, positionY, positionZ + 1)
  1052.         end
  1053.     end
  1054. end
  1055.  
  1056. -- Previous Progress Resuming, Simulation functions, Command Line, and File Backend
  1057. -- Will check for a "progress" file.
  1058. function CheckForPrevious()
  1059.     if fs.exists(progFileName) then
  1060.         return true
  1061.     else
  1062.         return false
  1063.     end
  1064. end
  1065.  
  1066. -- Creates a progress file, containing a serialized table consisting of the shape type, shape input params, and the last known x, y, and z coords of the turtle (beginning of build project)
  1067. function ProgressFileCreate()
  1068.     if not CheckForPrevious() then
  1069.         fs.makeDir(progFileName)
  1070.         return true
  1071.     else
  1072.         return false
  1073.     end
  1074. end
  1075.  
  1076. -- Deletes the progress file (at the end of the project, or at beginning if user chooses to delete old progress)
  1077. function ProgressFileDelete()
  1078.     if fs.exists(progFileName) then
  1079.         fs.delete(progFileName)
  1080.         return true
  1081.     else
  1082.         return false
  1083.     end
  1084. end
  1085.  
  1086. -- To read the shape params from the file.  Shape type, and input params (e.g. "dome" and radius)
  1087. function ReadShapeParams()
  1088.     -- TODO. Unneeded for now, can just use the table elements directly
  1089. end
  1090.  
  1091. function WriteShapeParams(...) -- The ... lets it take any number of arguments and stores it to the table arg{} | This is still unused anywhere
  1092.     local paramTable = arg
  1093.     local paramName = "param"
  1094.     local paramName2 = paramName
  1095.     for i, v in ipairs(paramTable) do -- Iterates through the args passed to the function, ex. paramTable[1] i = 1 so paramName2 should be "param1", tested and works!
  1096.         paramName2 = paramName .. i
  1097.         tempProgTable[paramName2] = v
  1098.         progTable[paramName2] = v
  1099.     end
  1100. end
  1101.  
  1102. -- function to write the progress to the file (x, y, z)
  1103. function writeProgress()
  1104.     local progFile
  1105.     local progString = ""
  1106.     if not (sim_mode or cost_only) then
  1107.         progString = textutils.serialize(progTable) -- Put in here to save processing time when in cost_only
  1108.         progFile = fs.open(progFileName, "w")
  1109.         progFile.write(progString)
  1110.         progFile.close()
  1111.     end
  1112.  
  1113. end
  1114.  
  1115. -- Reads progress from file (shape, x, y, z, facing, blocks, param1, param2, param3)
  1116. function readProgress()
  1117.     local progFile = fs.open(progFileName, "r")
  1118.     local readProgTable = textutils.unserialize(progFile.readAll())
  1119.     progFile.close()
  1120.     return readProgTable
  1121. end
  1122.  
  1123. -- compares the progress read from the file to the current sim progress.  needs all four params
  1124. function compareProgress()
  1125.     local progTableIn = progTable
  1126.     local readProgTable = readProgress()
  1127.     if (progTableIn.shape == readProgTable.shape and progTableIn.x == readProgTable.x and progTableIn.y == readProgTable.y and progTableIn.blocks == readProgTable.blocks and progTableIn.facing == readProgTable.facing) then
  1128.         writeOut("All caught up!")
  1129.         return true -- We're caught up!
  1130.     else
  1131.         return false -- Not there yet...
  1132.     end
  1133. end
  1134.  
  1135. function getGPSInfo() -- TODO: finish this
  1136.     position = gps.locate()
  1137.     gpsPositionX = position.x
  1138.     gpsPositionZ = position.y
  1139.     gpsPositionY = position.z
  1140.    
  1141. end
  1142.  
  1143. function setSimFlags(b)
  1144.     sim_mode = b
  1145.     cost_only = b
  1146.     if cmd_line_cost_only then
  1147.         cost_only = true
  1148.     end
  1149. end
  1150.  
  1151. function simulationCheck() -- checks state of the simulation
  1152.     if sim_mode then
  1153.         if compareProgress() then
  1154.             setSimFlags(false) -- If we're caught up, un-set flags
  1155.         else
  1156.             setSimFlags(true)  -- If not caught up, just re-affirm that the flags are set
  1157.         end
  1158.     end
  1159. end
  1160.  
  1161. function continueQuery()
  1162.     if cmd_line_resume then
  1163.          return true
  1164.     else
  1165.          if not cmd_line then
  1166.              writeOut("Do you want to continue the last job?")
  1167.              local yes = io.read()
  1168.              if yes == "y" then
  1169.                  return true
  1170.              else
  1171.                  return false
  1172.              end
  1173.          end
  1174.     end
  1175. end
  1176.  
  1177. function progressUpdate()  -- This ONLY updates the local table variable.  Writing is handled above. -- I want to change this to allow for any number of params
  1178.     progTable = {shape = choice, enderchest_refilling = tempProgTable.enderchest_refilling, param1 = tempProgTable.param1, param2 = tempProgTable.param2, param3 = tempProgTable.param3, param4 = tempProgTable.param4, x = positionX, y = positionY, z = positionZ, facing = facing, blocks = blocks}
  1179.     if not sim_mode then
  1180.         writeProgress()
  1181.     end
  1182. end
  1183.  
  1184.  -- Command Line
  1185. function checkCommandLine() --True if arguments were passed
  1186.     if #argTable > 0 then
  1187.         cmd_line = true
  1188.         return true
  1189.     else
  1190.         cmd_line = false
  1191.         return false
  1192.     end
  1193. end
  1194.  
  1195. function needsHelp() -- True if -h is passed
  1196.     for i, v in pairs(argTable) do
  1197.         if v == "-h" or v == "-help" or v == "--help" then
  1198.             return true
  1199.         else
  1200.             return false
  1201.         end
  1202.     end
  1203. end
  1204.  
  1205. function setFlagsFromCommandLine() -- Sets count_only, chain_next_shape, and sim_mode
  1206.     for i, v in pairs(argTable) do
  1207.         if v == "-c" or v == "-cost" or v == "--cost" then
  1208.             cost_only = true
  1209.             cmd_line_cost_only = true
  1210.             writeOut("Cost Only Mode")
  1211.         end
  1212.         if v == "-z" or v == "-chain" or v == "--chain" then
  1213.             chain_next_shape = true
  1214.             writeOut("Chained Shape Mode")
  1215.         end
  1216.         if v == "-r" or v == "-resume" or v == "--resume" then
  1217.             cmd_line_resume = true
  1218.             writeOut("Resuming")
  1219.         end
  1220.         if v == "-e" or v == "-ender" or v == "--ender" then
  1221.             enderchest_refilling = true
  1222.             tempProgTable.enderchest_refilling = true
  1223.             writeOut("Enderchest Mode")
  1224.         end
  1225.         if v == "-g" or v == "-home" or v == "--home" then
  1226.             return_to_home = true
  1227.             writeOut("Will return home")
  1228.         end
  1229.     end
  1230. end
  1231.  
  1232. function setTableFromCommandLine() -- Sets progTable and tempProgTable from command line arguments
  1233.     progTable.shape = argTable[1]
  1234.     tempProgTable.shape = argTable[1]
  1235.     local paramName = "param"
  1236.     local paramName2 = paramName
  1237.     for i = 2, #argTable do
  1238.         local addOn = tostring(i - 1)
  1239.         paramName2 = paramName .. addOn
  1240.         progTable[paramName2] = argTable[i]
  1241.         tempProgTable[paramName2] = argTable[i]
  1242.     end
  1243. end
  1244.  
  1245. -- Menu, Drawing and Main functions
  1246.  
  1247. function choiceIsValidShape(choice)
  1248.     local validShapes = {"rectangle", "square", "line", "wall", "platform", "stair", "stairs", "cuboid", "1/2-sphere", "1/2 sphere", "half-sphere", "half sphere", "dome", "bowl", "sphere", "circle", "cylinder", "pyramid", "polygon", "polyprism", "polygonc", "polyprismc"}
  1249.     for i = 1, #validShapes do
  1250.         if choice == validShapes[i] then
  1251.             return true
  1252.         end
  1253.     end
  1254.     return false
  1255. end
  1256.  
  1257. function choiceFunction()
  1258.     if sim_mode == false and cmd_line == false then -- If we are NOT resuming progress
  1259.         local page = 1
  1260.         choice = io.read()
  1261.         choice = string.lower(choice) -- All checks are against lower case words so this is to ensure that
  1262.         while ((choice == "next") or (choice == "back")) do
  1263.             if (choice == "next") then
  1264.                 if page == 1 then
  1265.                     writeMenu2()
  1266.                     page = 2
  1267.                 else
  1268.                     writeMenu()
  1269.                     page = 1
  1270.                 end
  1271.             end
  1272.             if (choice == "back") then
  1273.                 if page == 1 then
  1274.                     writeMenu2()
  1275.                     page = 2
  1276.                 else
  1277.                     writeMenu()
  1278.                     page = 1
  1279.                 end
  1280.             end
  1281.             choice = io.read()
  1282.             choice = string.lower(choice) -- All checks are aginst lower case words so this is to ensure that
  1283.         end
  1284.         if choice == "end" or choice == "exit" then
  1285.             writeOut("Goodbye.")
  1286.             return
  1287.         end
  1288.         if choice == "help" then
  1289.             getHelp()
  1290.             return
  1291.         end
  1292.         if choice == "credits" then
  1293.             showCredits()
  1294.             return
  1295.         end
  1296.         tempProgTable = {shape = choice}
  1297.         progTable = {shape = choice}
  1298.         if not choiceIsValidShape(choice) then
  1299.             writeOut(choice ..  " is not a valid shape choice.")
  1300.             return
  1301.         end
  1302.         writeOut("Building a "..choice)
  1303.         local yes = getInput("string","Want to just calculate the cost?","y","n")
  1304.         if yes == 'y' then
  1305.             cost_only = true
  1306.         end
  1307.         local yes = getInput("string","Want turtle to return to start after build?","y","n")
  1308.         if yes == 'y' then
  1309.             return_to_home = true
  1310.         end
  1311.         local yes = getInput("string","Want the turtle to refill from enderchest (slot 16)?","y","n")
  1312.         if yes == 'y' then
  1313.             enderchest_refilling = true
  1314.             tempProgTable.enderchest_refilling = true
  1315.         end
  1316.     elseif sim_mode == true then -- If we ARE resuming progress
  1317.         tempProgTable = readProgress()
  1318.         choice = tempProgTable.shape
  1319.         choice = string.lower(choice) -- All checks are aginst lower case words so this is to ensure that
  1320.         enderchest_refilling =  tempProgTable.enderchest_refilling
  1321.     elseif cmd_line == true then -- If running from command line
  1322.         if needsHelp() then
  1323.             showCmdLineHelp()
  1324.             return
  1325.         end
  1326.         choice = tempProgTable.shape
  1327.         choice = string.lower(choice) -- All checks are aginst lower case words so this is to ensure that
  1328.         enderchest_refilling =  tempProgTable.enderchest_refilling
  1329.         writeOut("Building a "..choice)
  1330.     end
  1331.     if not cost_only then
  1332.         turtle.select(1)
  1333.         activeSlot = 1
  1334.         if turtle.getItemCount(activeSlot) == 0 then
  1335.             if resupply then
  1336.                 writeOut("Please put building blocks in the first slot.")
  1337.             else
  1338.                 writeOut("Please put building blocks in the first slot (and more if you need them)")
  1339.             end
  1340.             while turtle.getItemCount(activeSlot) <= 1 do
  1341.                 os.sleep(.1)
  1342.             end
  1343.         end
  1344.     else
  1345.         activeSlot = 1
  1346.     end
  1347.     -- Shape selection if cascade
  1348.     -- Line based shapes
  1349.     if choice == "rectangle" then
  1350.         local depth = 0
  1351.         local width = 0
  1352.         if sim_mode == false and cmd_line == false then
  1353.             width = getInput("int","How wide does it need to be?")
  1354.             depth = getInput("int","How deep does it need to be?")
  1355.         elseif sim_mode == true or cmd_line == true then
  1356.             width = tempProgTable.param1
  1357.             depth = tempProgTable.param2
  1358.         end
  1359.         tempProgTable.param1 = width
  1360.         tempProgTable.param2 = depth
  1361.         progTable = {param1 = width, param2 = depth} -- THIS is here because we NEED to update the local table!
  1362.         rectangle(width, depth)
  1363.     end
  1364.     if choice == "square" then
  1365.         local sideLength
  1366.         if sim_mode == false and cmd_line == false then
  1367.             sideLength = getInput("int","How long does each side need to be?")
  1368.         elseif sim_mode == true or cmd_line == true then
  1369.             sideLength = tempProgTable.param1
  1370.         end
  1371.         tempProgTable.param1 = sideLength
  1372.         progTable = {param1 = sideLength}
  1373.         square(sideLength)
  1374.     end
  1375.     if choice == "line" then
  1376.         local startX = 0
  1377.         local startY = 0
  1378.         local endX = 0
  1379.         local endY = 0
  1380.         if sim_mode == false and cmd_line == false then
  1381.             writeOut("Note that the turtle's starting position is 0, 0.")
  1382.             startX = getInput("int","Where does the start X need to be?")
  1383.             startY = getInput("int","Where does the start Y need to be?")
  1384.             endX = getInput("int","Where does the end X need to be?")
  1385.             endY = getInput("int","Where does the end Y need to be?")
  1386.         elseif sim_mode == true or cmd_line == true then
  1387.             startX = tempProgTable.param1
  1388.             startY = tempProgTable.param2
  1389.             endX = tempProgTable.param3
  1390.             endY = tempProgTable.param4
  1391.         end
  1392.         tempProgTable.param1 = startX
  1393.         tempProgTable.param2 = startY
  1394.         tempProgTable.param3 = endX
  1395.         tempProgTable.param4 = endY
  1396.         progTable = {param1 = startX, param2 = startY, param3 = endX, param4 = endY}
  1397.         drawLine(endX, endY, startX, startY)
  1398.     end
  1399.     if choice == "wall" then
  1400.         local depth = 0
  1401.         local height = 0
  1402.         if sim_mode == false and cmd_line == false then
  1403.             depth = getInput("int","How deep does it need to be?")
  1404.             height = getInput("int","How high does it need to be?")
  1405.         elseif sim_mode == true or cmd_line == true then
  1406.             depth = tempProgTable.param1
  1407.             height = tempProgTable.param2
  1408.         end        
  1409.         tempProgTable.param1 = depth
  1410.         tempProgTable.param2 = height
  1411.         progTable = {param1 = depth, param2 = height}
  1412.         wall(depth, height)
  1413.     end
  1414.     if choice == "platform" then
  1415.         local width = 0
  1416.         local depth = 0
  1417.         if sim_mode == false and cmd_line == false then
  1418.             width = getInput("int","How wide does it need to be?")
  1419.             depth = getInput("int","How deep does it need to be?")
  1420.         elseif sim_mode == true or cmd_line == true then   
  1421.             width = tempProgTable.param1       
  1422.             depth = tempProgTable.param2
  1423.         end    
  1424.         tempProgTable.param1 = width
  1425.         tempProgTable.param2 = depth
  1426.         progTable = {param1 = width, param2 = depth}
  1427.         platform(width, depth)
  1428.     end
  1429.     if choice == "stair" or choice == "stairs" then
  1430.         local width = 0
  1431.         local height = 0
  1432.         if sim_mode == false and cmd_line == false then
  1433.             width = getInput("int","How wide does it need to be?")
  1434.             height = getInput("int","How high does it need to be?")
  1435.         elseif sim_mode == true or cmd_line == true then
  1436.             width = tempProgTable.param1
  1437.             height = tempProgTable.param2
  1438.         end
  1439.         tempProgTable.param1 = width
  1440.         tempProgTable.param2 = height
  1441.         progTable = {param1 = width, param2 = height}
  1442.         stair(width, height)
  1443.         special_chain = true
  1444.     end
  1445.     if choice == "cuboid" then
  1446.         local width = 0
  1447.         local depth = 0
  1448.         local height = 0
  1449.         local hollow = ""
  1450.         if sim_mode == false and cmd_line == false then
  1451.             width = getInput("int","How wide does it need to be?")
  1452.             depth = getInput("int","How deep does it need to be?")
  1453.             height = getInput("int","How high does it need to be?")
  1454.             hollow = getInput("string","Does it need to be hollow?","y","n")
  1455.         elseif sim_mode == true or cmd_line == true then
  1456.             width = tempProgTable.param1
  1457.             depth = tempProgTable.param2
  1458.             height = tempProgTable.param3
  1459.             hollow = tempProgTable.param4
  1460.         end
  1461.         tempProgTable.param1 = width
  1462.         tempProgTable.param2 = depth
  1463.         tempProgTable.param3 = height
  1464.         tempProgTable.param4 = hollow  
  1465.         progTable = {param1 = width, param2 = depth, param3 = height}
  1466.         cuboid(width, depth, height, hollow)
  1467.     end
  1468.     if choice == "pyramid" then
  1469.         local length = 0
  1470.         local hollow = ""
  1471.         if sim_mode == false and cmd_line == false then
  1472.             length = getInput("int","How long does each side of the base layer need to be?")
  1473.             hollow = getInput("string","Does it need to be hollow?","y","n")
  1474.         elseif sim_mode == true or cmd_line == true then
  1475.             length = tempProgTable.param1
  1476.             hollow = tempProgTable.param2
  1477.         end
  1478.         tempProgTable.param1 = length
  1479.         tempProgTable.param2 = hollow
  1480.         progTable = {param1 = length, param2 = hollow}
  1481.         pyramid(length, hollow)
  1482.     end
  1483.     -- Circle based shapes
  1484.     if choice == "1/2-sphere" or choice == "1/2 sphere" then
  1485.         local diameter = 0
  1486.         local half = ""
  1487.         if sim_mode == false and cmd_line == false then
  1488.             diameter = getInput("int","What diameter does it need to be?")
  1489.             half = getInput("string","What half of the sphere does it need to be?","bottom","top")
  1490.         elseif sim_mode == true or cmd_line == true then
  1491.             diameter = tempProgTable.param1
  1492.             half = tempProgTable.param2
  1493.         end
  1494.         tempProgTable.param1 = diameter
  1495.         tempProgTable.param2 = half
  1496.         progTable = {param1 = diameter, param2 = half}
  1497.         if half == "bottom" then
  1498.             dome("bowl", diameter)
  1499.         elseif half == "top" then
  1500.             dome("dome", diameter)
  1501.         end
  1502.     end
  1503.     if choice == "dome" then
  1504.         local diameter = 0
  1505.         if sim_mode == false and cmd_line == false then
  1506.             diameter = getInput("int","What diameter does it need to be?")
  1507.         elseif sim_mode == true or cmd_line == true then
  1508.             diameter = tempProgTable.param1
  1509.         end
  1510.         tempProgTable.param1 = diameter
  1511.         progTable = {param1 = diameter}
  1512.         dome("dome", diameter)
  1513.     end
  1514.     if choice == "bowl" then
  1515.         local diameter = 0
  1516.         if sim_mode == false and cmd_line == false then
  1517.             diameter = getInput("int","What diameter does it need to be?")
  1518.         elseif sim_mode == true or cmd_line == true then
  1519.             diameter = tempProgTable.param1
  1520.         end
  1521.         tempProgTable.param1 = diameter
  1522.         progTable = {param1 = diameter}
  1523.         dome("bowl", diameter)
  1524.     end
  1525.     if choice == "sphere" then
  1526.         local diameter = 0
  1527.         if sim_mode == false and cmd_line == false then
  1528.             diameter = getInput("int","What diameter does it need to be?")
  1529.         elseif sim_mode == true or cmd_line == true then
  1530.             diameter = tempProgTable.param1
  1531.         end
  1532.         tempProgTable.param1 = diameter
  1533.         progTable = {param1 = diameter}
  1534.         dome("sphere", diameter)
  1535.     end
  1536.     if choice == "circle" then
  1537.         local diameter = 0
  1538.         if sim_mode == false and cmd_line == false then
  1539.             diameter = getInput("int","What diameter does it need to be?")
  1540.         elseif sim_mode == true or cmd_line == true then
  1541.             diameter = tempProgTable.param1
  1542.         end
  1543.         tempProgTable.param1 = diameter
  1544.         progTable = {param1 = diameter}
  1545.         circle(diameter)
  1546.     end
  1547.     if choice == "cylinder" then
  1548.         local diameter = 0
  1549.         local height = 0
  1550.         if sim_mode == false and cmd_line == false then
  1551.             diameter = getInput("int","What diameter does it need to be?")
  1552.             height = getInput("int","How high does it need to be?")
  1553.         elseif sim_mode == true or cmd_line == true then
  1554.             diameter = tempProgTable.param1
  1555.             height = tempProgTable.param2
  1556.         end
  1557.         tempProgTable.param1 = diameter
  1558.         tempProgTable.param2 = height
  1559.         progTable = {param1 = diameter, param2 = height}
  1560.         cylinder(diameter, height)
  1561.     end
  1562.     -- Polygon shapes
  1563.     if choice == "hexagon" then
  1564.         local length = 0
  1565.         if sim_mode == false and cmd_line == false then
  1566.             length = getInput("int","How long does each side need to be?")
  1567.         elseif sim_mode == true or cmd_line == true then
  1568.             length = tempProgTable.param1
  1569.         end
  1570.         tempProgTable.param1 = length
  1571.         progTable = {param1 = length}
  1572.         hexagon(length)
  1573.     end
  1574.     if choice == "octagon" then
  1575.         local length = 0
  1576.         if sim_mode == false and cmd_line == false then
  1577.             length = getInput("int","How long does each side need to be?")
  1578.         elseif sim_mode == true or cmd_line == true then
  1579.             length = tempProgTable.param1
  1580.         end
  1581.         tempProgTable.param1 = length
  1582.         progTable = {param1 = length}
  1583.         octagon(length)
  1584.     end
  1585.     if choice == "polygon" then
  1586.         local numSides = 3
  1587.         local length = 0
  1588.         local offSetAngle = 0
  1589.         if sim_mode == false and cmd_line == false then
  1590.             numSides = getInput("int","How many sides to build?")
  1591.             length = getInput("int","How long does each side need to be?")
  1592.             offSetAngle = getInput("int","What offset angle does it need to be, in degrees? (usually 0)")
  1593.         elseif sim_mode == true or cmd_line == true then
  1594.             numSides = tempProgTable.param1
  1595.             length = tempProgTable.param2
  1596.             offSetAngle = tempProgTable.param3
  1597.         end
  1598.         tempProgTable.param1 = numSides
  1599.         progTable = {param1 = numSides}
  1600.         tempProgTable.param2 = length
  1601.         progTable = {param2 = length}
  1602.         tempProgTable.param3 = offSetAngle
  1603.         progTable = {param3 = offSetAngle}
  1604.         polygon(numSides, length, offSetAngle)
  1605.     end
  1606.     if choice == "polygonc" then
  1607.         local numSides = 3
  1608.         local diameter = 0
  1609.         local offSetAngle = 0
  1610.         if sim_mode == false and cmd_line == false then
  1611.             numSides = getInput("int","How many sides to build?")
  1612.             diameter = getInput("int","What diameter does it need to be?")
  1613.             offSetAngle = getInput("int","What offset angle does it need to be, in degrees? (usually 0)")
  1614.         elseif sim_mode == true or cmd_line == true then
  1615.             numSides = tempProgTable.param1
  1616.             diameter = tempProgTable.param2
  1617.             offSetAngle = tempProgTable.param3
  1618.         end
  1619.         tempProgTable.param1 = numSides
  1620.         progTable = {param1 = numSides}
  1621.         tempProgTable.param2 = diameter
  1622.         progTable = {param2 = diameter}
  1623.         tempProgTable.param3 = offSetAngle
  1624.         progTable = {param3 = offSetAngle}
  1625.         circleLikePolygon(numSides, diameter, offSetAngle)
  1626.     end
  1627.     if choice == "polyprism" then
  1628.         local numSides = 3
  1629.         local length = 0
  1630.         local height = 0
  1631.         local offSetAngle = 0
  1632.         if sim_mode == false and cmd_line == false then
  1633.             numSides = getInput("int","How many sides to build?")
  1634.             length = getInput("int","How long does each side need to be?")
  1635.             height = getInput("int","How high does it need to be?")
  1636.             offSetAngle = getInput("int","What offset angle does it need to be, in degrees? (usually 0)")
  1637.         elseif sim_mode == true or cmd_line == true then
  1638.             numSides = tempProgTable.param1
  1639.             length = tempProgTable.param2
  1640.             height = tempProgTable.param3
  1641.             offSetAngle = tempProgTable.param4
  1642.         end
  1643.         tempProgTable.param1 = numSides
  1644.         progTable = {param1 = numSides}
  1645.         tempProgTable.param2 = length
  1646.         progTable = {param2 = length}
  1647.         tempProgTable.param3 = height
  1648.         progTable = {param3 = height}
  1649.         tempProgTable.param4 = offSetAngle
  1650.         progTable = {param4 = offSetAngle}
  1651.         polygonPrism(numSides, length, height, offSetAngle)
  1652.     end
  1653.     if choice == "polyprismc" then
  1654.         local numSides = 3
  1655.         local diameter = 0
  1656.         local height = 0
  1657.         local offSetAngle = 0
  1658.         if sim_mode == false and cmd_line == false then
  1659.             numSides = getInput("int","How many sides to build?")
  1660.             diameter = getInput("int","What diameter does it need to be?")
  1661.             height = getInput("int","How high does it need to be?")
  1662.             offSetAngle = getInput("int","What offset angle does it need to be, in degrees? (usually 0)")
  1663.         elseif sim_mode == true or cmd_line == true then
  1664.             numSides = tempProgTable.param1
  1665.             diameter = tempProgTable.param2
  1666.             height = tempProgTable.param3
  1667.             offSetAngle = tempProgTable.param4
  1668.         end
  1669.         tempProgTable.param1 = numSides
  1670.         progTable = {param1 = numSides}
  1671.         tempProgTable.param2 = diameter
  1672.         progTable = {param2 = diameter}
  1673.         tempProgTable.param3 = height
  1674.         progTable = {param3 = height}
  1675.         tempProgTable.param4 = offSetAngle
  1676.         progTable = {param4 = offSetAngle}
  1677.         circleLikePolygonPrism(numSides, diameter, height, offSetAngle)
  1678.     end
  1679.     if choice == "6-prism" or choice == "6 prism" then
  1680.         local length = 0
  1681.         local height = 0
  1682.         if sim_mode == false and cmd_line == false then
  1683.             length = getInput("int","How long does each side need to be?")
  1684.             height = getInput("int","How high does it need to be?")
  1685.         elseif sim_mode == true or cmd_line == true then
  1686.             length = tempProgTable.param1
  1687.             height = tempProgTable.param2
  1688.         end
  1689.         tempProgTable.param1 = length
  1690.         tempProgTable.param2 = height
  1691.         progTable = {param1 = length, param2 = height}
  1692.         hexagonPrism(length, height)
  1693.     end
  1694.     if choice == "8-prism" or choice == "8 prism" then
  1695.         local length = 0
  1696.         local height = 0
  1697.         if sim_mode == false and cmd_line == false then
  1698.             length = getInput("int","How long does each side need to be?")
  1699.             height = getInput("int","How high does it need to be?")
  1700.         elseif sim_mode == true or cmd_line == true then
  1701.             length = tempProgTable.param1
  1702.             height = tempProgTable.param2
  1703.         end
  1704.         tempProgTable.param1 = length
  1705.         tempProgTable.param2 = height
  1706.         progTable = {param1 = length, param2 = height}
  1707.         octagonPrism(length, height)
  1708.     end
  1709.     if return_to_home then
  1710.         goHome() -- After all shape building has finished
  1711.     end
  1712.     writeOut("Done") -- Saves a few lines when put here rather than in each if statement
  1713. end
  1714.  
  1715. function writeMenu()
  1716.     term.clear()
  1717.     term.setCursorPos(1, 1)
  1718.     writeOut("Shape Maker 1.8 by Keridos/CupricWolf/pokemane")
  1719.     if resupply then                    -- Any ideas to make this more compact/better looking (in terms of code)?
  1720.         writeOut("Resupply Mode Active")
  1721.     elseif (resupply and can_use_gps) then
  1722.         writeOut("Resupply and GPS Mode Active")
  1723.     elseif can_use_gps then
  1724.         writeOut("GPS Mode Active")
  1725.     else
  1726.         writeOut("Standard Mode Active")
  1727.     end
  1728.     if not cmd_line then
  1729.         writeOut("What shape do you want to build?")
  1730.         writeOut("[page 1/2]")
  1731.         writeOut("next for page 2")
  1732.         writeOut("+---------+-----------+-------+-------+")
  1733.         writeOut("| square  | rectangle | wall  | line  |")
  1734.         writeOut("| cylinder| platform  | stair | cuboid|")
  1735.         writeOut("| pyramid | 1/2-sphere| sphere| circle|")
  1736.         writeOut("+---------+-----------+-------+-------+")
  1737.         writeOut("")
  1738.     end
  1739. end
  1740.  
  1741. function writeMenu2()
  1742.     term.clear()
  1743.     term.setCursorPos(1, 1)
  1744.     writeOut("Shape Maker 1.8 by Keridos/CupricWolf/pokemane")
  1745.     if resupply then                    -- Any ideas to make this more compact/better looking (in terms of code)?
  1746.         writeOut("Resupply Mode Active")
  1747.     elseif (resupply and can_use_gps) then
  1748.         writeOut("Resupply and GPS Mode Active")
  1749.     elseif can_use_gps then
  1750.         writeOut("GPS Mode Active")
  1751.     else
  1752.         writeOut("Standard Mode Active")
  1753.     end
  1754.     writeOut("What shape do you want to build?")
  1755.     writeOut("[page 2/2]")
  1756.     writeOut("back for page 1")
  1757.     writeOut("+---------+-----------+-------+-------+")
  1758.     writeOut("| polygon | polyprism | dome  |       |")
  1759.     writeOut("| polygonC| polyprismC|       |       |")
  1760.     writeOut("| help    | credits   | end   |       |")
  1761.     writeOut("+---------+-----------+-------+-------+")
  1762.     writeOut("")
  1763. end
  1764.  
  1765. function showCmdLineHelp()
  1766.     term.clear()
  1767.     term.setCursorPos(1, 1)
  1768.     writeOut("Command line help")
  1769.     writeOut("Usage: shape [shape-type] [param1] [param2] [param3] [param4] [-c] [-h] [-z] [-r]")
  1770.     writeOut("-c or -cost or --cost: Activate cost only mode")
  1771.     writeOut("-h or -help or --help: Show this information")
  1772.     io.read()
  1773.     writeOut("-z or -chain or --chain: Lets you chain together multiple shapes")
  1774.     writeOut("-g or -home or --home: Make turtle go 'home' after build")
  1775.     writeOut("-r or -resume or --resume: Resume the last build if possible")
  1776.     io.read()
  1777.     writeOut("-e or -ender or --ender: Activate enderchest refilling")
  1778.     writeOut("shape-type can be any of the shapes in the menu")
  1779.     writeOut("After shape-type input all of the parameters for the shape, varies by shape")
  1780.     writeOut("Put any flags (-c, -h, etc.) at the end of your command")
  1781. end
  1782.  
  1783. function getHelp()
  1784.     term.clear()
  1785.     term.setCursorPos(1, 1)
  1786.     writeOut("Width is to the right of the turtle. (X-Axis)")
  1787.     writeOut("Depth is to the front of the turtle. (Y-Axis)")
  1788.     writeOut("Height is to the top of the turtle. (Z-Axis)")
  1789.     writeOut("Length is the side length of some shapes. (Squares and Polygons)")
  1790.     io.read()
  1791.     term.clear()
  1792.     term.setCursorPos(1, 1)
  1793.     local page = 1
  1794.     writeOut("What shape do you want help with?")
  1795.     writeOut("[page 1/2]")
  1796.     writeOut("next for page 2")
  1797.     writeOut("+---------+-----------+-------+-------+")
  1798.     writeOut("| square  | rectangle | wall  | line  |")
  1799.     writeOut("| cylinder| platform  | stair | cuboid|")
  1800.     writeOut("| pyramid | 1/2-sphere| sphere| circle|")
  1801.     writeOut("+---------+-----------+-------+-------+")
  1802.     writeOut("")
  1803.     choice = io.read()
  1804.     choice = string.lower(choice)
  1805.     while ((choice == "next") or (choice == "back")) do
  1806.         if (choice == "next") then
  1807.             if (page == 1) then
  1808.                 page = 2
  1809.                 term.clear()
  1810.                 term.setCursorPos(1, 1)
  1811.                 writeOut("What shape do you want help with?")
  1812.                 writeOut("[page 2/2]")
  1813.                 writeOut("back for page 1")
  1814.                 writeOut("+---------+-----------+-------+-------+")
  1815.                 writeOut("| polygon | polyprism | dome  |       |")
  1816.                 writeOut("| polygonC| polyprismC|       |       |")
  1817.                 writeOut("| help    | credits   | end   |       |")
  1818.                 writeOut("+---------+-----------+-------+-------+")
  1819.                 writeOut("")
  1820.             else
  1821.                 page = 1
  1822.                 term.clear()
  1823.                 term.setCursorPos(1, 1)
  1824.                 writeOut("What shape do you want help with?")
  1825.                 writeOut("[page 1/2]")
  1826.                 writeOut("next for page 2")
  1827.                 writeOut("+---------+-----------+-------+-------+")
  1828.                 writeOut("| square  | rectangle | wall  | line  |")
  1829.                 writeOut("| cylinder| platform  | stair | cuboid|")
  1830.                 writeOut("| pyramid | 1/2-sphere| sphere| circle|")
  1831.                 writeOut("+---------+-----------+-------+-------+")
  1832.                 writeOut("")
  1833.             end
  1834.         end
  1835.         if (choice == "back") then
  1836.             if (page == 1) then
  1837.                 page = 2
  1838.                 term.clear()
  1839.                 term.setCursorPos(1, 1)
  1840.                 writeOut("What shape do you want help with?")
  1841.                 writeOut("[page 2/2]")
  1842.                 writeOut("back for page 1")
  1843.                 writeOut("+---------+-----------+-------+-------+")
  1844.                 writeOut("| polygon | polyprism | dome  |       |")
  1845.                 writeOut("| polygonC| polyprismC|       |       |")
  1846.                 writeOut("| help    | credits   | end   |       |")
  1847.                 writeOut("+---------+-----------+-------+-------+")
  1848.                 writeOut("")
  1849.             else
  1850.                 page = 1
  1851.                 term.clear()
  1852.                 term.setCursorPos(1, 1)
  1853.                 writeOut("What shape do you want help with?")
  1854.                 writeOut("[page 2/2]")
  1855.                 writeOut("next for page 2")
  1856.                 writeOut("+---------+-----------+-------+-------+")
  1857.                 writeOut("| square  | rectangle | wall  | line  |")
  1858.                 writeOut("| cylinder| platform  | stair | cuboid|")
  1859.                 writeOut("| pyramid | 1/2-sphere| sphere| circle|")
  1860.                 writeOut("+---------+-----------+-------+-------+")
  1861.                 writeOut("")
  1862.             end
  1863.         end
  1864.         choice = io.read()
  1865.         choice = string.lower(choice)
  1866.     end
  1867.     if not choiceIsValidShape(choice) then
  1868.         writeOut(choice ..  " is not a valid shape choice.")
  1869.         return
  1870.     end
  1871.     -- If cascade time!
  1872.     if choice == "rectangle" then
  1873.         term.clear()
  1874.         term.setCursorPos(1, 1)
  1875.         writeOut("The rectangle is a perimeter of width by depth. Use platform if you want a filled in rectangle. The rectangle takes two parameters (two integers) Width then Depth.")
  1876.     end
  1877.     if choice == "square" then
  1878.         term.clear()
  1879.         term.setCursorPos(1, 1)
  1880.         writeOut("The square is a perimeter of length by length. Use platform if you want a filled in square. The square takes one parameter (one integer) Length.")
  1881.     end
  1882.     if choice == "line" then
  1883.         term.clear()
  1884.         term.setCursorPos(1, 1)
  1885.         writeOut("The line is drawn between the start and end points given. The turtle's initial position is 0, 0 so that must by taken into account. The line takes four parameters (four integers) Start X then Start Y then End X then End Y.")
  1886.     end
  1887.     if choice == "wall" then
  1888.         term.clear()
  1889.         term.setCursorPos(1, 1)
  1890.         writeOut("The wall is a vertical plane. The wall takes two parameters (two integers) Depth then Height.")
  1891.     end
  1892.     if choice == "platform" then
  1893.         term.clear()
  1894.         term.setCursorPos(1, 1)
  1895.         writeOut("The platform is a horizontal plane of width by depth. Use rectangle or square if you want just a perimeter. The platform takes two parameters (two integers) Width then Depth.")
  1896.     end
  1897.     if choice == "stair" or choice == "stairs" then
  1898.         term.clear()
  1899.         term.setCursorPos(1, 1)
  1900.         writeOut("The stair or stairs are an incline of width by height. The stair takes two parameters (two integers) Width then Height.")
  1901.     end
  1902.     if choice == "cuboid" then
  1903.         term.clear()
  1904.         term.setCursorPos(1, 1)
  1905.         writeOut("The cuboid is a rectangular prism of width by depth by height. The hollow parameter determines if the shape is solid or like a rectangular tube. The cuboid takes four parameters (three intergers and one y/n) Width then Depth then Height then Hollow(y/n).")
  1906.     end
  1907.     if choice == "1/2-sphere" or choice == "1/2 sphere" then
  1908.         term.clear()
  1909.         term.setCursorPos(1, 1)
  1910.         writeOut("The half sphere is the top or bottom half of a sphere. The half parameter determines of the top or bottom half of the sphere built. The half sphere takes two parameters (one integer and one top/bottom) Diameter then half(top/bottom).")
  1911.     end
  1912.     if choice == "dome" then
  1913.         term.clear()
  1914.         term.setCursorPos(1, 1)
  1915.         writeOut("The dome shape is a short-cut to the top half sphere. The dome takes one parameter (one integer) Diameter.")
  1916.     end
  1917.     if choice == "bowl" then
  1918.         term.clear()
  1919.         term.setCursorPos(1, 1)
  1920.         writeOut("The bowl shape is a short-cut to the bottom half sphere. The bowl takes one parameter (one integer) Diameter.")
  1921.     end
  1922.     if choice == "sphere" then
  1923.         term.clear()
  1924.         term.setCursorPos(1, 1)
  1925.         writeOut("The sphere is just that, a sphere. It is hollow. The sphere takes one parameter (one integer) Diameter.")
  1926.     end
  1927.     if choice == "circle" then
  1928.         term.clear()
  1929.         term.setCursorPos(1, 1)
  1930.         writeOut("The circle is just that, a circle. It is just a perimeter. The circle takes one parameter (one integer) Diameter.")
  1931.     end
  1932.     if choice == "cylinder" then
  1933.         term.clear()
  1934.         term.setCursorPos(1, 1)
  1935.         writeOut("The cylinder is a cylindrical tube of diameter by height. The cylinder takes two parameters (two integers) Diameter then Height.")
  1936.     end
  1937.     if choice == "pyramid" then
  1938.         term.clear()
  1939.         term.setCursorPos(1, 1)
  1940.         writeOut("The pyramid is a four sided pyramid with base length by length. The hollow parameter determines if the inside is filled. The pyramid takes two parameters (one integer and one y/n) Base Length then Hollow(y/n).")
  1941.     end
  1942.     if choice == "polygon" then
  1943.         term.clear()
  1944.         term.setCursorPos(1, 1)
  1945.         writeOut("The polygon is a polygonal perimeter. The polygon takes three parameters (three integers) Number of Sides then Side Length then Offset Angle.")
  1946.     end
  1947.     if choice == "polygonC" then
  1948.         term.clear()
  1949.         term.setCursorPos(1, 1)
  1950.         writeOut("The polygonC is a polygonal perimeter that inscribes inside a circle with the same diameter. The polygonC takes three parameters (three integers) Number of Sides then Diameter then Offset Angle.")
  1951.     end
  1952.     if choice == "polyprism" then
  1953.         term.clear()
  1954.         term.setCursorPos(1, 1)
  1955.         writeOut("The polyprism is a polygonal prism shaped tube. The polyprism takes four parameters (four integers) Number of Sides then Side Length then Height then Offset Angle.")
  1956.     end
  1957.     if choice == "polyprismC" then
  1958.         term.clear()
  1959.         term.setCursorPos(1, 1)
  1960.         writeOut("The polyprismC is a polygonal prism shaped tube that inscribes inside a cylinder with the same diameter. The polyprismC takes four parameters (four integers) Number of Sides then Diameter then Height then Offset Angle.")
  1961.     end
  1962.     if choice == "hexagon" then
  1963.         term.clear()
  1964.         term.setCursorPos(1, 1)
  1965.         writeOut("The hexagon is a hexagonal perimeter. The hexagon takes one parameter (one integer) Length.")
  1966.     end
  1967.     if choice == "octagon" then
  1968.         term.clear()
  1969.         term.setCursorPos(1, 1)
  1970.         writeOut("The octagon is and octagonal perimeter. The octagon takes one parameter (one integer) Length.")
  1971.     end
  1972.     if choice == "6-prism" or choice == "6 prism" then
  1973.         term.clear()
  1974.         term.setCursorPos(1, 1)
  1975.         writeOut("The 6 prism is a hexagonal prism shaped tube. The 6 prism takes two parameters (two integers) Length then Height.")
  1976.     end
  1977.     if choice == "8-prism" or choice == "8 prism" then
  1978.         term.clear()
  1979.         term.setCursorPos(1, 1)
  1980.         writeOut("The 8 prism is an octagonal prism shaped tube. The 8 prism takes two parameters (two integers) Length then Height.")
  1981.     end
  1982. end
  1983.  
  1984. function showCredits()
  1985.     term.clear()
  1986.     term.setCursorPos(1, 1)
  1987.     writeOut("Credits for the shape builder:")
  1988.     writeOut("Based on work by Michiel, Vliekkie, and Aeolun")
  1989.     writeOut("Sphere/dome code by IMarvinTPA")
  1990.     writeOut("Additional improvements by Keridos, CupricWolf, and pokemane")
  1991. end
  1992.  
  1993. function main()
  1994.     if wrapModules()=="resupply" then
  1995.         linkToRSStation()
  1996.     end
  1997.     if checkCommandLine() then
  1998.         if needsHelp() then
  1999.             showCmdLineHelp()
  2000.             return -- Close the program after help info is shown
  2001.         end
  2002.         setFlagsFromCommandLine()
  2003.         setTableFromCommandLine()
  2004.     end
  2005.     if (CheckForPrevious()) then  -- Will check to see if there was a previous job and gps is enabled, and if so, ask if the user would like to re-initialize to current progress status
  2006.         if not continueQuery() then -- If the user doesn't want to continue
  2007.             ProgressFileDelete()
  2008.             setSimFlags(false) -- Just to be safe
  2009.             writeMenu()
  2010.             choiceFunction()
  2011.         else    -- If the user wants to continue
  2012.             setSimFlags(true)
  2013.             choiceFunction()
  2014.         end
  2015.     else
  2016.         setSimFlags(false)
  2017.         writeMenu()
  2018.         choiceFunction()
  2019.     end
  2020.     if (blocks ~= 0) and (fuel ~= 0) then -- Do not show on help or credits page or when selecting end
  2021.         writeOut("Blocks used: " .. blocks)
  2022.         writeOut("Fuel used: " .. fuel)
  2023.     end
  2024.     ProgressFileDelete() -- Removes file upon successful completion of a job, or completion of a previous job.
  2025.     progTable = {}
  2026.     tempProgTable = {}
  2027. end
  2028. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement