Guest User

TAMS WPI by Big SHiny Toys

a guest
Sep 21st, 2012
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.68 KB | None | 0 0
  1. --[[
  2.         TAMS Turtle Advanced Movment Script
  3.         writen in Lua by Big Shiny Toys
  4.         I realease this Open source and public domain
  5. notes:
  6. this is a turtle mining and legistics system
  7. designed to allow simpe controll of mutiple turtles
  8.  
  9. -- stuff to add / repair / ect..
  10. 1 ) send function to net ALPHA
  11. 1.1 ) add phone book of addresseses update
  12.     when reciving new messsage from user.
  13. 2 ) goto GPS in movment system
  14. 3 ) check multi tasking
  15. 4 ) Controller side system / authentication
  16. 5 ) turtle task controll for ^
  17. 6 ) request for refuel
  18. 7 ) call for help
  19. 8 ) allow access to files remotle
  20. 9 ) automatic update distrobution
  21. 10 ) checking system in turtle tracking system
  22. 11 ) mining script with send on complet -- ask for fuel and ask for item reteval
  23. 12 ) parth finding using pipes and roads
  24. 13 ) turtle taks build road send on completion
  25. 14 ) turtle task mine 1,1 12,12 will take from Z 70 down to bead rock
  26. 15 ) save position
  27. ]]--
  28. -- test         --
  29. term.clear()
  30. term.setCursorPos(1,1)
  31. if not turtle then
  32.     print("Not a turtle")
  33.     return
  34. end
  35. -- Indexes      --
  36.  
  37. local tFacesRAW = {"+Y","+X","-Y","-X"}
  38. local tFaces = {"north","south","west","east"}
  39.  
  40. -- varibles     --
  41.  
  42. local bRunning = true
  43. local machineID = os.getComputerID()
  44. local modemOn
  45. local turX,turY,turZ,turF = nil,nil,nil,1
  46. local task = {} -- so task function can be called from all programs
  47.  
  48. local home = nil
  49.  
  50. local tThreads = {}
  51.  
  52. -- Functions    --
  53. local netWork = {}
  54. netWork.open = function()
  55.     local listOfSides = rs.getSides()
  56.     for i = 1,6 do
  57.         if peripheral.isPresent(listOfSides[i]) and peripheral.getType(listOfSides[i]) == "modem" then
  58.             rednet.open(listOfSides[i])
  59.             return listOfSides[i]
  60.         end
  61.     end
  62.     return false
  63. end
  64.  
  65. local move = {}
  66. move.up = function()
  67.     if turtle.up() then
  68.         turZ = turZ + 1
  69.         return true
  70.     else
  71.         return false
  72.     end
  73. end
  74. move.down = function()
  75.     if turtle.down() then
  76.         turZ = turZ - 1
  77.         return true
  78.     else
  79.         return false
  80.     end
  81. end
  82. move.forward = function()
  83.     if turtle.forward() then
  84.         if turF == 1 then
  85.             turY = turY + 1
  86.         elseif turF == 2 then
  87.             turX = turX + 1
  88.         elseif turF == 3 then
  89.             turY = turY - 1
  90.         elseif turF == 4 then
  91.             turX = turX - 1
  92.         end
  93.         return true
  94.     else
  95.         return false
  96.     end
  97. end
  98. move.back = function()
  99.     if turtle.back() then
  100.         if turF == 1 then
  101.             turY = turY - 1
  102.         elseif turF == 2 then
  103.             turX = turX - 1
  104.         elseif turF == 3 then
  105.             turY = turY + 1
  106.         elseif turF == 4 then
  107.             turX = turX + 1
  108.         end
  109.         return true
  110.     else
  111.         return false
  112.     end
  113. end
  114. move.currentPos = function()
  115.     return turX,turY,turZ,turF
  116. end
  117. local turn = {}
  118. turn.left = function()
  119.     if turtle.turnLeft() then
  120.         turF = turF - 1
  121.         if turF < 1 then
  122.             turF = 4
  123.         end
  124.         return true
  125.     else
  126.         return false
  127.     end
  128. end
  129. turn.right = function()
  130.     if turtle.turnRight() then
  131.         turF = turF + 1
  132.         if turF > 4 then
  133.             turF = 1
  134.         end
  135.         return true
  136.     else
  137.         return false
  138.     end
  139. end
  140. turn.face = function(direction)
  141.     if direction > 4 or direction < 1 then return false end
  142.     if direction == turF then return true end
  143.     if direction == turF - 2 or direction == turF + 2 then
  144.         turn.right()
  145.         turn.right()
  146.     else
  147.         local temp = direction-1
  148.         for p = 1,4 do
  149.             temp = temp+1
  150.             if temp > 4 then
  151.                 temp = 1
  152.             end
  153.             if turF == temp then
  154.                 if p == 1 or p == 4 then
  155.                     turn.right()
  156.                 elseif p == 2 or p == 3 then
  157.                     turn.left()
  158.                 end
  159.             end
  160.         end
  161.     end
  162. end
  163. move.gotoPos = function(gotoX,gotoY,gotoZ,gotoF) -- turX,turY,turZ,turF
  164.     local rep = 0
  165.     local happy
  166.     if gotoF == nil then
  167.         local happy = true
  168.     else
  169.         happy = function()
  170.             return turF ~= gotoF
  171.         end
  172.     end
  173.     while turX ~= gotoX or turY ~= gotoY or turZ ~= gotoZ or happy do
  174.         if turX > gotoX then
  175.             local dif = turX - gotoX
  176.             turn.face(4)
  177.             for i = 1,dif do
  178.                 move.forward()
  179.             end
  180.         end
  181.         if turX < gotoX then
  182.             local dif = gotoX - turX
  183.             turn.face(2)
  184.             for i = 1,dif do
  185.                 move.forward()
  186.             end
  187.         end
  188.         if turY > gotoY then
  189.             local dif = turY - gotoY
  190.             turn.face(3)
  191.             for i = 1,dif do
  192.                 move.forward()
  193.             end
  194.         end
  195.         if turY < gotoY then
  196.             local dif = gotoY - turY
  197.             turn.face(1)
  198.             for i = 1,dif do
  199.                 move.forward()
  200.             end
  201.         end
  202.         if turZ > gotoZ then
  203.             local dif = turZ - gotoZ
  204.             for i = 1,dif do
  205.                 move.down()
  206.             end
  207.         end
  208.         if turZ < gotoZ then
  209.             local dif = gotoZ - turZ
  210.             for i = 1,dif do
  211.                 move.up()
  212.             end
  213.         end
  214.         if gotoF then
  215.             turn.face(gotoF)
  216.         end
  217.         if rep > 5 then
  218.             return false
  219.         end
  220.         rep = rep + 1
  221.     end
  222. end
  223. local function CommandDecoder(Input)
  224.     local tWords = {}
  225.     for match in string.gmatch(Input, "[^ \t]+") do
  226.         table.insert( tWords, match )
  227.     end
  228.     if tWords[1] == "run" then
  229.         local program = tostring(tWords[2])
  230.         table.remove(tWords,1)
  231.         table.remove(tWords,1)
  232.         if task.run(program,unpack(tWords)) then
  233.             print("Running "..tostring(program))
  234.         else
  235.             print("program not started")
  236.         end
  237.     elseif tWords[1] == "kill" then
  238.         if task.kill(tostring(tWords[2])) then
  239.             print("Killed "..tostring(tWords[2]))
  240.         else
  241.             print("program not killed")
  242.         end
  243.     elseif tWords[1] == "pause" then
  244.         if task.pause(tostring(tWords[2])) then
  245.             print("Paused "..tostring(tWords[2]))
  246.         else
  247.             print("program not paused")
  248.         end
  249.     elseif tWords[1] == "resume" then
  250.         if task.resume(tostring(tWords[2])) then
  251.             print("Resuming "..tostring(tWords[2]))
  252.         else
  253.             print("program not Resumed")
  254.         end
  255.     elseif tWords[1] == "tasks" then
  256.             for i = 1,#tThreads do
  257.             --term.setCursorPos(1,sizY)
  258.             print(tThreads[i]["name"].." req "..tostring(tThreads[i]["req"]).." "..tostring(tThreads[i]["status"]))
  259.         end
  260.     elseif tWords[1] == "goto" then
  261.         if tWords[2] and tWords[2] == "home" then
  262.             if home then
  263.                 print("going home")
  264.                 move.gotoPos(home.x,home.y,home.z,home.f)
  265.             else
  266.                 print("home not set")
  267.             end
  268.         else
  269.             if #tWords == 4 then
  270.                 --term.setCursorPos(1,sizY)
  271.                 print("going to X-"..tWords[2].." Y-"..tWords[3].." Z-"..tWords[4])
  272.                 move.gotoPos(tonumber(tWords[2]),tonumber(tWords[3]),tonumber(tWords[4]))
  273.             elseif #tWords == 5 then
  274.                 --term.setCursorPos(1,sizY)
  275.                 print("going to X-"..tWords[2].." Y-"..tWords[3].." Z-"..tWords[4].." F-"..tWords[5])
  276.                 move.gotoPos(tonumber(tWords[2]),tonumber(tWords[3]),tonumber(tWords[4]),tonumber(tWords[5]))
  277.             end
  278.         end
  279.     elseif tWords[1] == "exit" then
  280.         --term.setCursorPos(1,sizY)
  281.         print("exiting")
  282.         os.pullEvent("exit")
  283.     --[[elseif tWords[1] == "help" then
  284.         print("Alavible Function's")
  285.         for i,v in ipairs(tPrograms) do
  286.             print(tostring(i).." "..tostring(v))
  287.         end]]--
  288.     elseif tWords[1] == "setHome" then -- needs work
  289.         home = {}
  290.         home.x = tonumber(tWords[2])
  291.         home.y = tonumber(tWords[3])
  292.         home.z = tonumber(tWords[4])
  293.         home.f = tonumber(tWords[5])
  294.         print("home set")
  295.         print("Home is X : "..home.x.." Y : "..home.y.." Z : "..home.z.." F : "..home.f)
  296.     elseif tWords[1] == "clearHome" then
  297.         if home then
  298.         home = nil
  299.             print("Home cleared")
  300.         else
  301.             print("home is already nil")
  302.         end
  303.     elseif tWords[1] == "home" then
  304.         if home then
  305.             print("Home is X : "..home.x.." Y : "..home.y.." Z : "..home.z.." F : "..home.f)
  306.         else
  307.             print("Home not set")
  308.         end
  309.     elseif tWords[1] == "fuel" then
  310.         print(turtle.getFuelLevel())
  311.     end
  312. end
  313.  
  314. -- sub programs --
  315.  
  316. -- netALPHA     --
  317. local tPrograms = {}
  318. tPrograms["netALPHA"] = function()
  319.     netALPHA = true --  so programs can test for NetALPHA
  320.     --local
  321.     local ver = 0.2
  322.     local Status = "unstable"
  323.     local off = true -- debug Mode is false no print is true
  324.     local MachineID = os.getComputerID()
  325.     local bSendMode = false
  326.     local tNodes = {} -- stores all avalible routes
  327.     local adressBook = {}
  328.     local maxHop = 5
  329.     -- functions
  330.     local function sPrint(Input)
  331.         if off then
  332.             return
  333.         end
  334.         if type(Input) == "table" then
  335.             print(tostring(Input).." "..#Input)
  336.         elseif type(Input) == "string" then
  337.             print(tostring(Input))
  338.         elseif Input == nil then
  339.             print("Nil Value fucked up here lol XD")
  340.         elseif type(Input) == "number" then
  341.             print(tostring(Input))
  342.         elseif type(Input) == "function" then
  343.             print(tostring(Input))
  344.         elseif type(Input) == "thread" then
  345.             print(tostring(Input))
  346.         else
  347.             print("Unknown Print request")
  348.         end
  349.     end
  350.  
  351.     local function DistanceMesure(set1X,set1Y,set1Z,set2X,set2Y,set2Z)
  352.         local iMeters = math.sqrt((math.sqrt(((set1X - set2X)^2) + ((set1Y - set2Y)^2)))^2 + (set1Z - set2Z)^2)
  353.         return iMeters
  354.     end
  355.  
  356.     local function findRoute(DesID,DesX,DesY,DesZ) -- find clostest router to destination.
  357.         local shortestM = nil
  358.         local shortestID = nil
  359.         for i = 1,#tNodes do
  360.             local Distance = math.sqrt((math.sqrt(((DesX - tNodes[i][2])^2) + ((DesY - tNodes[i][3])^2)))^2 + (DesZ - tNodes[i][4])^2)
  361.             if tNodes[i][1] == DesID then
  362.                 shortestM = Distance
  363.                 shortestID = tNodes[i][1]
  364.                 return  shortestID , shortestM
  365.             elseif shortestM == nil then
  366.                 shortestM = Distance
  367.                 shortestID = tNodes[i][1]
  368.             elseif Distance < shortestM then
  369.                 shortestM = Distance
  370.                 shortestID = tNodes[i][1]
  371.             end
  372.         end
  373.         if shortestM then
  374.             return shortestID , shortestM
  375.         else
  376.             return false
  377.         end
  378.     end
  379.  
  380.     local function PacketDecode(sPacket)
  381.         if string.sub(sPacket,1,8) == "netALPHA" then
  382.             local sTemp = string.find(sPacket,"{")
  383.             --sPrint(sTemp)
  384.             local sTemp3 = string.sub(sPacket,9,sTemp-1)
  385.             --sPrint(sTemp3)
  386.             local sTemp2 = tonumber(sTemp3)
  387.             --sPrint(sTemp2)
  388.             local tOutput = textutils.unserialize(string.sub(sPacket,sTemp,sTemp2+8+#sTemp3))
  389.             --sPrint(tOutput)
  390.             local sOutput = string.sub(sPacket,sTemp2+9+#sTemp3,#sPacket)
  391.             --sPrint(sOutput)
  392.             if type(tOutput) == "table" and type(sOutput) == "string" then
  393.                 if sOutput == "" then
  394.                     return tOutput
  395.                 else
  396.                     return tOutput,sOutput
  397.                 end
  398.             end
  399.         end
  400.         error()
  401.     end
  402.     local function printD(...)
  403.         if off then
  404.             return
  405.         else
  406.         print(...) 
  407.         end
  408.     end
  409.     local function addRoutBook(tAddress)
  410.         for i = 1,#tNodes do
  411.             if tNodes[i][1] == tAddress[1] then
  412.                 tNodes[i] = tAddress
  413.                 return
  414.             end
  415.         end
  416.         table.insert(tNodes,tAddress)
  417.         printD(type(tAddress))
  418.     end
  419.  
  420.     local function PacketBuilder(tInput,sInput)
  421.         if sInput == nil then
  422.             sInput = ""
  423.         end
  424.         if type(tInput) == "table" and type(sInput) == "string" then
  425.             local temp = textutils.serialize(tInput)
  426.             printD(temp)
  427.             local sOut = "netALPHA"..tostring(#temp)..temp..sInput
  428.             return sOut
  429.         else
  430.             return false
  431.         end
  432.     end
  433.  
  434.     local function sendPing()
  435.         rednet.broadcast(PacketBuilder({"INS","PING",MachineID,turX,turY,turZ}))
  436.     end
  437.  
  438.     os.startTimer(120+math.random(1,30)) -- 2 mins +- 15 secs
  439.     sendPing()
  440.  
  441.     -- main function
  442.     local function netALPHACore()
  443.         while true do
  444.             local sEvent,isendID,sMessage,iDistance = coroutine.yield()
  445.             if sEvent == "rednet_message" then
  446.                 local bStatus,tPacket,sPacket = pcall(PacketDecode,sMessage)
  447.                 if bStatus then
  448.                     if tPacket[1] == "PKT" and #tPacket == 10 then
  449.                         if tPacket[7] == MachineID then
  450.                             printD("Packet form me")
  451.                             printD("From ID: "..tPacket[3].." loc X: "..tPacket[4].." Y: "..tPacket[5].." Z: "..tPacket[6])
  452.                             printD("sent To: "..tPacket[7].." loc X: "..tPacket[8].." Y: "..tPacket[9].." Z: "..tPacket[10])
  453.                             os.queueEvent("netALPHA",tPacket[3],sPacket,DistanceMesure(tPacket[4],tPacket[5],tPacket[6],turX,turY,turZ))
  454.                         else
  455.                             printD("packet to forward")
  456.                             printD("From ID: "..tPacket[3].." loc X: "..tPacket[4].." Y: "..tPacket[5].." Z: "..tPacket[6])
  457.                             printD("sent To: "..tPacket[7].." loc X: "..tPacket[8].." Y: "..tPacket[9].." Z: "..tPacket[10])
  458.                             if tPacket[2] <= maxHop then
  459.                                 local forwardID,forwardM = findRoute(tPacket[7],tPacket[8],tPacket[9],tPacket[10])
  460.                                 sPrint("forwded to")
  461.                                 sPrint(forwardID)
  462.                                 sPrint(forwardM)
  463.                                 tPacket[2] = tPacket[2]+1 -- incrementing hop
  464.                                 rednet.send(forwardID,PacketBuilder(tPacket,sPacket))
  465.                             else
  466.                                 printD("MaxHop Ignore Packet")
  467.                             end
  468.                         end
  469.                     elseif tPacket[1] == "INS" then
  470.                         printD("instruction "..tPacket[2])
  471.                         if tPacket[2] == "PING" and #tPacket == 6 then
  472.                             addRoutBook({tPacket[3],tPacket[4],tPacket[5],tPacket[6]})
  473.                             rednet.send(isendID,PacketBuilder({"INS","PONG",MachineID,turX,turY,turZ}))
  474.                         elseif tPacket[2] == "PONG" and #tPacket == 6 then
  475.                             addRoutBook({tPacket[3],tPacket[4],tPacket[5],tPacket[6]})
  476.                         elseif tPacket[2] == "CHK-" and #tPacket == 10 then
  477.                         elseif tPacket[2] == "RPL-" and #tPacket == 10 then
  478.                         end
  479.                     end
  480.                 end
  481.             elseif sEvent == "timer" then
  482.                 os.startTimer(120+math.random(1,30))
  483.                 tNodes = {}
  484.                 sendPing()
  485.             end
  486.             if #tNodes >= 1 then
  487.                 for i = 1,#tNodes do
  488.                     printD("T "..i.." of "..#tNodes.." ID "..tNodes[i][1].." X"..tNodes[i][2].." Y"..tNodes[i][3].." Z"..tNodes[i][4])
  489.                 end
  490.             end
  491.         end
  492.     end
  493.     netALPHACore()
  494. end
  495.  
  496. tPrograms["manual"] = function()
  497.     while true do
  498.         local e,e1,e2,e3 = os.pullEvent()
  499.         if e == "netALPHA" then
  500.             print(tostring(e1).." "..tostring(e2).." "..tostring(e3))
  501.         elseif e == "char" then
  502.             if e1 == "w" then
  503.                 move.forward()
  504.             elseif e1 == "s" then
  505.                 move.back()
  506.             elseif e1 == "a" then
  507.                 turn.left()
  508.             elseif e1 == "d" then
  509.                 turn.right()
  510.             elseif e1 == "q" then
  511.                 move.up()
  512.             elseif e1 == "e" then
  513.                 move.down()
  514.             end
  515.         end
  516.     end
  517. end
  518.  
  519. tPrograms["console"] = function()
  520.     local tCommandHistory = {}
  521.     while true do
  522.         local sizX,sizY = term.getSize()
  523.         term.setCursorPos(1,sizY)
  524.         term.clearLine()
  525.         write("> ")
  526.         local sLine = read( nil, tCommandHistory )
  527.         CommandDecoder(sLine)
  528.         table.insert( tCommandHistory, sLine )
  529.     end
  530. end
  531. tPrograms["mine"] = function(...)
  532.     local tArgs = {...}
  533.     for i = 1,#tArgs do
  534.         tArgs[i] = tonumber(tArgs[i])
  535.     end
  536.     local startX,startY,startZ,face,lenX,lenY,depZ = unpack(tArgs)
  537.     -- local startX,startY,startZ,face,lenX,lenY,depZ = 15,-65,72,3,10,6,18
  538.     move.gotoPos(startX,startY,startZ,face)
  539.    
  540.     local neg = false
  541.     if math.fmod(lenY,2) ~= 0 then
  542.         neg = true
  543.     end
  544.     for p = 1,depZ do
  545.         for a = 1,lenY do
  546.             for i = 1,lenX-1 do
  547.                 turtle.dig()
  548.                 move.forward()
  549.             end
  550.             if a ~= lenY then
  551.                 if math.fmod(p,2) == 0 or neg then
  552.                     if math.fmod(a,2) == 0 then
  553.                         turn.left()
  554.                         turtle.dig()
  555.                         move.forward()
  556.                         turn.left()
  557.                     else
  558.                         turn.right()
  559.                         turtle.dig()
  560.                         move.forward()
  561.                         turn.right()
  562.                     end
  563.                 else
  564.                     if math.fmod(a,2) ~= 0 then
  565.                         turn.left()
  566.                         turtle.dig()
  567.                         move.forward()
  568.                         turn.left()
  569.                     else
  570.                         turn.right()
  571.                         turtle.dig()
  572.                         move.forward()
  573.                         turn.right()
  574.                     end
  575.                 end
  576.             else
  577.                 if math.fmod(a,2) == 0 then
  578.                     turn.left()
  579.                     turn.left()
  580.                 else
  581.                     turn.right()
  582.                     turn.right()
  583.                 end
  584.             end
  585.         end
  586.         if p ~= depZ then
  587.             turtle.digDown()
  588.             move.down()
  589.         end
  590.     end
  591.     if home then
  592.         move.gotoPos(home.x,home.y,home.z,home.f)
  593.     end
  594. end
  595. tPrograms["netCON"] = function()
  596.     while true do
  597.         local event,e1,e2,e3,e4,e5 = os.pullEvent("netALPHA")
  598.         print("RMT ins "..tostring(e1).." dst "..tostring(e3))
  599.         print(tostring(e2))
  600.         CommandDecoder(e2)
  601.     end
  602. end
  603.  
  604. -- task mangment-- local task = {}
  605. -- needs work
  606. task.run = function(program,...)
  607.     local tArgs = {...}
  608.     if tPrograms[program] then
  609.         local nNunber = #tThreads+1
  610.         tThreads[nNunber] = {}
  611.         tThreads[nNunber]["name"] = program
  612.         tThreads[nNunber]["thread"] = coroutine.create(tPrograms[program])
  613.         tThreads[nNunber]["req"] = nil
  614.         tThreads[nNunber]["status"] = "run"
  615.         if #tArgs == 0 then
  616.             tThreads[nNunber]["next"] = nil
  617.         else
  618.             tThreads[nNunber]["next"] = tArgs
  619.         end
  620.         return true
  621.     end
  622.     return false
  623. end
  624. task.pause = function(program)
  625.     for i = 1,#tThreads do
  626.         if tThreads[i]["name"] == program then
  627.             tThreads[i]["status"] = "pause"
  628.             return true
  629.         end
  630.     end
  631.     return false
  632. end
  633. task.resume = function(program)
  634.     for i = 1,#tThreads do
  635.         if tThreads[i]["name"] == program then
  636.             tThreads[i]["status"] = "run"
  637.             return true
  638.         end
  639.     end
  640.     return false
  641. end
  642. task.kill = function(program)
  643.     for i = 1,#tThreads do
  644.         if tThreads[i]["name"] == program then
  645.             table.remove(tThreads,i)
  646.             return true
  647.         end
  648.     end
  649.     return false
  650. end
  651.  
  652. -- boot process --
  653. print("Booting turtle NO: "..machineID)
  654. modemOn = netWork.open()
  655. if not modemOn then
  656.     print("No WIFI Modem\nPress any key to exit")
  657.     os.pullEvent("key")
  658.     return
  659. else
  660.     print("Opened wifi on "..modemOn.." side")
  661. end
  662. turX,turY,turZ = gps.locate(2,true) -- EDIT this line to > turX,turY,turZ = 0,0,0
  663. if not turX then
  664.     print("GPS locate failed\nPress any key to exit")
  665.     os.pullEvent("key")
  666.     return
  667. end
  668. print("Starting Networking")
  669. task.run("console")
  670. task.run("netALPHA")
  671. print("netPLPHA ID :".." "..machineID.." "..turX.." "..turY..""..turZ)
  672. print("boot compleet")
  673.  
  674. term.clear()
  675. term.setCursorPos(1,1)
  676.  
  677. -- main loop    --
  678. while bRunning do
  679.     local tEvent = {os.pullEvent()}
  680.     -- print(tEvent[1])
  681.     local loop = 1
  682.     while true do
  683.         if loop == #tThreads + 1 then
  684.             break
  685.         end
  686.         if coroutine.status(tThreads[loop]["thread"]) ~= "dead" then
  687.             if tThreads[loop]["status"] == "run" and type(tThreads[loop]["next"]) == "table" then
  688.                 --print("MARKER two")
  689.                 test,tThreads[loop]["req"] = coroutine.resume(tThreads[loop]["thread"],unpack(tThreads[loop]["next"])) -- fix
  690.                 tThreads[loop]["next"] = nil
  691.             end
  692.             if tThreads[loop]["req"] == "exit" then
  693.                 bRunning = false
  694.             end
  695.             if ( tThreads[loop]["req"] == nil or tEvent[1] == tThreads[loop]["req"] ) and tThreads[loop]["status"] == "run" then
  696.                 test,tThreads[loop]["req"] = coroutine.resume(tThreads[loop]["thread"],unpack(tEvent)) -- fix
  697.             elseif tThreads[loop]["status"] == "pause" and tEvent[1] == tThreads[loop]["req"] and tThreads[loop]["next"] == nil then
  698.                 --print("here marker")
  699.                 tThreads[loop]["next"] = tEvent
  700.             end
  701.             if tThreads[loop]["req"] == "exit" then
  702.                 bRunning = false
  703.             end
  704.             loop = loop + 1
  705.         else
  706.             print("Thread Crash")
  707.             print(tostring(tThreads[loop]["name"]))
  708.             print(tostring(tThreads[loop]["req"]))
  709.             table.remove(tThreads,loop)
  710.         end
  711.     end
  712.     local oldX,oldY = term.getCursorPos()
  713.     term.setCursorPos(1,1)
  714.     write(machineID.." threds: "..#tThreads.." "..tostring(tThreads[1]["req"]))
  715.     term.setCursorPos(oldX,oldY)
  716. end
  717. term.clear()
  718. term.setCursorPos(1,1)
  719. print("TAMS ended")
  720.  
  721. -- test --
  722. --[[
  723. turn.face(1)
  724. turn.face(2)
  725. turn.face(3)
  726. turn.face(4)
  727. turn.face(1)
  728. turn.face(2)
  729. turn.face(3)
  730. turn.face(4)
  731. print("pasued")
  732. os.pullEvent("key")
  733.  
  734. for i = 1,5 do
  735.     move.gotoPos(0,0,74)
  736.     move.gotoPos(-6,0,70)
  737.     move.gotoPos(-6,-13,68)
  738.     move.gotoPos(2,-4,80)
  739. end
  740. print("pasued")
  741. os.pullEvent("key")
  742. ]]--
  743.  
  744.  
  745. -- test script  --
  746. --[[
  747. local function positionPrint()
  748.     print("X "..turX.." Y "..turY.." Z "..turZ.." heading "..tFaces[turF])
  749. end
  750. local function sPrint(input)
  751.     print(type(input).." "..tostring(input))
  752. end
  753. positionPrint()
  754. move.forward()
  755. positionPrint()
  756. turn.left()
  757. positionPrint()
  758. move.forward()
  759. positionPrint()
  760. move.back()
  761. positionPrint()
  762. turn.right()
  763. positionPrint()
  764. move.back()
  765. positionPrint()
  766. move.up()
  767. positionPrint()
  768. move.down()
  769. positionPrint()
  770. ]]--
  771. --[[
  772. FAILED DIGGER script
  773.     local startX,startY,startZ,face,lenX,lenY,depZ = 15,-29,72,3,10,6,20
  774.     move.gotoPos(startX,startY,startZ,face)
  775.     for p = 1,depZ do
  776.         for a = 1,lenY do
  777.             for i = 1,lenX do
  778.                 turtle.dig()
  779.                 move.forward()
  780.             end
  781.             if math.fmod(p,2) == 0 then
  782.                 if math.fmod(a,2) == 0 then
  783.                     turn.left()
  784.                     turtle.dig()
  785.                     move.forward()
  786.                     turn.left()
  787.                 else
  788.                     turn.right()
  789.                     turtle.dig()
  790.                     move.forward()
  791.                     turn.right()
  792.                 end
  793.             else
  794.                 if math.fmod(a,2) ~= 0 then
  795.                     turn.left()
  796.                     turtle.dig()
  797.                     move.forward()
  798.                     turn.left()
  799.                 else
  800.                     turn.right()
  801.                     turtle.dig()
  802.                     move.forward()
  803.                     turn.right()
  804.                 end
  805.  
  806.             end
  807.         end
  808.         turtle.digDown()
  809.         move.down()
  810.     end
  811.     move.gotoPos(0,0,70)
  812. ]]--
Advertisement
Add Comment
Please, Sign In to add comment