SHOW:
|
|
- or go back to the newest paste.
| 1 | -- Efficient Digging Program by Galygious | |
| 2 | --Variables | |
| 3 | tArgs = { ... }
| |
| 4 | m3 = 0 | |
| 5 | m2 = 0 | |
| 6 | m1 = 0 | |
| 7 | h = 0 | |
| 8 | r = 0 | |
| 9 | f = o | |
| 10 | forward = true | |
| 11 | --Functions | |
| 12 | local printUsage = function(ecode) | |
| 13 | if ecode == 0 then | |
| 14 | print('Error Code 0\nThis Program Requires these variables:\narg1 - Depth (positive number)\narg2 - Width (positive number)\narg3 - Height (positive number)')
| |
| 15 | error() | |
| 16 | elseif ecode == 1 then | |
| 17 | print('Error Code 0\nThis Program Requires these variables:\narg1 - Depth (positive number)\narg2 - Width (positive number)\narg3 - Height (positive number)')
| |
| 18 | error() | |
| 19 | elseif ecode == 2 then | |
| 20 | print('Error Code 2\nFirst argument must represent a distance (positive number)')
| |
| 21 | error() | |
| 22 | elseif ecode == 3 then | |
| 23 | print('Error Code 3\nFirst argument must represent a distance (positive number)')
| |
| 24 | error() | |
| 25 | elseif ecode == 4 then | |
| 26 | print('Error Code 4\nSecond argument must represent a distance (positive number)')
| |
| 27 | error() | |
| 28 | elseif ecode == 5 then | |
| 29 | print('Error Code 5\nSecond argument must represent a distance (positive number)')
| |
| 30 | error() | |
| 31 | elseif ecode == 6 then | |
| 32 | print('Error Code 6\nThird argument must represent a distance (positive number)')
| |
| 33 | error() | |
| 34 | elseif ecode == 7 then | |
| 35 | print('Error Code 7\nThird argument must represent a distance (positive number)')
| |
| 36 | error() | |
| 37 | end | |
| 38 | end | |
| 39 | ||
| 40 | local mineup = function() | |
| 41 | while turtle.detectUp() do | |
| 42 | if not turtle.digUp() then | |
| 43 | sleep(0.8) | |
| 44 | end | |
| 45 | end | |
| 46 | end | |
| 47 | ||
| 48 | local minedown = function() | |
| 49 | while turtle.detectDown() do | |
| 50 | if not turtle.digDown() then | |
| 51 | sleep(0.8) | |
| 52 | end | |
| 53 | end | |
| 54 | ||
| 55 | end | |
| 56 | ||
| 57 | local move = function(Dir,Dis) | |
| 58 | shell.run('/progs/move',Dir,Dis)
| |
| 59 | end | |
| 60 | ||
| 61 | local tturn = function(Dir) | |
| 62 | shell.run('/progs/tturn',Dir)
| |
| 63 | end | |
| 64 | ||
| 65 | local mine1 = function() | |
| 66 | move('f',1)
| |
| 67 | end | |
| 68 | ||
| 69 | local mine2 = function() | |
| 70 | move('f',1)
| |
| 71 | mineup() | |
| 72 | end | |
| 73 | ||
| 74 | local mine3 = function() | |
| 75 | move('f',1)
| |
| 76 | mineup() | |
| 77 | minedown() | |
| 78 | end | |
| 79 | ||
| 80 | local row1 = function() | |
| 81 | for i=1,depth-1 do | |
| 82 | mine1() | |
| 83 | end | |
| 84 | end | |
| 85 | ||
| 86 | local row2 = function() | |
| 87 | mineup() | |
| 88 | for i=1,depth-1 do | |
| 89 | mine2() | |
| 90 | end | |
| 91 | end | |
| 92 | ||
| 93 | local row3 = function() | |
| 94 | mineup() | |
| 95 | minedown() | |
| 96 | for i=1,depth-1 do | |
| 97 | mine3() | |
| 98 | end | |
| 99 | end | |
| 100 | ||
| 101 | local quarry1 = function() | |
| 102 | if height > 1 then | |
| 103 | move('u',2)
| |
| 104 | h=h+2 | |
| 105 | tturn('u')
| |
| 106 | forward = not forward | |
| 107 | end | |
| 108 | for i=1,width do | |
| 109 | row1() | |
| 110 | if forward==true and i ~= width then | |
| 111 | if not (runs % 2 == 0) then | |
| 112 | move('r',1)
| |
| 113 | tturn('r')
| |
| 114 | else | |
| 115 | move('l',1)
| |
| 116 | tturn('l')
| |
| 117 | end | |
| 118 | forward=not forward | |
| 119 | elseif forward==false and i ~= width then | |
| 120 | if not (runs % 2 == 0) then | |
| 121 | move('l',1)
| |
| 122 | tturn('l')
| |
| 123 | else | |
| 124 | move('r',1)
| |
| 125 | tturn('r')
| |
| 126 | end | |
| 127 | forward=not forward | |
| 128 | end | |
| 129 | end | |
| 130 | end | |
| 131 | ||
| 132 | local quarry2 = function() | |
| 133 | if height > 2 then | |
| 134 | move('u',2)
| |
| 135 | h=h+2 | |
| 136 | tturn('u')
| |
| 137 | forward = not forward | |
| 138 | end | |
| 139 | for i=1,width do | |
| 140 | row2() | |
| 141 | if forward==true and i ~= width then | |
| 142 | if not (runs % 2 == 0) then | |
| 143 | move('r',1)
| |
| 144 | tturn('r')
| |
| 145 | else | |
| 146 | move('l',1)
| |
| 147 | tturn('l')
| |
| 148 | end | |
| 149 | forward=not forward | |
| 150 | elseif forward==false and i ~= width then | |
| 151 | if not (runs % 2 == 0) then | |
| 152 | move('l',1)
| |
| 153 | tturn('l')
| |
| 154 | else | |
| 155 | move('r',1)
| |
| 156 | tturn('r')
| |
| 157 | end | |
| 158 | forward=not forward | |
| 159 | end | |
| 160 | end | |
| 161 | ||
| 162 | end | |
| 163 | ||
| 164 | local quarry3 = function() | |
| 165 | if height > 3 and start == false then | |
| 166 | move('u',3)
| |
| 167 | h=h+3 | |
| 168 | tturn('u')
| |
| 169 | forward = not forward | |
| 170 | elseif start == true then | |
| 171 | move('u',1)
| |
| 172 | h=h+1 | |
| 173 | start = not start | |
| 174 | end | |
| 175 | for i=1,width do | |
| 176 | row3() | |
| 177 | if forward==true and i ~= width then | |
| 178 | if not ((m3c + 1)% 2 == 0) then | |
| 179 | move('r',1)
| |
| 180 | tturn('r')
| |
| 181 | else | |
| 182 | move('l',1)
| |
| 183 | tturn('l')
| |
| 184 | end | |
| 185 | forward=not forward | |
| 186 | elseif forward==false and i ~= width then | |
| 187 | if not ((m3c + 1)% 2 == 0) then | |
| 188 | move('l',1)
| |
| 189 | tturn('l')
| |
| 190 | else | |
| 191 | move('r',1)
| |
| 192 | tturn('r')
| |
| 193 | end | |
| 194 | forward=not forward | |
| 195 | end | |
| 196 | end | |
| 197 | end | |
| 198 | ||
| 199 | --Argument Handling | |
| 200 | if tArgs[1] ~= nil then | |
| 201 | if #tArgs ~= 3 then | |
| 202 | printUsage(1) | |
| 203 | elseif not tonumber(tArgs[1]) then | |
| 204 | printUsage(2) | |
| 205 | elseif tonumber(tArgs[1]) < 0 then | |
| 206 | printUsage(3) | |
| 207 | elseif not tonumber(tArgs[2]) then | |
| 208 | printUsage(4) | |
| 209 | elseif tonumber(tArgs[2]) < 0 then | |
| 210 | printUsage(5) | |
| 211 | elseif not tonumber(tArgs[3]) then | |
| 212 | printUsage(6) | |
| 213 | elseif tonumber(tArgs[3]) < 0 then | |
| 214 | printUsage(7) | |
| 215 | else | |
| 216 | depth = tonumber(tArgs[1]) | |
| 217 | print('depth = ' .. tArgs[1])
| |
| 218 | width = tonumber(tArgs[2]) | |
| 219 | print('width = ' .. tArgs[2])
| |
| 220 | height = tonumber(tArgs[3]) | |
| 221 | print('height = ' .. tArgs[3])
| |
| 222 | end | |
| 223 | else | |
| 224 | printUsage(0) | |
| 225 | end | |
| 226 | ||
| 227 | --calculate how to mine | |
| 228 | h = tonumber(height) | |
| 229 | while h > 2 do | |
| 230 | h=h-3 | |
| 231 | m3=m3+1 | |
| 232 | end | |
| 233 | if h>1 then | |
| 234 | h=0 | |
| 235 | m2=1 | |
| 236 | elseif h>0 then | |
| 237 | h=0 | |
| 238 | m1=1 | |
| 239 | end | |
| 240 | ||
| 241 | -- Begin Mining | |
| 242 | runs = m3 + m2 +m1 | |
| 243 | start=true | |
| 244 | m3c=0 | |
| 245 | while m3c < m3 do | |
| 246 | quarry3() | |
| 247 | m3c=m3c+1 | |
| 248 | end | |
| 249 | if m2 > 0 then | |
| 250 | quarry2() | |
| 251 | end | |
| 252 | if m1 > 0 then | |
| 253 | quarry1() | |
| 254 | end | |
| 255 | if (runs % 2 == 0) then | |
| 256 | --already at start | |
| 257 | move('d',h)
| |
| 258 | tturn('u')
| |
| 259 | else | |
| 260 | --move back to left | |
| 261 | if forward == true then | |
| 262 | move('l',width-1)
| |
| 263 | move('l',depth-1)
| |
| 264 | tturn('u')
| |
| 265 | move('d',h)
| |
| 266 | else | |
| 267 | move('r',width-1)
| |
| 268 | tturn('r')
| |
| 269 | move('d',h)
| |
| 270 | end | |
| 271 | end |