Advertisement
Guest User

Untitled

a guest
Jul 30th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 stepUp = true
  14.  
  15. -- Record Keeping Variables: These are for recoding the blocks and fuel used
  16. local blocks = 0
  17. local fuel = 0
  18. local crescentSlot = 15
  19.  
  20. -- Position Tracking Variables: These are for keeping track of the turtle's position
  21. local positionX = 0
  22. local positionY = 0
  23. local positionZ = 0
  24. local facing = 0
  25. local gpsPositionX = 0
  26. local gpsPositionY = 0
  27. local gpsPositionZ = 0
  28. local gpsFacing = 0
  29.  
  30. -- General Variables: Other variables that don't fit in the other categories
  31. local resupply = false
  32. local enderchestRefilling = false
  33. local can_use_gps = false
  34. local returntohome = false -- whether the turtle shall return to start after build
  35. local choice = ""
  36.  
  37. -- Progress Table: These variables are the tables that the turtle's progress is tracked in
  38. local tempProgTable = {}
  39. local progTable = {} --This is the LOCAL table! used for local stuff only, and is ONLY EVER WRITTEN when sim_mode is FALSE
  40. local progFileName = "ShapesProgressFile"
  41.  
  42. -- Utility functions
  43.  
  44. 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)
  45. for i, v in ipairs(arg) do
  46. print(v)
  47. end
  48. end
  49.  
  50. function getInput(inputtype, message, option1, option2)
  51. local input = ""
  52. if inputtype == "string" then
  53. writeOut(message.. "(" ..option1 .. " or "..option2..")" )
  54. while true do
  55. input = io.read()
  56. input = string.lower(input)
  57. if input ~= option1 and input ~= option2 then
  58. writeOut("You didn't enter a valid option. Please try again.")
  59. else
  60. return input
  61. end
  62. end
  63. end
  64. if inputtype == "int" then
  65. writeOut(message)
  66. while true do
  67. input = io.read()
  68. if tonumber(input) ~= nil then
  69. return tonumber(input)
  70. else
  71. writeOut("Need a number. Please try again")
  72. end
  73. end
  74. end
  75. end
  76.  
  77. function wrapmodules() -- checks for and wraps turtle modules
  78. local test = 0
  79. if peripheral.getType("left" )== "resupply" then
  80. resupplymodule=peripheral.wrap("left")
  81. resupply = true
  82. elseif peripheral.getType("right") == "resupply" then
  83. resupplymodule=peripheral.wrap("right")
  84. resupply = true
  85. end
  86. if peripheral.getType("left") == "modem" then
  87. modem=peripheral.wrap("left")
  88. test, _, _ = gps.locate(1)
  89. if test ~= nil then
  90. can_use_gps = true
  91. end
  92. elseif peripheral.getType("right") == "modem" then
  93. modem=peripheral.wrap("right")
  94. test, _, _ = gps.locate(1)
  95. if test ~= nil then
  96. can_use_gps = true
  97. end
  98. end
  99. if resupply then
  100. return "resupply"
  101. end
  102. end
  103.  
  104. function linkToRSStation() -- Links to resupply station
  105. if resupplymodule.link() then
  106. return true
  107. else
  108. writeOut("Please put Resupply Station to the left of the turtle and press Enter to continue")
  109. io.read()
  110. linkToRSStation()
  111. end
  112. end
  113.  
  114. function compareResources()
  115. if (turtle.compareTo(1) == false) then
  116. turtle.drop()
  117. end
  118. end
  119.  
  120. function checkResources()
  121. if resupply then
  122. if turtle.getItemCount(activeslot) <= 1 then
  123. while not(resupplymodule.resupply(1)) do
  124. os.sleep(0.5)
  125. end
  126. end
  127. elseif enderchestRefilling then
  128. compareResources()
  129. while (turtle.getItemCount(activeslot) <= 1) do
  130. if (activeslot == 15) and (turtle.getItemCount(activeslot)<=1) then
  131. turtle.select(16)
  132. turtle.digUp()
  133. for i = 1, 15 do
  134. turtle.select(i)
  135. turtle.drop()
  136. end
  137. turtle.select(16)
  138. turtle.placeUp()
  139. turtle.select(1)
  140. for i = 1, 15 do
  141. turtle.suckUp()
  142. end
  143. turtle.select(16)
  144. turtle.digUp()
  145. activeslot = 1
  146. turtle.select(activeslot)
  147. else
  148. activeslot = activeslot+1
  149. -- writeOut("Turtle slot empty, trying slot "..activeslot)
  150. turtle.select(activeslot)
  151. end
  152. compareResources()
  153. os.sleep(0.2)
  154. end
  155. else
  156. compareResources()
  157. while (turtle.getItemCount(activeslot) <= 1) do
  158. if (activeslot == 16) and (turtle.getItemCount(activeslot)<=1) then
  159. writeOut("Turtle is empty, please put building block in slots and press enter to continue")
  160. io.read()
  161. activeslot = 1
  162. turtle.select(activeslot)
  163. else
  164. activeslot = activeslot+1
  165. -- writeOut("Turtle slot almost empty, trying slot "..activeslot)
  166. turtle.select(activeslot)
  167. end
  168. compareResources()
  169. os.sleep(0.2)
  170. end
  171. end
  172. end
  173.  
  174. function checkFuel()
  175. if (not(tonumber(turtle.getFuelLevel()) == nil)) then
  176. while turtle.getFuelLevel() < 50 do
  177. writeOut("Turtle almost out of fuel, pausing. Please drop fuel in inventory. And press enter.")
  178. io.read()
  179. turtle.refuel()
  180. end
  181. end
  182. end
  183.  
  184. function placeBlock()
  185. blocks = blocks + 1
  186. simulationCheck()
  187. if cost_only then
  188. return
  189. end
  190. if turtle.detectDown() and not turtle.compareDown() then
  191. turtle.digDown()
  192. end
  193. checkResources()
  194. turtle.placeDown()
  195. progressUpdate()
  196. end
  197.  
  198. function round(toBeRounded, decimalPlace) -- Needed for hexagon and octagon
  199. local multiplier = 10^(decimalPlace or 0)
  200. return math.floor(toBeRounded * multiplier + 0.5) / multiplier
  201. end
  202.  
  203. -- Navigation functions
  204. -- Allow the turtle to move while tracking its position
  205. -- This allows us to just give a destination point and have it go there
  206.  
  207. function turnRightTrack()
  208. simulationCheck()
  209. facing = facing + 1
  210. if facing >= 4 then
  211. facing = 0
  212. end
  213. progressUpdate()
  214. if cost_only then
  215. return
  216. end
  217. turtle.turnRight()
  218. end
  219.  
  220. function turnLeftTrack()
  221. simulationCheck()
  222. facing = facing - 1
  223. if facing < 0 then
  224. facing = 3
  225. end
  226. progressUpdate()
  227. if cost_only then
  228. return
  229. end
  230. turtle.turnLeft()
  231. end
  232.  
  233. function turnAroundTrack()
  234. turnLeftTrack()
  235. turnLeftTrack()
  236. end
  237.  
  238. function turnToFace(direction)
  239. if direction >= 4 or direction < 0 then
  240. return false
  241. end
  242. while facing ~= direction do
  243. turnLeftTrack()
  244. end
  245. return true
  246. end
  247.  
  248. function safeForward()
  249. simulationCheck()
  250. if facing == 0 then
  251. positionY = positionY + 1
  252. elseif facing == 1 then
  253. positionX = positionX + 1
  254. elseif facing == 2 then
  255. positionY = positionY - 1
  256. elseif facing == 3 then
  257. positionX = positionX - 1
  258. end
  259. fuel = fuel + 1
  260. progressUpdate()
  261. if cost_only then
  262. return
  263. end
  264. checkFuel()
  265. local success = false
  266. local tries = 0
  267. while not success do
  268. success = turtle.forward()
  269. if not success then
  270. while (not success) and tries < 6 do
  271. tries = tries + 1
  272. turtle.dig()
  273. success = turtle.forward()
  274. sleep(0.3)
  275. end
  276. if not success then
  277. writeOut("Blocked attempting to move forward.")
  278. writeOut("Please clear and press enter to continue.")
  279. io.read()
  280. end
  281. end
  282. end
  283. end
  284.  
  285. function safeBack()
  286. simulationCheck()
  287. if facing == 0 then
  288. positionY = positionY - 1
  289. elseif facing == 1 then
  290. positionX = positionX - 1
  291. elseif facing == 2 then
  292. positionY = positionY + 1
  293. elseif facing == 3 then
  294. positionX = positionX + 1
  295. end
  296. fuel = fuel + 1
  297. progressUpdate()
  298. if cost_only then
  299. return
  300. end
  301. checkFuel()
  302. local success = false
  303. local tries = 0
  304. while not success do
  305. success = turtle.back()
  306. if not success then
  307. turnAroundTrack()
  308. while turtle.detect() and tries < 6 do
  309. tries = tries + 1
  310. if turtle.dig() then
  311. break
  312. end
  313. sleep(0.3)
  314. end
  315. turnAroundTrack()
  316. success = turtle.back()
  317. if not success then
  318. writeOut("Blocked attempting to move back.")
  319. writeOut("Please clear and press enter to continue.")
  320. io.read()
  321. end
  322. end
  323. end
  324. end
  325.  
  326. function safeUp()
  327. simulationCheck()
  328. positionZ = positionZ + 1
  329. fuel = fuel + 1
  330. progressUpdate()
  331. if cost_only then
  332. return
  333. end
  334. checkFuel()
  335. local success = false
  336. while not success do
  337. success = turtle.up()
  338. if not success then
  339. while turtle.detectUp() do
  340. if not turtle.digUp() then
  341. writeOut("Blocked attempting to move up.")
  342. writeOut("Please clear and press enter to continue.")
  343. io.read()
  344. end
  345. end
  346. end
  347. end
  348. end
  349.  
  350. function safeDown()
  351. simulationCheck()
  352. positionZ = positionZ - 1
  353. fuel = fuel + 1
  354. progressUpdate()
  355. if cost_only then
  356. return
  357. end
  358. checkFuel()
  359. local success = false
  360. while not success do
  361. success = turtle.down()
  362. if not success then
  363. while turtle.detectDown() do
  364. if not turtle.digDown() then
  365. writeOut("Blocked attempting to move down.")
  366. writeOut("Please clear and press enter to continue.")
  367. io.read()
  368. end
  369. end
  370. end
  371. end
  372. end
  373.  
  374. function moveY(targetY)
  375. if targetY == positionY then
  376. return
  377. end
  378. if (facing ~= 0 and facing ~= 2) then -- Check axis
  379. turnRightTrack()
  380. end
  381. while targetY > positionY do
  382. if facing == 0 then
  383. safeForward()
  384. else
  385. safeBack()
  386. end
  387. end
  388. while targetY < positionY do
  389. if facing == 2 then
  390. safeForward()
  391. else
  392. safeBack()
  393. end
  394. end
  395. end
  396.  
  397. function moveX(targetX)
  398. if targetX == positionX then
  399. return
  400. end
  401. if (facing ~= 1 and facing ~= 3) then -- Check axis
  402. turnRightTrack()
  403. end
  404. while targetX > positionX do
  405. if facing == 1 then
  406. safeForward()
  407. else
  408. safeBack()
  409. end
  410. end
  411. while targetX < positionX do
  412. if facing == 3 then
  413. safeForward()
  414. else
  415. safeBack()
  416. end
  417. end
  418. end
  419.  
  420. function moveZ(targetZ)
  421. if targetZ == positionZ then
  422. return
  423. end
  424. while targetZ < positionZ do
  425. safeDown()
  426. end
  427. while targetZ > positionZ do
  428. safeUp()
  429. end
  430. end
  431.  
  432. -- 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
  433. function navigateTo(targetX, targetY, targetZ, move_z_first)
  434. 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()
  435. move_z_first = move_z_first or false -- Defaults to moving z last, if true is passed as 4th argument, it moves vertically first
  436.  
  437. if move_z_first then
  438. moveZ(targetZ)
  439. end
  440.  
  441. if facing == 0 or facing == 2 then -- Y axis
  442. moveY(targetY)
  443. moveX(targetX)
  444. else
  445. moveX(targetX)
  446. moveY(targetY)
  447. end
  448.  
  449. if not move_z_first then
  450. moveZ(targetZ)
  451. end
  452. end
  453.  
  454. function goHome()
  455. if chain_next_shape then
  456. if not special_chain then
  457. navigateTo(0, 0) -- So another program can chain multiple shapes together to create bigger structures
  458. end
  459. else
  460. 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
  461. end
  462. turnToFace(0)
  463. end
  464.  
  465. -- Shape Building functions
  466.  
  467. function line(length)
  468. if length <= 0 then
  469. error("Error, length can not be 0")
  470. end
  471. local i
  472. for i = 1, length do
  473. placeBlock()
  474. if i ~= length then
  475. safeForward()
  476. end
  477. end
  478. end
  479.  
  480. function rectangle(depth, width)
  481. if depth <= 0 then
  482. error("Error, depth can not be 0")
  483. end
  484. if width <= 0 then
  485. error("Error, width can not be 0")
  486. end
  487. local lengths = {depth, width, depth, width }
  488. local j
  489. for j=1,4 do
  490. line(lengths[j])
  491. turnRightTrack()
  492. end
  493. end
  494.  
  495. function square(width)
  496. rectangle(width, width)
  497. end
  498.  
  499. function wall(length, height)
  500. local i
  501. local j
  502. for i = 1, length do
  503. for j = 1, height do
  504. placeBlock()
  505. if j < height then
  506. safeUp()
  507. end
  508. end
  509. safeForward()
  510. for j = 1, height - 1 do
  511. safeDown()
  512. end
  513. end
  514. turnLeftTrack()
  515. end
  516.  
  517. function platform(x, y)
  518. local forward = true
  519. for counterY = 0, y - 1 do
  520. for counterX = 0, x - 1 do
  521. if forward then
  522. navigateTo(counterX, counterY)
  523. else
  524. navigateTo(x - counterX - 1, counterY)
  525. end
  526. placeBlock()
  527. end
  528. if forward then
  529. forward = false
  530. else
  531. forward = true
  532. end
  533. end
  534. end
  535.  
  536. function cuboid(depth, width, height, hollow)
  537. platform(depth, width)
  538. while (facing > 0) do
  539. turnLeftTrack()
  540. end
  541. turnAroundTrack()
  542. if ((width % 2) == 0) then -- This is for reorienting the turtle to build the walls correct in relation to the floor and ceiling
  543. turnLeftTrack()
  544. end
  545. if not(hollow == "n") then
  546. for i = 1, height - 2 do
  547. safeUp()
  548. if ((width % 2) == 0) then -- This as well
  549. rectangle(depth, width)
  550. else
  551. rectangle(width, depth)
  552. end
  553. end
  554. else
  555. for i = 1, height - 2 do
  556. safeUp()
  557. platform(depth,width)
  558. end
  559. end
  560. safeUp()
  561. platform(depth, width)
  562. end
  563.  
  564. function pyramid(length, hollow)
  565. height = math.ceil(length / 2)
  566. for i = 1, height do
  567. if hollow=="y" then
  568. rectangle(length, length)
  569. else
  570. platform(length, length)
  571. navigateTo(0,0)
  572. while facing ~= 0 do
  573. turnRightTrack()
  574. end
  575. end
  576. if i ~= height then
  577. safeUp()
  578. safeForward()
  579. turnRightTrack()
  580. safeForward()
  581. turnLeftTrack()
  582. length = length - 2
  583. end
  584. end
  585. end
  586.  
  587. function stair(width, height)
  588. turnRightTrack()
  589. local counterX = 1
  590. local counterY = 0.0
  591. local goForward = 0
  592. while counterY < height do
  593. while counterX < width do
  594. placeBlock()
  595. safeForward()
  596. counterX = counterX + 1
  597. end
  598. placeBlock()
  599. if stepUp == true then
  600. turtle.select(15)
  601. turtle.placeDown()
  602. turtle.select(1)
  603. end
  604. counterX = 1
  605. counterY = counterY + 0.5
  606. if counterY < height then
  607. if goForward == 1 and stepUp == true then
  608. turnRightTrack()
  609. safeForward()
  610. turnRightTrack()
  611. goForward = 0
  612. stepUp = false
  613. else if goForward == 1 then
  614. turnRightTrack()
  615. safeUp()
  616. safeForward()
  617. turnRightTrack()
  618. goForward = 0
  619. else
  620. turnLeftTrack()
  621. safeUp()
  622. safeForward()
  623. turnLeftTrack()
  624. goForward = 1
  625. stepUp = true
  626. end
  627. end
  628. end
  629. end
  630. end
  631.  
  632. function circle(diameter)
  633. odd = not (math.fmod(diameter, 2) == 0)
  634. radius = diameter / 2;
  635. if odd then
  636. width = (2 * math.ceil(radius)) + 1;
  637. offset = math.floor(width/2);
  638. else
  639. width = (2 * math.ceil(radius)) + 2;
  640. offset = math.floor(width/2) - 0.5;
  641. end
  642. --diameter --radius * 2 + 1
  643. sqrt3 = 3 ^ 0.5
  644. boundaryRadius = radius + 1.0
  645. boundary2 = boundaryRadius ^ 2
  646. radius2 = radius ^ 2
  647. z = math.floor(radius)
  648. cz2 = (radius - z) ^ 2
  649. limitOffsetY = (boundary2 - cz2) ^ 0.5
  650. maxOffsetY = math.ceil(limitOffsetY)
  651. -- We do first the +x side, then the -x side to make movement efficient
  652. for side = 0,1 do
  653. -- On the right we go from small y to large y, on the left reversed
  654. -- This makes us travel clockwise (from below) around each layer
  655. if (side == 0) then
  656. yStart = math.floor(radius) - maxOffsetY
  657. yEnd = math.floor(radius) + maxOffsetY
  658. yStep = 1
  659. else
  660. yStart = math.floor(radius) + maxOffsetY
  661. yEnd = math.floor(radius) - maxOffsetY
  662. yStep = -1
  663. end
  664. for y = yStart,yEnd,yStep do
  665. cy2 = (radius - y) ^ 2
  666. remainder2 = (boundary2 - cz2 - cy2)
  667. if remainder2 >= 0 then
  668. -- This is the maximum difference in x from the centre we can be without definitely being outside the radius
  669. maxOffsetX = math.ceil((boundary2 - cz2 - cy2) ^ 0.5)
  670. -- Only do either the +x or -x side
  671. if (side == 0) then
  672. -- +x side
  673. xStart = math.floor(radius)
  674. xEnd = math.floor(radius) + maxOffsetX
  675. else
  676. -- -x side
  677. xStart = math.floor(radius) - maxOffsetX
  678. xEnd = math.floor(radius) - 1
  679. end
  680. -- Reverse direction we traverse xs when in -y side
  681. if y > math.floor(radius) then
  682. temp = xStart
  683. xStart = xEnd
  684. xEnd = temp
  685. xStep = -1
  686. else
  687. xStep = 1
  688. end
  689.  
  690. for x = xStart,xEnd,xStep do
  691. -- Only blocks within the radius but still within 1 3d-diagonal block of the edge are eligible
  692. if isSphereBorder(offset, x, y, z, radius2) then
  693. navigateTo(x, y)
  694. placeBlock()
  695. end
  696. end
  697. end
  698. end
  699. end
  700. end
  701.  
  702. function blockInSphereIsFull(offset, x, y, z, radiusSq)
  703. x = x - offset
  704. y = y - offset
  705. z = z - offset
  706. x = x ^ 2
  707. y = y ^ 2
  708. z = z ^ 2
  709. return x + y + z <= radiusSq
  710. end
  711.  
  712. function isSphereBorder(offset, x, y, z, radiusSq)
  713. spot = blockInSphereIsFull(offset, x, y, z, radiusSq)
  714. if spot then
  715. spot = not blockInSphereIsFull(offset, x, y - 1, z, radiusSq) or
  716. not blockInSphereIsFull(offset, x, y + 1, z, radiusSq) or
  717. not blockInSphereIsFull(offset, x - 1, y, z, radiusSq) or
  718. not blockInSphereIsFull(offset, x + 1, y, z, radiusSq) or
  719. not blockInSphereIsFull(offset, x, y, z - 1, radiusSq) or
  720. not blockInSphereIsFull(offset, x, y, z + 1, radiusSq)
  721. end
  722. return spot
  723. end
  724.  
  725. function dome(typus, diameter)
  726. -- Main dome and sphere building routine
  727. odd = not (math.fmod(diameter, 2) == 0)
  728. radius = diameter / 2;
  729. if odd then
  730. width = (2 * math.ceil(radius)) + 1;
  731. offset = math.floor(width/2);
  732. else
  733. width = (2 * math.ceil(radius)) + 2;
  734. offset = math.floor(width/2) - 0.5;
  735. end
  736. --diameter --radius * 2 + 1
  737. sqrt3 = 3 ^ 0.5
  738. boundaryRadius = radius + 1.0
  739. boundary2 = boundaryRadius ^ 2
  740. radius2 = radius ^ 2
  741.  
  742. if typus == "dome" then
  743. zstart = math.ceil(radius)
  744. elseif typus == "sphere" then
  745. zstart = 1
  746. elseif typus == "bowl" then
  747. zstart = 1
  748. end
  749. if typus == "bowl" then
  750. zend = math.floor(radius)
  751. else
  752. zend = width - 1
  753. end
  754.  
  755. -- This loop is for each vertical layer through the sphere or dome.
  756. for z = zstart,zend do
  757. if not cost_only and z ~= zstart then
  758. safeUp()
  759. end
  760. --writeOut("Layer " .. z)
  761. cz2 = (radius - z) ^ 2
  762. limitOffsetY = (boundary2 - cz2) ^ 0.5
  763. maxOffsetY = math.ceil(limitOffsetY)
  764. -- We do first the +x side, then the -x side to make movement efficient
  765. for side = 0,1 do
  766. -- On the right we go from small y to large y, on the left reversed
  767. -- This makes us travel clockwise (from below) around each layer
  768. if (side == 0) then
  769. yStart = math.floor(radius) - maxOffsetY
  770. yEnd = math.floor(radius) + maxOffsetY
  771. yStep = 1
  772. else
  773. yStart = math.floor(radius) + maxOffsetY
  774. yEnd = math.floor(radius) - maxOffsetY
  775. yStep = -1
  776. end
  777. for y = yStart,yEnd,yStep do
  778. cy2 = (radius - y) ^ 2
  779. remainder2 = (boundary2 - cz2 - cy2)
  780. if remainder2 >= 0 then
  781. -- This is the maximum difference in x from the centre we can be without definitely being outside the radius
  782. maxOffsetX = math.ceil((boundary2 - cz2 - cy2) ^ 0.5)
  783. -- Only do either the +x or -x side
  784. if (side == 0) then
  785. -- +x side
  786. xStart = math.floor(radius)
  787. xEnd = math.floor(radius) + maxOffsetX
  788. else
  789. -- -x side
  790. xStart = math.floor(radius) - maxOffsetX
  791. xEnd = math.floor(radius) - 1
  792. end
  793. -- Reverse direction we traverse xs when in -y side
  794. if y > math.floor(radius) then
  795. temp = xStart
  796. xStart = xEnd
  797. xEnd = temp
  798. xStep = -1
  799. else
  800. xStep = 1
  801. end
  802.  
  803. for x = xStart,xEnd,xStep do
  804. -- Only blocks within the radius but still within 1 3d-diagonal block of the edge are eligible
  805. if isSphereBorder(offset, x, y, z, radius2) then
  806. navigateTo(x, y)
  807. placeBlock()
  808. end
  809. end
  810. end
  811. end
  812. end
  813. end
  814. end
  815.  
  816. function cylinder(diameter, height)
  817. for i = 1, height do
  818. circle(diameter)
  819. safeUp()
  820. end
  821. end
  822.  
  823. function hexagon(sideLength)
  824. local changeX = sideLength / 2
  825. local changeY = round(math.sqrt(3) * changeX, 0)
  826. changeX = round(changeX, 0)
  827. local counter = 0
  828.  
  829. navigateTo(changeX, 0)
  830.  
  831. for currentSide = 1, 6 do
  832. counter = 0
  833.  
  834. if currentSide == 1 then
  835. for placed = 1, sideLength do
  836. navigateTo(positionX + 1, positionY)
  837. placeBlock()
  838. end
  839. elseif currentSide == 2 then
  840. navigateTo(positionX, positionY + 1)
  841. while positionY <= changeY do
  842. if counter == 0 or counter == 2 or counter == 4 then
  843. navigateTo(positionX + 1, positionY)
  844. end
  845. placeBlock()
  846. navigateTo(positionX, positionY + 1)
  847. counter = counter + 1
  848. if counter == 5 then
  849. counter = 0
  850. end
  851. end
  852. elseif currentSide == 3 then
  853. while positionY <= (2 * changeY) do
  854. if counter == 0 or counter == 2 or counter == 4 then
  855. navigateTo(positionX - 1, positionY)
  856. end
  857. placeBlock()
  858. navigateTo(positionX, positionY + 1)
  859. counter = counter + 1
  860. if counter == 5 then
  861. counter = 0
  862. end
  863. end
  864. elseif currentSide == 4 then
  865. for placed = 1, sideLength do
  866. navigateTo(positionX - 1, positionY)
  867. placeBlock()
  868. end
  869. elseif currentSide == 5 then
  870. navigateTo(positionX, positionY - 1)
  871. while positionY >= changeY do
  872. if counter == 0 or counter == 2 or counter == 4 then
  873. navigateTo(positionX - 1, positionY)
  874. end
  875. placeBlock()
  876. navigateTo(positionX, positionY - 1)
  877. counter = counter + 1
  878. if counter == 5 then
  879. counter = 0
  880. end
  881. end
  882. elseif currentSide == 6 then
  883. while positionY >= 0 do
  884. if counter == 0 or counter == 2 or counter == 4 then
  885. navigateTo(positionX + 1, positionY)
  886. end
  887. placeBlock()
  888. navigateTo(positionX, positionY - 1)
  889. counter = counter + 1
  890. if counter == 5 then
  891. counter = 0
  892. end
  893. end
  894. end
  895. end
  896. end
  897.  
  898. function octagon(sideLength)
  899. local sideLength2 = sideLength - 1
  900. local change = round(sideLength2 / math.sqrt(2), 0)
  901.  
  902. navigateTo(change, 0)
  903.  
  904. for currentSide = 1, 8 do
  905. if currentSide == 1 then
  906. for placed = 1, sideLength2 do
  907. navigateTo(positionX + 1, positionY)
  908. placeBlock()
  909. end
  910. elseif currentSide == 2 then
  911. for placed = 1, change do
  912. navigateTo(positionX + 1, positionY + 1)
  913. placeBlock()
  914. end
  915. elseif currentSide == 3 then
  916. for placed = 1, sideLength2 do
  917. navigateTo(positionX, positionY + 1)
  918. placeBlock()
  919. end
  920. elseif currentSide == 4 then
  921. for placed = 1, change do
  922. navigateTo(positionX - 1, positionY + 1)
  923. placeBlock()
  924. end
  925. elseif currentSide == 5 then
  926. for placed = 1, sideLength2 do
  927. navigateTo(positionX - 1, positionY)
  928. placeBlock()
  929. end
  930. elseif currentSide == 6 then
  931. for placed = 1, change do
  932. navigateTo(positionX - 1, positionY - 1)
  933. placeBlock()
  934. end
  935. elseif currentSide == 7 then
  936. for placed = 1, sideLength2 do
  937. navigateTo(positionX, positionY - 1)
  938. placeBlock()
  939. end
  940. elseif currentSide == 8 then
  941. for placed = 1, change do
  942. navigateTo(positionX + 1, positionY - 1)
  943. placeBlock()
  944. end
  945. end
  946. end
  947. end
  948.  
  949. function sixprism(length, height)
  950. for i = 1, height do
  951. hexagon(length)
  952. safeUp()
  953. end
  954. end
  955.  
  956. function eigthprism(length, height)
  957. for i = 1, height do
  958. octagon(length)
  959. safeUp()
  960. end
  961. end
  962.  
  963. -- Previous Progress Resuming, Simulation functions, Command Line, and File Backend
  964. -- Will check for a "progress" file.
  965. function CheckForPrevious()
  966. if fs.exists(progFileName) then
  967. return true
  968. else
  969. return false
  970. end
  971. end
  972.  
  973. -- 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)
  974. function ProgressFileCreate()
  975. if not CheckForPrevious() then
  976. fs.makeDir(progFileName)
  977. return true
  978. else
  979. return false
  980. end
  981. end
  982.  
  983. -- Deletes the progress file (at the end of the project, also at beginning if user chooses to delete old progress)
  984. function ProgressFileDelete()
  985. if fs.exists(progFileName) then
  986. fs.delete(progFileName)
  987. return true
  988. else
  989. return false
  990. end
  991. end
  992.  
  993. -- To read the shape params from the file. Shape type, and input params (e.g. "dome" and radius)
  994. function ReadShapeParams()
  995. -- TODO. Unneeded for now, can just use the table elements directly
  996. end
  997.  
  998. function WriteShapeParams(...) -- The ... lets it take any number of arguments and stores it to the table arg{} | This is still unused anywhere
  999. local paramTable = arg
  1000. local paramName = "param"
  1001. local paramName2 = paramName
  1002. 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!
  1003. paramName2 = paramName .. i
  1004. tempProgTable[paramName2] = v
  1005. progTable[paramName2] = v
  1006. end
  1007. end
  1008.  
  1009. -- function to write the progress to the file (x, y, z)
  1010. function writeProgress()
  1011. local progFile
  1012. local progString = ""
  1013. if not (sim_mode or cost_only) then
  1014. progString = textutils.serialize(progTable) -- Put in here to save processing time when in cost_only
  1015. progFile = fs.open(progFileName, "w")
  1016. progFile.write(progString)
  1017. progFile.close()
  1018. end
  1019.  
  1020. end
  1021.  
  1022. -- Reads progress from file (shape, x, y, z, facing, blocks, param1, param2, param3)
  1023. function readProgress()
  1024. local progFile = fs.open(progFileName, "r")
  1025. local readProgTable = textutils.unserialize(progFile.readAll())
  1026. progFile.close()
  1027. return readProgTable
  1028. end
  1029.  
  1030. -- compares the progress read from the file to the current sim progress. needs all four params
  1031. function compareProgress()
  1032. local progTableIn = progTable
  1033. local readProgTable = readProgress()
  1034. 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
  1035. writeOut("All caught up!")
  1036. return true -- We're caught up!
  1037. else
  1038. return false -- Not there yet...
  1039. end
  1040. end
  1041.  
  1042. function getGPSInfo() -- TODO: finish this
  1043. position = gps.locate()
  1044. gpsPositionX = position.x
  1045. gpsPositionZ = position.y
  1046. gpsPositionY = position.z
  1047.  
  1048. end
  1049.  
  1050. function setSimFlags(b)
  1051. sim_mode = b
  1052. cost_only = b
  1053. if cmd_line_cost_only then
  1054. cost_only = true
  1055. end
  1056. end
  1057.  
  1058. function simulationCheck() -- checks state of the simulation
  1059. if sim_mode then
  1060. if compareProgress() then
  1061. setSimFlags(false) -- If we're caught up, un-set flags
  1062. else
  1063. setSimFlags(true) -- If not caught up, just re-affirm that the flags are set
  1064. end
  1065. end
  1066. end
  1067.  
  1068. function continueQuery()
  1069. if cmd_line_resume then
  1070. return true
  1071. else
  1072. if not cmd_line then
  1073. writeOut("Do you want to continue the last job?")
  1074. local yes = io.read()
  1075. if yes == "y" then
  1076. return true
  1077. else
  1078. return false
  1079. end
  1080. end
  1081. end
  1082. end
  1083.  
  1084. 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
  1085. progTable = {shape = choice, enderchestRefilling = tempProgTable.enderchestRefilling, param1 = tempProgTable.param1, param2 = tempProgTable.param2, param3 = tempProgTable.param3, param4 = tempProgTable.param4, x = positionX, y = positionY, z = positionZ, facing = facing, blocks = blocks}
  1086. if not sim_mode then
  1087. writeProgress()
  1088. end
  1089. end
  1090.  
  1091. -- Command Line
  1092. function checkCommandLine() --True if arguments were passed
  1093. if #argTable > 0 then
  1094. cmd_line = true
  1095. return true
  1096. else
  1097. cmd_line = false
  1098. return false
  1099. end
  1100. end
  1101.  
  1102. function needsHelp() -- True if -h is passed
  1103. for i, v in pairs(argTable) do
  1104. if v == "-h" or v == "-help" or v == "--help" then
  1105. return true
  1106. else
  1107. return false
  1108. end
  1109. end
  1110. end
  1111.  
  1112. function setFlagsFromCommandLine() -- Sets count_only, chain_next_shape, and sim_mode
  1113. for i, v in pairs(argTable) do
  1114. if v == "-c" or v == "-cost" or v == "--cost" then
  1115. cost_only = true
  1116. cmd_line_cost_only = true
  1117. writeOut("Cost only mode")
  1118. end
  1119. if v == "-z" or v == "-chain" or v == "--chain" then
  1120. chain_next_shape = true
  1121. writeOut("Chained shape mode")
  1122. end
  1123. if v == "-r" or v == "-resume" or v == "--resume" then
  1124. cmd_line_resume = true
  1125. writeOut("Resuming")
  1126. end
  1127. end
  1128. end
  1129.  
  1130. function setTableFromCommandLine() -- Sets progTable and tempProgTable from command line arguments
  1131. progTable.shape = argTable[1]
  1132. tempProgTable.shape = argTable[1]
  1133. local paramName = "param"
  1134. local paramName2 = paramName
  1135. for i = 2, #argTable do
  1136. local addOn = tostring(i - 1)
  1137. paramName2 = paramName .. addOn
  1138. progTable[paramName2] = argTable[i]
  1139. tempProgTable[paramName2] = argTable[i]
  1140. end
  1141. end
  1142.  
  1143. -- Menu, Drawing and Main functions
  1144.  
  1145. function choiceFunction()
  1146. if sim_mode == false and cmd_line == false then -- If we are NOT resuming progress
  1147. choice = io.read()
  1148. choice = string.lower(choice) -- All checks are aginst lower case words so this is to ensure that
  1149. tempProgTable = {shape = choice}
  1150. progTable = {shape = choice}
  1151. if choice == "next" then
  1152. WriteMenu2()
  1153. choice = io.read()
  1154. choice = string.lower(choice) -- All checks are aginst lower case words so this is to ensure that
  1155. end
  1156. if choice == "end" or choice == "exit" then
  1157. writeOut("Goodbye.")
  1158. return
  1159. end
  1160. if choice == "help" then
  1161. showHelp()
  1162. return
  1163. end
  1164. if choice == "credits" then
  1165. showCredits()
  1166. return
  1167. end
  1168. writeOut("Building a "..choice)
  1169. local yes = getInput("string","Want to just calculate the cost?","y","n")
  1170. if yes == 'y' then
  1171. cost_only = true
  1172. end
  1173. local yes = getInput("string","Want turtle to return to start after build?","y","n")
  1174. if yes == 'y' then
  1175. returntohome = true
  1176. end
  1177. local yes = getInput("string","Want the turtle to refill from enderchest (slot 16)?","y","n")
  1178. if yes == 'y' then
  1179. enderchestRefilling = true
  1180. tempProgTable.enderchestRefilling = true;
  1181. end
  1182. elseif sim_mode == true then -- If we ARE resuming progress
  1183. tempProgTable = readProgress()
  1184. choice = tempProgTable.shape
  1185. choice = string.lower(choice) -- All checks are aginst lower case words so this is to ensure that
  1186. enderchestRefilling = tempProgTable.enderchestRefilling
  1187. elseif cmd_line == true then -- If running from command line
  1188. choice = tempProgTable.shape
  1189. choice = string.lower(choice) -- All checks are aginst lower case words so this is to ensure that
  1190. enderchestRefilling = tempProgTable.enderchestRefilling
  1191. writeOut("Building a "..choice)
  1192. end
  1193. if not cost_only then
  1194. turtle.select(1)
  1195. activeslot = 1
  1196. if turtle.getItemCount(activeslot) == 0 then
  1197. if resupply then
  1198. writeOut("Please put building blocks in the first slot.")
  1199. else
  1200. writeOut("Please put building blocks in the first slot (and more if you need them)")
  1201. end
  1202. while turtle.getItemCount(activeslot) == 0 do
  1203. os.sleep(2)
  1204. end
  1205. end
  1206. else
  1207. activeslot = 1
  1208. end
  1209. -- shape selection if cascade
  1210. if choice == "rectangle" then
  1211. local depth = 0
  1212. local width = 0
  1213. if sim_mode == false and cmd_line == false then
  1214. depth = getInput("int","How deep does it need to be?")
  1215. width = getInput("int","How wide does it need to be?")
  1216. elseif sim_mode == true or cmd_line == true then
  1217. depth = tempProgTable.param1
  1218. width = tempProgTable.param2
  1219. end
  1220. tempProgTable.param1 = depth
  1221. tempProgTable.param2 = width
  1222. progTable = {param1 = depth, param2 = width} -- THIS is here because we NEED to update the local table!
  1223. rectangle(depth, width)
  1224. end
  1225. if choice == "square" then
  1226. local sideLength
  1227. if sim_mode == false and cmd_line == false then
  1228. sideLength = getInput("int","What depth/width does it need to be?")
  1229. elseif sim_mode == true or cmd_line == true then
  1230. sideLength = tempProgTable.param1
  1231. end
  1232. tempProgTable.param1 = sideLength
  1233. progTable = {param1 = sideLength}
  1234. square(sideLength)
  1235. end
  1236. if choice == "line" then
  1237. local lineLength = 0
  1238. if sim_mode == false and cmd_line == false then
  1239. lineLength = getInput("int","How long does it need to be?")
  1240. elseif sim_mode == true or cmd_line == true then
  1241. lineLength = tempProgTable.param1
  1242. end
  1243. tempProgTable.param1 = lineLength
  1244. progTable = {param1 = lineLength}
  1245. line(lineLength)
  1246. end
  1247. if choice == "wall" then
  1248. local depth = 0
  1249. local height = 0
  1250. if sim_mode == false and cmd_line == false then
  1251. depth = getInput("int","How deep does it need to be?")
  1252. height = getInput("int","How high does it need to be?")
  1253. elseif sim_mode == true or cmd_line == true then
  1254. depth = tempProgTable.param1
  1255. height = tempProgTable.param2
  1256. end
  1257. tempProgTable.param1 = depth
  1258. tempProgTable.param2 = height
  1259. progTable = {param1 = depth, param2 = height}
  1260. wall(depth, height)
  1261. end
  1262. if choice == "platform" then
  1263. local depth = 0
  1264. local width = 0
  1265. if sim_mode == false and cmd_line == false then
  1266. depth = getInput("int","How deep does it need to be?")
  1267. width = getInput("int","How wide does it need to be?")
  1268. elseif sim_mode == true or cmd_line == true then
  1269. depth = tempProgTable.param1
  1270. width = tempProgTable.param2
  1271. end
  1272. tempProgTable.param1 = depth
  1273. tempProgTable.param2 = width
  1274. progTable = {param1 = depth, param2 = width}
  1275. platform(width, depth)
  1276. end
  1277. if choice == "stair" then
  1278. local width = 0
  1279. local height = 0
  1280. if sim_mode == false and cmd_line == false then
  1281. width = getInput("int","How wide does it need to be?")
  1282. height = getInput("int","How high does it need to be?")
  1283. elseif sim_mode == true or cmd_line == true then
  1284. width = tempProgTable.param1
  1285. height = tempProgTable.param2
  1286. end
  1287. tempProgTable.param1 = width
  1288. tempProgTable.param2 = height
  1289. progTable = {param1 = width, param2 = height}
  1290. stair(width, height)
  1291. special_chain = true
  1292. end
  1293. if choice == "cuboid" then
  1294. local depth = 0
  1295. local width = 0
  1296. local height = 0
  1297. local hollow = ""
  1298. if sim_mode == false and cmd_line == false then
  1299. depth = getInput("int","How deep does it need to be?")
  1300. width = getInput("int","How wide does it need to be?")
  1301. height = getInput("int","How high does it need to be?")
  1302. hollow = getInput("string","Does it need to be hollow?","y","n")
  1303. elseif sim_mode == true or cmd_line == true then
  1304. depth = tempProgTable.param1
  1305. width = tempProgTable.param2
  1306. height = tempProgTable.param3
  1307. hollow = tempProgTable.param4
  1308. end
  1309. tempProgTable.param1 = depth
  1310. tempProgTable.param2 = width
  1311. tempProgTable.param3 = height
  1312. tempProgTable.param4 = hollow
  1313. if height < 3 then
  1314. height = 3
  1315. end
  1316. if depth < 3 then
  1317. depth = 3
  1318. end
  1319. if width < 3 then
  1320. width = 3
  1321. end
  1322. progTable = {param1 = depth, param2 = width, param3 = height}
  1323. cuboid(depth, width, height, hollow)
  1324. end
  1325. if choice == "1/2-sphere" or choice == "1/2 sphere" then
  1326. local diameter = 0
  1327. local half = ""
  1328. if sim_mode == false and cmd_line == false then
  1329. diameter = getInput("int","What diameter does it need to be?")
  1330. half = getInput("string","What half of the sphere does it need to be?","bottom","top")
  1331. elseif sim_mode == true or cmd_line == true then
  1332. diameter = tempProgTable.param1
  1333. half = tempProgTable.param2
  1334. end
  1335. tempProgTable.param1 = diameter
  1336. tempProgTable.param2 = half
  1337. progTable = {param1 = diameter, param2 = half}
  1338. if half == "bottom" then
  1339. dome("bowl", diameter)
  1340. else
  1341. dome("dome", diameter)
  1342. end
  1343. end
  1344. if choice == "dome" then
  1345. local diameter = 0
  1346. if sim_mode == false and cmd_line == false then
  1347. diameter = getInput("int","What diameter does it need to be?")
  1348. elseif sim_mode == true or cmd_line == true then
  1349. diameter = tempProgTable.param1
  1350. end
  1351. tempProgTable.param1 = diameter
  1352. progTable = {param1 = diameter}
  1353. dome("dome", diameter)
  1354. end
  1355. if choice == "bowl" then
  1356. local diameter = 0
  1357. if sim_mode == false and cmd_line == false then
  1358. diameter = getInput("int","What diameter does it need to be?")
  1359. elseif sim_mode == true or cmd_line == true then
  1360. diameter = tempProgTable.param1
  1361. end
  1362. tempProgTable.param1 = diameter
  1363. progTable = {param1 = diameter}
  1364. dome("bowl", diameter)
  1365. end
  1366. if choice == "circle" then
  1367. local diameter = 0
  1368. if sim_mode == false and cmd_line == false then
  1369. diameter = getInput("int","What diameter does it need to be?")
  1370. elseif sim_mode == true or cmd_line == true then
  1371. diameter = tempProgTable.param1
  1372. end
  1373. tempProgTable.param1 = diameter
  1374. progTable = {param1 = diameter}
  1375. circle(diameter)
  1376. end
  1377. if choice == "cylinder" then
  1378. local diameter = 0
  1379. local height = 0
  1380. if sim_mode == false and cmd_line == false then
  1381. diameter = getInput("int","What diameter does it need to be?")
  1382. height = getInput("int","How high does it need to be?")
  1383. elseif sim_mode == true or cmd_line == true then
  1384. diameter = tempProgTable.param1
  1385. height = tempProgTable.param2
  1386. end
  1387. tempProgTable.param1 = diameter
  1388. tempProgTable.param2 = height
  1389. progTable = {param1 = diameter, param2 = height}
  1390. cylinder(diameter, height)
  1391. end
  1392. if choice == "pyramid" then
  1393. local length = 0
  1394. local hollow = ""
  1395. if sim_mode == false and cmd_line == false then
  1396. length = getInput("int","What depth/width does it need to be?")
  1397. hollow = getInput("string","Does it need to be hollow?","y","n")
  1398. elseif sim_mode == true or cmd_line == true then
  1399. length = tempProgTable.param1
  1400. hollow = tempProgTable.param2
  1401. end
  1402. tempProgTable.param1 = length
  1403. tempProgTable.param2 = hollow
  1404. progTable = {param1 = length, param2 = hollow}
  1405. pyramid(length, hollow)
  1406. end
  1407. if choice == "sphere" then
  1408. local diameter = 0
  1409. if sim_mode == false and cmd_line == false then
  1410. diameter = getInput("int","What diameter does it need to be?")
  1411. elseif sim_mode == true or cmd_line == true then
  1412. diameter = tempProgTable.param1
  1413. end
  1414. tempProgTable.param1 = diameter
  1415. progTable = {param1 = diameter}
  1416. dome("sphere", diameter)
  1417. end
  1418. if choice == "hexagon" then
  1419. local length = 0
  1420. if sim_mode == false and cmd_line == false then
  1421. length = getInput("int","How long does each side need to be?")
  1422. elseif sim_mode == true or cmd_line == true then
  1423. length = tempProgTable.param1
  1424. end
  1425. tempProgTable.param1 = length
  1426. progTable = {param1 = length}
  1427. hexagon(length)
  1428. end
  1429. if choice == "octagon" then
  1430. local length = 0
  1431. if sim_mode == false and cmd_line == false then
  1432. length = getInput("int","How long does each side need to be?")
  1433. elseif sim_mode == true or cmd_line == true then
  1434. length = tempProgTable.param1
  1435. end
  1436. tempProgTable.param1 = length
  1437. progTable = {param1 = length}
  1438. octagon(length)
  1439. end
  1440. if choice == "6-prism" or choice == "6 prism" then
  1441. local length = 0
  1442. local height = 0
  1443. if sim_mode == false and cmd_line == false then
  1444. length = getInput("int","How long does each side need to be?")
  1445. height = getInput("int","What height does it need to be?")
  1446. elseif sim_mode == true or cmd_line == true then
  1447. length = tempProgTable.param1
  1448. height = tempProgTable.param2
  1449. end
  1450. tempProgTable.param1 = length
  1451. tempProgTable.param2 = height
  1452. progTable = {param1 = length, param2 = height}
  1453. sixprism(length, height)
  1454. end
  1455. if choice == "8-prism" or choice == "8 prism" then
  1456. local length = 0
  1457. local height = 0
  1458. if sim_mode == false and cmd_line == false then
  1459. length = getInput("int","How long does each side need to be?")
  1460. height = getInput("int","What height does it need to be?")
  1461. elseif sim_mode == true or cmd_line == true then
  1462. length = tempProgTable.param1
  1463. height = tempProgTable.param2
  1464. end
  1465. tempProgTable.param1 = length
  1466. tempProgTable.param2 = height
  1467. progTable = {param1 = length, param2 = height}
  1468. eightprism(length, height)
  1469. end
  1470. if returntohome then
  1471. goHome() -- After all shape building has finished
  1472. end
  1473. writeOut("Done") -- Saves a few lines when put here rather than in each if statement
  1474. end
  1475.  
  1476. function WriteMenu()
  1477. term.clear()
  1478. term.setCursorPos(1, 1)
  1479. writeOut("Shape Maker 1.5 by Keridos/Happydude/pokemane")
  1480. if resupply then -- Any ideas to make this more compact/betterlooking (in terms of code)?
  1481. writeOut("Resupply Mode Active")
  1482. elseif (resupply and can_use_gps) then
  1483. writeOut("Resupply and GPS Mode Active")
  1484. elseif can_use_gps then
  1485. writeOut("GPS Mode Active")
  1486. else
  1487. writeOut("")
  1488. end
  1489. if not cmd_line then
  1490. writeOut("What should be built? [page 1/2]");
  1491. writeOut("next for page 2")
  1492. writeOut("+---------+-----------+-------+-------+")
  1493. writeOut("| square | rectangle | wall | line |")
  1494. writeOut("| cylinder| platform | stair | cuboid|")
  1495. writeOut("| pyramid | 1/2-sphere| circle| next |")
  1496. writeOut("+---------+-----------+-------+-------+")
  1497. writeOut("")
  1498. end
  1499. end
  1500.  
  1501. function WriteMenu2()
  1502. term.clear()
  1503. term.setCursorPos(1, 1)
  1504. writeOut("Shape Maker 1.5 by Keridos/Happydude/pokemane")
  1505. if resupply then -- Any ideas to make this more compact/betterlooking (in terms of code)?
  1506. writeOut("Resupply Mode Active")
  1507. elseif (resupply and can_use_gps) then
  1508. writeOut("Resupply and GPS Mode Active")
  1509. elseif can_use_gps then
  1510. writeOut("GPS Mode Active")
  1511. else
  1512. writeOut("")
  1513. end
  1514. writeOut("What should be built [page 2/2]?");
  1515. writeOut("")
  1516. writeOut("+---------+-----------+-------+-------+")
  1517. writeOut("| hexagon | octagon | help | |")
  1518. writeOut("| 6-prism | 8-prism | end | |")
  1519. writeOut("| sphere | credits | | |")
  1520. writeOut("+---------+-----------+-------+-------+")
  1521. writeOut("")
  1522. end
  1523.  
  1524. function showHelp()
  1525. writeOut("Usage: shape [shape-type [param1 param2 param3 ...]] [-c] [-h] [-z] [-r]")
  1526. writeOut("-c: Activate cost only mode")
  1527. writeOut("-h: Show this page")
  1528. writeOut("-z: Set chain_next_shape to true, lets you chain together multiple shapes")
  1529. io.read() -- Pause here
  1530. writeOut("-r: Resume the last shape if there is a resume file")
  1531. writeOut("shape-type can be any of the shapes in the menu")
  1532. writeOut("After shape-type input all of the paramaters for the shape")
  1533. io.read() -- Pause here, too
  1534. end
  1535.  
  1536. function showCredits()
  1537. writeOut("Credits for the shape builder:")
  1538. writeOut("Based on work by Michiel,Vliekkie, and Aeolun")
  1539. writeOut("Sphere/dome code by pruby")
  1540. writeOut("Additional improvements by Keridos,Happydude and pokemane")
  1541. io.read() -- Pause here, too
  1542. end
  1543.  
  1544. function main()
  1545. if wrapmodules()=="resupply" then
  1546. linkToRSStation()
  1547. end
  1548. if checkCommandLine() then
  1549. if needsHelp() then
  1550. showHelp()
  1551. return -- Close the program after help info is shown
  1552. end
  1553. setFlagsFromCommandLine()
  1554. setTableFromCommandLine()
  1555. end
  1556. 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
  1557. if not continueQuery() then -- If the user doesn't want to continue
  1558. ProgressFileDelete()
  1559. setSimFlags(false) -- Just to be safe
  1560. WriteMenu()
  1561. choiceFunction()
  1562. else -- If the user wants to continue
  1563. setSimFlags(true)
  1564. choiceFunction()
  1565. end
  1566. else
  1567. setSimFlags(false)
  1568. WriteMenu()
  1569. choiceFunction()
  1570. end
  1571. if (blocks ~= 0) and (fuel ~= 0) then -- Do not show on help or credits page or when selecting end
  1572. writeOut("Blocks used: " .. blocks)
  1573. writeOut("Fuel used: " .. fuel)
  1574. end
  1575. ProgressFileDelete() -- Removes file upon successful completion of a job, or completion of a previous job.
  1576. progTable = {}
  1577. tempProgTable = {}
  1578. end
  1579.  
  1580. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement