spankyTheBeaver

Castle46

Jul 23rd, 2023 (edited)
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 40.45 KB | None | 0 0
  1. -----------Castle in a turtle--------
  2.              --main v4.6---
  3.  
  4. --[[
  5. To do:
  6. -key presses moeten via keys api voor cc tweaked            -done
  7. -functies updaten zoals tower v4.2 voor cc tweaked          -done
  8. -plaatsing disk misschien niet bestand tegen gravel/sand    -ignore
  9. -iets mis met alarm in tower                                -probably done, check it
  10. -tower start opnieuw met server restart                     -done
  11. -base toevoegen                                             -in progress
  12. -model 2 toevoegen                                          -done
  13. -model 3 toevoegen                                          -done
  14. -orientatie bij plaatsing wall                              -done
  15. -center tower                                               -done
  16. -zuigen met mate in wall                                    -done
  17. -up after placement                                         -done
  18. -enderchest automatisch printen                             -kan niet meer met cc tweaked                      
  19. -resume voorkomen                                           -done
  20. -chunkloaders                                               -beter in de map doen of erbij blijven
  21. -grass fucks up placement of turtles and disk drives        -done
  22. -modem aan zelfde kant als diskdrive kan niet (no wireless? achterkant?)    -done
  23. -als directory bestaat, verwijderen                         -done
  24. -setup wall stuff same as tower stuff                       -done
  25. --]]
  26.  
  27. -------------pastebin links--------------
  28. local tower = "v5dhVpG0" --updated to tower v4.2 2023-07-16
  29. local wall = "712PwYyU"  --updated to wall v2.1  2023-07-16
  30. local base = ""          --moet nog
  31.  
  32. ------------design parameters-----------------
  33. -- towerdiam 22 en wallheigt 20 kan wel maar is erg krap
  34. -- 24 en 18 lijkt beter
  35. -- 8 en 5 is lelijk maar werkt voor testen
  36.  
  37. local towerDiamList = {24,24,24,24,24,24,24,24}    
  38. local towerHeightList = {40,40,40,40,40,40,40,40}  
  39. local overhangList = {2,2,2,2,2,2,2,2}              --overhang van het dak, 2 is vaak het beste
  40. local towerDistance = 64                            --afstand tussen torens
  41. local walHeight = 18                                --muurhoogte
  42. local wallWidth = 5                                 --muurbreedte
  43. local wallLength = {}
  44. local slots = 1
  45. local turtleSlot = 1
  46. local fuelChestSlot = 2
  47. local materialChestSlot = 3
  48. local roofChestSlot = 4
  49. local roofSupportChestSlot = 5
  50. local diskDriveSlot = 6
  51. local diskSlot = 7
  52. local rommelSlot = 8
  53. local fuelSlot = 16
  54. local facing = 1 --orientatie is arbitrair zonder GPS, gebruik noord als interne benaming voor start facing
  55. local facings = {"north", "east", "south", "west"}
  56. local dx = {0, 1, 0, -1}
  57. local dz = {-1, 0, 1, 0}
  58. local home = vector.new(0, 0, 0)
  59. local current = vector.new(0, 0, 0)
  60. local target = vector.new(0, 0, 0)
  61.  
  62. ----------counting stuff-----------------
  63. local wallMaterialQTY = 0
  64. local roofMaterialQTY = 0
  65. local supportQTY = 0
  66.  
  67. ----------------menu stuff-----------------------
  68. local model = 1
  69. local modelMax = 3
  70. local offset = 22
  71. local kontgaatje = false        --used as enter in gui()
  72. local passed = false            --used in valseStart()
  73. local option = 1
  74. local optionMax = 8
  75. local preset = "Medium"
  76.  
  77. ------------start positions-----------------
  78. local towerPos1 = vector.new(0, 0, 0)
  79. local towerPos2 = vector.new(0, 0, 0)
  80. local towerPos3 = vector.new(0, 0, 0)
  81. local towerPos4 = vector.new(0, 0, 0)
  82. local towerPos5 = vector.new(0, 0, 0)
  83. local towerPos6 = vector.new(0, 0, 0)
  84. local towerPos7 = vector.new(0, 0, 0)
  85. local towerPos8 = vector.new(0, 0, 0)
  86. local wallPos1 = vector.new(0, 0, 0)
  87. local wallPos2 = vector.new(0, 0, 0)
  88. local wallPos3 = vector.new(0, 0, 0)
  89. local wallPos4 = vector.new(0, 0, 0)
  90. local wallPos5 = vector.new(0, 0, 0)
  91. local wallPos6 = vector.new(0, 0, 0)
  92. local wallPos7 = vector.new(0, 0, 0)
  93. local wallPos8 = vector.new(0, 0, 0)
  94. local wallDir1 = ""
  95. local wallDir2 = ""
  96. local wallDir3 = ""
  97. local wallDir4 = ""
  98. local wallDir5 = ""
  99. local wallDir6 = ""
  100. local wallDir7 = ""
  101. local wallDir8 = ""
  102. local wallDir9 = ""
  103.  
  104. function round(num, idp)
  105.   local mult = 10^(idp or 0)
  106.   return math.floor(num * mult + 0.5) / mult
  107. end
  108.  
  109. function reFuel()--met 64 fuel moet hij het wel redden
  110.     if turtle.getFuelLevel() < 16 then
  111.         turtle.select(fuelSlot)
  112.         turtle.refuel(8)
  113.         if turtle.getFuelLevel() < 16 then
  114.             term.clear()
  115.             term.setCursorPos(1,1)
  116.             print("Give me some fuel and press enter")
  117.             read()
  118.             reFuel()
  119.         end    
  120.     end
  121. end
  122.  
  123. function turtleLeft()
  124.     facing = facing - 1
  125.     facing = (facing - 1) % 4  
  126.     facing = facing + 1
  127.     turtle.turnLeft()
  128.     sendPos()
  129. end
  130.  
  131. function turtleRight()
  132.     facing = facing - 1
  133.     facing = (facing + 1) % 4      
  134.     facing = facing + 1
  135.     turtle.turnRight()
  136.     sendPos()
  137. end
  138.  
  139. function face(direction)
  140.     if direction == "north" then dir = 1
  141.     elseif direction == "east" then dir = 2
  142.     elseif direction == "south" then dir = 3
  143.     elseif direction == "west" then dir = 4
  144.     end
  145.     if dir - facing == 1 or dir - facing == -3 then
  146.         while direction ~= facings[facing] do
  147.             turtleRight()
  148.         end
  149.     else
  150.         while direction ~= facings[facing] do
  151.             turtleLeft()
  152.         end
  153.     end
  154. end
  155.  
  156. function goNorth(distance)
  157.     face("north")
  158.     local dist = 0
  159.     while dist < distance do
  160.         local moved = false
  161.         while not(moved) do
  162.             turtle.select(rommelSlot)
  163.             turtle.dig()
  164.             turtle.drop()
  165.             reFuel()
  166.             moved = turtle.forward()
  167.         end
  168.         dist = dist + 1
  169.         current.x = current.x + dx[facing]  --change in location will be looked up in tables
  170.         current.z = current.z + dz[facing]  --dx and dz, dependend on faci
  171.     end
  172. end
  173.  
  174. function goEast(distance)
  175.     face("east")
  176.     local dist = 0
  177.     while dist < distance do
  178.         local moved = false
  179.         while not(moved) do
  180.             turtle.select(rommelSlot)
  181.             turtle.dig()
  182.             turtle.drop()
  183.             reFuel()
  184.             moved = turtle.forward()
  185.         end
  186.         dist = dist + 1
  187.         current.x = current.x + dx[facing]  --change in location will be looked up in tables
  188.         current.z = current.z + dz[facing]  --dx and dz, dependend on faci
  189.     end
  190. end
  191.  
  192. function goSouth(distance)
  193.     face("south")
  194.     local dist = 0
  195.     while dist < distance do
  196.         local moved = false
  197.         while not(moved) do
  198.             turtle.select(rommelSlot)
  199.             turtle.dig()
  200.             turtle.drop()
  201.             reFuel()
  202.             moved = turtle.forward()
  203.         end
  204.         dist = dist + 1
  205.         current.x = current.x + dx[facing]  --change in location will be looked up in tables
  206.         current.z = current.z + dz[facing]  --dx and dz, dependend on faci
  207.     end
  208. end
  209.  
  210. function goWest(distance)
  211.     face("west")
  212.     local dist = 0
  213.     while dist < distance do
  214.         local moved = false
  215.         while not(moved) do
  216.             turtle.select(rommelSlot)
  217.             turtle.dig()
  218.             turtle.drop()
  219.             reFuel()
  220.             moved = turtle.forward()
  221.         end
  222.         dist = dist + 1
  223.         current.x = current.x + dx[facing]  --change in location will be looked up in tables
  224.         current.z = current.z + dz[facing]  --dx and dz, dependend on faci
  225.     end
  226. end
  227.  
  228. function goUp(distance)
  229.     local dist = 0
  230.     while dist < distance do
  231.         local moved = false
  232.         while not(moved) do
  233.             turtle.select(rommelSlot)
  234.             turtle.digUp()
  235.             turtle.drop()
  236.             reFuel()
  237.             moved = turtle.up()
  238.         end
  239.         dist = dist + 1
  240.         current.y = current.y + 1
  241.     end
  242. end
  243.  
  244. function goDown(distance)
  245.     local dist = 0
  246.     while dist < distance do
  247.         local moved = false
  248.         while not(moved) do
  249.             turtle.select(rommelSlot)
  250.             turtle.digDown()
  251.             turtle.drop()
  252.             reFuel()
  253.             moved = turtle.down()
  254.         end
  255.         dist = dist + 1
  256.         current.y = current.y - 1
  257.     end
  258. end
  259.  
  260. function moveXYZ(Xmove, Ymove, Zmove)
  261.     if Ymove > 0 then
  262.         goUp(Ymove)
  263.     elseif Ymove < 0 then
  264.         Ypooplicker = -1 * Ymove
  265.         goDown(Ypooplicker)
  266.     else
  267.     end
  268.     if Xmove > 0 then
  269.         goEast(Xmove)
  270.     elseif Xmove < 0 then
  271.         Xpooplicker = -1 * Xmove
  272.         goWest(Xpooplicker)
  273.     else
  274.     end
  275.     if Zmove > 0 then
  276.         goSouth(Zmove)
  277.     elseif Zmove < 0 then
  278.         Zpooplicker = -1 * Zmove
  279.         goNorth(Zpooplicker)
  280.     else
  281.     end
  282. end
  283.  
  284. function moveToXYZ(Xtarget, Ytarget, Ztarget)
  285.     local desiredPos = vector.new(Xtarget, Ytarget, Ztarget)
  286.     currentPos = vector.new(current.x, current.y, current.z)
  287.     local toMove = desiredPos - currentPos
  288.     moveXYZ(toMove.x, toMove.y, toMove.z)
  289. end
  290.  
  291. function fwrite(path, text)
  292.     local file = assert(io.open(path, "w"))
  293.     file:write(text)
  294.     file:close()
  295. end
  296.  
  297. function split(s, delimiter)
  298.     result = {};
  299.     for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  300.         table.insert(result, match);
  301.     end
  302.     return result;
  303. end
  304.  
  305. function sendPos()
  306.     if resume then
  307.         fwrite("turtlePos", current.x..", "..current.y..", "..current.z..", "..facing..", "..quarryStart.x..", "..quarryStart.y..", "..quarryStart.z..", "..quarryEnd.x..", "..quarryEnd.y..", "..quarryEnd.z..", "..action)
  308.     else
  309.     end
  310. end
  311.  
  312. function digForwards(distance)
  313.     local dist = 0
  314.     while dist < distance do
  315.         local moved = false
  316.         while not(moved) do
  317.             turtle.select(rommelSlot)
  318.             turtle.dig()
  319.             turtle.drop()
  320.             moved = turtle.forward()
  321.         end
  322.         dist = dist + 1
  323.         current.x = current.x + dx[facing]  --change in location will be looked up in tables
  324.         current.z = current.z + dz[facing]  --dx and dz, dependend on faci
  325.         reFuel()
  326.     end
  327. end
  328.  
  329. function placer(what, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) 
  330. --[[ Syntax:
  331. Tower v4.2:
  332. placer("tower", 20, 2, 2, 1) voor toren diam=20 h=2, overhang=2, autostart=true
  333.  
  334. Wall v2.1:
  335. placer direction height width distance kantelen needRoof roofHeight supportInterval fancyRoof Autostart
  336. placer("wall", angleLeft, 20, 5, 128, 1, 1, 3, 4, 1, 1) voor muur schuin naar links, 20 hoog,
  337. 5 breed, 128 lang, met kantelen, met dak, 3 hoog dak, om de 4 blokjes een support, met fancyroof, autostart
  338. --]]
  339.  
  340.     fs.delete("disk")   --in geval dit als directory aanwezig was
  341.     turtle.select(rommelSlot)   --zooi opruimen
  342.     turtle.dig()--dit werkt vast niet als er gravel of sand is
  343.     goUp(1)
  344.     turtle.dig()
  345.     if what == "tower" then
  346.         slots = 4
  347.     elseif what == "wall" then
  348.         slots = 5
  349.     else
  350.     end
  351.     goDown(slots-1)
  352.  
  353.     while slots > 0 do 
  354.         goUp(1)
  355.         local placed = false--turtle, kistjes en diskdrive plaatsen
  356.         while not placed do --turtle=1, fuel=2, material=3, roof=4, roofSupport=5
  357.             turtle.select(rommelSlot)
  358.             turtle.dig()
  359.             turtle.select(slots)
  360.             local zaadlap = false   --grass fix
  361.             while not zaadlap do
  362.                 placed = turtle.place()
  363.                 zaadlap = turtle.detect()
  364.             end
  365.         end
  366.         slots = slots - 1
  367.     end
  368.  
  369.     goUp(1) --tot boven turtle
  370.     turtle.select(diskDriveSlot)   
  371.     local placed = false    --diskdrive=6
  372.     while not placed do
  373.         turtle.select(rommelSlot)
  374.         turtle.dig()
  375.         turtle.select(diskDriveSlot)   
  376.         local spermalap = false --grass fix
  377.         while not spermalap do
  378.             placed = turtle.place()
  379.             spermalap = turtle.detect()
  380.         end
  381.     end
  382.     turtle.select(diskSlot)
  383.     turtle.drop()   --disk=7
  384.  
  385.     if what == "tower" then                     --tower
  386.         fs.delete("disk/startup")
  387.         file = fs.open("disk/startup","w")  --startup op disk
  388.         file.write(
  389.         [[
  390.             fs.copy("disk/install","startup")
  391.             fs.delete("disk/startup")
  392.             fs.copy("disk/tower","tower")
  393.             fs.delete("disk/tower")
  394.             sleep(5)
  395.             os.reboot()
  396.         ]])
  397.         file.close()
  398.         fs.delete("disk/install")
  399.         file = fs.open("disk/install","w")      --startup van de turtle is: tower diam hoogte overhang autostart
  400.         file.write(
  401.         [[
  402.             shell.run("tower ]]..arg1.." "..arg2.." "..arg3.." "..arg4..[[")
  403.         ]])
  404.         file.close()
  405.         fs.delete("disk/tower")
  406.         shell.run("pastebin get "..tower.." disk/tower")    --programma tower pakken
  407.     elseif what == "wall" then                  --wall
  408.         fs.delete("disk/startup")
  409.         file = fs.open("disk/startup","w")  --startup op disk
  410.         file.write(
  411.         [[
  412.             fs.copy("disk/install","startup")
  413.             fs.delete("disk/startup")
  414.             fs.copy("disk/wall","wall")
  415.             fs.delete("disk/wall")
  416.             sleep(5)
  417.             os.reboot()
  418.         ]])
  419.         file.close()
  420.         fs.delete("disk/install")  
  421.         file = fs.open("disk/install","w")      --startup van de turtle is: wall ...
  422.         file.write(
  423.         [[
  424.             shell.run("wall ]]..arg1.." "..arg2.." "..arg3.." "..arg4.." "..arg5.." "..arg6.." "..arg7.." "..arg8.." "..arg9.." "..arg10..[[")
  425.         ]])
  426.         file.close()
  427.         fs.delete("disk/wall")
  428.         shell.run("pastebin get "..wall.." disk/wall")  --programma wall pakken
  429.     elseif what == "base" then
  430.         fs.delete("disk/startup")
  431.         file = fs.open("disk/startup","w")  --startup op disk
  432.         file.write(
  433.         [[
  434.             fs.copy("disk/install","startup")
  435.             fs.delete("disk/startup")
  436.             fs.copy("disk/wall","base")
  437.             fs.delete("disk/base")
  438.             sleep(5)
  439.             os.reboot()
  440.         ]])
  441.         file.close()
  442.         fs.delete("disk/install")  
  443.         file = fs.open("disk/install","w")      --startup van de turtle is: base ...
  444.         file.write(
  445.         [[
  446.             shell.run("base ]]..arg1.." "..arg2.." "..arg3.." "..arg4.." "..arg5.." "..arg6.." "..arg7.." "..arg8.." "..arg9.." "..arg10..[[")
  447.         ]])
  448.         file.close()
  449.         fs.delete("disk/base")
  450.         shell.run("pastebin get "..base.." disk/base")  --programma base pakken        
  451.     end
  452.     goDown(1)  
  453.     peripheral.call("front","turnOn")  
  454.     goUp(1)    
  455.     turtle.select(diskSlot)
  456.     turtle.suck()       --disk
  457.     turtle.select(diskDriveSlot)
  458.     turtle.dig()        --disk drive
  459. end
  460.  
  461. function natteScheet()--de functie die het harde werk doet
  462. --[[
  463. Schets: mag geen hyperlink bij pastebin
  464.  
  465. Begin posities torens is center, walls is rand van toren midden van de muur
  466. Turtle begint op 0,0,0
  467. Diam is de diameter voor elke toren respectievelijk
  468. dist = towerDistance
  469.  
  470. Wall:
  471. placer direction height width distance kantelen needRoof roofHeight supportInterval fancyRoof Autostart
  472. placer("wall", angleLeft, 20, 5, 128, 1, 1, 3, 4, 1, 1) voor muur schuin naar links, 20 hoog,
  473. 5 breed, 128 lang, met kantelen, met dak, 3 hoog dak, om de 4 blokjes een support, met fancyroof, autostart
  474. ]]--
  475.     if model == 1 then  --start posities enzo uitrekenen afhankelijk van model en tower diam
  476. --      *--*   
  477. --      |  |
  478. --      *--*
  479.         towerPos1 = vector.new(towerDiamList[1]/2, 0, -towerDiamList[1]/2)
  480.         towerPos2 = vector.new(towerPos1.x + towerDistance, 0, towerPos1.z)
  481.         towerPos3 = vector.new(towerPos2.x, 0, towerPos1.z - towerDistance)
  482.         towerPos4 = vector.new(towerPos1.x, 0, towerPos3.z)
  483.         wallPos1 = vector.new(towerDiamList[1], -3, towerPos1.z)
  484.         wallPos2 = vector.new(towerPos2.x, -3, -towerDiamList[1])
  485.         wallPos3 = vector.new(towerDistance, -3, towerPos3.z)
  486.         wallPos4 = vector.new(towerPos1.x, -3, towerPos3.z + towerDiamList[1]/2)
  487.         wallDir1 = "east"
  488.         wallDir2 = "north"
  489.         wallDir3 = "west"
  490.         wallDir4 = "south"
  491.         towerDiamList[5] = towerDiamList[1]
  492.         n=1
  493.         while n < 5 do
  494.         wallLength[n] = towerDistance - math.floor((towerDiamList[n] + towerDiamList[n+1])/2)
  495.         n = n + 1
  496.         end
  497.         ----------------------aan de slag---------------------------
  498.         term.clear()
  499.         term.setCursorPos(1,1)
  500.        
  501.         moveToXYZ(towerPos1.x, towerPos1.y, towerPos1.z)
  502.         placer("tower", towerDiamList[1], towerHeightList[1], overhangList[1], 1)
  503.         moveToXYZ(wallPos1.x,wallPos1.y + 10,wallPos1.z)   
  504.         moveToXYZ(wallPos1.x,wallPos1.y,wallPos1.z)
  505.         face(wallDir1)
  506.         placer("wall", "straight", walHeight, wallWidth, wallLength[1], 1, 1, 3, 4, 1, 1)
  507.        
  508.         moveToXYZ(towerPos2.x, towerPos2.y + 10, towerPos2.z)  
  509.         moveToXYZ(towerPos2.x, towerPos2.y, towerPos2.z)
  510.         placer("tower", towerDiamList[2], towerHeightList[2], overhangList[2], 1)
  511.         moveToXYZ(wallPos2.x,wallPos2.y + 10,wallPos2.z)
  512.         moveToXYZ(wallPos2.x,wallPos2.y,wallPos2.z)
  513.         face(wallDir2)
  514.         placer("wall", "straight", walHeight, wallWidth, wallLength[2], 1, 1, 3, 4, 1, 1)
  515.        
  516.         moveToXYZ(towerPos3.x, towerPos3.y + 10, towerPos3.z)
  517.         moveToXYZ(towerPos3.x, towerPos3.y, towerPos3.z)
  518.         placer("tower", towerDiamList[3], towerHeightList[3], overhangList[3], 1)
  519.         moveToXYZ(wallPos3.x,wallPos3.y + 10,wallPos3.z)
  520.         moveToXYZ(wallPos3.x,wallPos3.y,wallPos3.z)
  521.         face(wallDir3)
  522.         placer("wall", "straight", walHeight, wallWidth, wallLength[3], 1, 1, 3, 4, 1, 1)
  523.        
  524.         moveToXYZ(towerPos4.x, towerPos4.y + 10, towerPos4.z)
  525.         moveToXYZ(towerPos4.x, towerPos4.y, towerPos4.z)
  526.         placer("tower", towerDiamList[4], towerHeightList[4], overhangList[4], 1)
  527.         moveToXYZ(wallPos4.x,wallPos4.y + 10,wallPos4.z)
  528.         moveToXYZ(wallPos4.x,wallPos4.y,wallPos4.z)
  529.         face(wallDir4)
  530.         placer("wall", "straight", walHeight, wallWidth, wallLength[4], 1, 1, 3, 4, 1, 1)
  531.                
  532.     elseif model == 2 then--start posities enzo uitrekenen afhankelijk van model en tower diam
  533. --        *--*     
  534. --       /    \
  535. --      *      *
  536. --       \    /
  537. --        *--*
  538.         towerPos1 = vector.new(towerDiamList[1]/2, 0, -towerDiamList[1]/2)
  539.         towerPos2 = vector.new(towerPos1.x + towerDistance, 0, towerPos1.z)
  540.         towerPos3 = vector.new(towerPos2.x + round(math.sqrt(towerDistance^2/2),0), 0, round(towerPos1.z-math.sqrt(towerDistance^2/2),0))
  541.         towerPos4 = vector.new(towerPos2.x, 0, towerPos1.z - round(2*math.sqrt(towerDistance^2/2),0))
  542.         towerPos5 = vector.new(towerPos1.x, 0, towerPos4.z)
  543.         towerPos6 = vector.new((towerPos1.x - round(math.sqrt(towerDistance^2/2),0)), 0, towerPos3.z)
  544.          
  545.         wallPos1 = vector.new(towerDiamList[1], -3, towerPos1.z)
  546.         wallDir1 = "east" --straight
  547.         wallLength[1] = towerDistance - math.floor((towerDiamList[1] + towerDiamList[2])/2)
  548.        
  549.         wallPos2 = vector.new(towerPos2.x + round(math.sqrt((towerDiamList[2]/2)^2/2),0), -3, towerPos2.z - round(math.sqrt((towerDiamList[2]/2)^2/2),0))
  550.         wallDir2 = "east" --angle left
  551.         wallLength[2] = towerDistance - math.floor((towerDiamList[2] + towerDiamList[3])/2)
  552.        
  553.         wallPos3 = vector.new(towerPos3.x - round(math.sqrt((towerDiamList[3]/2)^2/2),0), -3, towerPos3.z - round(math.sqrt((towerDiamList[3]/2)^2/2),0))
  554.         wallDir3 = "north" --angle left
  555.         wallLength[3] = towerDistance - math.floor((towerDiamList[3] + towerDiamList[4])/2)
  556.        
  557.         wallPos4 = vector.new(towerPos4.x - round(towerDiamList[4]/2,0), -3, towerPos4.z)
  558.         wallDir4 = "west" --straight
  559.         wallLength[4] = towerDistance - math.floor((towerDiamList[4] + towerDiamList[5])/2)
  560.        
  561.         wallPos5 = vector.new(towerPos5.x - round(math.sqrt((towerDiamList[5]/2)^2/2),0), -3, towerPos5.z + round(math.sqrt((towerDiamList[5]/2)^2/2),0))
  562.         wallDir5 = "west" --angle left
  563.         wallLength[5] = towerDistance - math.floor((towerDiamList[5] + towerDiamList[6])/2)
  564.        
  565.         wallPos6 = vector.new(towerPos6.x + round(math.sqrt((towerDiamList[6]/2)^2/2),0), -3, towerPos6.z + round(math.sqrt((towerDiamList[6]/2)^2/2),0))
  566.         wallDir6 = "south" --angle left
  567.         wallLength[6] = towerDistance - math.floor((towerDiamList[6] + towerDiamList[1])/2)
  568.         ----------------------aan de slag---------------------------
  569.         term.clear()
  570.         term.setCursorPos(1,1)
  571.        
  572.         moveToXYZ(towerPos1.x, towerPos1.y, towerPos1.z)
  573.         placer("tower", towerDiamList[1], towerHeightList[1], overhangList[1], 1)
  574.         moveToXYZ(wallPos1.x,wallPos1.y + 10,wallPos1.z)   
  575.         moveToXYZ(wallPos1.x,wallPos1.y,wallPos1.z)
  576.         face(wallDir1)
  577.         placer("wall", "straight", walHeight, wallWidth, wallLength[1], 1, 1, 3, 4, 1, 1)
  578.        
  579.         moveToXYZ(towerPos2.x, towerPos2.y + 10, towerPos2.z)  
  580.         moveToXYZ(towerPos2.x, towerPos2.y, towerPos2.z)
  581.         placer("tower", towerDiamList[2], towerHeightList[2], overhangList[2], 1)
  582.         moveToXYZ(wallPos2.x,wallPos2.y + 10,wallPos2.z)
  583.         moveToXYZ(wallPos2.x,wallPos2.y,wallPos2.z)
  584.         face(wallDir2)
  585.         placer("wall", "angleLeft", walHeight, wallWidth, wallLength[2], 1, 1, 3, 4, 1, 1)
  586.        
  587.         moveToXYZ(towerPos3.x, towerPos3.y + 10, towerPos3.z)
  588.         moveToXYZ(towerPos3.x, towerPos3.y, towerPos3.z)
  589.         placer("tower", towerDiamList[3], towerHeightList[3], overhangList[3], 1)
  590.         moveToXYZ(wallPos3.x,wallPos3.y + 10,wallPos3.z)
  591.         moveToXYZ(wallPos3.x,wallPos3.y,wallPos3.z)
  592.         face(wallDir3)
  593.         placer("wall", "angleLeft", walHeight, wallWidth, wallLength[3], 1, 1, 3, 4, 1, 1)
  594.        
  595.         moveToXYZ(towerPos4.x, towerPos4.y + 10, towerPos4.z)
  596.         moveToXYZ(towerPos4.x, towerPos4.y, towerPos4.z)
  597.         placer("tower", towerDiamList[4], towerHeightList[4], overhangList[4], 1)
  598.         moveToXYZ(wallPos4.x,wallPos4.y + 10,wallPos4.z)
  599.         moveToXYZ(wallPos4.x,wallPos4.y,wallPos4.z)
  600.         face(wallDir4)
  601.         placer("wall", "straight", walHeight, wallWidth, wallLength[4], 1, 1, 3, 4, 1, 1)
  602.  
  603.         moveToXYZ(towerPos5.x, towerPos5.y + 10, towerPos5.z)
  604.         moveToXYZ(towerPos5.x, towerPos5.y, towerPos5.z)
  605.         placer("tower", towerDiamList[5], towerHeightList[5], overhangList[5], 1)
  606.         moveToXYZ(wallPos5.x,wallPos5.y + 10,wallPos5.z)
  607.         moveToXYZ(wallPos5.x,wallPos5.y,wallPos5.z)
  608.         face(wallDir5)
  609.         placer("wall", "angleLeft", walHeight, wallWidth, wallLength[5], 1, 1, 3, 4, 1, 1) 
  610.  
  611.         moveToXYZ(towerPos6.x, towerPos6.y + 10, towerPos6.z)
  612.         moveToXYZ(towerPos6.x, towerPos6.y, towerPos6.z)
  613.         placer("tower", towerDiamList[6], towerHeightList[6], overhangList[6], 1)
  614.         moveToXYZ(wallPos6.x,wallPos6.y + 10,wallPos6.z)
  615.         moveToXYZ(wallPos6.x,wallPos6.y,wallPos6.z)
  616.         face(wallDir6)
  617.         placer("wall", "angleLeft", walHeight, wallWidth, wallLength[6], 1, 1, 3, 4, 1, 1)
  618.  
  619.     elseif model == 3 then
  620. --          *--*
  621. --         /    \
  622. --        *      *
  623. --        |      |
  624. --        *      *
  625. --         \    /
  626. --          *--*
  627.         towerPos1 = vector.new(towerDiamList[1]/2, 0, -towerDiamList[1]/2)
  628.         towerPos2 = vector.new(towerPos1.x + towerDistance, 0, towerPos1.z)
  629.         towerPos3 = vector.new(towerPos2.x + round(math.sqrt(towerDistance^2/2),0), 0, round(towerPos1.z-math.sqrt(towerDistance^2/2),0))
  630.         towerPos4 = vector.new(towerPos3.x, 0, towerPos3.z - towerDistance)
  631.         towerPos5 = vector.new(towerPos2.x, 0, towerPos4.z - round(math.sqrt(towerDistance^2/2),0))
  632.         towerPos6 = vector.new(towerPos1.x, 0, towerPos5.z)
  633.         towerPos7 = vector.new(towerPos1.x - round(math.sqrt(towerDistance^2/2),0), 0, towerPos4.z)
  634.         towerPos8 = vector.new(towerPos7.x, 0, towerPos3.z)
  635.        
  636.         wallPos1 = vector.new(towerDiamList[1], -3, towerPos1.z)
  637.         wallDir1 = "east" --straight
  638.         wallLength[1] = towerDistance - math.floor((towerDiamList[1] + towerDiamList[2])/2)
  639.        
  640.         wallPos2 = vector.new(towerPos2.x + round(math.sqrt((towerDiamList[2]/2)^2/2),0), -3, towerPos2.z - round(math.sqrt((towerDiamList[2]/2)^2/2),0))
  641.         wallDir2 = "east" --angle left
  642.         wallLength[2] = towerDistance - math.floor((towerDiamList[2] + towerDiamList[3])/2)
  643.        
  644.         wallPos3 = vector.new(towerPos3.x, -3, towerPos3.z - round(towerDiamList[3]/2,0))
  645.         wallDir3 = "north" --straight
  646.         wallLength[3] = towerDistance - math.floor((towerDiamList[3] + towerDiamList[4])/2)
  647.        
  648.         wallPos4 = vector.new(towerPos4.x - round(math.sqrt((towerDiamList[4]/2)^2/2),0), -3, towerPos4.z - round(math.sqrt((towerDiamList[4]/2)^2/2),0))
  649.         wallDir4 = "north" --angle left
  650.         wallLength[4] = towerDistance - math.floor((towerDiamList[4] + towerDiamList[5])/2)
  651.        
  652.         wallPos5 = vector.new(towerPos5.x - round(towerDiamList[5]/2,0), -3, towerPos5.z)
  653.         wallDir5 = "west" --straight
  654.         wallLength[5] = towerDistance - math.floor((towerDiamList[5] + towerDiamList[6])/2)
  655.        
  656.         wallPos6 = vector.new(towerPos6.x - round(math.sqrt((towerDiamList[6]/2)^2/2),0), -3, towerPos6.z + round(math.sqrt((towerDiamList[6]/2)^2/2),0))
  657.         wallDir6 = "west" --angle left
  658.         wallLength[6] = towerDistance - math.floor((towerDiamList[6] + towerDiamList[7])/2)
  659.        
  660.         wallPos7 = vector.new(towerPos7.x, -3, towerPos7.z + round(towerDiamList[7]/2,0))
  661.         wallDir7 = "south" --straight
  662.         wallLength[7] = towerDistance - math.floor((towerDiamList[7] + towerDiamList[8])/2)    
  663.    
  664.         wallPos8 = vector.new(towerPos8.x + round(math.sqrt((towerDiamList[8]/2)^2/2),0), -3, towerPos8.z + round(math.sqrt((towerDiamList[8]/2)^2/2),0))
  665.         wallDir8 = "south" --angle left
  666.         wallLength[8] = towerDistance - math.floor((towerDiamList[8] + towerDiamList[1])/2)
  667.        
  668.         term.clear()
  669.         term.setCursorPos(1,1)
  670.        
  671.         moveToXYZ(towerPos1.x, towerPos1.y, towerPos1.z)
  672.         placer("tower", towerDiamList[1], towerHeightList[1], overhangList[1], 1)
  673.         moveToXYZ(wallPos1.x,wallPos1.y + 10, wallPos1.z)  
  674.         moveToXYZ(wallPos1.x,wallPos1.y,wallPos1.z)
  675.         face(wallDir1)
  676.         placer("wall", "straight", walHeight, wallWidth, wallLength[1], 1, 1, 3, 4, 1, 1)
  677.        
  678.         moveToXYZ(towerPos2.x, towerPos2.y + 10, towerPos2.z)  
  679.         moveToXYZ(towerPos2.x, towerPos2.y, towerPos2.z)
  680.         placer("tower", towerDiamList[2], towerHeightList[2], overhangList[2], 1)
  681.         moveToXYZ(wallPos2.x,wallPos2.y + 10, wallPos2.z)
  682.         moveToXYZ(wallPos2.x,wallPos2.y,wallPos2.z)
  683.         face(wallDir2)
  684.         placer("wall", "angleLeft", walHeight, wallWidth, wallLength[2], 1, 1, 3, 4, 1, 1)
  685.        
  686.         moveToXYZ(towerPos3.x, towerPos3.y, towerPos3.z)
  687.         placer("tower", towerDiamList[3], towerHeightList[3], overhangList[3], 1)
  688.         moveToXYZ(wallPos3.x,wallPos3.y + 10, wallPos3.z)  
  689.         moveToXYZ(wallPos3.x,wallPos3.y,wallPos3.z)
  690.         face(wallDir3)
  691.         placer("wall", "straight", walHeight, wallWidth, wallLength[3], 1, 1, 3, 4, 1, 1)      
  692.        
  693.         moveToXYZ(towerPos4.x, towerPos4.y + 10, towerPos4.z)  
  694.         moveToXYZ(towerPos4.x, towerPos4.y, towerPos4.z)
  695.         placer("tower", towerDiamList[4], towerHeightList[4], overhangList[4], 1)
  696.         moveToXYZ(wallPos4.x,wallPos4.y + 10, wallPos4.z)
  697.         moveToXYZ(wallPos4.x,wallPos4.y,wallPos4.z)
  698.         face(wallDir4)
  699.         placer("wall", "angleLeft", walHeight, wallWidth, wallLength[4], 1, 1, 3, 4, 1, 1)
  700.  
  701.         moveToXYZ(towerPos5.x, towerPos5.y, towerPos5.z)
  702.         placer("tower", towerDiamList[5], towerHeightList[5], overhangList[5], 1)
  703.         moveToXYZ(wallPos5.x,wallPos5.y + 10, wallPos5.z)  
  704.         moveToXYZ(wallPos5.x,wallPos5.y,wallPos5.z)
  705.         face(wallDir5)
  706.         placer("wall", "straight", walHeight, wallWidth, wallLength[5], 1, 1, 3, 4, 1, 1)  
  707.  
  708.         moveToXYZ(towerPos6.x, towerPos6.y + 10, towerPos6.z)  
  709.         moveToXYZ(towerPos6.x, towerPos6.y, towerPos6.z)
  710.         placer("tower", towerDiamList[6], towerHeightList[6], overhangList[6], 1)
  711.         moveToXYZ(wallPos6.x,wallPos6.y + 10, wallPos6.z)
  712.         moveToXYZ(wallPos6.x,wallPos6.y,wallPos6.z)
  713.         face(wallDir6)
  714.         placer("wall", "angleLeft", walHeight, wallWidth, wallLength[6], 1, 1, 3, 4, 1, 1)
  715.        
  716.         moveToXYZ(towerPos7.x, towerPos7.y, towerPos7.z)
  717.         placer("tower", towerDiamList[7], towerHeightList[7], overhangList[7], 1)
  718.         moveToXYZ(wallPos7.x,wallPos7.y + 10, wallPos7.z)  
  719.         moveToXYZ(wallPos7.x,wallPos7.y,wallPos7.z)
  720.         face(wallDir7)
  721.         placer("wall", "straight", walHeight, wallWidth, wallLength[7], 1, 1, 3, 4, 1, 1)
  722.        
  723.         moveToXYZ(towerPos8.x, towerPos8.y + 10, towerPos8.z)  
  724.         moveToXYZ(towerPos8.x, towerPos8.y, towerPos8.z)
  725.         placer("tower", towerDiamList[8], towerHeightList[8], overhangList[8], 1)
  726.         moveToXYZ(wallPos8.x,wallPos8.y + 10, wallPos8.z)
  727.         moveToXYZ(wallPos8.x,wallPos8.y,wallPos8.z)
  728.         face(wallDir8)
  729.         placer("wall", "angleLeft", walHeight, wallWidth, wallLength[8], 1, 1, 3, 4, 1, 1)
  730.     end
  731. end
  732.  
  733. --------------menu stuff-----------------
  734.  
  735. function plotTower(x, y)       
  736.     term.setBackgroundColor(colors.white)
  737.     term.setTextColor(colors.black)
  738.     local xt = x
  739.     while xt <= x + 1 do
  740.         local yt = y
  741.         while yt <= y + 1 do
  742.             term.setCursorPos(xt + offset,yt)
  743.             term.write(" ")
  744.             yt = yt + 1
  745.         end
  746.         xt = xt + 1
  747.     end
  748.     term.setBackgroundColor(colors.black)
  749.     term.setTextColor(colors.white)
  750. end
  751.  
  752. function plotWall(x, y, dir)   
  753.     term.setBackgroundColor(colors.black)
  754.     term.setTextColor(colors.white)
  755.     term.setCursorPos(x + offset,y)
  756.     muurRichting = tostring(dir)
  757.     if muurRichting == "1" then
  758.         term.write("|")
  759.     elseif muurRichting == "2" then
  760.         term.write("/")
  761.     elseif muurRichting == "3" then
  762.         term.write("-")
  763.     elseif muurRichting == "4" then
  764.         term.write("\\")
  765.     else
  766.         term.write(muurRichting)
  767.     end
  768. end
  769.  
  770. function design1() 
  771.     plotTower(7,4)
  772.     plotTower(11,4)
  773.     plotTower(7,8)
  774.     plotTower(11,8)
  775.     plotWall(9,5,3)
  776.     plotWall(10,5,3)
  777.     plotWall(8,6,1)
  778.     plotWall(8,7,1)
  779.     plotWall(11,6,1)
  780.     plotWall(11,7,1)
  781.     plotWall(9,8,3)
  782.     plotWall(10,8,3)
  783. end
  784.  
  785. function design2() 
  786.     plotTower(7,2)
  787.     plotTower(11,2)
  788.     plotTower(3,6)
  789.     plotTower(15,6)
  790.     plotTower(7,10)
  791.     plotTower(11,10)
  792.     plotWall(9,3,3)
  793.     plotWall(10,3,3)
  794.     plotWall(6,4,2)
  795.     plotWall(13,4,4)
  796.     plotWall(5,5,2)
  797.     plotWall(14,5,4)
  798.     plotWall(5,8,4)
  799.     plotWall(14,8,2)
  800.     plotWall(6,9,4)
  801.     plotWall(13,9,2)
  802.     plotWall(9,10,3)
  803.     plotWall(10,10,3)
  804. end
  805.  
  806. function design3() 
  807.     plotTower(7,2)
  808.     plotTower(11,2)
  809.     plotTower(4,5)
  810.     plotTower(14,5)
  811.     plotTower(4,9)
  812.     plotTower(14,9)
  813.     plotTower(7,12)
  814.     plotTower(11,12)
  815.     plotWall(9,3,3)
  816.     plotWall(10,3,3)
  817.     plotWall(6,4,2)
  818.     plotWall(13,4,4)
  819.     plotWall(5,7,1)
  820.     plotWall(14,7,1)
  821.     plotWall(5,8,1)
  822.     plotWall(14,8,1)
  823.     plotWall(6,11,4)
  824.     plotWall(13,11,2)
  825.     plotWall(9,12,3)
  826.     plotWall(10,12,3)
  827. end
  828.  
  829. function plot(plotwat) 
  830.     hoer = {doen = plotwat}
  831.     hoer.doen()
  832. end
  833.  
  834. function clearGraphic()
  835.     local breedte = offset + 1
  836.     while breedte < 39 do
  837.         local hoogte = 1
  838.         while hoogte < 14 do
  839.             term.setCursorPos(breedte, hoogte)
  840.             term.write(" ")
  841.             hoogte = hoogte + 1
  842.         end
  843.         breedte = breedte + 1
  844.     end
  845. end
  846.  
  847. function clearMenu()   
  848.     local breedte = 1
  849.     while breedte < offset do
  850.         local hoogte = 1
  851.         while hoogte < 13 do
  852.             term.setCursorPos(breedte, hoogte)
  853.             term.write(" ")
  854.             hoogte = hoogte + 1
  855.         end
  856.         breedte = breedte + 1
  857.     end
  858.     local lul = 1
  859.     while lul < 13 do
  860.         term.setCursorPos(offset + 1,lul)
  861.         print(".")
  862.         lul = lul + 1
  863.     end
  864. end
  865.  
  866. function gui()
  867.     term.clear()
  868.     while not kontgaatje do                     --while enter is not pressed do
  869.         clearGraphic()                          --do graphic
  870.         term.setCursorPos(7 + offset ,1)
  871.         print("model "..model)
  872.         if model == 1 then  --4 torens
  873.             plot(design1)
  874.         elseif model == 2 then
  875.             plot(design2)
  876.         elseif model == 3 then
  877.             plot(design3)
  878.         end
  879.         clearMenu()                             --do menu
  880.         term.setCursorPos(1,6)
  881.         print("  Use arrow keys to")
  882.         print(" select model and hit")
  883.         print("  enter to continue")
  884.         local event, key = os.pullEvent("key")  --do keyEvents
  885.         if key == keys.left then    --left
  886.             model = model - 2
  887.             model = model % modelMax
  888.             model = model + 1
  889.         elseif key == keys.right then   --right
  890.             model = model % modelMax
  891.             model = model + 1
  892.         elseif key == keys.enter then   --enter
  893.             kontgaatje = true
  894.         else
  895.             gui()
  896.         end
  897.     end
  898. end
  899.  
  900. function menu()
  901.     kontgaatje = false
  902.     while not kontgaatje do
  903.         term.clear()
  904.         term.setCursorPos(1,1)
  905.         print("Select variable to change.")
  906.         print("")
  907.         print("1-Tower specifications")
  908.         print("2-Wall specifications")
  909.         print("3-Presets")
  910.         print("")
  911.         print("Enter to continue with current specifications")
  912.         print("")
  913.         local event, key = os.pullEvent("key")
  914.         if key == keys.enter then   --enter
  915.             kontgaatje = true
  916.         elseif key == keys.one then --1
  917.             subMenuTower()
  918.             menu()
  919.         elseif key == keys.two then --2
  920.             subMenuWall()
  921.             menu()
  922.         elseif key == keys.three then   --3
  923.             subMenuPresets()
  924.             menu()
  925.         end
  926.     end
  927. end
  928.  
  929. function subMenuTower()
  930.     term.clear()
  931.     term.setCursorPos(1,1)
  932.     print("Tower specification:")
  933.     print("")
  934.     print("1-Height")
  935.     print("2-Diameter")
  936.     print("3-Roof overhang")
  937.     print("")
  938.     print("4-Back")
  939.     local event, key = os.pullEvent("key")
  940.     if key == keys.one then --1
  941.         subTowerHeight()
  942.         subMenuTower()
  943.     elseif key == keys.two then --2
  944.         subTowerDiam()
  945.         subMenuTower()
  946.     elseif key == keys.three then   --3
  947.         subTowerOverhang()
  948.         subMenuTower()
  949.     end
  950. end
  951.  
  952. function subTowerHeight()
  953.     kontgaatje = false
  954.     term.clear()
  955.     term.setCursorPos(1,1)
  956.     print("Tower heights: (Enter to go back)")
  957.     print("")
  958.     n=1
  959.     while n <= optionMax do
  960.         if option == n then
  961.         term.setBackgroundColor(colors.white)
  962.         term.setTextColor(colors.black)
  963.         else
  964.         term.setBackgroundColor(colors.black)
  965.         term.setTextColor(colors.white)
  966.         end
  967.         print("Tower "..n..": "..towerHeightList[n])
  968.         term.setBackgroundColor(colors.black)
  969.         term.setTextColor(colors.white)
  970.         n = n + 1
  971.     end
  972.     print("")
  973.     print("Up/down to select, +/- to change.")
  974.     local event, key = os.pullEvent("key")  --do keyEvents
  975.     if key == keys.down then    --down
  976.         option = option + 1
  977.         if option > optionMax then
  978.             option = 1
  979.         end
  980.     elseif key == keys.up then  --up
  981.         option = option - 1
  982.         if option < 1 then
  983.             option = optionMax
  984.         end
  985.     elseif key == keys.numPadAdd then   -- +
  986.         towerHeightList[option] = towerHeightList[option] + 1
  987.     elseif key == keys.numPadSubtract then  -- -
  988.         towerHeightList[option] = towerHeightList[option] - 1
  989.         if towerHeightList[option] < 1 then
  990.             towerHeightList[option] = 1
  991.         end
  992.     elseif key == keys.enter then   --enter
  993.         kontgaatje = true
  994.     end
  995.     if not kontgaatje then
  996.         subTowerHeight()
  997.     end
  998. end
  999.  
  1000. function subTowerDiam()
  1001.     kontgaatje = false
  1002.     term.clear()
  1003.     term.setCursorPos(1,1)
  1004.     print("Tower diameters: (Enter to go back)")
  1005.     print("")
  1006.     n=1
  1007.     while n <= optionMax do
  1008.         if option == n then
  1009.             term.setBackgroundColor(colors.white)
  1010.             term.setTextColor(colors.black)
  1011.         else
  1012.             term.setBackgroundColor(colors.black)
  1013.             term.setTextColor(colors.white)
  1014.         end
  1015.         print("Tower "..n..": "..towerDiamList[n])
  1016.         term.setBackgroundColor(colors.black)
  1017.         term.setTextColor(colors.white)
  1018.         n = n + 1
  1019.     end
  1020.     print("")
  1021.     print("Up/down to select, +/- to change.")
  1022.     local event, key = os.pullEvent("key")  --do keyEvents 
  1023.     if key == keys.down then    --down?
  1024.         option = option + 1
  1025.         if option > optionMax then
  1026.             option = 1
  1027.         end
  1028.     elseif key == keys.up then  --up?
  1029.         option = option - 1
  1030.         if option < 1 then
  1031.             option = optionMax
  1032.         end
  1033.     elseif key == keys.numPadAdd then   -- +
  1034.         towerDiamList[option] = towerDiamList[option] + 1
  1035.     elseif key == keys.numPadSubtract then  -- -
  1036.         towerDiamList[option] = towerDiamList[option] - 1
  1037.         if towerDiamList[option] < 1 then
  1038.             towerDiamList[option] = 1
  1039.         end
  1040.     elseif key == keys.enter then   --enter
  1041.         kontgaatje = true
  1042.     end
  1043.     if not kontgaatje then
  1044.         subTowerDiam()
  1045.     end
  1046. end
  1047.  
  1048. function subTowerOverhang()
  1049.     kontgaatje = false
  1050.     term.clear()
  1051.     term.setCursorPos(1,1)
  1052.     print("Tower roof overhang: (Enter to go back)")
  1053.     print("")
  1054.     n=1
  1055.     while n <= optionMax do
  1056.         if option == n then
  1057.             term.setBackgroundColor(colors.white)
  1058.             term.setTextColor(colors.black)
  1059.         else
  1060.             term.setBackgroundColor(colors.black)
  1061.             term.setTextColor(colors.white)
  1062.         end
  1063.         print("Tower "..n..": "..overhangList[n])
  1064.         term.setBackgroundColor(colors.black)
  1065.         term.setTextColor(colors.white)
  1066.         n = n + 1
  1067.         end
  1068.     print("")
  1069.     print("Up/down to select, +/- to change.") 
  1070.     local event, key = os.pullEvent("key")  --do keyEvents
  1071.     if key == keys.down then    --down
  1072.         option = option + 1
  1073.         if option > optionMax then
  1074.             option = 1
  1075.         end
  1076.     elseif key == keys.up then  --up
  1077.         option = option - 1
  1078.         if option < 1 then
  1079.             option = optionMax
  1080.         end
  1081.     elseif key == keys.numPadAdd then   -- +
  1082.         overhangList[option] = overhangList[option] + 1
  1083.     elseif key == keys.numPadSubtract then  -- -
  1084.         overhangList[option] = overhangList[option] - 1
  1085.         if overhangList[option] < 1 then
  1086.             overhangList[option] = 1
  1087.         end
  1088.     elseif key == keys.enter then   --enter
  1089.         kontgaatje = true
  1090.     end
  1091.     if not kontgaatje then
  1092.         subTowerOverhang()
  1093.     end
  1094. end
  1095.  
  1096. function subMenuWall()
  1097.     option = 1
  1098.     kontgaatje = false
  1099.     while not kontgaatje do
  1100.         term.clear()
  1101.         term.setCursorPos(1,1)
  1102.         print("Wall specification: (Enter to go back)")
  1103.         print("")
  1104.         if option == 1 then
  1105.             term.setBackgroundColor(colors.white)
  1106.             term.setTextColor(colors.black)
  1107.         end
  1108.         print("Height "..walHeight)
  1109.         term.setBackgroundColor(colors.black)
  1110.         term.setTextColor(colors.white)    
  1111.         if option == 2 then
  1112.             term.setBackgroundColor(colors.white)
  1113.             term.setTextColor(colors.black)
  1114.         end    
  1115.         print("Width "..wallWidth)
  1116.         term.setBackgroundColor(colors.black)
  1117.         term.setTextColor(colors.white)    
  1118.         if option == 3 then
  1119.             term.setBackgroundColor(colors.white)
  1120.             term.setTextColor(colors.black)
  1121.         end        
  1122.         print("Tower distance "..towerDistance)
  1123.         term.setBackgroundColor(colors.black)
  1124.         term.setTextColor(colors.white)
  1125.         print("")
  1126.         print("Up/down to select, +/- to change.")
  1127.         local event, key = os.pullEvent("key")
  1128.         if key == keys.down then    --down
  1129.             option = option + 1
  1130.             if option > 3 then
  1131.                 option = 1
  1132.             end
  1133.         elseif key == keys.up then  --up
  1134.             option = option - 1
  1135.             if option < 1 then
  1136.                 option = 3
  1137.             end
  1138.         elseif key == keys.numPadAdd then   -- +
  1139.             if option == 1 then
  1140.                 walHeight = walHeight + 1
  1141.             elseif option == 2 then
  1142.                 wallWidth = wallWidth + 1
  1143.             elseif option == 3 then
  1144.                 towerDistance = towerDistance + 1
  1145.             end
  1146.         elseif key == keys.numPadSubtract then  -- -
  1147.             if option == 1 then
  1148.                 walHeight = walHeight - 1
  1149.             elseif option == 2 then
  1150.                 wallWidth = wallWidth - 1
  1151.             elseif option == 3 then
  1152.                 towerDistance = towerDistance - 1
  1153.             end
  1154.         elseif key == keys.enter then --enter
  1155.             kontgaatje = true
  1156.         end
  1157.     end
  1158. end
  1159.  
  1160. function subMenuPresets()
  1161.     term.clear()
  1162.     term.setCursorPos(1,1)
  1163.     print("Available presets: (Enter to go back)")
  1164.     print("")
  1165.     print("1-Tiny")
  1166.     print("2-Medium")
  1167.     print("3-HUUUUUGE")
  1168.     print("")
  1169.     print("*Unfinished*")
  1170.    
  1171.     local event, key = os.pullEvent("key")
  1172.     term.clear()
  1173.     term.setCursorPos(1,1)
  1174.     if key == keys.one or key == keys.numPad1 then  --1
  1175.         preset = "Tiny"
  1176.         towerDiamList = {8,8,8,8,8,8,8,8}
  1177.         towerHeightList = {10,10,10,10,10,10,10,10}
  1178.         overhangList = {2,2,2,2,2,2,2,2}
  1179.         towerDistance = 16             
  1180.         walHeight = 5                      
  1181.         wallWidth = 3
  1182.     elseif key == keys.two or key == keys.numPad2 then  --2
  1183.         preset = "Medium"
  1184.         towerDiamList = {24,24,24,24,24,24,24,24}       --vul hier de diameters van de torens in
  1185.         towerHeightList = {40,40,40,40,40,40,40,40}
  1186.         overhangList = {2,2,2,2,2,2,2,2}
  1187.         towerDistance = 64             
  1188.         walHeight = 18                 
  1189.         wallWidth = 5
  1190.     elseif key == keys.three or key == keys.numPad3 then    --3
  1191.         preset = "HUUUUUGE"
  1192.         towerDiamList = {32,32,32,32,32,32,32,32}       --vul hier de diameters van de torens in
  1193.         towerHeightList = {60,60,60,60,60,60,60,60}
  1194.         overhangList = {4,4,4,4,4,4,4,4}
  1195.         towerDistance = 86             
  1196.         walHeight = 30                 
  1197.         wallWidth = 7
  1198.     end
  1199.     term.clear()
  1200.     term.setCursorPos(1,1)
  1201.     print("Preset "..preset.." selected")
  1202.     print("")
  1203.     print("For all towers and walls:")
  1204.     print("")
  1205.     print("Tower diameter = "..towerDiamList[1])
  1206.     print("Tower height = "..towerHeightList[1])
  1207.     print("Roof overhang = "..overhangList[1])
  1208.     print("Tower distance = "..towerDistance)
  1209.     print("Wall height = "..walHeight)
  1210.     print("Wall width = "..wallWidth)
  1211.     print("")
  1212.     print("Enter to go back")
  1213.     os.pullEvent("key")
  1214. end
  1215.  
  1216. function estimate()--------Benodigd materiaal inschatten---------
  1217.     towerWallQTY = 4 * towerHeightList[1] * math.ceil(math.pi * towerDiamList[1])
  1218.     wallQTY = 4 * (towerDistance - towerDiamList[1]) * 20 * 2 + 3 * (towerDistance - towerDiamList[1])
  1219.     wallMaterialQTY = towerWallQTY + wallQTY
  1220.     towerRoofQTY = 0---dak van toren
  1221.     diamCalc = towerDiamList[1] + overhangList[1]
  1222.     while diamCalc > 0 do
  1223.         towerRoofQTY = towerRoofQTY + math.ceil(math.pi * diamCalc)
  1224.         diamCalc = diamCalc - 1
  1225.     end
  1226.     towerRoofQTY = towerRoofQTY * 4--4 torens
  1227.     wallRoofQTY = 4 * (towerDistance - towerDiamList[1]) * 5 --5 breed
  1228.     roofMaterialQTY = towerRoofQTY + wallRoofQTY
  1229.     supportQTY = (towerDistance - towerDiamList[1] + math.ceil((towerDistance - towerDiamList[1])/4)) * 8   --4 is support interval 8 is 4 torens 2 kanten
  1230.     if model == 2 then--1.5x zo groot als model 1
  1231.         wallMaterialQTY = wallMaterialQTY * 1.5
  1232.         roofMaterialQTY = roofMaterialQTY * 1.5
  1233.         supportQTY = supportQTY * 1.5
  1234.     elseif model == 3 then--2x zo groot als model 1
  1235.         wallMaterialQTY = wallMaterialQTY * 2
  1236.         roofMaterialQTY = roofMaterialQTY * 2
  1237.         supportQTY = supportQTY * 2
  1238.     end
  1239.     wallMaterialStack = math.ceil(wallMaterialQTY/64)
  1240.     roofMaterialStack = math.ceil(roofMaterialQTY/64)
  1241.     supportStack = math.ceil(supportQTY/64)
  1242.     term.clear()
  1243.     term.setCursorPos(1,1)
  1244.     print("Make sure the following is available:")
  1245.     print("(Use AE to fill ender chests)")
  1246.     print(" ")
  1247.     print("Wall Material: "..wallMaterialQTY.." ("..wallMaterialStack.." stacks)")
  1248.     print("Roof Material: "..roofMaterialQTY.." ("..roofMaterialStack.." stacks)")
  1249.     print("Roof Support:  "..supportQTY.." ("..supportStack.." stacks)")
  1250.     print(" ")
  1251.     print("Press enter to proceed.")
  1252.     read()
  1253. end
  1254.  
  1255. function falseStart()---------turtle inventory check----------------
  1256.     local turtleAmount = {8,12,16}
  1257.     local fuelChestAmount = {9,13,17}
  1258.     local RoofSupportChestAmount = {4,6,8}
  1259.     term.clear()
  1260.     term.setCursorPos(1,1)
  1261.     print("Folowing is required:")
  1262.     print(" ")
  1263.     print("Slot Item            Av./Req.")
  1264.     print("[01] turtle            "..turtle.getItemCount(turtleSlot).."/"..turtleAmount[model])
  1265.     print("[02] FuelChest         "..turtle.getItemCount(fuelChestSlot).."/"..fuelChestAmount[model])
  1266.     print("[03] WallMaterialChest "..turtle.getItemCount(materialChestSlot).."/"..turtleAmount[model])
  1267.     print("[04] RoofMaterialChest "..turtle.getItemCount(roofChestSlot).."/"..turtleAmount[model])
  1268.     print("[05] RoofSupportChest  "..turtle.getItemCount(roofSupportChestSlot).."/"..RoofSupportChestAmount[model])
  1269.     print("[06] DiskDrive         "..turtle.getItemCount(diskDriveSlot).."/1")
  1270.     print("[07] Disk              "..turtle.getItemCount(diskSlot).."/1")
  1271.     print("[16] Fuel              "..turtle.getItemCount(fuelSlot).."/64")
  1272.    
  1273.     if turtle.getItemCount(turtleSlot) >= turtleAmount[model] then
  1274.         if turtle.getItemCount(fuelChestSlot) >= fuelChestAmount[model] then
  1275.             if turtle.getItemCount(materialChestSlot) >= turtleAmount[model] then
  1276.                 if turtle.getItemCount(roofChestSlot) >= turtleAmount[model] then
  1277.                     if turtle.getItemCount(roofSupportChestSlot) >= RoofSupportChestAmount[model] then
  1278.                         if turtle.getItemCount(diskDriveSlot) >= 1 then
  1279.                             if turtle.getItemCount(diskSlot) >= 1 then
  1280.                                 if turtle.getItemCount(fuelSlot) >= 64 then
  1281.                                     passed = true
  1282.                                     print(" ")
  1283.                                     term.write("press enter to start")
  1284.                                     local balzak = tostring(read())
  1285.                                 end
  1286.                             end
  1287.                         end
  1288.                     end
  1289.                 end
  1290.             end
  1291.         end
  1292.     end
  1293.     if not passed then 
  1294.         local event, p1 = os.pullEvent("turtle_inventory")
  1295.         falseStart()
  1296.     end
  1297. end
  1298.  
  1299. function programma()
  1300.     gui()
  1301.     menu()
  1302.     estimate()
  1303.     falseStart()
  1304.     reFuel()
  1305.     natteScheet()
  1306.     term.clear()
  1307.     term.setCursorPos(1,1)
  1308.     print("done")
  1309. end
  1310.  
  1311. programma()
  1312.  
  1313. --model = 3
  1314. --natteScheet()
Add Comment
Please, Sign In to add comment