SHOW:
|
|
- or go back to the newest paste.
| 1 | - | --Create a Jetsons-style circular tower by mining straight down in columns all the way to bedrock. |
| 1 | + | --Create a circular platform |
| 2 | - | --leave a spiral staircase on the way back up. |
| 2 | + | |
| 3 | - | --put excess lava in a column |
| 3 | + | --declare global variables that are relevant to platform |
| 4 | - | --Time to try to get rid of collisions. Moving the chests upward making the turtles stay below them on their own levels. |
| 4 | + | R_hole = 50 --outer radius of the platform |
| 5 | numStripes = 16 --number of stripes as it goes out. | |
| 6 | swirlFactor = 1 --control degree of swirl | |
| 7 | ||
| 8 | - | print("Starting radius >")
|
| 8 | + | |
| 9 | - | theta = tonumber(read()) |
| 9 | + | |
| 10 | theta = 0 --sweep of the spiral | |
| 11 | step = 0.001 --change in theta each step | |
| 12 | b = 0.14 --growth factor for spiral | |
| 13 | theta = theta / b | |
| 14 | - | print("Enter the turtle ID (0-3)")
|
| 14 | + | |
| 15 | - | turtID = tonumber(read()) |
| 15 | + | |
| 16 | R_base = 6 --The radius at the base. Also the radius of the stairs all the way up. | |
| 17 | - | R_hole = 15 --the radius of the hole |
| 17 | + | |
| 18 | Floor_Spacing = 6 --put a floor in every this many blocks | |
| 19 | lavaSum = 200 --sum of the YY locations for finding lava | |
| 20 | lavaCount = 0 --number of lava blocks collected | |
| 21 | cobbleCountMax = 1600 --give up if you check this many columns and they're all already done | |
| 22 | firstEmptyChest = 1 | |
| 23 | Chest_Level = 5 --elevation of the chests | |
| 24 | top_column_height = 12 --don't start pinching in the radius until this far | |
| 25 | killMode = 0 --set to 1 to hunt and capture other turtles. | |
| 26 | fuelStop = 0 --stop when the tank is full | |
| 27 | ||
| 28 | if term.isColor() then | |
| 29 | maxFuel = 99000 --this is an advanced turtle | |
| 30 | else | |
| 31 | maxFuel = 19000 --this is a normal turtle | |
| 32 | end | |
| 33 | StartX = 0 | |
| 34 | StartY = 20 | |
| 35 | StartZ = 14 | |
| 36 | ||
| 37 | curX = 0 --current X position relative to the start | |
| 38 | curY = 0 --current Y position relative to the start | |
| 39 | curZ = 0 --current Z position relative to the start | |
| 40 | facing = 0 --what direction is the turtle facing (0,1,2,3) | |
| 41 | --0 is toward positive Z | |
| 42 | waterLevel = -1000 --the highest location that water has been found | |
| 43 | ||
| 44 | ||
| 45 | function fuel(direction) | |
| 46 | --called periodically, and also when lava is detected. | |
| 47 | turtle.select(1) | |
| 48 | --Now let's pickup the lava | |
| 49 | if string.find(direction, "f") then | |
| 50 | --its in front | |
| 51 | turtle.place() | |
| 52 | elseif string.find(direction, "d") then | |
| 53 | turtle.placeDown() | |
| 54 | lavaSum = lavaSum + curY | |
| 55 | lavaCount = lavaCount + 1 | |
| 56 | elseif string.find(direction, "u") then | |
| 57 | turtle.placeUp() | |
| 58 | lavaSum = lavaSum + curY | |
| 59 | lavaCount = lavaCount + 1 | |
| 60 | end | |
| 61 | if turtle.getFuelLevel() < maxFuel then | |
| 62 | for slot = 4,16,1 do | |
| 63 | turtle.select(slot) | |
| 64 | turtle.refuel() | |
| 65 | if turtle.compareTo(1) then | |
| 66 | turtle.transferTo(1) | |
| 67 | end | |
| 68 | if turtle.getFuelLevel() > maxFuel then | |
| 69 | break | |
| 70 | end | |
| 71 | end | |
| 72 | if curY >=0 and turtle.getFuelLevel() < 1000 then | |
| 73 | local oldY = curY | |
| 74 | for i=1,4,1 do | |
| 75 | if not turtle.detectUp() then Up() end | |
| 76 | end | |
| 77 | repeat | |
| 78 | --Time to refuel | |
| 79 | for slot = 4,16,1 do | |
| 80 | turtle.select(slot) | |
| 81 | turtle.refuel() | |
| 82 | if turtle.compareTo(1) then | |
| 83 | turtle.transferTo(1) | |
| 84 | end | |
| 85 | end | |
| 86 | until (turtle.getFuelLevel() > 1000) --don't stop trying if the level is too low | |
| 87 | end | |
| 88 | else | |
| 89 | --fuel has been called, but the tank is full | |
| 90 | if turtle.getItemCount(1) == 1 or turtle.getItemCount(16) > 0 then | |
| 91 | --We're either out of buckets or out of space | |
| 92 | dumpLava() | |
| 93 | end | |
| 94 | end | |
| 95 | turtle.select(1) | |
| 96 | report("refueled")
| |
| 97 | end | |
| 98 | ||
| 99 | function dumpLava() | |
| 100 | --return to the repository to get rid of excess lava | |
| 101 | local XX = curX | |
| 102 | local YY = curY | |
| 103 | local ZZ = curZ | |
| 104 | oldfacing = facing | |
| 105 | ||
| 106 | MoveTo(curX,1+turtID,curZ) | |
| 107 | MoveTo(0,1+turtID,0) | |
| 108 | lavaFuel() | |
| 109 | MoveTo(0,1+turtID,0) | |
| 110 | MoveTo(XX,1+turtID,ZZ) | |
| 111 | MoveTo(XX,-2,ZZ) | |
| 112 | setCobble("u")
| |
| 113 | MoveTo(XX,YY,ZZ) | |
| 114 | TurnTo(oldfacing) | |
| 115 | end | |
| 116 | ||
| 117 | ||
| 118 | function lavaFuel() | |
| 119 | --refuel from onboard lava buckets. | |
| 120 | --if fuel is full, then dump excess in lava repository below (0,0,0) | |
| 121 | if turtle.getFuelLevel() < maxFuel then | |
| 122 | for slot = 4,16,1 do | |
| 123 | turtle.select(slot) | |
| 124 | turtle.refuel() | |
| 125 | if turtle.compareTo(1) then | |
| 126 | turtle.transferTo(1) | |
| 127 | end | |
| 128 | if turtle.getFuelLevel() > maxFuel then | |
| 129 | break | |
| 130 | end | |
| 131 | end | |
| 132 | end | |
| 133 | lava = 0 | |
| 134 | for slot = 4,16,1 do | |
| 135 | local data = turtle.getItemDetail(slot) | |
| 136 | if data and string.find(data.name,"lava") then | |
| 137 | lava = lava + 1 | |
| 138 | end | |
| 139 | end | |
| 140 | while lava > 0 or turtle.getFuelLevel() < 2000 do | |
| 141 | --either we have excess fuel or level is too low. | |
| 142 | --time to go to the repository | |
| 143 | print("Going to repository I have ", lava , "buckets.")
| |
| 144 | MoveTo(curX,turtID+1,curZ) | |
| 145 | MoveTo(0,turtID+1,0) | |
| 146 | MoveTo(0,0,0) | |
| 147 | local success, data = turtle.inspectDown() | |
| 148 | local success_f, data_f = turtle.inspect() | |
| 149 | if success and string.find(data.name,"trap") then | |
| 150 | os.exit() | |
| 151 | end | |
| 152 | while not success or | |
| 153 | not ( (success and string.find(data.name,"bedrock") ) | |
| 154 | or | |
| 155 | (success and string.find(data.name, "lava") and data.state.level == 0 ) | |
| 156 | or | |
| 157 | (success_f and string.find(data_f.name, "lava") and data.state.level == 0 ) | |
| 158 | or | |
| 159 | (success and string.find(data.name, "trapdoor") ) | |
| 160 | ) do | |
| 161 | Down() | |
| 162 | if (success and string.find(data.name, "trapdoor") ) then | |
| 163 | while (success and string.find(data.name, "trapdoor")) do | |
| 164 | sleep(120) | |
| 165 | success, data = turtle.inspectDown() | |
| 166 | end | |
| 167 | end | |
| 168 | success, data = turtle.inspectDown() | |
| 169 | end | |
| 170 | --We're now either over lava or over bedrock | |
| 171 | print("At lava level")
| |
| 172 | if turtle.getFuelLevel() < 2000 then | |
| 173 | --we're here to pick up lava | |
| 174 | done = 0 | |
| 175 | while done==0 do | |
| 176 | for i=0,3,1 do | |
| 177 | fuel("f")
| |
| 178 | TRight() | |
| 179 | end | |
| 180 | fuel("d")
| |
| 181 | Down() | |
| 182 | if turtle.getFuelLevel() > 15000 or turtle.detectDown() then | |
| 183 | done = 1 | |
| 184 | end | |
| 185 | end | |
| 186 | else | |
| 187 | --we're here to deposit | |
| 188 | print("Depositing")
| |
| 189 | local done = 0 | |
| 190 | local dir = 0 | |
| 191 | while done == 0 do | |
| 192 | done = 1 | |
| 193 | for s = 4,16,1 do | |
| 194 | data = turtle.getItemDetail(s) | |
| 195 | if data and string.find(data.name,"lava") then | |
| 196 | turtle.select(s) | |
| 197 | if dir < 4 then | |
| 198 | TurnTo(dir) | |
| 199 | if turtle.place() then | |
| 200 | turtle.transferTo(1) | |
| 201 | end | |
| 202 | else | |
| 203 | --we've already gone in all directions. | |
| 204 | Up() | |
| 205 | if turtle.placeDown() then | |
| 206 | turtle.transferTo(1) | |
| 207 | end | |
| 208 | dir = -1 | |
| 209 | end | |
| 210 | done = 0 | |
| 211 | dir = dir + 1 | |
| 212 | end | |
| 213 | end | |
| 214 | end | |
| 215 | end | |
| 216 | if curY > -4 then | |
| 217 | --we've filled the repository | |
| 218 | MoveTo(0,1+turtID,1) | |
| 219 | os.exit() | |
| 220 | end | |
| 221 | MoveTo(0,1+turtID,0) | |
| 222 | if turtle.getFuelLevel() < 2000 then | |
| 223 | MoveTo(0,turtID+1,1) --park position | |
| 224 | sleep(120) | |
| 225 | fuel("n")
| |
| 226 | end | |
| 227 | MoveTo(0,1+turtID,0) | |
| 228 | lava = 0 | |
| 229 | for slot = 4,16,1 do | |
| 230 | local data = turtle.getItemDetail(slot) | |
| 231 | if data and string.find(data.name,"lava") then | |
| 232 | lava = lava + 1 | |
| 233 | end | |
| 234 | end | |
| 235 | end | |
| 236 | end | |
| 237 | ||
| 238 | function Init() | |
| 239 | --called when I want the turtle to set up the chests for me | |
| 240 | turtle.select(4) -- slot to put a stack of chests | |
| 241 | local row = 0 | |
| 242 | while turtle.getItemCount(4) > 0 or turtle.getItemCount(5) > 0 do | |
| 243 | MoveTo(row,5,1) | |
| 244 | TurnTo(0) | |
| 245 | for x=1,10,1 do | |
| 246 | turtle.placeUp() | |
| 247 | if turtle.getItemCount(4) == 0 then | |
| 248 | turtle.select(5) | |
| 249 | end | |
| 250 | Forward() | |
| 251 | end | |
| 252 | row = row+1 | |
| 253 | end | |
| 254 | MoveTo(0,0,0) | |
| 255 | end | |
| 256 | ||
| 257 | ||
| 258 | function SlotItems(slot) | |
| 259 | turtle.select(slot) | |
| 260 | if turtle.getItemCount() == 0 then | |
| 261 | return "nothing" | |
| 262 | else | |
| 263 | local data = turtle.getItemDetail() | |
| 264 | return data.name | |
| 265 | end | |
| 266 | end | |
| 267 | ||
| 268 | function TRight() | |
| 269 | --Turn the turtle to the right | |
| 270 | turtle.turnRight() | |
| 271 | facing = facing +1 | |
| 272 | if facing > 3 then | |
| 273 | facing = facing - 4 | |
| 274 | end | |
| 275 | end | |
| 276 | ||
| 277 | function TLeft() | |
| 278 | --Turn the turtle to the right | |
| 279 | turtle.turnLeft() | |
| 280 | facing = facing - 1 | |
| 281 | if facing < 0 then | |
| 282 | facing = facing + 4 | |
| 283 | end | |
| 284 | end | |
| 285 | ||
| 286 | function Forward() | |
| 287 | local success, data = turtle.inspect() | |
| 288 | if success then | |
| 289 | local count = 0 | |
| 290 | if string.find(data.name, "urtle") and killMode == 0 then | |
| 291 | local p=0 | |
| 292 | while success do | |
| 293 | if not p then | |
| 294 | print("Turtle detected: Can't move forward!")
| |
| 295 | p=1 | |
| 296 | end | |
| 297 | sleep(math.random(100)/10) | |
| 298 | count = count + 1 | |
| 299 | if count > 4 and count % 10 == 7 then | |
| 300 | if not turtle.detectUp() then | |
| 301 | Up() | |
| 302 | sleep(20) | |
| 303 | Down() | |
| 304 | elseif not turtle.detectDown() then | |
| 305 | Down() | |
| 306 | sleep(20) | |
| 307 | Up() | |
| 308 | end | |
| 309 | end | |
| 310 | success, data = turtle.inspect() | |
| 311 | if count > 2000 then | |
| 312 | --we've waited long enough the turtle must be stuck capture it and return home | |
| 313 | for s = 2,16,1 do | |
| 314 | turtle.select(s) | |
| 315 | turtle.drop() | |
| 316 | end | |
| 317 | turtle.dig() | |
| 318 | end | |
| 319 | end | |
| 320 | end | |
| 321 | if success and string.find(data.name, "lava") then | |
| 322 | fuel("f")
| |
| 323 | end | |
| 324 | end | |
| 325 | while not turtle.forward() do | |
| 326 | turtle.dig() | |
| 327 | end | |
| 328 | if facing == 0 then | |
| 329 | curZ = curZ + 1 | |
| 330 | elseif facing == 1 then | |
| 331 | curX = curX +1 | |
| 332 | elseif facing == 2 then | |
| 333 | curZ = curZ - 1 | |
| 334 | else | |
| 335 | curX = curX - 1 | |
| 336 | end | |
| 337 | end | |
| 338 | ||
| 339 | function Up() | |
| 340 | local success, data = turtle.inspectUp() | |
| 341 | if success then | |
| 342 | local count = 0 | |
| 343 | if string.find(data.name, "urtle") and killMode == 0 then | |
| 344 | local p = 0 | |
| 345 | while success do | |
| 346 | if not p then | |
| 347 | print("Turtle detected: Can't move up!")
| |
| 348 | p=1 | |
| 349 | end | |
| 350 | sleep(math.random(10)) | |
| 351 | success, data = turtle.inspectUp() | |
| 352 | count = count +1 | |
| 353 | if count > 3 and count % 10 == 4 then | |
| 354 | local olddir = facing | |
| 355 | while turtle.detect() do | |
| 356 | TRight() | |
| 357 | end | |
| 358 | Forward() | |
| 359 | sleep(20) | |
| 360 | TRight() | |
| 361 | TRight() | |
| 362 | Forward() | |
| 363 | TurnTo(olddir) | |
| 364 | end | |
| 365 | end | |
| 366 | end | |
| 367 | if success and string.find(data.name, "lava") and data.state.level ==0 then | |
| 368 | fuel("u")
| |
| 369 | end | |
| 370 | end | |
| 371 | while not turtle.up() do | |
| 372 | turtle.digUp() | |
| 373 | end | |
| 374 | curY = curY + 1 | |
| 375 | end | |
| 376 | ||
| 377 | function Down() | |
| 378 | local success, data = turtle.inspectDown() | |
| 379 | if success then | |
| 380 | --print(data.name) | |
| 381 | local count = 0 | |
| 382 | if (string.find(data.name,"brick") or | |
| 383 | string.find(data.name,"end") ) then | |
| 384 | return 0 | |
| 385 | end | |
| 386 | if string.find(data.name, "urtle") and killMode == 0 then | |
| 387 | local p = 0 | |
| 388 | while success do | |
| 389 | if not p then | |
| 390 | print("Turtle detected: Can't move down")
| |
| 391 | p=1 | |
| 392 | end | |
| 393 | sleep(math.random(10)) | |
| 394 | success, data = turtle.inspectDown() | |
| 395 | count = count +1 | |
| 396 | if count > 3 and count % 10 == 4 then | |
| 397 | local olddir = facing | |
| 398 | while turtle.detect() do | |
| 399 | TRight() | |
| 400 | end | |
| 401 | Forward() | |
| 402 | sleep(20) | |
| 403 | TRight() | |
| 404 | TRight() | |
| 405 | Forward() | |
| 406 | TurnTo(olddir) | |
| 407 | end | |
| 408 | if count > 2000 then | |
| 409 | turtle.digDown() --the turtle is not getting out of the way. Eat it. | |
| 410 | end | |
| 411 | end | |
| 412 | end | |
| 413 | end | |
| 414 | if success and string.find(data.name, "lava") and data.state.level == 0 then | |
| 415 | fuel("d")
| |
| 416 | end | |
| 417 | if success and (string.find(data.name, "bedrock") or | |
| 418 | string.find(data.name, "spawner") or | |
| 419 | string.find(data.name, "torch") ) then | |
| 420 | --we've hit bedrock. We can't go further. | |
| 421 | --print("hit something we can dig. Returning 0")
| |
| 422 | return 0 | |
| 423 | end | |
| 424 | while not turtle.down() do | |
| 425 | turtle.digDown() | |
| 426 | end | |
| 427 | curY = curY - 1 | |
| 428 | return 1 | |
| 429 | end | |
| 430 | ||
| 431 | function TurnTo(face) | |
| 432 | if (face - facing) % 4 == 3 then | |
| 433 | while (facing ~= face) do | |
| 434 | TLeft() | |
| 435 | end | |
| 436 | else | |
| 437 | while (facing ~= face) do | |
| 438 | TRight() | |
| 439 | end | |
| 440 | end | |
| 441 | end | |
| 442 | ||
| 443 | function MoveTo (MoveToX, MoveToY, MoveToZ) | |
| 444 | --Move the turtle to the desired position | |
| 445 | --first X | |
| 446 | --print(MoveToX, " " , MoveToY, " " ,MoveToZ) | |
| 447 | if MoveToX < curX then | |
| 448 | TurnTo(3) | |
| 449 | while MoveToX < curX do | |
| 450 | Forward() | |
| 451 | end | |
| 452 | elseif MoveToX > curX then | |
| 453 | TurnTo(1) | |
| 454 | while MoveToX > curX do | |
| 455 | Forward() | |
| 456 | end | |
| 457 | end | |
| 458 | --Now Z | |
| 459 | if MoveToZ < curZ then | |
| 460 | TurnTo(2) | |
| 461 | while MoveToZ < curZ do | |
| 462 | Forward() | |
| 463 | end | |
| 464 | elseif MoveToZ > curZ then | |
| 465 | TurnTo(0) | |
| 466 | while MoveToZ > curZ do | |
| 467 | Forward() | |
| 468 | end | |
| 469 | end | |
| 470 | --Now Y | |
| 471 | if MoveToY < curY then | |
| 472 | while MoveToY < curY do | |
| 473 | Down() | |
| 474 | end | |
| 475 | end | |
| 476 | while MoveToY > curY do | |
| 477 | Up() | |
| 478 | end | |
| 479 | end --MoveTo | |
| 480 | ||
| 481 | function cobbleBelow() | |
| 482 | local success, data = turtle.inspectDown() | |
| 483 | if success then | |
| 484 | if string.find(data.name, "cobble") or string.find(data.name, "urtle") then | |
| 485 | return 1 | |
| 486 | end | |
| 487 | end | |
| 488 | return nil | |
| 489 | end | |
| 490 | ||
| 491 | function setCobble(direction) | |
| 492 | for i=1,2,1 do | |
| 493 | for slot = 2,3,1 do | |
| 494 | turtle.select(slot) | |
| 495 | if turtle.getItemCount() > 1 then | |
| 496 | if string.find(direction, "d") then | |
| 497 | turtle.placeDown() | |
| 498 | elseif string.find(direction, "u") then | |
| 499 | turtle.placeUp() | |
| 500 | else | |
| 501 | --forward | |
| 502 | turtle.place() | |
| 503 | end | |
| 504 | if turtle.getItemCount() < 10 then | |
| 505 | for s=5,16,1 do | |
| 506 | turtle.select(s) | |
| 507 | if turtle.compareTo(slot) then | |
| 508 | turtle.transferTo(slot) | |
| 509 | return(1) | |
| 510 | end | |
| 511 | end | |
| 512 | end | |
| 513 | return(1) | |
| 514 | end | |
| 515 | end | |
| 516 | replenishCobble() | |
| 517 | end | |
| 518 | moveTo(0,1+turtID,1) | |
| 519 | print("ran out of cobblestone")
| |
| 520 | os.exit() | |
| 521 | end | |
| 522 | ||
| 523 | function replenishCobble() | |
| 524 | --return to the chests and load up on cobble. | |
| 525 | local XX = curX | |
| 526 | local YY = curY | |
| 527 | local ZZ = curZ | |
| 528 | oldfacing = facing | |
| 529 | ||
| 530 | MoveTo(curX,1+turtID,curZ) | |
| 531 | MoveTo(turtID,1+turtID,1) | |
| 532 | MoveTo(turtID,5,1) | |
| 533 | fuel("n")
| |
| 534 | local chestNum = 11 | |
| 535 | local needMore = 1 | |
| 536 | while chestNum > 0 do | |
| 537 | chestNum = chestNum - 1 | |
| 538 | MoveTo(2*math.floor(chestNum/10) +turtID ,curY, chestNum % 10 + 1) | |
| 539 | needMore = 0 | |
| 540 | for slot = 2,4,1 do | |
| 541 | turtle.select(slot) | |
| 542 | turtle.suckUp() | |
| 543 | if turtle.getItemCount() < 64 then | |
| 544 | needMore = 1 | |
| 545 | end | |
| 546 | end | |
| 547 | end | |
| 548 | if turtle.getItemCount(3) < 64 then | |
| 549 | print("I need more cobble.")
| |
| 550 | MoveTo(curX,turtID+1,curZ) | |
| 551 | turtle.select(3) | |
| 552 | while turtle.getItemCount() < 64 do | |
| 553 | sleep(10) | |
| 554 | end | |
| 555 | fuel("n")
| |
| 556 | end | |
| 557 | MoveTo(XX,1+turtID,ZZ) | |
| 558 | MoveTo(XX,-2,ZZ) | |
| 559 | setCobble("u")
| |
| 560 | MoveTo(XX,YY,ZZ) | |
| 561 | TurnTo(oldfacing) | |
| 562 | end | |
| 563 | ||
| 564 | function facingOut() | |
| 565 | --determine if the turtle is facing toward the center or outward | |
| 566 | --return true if outward | |
| 567 | print( curX, ",", curY, "," ,curZ) | |
| 568 | if curX > 0 then | |
| 569 | if curZ > 0 then | |
| 570 | if facing == 0 or facing == 1 then | |
| 571 | ||
| 572 | return true | |
| 573 | else | |
| 574 | return false | |
| 575 | end | |
| 576 | elseif curZ < 0 then | |
| 577 | if facing == 1 or facing == 2 then | |
| 578 | return true | |
| 579 | else | |
| 580 | return false | |
| 581 | end | |
| 582 | else | |
| 583 | --Z is 0 | |
| 584 | if facing == 0 or facing == 1 or facing == 2 then | |
| 585 | return true | |
| 586 | else | |
| 587 | return false | |
| 588 | end | |
| 589 | end | |
| 590 | elseif curX < 0 then | |
| 591 | if curZ > 0 then | |
| 592 | if facing == 0 or facing ==3 then | |
| 593 | return true | |
| 594 | else | |
| 595 | return false | |
| 596 | end | |
| 597 | elseif curZ < 0 then | |
| 598 | if facing == 2 or facing == 3 then | |
| 599 | return true | |
| 600 | else | |
| 601 | return false | |
| 602 | end | |
| 603 | else | |
| 604 | --Z is 0 | |
| 605 | if facing == 0 or facing == 3 or facing == 2 then | |
| 606 | return true | |
| 607 | else | |
| 608 | return false | |
| 609 | end | |
| 610 | end | |
| 611 | else | |
| 612 | --x is zero | |
| 613 | if curZ > 0 then | |
| 614 | if facing == 0 or facing == 3 or facing == 1 then | |
| 615 | return true | |
| 616 | else | |
| 617 | return false | |
| 618 | end | |
| 619 | elseif curZ < 0 then | |
| 620 | if facing == 2 or facing == 3 or facing == 1 then | |
| 621 | return true | |
| 622 | else | |
| 623 | return false | |
| 624 | end | |
| 625 | else | |
| 626 | --we are at 0,0 | |
| 627 | return true | |
| 628 | end | |
| 629 | end | |
| 630 | end | |
| 631 | ||
| 632 | function Outward() | |
| 633 | --determine the directions that are outward | |
| 634 | local directions = {}
| |
| 635 | ||
| 636 | if math.abs(curX) >= math.abs(curZ)-1 then | |
| 637 | if curX >= 0 then | |
| 638 | table.insert(directions, 1) | |
| 639 | end | |
| 640 | if curX <= 0 then | |
| 641 | table.insert(directions, 3) | |
| 642 | end | |
| 643 | end | |
| 644 | if math.abs(curZ) >= math.abs(curX)-1 then | |
| 645 | if curZ >= 0 then | |
| 646 | table.insert(directions, 0) | |
| 647 | end | |
| 648 | if curZ <= 0 then | |
| 649 | table.insert(directions, 2) | |
| 650 | end | |
| 651 | end | |
| 652 | if curZ == 0 and theta*b < 5 then | |
| 653 | table.insert(directions, 0) | |
| 654 | table.insert(directions, 2) | |
| 655 | end | |
| 656 | if curX == 0 and theta*b < 5 then | |
| 657 | table.insert(directions, 1) | |
| 658 | table.insert(directions, 3) | |
| 659 | end | |
| 660 | return directions | |
| 661 | end | |
| 662 | ||
| 663 | ||
| 664 | ||
| 665 | function Dry(direction) | |
| 666 | if string.find(direction, "d") then | |
| 667 | --there is water below | |
| 668 | setCobble("d")
| |
| 669 | else | |
| 670 | --there is water in front | |
| 671 | Forward() | |
| 672 | TLeft() | |
| 673 | for i=1,3,1 do | |
| 674 | local success, data = turtle.inspect() | |
| 675 | if success then | |
| 676 | --print(curX,",",curZ,",",facing,",",facingOut()) | |
| 677 | if string.find(data.name, "water") and facingOut() then | |
| 678 | setCobble("f")
| |
| 679 | elseif string.find(data.name, "seagrass") or | |
| 680 | string.find(data.name, "kelp") and facingOut() then | |
| 681 | turtle.dig() | |
| 682 | setCobble("f")
| |
| 683 | end | |
| 684 | end | |
| 685 | TRight() | |
| 686 | end | |
| 687 | Forward() | |
| 688 | TRight() | |
| 689 | TRight() | |
| 690 | setCobble("f")
| |
| 691 | turtle.dig() | |
| 692 | end | |
| 693 | end | |
| 694 | ||
| 695 | function report(out) | |
| 696 | --term.clear() | |
| 697 | print("theta=", theta, "fuel=", turtle.getFuelLevel())
| |
| 698 | print(out) | |
| 699 | end | |
| 700 | ||
| 701 | function returnUp() | |
| 702 | local radius = math.sqrt(curX*curX + curZ*curZ) | |
| 703 | while curY < -1 do | |
| 704 | turtle.select(2) | |
| 705 | Up() | |
| 706 | if radius < R_base then | |
| 707 | --we're in the area to make the stairs and the lava column | |
| 708 | if (curY + math.floor(2*math.atan2(curX,curZ))) % 12 == 0 and theta > 9.2 or | |
| 709 | (math.abs(curX) == 1 and math.abs(curZ)==1) or | |
| 710 | (curX==0 and math.abs(curZ)==2) or | |
| 711 | (curZ==0 and math.abs(curX)==2) then | |
| 712 | setCobble("d")
| |
| 713 | end | |
| 714 | elseif radius <= R_max and radius < R_base + (R_max - R_base)*2^((curY + top_column_height) / R_decay) then | |
| 715 | --we're in the region to put regular floors | |
| 716 | if curY % Floor_Spacing ==0 or radius > R_max - 1 then | |
| 717 | setCobble("d")
| |
| 718 | end | |
| 719 | end | |
| 720 | end | |
| 721 | --place the cobbles at the top (YY=-1) | |
| 722 | Up() | |
| 723 | setCobble("d") --place a cobblestone in this location to mark it as done
| |
| 724 | end | |
| 725 | ||
| 726 | --Start the program | |
| 727 | ||
| 728 | ||
| 729 | ||
| 730 | - | --Move to the starting location and then reset the coordinates |
| 730 | + | |
| 731 | - | MoveTo(StartX,StartY,StartZ) |
| 731 | + | |
| 732 | - | curX = 0 |
| 732 | + | |
| 733 | - | curY = 0 |
| 733 | + | |
| 734 | - | curZ = 0 |
| 734 | + | |
| 735 | ZZ = 0 | |
| 736 | while math.abs(theta) < R_hole/b do | |
| 737 | --find the next (XX,ZZ) | |
| 738 | --first change theuntil we get to a new column | |
| 739 | --print("new column")
| |
| 740 | print("theta=", theta, " , fuel=" , turtle.getFuelLevel())
| |
| 741 | if theta ~= 0 then | |
| 742 | while ((XX == oldXX) and (ZZ == oldZZ)) do | |
| 743 | - | if theta < 0 then |
| 743 | + | |
| 744 | - | Init() |
| 744 | + | |
| 745 | - | theta = 0 |
| 745 | + | |
| 746 | end | |
| 747 | - | fuel("n")
|
| 747 | + | |
| 748 | theta = theta + step | |
| 749 | end | |
| 750 | --now the column has changed, but is it really one we've never done before? | |
| 751 | MoveTo(XX,curY,ZZ) | |
| 752 | MoveTo(XX,0,ZZ) | |
| 753 | oldXX = XX | |
| 754 | - | while ((XX == oldXX) and (ZZ == oldZZ)) or math.abs(turtID - ( (XX %2) + 2*(ZZ%2)) ) > 0.5 do |
| 754 | + | |
| 755 | turtle.digUp() | |
| 756 | --determine which color to place upward | |
| 757 | if math.floor(theta / (6.28318531/ numStripes) + (theta/swirlFactor)) % 2 == 0 then | |
| 758 | turtle.select(1) | |
| 759 | turtle.placeUp() | |
| 760 | if turtle.getItemCount() == 1 then | |
| 761 | for i=8,2,-1 do | |
| 762 | turtle.select(i) | |
| 763 | turtle.transferTo(1) | |
| 764 | end | |
| 765 | - | --print("Checking for cobble")
|
| 765 | + | |
| 766 | - | cobbleCount = 0 |
| 766 | + | |
| 767 | - | while cobbleBelow() or math.abs(turtID - ( (curX %2) + 2*(curZ%2)) ) > 0.5 do |
| 767 | + | while turtle.getItemCount() == 1 do |
| 768 | - | --print(turtID, "," ,turtID - ((curX %2) + 2*(curZ%2)) ) |
| 768 | + | print("Please reload")
|
| 769 | - | --print(XX, "," ZZ, "," , (ZZ-XX*2) % 5) |
| 769 | + | sleep(1) |
| 770 | - | oldXX = XX |
| 770 | + | |
| 771 | - | oldZZ = ZZ |
| 771 | + | |
| 772 | - | junk = math.random(100) |
| 772 | + | turtle.select(9) |
| 773 | - | while (XX == oldXX) and (ZZ == oldZZ) do |
| 773 | + | turtle.placeUp() |
| 774 | if turtle.getItemCount() == 1 then | |
| 775 | - | XX = math.floor((b*theta) * math.cos(theta)+0.5) |
| 775 | + | for i=16,10,-1 do |
| 776 | - | ZZ = math.floor((b*theta) * math.sin(theta)+0.5) |
| 776 | + | turtle.select(i) |
| 777 | turtle.transferTo(9) | |
| 778 | - | MoveTo(curX,1+turtID,curZ) |
| 778 | + | |
| 779 | - | MoveTo(XX,curY,ZZ) |
| 779 | + | |
| 780 | - | cobbleCount = cobbleCount + 1 |
| 780 | + | turtle.select(9) |
| 781 | - | if cobbleCount > cobbleCountMax then |
| 781 | + | while turtle.getItemCount() == 1 do |
| 782 | - | --Looks like we've run into an area already processed by another turtle. |
| 782 | + | print("Please reload")
|
| 783 | - | report("Couldn't find a new column. Finishing!")
|
| 783 | + | sleep(1) |
| 784 | - | MoveTo(0,turtID+1,1) |
| 784 | + | |
| 785 | - | os.exit() |
| 785 | + | |
| 786 | end | |
| 787 | - | if math.abs(turtID - ( (curX %2) + 2*(curZ%2)) ) < 0.5 then |
| 787 | + | MoveTo(0,0,0) |