SHOW:
|
|
- or go back to the newest paste.
| 1 | -- --------------------------------------------------------------------------------------- -- | |
| 2 | -- START OF THE DEFAULT CONFIG OF THIS PROGRAM, THOUGH COMMAND LINE PARAMETERS CAN BE USED -- | |
| 3 | -- FOR THE DIRECTION PARAMETERS USE up/down/left/right/forward/back -- | |
| 4 | -- --------------------------------------------------------------------------------------- -- | |
| 5 | ||
| 6 | args={...}
| |
| 7 | ||
| 8 | local configuration={}
| |
| 9 | ||
| 10 | -- THE NUMBER OF LEVELS | |
| 11 | configuration.numL = 1 | |
| 12 | ||
| 13 | -- THE NUMBER OF TUNNELS | |
| 14 | configuration.numT = 4 | |
| 15 | ||
| 16 | -- THE NUMBER OF SHAFTS TO EXCAVATE | |
| 17 | - | configuration.numS = 16 |
| 17 | + | configuration.numS = 21 |
| 18 | ||
| 19 | -- HOW MANY LEVELS TO SKIP | |
| 20 | configuration.skipL = 0 | |
| 21 | ||
| 22 | -- HOW MANY TUNNELS TO SKIP | |
| 23 | configuration.skipT = 0 | |
| 24 | ||
| 25 | -- HOW MANY SHAFTS TO SKIP | |
| 26 | configuration.skipS = 0 | |
| 27 | ||
| 28 | -- THE DIRECTION OF THE NEXT LEVEL (UP or DOWN) | |
| 29 | configuration.nextDirL = "up" | |
| 30 | ||
| 31 | -- THE DIRECTION OF THE NEXT TUNNEL (LEFT or RIGHT) | |
| 32 | configuration.nextDirT = "left" | |
| 33 | ||
| 34 | -- THE HEIGHT OF THE LEVELS/TUNNELS | |
| 35 | configuration.height = 3 | |
| 36 | ||
| 37 | -- THE NUMBER OF BLOCKS BETWEEN EACH SHAFT | |
| 38 | - | configuration.blocksBetweenShafts = 3 |
| 38 | + | configuration.blocksBetweenShafts = 2 |
| 39 | ||
| 40 | -- HOW MANY BLOCKS WILL THE TURTLE MOVE BEFORE DIGGING THE FIRST SHAFT | |
| 41 | configuration.firstShaftOffset = 4 | |
| 42 | ||
| 43 | -- THE NUMBER OF BLOCKS THE EVEN LEVEL SHAFTS WILL BE OFFSET | |
| 44 | configuration.evenLevelOffset = 2 | |
| 45 | ||
| 46 | -- DOES THE TURTLE ALSO PLACE TORCHES | |
| 47 | configuration.placeTorches = false | |
| 48 | ||
| 49 | -- IS THERE A SINGLE DROPOFF CHEST (true) OR ONE PER DIRECTION, PER LEVEL (false) | |
| 50 | configuration.singleChest = false | |
| 51 | ||
| 52 | -- THE RADIUS OF THE CIRCLE ON WHICH THE REFUELING STATIONS ARE POSITIONED | |
| 53 | configuration.centerRadius = 5 | |
| 54 | ||
| 55 | -- THE NUMBER OF BLOCK TYPES THE TURTLE WILL _NOT_ DIG UNLESS NEEDED | |
| 56 | -- DEFAULT CONSIDERS: Smooth stone, Dirt, Gravel, Marble (Tekkit), Wood, stone bricks | |
| 57 | - | configuration.numIgnoreBlocks = 6 |
| 57 | + | configuration.numIgnoreBlocks = 4 |
| 58 | ||
| 59 | -- DOES THE TURTLE REQUIRE FUEL TO OPERATE? | |
| 60 | - | configuration.requiresFuel = true |
| 60 | + | configuration.requiresFuel = false |
| 61 | ||
| 62 | -- THE AMOUNT OF FUEL THE TURTLE WILL STORE BEFORE HEADING OF TO A SHAFT | |
| 63 | configuration.departureFuel = 1200 | |
| 64 | ||
| 65 | -- THE AMOUNT OF FUEL AT WHICH THE TURTLE WILL RETURN TO DROPOFF | |
| 66 | configuration.returnFuel = 200 | |
| 67 | ||
| 68 | -- THE DIRECTION OF THE FUEL ITEMS (IN THE REFUELING STATION) | |
| 69 | configuration.fuelSuckDir = "up" | |
| 70 | ||
| 71 | -- THE DIRECTION WHERE THE TURTLE WILL DROP LEFTOVERS (BUCKETS) | |
| 72 | configuration.fuelDropDir = "down" | |
| 73 | ||
| 74 | -- THE DIRECTION WHERE THE TURTLE WILL DROP ANY MINED ITEMS | |
| 75 | configuration.itemDropDir = "down" | |
| 76 | ||
| 77 | -- THE DIRECTION OF THE TORCHES | |
| 78 | configuration.torchSuckDir = "right" | |
| 79 | ||
| 80 | -- THE DIRECTION OF THE IGNORE BLOCKS | |
| 81 | configuration.ignoreDir = "left" | |
| 82 | ||
| 83 | -- USED TO KEEP TRACK OF THE POSITION OF THE TUNNEL | |
| 84 | configuration.currentL = 1 | |
| 85 | configuration.currentT = 1 | |
| 86 | configuration.currentS = 0 | |
| 87 | ||
| 88 | -- ------------------------------------------------------------------------------------- -- | |
| 89 | -- END OF THE DEFAULT CONFIG OF THIS PROGRAM, THOUGH COMMAND LINE PARAMETERS CAN BE USED -- | |
| 90 | -- FOR THE DIRECTION PARAMETERS USE up/down/left/right/forward/back -- | |
| 91 | -- ------------------------------------------------------------------------------------- -- | |
| 92 | ||
| 93 | -- -------------------------------------------------- -- | |
| 94 | -- START OF THE PARSING OF THE COMMAND LINE ARGUMENTS -- | |
| 95 | -- -------------------------------------------------- -- | |
| 96 | ||
| 97 | -- PRINTS THE MANUAL TO THE TERMINAL IN CASE THE USER SPECIFIED INCORRECT VALUES | |
| 98 | function printManual() | |
| 99 | term.clear() | |
| 100 | print("Usage: digOres [OPTIONS] (1/3)")
| |
| 101 | print("------------------------------")
| |
| 102 | print(" -numL <num> (=nr. of levels)")
| |
| 103 | print(" -numT <num> (=nr. of tunnels)")
| |
| 104 | print(" -numS <num> (=nr. of shafts)")
| |
| 105 | print(" -skipL <num> (=skip # levels)")
| |
| 106 | print(" -skipT <num> (=skip # tunnels)")
| |
| 107 | print(" -skipS <num> (=skip # shafts)")
| |
| 108 | print(" -dirNextL <dir> (=next lev. U/D)")
| |
| 109 | print(" -dirNextT <dir> (=next tun. L/R)")
| |
| 110 | print("PRESS ANY KEY TO CONTINUE")
| |
| 111 | print("")
| |
| 112 | read() | |
| 113 | term.clear() | |
| 114 | print("Usage: digOres [OPTIONS] (2/3)")
| |
| 115 | print("------------------------------")
| |
| 116 | print(" -height <num> (=level height 2/3)")
| |
| 117 | print(" -betw <num> (=blocks betw shafts)")
| |
| 118 | print(" -firstOffs <num>(=first shaft offset)")
| |
| 119 | print(" -evenOffs <num> (=even level offset)")
| |
| 120 | print(" -torches (=place torches)")
| |
| 121 | print(" -oneChest (=single drop chest)")
| |
| 122 | print(" -rad <num> (=center radius)")
| |
| 123 | print(" -numIgnore <num>(=num ignore blocks)")
| |
| 124 | print("PRESS ANY KEY TO CONTINUE")
| |
| 125 | print("")
| |
| 126 | read() | |
| 127 | term.clear() | |
| 128 | print("Usage: digOres [OPTIONS] (3/3)")
| |
| 129 | print("------------------------------")
| |
| 130 | print(" -noFuel (=no need for fuel)")
| |
| 131 | print(" -depFuel <num> (=departure fuel)")
| |
| 132 | print(" -retFuel <num> (=return fuel)")
| |
| 133 | print(" -fuelS <dir> (=fuel suck dir)")
| |
| 134 | print(" -fuelD <dir> (=fuel drop dir)")
| |
| 135 | print(" -torchS <dir> (=torch suck dir)")
| |
| 136 | print(" -itemD <dir> (=item drop dir)")
| |
| 137 | print(" -ignoreS <dir> (=ignore block dir)")
| |
| 138 | print("")
| |
| 139 | print("")
| |
| 140 | end | |
| 141 | ||
| 142 | -- PRINTS THE POSSIBLE DIRECTION VALUES TO THE TERMINAL | |
| 143 | function printDirs() | |
| 144 | term.clear() | |
| 145 | print("Invalid direction chosen: pick from:")
| |
| 146 | print("------------------------------------")
| |
| 147 | print(" up")
| |
| 148 | print(" down")
| |
| 149 | print(" forward")
| |
| 150 | print(" back")
| |
| 151 | print(" right")
| |
| 152 | print(" left")
| |
| 153 | print("")
| |
| 154 | print("")
| |
| 155 | print("")
| |
| 156 | print("")
| |
| 157 | end | |
| 158 | ||
| 159 | -- CHECKS IF A STRING DENOTES A DIRECTION | |
| 160 | function isDir(dir) | |
| 161 | if dir=="forward" or dir=="back" or dir=="left" or dir=="right" or dir=="up" or dir=="down" then | |
| 162 | return true | |
| 163 | end | |
| 164 | return false | |
| 165 | end | |
| 166 | ||
| 167 | -- READS IN THE COMMAND LINE ARGUMENTS AND PARSES THEM | |
| 168 | readParams = 0 | |
| 169 | while readParams < #args do | |
| 170 | if args[readParams+1] == "-numL" then | |
| 171 | if not (readParams + 1 < #args) then | |
| 172 | printManual() | |
| 173 | return | |
| 174 | end | |
| 175 | configuration.numL=tonumber(args[readParams+2]) | |
| 176 | readParams=readParams+2 | |
| 177 | ||
| 178 | elseif args[readParams+1] == "-numT" then | |
| 179 | if not (readParams + 1 < #args) then | |
| 180 | printManual() | |
| 181 | return | |
| 182 | end | |
| 183 | configuration.numT=tonumber(args[readParams+2]) | |
| 184 | readParams=readParams+2 | |
| 185 | ||
| 186 | elseif args[readParams+1] == "-numS" then | |
| 187 | if not (readParams + 1 < #args) then | |
| 188 | printManual() | |
| 189 | return | |
| 190 | end | |
| 191 | configuration.numS=tonumber(args[readParams+2]) | |
| 192 | readParams=readParams+2 | |
| 193 | ||
| 194 | elseif args[readParams+1] == "-skipL" then | |
| 195 | if not (readParams + 1 < #args) then | |
| 196 | printManual() | |
| 197 | return | |
| 198 | end | |
| 199 | configuration.skipL=tonumber(args[readParams+2]) | |
| 200 | readParams=readParams+2 | |
| 201 | ||
| 202 | elseif args[readParams+1] == "-skipT" then | |
| 203 | if not (readParams + 1 < #args) then | |
| 204 | printManual() | |
| 205 | return | |
| 206 | end | |
| 207 | configuration.skipT=tonumber(args[readParams+2]) | |
| 208 | readParams=readParams+2 | |
| 209 | ||
| 210 | elseif args[readParams+1] == "-skipS" then | |
| 211 | if not (readParams + 1 < #args) then | |
| 212 | printManual() | |
| 213 | return | |
| 214 | end | |
| 215 | configuration.skipS=tonumber(args[readParams+2]) | |
| 216 | readParams=readParams+2 | |
| 217 | ||
| 218 | elseif args[readParams+1] == "-dirNextL" then | |
| 219 | if not (readParams + 1 < #args) then | |
| 220 | printManual() | |
| 221 | return | |
| 222 | end | |
| 223 | if not isDir(args[readParams+2]) then | |
| 224 | printDirs() | |
| 225 | return | |
| 226 | end | |
| 227 | configuration.nextDirL=args[readParams+2] | |
| 228 | readParams=readParams+2 | |
| 229 | ||
| 230 | elseif args[readParams+1] == "-dirNextT" then | |
| 231 | if not (readParams + 1 < #args) then | |
| 232 | printManual() | |
| 233 | return | |
| 234 | end | |
| 235 | if not isDir(args[readParams+2]) then | |
| 236 | printDirs() | |
| 237 | return | |
| 238 | end | |
| 239 | configuration.nextDirT=args[readParams+2] | |
| 240 | readParams=readParams+2 | |
| 241 | ||
| 242 | elseif args[readParams+1] == "-height" then | |
| 243 | if not (readParams + 1 < #args) then | |
| 244 | printManual() | |
| 245 | return | |
| 246 | end | |
| 247 | configuration.height=tonumber(args[readParams+2]) | |
| 248 | readParams=readParams+2 | |
| 249 | ||
| 250 | elseif args[readParams+1] == "-betw" then | |
| 251 | if not (readParams + 1 < #args) then | |
| 252 | printManual() | |
| 253 | return | |
| 254 | end | |
| 255 | configuration.blocksBetweenShafts=tonumber(args[readParams+2]) | |
| 256 | readParams=readParams+2 | |
| 257 | ||
| 258 | elseif args[readParams+1] == "-firstOffs" then | |
| 259 | if not (readParams + 1 < #args) then | |
| 260 | printManual() | |
| 261 | return | |
| 262 | end | |
| 263 | configuration.firstShaftOffset=tonumber(args[readParams+2]) | |
| 264 | readParams=readParams+2 | |
| 265 | ||
| 266 | elseif args[readParams+1] == "-evenOffs" then | |
| 267 | if not (readParams + 1 < #args) then | |
| 268 | printManual() | |
| 269 | return | |
| 270 | end | |
| 271 | configuration.evenLevelOffset=tonumber(args[readParams+2]) | |
| 272 | readParams=readParams+2 | |
| 273 | ||
| 274 | elseif args[readParams+1] == "-torches" then | |
| 275 | configuration.placeTorches=true | |
| 276 | readParams=readParams+1 | |
| 277 | ||
| 278 | elseif args[readParams+1] == "-oneChest" then | |
| 279 | configuration.singleChest=true | |
| 280 | readParams=readParams+1 | |
| 281 | ||
| 282 | elseif args[readParams+1] == "-rad" then | |
| 283 | if not (readParams + 1 < #args) then | |
| 284 | printManual() | |
| 285 | return | |
| 286 | end | |
| 287 | configuration.centerRadius=tonumber(args[readParams+2]) | |
| 288 | readParams=readParams+2 | |
| 289 | ||
| 290 | elseif args[readParams+1] == "-numIgnore" then | |
| 291 | if not (readParams + 1 < #args) then | |
| 292 | printManual() | |
| 293 | return | |
| 294 | end | |
| 295 | configuration.numIgnoreBlocks=tonumber(args[readParams+2]) | |
| 296 | readParams=readParams+2 | |
| 297 | ||
| 298 | elseif args[readParams+1] == "-noFuel" then | |
| 299 | configuration.requiresFuel=false | |
| 300 | readParams=readParams+1 | |
| 301 | ||
| 302 | elseif args[readParams+1] == "-depFuel" then | |
| 303 | if not (readParams + 1 < #args) then | |
| 304 | printManual() | |
| 305 | return | |
| 306 | end | |
| 307 | configuration.departureFuel=tonumber(args[readParams+2]) | |
| 308 | readParams=readParams+2 | |
| 309 | ||
| 310 | elseif args[readParams+1] == "-retFuel" then | |
| 311 | if not (readParams + 1 < #args) then | |
| 312 | printManual() | |
| 313 | return | |
| 314 | end | |
| 315 | configuration.returnFuel=tonumber(args[readParams+2]) | |
| 316 | readParams=readParams+2 | |
| 317 | ||
| 318 | elseif args[readParams+1] == "-fuelS" then | |
| 319 | if not (readParams + 1 < #args) then | |
| 320 | printManual() | |
| 321 | return | |
| 322 | end | |
| 323 | if not isDir(args[readParams+2]) then | |
| 324 | printDirs() | |
| 325 | return | |
| 326 | end | |
| 327 | configuration.fuelSuckDir=args[readParams+2] | |
| 328 | readParams=readParams+2 | |
| 329 | ||
| 330 | elseif args[readParams+1] == "-fuelD" then | |
| 331 | if not (readParams + 1 < #args) then | |
| 332 | printManual() | |
| 333 | return | |
| 334 | end | |
| 335 | if not isDir(args[readParams+2]) then | |
| 336 | printDirs() | |
| 337 | return | |
| 338 | end | |
| 339 | configuration.fuelDropDir=args[readParams+2] | |
| 340 | readParams=readParams+2 | |
| 341 | ||
| 342 | elseif args[readParams+1] == "-torchS" then | |
| 343 | if not (readParams + 1 < #args) then | |
| 344 | printManual() | |
| 345 | return | |
| 346 | end | |
| 347 | if not isDir(args[readParams+2]) then | |
| 348 | printDirs() | |
| 349 | return | |
| 350 | end | |
| 351 | configuration.torchSuckDir=args[readParams+2] | |
| 352 | readParams=readParams+2 | |
| 353 | ||
| 354 | elseif args[readParams+1] == "-itemD" then | |
| 355 | if not (readParams + 1 < #args) then | |
| 356 | printManual() | |
| 357 | return | |
| 358 | end | |
| 359 | if not isDir(args[readParams+2]) then | |
| 360 | printDirs() | |
| 361 | return | |
| 362 | end | |
| 363 | configuration.itemDropDir=args[readParams+2] | |
| 364 | readParams=readParams+2 | |
| 365 | ||
| 366 | elseif args[readParams+1] == "-ignoreS" then | |
| 367 | if not (readParams + 1 < #args) then | |
| 368 | printManual() | |
| 369 | return | |
| 370 | end | |
| 371 | if not isDir(args[readParams+2]) then | |
| 372 | printDirs() | |
| 373 | return | |
| 374 | end | |
| 375 | configuration.ignoreDir=args[readParams+2] | |
| 376 | readParams=readParams+2 | |
| 377 | ||
| 378 | else | |
| 379 | printManual() | |
| 380 | return | |
| 381 | end | |
| 382 | end | |
| 383 | ||
| 384 | -- ------------------------------------------------ -- | |
| 385 | -- END OF THE PARSING OF THE COMMAND LINE ARGUMENTS -- | |
| 386 | -- ------------------------------------------------ -- | |
| 387 | ||
| 388 | -- ---------------------------------------------------------------------- -- | |
| 389 | -- START OF COPY/PASTED CODE EXTENDING THE FUNCTIONALITY OF THE BASIC API -- | |
| 390 | -- SOME OF THESE FUNCTIONS MIGHT BE REDUNDANT FOR THIS PROGRAM -- | |
| 391 | -- ---------------------------------------------------------------------- -- | |
| 392 | ||
| 393 | up = "up" | |
| 394 | down = "down" | |
| 395 | forward = "forward" | |
| 396 | back = "back" | |
| 397 | right = "right" | |
| 398 | left = "left" | |
| 399 | ||
| 400 | -- ALIGNS THE TURTLE TO MOVE, DIG, ... IN A CERTAIN DIRECTION | |
| 401 | function turnTo(dir) | |
| 402 | if dir==back then | |
| 403 | turtle.turnLeft() | |
| 404 | turtle.turnLeft() | |
| 405 | elseif dir==right then | |
| 406 | turtle.turnRight() | |
| 407 | elseif dir==left then | |
| 408 | turtle.turnLeft() | |
| 409 | end | |
| 410 | end | |
| 411 | ||
| 412 | -- REALIGNS THE TURTLE TO THE ORIGINAL DIRECTION | |
| 413 | function turnFrom(dir) | |
| 414 | if dir==back then | |
| 415 | turtle.turnLeft() | |
| 416 | turtle.turnLeft() | |
| 417 | elseif dir==right then | |
| 418 | turtle.turnLeft() | |
| 419 | elseif dir==left then | |
| 420 | turtle.turnRight() | |
| 421 | end | |
| 422 | end | |
| 423 | ||
| 424 | -- RETURNS THE DIRECTION THE TURTLE SHOULD MOVE, DIG, ... AFTER THE PREVIOUS ALIGNMENT | |
| 425 | function turnedDir(dir) | |
| 426 | if dir==right or dir==left or dir==back then | |
| 427 | return forward | |
| 428 | else | |
| 429 | return dir | |
| 430 | end | |
| 431 | end | |
| 432 | ||
| 433 | -- RETURNS THE REVERSE DIRECTION SO UP BECOMES DOWN ETC | |
| 434 | function reverseDir(dir) | |
| 435 | if dir==forward then | |
| 436 | return back | |
| 437 | elseif dir==back then | |
| 438 | return forward | |
| 439 | elseif dir==up then | |
| 440 | return down | |
| 441 | elseif dir==down then | |
| 442 | return up | |
| 443 | elseif dir==right then | |
| 444 | return left | |
| 445 | elseif dir==left then | |
| 446 | return right | |
| 447 | end | |
| 448 | end | |
| 449 | ||
| 450 | -- RETURNS THE DIRECTION USED BY THE PERIPHERAL FUNCTIONS | |
| 451 | function peripheralDir(dir) | |
| 452 | if dir==forward then | |
| 453 | return "front" | |
| 454 | elseif dir==up then | |
| 455 | return "top" | |
| 456 | elseif dir==down then | |
| 457 | return "bottom" | |
| 458 | end | |
| 459 | end | |
| 460 | ||
| 461 | -- MOVES THE TURTLE A CERTAIN DISTANCE IN A CERTAIN DIRECTION | |
| 462 | -- IF NO DISTANCE IS SPECIFIED IT WILL JUST MOVE 1 STEP | |
| 463 | function move(dir, steps) | |
| 464 | steps = steps or 1 | |
| 465 | local stepsTaken = 0 | |
| 466 | turnTo(dir) | |
| 467 | local tDir=turnedDir(dir) | |
| 468 | for i=1,steps,1 do | |
| 469 | local tries=0 | |
| 470 | local success=false | |
| 471 | while ((not success) and (tries<10)) do | |
| 472 | if tDir==forward then | |
| 473 | success=turtle.forward() | |
| 474 | elseif tDir==up then | |
| 475 | success=turtle.up() | |
| 476 | elseif tDir==down then | |
| 477 | success=turtle.down() | |
| 478 | end | |
| 479 | if success then | |
| 480 | break | |
| 481 | end | |
| 482 | attack(tDir) | |
| 483 | tries = tries+1 | |
| 484 | sleep(0.5) | |
| 485 | end | |
| 486 | if not success then | |
| 487 | break | |
| 488 | end | |
| 489 | stepsTaken=stepsTaken+1 | |
| 490 | end | |
| 491 | turnFrom(dir) | |
| 492 | return stepsTaken | |
| 493 | end | |
| 494 | ||
| 495 | -- DIGS IN A CERTAIN DIRECTION | |
| 496 | function dig(dir) | |
| 497 | turnTo(dir) | |
| 498 | local tDir=turnedDir(dir) | |
| 499 | local tries=0 | |
| 500 | local success=false | |
| 501 | if not (peripheral.getType(peripheralDir(tDir))=="turtle") then | |
| 502 | while ((detect(tDir)) and (tries<10)) do | |
| 503 | if tDir==forward then | |
| 504 | success=turtle.dig() | |
| 505 | elseif tDir==up then | |
| 506 | success=turtle.digUp() | |
| 507 | elseif tDir==down then | |
| 508 | success=turtle.digDown() | |
| 509 | end | |
| 510 | if not success then | |
| 511 | tries = tries+1 | |
| 512 | end | |
| 513 | sleep(0.5) | |
| 514 | end | |
| 515 | end | |
| 516 | turnFrom(dir) | |
| 517 | return success | |
| 518 | end | |
| 519 | ||
| 520 | -- DIGS AND MOVES A CERTAIN DISTANCE IN A CERTAIN DIRECTION | |
| 521 | -- IF NO DISTANCE IS SPECIFIED IT WILL JUST MOVE 1 STEP | |
| 522 | function digAndMove(dir, steps) | |
| 523 | steps = steps or 1 | |
| 524 | local stepsTaken = 0 | |
| 525 | turnTo(dir) | |
| 526 | local tDir=turnedDir(dir) | |
| 527 | for i=1,steps,1 do | |
| 528 | dig(tDir) | |
| 529 | local success=move(tDir) | |
| 530 | if success==0 then | |
| 531 | turnFrom(dir) | |
| 532 | return stepsTaken | |
| 533 | end | |
| 534 | stepsTaken=stepsTaken+1 | |
| 535 | end | |
| 536 | turnFrom(dir) | |
| 537 | return stepsTaken | |
| 538 | end | |
| 539 | ||
| 540 | -- ATTACKS IN A CERTAIN DIRECTION | |
| 541 | function attack(dir) | |
| 542 | turnTo(dir) | |
| 543 | local tDir=turnedDir(dir) | |
| 544 | while turtle.attack(tDir) do | |
| 545 | sleep(0.3) | |
| 546 | end | |
| 547 | turnFrom(dir) | |
| 548 | end | |
| 549 | ||
| 550 | -- PLACES A BLOCK FROM A CERTAIN SLOT IN A CERTAIN DIRECTION | |
| 551 | function place(dir, slot) | |
| 552 | turtle.select(slot) | |
| 553 | turnTo(dir) | |
| 554 | local tDir=turnedDir(dir) | |
| 555 | if tDir==forward then | |
| 556 | turtle.place() | |
| 557 | elseif tDir==up then | |
| 558 | turtle.placeUp() | |
| 559 | elseif tDir==down then | |
| 560 | turtle.placeDown() | |
| 561 | end | |
| 562 | turnFrom(dir) | |
| 563 | end | |
| 564 | ||
| 565 | -- DETECTS IF THERE IS A BLOCK IN A CERTAIN DIRECTION | |
| 566 | function detect(dir) | |
| 567 | local block = false | |
| 568 | turnTo(dir) | |
| 569 | local tDir=turnedDir(dir) | |
| 570 | if tDir==forward then | |
| 571 | block = turtle.detect() | |
| 572 | elseif tDir==up then | |
| 573 | block = turtle.detectUp() | |
| 574 | elseif tDir==down then | |
| 575 | block = turtle.detectDown() | |
| 576 | end | |
| 577 | turnFrom(dir) | |
| 578 | return block | |
| 579 | end | |
| 580 | ||
| 581 | -- COMPARES A BLOCK IN A CERTAIN DIRECTION TO THE BLOCK IN A CERTAIN INVENTORY SLOT | |
| 582 | function compare(dir, slot) | |
| 583 | local same = false | |
| 584 | turtle.select(slot) | |
| 585 | turnTo(dir) | |
| 586 | local tDir=turnedDir(dir) | |
| 587 | if tDir==forward then | |
| 588 | same = turtle.compare() | |
| 589 | elseif tDir==up then | |
| 590 | same = turtle.compareUp() | |
| 591 | elseif tDir==down then | |
| 592 | same = turtle.compareDown() | |
| 593 | end | |
| 594 | turnFrom(dir) | |
| 595 | return same | |
| 596 | end | |
| 597 | ||
| 598 | -- COMPARES A BLOCK IN A CERTAIN DIRECTION TO A CERTAIN INVENTORY SLOT | |
| 599 | -- IF IT MATCHES THE BLOCK WILL BE REPLACED BY A BLOCK IN THE SPECIFIED SLOT | |
| 600 | function compareAndReplace(dir, compareSlot, replaceSlot) | |
| 601 | local replaced = false | |
| 602 | turnTo(dir) | |
| 603 | local tDir=turnedDir(dir) | |
| 604 | if not compare(tDir, compareSlot) then | |
| 605 | replaced = true | |
| 606 | dig(tDir) | |
| 607 | place(tDir, replaceSlot) | |
| 608 | end | |
| 609 | turnFrom(dir) | |
| 610 | return replaced | |
| 611 | end | |
| 612 | ||
| 613 | -- DROPS A CERTAIN NUMBER OF ITEMS IN A CERTAIN DIRECTION | |
| 614 | -- IF NO NUMBER IS SPECIFIED IT WILL DROP ALL THE ITEMS | |
| 615 | function drop(dir, num) | |
| 616 | turnTo(dir) | |
| 617 | local tDir=turnedDir(dir) | |
| 618 | if num == null then | |
| 619 | if tDir==forward then | |
| 620 | turtle.drop() | |
| 621 | elseif tDir==up then | |
| 622 | turtle.dropUp() | |
| 623 | elseif tDir==down then | |
| 624 | turtle.dropDown() | |
| 625 | end | |
| 626 | else | |
| 627 | if tDir==forward then | |
| 628 | turtle.drop(num) | |
| 629 | elseif tDir==up then | |
| 630 | turtle.dropUp(num) | |
| 631 | elseif tDir==down then | |
| 632 | turtle.dropDown(num) | |
| 633 | end | |
| 634 | end | |
| 635 | turnFrom(dir) | |
| 636 | end | |
| 637 | ||
| 638 | -- SUCKS UP ITEMS FROM A CERTAIN DIRECTION | |
| 639 | function suck(dir) | |
| 640 | turnTo(dir) | |
| 641 | local tDir=turnedDir(dir) | |
| 642 | if tDir==forward then | |
| 643 | turtle.suck() | |
| 644 | elseif tDir==up then | |
| 645 | turtle.suckUp() | |
| 646 | elseif tDir==down then | |
| 647 | turtle.suckDown() | |
| 648 | end | |
| 649 | turnFrom(dir) | |
| 650 | end | |
| 651 | ||
| 652 | -- REFUELS THE TURTLE, PARAMETERS DENOTE IN WHICH DIRECTION THE FUEL ITEMS WILL BE, WHERE TO DROP ANY | |
| 653 | -- LEFTOVERS (BUCKETS) IN WHICH INVENTORY SPOT THE FUEL WILL BE AND HOW MUCH FUEL NEEDS TO BE STORED | |
| 654 | function refuel(suckDir, dropDir, fuelSlot, requiredFuel) | |
| 655 | - | turtle.select(fuelSlot) |
| 655 | + | --[[turtle.select(fuelSlot) |
| 656 | while turtle.getFuelLevel() < requiredFuel do | |
| 657 | suck(suckDir) | |
| 658 | turtle.refuel() | |
| 659 | drop(dropDir) | |
| 660 | sleep(0) | |
| 661 | end]]-- | |
| 662 | turtle.select(1) | |
| 663 | end | |
| 664 | ||
| 665 | -- -------------------------------------------------------------------- -- | |
| 666 | -- END OF COPY/PASTED CODE EXTENDING THE FUNCTIONALITY OF THE BASIC API -- | |
| 667 | -- -------------------------------------------------------------------- -- | |
| 668 | ||
| 669 | -- -------------------------------------------------- -- | |
| 670 | -- START OF THE FUNCTIONS SHARED BETWEEN ALL PROGRAMS -- | |
| 671 | -- -------------------------------------------------- -- | |
| 672 | ||
| 673 | -- CHECKS IF THE TURTLE NEEDS RESTOCKING | |
| 674 | function needsRestocking(configuration) | |
| 675 | - | if turtle.getFuelLevel() < configuration.returnFuel then |
| 675 | + | --[[if turtle.getFuelLevel() < configuration.returnFuel then |
| 676 | return true | |
| 677 | end]]-- | |
| 678 | if turtle.getItemCount(15)~=0 or turtle.getItemCount(16)~=0 then | |
| 679 | return true | |
| 680 | end | |
| 681 | if configuration.placeTorches and turtle.getItemCount(1)==0 then | |
| 682 | return true | |
| 683 | end | |
| 684 | return false | |
| 685 | end | |
| 686 | ||
| 687 | -- EMPTIES THE INVENTORY, GETS NEW TORCHES AND NEW FUEL | |
| 688 | function restockTurtle(configuration, ignoreBlocks) | |
| 689 | tempL = configuration.currentL | |
| 690 | tempT = configuration.currentT | |
| 691 | tempS = configuration.currentS | |
| 692 | if configuration.singleChest then | |
| 693 | moveToLocation(configuration, 1, 1, 0) | |
| 694 | else | |
| 695 | moveToLocation(configuration, tempL, tempT, 0) | |
| 696 | end | |
| 697 | dropoff(configuration, ignoreBlocks) | |
| 698 | if configuration.placeTorches then | |
| 699 | restockTorches(configuration, ignoreBlocks) | |
| 700 | end | |
| 701 | if configuration.requiresFuel then | |
| 702 | refuel(configuration.fuelSuckDir, configuration.fuelDropDir, 16, configuration.departureFuel) | |
| 703 | end | |
| 704 | moveToLocation(configuration, tempL, tempT, tempS) | |
| 705 | end | |
| 706 | ||
| 707 | -- PARTIALLY EMPTIES THE INVENTORY | |
| 708 | function dropoff(configuration, ignoreBlocks) | |
| 709 | ignoreBlocks = ignoreBlocks or 0 | |
| 710 | local torchSlot=0 | |
| 711 | if configuration.placeTorches then | |
| 712 | torchSlot=1 | |
| 713 | end | |
| 714 | ||
| 715 | -- Drop the extras of the ignore blocks | |
| 716 | turnTo(configuration.itemDropDir) | |
| 717 | for i=1+torchSlot,torchSlot+ignoreBlocks do | |
| 718 | turtle.select(i) | |
| 719 | drop(turnedDir(configuration.itemDropDir), math.max(turtle.getItemCount(i)-1, 0)) | |
| 720 | end | |
| 721 | turnFrom(configuration.itemDropDir) | |
| 722 | ||
| 723 | -- Drop the other items | |
| 724 | turnTo(configuration.itemDropDir) | |
| 725 | for i=torchSlot+ignoreBlocks+1,16 do | |
| 726 | turtle.select(i) | |
| 727 | drop(turnedDir(configuration.itemDropDir), turtle.getItemCount(i)) | |
| 728 | end | |
| 729 | turnFrom(configuration.itemDropDir) | |
| 730 | ||
| 731 | turtle.select(1) | |
| 732 | end | |
| 733 | ||
| 734 | -- COMPLETELY EMPTIES THE INVENTORY | |
| 735 | function dropAll(configuration, ignoreBlocks) | |
| 736 | ignoreBlocks = ignoreBlocks or 0 | |
| 737 | local torchSlot=0 | |
| 738 | ||
| 739 | -- Drop the torches | |
| 740 | if configuration.placeTorches then | |
| 741 | torchSlot=1 | |
| 742 | drop(configuration.torchSuckDir) | |
| 743 | end | |
| 744 | ||
| 745 | -- Drop the extras of the ignore blocks | |
| 746 | turnTo(configuration.itemDropDir) | |
| 747 | for i=1+torchSlot,torchSlot+ignoreBlocks do | |
| 748 | turtle.select(i) | |
| 749 | drop(turnedDir(configuration.itemDropDir), math.max(turtle.getItemCount(i)-1, 0)) | |
| 750 | end | |
| 751 | turnFrom(configuration.itemDropDir) | |
| 752 | ||
| 753 | -- Drop the ignore blocks | |
| 754 | turnTo(configuration.ignoreDir) | |
| 755 | for i=1+torchSlot,torchSlot+ignoreBlocks do | |
| 756 | turtle.select(i) | |
| 757 | drop(turnedDir(configuration.ignoreDir), 1) | |
| 758 | end | |
| 759 | turnFrom(configuration.ignoreDir) | |
| 760 | ||
| 761 | -- Drop the other items | |
| 762 | turnTo(configuration.itemDropDir) | |
| 763 | for i=torchSlot+ignoreBlocks+1,16 do | |
| 764 | turtle.select(i) | |
| 765 | drop(turnedDir(configuration.itemDropDir), turtle.getItemCount(i)) | |
| 766 | end | |
| 767 | turnFrom(configuration.itemDropDir) | |
| 768 | ||
| 769 | turtle.select(1) | |
| 770 | end | |
| 771 | ||
| 772 | -- GETS NEW TORCHES | |
| 773 | function restockTorches(configuration, ignoreBlocks) | |
| 774 | ignoreBlocks = ignoreBlocks or 0 | |
| 775 | turnTo(configuration.torchSuckDir) | |
| 776 | local tDir = turnedDir(configuration.torchSuckDir) | |
| 777 | turtle.select(1) | |
| 778 | suck(tDir) | |
| 779 | turtle.select(2+ignoreBlocks) | |
| 780 | drop(tDir) | |
| 781 | turnFrom(configuration.torchSuckDir) | |
| 782 | end | |
| 783 | ||
| 784 | -- CALCULATES HOW MUCH MOVES NEED TO BE MADE TO GO FROM ONE SHAFT TO ANOTHER | |
| 785 | function calculateMoves(configuration, numL, fromS, toS) | |
| 786 | local lowS = fromS | |
| 787 | local highS = toS | |
| 788 | if highS < lowS then | |
| 789 | lowS = toS | |
| 790 | highS = fromS | |
| 791 | end | |
| 792 | if lowS == highS then | |
| 793 | return 0 | |
| 794 | end | |
| 795 | local requiredMoves = 0 | |
| 796 | if highS == (configuration.numS + 1) then | |
| 797 | if numL % 2 == 1 then | |
| 798 | requiredMoves = requiredMoves+configuration.evenLevelOffset | |
| 799 | end | |
| 800 | highS = highS - 1 | |
| 801 | end | |
| 802 | if lowS == 0 then | |
| 803 | requiredMoves = requiredMoves+configuration.firstShaftOffset | |
| 804 | if numL % 2 == 0 then | |
| 805 | requiredMoves = requiredMoves+configuration.evenLevelOffset | |
| 806 | end | |
| 807 | requiredMoves = requiredMoves+((configuration.blocksBetweenShafts+1)*(highS-1)) | |
| 808 | else | |
| 809 | requiredMoves = requiredMoves+((configuration.blocksBetweenShafts+1)*(highS-lowS)) | |
| 810 | end | |
| 811 | return requiredMoves | |
| 812 | end | |
| 813 | ||
| 814 | -- MOVES FROM THE CURRENT LOCATION TO ANOTHER | |
| 815 | function moveToLocation(configuration, newL, newT, newS) | |
| 816 | if newL == configuration.currentL and newT == configuration.currentT then | |
| 817 | if configuration.currentS < newS then | |
| 818 | digAndMove(forward, calculateMoves(configuration, newL, configuration.currentS, newS)) | |
| 819 | elseif newS < configuration.currentS then | |
| 820 | digAndMove(reverseDir(forward), calculateMoves(configuration, newL, configuration.currentS, newS)) | |
| 821 | end | |
| 822 | else | |
| 823 | local turnDir = configuration.nextDirT | |
| 824 | local moves = newT - configuration.currentT | |
| 825 | if configuration.currentT > newT then | |
| 826 | turnDir = reverseDir(turnDir) | |
| 827 | moves = configuration.currentT - newT | |
| 828 | end | |
| 829 | if configuration.currentS == 0 then | |
| 830 | digAndMove(forward) | |
| 831 | turnTo(turnDir) | |
| 832 | else | |
| 833 | turnTo(back) | |
| 834 | digAndMove(forward, calculateMoves(configuration, configuration.currentL, 0, configuration.currentS)-1) | |
| 835 | turnFrom(turnDir) | |
| 836 | end | |
| 837 | digAndMove(forward, configuration.centerRadius+1) | |
| 838 | if configuration.currentL < newL then | |
| 839 | digAndMove(configuration.nextDirL, (newL-configuration.currentL)*(configuration.height+1)) | |
| 840 | end | |
| 841 | if configuration.currentL > newL then | |
| 842 | digAndMove(reverseDir(configuration.nextDirL), (configuration.currentL-newL)*(configuration.height+1)) | |
| 843 | end | |
| 844 | if newT == configuration.currentT then | |
| 845 | turnTo(back) | |
| 846 | else | |
| 847 | turnTo(turnDir) | |
| 848 | for i=2, moves do | |
| 849 | digAndMove(forward, 2*(configuration.centerRadius+1)) | |
| 850 | turnTo(turnDir) | |
| 851 | end | |
| 852 | end | |
| 853 | if newT == configuration.currentT then | |
| 854 | turnDir = reverseDir(turnDir) | |
| 855 | end | |
| 856 | digAndMove(forward, configuration.centerRadius+1) | |
| 857 | if newS == 0 then | |
| 858 | turnTo(turnDir) | |
| 859 | digAndMove(forward) | |
| 860 | turnTo(back) | |
| 861 | else | |
| 862 | turnFrom(turnDir) | |
| 863 | digAndMove(forward, calculateMoves(configuration, newL, 0, newS)-1) | |
| 864 | end | |
| 865 | end | |
| 866 | configuration.currentL = newL | |
| 867 | configuration.currentT = newT | |
| 868 | configuration.currentS = newS | |
| 869 | end | |
| 870 | ||
| 871 | -- ------------------------------------------------ -- | |
| 872 | -- END OF THE FUNCTIONS SHARED BETWEEN ALL PROGRAMS -- | |
| 873 | -- ------------------------------------------------ -- | |
| 874 | ||
| 875 | -- ------------------------------------------ -- | |
| 876 | -- START OF THE FUNCTIONS SPECIFIC TO digOres -- | |
| 877 | -- ------------------------------------------ -- | |
| 878 | ||
| 879 | -- EXCAVATES A SHAFT, DIGGING OUT ALL THE SPECIAL BLOCKS (ORES ETC) | |
| 880 | function excavateShaft(configuration, dir) | |
| 881 | local squaresMoved=0 | |
| 882 | for i=1,configuration.centerRadius+calculateMoves(configuration, configuration.currentL, 0, configuration.currentS) do | |
| 883 | if needsRestocking(configuration) then | |
| 884 | turnTo(back) | |
| 885 | exitShaftAndRestock(configuration, dir, squaresMoved) | |
| 886 | end | |
| 887 | if digAndMove(forward)==0 then | |
| 888 | print("Encountered obstruction in:")
| |
| 889 | print(" LEV: "..configuration.currentL)
| |
| 890 | print(" TUN: "..configuration.currentT)
| |
| 891 | print(" SH : "..configuration.currentS.." ("..dir..")")
| |
| 892 | break | |
| 893 | end | |
| 894 | squaresMoved = squaresMoved + 1 | |
| 895 | checkSides(configuration, up) | |
| 896 | end | |
| 897 | digAndMove(down) | |
| 898 | turnTo(back) | |
| 899 | checkSides(configuration, down) | |
| 900 | for i=1,squaresMoved do | |
| 901 | if configuration.placeTorches and (squaresMoved%8==7) then | |
| 902 | place(up, 1) | |
| 903 | end | |
| 904 | if needsRestocking(configuration) then | |
| 905 | digAndMove(up) | |
| 906 | exitShaftAndRestock(configuration, dir, squaresMoved) | |
| 907 | turnTo(back) | |
| 908 | digAndMove(down) | |
| 909 | end | |
| 910 | if digAndMove(forward)==0 then | |
| 911 | print("Encountered obstruction in:")
| |
| 912 | print(" LEV: "..configuration.currentL)
| |
| 913 | print(" TUN: "..configuration.currentT)
| |
| 914 | print(" SH : "..configuration.currentS.." ("..dir..")")
| |
| 915 | break | |
| 916 | end | |
| 917 | squaresMoved = squaresMoved - 1 | |
| 918 | checkSides(configuration, down) | |
| 919 | end | |
| 920 | digAndMove(up) | |
| 921 | digAndMove(forward, squaresMoved) | |
| 922 | end | |
| 923 | ||
| 924 | -- CHECKS IF THE BLOCKS AT THE LEFT OR RIGHT ARE SPECIAL (AND THE TOP OR BOTTOM, DEPENDING ON THE INPUT) | |
| 925 | -- IF SO IT WILL DIG OUT THAT BLOCK AND EXCAVATE THE REST OF THE VEIN | |
| 926 | function checkSides(configuration, vDir) | |
| 927 | check(configuration, vDir) | |
| 928 | check(configuration, left) | |
| 929 | check(configuration, right) | |
| 930 | end | |
| 931 | ||
| 932 | -- DROPS THE ITEMS IN THE INVENTORY AND REFUELS THE TURTLE | |
| 933 | function exitShaftAndRestock(configuration, dir, squaresMoved) | |
| 934 | local cur | |
| 935 | digAndMove(forward, squaresMoved) | |
| 936 | turnTo(dir) | |
| 937 | restockTurtle(configuration, configuration.numIgnoreBlocks) | |
| 938 | turnTo(dir) | |
| 939 | digAndMove(forward, squaresMoved) | |
| 940 | end | |
| 941 | ||
| 942 | -- CHECKS IF A BLOCK IN A CERTAIN DIRECTION IS SPECIAL | |
| 943 | -- IF SO IT WILL DIG OUT THAT BLOCK AND EXCAVATE THE REST OF THE VEIN | |
| 944 | function check(configuration, dir) | |
| 945 | turnTo(dir) | |
| 946 | local tDir=turnedDir(dir) | |
| 947 | if detect(tDir) then | |
| 948 | if isSpecial(configuration, tDir) then | |
| 949 | if digAndMove(tDir) == 1 then | |
| 950 | excavate(configuration) | |
| 951 | digAndMove(reverseDir(tDir)) | |
| 952 | end | |
| 953 | end | |
| 954 | end | |
| 955 | turnFrom(dir) | |
| 956 | end | |
| 957 | ||
| 958 | -- CHECKS IF A BLOCK IN A CERTAIN DIRECTION IS SPECIAL (NOT ONE OF THE REFERENCE COMPONENTS (DIRT ETC)) | |
| 959 | function isSpecial(configuration, dir) | |
| 960 | turnTo(dir) | |
| 961 | local tDir=turnedDir(dir) | |
| 962 | local torchSlot=0 | |
| 963 | if configuration.placeTorches then | |
| 964 | torchSlot=1 | |
| 965 | end | |
| 966 | if not detect(tDir) then | |
| 967 | return false | |
| 968 | end | |
| 969 | for i=1, configuration.numIgnoreBlocks do | |
| 970 | if compare(tDir, i+torchSlot) then | |
| 971 | turnFrom(dir) | |
| 972 | return false | |
| 973 | end | |
| 974 | end | |
| 975 | turnFrom(dir) | |
| 976 | return true | |
| 977 | end | |
| 978 | ||
| 979 | -- EXCAVATES AN ORE VEIN | |
| 980 | function excavate(configuration) | |
| 981 | local numSteps = 0 | |
| 982 | local steps = {}
| |
| 983 | repeat | |
| 984 | steps[numSteps] = steps[numSteps] or 0 | |
| 985 | steps[numSteps] = lookForOres(configuration, steps[numSteps]) | |
| 986 | if steps[numSteps] ~= 7 then | |
| 987 | if digAndMove(turnedDir(intToDir(steps[numSteps]))) == 1 then | |
| 988 | numSteps = numSteps + 1 | |
| 989 | end | |
| 990 | else | |
| 991 | steps[numSteps] = 0 | |
| 992 | numSteps = numSteps - 1 | |
| 993 | if numSteps >= 0 then | |
| 994 | digAndMove(reverseDir(turnedDir(intToDir(steps[numSteps])))) | |
| 995 | end | |
| 996 | end | |
| 997 | until numSteps < 0 | |
| 998 | end | |
| 999 | ||
| 1000 | -- LOOKS AROUND THE CURRENT POSITION, LOOKING FOR ORES | |
| 1001 | function lookForOres(configuration, dir) | |
| 1002 | if dir < 1 then | |
| 1003 | dir = dir + 1 | |
| 1004 | if isSpecial(configuration, up) then | |
| 1005 | return 1 | |
| 1006 | end | |
| 1007 | end | |
| 1008 | if dir < 2 then | |
| 1009 | dir = dir + 1 | |
| 1010 | if isSpecial(configuration, down) then | |
| 1011 | return 2 | |
| 1012 | end | |
| 1013 | end | |
| 1014 | if dir > 2 then | |
| 1015 | turnTo(left) | |
| 1016 | end | |
| 1017 | for dir=dir+1, 6 do | |
| 1018 | if isSpecial(configuration, forward) then | |
| 1019 | return dir | |
| 1020 | end | |
| 1021 | turnTo(left) | |
| 1022 | end | |
| 1023 | return 7 | |
| 1024 | end | |
| 1025 | ||
| 1026 | -- CONVERTS AN INTEGER TO A DIRECTION | |
| 1027 | function intToDir(dir) | |
| 1028 | if dir == 1 then | |
| 1029 | return up | |
| 1030 | elseif dir == 2 then | |
| 1031 | return down | |
| 1032 | elseif dir == 3 then | |
| 1033 | return forward | |
| 1034 | elseif dir == 4 then | |
| 1035 | return left | |
| 1036 | elseif dir == 5 then | |
| 1037 | return back | |
| 1038 | elseif dir == 6 then | |
| 1039 | return right | |
| 1040 | end | |
| 1041 | end | |
| 1042 | ||
| 1043 | -- PUTS THE IGNORE BLOCKS IN THE INVENTORY | |
| 1044 | function restockIgnore(configuration, ignoreBlocks) | |
| 1045 | local torchSlot=0 | |
| 1046 | if configuration.placeTorches then | |
| 1047 | torchSlot=1 | |
| 1048 | end | |
| 1049 | turnTo(configuration.ignoreDir) | |
| 1050 | local tDir = turnedDir(configuration.ignoreDir) | |
| 1051 | for i=1+torchSlot,ignoreBlocks+torchSlot do | |
| 1052 | suck(tDir) | |
| 1053 | end | |
| 1054 | turnFrom(configuration.ignoreDir) | |
| 1055 | end | |
| 1056 | ||
| 1057 | ||
| 1058 | -- CHECKS IF THE USER PLACED ENOUGH BLOCKS IN THE INVENTORY | |
| 1059 | function enoughBlocksProvided(configuration) | |
| 1060 | local torchSlot=0 | |
| 1061 | if configuration.placeTorches then | |
| 1062 | torchSlot=1 | |
| 1063 | end | |
| 1064 | for i=1+torchSlot,configuration.numIgnoreBlocks+torchSlot do | |
| 1065 | if turtle.getItemCount(i)==0 then | |
| 1066 | return false | |
| 1067 | end | |
| 1068 | end | |
| 1069 | return true | |
| 1070 | end | |
| 1071 | ||
| 1072 | -- ---------------------------------------- -- | |
| 1073 | -- END OF THE FUNCTIONS SPECIFIC TO digOres -- | |
| 1074 | -- ---------------------------------------- -- | |
| 1075 | ||
| 1076 | -- ------------------------------------------------------------ -- | |
| 1077 | -- START OF THE CODE THAT GETS EXECUTED WHEN THE PROGRAM STARTS -- | |
| 1078 | -- ------------------------------------------------------------ -- | |
| 1079 | ||
| 1080 | restockTurtle(configuration, configuration.numIgnoreBlocks) | |
| 1081 | restockIgnore(configuration, configuration.numIgnoreBlocks) | |
| 1082 | ||
| 1083 | if not enoughBlocksProvided(configuration) then | |
| 1084 | term.clear() | |
| 1085 | print("You said you wanted to turtle")
| |
| 1086 | print("To ignore "..configuration.numIgnoreBlocks.." blocks but didn't")
| |
| 1087 | print("place them all in the inventory")
| |
| 1088 | return | |
| 1089 | end | |
| 1090 | ||
| 1091 | if (configuration.departureFuel < 400) then | |
| 1092 | print("Warning: Low fuel value chosen")
| |
| 1093 | print("Do you wish to proceed? (Y/N)")
| |
| 1094 | local answer=io.read() | |
| 1095 | if not (answer=="Y") then | |
| 1096 | return | |
| 1097 | end | |
| 1098 | end | |
| 1099 | ||
| 1100 | -- For every level | |
| 1101 | for curL = 1 + configuration.skipL, configuration.numL do | |
| 1102 | local firstT = 1 | |
| 1103 | if curL == 1 + configuration.skipL then | |
| 1104 | firstT = firstT + configuration.skipT | |
| 1105 | end | |
| 1106 | ||
| 1107 | -- For every tunnel | |
| 1108 | for curT = firstT, configuration.numT do | |
| 1109 | local firstS = 1 | |
| 1110 | if (curL == 1 + configuration.skipL) and (curT == 1 + configuration.skipT) and (configuration.skipS~=0) then | |
| 1111 | firstS = 1 + configuration.skipS | |
| 1112 | end | |
| 1113 | ||
| 1114 | -- For every shaft | |
| 1115 | for curS = firstS, configuration.numS do | |
| 1116 | moveToLocation(configuration, curL, curT, curS) | |
| 1117 | turnTo(left) | |
| 1118 | excavateShaft(configuration, left) | |
| 1119 | excavateShaft(configuration, right) | |
| 1120 | turnTo(right) | |
| 1121 | if needsRestocking(configuration) then | |
| 1122 | restockTurtle(configuration, configuration.numIgnoreBlocks) | |
| 1123 | end | |
| 1124 | end | |
| 1125 | end | |
| 1126 | end | |
| 1127 | ||
| 1128 | -- Return to start | |
| 1129 | moveToLocation(configuration, 1, 1, 0) | |
| 1130 | dropAll(configuration, configuration.numIgnoreBlocks) | |
| 1131 | ||
| 1132 | -- ---------------------------------------------------------- -- | |
| 1133 | -- END OF THE CODE THAT GETS EXECUTED WHEN THE PROGRAM STARTS -- | |
| 1134 | -- ---------------------------------------------------------- -- |