Advertisement
Kwekerij

platform

Mar 25th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.02 KB | None | 0 0
  1. --{program="tPlatform",version="1.10",date="2019-03-25"}
  2. ---------------------------------------
  3.  
  4. ---------------------------------------
  5. ---- ASSUMPTIONS/PRECONDITIONS --------
  6. ---------------------------------------
  7. -- Turtle movement:
  8. -- - building space must be empty
  9.  
  10. ---------------------------------------
  11. ---- PARAMETERS -----------------------
  12. ---------------------------------------
  13. local cSleepTime=10
  14.  
  15. ---------------------------------------
  16. ---- VARIABLES ------------------------
  17. ---------------------------------------
  18. local userX=3 userY=1
  19. local blnAskForParameters=true
  20. local blnDirectionX=true
  21. local currentSlot=1
  22.  
  23. ---------------------------------------
  24. ---- tArgs ----------------------------
  25. ---------------------------------------
  26. local tArgs = {...}
  27. if #tArgs == 2 then -- no error check
  28. blnAskForParameters=false
  29. userX=tonumber(tArgs[1])
  30. userY=tonumber(tArgs[2])
  31. end
  32.  
  33. ---------------------------------------
  34. -- basic functions for turtle control -
  35. ---------------------------------------
  36. local function mats()
  37. if turtle.getItemCount(currentSlot)==0 then
  38. currentSlot=currentSlot+1
  39. if currentSlot>16 then
  40. currentSlot=1
  41. print("Out of materials, please restock!")
  42. print(" Sleeping for "..cSleepTime.." sec ...")
  43. os.sleep(cSleepTime)
  44. end
  45. turtle.select(currentSlot)
  46. mats()
  47. end
  48. end
  49.  
  50. local function gf() while not turtle.forward() do end end
  51. local function gb() while not turtle.back() do end end
  52. local function gu() while not turtle.up() do end end
  53. local function gd() while not turtle.down() do end end
  54. local function gl() while not turtle.turnLeft() do end end
  55. local function gr() while not turtle.turnRight() do end end
  56. local function df() turtle.dig() end
  57. local function du() turtle.digUp() end
  58. local function dd() turtle.digDown() end
  59. local function pf() mats() while not turtle.place() do end end
  60. local function pu() mats() while not turtle.placeUp() do end end
  61. local function pd() mats() while not turtle.placeDown() do end end
  62. local function sf() turtle.suck() end
  63. local function su() turtle.suckUp() end
  64. local function sd() turtle.suckDown() end
  65. local function Df() turtle.drop() end
  66. local function Du() turtle.dropUp() end
  67. local function Dd() turtle.dropDown() end
  68. local function ss(s) turtle.select(s) end
  69.  
  70. local function askForInputText(textt)
  71. local at=""
  72. -- check prompting texts
  73. if textt==nil then textt="Enter text:" end
  74.  
  75. -- ask for input
  76. write(textt)
  77. at=read()
  78. return at
  79. end
  80.  
  81.  
  82. local function checkFuel()
  83. local tmp=turtle.getFuelLevel()
  84. return tmp
  85. end
  86.  
  87. ------------------------------------------------------------------------------
  88. -- main ----------------------------------------------------------------------
  89. ------------------------------------------------------------------------------
  90.  
  91. -- step 0 usage hints
  92. term.clear() term.setCursorPos(1,1)
  93. print("+-------------------------------------+")
  94. print("| Platform Bot von Kwekerij |")
  95. print("+-------------------------------------+")
  96. print("| Put in building materials in any |")
  97. print("| slot(s) and press enter. |")
  98. print("| Platform size: Enter x and y to |")
  99. print("| determine size. Either when asked |")
  100. print("| by program or with function call, |")
  101. print("| e.g., tPlatform 5 10 |")
  102. print("| If turtle runs out of materials it |")
  103. print("| waits until resupplied. |")
  104. print("+-------------------------------------+")
  105.  
  106. -- step 1 get input
  107. ss(1)
  108. if blnAskForParameters then
  109. askForInputText("Put in materials + press enter!")
  110. -- step 1.1 get x
  111. write("Enter depth x (default&min=3):")
  112. userX=read()
  113. if userX==nil or userX=="" then userX=3 end
  114. userX=tonumber(userX) -- no error check yet
  115. if userX<3 then userX=3 end
  116.  
  117. -- step 1.2 get y
  118. write("Enter width y (default&min=1):")
  119. userY=read()
  120. if userY==nil or userY=="" then userY=3 end
  121. userY=tonumber(userY) -- no error check yet
  122. --if userY<2 then userY=2 end
  123. end
  124. userX=math.floor(userX)
  125. userY=math.floor(userY)
  126.  
  127. -- check fuel level
  128. local cMinFuel=(userX)*(userY+1)+1
  129. turtleOk, turtleVal = pcall(checkFuel)
  130. if turtleVal<cMinFuel then
  131. term.clear() term.setCursorPos(1,1)
  132. print("+-------------------------------------+")
  133. print("| Platform Bot von Kwekerij |")
  134. print("+-------------------------------------+")
  135. print("| Please refuel turtle, it needs a |")
  136. print("| minimum of about ",cMinFuel," fuel units.")
  137. print("| Tip: Put some fuel (e.g. coal) in |")
  138. print("| slot 1 and enter: refuel all. |")
  139. print("| This will consume all(!) fuel |")
  140. print("| items in the turtle's inventory|")
  141. print("+-------------------------------------+")
  142. return
  143. end
  144.  
  145. -- step 2 loops
  146. print("Let's build something verführerisch:")
  147. -- step 2.1 go to start position
  148. -- & if odd number go back
  149. if userY%2==1 then
  150. -- odd number of rows
  151. for i=1,userX,1 do gf() end
  152. blnDirectionX=false
  153. else
  154. -- even number of rows
  155. gf() gf() gl() gl()
  156. blnDirectionX=true
  157. end
  158.  
  159. -- step 2.2 build it
  160. for iY=1,userY,1 do
  161. for iX=1,userX-1 do
  162. if iX==1 then
  163. if iY~=1 then
  164. if blnDirectionX then
  165. gl()
  166. else
  167. gr()
  168. end
  169. end
  170. gb() pf()
  171. elseif iX==userX-1 then
  172. if iY~=userY then
  173. if blnDirectionX then
  174. -- right turn
  175. gr()
  176. else
  177. -- left turn
  178. gl()
  179. end
  180. end
  181. gb() pf()
  182. else -- in between start and end
  183. gb() pf()
  184. end
  185.  
  186. end
  187. blnDirectionX=not blnDirectionX
  188. end
  189. -- go back within 1st row
  190. gr()
  191. for i=1,userY-1,1 do gb() pf() end
  192. gl() gb() pf()
  193.  
  194. print("Sieht super aus mein Führer")
  195. os.sleep(0.4)
  196. print("***************************************")
  197. print("* Bei weiteren Anfragen gerne melden *")
  198. print("* Sieg Heil 88 *")
  199. print("***************************************")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement