Advertisement
Guest User

Untitled

a guest
Jul 30th, 2014
197
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 = false
  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. counterX = 1
  600. counterY = counterY + 0.5
  601. if counterY < height then
  602. if goForward == 1 and stepUp == true then --gofw 1; stU 1
  603. turnRightTrack()
  604. safeForward()
  605. turnRightTrack()
  606. goForward = 0
  607. stepUp = false
  608. end
  609. if goForward == 1 and stepUp == false then --gofw 1; stU 0
  610. turnRightTrack()
  611. safeUp()
  612. safeForward()
  613. turnRightTrack()
  614. goForward = 0
  615. stepUp = true
  616. end
  617. if goForward == 0 and stepUp == true then --gofw 0; stU 1
  618. turnLeftTrack()
  619. safeUp()
  620. safeForward()
  621. turnLeftTrack()
  622. goForward = 1
  623. stepUp = true
  624. end
  625. if goForward == 0 and stepUp == false then --gofw 0; stU 0
  626. turnLeftTrack()
  627. safeUp()
  628. turtle.select(15)
  629. turtle.placeDown()
  630. turtle.select(1)
  631. safeForward()
  632. turnLeftTrack()
  633. goForward = 1
  634. stepUp = true
  635. end
  636. end
  637. end
  638. end
  639.  
  640. function circle(diameter)
  641. odd = not (math.fmod(diameter, 2) == 0)
  642. radius = diameter / 2;
  643. if odd then
  644. width = (2 * math.ceil(radius)) + 1;
  645. offset = math.floor(width/2);
  646. else
  647. width = (2 * math.ceil(radius)) + 2;
  648. offset = math.floor(width/2) - 0.5;
  649. end
  650. --diameter --radius * 2 + 1
  651. sqrt3 = 3 ^ 0.5
  652. boundaryRadius = radius + 1.0
  653. boundary2 = boundaryRadius ^ 2
  654. radius2 = radius ^ 2
  655. z = math.floor(radius)
  656. cz2 = (radius - z) ^ 2
  657. limitOffsetY = (boundary2 - cz2) ^ 0.5
  658. maxOffsetY = math.ceil(limitOffsetY)
  659. -- We do first the +x side, then the -x side to make movement efficient
  660. for side = 0,1 do
  661. -- On the right we go from small y to large y, on the left reversed
  662. -- This makes us travel clockwise (from below) around each layer
  663. if (side == 0) then
  664. yStart = math.floor(radius) - maxOffsetY
  665. yEnd = math.floor(radius) + maxOffsetY
  666. yStep = 1
  667. else
  668. yStart = math.floor(radius) + maxOffsetY
  669. yEnd = math.floor(radius) - maxOffsetY
  670. yStep = -1
  671. end
  672. for y = yStart,yEnd,yStep do
  673. cy2 = (radius - y) ^ 2
  674. remainder2 = (boundary2 - cz2 - cy2)
  675. if remainder2 >= 0 then
  676. -- This is the maximum difference in x from the centre we can be without definitely being outside the radius
  677. maxOffsetX = math.ceil((boundary2 - cz2 - cy2) ^ 0.5)
  678. -- Only do either the +x or -x side
  679. if (side == 0) then
  680. -- +x side
  681. xStart = math.floor(radius)
  682. xEnd = math.floor(radius) + maxOffsetX
  683. else
  684. -- -x side
  685. xStart = math.floor(radius) - maxOffsetX
  686. xEnd = math.floor(radius) - 1
  687. end
  688. -- Reverse direction we traverse xs when in -y side
  689. if y > math.floor(radius) then
  690. temp = xStart
  691. xStart = xEnd
  692. xEnd = temp
  693. xStep = -1
  694. else
  695. xStep = 1
  696. end
  697.  
  698. for x = xStart,xEnd,xStep do
  699. -- Only blocks within the radius but still within 1 3d-diagonal block of the edge are eligible
  700. if isSphereBorder(offset, x, y, z, radius2) then
  701. navigateTo(x, y)
  702. placeBlock()
  703. end
  704. end
  705. end
  706. end
  707. end
  708. end
  709.  
  710. function blockInSphereIsFull(offset, x, y, z, radiusSq)
  711. x = x - offset
  712. y = y - offset
  713. z = z - offset
  714. x = x ^ 2
  715. y = y ^ 2
  716. z = z ^ 2
  717. return x + y + z <= radiusSq
  718. end
  719.  
  720. function isSphereBorder(offset, x, y, z, radiusSq)
  721. spot = blockInSphereIsFull(offset, x, y, z, radiusSq)
  722. if spot then
  723. spot = not blockInSphereIsFull(offset, x, y - 1, z, radiusSq) or
  724. not blockInSphereIsFull(offset, x, y + 1, z, radiusSq) or
  725. not blockInSphereIsFull(offset, x - 1, y, z, radiusSq) or
  726. not blockInSphereIsFull(offset, x + 1, y, z, radiusSq) or
  727. not blockInSphereIsFull(offset, x, y, z - 1, radiusSq) or
  728. not blockInSphereIsFull(offset, x, y, z + 1, radiusSq)
  729. end
  730. return spot
  731. end
  732.  
  733. function dome(typus, diameter)
  734. -- Main dome and sphere building routine
  735. odd = not (math.fmod(diameter, 2) == 0)
  736. radius = diameter / 2;
  737. if odd then
  738. width = (2 * math.ceil(radius)) + 1;
  739. offset = math.floor(width/2);
  740. else
  741. width = (2 * math.ceil(radius)) + 2;
  742. offset = math.floor(width/2) - 0.5;
  743. end
  744. --diameter --radius * 2 + 1
  745. sqrt3 = 3 ^ 0.5
  746. boundaryRadius = radius + 1.0
  747. boundary2 = boundaryRadius ^ 2
  748. radius2 = radius ^ 2
  749.  
  750. if typus == "dome" then
  751. zstart = math.ceil(radius)
  752. elseif typus == "sphere" then
  753. zstart = 1
  754. elseif typus == "bowl" then
  755. zstart = 1
  756. end
  757. if typus == "bowl" then
  758. zend = math.floor(radius)
  759. else
  760. zend = width - 1
  761. end
  762.  
  763. -- This loop is for each vertical layer through the sphere or dome.
  764. for z = zstart,zend do
  765. if not cost_only and z ~= zstart then
  766. safeUp()
  767. end
  768. --writeOut("Layer " .. z)
  769. cz2 = (radius - z) ^ 2
  770. limitOffsetY = (boundary2 - cz2) ^ 0.5
  771. maxOffsetY = math.ceil(limitOffsetY)
  772. -- We do first the +x side, then the -x side to make movement efficient
  773. for side = 0,1 do
  774. -- On the right we go from small y to large y, on the left reversed
  775. -- This makes us travel clockwise (from below) around each layer
  776. if (side == 0) then
  777. yStart = math.floor(radius) - maxOffsetY
  778. yEnd = math.floor(radius) + maxOffsetY
  779. yStep = 1
  780. else
  781. yStart = math.floor(radius) + maxOffsetY
  782. yEnd = math.floor(radius) - maxOffsetY
  783. yStep = -1
  784. end
  785. for y = yStart,yEnd,yStep do
  786. cy2 = (radius - y) ^ 2
  787. remainder2 = (boundary2 - cz2 - cy2)
  788. if remainder2 >= 0 then
  789. -- This is the maximum difference in x from the centre we can be without definitely being outside the radius
  790. maxOffsetX = math.ceil((boundary2 - cz2 - cy2) ^ 0.5)
  791. -- Only do either the +x or -x side
  792. if (side == 0) then
  793. -- +x side
  794. xStart = math.floor(radius)
  795. xEnd = math.floor(radius) + maxOffsetX
  796. else
  797. -- -x side
  798. xStart = math.floor(radius) - maxOffsetX
  799. xEnd = math.floor(radius) - 1
  800. end
  801. -- Reverse direction we traverse xs when in -y side
  802. if y > math.floor(radius) then
  803. temp = xStart
  804. xStart = xEnd
  805. xEnd = temp
  806. xStep = -1
  807. else
  808. xStep = 1
  809. end
  810.  
  811. for x = xStart,xEnd,xStep do
  812. -- Only blocks within the radius but still within 1 3d-diagonal block of the edge are eligible
  813. if isSphereBorder(offset, x, y, z, radius2) then
  814. navigateTo(x, y)
  815. placeBlock()
  816. end
  817. end
  818. end
  819. end
  820. end
  821. end
  822. end
  823.  
  824. function cylinder(diameter, height)
  825. for i = 1, height do
  826. circle(diameter)
  827. safeUp()
  828. end
  829. end
  830.  
  831. function hexagon(sideLength)
  832. local changeX = sideLength / 2
  833. local changeY = round(math.sqrt(3) * changeX, 0)
  834. changeX = round(changeX, 0)
  835. local counter = 0
  836.  
  837. navigateTo(changeX, 0)
  838.  
  839. for currentSide = 1, 6 do
  840. counter = 0
  841.  
  842. if currentSide == 1 then
  843. for placed = 1, sideLength do
  844. navigateTo(positionX + 1, positionY)
  845. placeBlock()
  846. end
  847. elseif currentSide == 2 then
  848. navigateTo(positionX, positionY + 1)
  849. while positionY <= changeY do
  850. if counter == 0 or counter == 2 or counter == 4 then
  851. navigateTo(positionX + 1, positionY)
  852. end
  853. placeBlock()
  854. navigateTo(positionX, positionY + 1)
  855. counter = counter + 1
  856. if counter == 5 then
  857. counter = 0
  858. end
  859. end
  860. elseif currentSide == 3 then
  861. while positionY <= (2 * changeY) do
  862. if counter == 0 or counter == 2 or counter == 4 then
  863. navigateTo(positionX - 1, positionY)
  864. end
  865. placeBlock()
  866. navigateTo(positionX, positionY + 1)
  867. counter = counter + 1
  868. if counter == 5 then
  869. counter = 0
  870. end
  871. end
  872. elseif currentSide == 4 then
  873. for placed = 1, sideLength do
  874. navigateTo(positionX - 1, positionY)
  875. placeBlock()
  876. end
  877. elseif currentSide == 5 then
  878. navigateTo(positionX, positionY - 1)
  879. while positionY >= changeY do
  880. if counter == 0 or counter == 2 or counter == 4 then
  881. navigateTo(positionX - 1, positionY)
  882. end
  883. placeBlock()
  884. navigateTo(positionX, positionY - 1)
  885. counter = counter + 1
  886. if counter == 5 then
  887. counter = 0
  888. end
  889. end
  890. elseif currentSide == 6 then
  891. while positionY >= 0 do
  892. if counter == 0 or counter == 2 or counter == 4 then
  893. navigateTo(positionX + 1, positionY)
  894. end
  895. placeBlock()
  896. navigateTo(positionX, positionY - 1)
  897. counter = counter + 1
  898. if counter == 5 then
  899. counter = 0
  900. end
  901. end
  902. end
  903. end
  904. end
  905.  
  906. function octagon(sideLength)
  907. local sideLength2 = sideLength - 1
  908. local change = round(sideLength2 / math.sqrt(2), 0)
  909.  
  910. navigateTo(change, 0)
  911.  
  912. for currentSide = 1, 8 do
  913. if currentSide == 1 then
  914. for placed = 1, sideLength2 do
  915. navigateTo(positionX + 1, positionY)
  916. placeBlock()
  917. end
  918. elseif currentSide == 2 then
  919. for placed = 1, change do
  920. navigateTo(positionX + 1, positionY + 1)
  921. placeBlock()
  922. end
  923. elseif currentSide == 3 then
  924. for placed = 1, sideLength2 do
  925. navigateTo(positionX, positionY + 1)
  926. placeBlock()
  927. end
  928. elseif currentSide == 4 then
  929. for placed = 1, change do
  930. navigateTo(positionX - 1, positionY + 1)
  931. placeBlock()
  932. end
  933. elseif currentSide == 5 then
  934. for placed = 1, sideLength2 do
  935. navigateTo(positionX - 1, positionY)
  936. placeBlock()
  937. end
  938. elseif currentSide == 6 then
  939. for placed = 1, change do
  940. navigateTo(positionX - 1, positionY - 1)
  941. placeBlock()
  942. end
  943. elseif currentSide == 7 then
  944. for placed = 1, sideLength2 do
  945. navigateTo(positionX, positionY - 1)
  946. placeBlock()
  947. end
  948. elseif currentSide == 8 then
  949. for placed = 1, change do
  950. navigateTo(positionX + 1, positionY - 1)
  951. placeBlock()
  952. end
  953. end
  954. end
  955. end
  956.  
  957. function sixprism(length, height)
  958. for i = 1, height do
  959. hexagon(length)
  960. safeUp()
  961. end
  962. end
  963.  
  964. function eigthprism(length, height)
  965. for i = 1, height do
  966. octagon(length)
  967. safeUp()
  968. end
  969. end
  970.  
  971. -- Previous Progress Resuming, Simulation functions, Command Line, and File Backend
  972. -- Will check for a "progress" file.
  973. function CheckForPrevious()
  974. if fs.exists(progFileName) then
  975. return true
  976. else
  977. return false
  978. end
  979. end
  980.  
  981. -- 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)
  982. function ProgressFileCreate()
  983. if not CheckForPrevious() then
  984. fs.makeDir(progFileName)
  985. return true
  986. else
  987. return false
  988. end
  989. end
  990.  
  991. -- Deletes the progress file (at the end of the project, also at beginning if user chooses to delete old progress)
  992. function ProgressFileDelete()
  993. if fs.exists(progFileName) then
  994. fs.delete(progFileName)
  995. return true
  996. else
  997. return false
  998. end
  999. end
  1000.  
  1001. -- To read the shape params from the file. Shape type, and input params (e.g. "dome" and radius)
  1002. function ReadShapeParams()
  1003. -- TODO. Unneeded for now, can just use the table elements directly
  1004. end
  1005.  
  1006. function WriteShapeParams(...) -- The ... lets it take any number of arguments and stores it to the table arg{} | This is still unused anywhere
  1007. local paramTable = arg
  1008. local paramName = "param"
  1009. local paramName2 = paramName
  1010. 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!
  1011. paramName2 = paramName .. i
  1012. tempProgTable[paramName2] = v
  1013. progTable[paramName2] = v
  1014. end
  1015. end
  1016.  
  1017. -- function to write the progress to the file (x, y, z)
  1018. function writeProgress()
  1019. local progFile
  1020. local progString = ""
  1021. if not (sim_mode or cost_only) then
  1022. progString = textutils.serialize(progTable) -- Put in here to save processing time when in cost_only
  1023. progFile = fs.open(progFileName, "w")
  1024. progFile.write(progString)
  1025. progFile.close()
  1026. end
  1027.  
  1028. end
  1029.  
  1030. -- Reads progress from file (shape, x, y, z, facing, blocks, param1, param2, param3)
  1031. function readProgress()
  1032. local progFile = fs.open(progFileName, "r")
  1033. local readProgTable = textutils.unserialize(progFile.readAll())
  1034. progFile.close()
  1035. return readProgTable
  1036. end
  1037.  
  1038. -- compares the progress read from the file to the current sim progress. needs all four params
  1039. function compareProgress()
  1040. local progTableIn = progTable
  1041. local readProgTable = readProgress()
  1042. 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
  1043. writeOut("All caught up!")
  1044. return true -- We're caught up!
  1045. else
  1046. return false -- Not there yet...
  1047. end
  1048. end
  1049.  
  1050. function getGPSInfo() -- TODO: finish this
  1051. position = gps.locate()
  1052. gpsPositionX = position.x
  1053. gpsPositionZ = position.y
  1054. gpsPositionY = position.z
  1055.  
  1056. end
  1057.  
  1058. function setSimFlags(b)
  1059. sim_mode = b
  1060. cost_only = b
  1061. if cmd_line_cost_only then
  1062. cost_only = true
  1063. end
  1064. end
  1065.  
  1066. function simulationCheck() -- checks state of the simulation
  1067. if sim_mode then
  1068. if compareProgress() then
  1069. setSimFlags(false) -- If we're caught up, un-set flags
  1070. else
  1071. setSimFlags(true) -- If not caught up, just re-affirm that the flags are set
  1072. end
  1073. end
  1074. end
  1075.  
  1076. function continueQuery()
  1077. if cmd_line_resume then
  1078. return true
  1079. else
  1080. if not cmd_line then
  1081. writeOut("Do you want to continue the last job?")
  1082. local yes = io.read()
  1083. if yes == "y" then
  1084. return true
  1085. else
  1086. return false
  1087. end
  1088. end
  1089. end
  1090. end
  1091.  
  1092. 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
  1093. 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}
  1094. if not sim_mode then
  1095. writeProgress()
  1096. end
  1097. end
  1098.  
  1099. -- Command Line
  1100. function checkCommandLine() --True if arguments were passed
  1101. if #argTable > 0 then
  1102. cmd_line = true
  1103. return true
  1104. else
  1105. cmd_line = false
  1106. return false
  1107. end
  1108. end
  1109.  
  1110. function needsHelp() -- True if -h is passed
  1111. for i, v in pairs(argTable) do
  1112. if v == "-h" or v == "-help" or v == "--help" then
  1113. return true
  1114. else
  1115. return false
  1116. end
  1117. end
  1118. end
  1119.  
  1120. function setFlagsFromCommandLine() -- Sets count_only, chain_next_shape, and sim_mode
  1121. for i, v in pairs(argTable) do
  1122. if v == "-c" or v == "-cost" or v == "--cost" then
  1123. cost_only = true
  1124. cmd_line_cost_only = true
  1125. writeOut("Cost only mode")
  1126. end
  1127. if v == "-z" or v == "-chain" or v == "--chain" then
  1128. chain_next_shape = true
  1129. writeOut("Chained shape mode")
  1130. end
  1131. if v == "-r" or v == "-resume" or v == "--resume" then
  1132. cmd_line_resume = true
  1133. writeOut("Resuming")
  1134. end
  1135. end
  1136. end
  1137.  
  1138. function setTableFromCommandLine() -- Sets progTable and tempProgTable from command line arguments
  1139. progTable.shape = argTable[1]
  1140. tempProgTable.shape = argTable[1]
  1141. local paramName = "param"
  1142. local paramName2 = paramName
  1143. for i = 2, #argTable do
  1144. local addOn = tostring(i - 1)
  1145. paramName2 = paramName .. addOn
  1146. progTable[paramName2] = argTable[i]
  1147. tempProgTable[paramName2] = argTable[i]
  1148. end
  1149. end
  1150.  
  1151. -- Menu, Drawing and Main functions
  1152.  
  1153. function choiceFunction()
  1154. if sim_mode == false and cmd_line == false then -- If we are NOT resuming progress
  1155. choice = io.read()
  1156. choice = string.lower(choice) -- All checks are aginst lower case words so this is to ensure that
  1157. tempProgTable = {shape = choice}
  1158. progTable = {shape = choice}
  1159. if choice == "next" then
  1160. WriteMenu2()
  1161. choice = io.read()
  1162. choice = string.lower(choice) -- All checks are aginst lower case words so this is to ensure that
  1163. end
  1164. if choice == "end" or choice == "exit" then
  1165. writeOut("Goodbye.")
  1166. return
  1167. end
  1168. if choice == "help" then
  1169. showHelp()
  1170. return
  1171. end
  1172. if choice == "credits" then
  1173. showCredits()
  1174. return
  1175. end
  1176. writeOut("Building a "..choice)
  1177. local yes = getInput("string","Want to just calculate the cost?","y","n")
  1178. if yes == 'y' then
  1179. cost_only = true
  1180. end
  1181. local yes = getInput("string","Want turtle to return to start after build?","y","n")
  1182. if yes == 'y' then
  1183. returntohome = true
  1184. end
  1185. local yes = getInput("string","Want the turtle to refill from enderchest (slot 16)?","y","n")
  1186. if yes == 'y' then
  1187. enderchestRefilling = true
  1188. tempProgTable.enderchestRefilling = true;
  1189. end
  1190. elseif sim_mode == true then -- If we ARE resuming progress
  1191. tempProgTable = readProgress()
  1192. choice = tempProgTable.shape
  1193. choice = string.lower(choice) -- All checks are aginst lower case words so this is to ensure that
  1194. enderchestRefilling = tempProgTable.enderchestRefilling
  1195. elseif cmd_line == true then -- If running from command line
  1196. choice = tempProgTable.shape
  1197. choice = string.lower(choice) -- All checks are aginst lower case words so this is to ensure that
  1198. enderchestRefilling = tempProgTable.enderchestRefilling
  1199. writeOut("Building a "..choice)
  1200. end
  1201. if not cost_only then
  1202. turtle.select(1)
  1203. activeslot = 1
  1204. if turtle.getItemCount(activeslot) == 0 then
  1205. if resupply then
  1206. writeOut("Please put building blocks in the first slot.")
  1207. else
  1208. writeOut("Please put building blocks in the first slot (and more if you need them)")
  1209. end
  1210. while turtle.getItemCount(activeslot) == 0 do
  1211. os.sleep(2)
  1212. end
  1213. end
  1214. else
  1215. activeslot = 1
  1216. end
  1217. -- shape selection if cascade
  1218. if choice == "rectangle" then
  1219. local depth = 0
  1220. local width = 0
  1221. if sim_mode == false and cmd_line == false then
  1222. depth = getInput("int","How deep does it need to be?")
  1223. width = getInput("int","How wide does it need to be?")
  1224. elseif sim_mode == true or cmd_line == true then
  1225. depth = tempProgTable.param1
  1226. width = tempProgTable.param2
  1227. end
  1228. tempProgTable.param1 = depth
  1229. tempProgTable.param2 = width
  1230. progTable = {param1 = depth, param2 = width} -- THIS is here because we NEED to update the local table!
  1231. rectangle(depth, width)
  1232. end
  1233. if choice == "square" then
  1234. local sideLength
  1235. if sim_mode == false and cmd_line == false then
  1236. sideLength = getInput("int","What depth/width does it need to be?")
  1237. elseif sim_mode == true or cmd_line == true then
  1238. sideLength = tempProgTable.param1
  1239. end
  1240. tempProgTable.param1 = sideLength
  1241. progTable = {param1 = sideLength}
  1242. square(sideLength)
  1243. end
  1244. if choice == "line" then
  1245. local lineLength = 0
  1246. if sim_mode == false and cmd_line == false then
  1247. lineLength = getInput("int","How long does it need to be?")
  1248. elseif sim_mode == true or cmd_line == true then
  1249. lineLength = tempProgTable.param1
  1250. end
  1251. tempProgTable.param1 = lineLength
  1252. progTable = {param1 = lineLength}
  1253. line(lineLength)
  1254. end
  1255. if choice == "wall" then
  1256. local depth = 0
  1257. local height = 0
  1258. if sim_mode == false and cmd_line == false then
  1259. depth = getInput("int","How deep does it need to be?")
  1260. height = getInput("int","How high does it need to be?")
  1261. elseif sim_mode == true or cmd_line == true then
  1262. depth = tempProgTable.param1
  1263. height = tempProgTable.param2
  1264. end
  1265. tempProgTable.param1 = depth
  1266. tempProgTable.param2 = height
  1267. progTable = {param1 = depth, param2 = height}
  1268. wall(depth, height)
  1269. end
  1270. if choice == "platform" then
  1271. local depth = 0
  1272. local width = 0
  1273. if sim_mode == false and cmd_line == false then
  1274. depth = getInput("int","How deep does it need to be?")
  1275. width = getInput("int","How wide does it need to be?")
  1276. elseif sim_mode == true or cmd_line == true then
  1277. depth = tempProgTable.param1
  1278. width = tempProgTable.param2
  1279. end
  1280. tempProgTable.param1 = depth
  1281. tempProgTable.param2 = width
  1282. progTable = {param1 = depth, param2 = width}
  1283. platform(width, depth)
  1284. end
  1285. if choice == "stair" then
  1286. local width = 0
  1287. local height = 0
  1288. if sim_mode == false and cmd_line == false then
  1289. width = getInput("int","How wide does it need to be?")
  1290. height = getInput("int","How high does it need to be?")
  1291. elseif sim_mode == true or cmd_line == true then
  1292. width = tempProgTable.param1
  1293. height = tempProgTable.param2
  1294. end
  1295. tempProgTable.param1 = width
  1296. tempProgTable.param2 = height
  1297. progTable = {param1 = width, param2 = height}
  1298. stair(width, height)
  1299. special_chain = true
  1300. end
  1301. if choice == "cuboid" then
  1302. local depth = 0
  1303. local width = 0
  1304. local height = 0
  1305. local hollow = ""
  1306. if sim_mode == false and cmd_line == false then
  1307. depth = getInput("int","How deep does it need to be?")
  1308. width = getInput("int","How wide does it need to be?")
  1309. height = getInput("int","How high does it need to be?")
  1310. hollow = getInput("string","Does it need to be hollow?","y","n")
  1311. elseif sim_mode == true or cmd_line == true then
  1312. depth = tempProgTable.param1
  1313. width = tempProgTable.param2
  1314. height = tempProgTable.param3
  1315. hollow = tempProgTable.param4
  1316. end
  1317. tempProgTable.param1 = depth
  1318. tempProgTable.param2 = width
  1319. tempProgTable.param3 = height
  1320. tempProgTable.param4 = hollow
  1321. if height < 3 then
  1322. height = 3
  1323. end
  1324. if depth < 3 then
  1325. depth = 3
  1326. end
  1327. if width < 3 then
  1328. width = 3
  1329. end
  1330. progTable = {param1 = depth, param2 = width, param3 = height}
  1331. cuboid(depth, width, height, hollow)
  1332. end
  1333. if choice == "1/2-sphere" or choice == "1/2 sphere" then
  1334. local diameter = 0
  1335. local half = ""
  1336. if sim_mode == false and cmd_line == false then
  1337. diameter = getInput("int","What diameter does it need to be?")
  1338. half = getInput("string","What half of the sphere does it need to be?","bottom","top")
  1339. elseif sim_mode == true or cmd_line == true then
  1340. diameter = tempProgTable.param1
  1341. half = tempProgTable.param2
  1342. end
  1343. tempProgTable.param1 = diameter
  1344. tempProgTable.param2 = half
  1345. progTable = {param1 = diameter, param2 = half}
  1346. if half == "bottom" then
  1347. dome("bowl", diameter)
  1348. else
  1349. dome("dome", diameter)
  1350. end
  1351. end
  1352. if choice == "dome" then
  1353. local diameter = 0
  1354. if sim_mode == false and cmd_line == false then
  1355. diameter = getInput("int","What diameter does it need to be?")
  1356. elseif sim_mode == true or cmd_line == true then
  1357. diameter = tempProgTable.param1
  1358. end
  1359. tempProgTable.param1 = diameter
  1360. progTable = {param1 = diameter}
  1361. dome("dome", diameter)
  1362. end
  1363. if choice == "bowl" then
  1364. local diameter = 0
  1365. if sim_mode == false and cmd_line == false then
  1366. diameter = getInput("int","What diameter does it need to be?")
  1367. elseif sim_mode == true or cmd_line == true then
  1368. diameter = tempProgTable.param1
  1369. end
  1370. tempProgTable.param1 = diameter
  1371. progTable = {param1 = diameter}
  1372. dome("bowl", diameter)
  1373. end
  1374. if choice == "circle" then
  1375. local diameter = 0
  1376. if sim_mode == false and cmd_line == false then
  1377. diameter = getInput("int","What diameter does it need to be?")
  1378. elseif sim_mode == true or cmd_line == true then
  1379. diameter = tempProgTable.param1
  1380. end
  1381. tempProgTable.param1 = diameter
  1382. progTable = {param1 = diameter}
  1383. circle(diameter)
  1384. end
  1385. if choice == "cylinder" then
  1386. local diameter = 0
  1387. local height = 0
  1388. if sim_mode == false and cmd_line == false then
  1389. diameter = getInput("int","What diameter does it need to be?")
  1390. height = getInput("int","How high does it need to be?")
  1391. elseif sim_mode == true or cmd_line == true then
  1392. diameter = tempProgTable.param1
  1393. height = tempProgTable.param2
  1394. end
  1395. tempProgTable.param1 = diameter
  1396. tempProgTable.param2 = height
  1397. progTable = {param1 = diameter, param2 = height}
  1398. cylinder(diameter, height)
  1399. end
  1400. if choice == "pyramid" then
  1401. local length = 0
  1402. local hollow = ""
  1403. if sim_mode == false and cmd_line == false then
  1404. length = getInput("int","What depth/width does it need to be?")
  1405. hollow = getInput("string","Does it need to be hollow?","y","n")
  1406. elseif sim_mode == true or cmd_line == true then
  1407. length = tempProgTable.param1
  1408. hollow = tempProgTable.param2
  1409. end
  1410. tempProgTable.param1 = length
  1411. tempProgTable.param2 = hollow
  1412. progTable = {param1 = length, param2 = hollow}
  1413. pyramid(length, hollow)
  1414. end
  1415. if choice == "sphere" then
  1416. local diameter = 0
  1417. if sim_mode == false and cmd_line == false then
  1418. diameter = getInput("int","What diameter does it need to be?")
  1419. elseif sim_mode == true or cmd_line == true then
  1420. diameter = tempProgTable.param1
  1421. end
  1422. tempProgTable.param1 = diameter
  1423. progTable = {param1 = diameter}
  1424. dome("sphere", diameter)
  1425. end
  1426. if choice == "hexagon" then
  1427. local length = 0
  1428. if sim_mode == false and cmd_line == false then
  1429. length = getInput("int","How long does each side need to be?")
  1430. elseif sim_mode == true or cmd_line == true then
  1431. length = tempProgTable.param1
  1432. end
  1433. tempProgTable.param1 = length
  1434. progTable = {param1 = length}
  1435. hexagon(length)
  1436. end
  1437. if choice == "octagon" then
  1438. local length = 0
  1439. if sim_mode == false and cmd_line == false then
  1440. length = getInput("int","How long does each side need to be?")
  1441. elseif sim_mode == true or cmd_line == true then
  1442. length = tempProgTable.param1
  1443. end
  1444. tempProgTable.param1 = length
  1445. progTable = {param1 = length}
  1446. octagon(length)
  1447. end
  1448. if choice == "6-prism" or choice == "6 prism" then
  1449. local length = 0
  1450. local height = 0
  1451. if sim_mode == false and cmd_line == false then
  1452. length = getInput("int","How long does each side need to be?")
  1453. height = getInput("int","What height does it need to be?")
  1454. elseif sim_mode == true or cmd_line == true then
  1455. length = tempProgTable.param1
  1456. height = tempProgTable.param2
  1457. end
  1458. tempProgTable.param1 = length
  1459. tempProgTable.param2 = height
  1460. progTable = {param1 = length, param2 = height}
  1461. sixprism(length, height)
  1462. end
  1463. if choice == "8-prism" or choice == "8 prism" then
  1464. local length = 0
  1465. local height = 0
  1466. if sim_mode == false and cmd_line == false then
  1467. length = getInput("int","How long does each side need to be?")
  1468. height = getInput("int","What height does it need to be?")
  1469. elseif sim_mode == true or cmd_line == true then
  1470. length = tempProgTable.param1
  1471. height = tempProgTable.param2
  1472. end
  1473. tempProgTable.param1 = length
  1474. tempProgTable.param2 = height
  1475. progTable = {param1 = length, param2 = height}
  1476. eightprism(length, height)
  1477. end
  1478. if returntohome then
  1479. goHome() -- After all shape building has finished
  1480. end
  1481. writeOut("Done") -- Saves a few lines when put here rather than in each if statement
  1482. end
  1483.  
  1484. function WriteMenu()
  1485. term.clear()
  1486. term.setCursorPos(1, 1)
  1487. writeOut("Shape Maker 1.5 by Keridos/Happydude/pokemane")
  1488. if resupply then -- Any ideas to make this more compact/betterlooking (in terms of code)?
  1489. writeOut("Resupply Mode Active")
  1490. elseif (resupply and can_use_gps) then
  1491. writeOut("Resupply and GPS Mode Active")
  1492. elseif can_use_gps then
  1493. writeOut("GPS Mode Active")
  1494. else
  1495. writeOut("")
  1496. end
  1497. if not cmd_line then
  1498. writeOut("What should be built? [page 1/2]");
  1499. writeOut("next for page 2")
  1500. writeOut("+---------+-----------+-------+-------+")
  1501. writeOut("| square | rectangle | wall | line |")
  1502. writeOut("| cylinder| platform | stair | cuboid|")
  1503. writeOut("| pyramid | 1/2-sphere| circle| next |")
  1504. writeOut("+---------+-----------+-------+-------+")
  1505. writeOut("")
  1506. end
  1507. end
  1508.  
  1509. function WriteMenu2()
  1510. term.clear()
  1511. term.setCursorPos(1, 1)
  1512. writeOut("Shape Maker 1.5 by Keridos/Happydude/pokemane")
  1513. if resupply then -- Any ideas to make this more compact/betterlooking (in terms of code)?
  1514. writeOut("Resupply Mode Active")
  1515. elseif (resupply and can_use_gps) then
  1516. writeOut("Resupply and GPS Mode Active")
  1517. elseif can_use_gps then
  1518. writeOut("GPS Mode Active")
  1519. else
  1520. writeOut("")
  1521. end
  1522. writeOut("What should be built [page 2/2]?");
  1523. writeOut("")
  1524. writeOut("+---------+-----------+-------+-------+")
  1525. writeOut("| hexagon | octagon | help | |")
  1526. writeOut("| 6-prism | 8-prism | end | |")
  1527. writeOut("| sphere | credits | | |")
  1528. writeOut("+---------+-----------+-------+-------+")
  1529. writeOut("")
  1530. end
  1531.  
  1532. function showHelp()
  1533. writeOut("Usage: shape [shape-type [param1 param2 param3 ...]] [-c] [-h] [-z] [-r]")
  1534. writeOut("-c: Activate cost only mode")
  1535. writeOut("-h: Show this page")
  1536. writeOut("-z: Set chain_next_shape to true, lets you chain together multiple shapes")
  1537. io.read() -- Pause here
  1538. writeOut("-r: Resume the last shape if there is a resume file")
  1539. writeOut("shape-type can be any of the shapes in the menu")
  1540. writeOut("After shape-type input all of the paramaters for the shape")
  1541. io.read() -- Pause here, too
  1542. end
  1543.  
  1544. function showCredits()
  1545. writeOut("Credits for the shape builder:")
  1546. writeOut("Based on work by Michiel,Vliekkie, and Aeolun")
  1547. writeOut("Sphere/dome code by pruby")
  1548. writeOut("Additional improvements by Keridos,Happydude and pokemane")
  1549. io.read() -- Pause here, too
  1550. end
  1551.  
  1552. function main()
  1553. if wrapmodules()=="resupply" then
  1554. linkToRSStation()
  1555. end
  1556. if checkCommandLine() then
  1557. if needsHelp() then
  1558. showHelp()
  1559. return -- Close the program after help info is shown
  1560. end
  1561. setFlagsFromCommandLine()
  1562. setTableFromCommandLine()
  1563. end
  1564. 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
  1565. if not continueQuery() then -- If the user doesn't want to continue
  1566. ProgressFileDelete()
  1567. setSimFlags(false) -- Just to be safe
  1568. WriteMenu()
  1569. choiceFunction()
  1570. else -- If the user wants to continue
  1571. setSimFlags(true)
  1572. choiceFunction()
  1573. end
  1574. else
  1575. setSimFlags(false)
  1576. WriteMenu()
  1577. choiceFunction()
  1578. end
  1579. if (blocks ~= 0) and (fuel ~= 0) then -- Do not show on help or credits page or when selecting end
  1580. writeOut("Blocks used: " .. blocks)
  1581. writeOut("Fuel used: " .. fuel)
  1582. end
  1583. ProgressFileDelete() -- Removes file upon successful completion of a job, or completion of a previous job.
  1584. progTable = {}
  1585. tempProgTable = {}
  1586. end
  1587.  
  1588. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement