SHOW:
|
|
- or go back to the newest paste.
| 1 | function gotoapi(gx, gy, gz, enddirlet) | |
| 2 | --local tArgs = {...}
| |
| 3 | - | face = 0 |
| 3 | + | local face = 0 |
| 4 | local r = 1 | |
| 5 | tru = 1 | |
| 6 | local tturned = 0 | |
| 7 | rednet.open("left")
| |
| 8 | local cx,cy,cz = gps.locate(2,false) | |
| 9 | if (gx and gy and gz) == nil then | |
| 10 | print("Incorrect usage of Function.")
| |
| 11 | --print("goto <x> <y> <z> (<Heading>)")
| |
| 12 | else | |
| 13 | --local gx = tonumber(tArgs[1]) | |
| 14 | --local gy = tonumber(tArgs[2]) | |
| 15 | --local gz = tonumber(tArgs[3]) | |
| 16 | --local enddirlet = tArgs[4] | |
| 17 | local x | |
| 18 | local y | |
| 19 | local z | |
| 20 | if enddirlet ~= nil then | |
| 21 | if enddirlet == "n" or enddirlet == "north" then | |
| 22 | enddir = 4 | |
| 23 | end | |
| 24 | if enddirlet == "s" or enddirlet == "south" then | |
| 25 | enddir = 2 | |
| 26 | end | |
| 27 | if enddirlet == "e" or enddirlet == "east" then | |
| 28 | enddir = 1 | |
| 29 | end | |
| 30 | if enddirlet == "w" or enddirlet == "west" then | |
| 31 | enddir = 3 | |
| 32 | end | |
| 33 | end | |
| 34 | function tturnup() | |
| 35 | tturned = tturned + 1 | |
| 36 | - | if tturned > 25 then |
| 36 | + | if tturned > 10 then |
| 37 | os.reboot() | |
| 38 | end | |
| 39 | end | |
| 40 | - | |
| 40 | + | |
| 41 | function PL() | |
| 42 | - | while face >= 5 do |
| 42 | + | --print("Going to:")
|
| 43 | - | face = face - 4 |
| 43 | + | --write(gx) write(" ") write(gy) write(" ") print(gz)
|
| 44 | end | |
| 45 | - | while face <= 0 do |
| 45 | + | |
| 46 | - | face = face + 4 |
| 46 | + | if face >= 5 then |
| 47 | face = 1 | |
| 48 | elseif face <= 0 then | |
| 49 | - | |
| 49 | + | face = 4 |
| 50 | - | |
| 50 | + | |
| 51 | - | |
| 51 | + | |
| 52 | - | |
| 52 | + | |
| 53 | - | function gps_face_math(cur_x,cur_z) |
| 53 | + | |
| 54 | - | mnx,mny,mnz = gps.locate(3,false) |
| 54 | + | |
| 55 | - | if mnx > cur_x then |
| 55 | + | |
| 56 | - | face = 1 |
| 56 | + | |
| 57 | - | end |
| 57 | + | |
| 58 | - | if mnx < cur_x then |
| 58 | + | |
| 59 | - | face = 3 |
| 59 | + | |
| 60 | - | end |
| 60 | + | |
| 61 | - | if mnz > cur_z then |
| 61 | + | if nx > cx then |
| 62 | - | face = 2 |
| 62 | + | face = 1 |
| 63 | - | end |
| 63 | + | |
| 64 | - | if mnz < cur_z then |
| 64 | + | if nx < cx then |
| 65 | - | face = 4 |
| 65 | + | face = 3 |
| 66 | - | end |
| 66 | + | |
| 67 | - | end |
| 67 | + | if nz > cz then |
| 68 | - | function forward_get_face() |
| 68 | + | face = 2 |
| 69 | - | tturned = 0 |
| 69 | + | |
| 70 | - | cux,cuy,cuz = gps.locate(3,false) |
| 70 | + | if nz < cz then |
| 71 | - | while turtle.forward() == false do |
| 71 | + | face = 4 |
| 72 | - | tturned = 0 |
| 72 | + | |
| 73 | - | if turtle.up() == false then |
| 73 | + | |
| 74 | - | --turtle.digUp() |
| 74 | + | |
| 75 | - | end |
| 75 | + | |
| 76 | - | end |
| 76 | + | |
| 77 | - | gps_face_math(cux,cuz) |
| 77 | + | |
| 78 | - | return true |
| 78 | + | |
| 79 | - | end |
| 79 | + | |
| 80 | - | |
| 80 | + | |
| 81 | - | |
| 81 | + | |
| 82 | - | |
| 82 | + | |
| 83 | if face == 1 then | |
| 84 | gototurnleft = 1 | |
| 85 | --print("E-to-N")
| |
| 86 | noredoturndir = 1 | |
| 87 | end | |
| 88 | end | |
| 89 | if dir == 1 then | |
| 90 | if face == 4 then | |
| 91 | - | gps_face_math(cx,cz) |
| 91 | + | |
| 92 | --print("N-to-E")
| |
| 93 | noredoturndir = 1 | |
| 94 | end | |
| 95 | end | |
| 96 | ||
| 97 | if noredoturndir == 0 then | |
| 98 | if face >= dir then | |
| 99 | gototurnleft = 1 | |
| 100 | end | |
| 101 | if face < dir then | |
| 102 | gototurnleft = 0 | |
| 103 | end | |
| 104 | end | |
| 105 | ||
| 106 | if dir == 4 then | |
| 107 | if face == 1 then | |
| 108 | gototurnleft = 1 | |
| 109 | --print("E-to-N")
| |
| 110 | noredoturndir = 1 | |
| 111 | end | |
| 112 | end | |
| 113 | if dir == 1 then | |
| 114 | if face == 4 then | |
| 115 | gototurnleft = 0 | |
| 116 | --print("N-to-E")
| |
| 117 | noredoturndir = 1 | |
| 118 | end | |
| 119 | end | |
| 120 | while dir ~= face do | |
| 121 | c_face() | |
| 122 | if gototurnleft == 1 then | |
| 123 | turtle.turnLeft() | |
| 124 | face = face - 1 | |
| 125 | tturnup() | |
| 126 | end | |
| 127 | if gototurnleft == 0 then | |
| 128 | turtle.turnRight() | |
| 129 | face = face + 1 | |
| 130 | tturnup() | |
| 131 | end | |
| 132 | c_face() | |
| 133 | end | |
| 134 | noredoturndir = 0 | |
| 135 | end | |
| 136 | function f() | |
| 137 | while not turtle.forward() do | |
| 138 | tturned = 0 | |
| 139 | if not turtle.up() then | |
| 140 | --turtle.digUp() | |
| 141 | end | |
| 142 | y = y + 1 | |
| 143 | end | |
| 144 | end | |
| 145 | function go() | |
| 146 | tturned = 0 | |
| 147 | if x < 0 then | |
| 148 | setDir(1) | |
| 149 | while x ~= 0 do | |
| 150 | f() | |
| 151 | x = x + 1 | |
| 152 | end | |
| 153 | end | |
| 154 | if x > 0 then | |
| 155 | setDir(3) | |
| 156 | - | while not forward_get_face() do |
| 156 | + | |
| 157 | f() | |
| 158 | - | if not turtle.up() then |
| 158 | + | |
| 159 | end | |
| 160 | end | |
| 161 | - | y = y + 1 |
| 161 | + | |
| 162 | setDir(2) | |
| 163 | while z ~= 0 do | |
| 164 | f() | |
| 165 | z = z + 1 | |
| 166 | end | |
| 167 | end | |
| 168 | if z > 0 then | |
| 169 | setDir(4) | |
| 170 | while z ~= 0 do | |
| 171 | f() | |
| 172 | z = z - 1 | |
| 173 | end | |
| 174 | end | |
| 175 | while y < 0 do | |
| 176 | tturned = 0 | |
| 177 | if turtle.up() ~= true then | |
| 178 | --turtle.digUp() | |
| 179 | end | |
| 180 | y = y + 1 | |
| 181 | end | |
| 182 | while y > 0 do | |
| 183 | tturned = 0 | |
| 184 | if turtle.down() ~= true then | |
| 185 | --turtle.digDown() | |
| 186 | end | |
| 187 | y = y - 1 | |
| 188 | end | |
| 189 | end | |
| 190 | ||
| 191 | ||
| 192 | ||
| 193 | tonumber(gx) | |
| 194 | tonumber(gy) | |
| 195 | tonumber(gz) | |
| 196 | PL() | |
| 197 | get_Face() | |
| 198 | calc() | |
| 199 | go() | |
| 200 | if enddir ~= nil then | |
| 201 | setDir(enddir) | |
| 202 | end | |
| 203 | ||
| 204 | end | |
| 205 | end | |
| 206 | ||
| 207 | ||
| 208 | ||
| 209 | function goto(Workinggototable) | |
| 210 | gtloop = 0 | |
| 211 | gtloopsleep = 0.0001 | |
| 212 | gototable = {}
| |
| 213 | goit = 1 | |
| 214 | while true do | |
| 215 | while goit < 5 do | |
| 216 | if Workinggototable[goit] ~= nil then | |
| 217 | table.insert(gototable, Workinggototable[goit]) | |
| 218 | elseif Workinggototable[goit] == nil then | |
| 219 | table.insert(gototable, Workinggototable[goit]) | |
| 220 | break | |
| 221 | end | |
| 222 | goit = goit + 1 | |
| 223 | end | |
| 224 | gotoapi(gototable[1], gototable[2], gototable[3], gototable[4]) | |
| 225 | local ecx,ecy,ecz = gps.locate(5,false) | |
| 226 | if ecx == tonumber(gototable[1]) then | |
| 227 | if ecy == tonumber(gototable[2]) then | |
| 228 | if ecz == tonumber(gototable[3]) then | |
| 229 | - | gtloopsleep = 0.01 |
| 229 | + | |
| 230 | - | gtloopsleep2 = gtloopsleep ^ 2 |
| 230 | + | |
| 231 | end | |
| 232 | end | |
| 233 | if gtloop < 100 then | |
| 234 | gtloop = gtloop + 1 | |
| 235 | end | |
| 236 | if gtloop > 5 then | |
| 237 | if gtloopsleep > 2.5 then | |
| 238 | gtloopsleep = 2.5 | |
| 239 | end | |
| 240 | sleep(gtloopsleep) | |
| 241 | gtloopsleep = gtloopsleep * 2 | |
| 242 | end | |
| 243 | end | |
| 244 | end |