Drew956

shapeBuilder extended

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