SHOW:
|
|
- or go back to the newest paste.
1 | local component = require("component") | |
2 | local computer = require("computer") | |
3 | - | local mvfncs = {{turtle.forward,turtle.detect,turtle.dig,turtle.attack}, |
3 | + | local robot = require("robot") |
4 | - | {turtle.up,turtle.detectUp,turtle.digUp,turtle.attackUp}, |
4 | + | local shell = require("shell") |
5 | - | {turtle.down,turtle.detectDown,turtle.digDown,turtle.attackDown},} |
5 | + | local term = require("term") |
6 | local sides = require("sides") | |
7 | ||
8 | local tArgs = { ... } | |
9 | local cldt = {} | |
10 | local mvfncs = {{robot.forward,robot.detect,robot.swing,robot.swing}, | |
11 | {robot.up,robot.detectUp,robot.swingUp,robot.swingUp}, | |
12 | {robot.down,robot.detectDown,robot.swingDown,robot.swingDown},} | |
13 | local function trply(mssgstr) -- i.e. "unbreakable block in path" | |
14 | print(mssgstr) | |
15 | if cldt.rcID then sleep(0.1) rednet.send(cldt.rcID,mssgstr) end | |
16 | end | |
17 | local function trply(mssgstr) -- i.e. "unbreakable block in path" | |
18 | print(mssgstr) | |
19 | - | elseif turtle.getFuelLevel() == 0 then trply("Out of fuel" ) return false |
19 | + | |
20 | end | |
21 | local function mvdgK(drctn) -- i.e.(1 = forward, 2 = up, 3 = down) | |
22 | local itr8 = 0 | |
23 | while not mvfncs[drctn][1]() do | |
24 | if mvfncs[drctn][2]() then | |
25 | if not mvfncs[drctn][3]() then trply("unbreakable block in path") return false end | |
26 | elseif computer.energy() == 0 then trply("Out of fuel" ) return false | |
27 | - | tnl = function() turtle.digUp() turtle.digDown() return mvdgK(1) end, |
27 | + | |
28 | if itr8 > 64 then trply("persistent impediment") return false end | |
29 | itr8 = itr8+1 | |
30 | end | |
31 | return true | |
32 | - | turtle.placeDown() |
32 | + | |
33 | rctfncs = { | |
34 | tnl = function() robot.swingUp() robot.swingDown() return mvdgK(1) end, | |
35 | dfd = function() return mvdgK(1) end, | |
36 | dup = function() return mvdgK(2) end, | |
37 | ddn = function() return mvdgK(3) end, | |
38 | - | if not turtle.suck() then |
38 | + | |
39 | - | turtle.suckUp() |
39 | + | robot.placeDown() |
40 | - | else turtle.suckDown() end |
40 | + | |
41 | sleep(0.5) | |
42 | redstone.setOutput("bottom",false) | |
43 | end, | |
44 | - | turtle.select(cldt.slt) |
44 | + | |
45 | - | trply("Slot "..cldt.slt.." selected, contains "..turtle.getItemCount(cldt.slt)..", "..turtle.getItemSpace(cldt.slt).." from full") |
45 | + | if not robot.suck() then |
46 | robot.suckUp() | |
47 | else robot.suckDown() end | |
48 | - | trply("Current fuel level is "..turtle.getFuelLevel()) |
48 | + | |
49 | - | if not turtle.refuel(turtle.getItemCount(cldt.slt)) then |
49 | + | |
50 | cldt.slt = math.fmod(cldt.slt,16)+1 | |
51 | - | else trply("New fuel level is "..turtle.getFuelLevel()) end |
51 | + | robot.select(cldt.slt) |
52 | trply("Slot "..cldt.slt.." selected, contains "..robot.count(cldt.slt)..", "..robot.space(cldt.slt).." from full") | |
53 | end, | |
54 | refuel = function() | |
55 | trply("Current fuel level is "..computer.energy()) | |
56 | if not component.generator.insert(robot.count(cldt.slt)) then | |
57 | trply("Slot "..cldt.slt.." does not contain fuel") | |
58 | - | gpslct = function() local x,y,z = gps.locate(2) trply("Turtle ID "..os.computerID().." GPS = "..x..", "..y..", "..z) end, |
58 | + | else trply("New fuel level is "..computer.energy()) end |
59 | end, | |
60 | gox = function() | |
61 | trply("send command string") | |
62 | repeat cldt[2], cldt[3] = rednet.receive() until cldt[2] == cldt.rcID | |
63 | tfnctns[6](cldt[3]) | |
64 | end, | |
65 | gpslct = function() local x,y,z = gps.locate(2) trply("Robot ID "..os.computerID().." GPS = "..x..", "..y..", "..z) end, | |
66 | gpshst = function() | |
67 | - | trply("TurtleID "..os.computerID().." GPS hosting terminated") |
67 | + | |
68 | local x,y,z = gps.locate(2) | |
69 | repeat | |
70 | rqstr,mssgrq = rednet.receive() | |
71 | if mssgrq == "PING" then rednet.send(rqstr, textutils.serialize({x,y,z})) | |
72 | elseif cldt.rcID == rqstr and mssgrq == "gpshst" then x = nil end | |
73 | until not x | |
74 | trply("Robot ID "..os.computerID().." GPS hosting terminated") | |
75 | end, | |
76 | rcvfl = function() | |
77 | trply("send file name") | |
78 | repeat cldt[2], cldt[3] = rednet.receive() until cldt[2] == cldt.rcID | |
79 | local flnm = cldt[3] | |
80 | trply("send file body") | |
81 | repeat cldt[2], cldt[3] = rednet.receive() until cldt[2] == cldt.rcID | |
82 | local flbdy = fs.open(flnm,"w") flbdy.write(cldt[3]) flbdy.close() | |
83 | trply(flnm.." Updated") | |
84 | end, | |
85 | srvfl = function() | |
86 | trply("send file path/name") | |
87 | repeat cldt[2], cldt[3] = rednet.receive() until cldt[2] == cldt.rcID | |
88 | local flbdy = fs.open(cldt[3],"r") | |
89 | trply(flbdy.readAll()) flbdy.close() | |
90 | end, | |
91 | - | cmdlst = {f=rctfncs.dfd,b=turtle.back,u=rctfncs.dup,d=rctfncs.ddn, |
91 | + | |
92 | - | l=turtle.turnLeft,r=turtle.turnRight,t= rctfncs.tnl, |
92 | + | |
93 | - | p=turtle.place,P=turtle.placeUp,o=turtle.placeDown, |
93 | + | |
94 | - | x=turtle.drop,X=turtle.dropUp,z=turtle.dropDown, |
94 | + | |
95 | - | e=turtle.dig,E=turtle.digUp,w=turtle.digDown, |
95 | + | |
96 | - | v=rctfncs.pckup,V=turtle.suckUp,c=turtle.suckDown, |
96 | + | |
97 | } | |
98 | cmdlst = {f=rctfncs.dfd,b=robot.back,u=rctfncs.dup,d=rctfncs.ddn, | |
99 | l=robot.turnLeft,r=robot.turnRight,t= rctfncs.tnl, | |
100 | p=robot.place,P=robot.placeUp,o=robot.placeDown, | |
101 | x=robot.drop,X=robot.dropUp,z=robot.dropDown, | |
102 | e=robot.swing,E=robot.swingUp,w=robot.swingDown, | |
103 | - | if psswrd then cldt[1] = psswrd cldt.slt = 1 turtle.select(cldt.slt) else |
103 | + | v=rctfncs.pckup,V=robot.suckUp,c=robot.suckDown, |
104 | R=rctfncs.refuel,S=rctfncs.slct,B=rctfncs.bmb, | |
105 | } | |
106 | tfnctns = { | |
107 | function(psswrd,rtID) | |
108 | cldt.rcID = rtID | |
109 | rednet.open("right") | |
110 | if psswrd then cldt[1] = psswrd cldt.slt = 1 robot.select(cldt.slt) else | |
111 | print("Enter confirmation password") | |
112 | cldt[1] = io.read() end | |
113 | print("Send password from control terminal") | |
114 | repeat cldt[2], cldt[3] = rednet.receive() | |
115 | - | if turtle[cldt[3]] then trply(tostring(turtle[cldt[3]](tonumber(cldt[4])))) |
115 | + | |
116 | until cldt[2] == cldt.rcID and cldt[3] == cldt[1] trply("password accepted") | |
117 | local hndl = fs.open("startup","w") | |
118 | hndl.writeLine("shell.run(\"clfn\",1,\""..cldt[1].."\")") hndl.close() | |
119 | while cldt.rcID do cldt[2],rnmssg = rednet.receive() | |
120 | if cldt[2] == cldt.rcID then | |
121 | _,_,cldt[3], cldt[4] = rnmssg:find("^(%a+)(.*)") | |
122 | if robot[cldt[3]] then trply(tostring(robot[cldt[3]](tonumber(cldt[4])))) | |
123 | elseif rctfncs[cldt[3]] then rctfncs[cldt[3]]() | |
124 | - | turtle.select(cldt.slt) |
124 | + | |
125 | end | |
126 | end | |
127 | print("Remote Control Terminated") fs.delete("startup") | |
128 | end, | |
129 | function() | |
130 | cldt.slt = 16 | |
131 | robot.select(cldt.slt) | |
132 | print("Place fuel in Slot 16 and enter") | |
133 | - | turtle.place() |
133 | + | |
134 | - | if turtle.getItemCount(cldt.slt) < 1 then rctfncs.slct() end |
134 | + | |
135 | - | if not turtle.dig() then print("Error") break end |
135 | + | |
136 | function() | |
137 | print("Place material to be sifted in Slots 1-15\nLeave Slot 16 empty") | |
138 | io.read() | |
139 | repeat | |
140 | robot.place() | |
141 | if robot.count(cldt.slt) < 1 then rctfncs.slct() end | |
142 | if not robot.swing() then print("Error") break end | |
143 | - | turtle.select(1) |
143 | + | |
144 | - | if not turtle.place() then print("There must be tilled dirt to plant") break end |
144 | + | |
145 | - | turtle.select(cldt.slt) |
145 | + | |
146 | - | if not turtle.place() then print("Process requires Bonemeal to continue") break end |
146 | + | |
147 | - | if turtle.getItemCount(cldt.slt) < 1 then rctfncs.slct() end |
147 | + | |
148 | - | turtle.dig() |
148 | + | |
149 | repeat | |
150 | robot.select(1) | |
151 | if not robot.place() then print("There must be tilled dirt to plant") break end | |
152 | robot.select(cldt.slt) | |
153 | if not robot.place() then print("Process requires Bonemeal to continue") break end | |
154 | - | turtle.select(2) |
154 | + | if robot.count(cldt.slt) < 1 then rctfncs.slct() end |
155 | - | turtle.place() |
155 | + | robot.swing() |
156 | - | for i=4,7 do if turtle.getItemCount(i) > 0 then turtle.select(i) break end end |
156 | + | |
157 | - | turtle.drop() |
157 | + | |
158 | function() | |
159 | local x1Ps,y1Ps,z1Ps,x2Ps,z2Ps = 0,255,0,1,0 | |
160 | local function gpsnode(xPos,yPos,zPos) | |
161 | - | turtle.up() |
161 | + | robot.select(2) |
162 | - | turtle.forward() |
162 | + | robot.place() |
163 | - | turtle.turnLeft() |
163 | + | for i=4,7 do if robot.count(i) > 0 then robot.select(i) break end end |
164 | - | turtle.back() |
164 | + | robot.drop() |
165 | - | turtle.select(1) |
165 | + | |
166 | - | turtle.place() |
166 | + | |
167 | - | turtle.back() |
167 | + | |
168 | - | turtle.select(3) |
168 | + | robot.up() |
169 | - | turtle.place() |
169 | + | robot.forward() |
170 | - | turtle.turnLeft() |
170 | + | robot.turnLeft() |
171 | - | turtle.forward() |
171 | + | robot.back() |
172 | - | turtle.turnRight() |
172 | + | robot.select(1) |
173 | - | turtle.forward() |
173 | + | robot.place() |
174 | - | turtle.forward() |
174 | + | robot.back() |
175 | - | turtle.turnRight() |
175 | + | robot.select(3) |
176 | robot.place() | |
177 | - | turtle.down() |
177 | + | robot.turnLeft() |
178 | robot.forward() | |
179 | robot.turnRight() | |
180 | robot.forward() | |
181 | - | turtle.forward() |
181 | + | robot.forward() |
182 | robot.turnRight() | |
183 | peripheral.call("front","turnOn") | |
184 | robot.down() | |
185 | end | |
186 | - | turtle.down() |
186 | + | |
187 | x1Ps,y1Ps,z1Ps = gps.locate(2,true) | |
188 | robot.forward() | |
189 | - | turtle.turnRight() |
189 | + | |
190 | - | turtle.turnRight() |
190 | + | |
191 | - | for c=1,2 do turtle.forward() end |
191 | + | |
192 | else x1Ps,y1Ps,z1Ps = xPos,yPos,zPos end | |
193 | robot.down() | |
194 | gpsnode(x1Ps+(x2Ps*2),y1Ps,z1Ps+(z2Ps*2)) | |
195 | -- Go back 2 and set the second node | |
196 | robot.turnRight() | |
197 | robot.turnRight() | |
198 | for c=1,2 do robot.forward() end | |
199 | - | Enter turtle's current x]]) |
199 | + | |
200 | end | |
201 | - | print("Enter turtle's current z") |
201 | + | |
202 | Slot 1 > 4+ Computers | |
203 | - | print("Enter turtle's current facing") |
203 | + | |
204 | - | for i=1, tonumber(io.read())+1 do turtle.turnLeft() end |
204 | + | |
205 | - | while turtle.getFuelLevel() < 500 do |
205 | + | |
206 | Enter robot's current x]]) | |
207 | local x3Ps = tonumber(io.read()) | |
208 | print("Enter robot's current z") | |
209 | - | turtle.select(16) |
209 | + | |
210 | - | print("Current fuel level is"..turtle.getFuelLevel()) |
210 | + | print("Enter robot's current facing") |
211 | - | if not turtle.refuel(turtle.getItemCount(16)) then |
211 | + | for i=1, tonumber(io.read())+1 do robot.turnLeft() end |
212 | while computer.energy() < 500 do | |
213 | - | else print("New fuel level is"..turtle.getFuelLevel()) end |
213 | + | |
214 | print("Place fuel in Slot 16 and press Enter") | |
215 | - | -- launch turtle |
215 | + | |
216 | - | while turtle.up() do end |
216 | + | robot.select(16) |
217 | print("Current fuel level is"..computer.energy()) | |
218 | if not component.generator.insert(robot.count(16)) then | |
219 | print("Slot "..cldt.slt.." does not contain fuel") | |
220 | - | turtle.back() |
220 | + | else print("New fuel level is"..computer.energy()) end |
221 | - | turtle.turnRight() |
221 | + | |
222 | -- launch robot | |
223 | - | while turtle.down() do end |
223 | + | while robot.up() do end |
224 | plcaxis(x3Ps,255,z3Ps) | |
225 | -- Go back to the middle and turn | |
226 | x2Ps,z2Ps = 0,1 | |
227 | robot.back() | |
228 | robot.turnRight() | |
229 | plcaxis(x3Ps,254,z3Ps) | |
230 | while robot.down() do end | |
231 | end, | |
232 | function(cmndstrng) -- Go commands | |
233 | -- non-nil array length | |
234 | local function lngth(lst) | |
235 | if lst then return #lst else return 0 end | |
236 | end | |
237 | local function gtNmbr(strg) | |
238 | local _,_,nmbr,rmndr = strg:find("^(%d+)(.*)$") | |
239 | return nmbr,lngth(strg)-lngth(rmndr) | |
240 | end | |
241 | local function gtLoop(strg) | |
242 | local _,_,loop,rmndr = strg:find("^(%b[])(.*)$") | |
243 | if loop then return loop:sub(2,-2),lngth(strg)-lngth(rmndr) | |
244 | else return nil,0 end | |
245 | end | |
246 | local function gox(cmnds) | |
247 | if not #cmnds then return false end | |
248 | local ndx,prvCmnd,result = 1,"" | |
249 | while ndx <= #cmnds do | |
250 | local char = cmnds:sub(ndx,ndx) | |
251 | local nxtCh = cmnds:sub(ndx+1, ndx+1) | |
252 | if cmdlst[char] then | |
253 | ndx,result = ndx+1,cmdlst[char]() | |
254 | else | |
255 | local nmbr, nLen = gtNmbr(cmnds:sub(ndx)) | |
256 | local loop, lpLen = gtLoop(cmnds:sub(ndx)) | |
257 | if nmbr then | |
258 | for i = 2,tonumber(nmbr) do gox(prvCmnd) end | |
259 | ndx = ndx+nLen | |
260 | elseif loop then | |
261 | local nmbr, nLen = gtNmbr(cmnds:sub(ndx+lpLen)) | |
262 | if nmbr then | |
263 | for i = 1,tonumber(nmbr) do gox(loop) end | |
264 | ndx = ndx+nLen | |
265 | else while gox(loop) do end end | |
266 | ndx = ndx+lpLen | |
267 | end end | |
268 | prvCmnd = char | |
269 | end | |
270 | return result | |
271 | end | |
272 | if not cmndstrng then | |
273 | - | cmndstrng = read() end |
273 | + | |
274 | f b u d l r to move, t to tunnel | |
275 | p P o to place[U/Dn], x X z to drop | |
276 | e E w to dig [U/Dn], v V c to suck | |
277 | - | shell.run('clear') |
277 | + | |
278 | [...] loop while last command succeeds | |
279 | number for fixed loop]]) | |
280 | - | turtle.select(cldt.slt) |
280 | + | cmndstrng = io.read() end |
281 | gox(cmndstrng) | |
282 | end, | |
283 | } | |
284 | - | turtle.select(cldt.slt) |
284 | + | term.clear() |
285 | cldt[1] = tonumber(tArgs[1]) | |
286 | cldt.slt = 1 | |
287 | robot.select(cldt.slt) | |
288 | if cldt[1] and tArgs[2] then tfnctns[cldt[1]](tArgs[2],tonumber(tArgs[3])) else | |
289 | repeat | |
290 | cldt.slt = 1 | |
291 | robot.select(cldt.slt) | |
292 | print("Select function by number") | |
293 | print([[1: Remote Control | |
294 | 2: Refuel | |
295 | 3: Sift Gravel | |
296 | 4: Auto Farm | |
297 | 5: Launch GPS Array | |
298 | 6: GoX commands | |
299 | Or other to exit]]) | |
300 | sclfn = tfnctns[tonumber(io.read())] | |
301 | if sclfn then sclfn() end | |
302 | until not sclfn | |
303 | end |