AlertK

Untitled

Oct 25th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. id=2
  2. id2=163621
  3.  
  4. rap={wyd="tartak", fun="drwal", orp=5, zgd=0, stn=0, akt=0, pal=0, pll=turtle.getFuelLevel(), sur=0, gpx=0, gpy=0, gpz=0, pro=0, fnn="", fno="", rod="", nrd=0, var=0, kom=""}
  5.  
  6.  
  7. program=1
  8. aktywnosc=0
  9.  
  10. P1={rodzaj="P1", tekst="Czy baza aktywna?"}
  11. P2={rodzaj="P2", tekst="Czy pracowac?"}
  12.  
  13. function napisz(arg1)
  14. local tablica={wyd=rap.wyd, fun=rap.fun, orp=rap.orp zgd=rap.zgd, stn=rap.stn, akt=rap.akt, pal=rap.pal, pll=rap.pll, sur=rap.sur, gpx=rap.gpx, gpy=rap.gpy, gpz=rap.gpz, pro=rap.pro, rod="F", nrd=0, var=0, kom=arg1, fnn=rap.fnn, fno=rap.fno} --pobiera zmienne z tablicy glownej (wiekszosc) ale przypisuje wlasny rodzaj i tresc komunikatu
  15. print(arg1)
  16. modem.transmit(1, id, tablica)
  17. end
  18.  
  19. function uruchom_modem()
  20.  
  21.   modem=peripheral.wrap("right")
  22.   modem.open(id)
  23.   if modem.isOpen(id)==true then
  24.   rap.fnn="W1"
  25.   rap.fno="uruchom_modem"
  26.     napisz("Modem otwarty na kanale"..id)
  27.   else
  28.     print("Modem nie zostal otwarty")
  29.   end
  30. end
  31.  
  32. function wyslij(arg1)
  33.  
  34. tablica = {numer=id, stan=aktywnosc, rodzaj=arg1.rodzaj, tekst=arg1.tekst}
  35.   modem.transmit(1, id, tablica)
  36. end
  37.  
  38. function raportuj()
  39.   while true do
  40.     modem.transmit(1, id, rap)
  41.     sleep(rap.orp)
  42.   end
  43. end
  44.  
  45. function odpbazy(q1, q2)
  46.   os.startTimer(q2)
  47.   repeat
  48.     a1, b1, c1, d1, e1, f1 = os.pullEvent()
  49.   until ((a1=="modem_message") and (q1==e1.rodzaj)) or (a1=="timer")
  50.   if (a1=="modem_message") and (q1==e1.rodzaj) then
  51.     return e1.tekst
  52.   elseif a1=="timer" then
  53.     return a1
  54.   end    
  55. end
  56.  
  57. function polaczenie_z_baza(arg1, arg2, arg3, arg4)
  58.   rap.fnn="W2"
  59.   rap.fno="polaczenie_z_baza"
  60.   local warunek=0
  61.   local licz=0
  62.   napisz("Polaczenie_z_baza(): Pytanie: "..tablica.rod)
  63.   napisz("Polaczenie_z_baza(): Tekst: "..tablica.kom)
  64.   repeat
  65.     local tablica={wyd=rap.wyd, fun=rap.fun, orp=rap.orp zgd=rap.zgd, stn=rap.stn, akt=rap.akt, pal=rap.pal, pll=rap.pll, sur=rap.sur, gpx=rap.gpx, gpy=rap.gpy, gpz=rap.gpz, pro=rap.pro, rod="P", nrd=arg1, kom=arg2, var=id, fnn=rap.fnn, fno=rap.fno}
  66.     modem.transmit(1, id, tablica)
  67.     napisz("Polaczenie_z_baza(): proba: "..licz)
  68.     os.startTimer(arg3)
  69.     repeat
  70.       a1, b1, c1, d1, e1, f1 = os.pullEvent()
  71.       if ((a1=="modem_message") and (e1.nrd=1) and (e1.rod=="P") and (e1.var==id2)) then
  72.         warunek=1
  73.       else
  74.         warunek=0
  75.       end
  76.     until (warunek==1) or (a1=="timer")
  77.   licz=licz+1
  78.   until (warunek==1) or (licz2==arg4)    
  79. if warunek==1 then
  80.       return e1.kom
  81.       napisz("Otrzymalem wiadomosc: "..e1.kom
  82.     elseif a1=="timer" then
  83.       return a1
  84.       napisz("polaczenie_z_baza: Uplynal czas oczekiwania.")
  85.   end    
  86. end
  87.  
  88. function sluchaj(arg1, arg2)
  89.   local odp=odpbazy(arg1.rodzaj, arg2)
  90.   return odp  
  91. end
  92.  
  93. function czypracowac()
  94.   local odp=sluchaj(P2, 10)
  95.   if odp=="TAK" then
  96.     print("Mozna pracowac!")
  97.     return odp
  98.   elseif odp=="NIE" then
  99.     print("Koniec pracy")
  100.     return odp
  101.   else
  102.     print("Inny komunikat")
  103.   end
  104. end
  105.  
  106. function sygnal(kierunek)
  107.   if kierunek=="przod" then
  108.   czyjest, blok=turtle.inspect()
  109.   elseif kierunek=="gora" then
  110.   czyjest, blok=turtle.inspectUp()
  111.   elseif kierunek=="dol" then
  112.   czyjest, blok=turtle.inspectDown()
  113.   else
  114.   print("funkcja sygnal ze zlym parametrem")
  115.  
  116.   program=0
  117.   end
  118.  
  119.   if czyjest==false then
  120.     znaleziono="nic"
  121.   elseif blok["name"]=="minecraft:log" then
  122.     znaleziono="drewno"
  123.   elseif blok["name"]=="minecraft:sapling" then
  124.     znaleziono="sadzonka"
  125.   elseif blok["name"]=="minecraft:glass" then
  126.     znaleziono="szklo"
  127.   elseif blok["name"]=="minecraft:chest" then
  128.     znaleziono="skrzynia"
  129.   elseif blok["name"]=="minecraft:leaves" then
  130.     znaleziono="lisc"
  131.   elseif blok["name"]=="minecraft:snow_layer" then
  132.     znaleziono="snieg"
  133.   elseif blok["name"]=="minecraft:nether_brick" then
  134.     znaleziono="ceglanetheru"
  135.   elseif blok["name"]=="minecraft:stone" then
  136.     znaleziono="kamien"
  137.   elseif blok["name"]=="minecraft:lit_pumpkin" then
  138.     znaleziono="lampion"
  139.   elseif blok["name"]=="minecraft:obsidian" then
  140.     znaleziono="obsydian"
  141.   elseif (blok["name"]=="minecraft:stained_glass") and (blok.state["color"]=="blue") then
  142.     znaleziono="szklo_niebieskie"
  143.   elseif (blok["name"]=="minecraft:stained_glass") and (blok.state["color"]=="red") then
  144.     znaleziono="szklo_czerwone"
  145.   elseif (blok["name"]=="minecraft:stained_glass") and (blok.state["color"]=="purple") then
  146.     znaleziono="szklo_purpurowe"
  147.   elseif (blok["name"]=="minecraft:stained_glass") and (blok.state["color"]=="yellow") then
  148.     znaleziono="szklo_zolte"
  149.   elseif (blok["name"]=="minecraft:stained_glass") and (blok.state["color"]=="orange") then
  150.     znaleziono="szklo_pomaranczowe"
  151.   else
  152.     znaleziono="inne"
  153.   end
  154.   return znaleziono
  155. end
  156.  
  157. function ruch()
  158.   rap.fno="ruch"
  159.   if sygnal("dol")=="ceglanetheru" then
  160.     napisz("Jestem na linii. Zaczynam isc")
  161.     while sygnal("dol")=="ceglanetheru" do
  162.       if (sygnal("przod")=="lisc") or (sygnal("przod")=="snieg") then
  163.         turtle.dig()
  164.       end
  165.       turtle.suck()
  166.       turtle.forward()  
  167.     end
  168.     napisz("Koniec linii.")
  169.   else
  170.     napisz("Nie jestem na linii. Nie mog isc.")
  171.     rap.pro=1
  172.   end
  173.   rap.fno="N/A"
  174. end
  175.  
  176. function wytnijpion()
  177.   rap.fno="wytnij_pion"
  178.   napisz("Zaczynam funkcję wycinki.")
  179.   local licz=0
  180.   while (sygnal("przod")=="drewno") or (sygnal("gora")=="drewno") do
  181.     turtle.dig()
  182.     turtle.digUp()
  183.     turtle.up()
  184.     licz=licz+1
  185.     napisz("Scialem: "..licz)
  186.   end
  187.   while turtle.down()==true do
  188.   end
  189.   turtle.dig()
  190.   rap.fno=""
  191.   napisz("Koniec funkcji wytnij_pion")
  192. end
  193.  
  194. function posadzswierka()
  195.   turtle.select(16)
  196.   slot = turtle.getItemDetail()
  197.   if (slot.name=="minecraft:sapling") and (slot.count>4) then
  198.     turtle.digUp()
  199.     turtle.up()
  200.     turtle.placeDown()
  201.     turtle.dig()
  202.     turtle.forward()
  203.     turtle.placeDown()
  204.     turtle.turnRight()
  205.     turtle.dig()
  206.     turtle.forward()
  207.     turtle.placeDown()
  208.     turtle.turnRight()
  209.     turtle.dig()
  210.     turtle.forward()
  211.     turtle.placeDown()
  212.     turtle.turnLeft()
  213.     turtle.turnLeft()
  214.     turtle.forward()
  215.     turtle.dig()
  216.     turtle.forward()
  217.     turtle.digDown()
  218.     turtle.down()
  219.   else
  220.     print("Brak sadzonek")
  221.     turtle.turnRight()
  222.     turtle.forward()
  223.     turtle.turnLeft()
  224.     turtle.forward()
  225.     turtle.dig()
  226.     turtle.forward()
  227.     turtle.dig()
  228.     turtle.forward()
  229.   end
  230.   turtle.select(1)
  231. end
  232.  
  233. function wycinka()
  234.   if sygnal("dol")=="obsydian" then
  235.     print("Ustawiony do ciecia")
  236.     turtle.dig()
  237.     turtle.forward()
  238.     wytnijpion()
  239.     turtle.turnLeft()
  240.     turtle.dig()
  241.     turtle.forward()
  242.     turtle.turnRight()
  243.     wytnijpion()
  244.     posadzswierka()
  245.   else
  246.     print("wywolano wycinke w zlym miejscu")  
  247.     program=0
  248.   end
  249.  
  250. end
  251.  
  252. function zawroc()
  253.   if sygnal("dol")=="szklo_czerwone" then  
  254.     turtle.turnRight()
  255.     turtle.dig()
  256.     turtle.forward()
  257.     turtle.turnRight()
  258.   else
  259.     print("F:zawroc - Nie jestem ustawiony na polu zawracania")
  260.   end
  261. end
  262.  
  263. function powrot()
  264. program=1
  265.   if sygnal("dol")=="szklo_purpurowe" then
  266.     while (sygnal("dol")=="szklo_purpurowe") or (sygnal("dol")=="kamien") or (sygnal("dol")=="lampion") do
  267.       turtle.suck()
  268.       if (sygnal("przod")=="lisc") or (sygnal("przod")=="snieg") then
  269.         turtle.dig()
  270.       end
  271.       turtle.forward()
  272.     end
  273.     if sygnal("dol")=="szklo_czerwone" then
  274.       print("Koniec powrotu. Pole poprawne.")
  275.       program=1
  276.     else
  277.       print("Powrot zakonczony niepoprawnie.")
  278.       program=0
  279.     end
  280.   else
  281.     print("Nie jestem ustawiony na starcie powrotu")
  282.     program=0
  283.   end
  284. end
  285.  
  286. function seriawycinka()
  287. program=1
  288.   if sygnal("dol")=="szklo_niebieskie" then
  289.     turtle.dig()
  290.     turtle.forward()
  291.     repeat
  292.       program=1
  293.       ruch()
  294.       wycinka()
  295.     until (program==0) or (sygnal("dol")=="szklo_czerwone")
  296.   else
  297.     print("Nie jestem ustawiony na starcie serii wycinki.")
  298.     program=0
  299.   end
  300. end
  301.  
  302. function czypusty()
  303.   local licz2=1
  304.   local znaleziono=0
  305.   repeat
  306.     if turtle.getItemCount(licz2)>0 then
  307.       znaleziono=1
  308.     end  
  309.     licz2=licz2+1
  310.   until licz2==17
  311.   if znaleziono==0 then
  312.     print("F:czypusty. Rozladowano")
  313.     return true
  314.   else
  315.     print("F:czypusty. Nie rozladowano!")
  316.     return false
  317.   end
  318. end
  319.  
  320. function wysyp()
  321.   if (sygnal("dol")=="szklo_niebieskie") and (sygnal("przod")=="skrzynia") then
  322.     local licz=1
  323.     repeat
  324.       turtle.select(licz)
  325.       turtle.drop()
  326.       licz=licz+1
  327.     until licz==17
  328.     if czypusty()==true then
  329.       print("F:wysyp. Material wysypany.")
  330.       return true
  331.     else
  332.       print("F:wysyp. Wysypywanie nieskuteczne.")
  333.       return false
  334.     end
  335.   else
  336.     print("F:wysyp. Nie moge wysypac. Niewlasciwe pole.")
  337.     return false
  338.   end
  339. end
  340.  
  341. function rozladunek()
  342.   if sygnal("dol")=="szklo_czerwone" then
  343.     if sygnal("przod")~="szklo" then
  344.       repeat
  345.         turtle.turnLeft()
  346.       until sygal("przod")=="szklo"
  347.     end
  348.     turtle.turnRight()
  349.     turtle.dig()
  350.     turtle.forward()
  351.     turtle.turnLeft()
  352.   elseif sygnal("dol")=="szklo_zolte" then
  353.     if sygnal("przod")~="skrzynia" then
  354.       repeat
  355.         turtle.turnLeft()
  356.       until sygnal("przod")=="skrzynia"
  357.     end
  358.     turtle.turnLeft()
  359.     turtle.dig()
  360.     turtle.forward()
  361.     turtle.dig()
  362.     turtle.forward()
  363.     turtle.dig()
  364.     turtle.forward()
  365.     turtle.turnRight()
  366.   elseif sygnal("dol")=="szklo_niebieskie" then
  367.     if sygnal("przod")~="skrzynia" then
  368.       repeat
  369.         turtle.turnLeft()
  370.       until sygnal("przod")=="skrzynia"
  371.     end  
  372.   elseif sygnal("dol")=="szklo_pomaranczowe" then
  373.     if sygnal("przod")~="skrzynia" then
  374.       repeat
  375.         turtle.turnLeft()
  376.       until sygnal("przod")=="skrzynia"
  377.     end
  378.     turtle.turnRight()
  379.     turtle.dig()
  380.     turtle.forward()
  381.     turtle.dig()
  382.     turtle.forward()
  383.     turtle.turnLeft()
  384.   else
  385.     print("F:rozladunek. Nie stoje na pozycji do ustawiania")
  386.   end
  387.  
  388.   if (sygnal("dol")=="szklo_niebieskie") and sygnal("przod")=="skrzynia" then
  389.     wysyp()
  390.     turtle.turnLeft()
  391.     turtle.turnLeft()  
  392.   else
  393.     print("F:rozladunek - nie stoje na pozycji do wysypu")
  394.   end
  395. end
  396.  
  397. function tankuj()
  398.  
  399.   if czypusty()==true then
  400.     if (sygnal("dol")=="szklo_zolte") and (sygnal("przod")=="skrzynia") then
  401.       print("F:tankuj. Rozpoczynam tankowanie")
  402.       turtle.select(1)
  403.       local tank=1
  404.       repeat
  405.         turtle.suck()
  406.         turtle.refuel()
  407.         tank=tank+1
  408.       until tank==16  
  409.       print("F:tankuj. Zakonczono tankowanie. Poziom paliwa: "..turtle.getFuelLevel())
  410.     else
  411.       print("F:tankuj. Nie ustawiony do tankowania.")  
  412.     end
  413.   else
  414.     print("F:tankuj. Inwentaz nie oprozniony")  
  415.   end
  416. end
  417.  
  418.  
  419. function tankowanie()
  420.   if turtle.getFuelLevel()<2000 then
  421.     if sygnal("dol")=="szklo_niebieskie" then
  422.       repeat
  423.         turtle.turnLeft()
  424.       until sygnal("przod")=="skrzynia"
  425.       turtle.turnRight()
  426.       turtle.dig()
  427.       turtle.forward()
  428.       turtle.dig()
  429.       turtle.forward()
  430.       turtle.dig()
  431.       turtle.forward()
  432.       turtle.turnLeft()
  433.       tankuj()
  434.       elseif sygnal("dol")=="szklo_czerwone" then
  435.       repeat
  436.         turtle.turnLeft()
  437.       until sygnal("dol")=="szklo"
  438.       turtle.turnRight()
  439.       turtle.dig()
  440.       turtle.forward()
  441.       turtle.dig()
  442.       turtle.forward()
  443.       turtle.dig()
  444.       turtle.forward()
  445.       turtle.dig()
  446.       turtle.forward()
  447.       turtle.turnLeft()    
  448.       tankuj()
  449.     elseif sygnal("dol")=="szklo_zolte" then
  450.       repeat
  451.         turtle.turnLeft()
  452.       until sygnal("przod")=="skrzynia"
  453.       tankuj()
  454.     else
  455.       print("F:tankowanie. Nie jestem ustawiony na pozycji wyjsciowej")
  456.     end  
  457.   else
  458.     print("F:tankowanie. Bak pelny. Nie ma potrzeby ustawiania")
  459.   end
  460. end
  461.  
  462. function ust_pobor_sadzonek()
  463.  
  464.   if sygnal("dol")=="szklo_zolte" then
  465.     if sygnal("przod")~="skrzynia" then
  466.       repeat
  467.         turtle.turnLeft()
  468.       until sygnal("przod")=="skrzynia"
  469.     end
  470.     turtle.turnLeft()
  471.     turtle.dig()
  472.     turtle.forward()
  473.     turtle.dig()
  474.     turtle.forward()
  475.     turtle.dig()
  476.     turtle.forward()
  477.     turtle.dig()
  478.     turtle.forward()
  479.     turtle.dig()
  480.     turtle.forward()    
  481.     turtle.turnRight()
  482.   elseif sygnal("dol")=="szklo_niebieskie" then
  483.     if sygnal("przod")~="skrzynia" then
  484.       repeat
  485.         turtle.turnLeft()
  486.       until sygnal("przod")=="skrzynia"
  487.     end
  488.     turtle.turnLeft()
  489.     turtle.dig()
  490.     turtle.forward()
  491.     turtle.dig()
  492.     turtle.forward()
  493.     turtle.turnRight()
  494.   elseif sygnal("dol")=="szklo_czerwone" then
  495.     if sygnal("przod")~="szklo" then
  496.       repeat
  497.         turtle.turnLeft()
  498.       until sygnal("przod")=="szklo"
  499.     end
  500.     turtle.turnLeft()
  501.     turtle.dig()
  502.     turtle.forward()
  503.     turtle.turnRight()
  504.   elseif sygnal("dol")=="szklo_pomaranczowe" then
  505.     if sygnal("przod")~="skrzynia" then
  506.       repeat
  507.         turtle.turnLeft()
  508.       until sygnal("przod")=="skrzynia"
  509.     end
  510.   else
  511.     print("ERR! (F:ust_pobor_sadzonek). Nie znajduje sie na pozycji wyjsciowej")
  512.   end
  513. end
  514.  
  515. function czy_brac_sadzonki()
  516.    
  517.   if turtle.getItemCount(16)==0 then
  518.     print("(F:czy_brac_sadzonki). Slot pusty, mozna brac")
  519.     return "A"
  520.   else
  521.     local slot=turtle.getItemDetail(16)
  522.     if slot.name~="minecraft:sapling" then
  523.       print("(F:czy_brac_sadzonki). Slot zajety czyms innym")
  524.       return "B"
  525.     elseif (slot.name=="minecraft:sapling") and turtle.getItemCount(16)>41 then
  526.       print("(F:czy_brac_sadzonki). Wystarczajaca ilosc sadzonek")
  527.       return "C"
  528.     else
  529.       print("(F:czy_brac_sadzonki) Inne - mozna brac.")
  530.       return "D"
  531.     end
  532.   end
  533. end
  534.  
  535. function ladowanie_sadzonek()
  536.  if (sygnal("dol")=="szklo_pomaranczowe") and (sygnal("przod")=="skrzynia") then
  537.   turtle.select(16)
  538.   local max=turtle.getItemSpace()
  539.   print("Brakuje: "..max)
  540.   turtle.suck(max)
  541.   if turtle.getItemCount(16)==0 then
  542.     print("F:ladowanie_sadzonek - slot pusty po ladowaniu")
  543.   else
  544.     local slot=turtle.getItemDetail(16)
  545.     if (slot.name=="minecraft:sapling") and (slot.count>60) then
  546.       print("F:ladowanie_sadzonek. Zaladowano. Jest OK")
  547.     elseif (slot.name=="minecraft:sapling") and (slot.count<60) then  
  548.       print("F:ladowanie_sadzonek. Po zaladunku mala ilosc sadzonek")
  549.     elseif slot.name~="minecraft:sapling" then
  550.       print("F:ladowanie_sadzonek. W slocie zly przedmiot")
  551.       print(slot.name)
  552.     else
  553.       print("F:ladowanie_sadzonek. Inny wynik nieznany funkcji")  
  554.     end      
  555.   end
  556.  else
  557.    print("F:ladowanie_sadzonek. Ustawiony na zlym slocie")
  558.  end
  559. end
  560.  
  561.  
  562. function pelnaseria()
  563.   seriawycinka()  
  564.   zawroc()
  565.   powrot()
  566.   zawroc()
  567.   rozladunek()
  568.   tankowanie()
  569. end
  570.  
  571. function sadzonki()
  572.   local warunek=0
  573.   repeat
  574.   ocena=czy_brac_sadzonki()
  575.     if (ocena=="A") or (ocena=="D") then
  576.       print("F:sadzonki - ustawiam i pobieram")
  577.       warunek=1
  578.       ust_pobor_sadzonek()
  579.       ladowanie_sadzonek()
  580.       turtle.turnRight()
  581.       turtle.dig()
  582.       turtle.forward()
  583.       turtle.dig()
  584.       turtle.forward()
  585.       turtle.turnRight()
  586.     elseif ocena=="B" then
  587.       print("F:sadzonki - slot zajety. Oprozniam")
  588.       rozladunek()
  589.     elseif ocena=="C" then
  590.       print("F:sadzonki - nie ma potrzeby uzupelniania.")
  591.       warunek=1
  592.     else
  593.       print("F:sadzonki- wynik funkcji ocen nieznany")
  594.       warunek=1
  595.     end
  596.   until warunek==1
  597. end
  598.  
  599. function zgodanaprace()
  600.   local odp=odpbazy("P2", 10)
  601.   if odp=="TAK" then
  602.     print("Otrzymalem zgode na kolejny cykl")
  603.     aktywnosc=1
  604.     return true
  605.   elseif odp=="NIE" then
  606.     print("Otrzymalem rozkaz wstrzymania")
  607.     aktywnosc=0
  608.     return true
  609.   elseif odp=="timer" then
  610.     print("Czas minal")
  611.     return false
  612.   else
  613.     print("Inny przebieg funkcji")
  614.     return false
  615.   end
  616. end
  617.  
  618. function sprawdzgotowosc()
  619.   repeat
  620.   until zgodanaprace()==true
  621.   if aktywnosc==1 then
  622.   end  
  623. end
  624.  
  625.  
  626. function cykl()
  627. seriawycinka()
  628. zawroc()
  629. powrot()
  630. zawroc()
  631. rozladunek()
  632. tankowanie()
  633. sadzonki()
  634. end
  635.  
  636. uruchom_modem()
  637. while true do
  638. raportuj()
  639. turtle.forward()
  640. turtle.back()
  641. end
  642.  
  643. function wylaczone()
  644. polaczeniezbaza(P2, 2)
  645. end
Add Comment
Please, Sign In to add comment