Advertisement
Guest User

kopro OS ver. 0.004

a guest
Sep 11th, 2014
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 50.16 KB | None | 0 0
  1.         MON_SCALE  = 0.5
  2.         MIN_OFFSET = 2
  3.         MAX_OFFSET = 250
  4.         lazors     = {}
  5.         states     = {}
  6.         wcores         = {}
  7.         step       = 12
  8.         xOffset    = 2
  9.         yOffset    = 4
  10.         offset     = MIN_OFFSET
  11.         lasN = 0
  12.         print("loading...")
  13.         sleep(2)
  14.         Alarm = "top"
  15.         Style = {
  16.         CDeflt = colors.white,
  17.         BGDeflt = colors.blue,
  18.         CTitle = colors.black,
  19.         BGTitle = colors.cyan,
  20.         CWarn = colors.white,
  21.         BGWarn = colors.red
  22.         }
  23.          
  24.         function setScreenPosition()
  25.           backbutton_position = {x = screen_width/2, y = 1}
  26.           start_all_position = {x = 1, y = screen_height-2}
  27.           stop_all_position  = {x = screen_width - 3, y = screen_height-2}
  28.           lasermode_position = {x = math.floor(screen_width/2 - 2), y = screen_height-4}
  29.           mining_position = {x=screen_width/2 - 2, y = screen_height/2-4}
  30.           jumping_position  = {x=screen_width/2 - 2, y = screen_height/2-2}
  31.           GoJump_position = {x=screen_width/2 - 3, y = screen_height/2}
  32.           JumpToCoord_position = {x=screen_width/2 - 3, y = screen_height/2+4}
  33.           automine_position = {x=screen_width/2 - 3, y = screen_height/2+2}
  34.           shipscan_position = {x=screen_width/2 - 3, y = screen_height/2+2}          
  35.           shipsc_position = {x=screen_width/2 - 2, y = screen_height/2-6}
  36.           deployship_position = {x=screen_width/2 - 3, y = screen_height/2-4}
  37.           deployship1_position = {x=2, y = screen_height/2-2}
  38.           deployship2_position = {x=2, y = screen_height/2}
  39.           deployship3_position = {x=2, y = screen_height/2+2}
  40.           deployship4_position = {x=2, y = screen_height/2+4}
  41.           radar_position = {x=screen_width/2 - 2, y = screen_height/2}
  42.           radarscan_position = {x=2, y = screen_height-2}
  43.           title_position  = {x=1, y = 1}
  44.           textcenter_position = {x=1, y = screen_height/2}
  45.  
  46.         end
  47.          
  48.         function resetColorsScreen()
  49.           screen.setBackgroundColor(colors.black)
  50.           screen.setTextColor(colors.white)
  51.         end
  52.          
  53.         function setlasermode()
  54.           if lasermode == "mine" then
  55.           lasermode = "quarry"
  56.           print(lasermode)
  57.           SData.lasermode = lasermode
  58.           SaveData()
  59.           else
  60.           lasermode = "mine"
  61.           print(lasermode)
  62.           SData.lasermode = lasermode
  63.           SaveData()
  64.           end
  65.         end  
  66.          
  67.         function start(laserNUM)
  68.           print("Calling laser "..lazors[laserNUM].." for start")
  69.           setOffset(laserNUM, offset)
  70.           m.callRemote(lazors[laserNUM], lasermode)
  71.         end
  72.          
  73.         function startAll()
  74.           for i =1 ,#lazors do
  75.            start(i)
  76.           end
  77.         end
  78.          
  79.         function stop(laserNUM)
  80.           print("Calling laser "..lazors[laserNUM].." for stop")
  81.           m.callRemote(lazors[laserNUM], "stop")
  82.         end
  83.          
  84.         function stopAll()
  85.           for i = 1 ,#lazors do
  86.            stop(i)
  87.           end
  88.         end
  89.          
  90.         function setOffset(laserNUM, offset)
  91.           m.callRemote(lazors[laserNUM], "offset", offset)
  92.         end
  93.          
  94.         function minestatistic()
  95.           screen.clear()
  96.           feelScreen(colors.black,colors.white)
  97.           qml = 0
  98.           lay = 0
  99.           lux = 0
  100.           min = 0
  101.           screen.setCursorPos(1 , 3)
  102.           screen.setBackgroundColor(colors.cyan)
  103.           screen.write( "LASERS      " .. #lazors)
  104.           feelScreen(colors.black,colors.white)
  105.           screen.setBackgroundColor(colors.blue)
  106.           screen.setCursorPos(start_all_position.x ,start_all_position.y)
  107.           if modemenu == "automine" then
  108.             screen.write("AUTOMINE")
  109.           else
  110.             screen.write("GO")
  111.             screen.setCursorPos(stop_all_position.x, stop_all_position.y)
  112.             screen.write("xXx")
  113.           end
  114.          
  115.           screen.setBackgroundColor(colors.green)
  116.           screen.setCursorPos(lasermode_position.x, lasermode_position.y)
  117.           screen.write(lasermode)
  118.           feelScreen(colors.black,colors.white)
  119.           screen.setBackgroundColor(colors.blue)
  120.           screen.setCursorPos(backbutton_position.x, backbutton_position.y)
  121.           screen.write("BACK")
  122.           feelScreen(colors.black,colors.white)
  123.           for a = 1,#lazors do
  124.             mState, mEnergy, mLayer, mValuablesMined, mValuablesInLayer = m.callRemote(lazors[a], "state")
  125.             print(mState)  
  126.             if mState ~= "not mining"  then                
  127.               qml= qml+1
  128.               lay = lay + mLayer
  129.               lux = lux + mValuablesMined
  130.               min = min + mValuablesInLayer
  131.               if mEnergy == 0 then
  132.                 screen.setCursorPos(1 , 11)
  133.                 screen.setBackgroundColor(colors.red)
  134.                 screen.write( "low energy L" ..a)
  135.                 feelScreen(colors.black,colors.white)
  136.               end                
  137.             end
  138.           end  
  139.           screen.setCursorPos(1 , 5)
  140.           screen.setBackgroundColor(colors.green)
  141.           screen.write( "IN WORK     " .. qml)
  142.           feelScreen(colors.black,colors.white)  
  143.           print(qml)
  144.           if qml > 0 then
  145.             mLay = lay/qml
  146.             mLux = lux/qml
  147.             mmin = min*10/qml
  148.           end
  149.           screen.setCursorPos(1 , 7)
  150.           screen.setBackgroundColor(colors.blue)
  151.           screen.write( "LAYER    " .. tostring(mLay))
  152.           feelScreen(colors.black,colors.white)
  153.           screen.setCursorPos(1 , 9)
  154.           screen.setBackgroundColor(colors.blue)
  155.           screen.write( "MINE  " .. tostring(lux) .."/" .. tostring(mmin))
  156.           feelScreen(colors.black,colors.white)
  157.           sleep(0.5)
  158.           return 0  
  159.         end
  160.          
  161.         function mining()
  162.           modemenu = "mine"
  163.           SData.modemenu = "mine"
  164.           SData.lasermode = lasermode;
  165.           SaveData()
  166.           screen.clear()
  167.           minestatistic()
  168.           sleep(0.5)
  169.           return 0
  170.         end
  171.          
  172.          
  173.         function automine()
  174.           modemenu = "automine"
  175.           SData.modemenu = "automine"
  176.           SData.lasermode  = lasermode
  177.           SaveData()
  178.          
  179.           minestatistic()
  180.          
  181.           if qml == 0 then
  182.             stopAll()
  183.             sleep(3)
  184.             Warp()
  185.             sleep(10)
  186.           end
  187.           sleep(0.5)
  188.           return 0
  189.         end
  190.          
  191.         function feelScreen(bcolor,tcolor)
  192.           screen.setBackgroundColor(bcolor)
  193.           screen.setTextColor(tcolor)
  194.         end
  195.          
  196.         function SetColorDeflt()
  197.           term.setBackgroundColor(Style.BGDeflt)
  198.           term.setTextColor(Style.CDeflt)
  199.         end
  200.          
  201.         function SetColorTitle()
  202.           term.setBackgroundColor(Style.BGTitle)
  203.           term.setTextColor(Style.CTitle)
  204.         end
  205.          
  206.         function SetColorWarn()
  207.           term.setBackgroundColor(Style.BGWarn)
  208.           term.setTextColor(Style.CWarn)
  209.         end
  210.          
  211.         function Clear()
  212.           term.clear()
  213.           term.setCursorPos(1,1)
  214.         end
  215.          
  216.         function Show(Text)
  217.           term.write(Text)
  218.           local xt,yt = term.getCursorPos()
  219.           term.setCursorPos(1, yt+1)
  220.         end
  221.          
  222.         function ShowTitle(Text)
  223.           SetColorTitle()
  224.           term.setCursorPos(12, 1)
  225.           Show(Text)
  226.           SetColorDeflt()
  227.         end
  228.          
  229.         function ShowMenu(Text)
  230.           term.write(Text)
  231.           local xt, yt = term.getCursorPos()
  232.           for i = xt, 51 do
  233.             term.write(" ")
  234.           end
  235.           term.setCursorPos(1, yt+1)
  236.         end
  237.          
  238.         function ShowWarning(Text)
  239.           SetColorWarn()
  240.           term.setCursorPos(10, 19)
  241.           term.write(" "..Text.." ")
  242.           SetColorDeflt()
  243.         end
  244.          
  245.         function SaveData()
  246.           local file = fs.open("shipdata.txt", "w")
  247.           file.writeLine(textutils.serialize(SData))
  248.           file.close()
  249.         end
  250.          
  251.         function ReadData()
  252.           local file = fs.open("shipdata.txt", "r")
  253.           SData = textutils.unserialize(file.readAll())
  254.           file.close()
  255.         end
  256.          
  257.         function Explode(d, p)
  258.           local t, ll
  259.           t = {}
  260.           ll = 0
  261.           if(#p == 1) then return {p} end
  262.           while true do
  263.             l = string.find(p ,d, ll, true)
  264.             if l ~= nil then
  265.               table.insert(t, string.sub(p, ll, l-1))
  266.               ll = l+1
  267.             else
  268.               table.insert(t, string.sub(p, ll))
  269.               break
  270.             end
  271.           end
  272.           return t
  273.         end
  274.          
  275.         function ShowDirection()
  276.           if SData.Direction == 1 then
  277.             Show(" Direction        = Up")
  278.             elseif SData.Direction == 2 then
  279.             Show(" Direction        = Down")
  280.             elseif SData.Direction == 0 then
  281.             Show(" Direction        = Front")
  282.             elseif SData.Direction == 180 then
  283.             Show(" Direction        = Back")
  284.             elseif SData.Direction == 90 then
  285.             Show(" Direction        = Left")
  286.             elseif SData.Direction == 255 then
  287.             Show(" Direction        = Right")
  288.           end
  289.           return 0
  290.         end
  291.  
  292.         function GetMinimumDistance()
  293.           if IsInHyper then          
  294.             MinimumDistance = 1
  295.           else
  296.             if SData.Direction == 1 or SData.Direction == 2 then
  297.               MinimumDistance = GUp + GDown            
  298.             elseif SData.Direction == 0 or SData.Direction == 180 then
  299.               MinimumDistance = GFront + GBack              
  300.             elseif SData.Direction == 90 or SData.Direction == 255 then
  301.               MinimumDistance = GLeft + GRight              
  302.             end
  303.             MinimumDistance = MinimumDistance + 1            
  304.           end          
  305.         end
  306.          
  307.         function CalcRealDistance()
  308.         GetMinimumDistance()
  309.           if IsInHyper then
  310.             RealDistance = SData.Distance * 100
  311.             JumpCost = (1000 * Weight) + (1000 * SData.Distance)
  312.           else
  313.             RealDistance = SData.Distance + MinimumDistance
  314.             JumpCost = (10 * Weight) + (100 * SData.Distance)
  315.           end
  316.           return 0
  317.         end
  318.          
  319.         function CalcNewCoords(cx, cy, cz)
  320.           local res = {x=cx, y=cy, z=cz}
  321.           if SData.Direction == 1 then
  322.             res.y = res.y + RealDistance
  323.           elseif SData.Direction == 2 then
  324.             res.y = res.y - RealDistance
  325.           end
  326.           local dx = warp.get_dx()
  327.           local dz = warp.get_dz()
  328.           if dx ~= 0 then
  329.             if SData.Direction == 0 then
  330.               res.x = res.x + (RealDistance * dx)
  331.             elseif SData.Direction == 180 then
  332.               res.x = res.x - (RealDistance * dx)
  333.             elseif SData.Direction == 90 then
  334.               res.z = res.z + (RealDistance * dx)
  335.             elseif SData.Direction == 255 then
  336.               res.z = res.z - (RealDistance * dx)
  337.             end
  338.           else
  339.             if SData.Direction == 0 then
  340.               res.z = res.z + (RealDistance * dz)
  341.             elseif SData.Direction == 180 then
  342.               res.z = res.z - (RealDistance * dz)
  343.             elseif SData.Direction == 90 then
  344.               res.x = res.x + (RealDistance * dz)
  345.             elseif SData.Direction == 255 then
  346.               res.x = res.x - (RealDistance * dz)
  347.             end
  348.           end
  349.           return res
  350.         end
  351.          
  352.         function ShowInfo()
  353.           Title = "<Jump-S 1.7.0 \""..SData.Shipname.."\">"
  354.           ShowTitle(Title)
  355.           if SData.MainCore == SData.CurrentCore then
  356.             Show("Current core: " .. tostring(wcores[curCoreIndex]["ID"]) .. "M")    
  357.           else
  358.             Show("Current core: " .. tostring(wcores[curCoreIndex]["ID"]) )
  359.           end    
  360.           Show(" x, y, z          = "..X..", "..Y..", "..Z)
  361.           local energy = warp.get_energy_level()
  362.           Show(" Energy           = "..math.floor(energy / 1000000).." % ("..energy.."EU)")
  363.           Show(" Attached players = "..warp.get_attached_players())
  364.           Show("Dimensions:")
  365.           Show(" Front, Right, Up = "..GFront..", "..GRight..", "..GUp)
  366.           Show(" Back, Left, Down = "..GBack..", "..GLeft..", "..GDown)
  367.           Show(" Size             = "..Weight.." blocks")
  368.           Show("Warp data:")
  369.           ShowDirection()
  370.           local dest = CalcNewCoords(X, Y, Z)
  371.           Show(" Distance         = "..RealDistance.." ("..JumpCost.."EU, "..math.floor(energy/JumpCost).." jumps)")
  372.           Show(" Dest.coordinates = "..dest.x..", "..dest.y..", "..dest.z)
  373.           if SData.Summon then
  374.             Show(" Summon after     = Yes")
  375.           else
  376.             Show(" Summon after     = No")
  377.           end
  378.         end
  379.          
  380.         function Confirm()
  381.           ShowWarning("Are you sure? (y/n)")
  382.           local event, keycode = os.pullEvent("key")
  383.           if keycode == 21 then
  384.             return true
  385.           else
  386.             return false
  387.           end
  388.           Clear()          
  389.         end
  390.          
  391.         function Warp()
  392.           rs.setOutput(Alarm, false)
  393.           if multicore then
  394.             for cr = 1, #wcores do
  395.               warp = wcores[cr]["core"]
  396.               SData.CurrentCore = wcores[cr]["ID"]
  397.               SaveData()
  398.               if SData.MainCore ~= SData.CurrentCore then
  399.                 warp.set_direction(SData.Direction)
  400.                 warp.set_distance(SData.Distance)
  401.                 if IsInHyper then
  402.                   warp.set_mode(2)
  403.                 else
  404.                   warp.set_mode(1)
  405.                 end
  406.                -- sleep(5)
  407.                 warp.do_jump()
  408.                 sleep(2)                  
  409.               end
  410.             end
  411.             warp = wcores[SData.MainCore]["core"]
  412.             warp.set_direction(SData.Direction)
  413.             warp.set_distance(SData.Distance)
  414.             if IsInHyper then
  415.                 warp.set_mode(2)
  416.             else
  417.                     warp.set_mode(1)
  418.             end
  419.             warp.do_jump()
  420.             sleep(1)
  421.           else
  422.             warp.set_direction(SData.Direction)
  423.             warp.set_distance(SData.Distance)
  424.             if IsInHyper then
  425.                     warp.set_mode(2)
  426.             else
  427.                     warp.set_mode(1)
  428.             end
  429.             warp.do_jump()
  430.  
  431.           end
  432.         end
  433.  
  434.         function autojumpStatistic()
  435.           screen.clear()        
  436.           feelScreen(colors.black,colors.white)
  437.           screen.setBackgroundColor(colors.blue)
  438.           screen.setCursorPos(backbutton_position.x, backbutton_position.y)
  439.           screen.write("BACK")  
  440.           feelScreen(colors.black,colors.white)
  441.           screen.setCursorPos(1 , 3)
  442.           screen.setBackgroundColor(colors.blue)
  443.           screen.write( "DestCoords")
  444.           feelScreen(colors.black,colors.white)
  445.           screen.setCursorPos(1 , 4)
  446.           screen.setBackgroundColor(colors.green)
  447.           screen.write( " x:" .. SData.DestCoordX .. " Z:" .. SData.DestCoordZ)
  448.           feelScreen(colors.black,colors.white)
  449.           screen.setCursorPos(1 , 6)
  450.           screen.setBackgroundColor(colors.green)
  451.           DX  = math.abs(SData.DestCoordX - X)          
  452.           DZ  = math.abs(SData.DestCoordZ - Z)        
  453.           screen.write( " DX:" .. DX)
  454.           feelScreen(colors.black,colors.white)
  455.           screen.setCursorPos(1 , 7)
  456.           screen.setBackgroundColor(colors.green)
  457.           screen.write( " DZ:" .. DZ)
  458.           feelScreen(colors.black,colors.white)
  459.           screen.setCursorPos(1 , 9)
  460.           screen.setBackgroundColor(colors.red)
  461.           screen.write( " ENERGY:" .. warp.get_energy_level())
  462.           feelScreen(colors.black,colors.white)
  463.           screen.setCursorPos(1 , 11)
  464.           screen.setBackgroundColor(colors.magenta)
  465.           screen.write( " Jumps:" ..math.floor(warp.get_energy_level()/JumpCost))
  466.           feelScreen(colors.black,colors.white)
  467.         end
  468.  
  469.         function SetCoord()
  470.           modemenu = "jtc"                    
  471.           if SData.autojump == true then
  472.             JumpToCoord()
  473.           end
  474.           Clear()          
  475.           ShowTitle("<====  Set DestCoords  ====>")          
  476.           term.write(" X ("..SData.DestCoordX..") : ")
  477.           SData.DestCoordX = tonumber(read())
  478.           term.write(" Z ("..SData.DestCoordZ..") : ")
  479.           SData.DestCoordZ = tonumber(read())
  480.           SaveData()
  481.           sleep(0.3)
  482.           if Confirm() then
  483.             JumpToCoord()
  484.           end
  485.         end
  486.  
  487.         function GoToSpace()
  488.           autojumpStatistic()
  489.           if warp.is_in_space() then
  490.             SData.DestCoordY = 250
  491.             SData.Direction = 1
  492.             GetMinimumDistance()            
  493.             SaveData()
  494.             DY  = math.abs(SData.DestCoordY - Y)
  495.             if DY > MinimumDistance then            
  496.               if SData.DestCoordY>Y then
  497.                 SData.Direction = 1
  498.               elseif SData.DestCoordY<Y then
  499.                 SData.Direction = 0
  500.               end
  501.               Dist = DY
  502.               GetMinimumDistance()
  503.               MaxDist = MinimumDistance+127            
  504.               print(MaxDist .. " MaxDist")
  505.               print(Dist .. " Dist")
  506.               if Dist>MaxDist then
  507.                 SData.Distance = MaxDist
  508.               else
  509.                 SData.Distance = Dist
  510.               end
  511.               SaveData()
  512.               Warp()
  513.               sleep(10)
  514.             end
  515.           elseif not IsInHyper then
  516.  
  517.             SData.Direction = 1
  518.             GetMinimumDistance()
  519.             MaxDist = MinimumDistance+127  
  520.             SData.Distance = MaxDist
  521.             SaveData()
  522.             Warp()
  523.             sleep(10)            
  524.           end
  525.         end
  526.  
  527.  
  528.         function JumpInHyper()
  529.           autojumpStatistic()
  530.           if IsInHyper then
  531.             print("in Hyperspace")
  532.  
  533.             DX  = math.abs(SData.DestCoordX - X)
  534.             print(DX .. " alldistX")
  535.             DZ  = math.abs(SData.DestCoordZ - Z)
  536.             print(DZ .. " alldistZ")
  537.             SData.Direction = 255
  538.             GetMinimumDistance()  
  539.  
  540.             if DX > 100 then            
  541.               if SData.DestCoordX>X then
  542.                 SData.Direction = 255
  543.               elseif SData.DestCoordX<X then
  544.                 SData.Direction = 90
  545.               end
  546.               Dist = DX
  547.               GetMinimumDistance()
  548.               MaxDist = MinimumDistance+127            
  549.               print(MaxDist .. " MaxDist")
  550.               print(Dist .. " Dist")
  551.               if Dist>MaxDist*100 then
  552.                 SData.Distance = MaxDist
  553.               else
  554.                 SData.Distance = math.floor(Dist/100)
  555.               end
  556.               SaveData()
  557.               Warp()
  558.               sleep(10)
  559.             else
  560.               SData.Direction = 180
  561.               GetMinimumDistance()
  562.               if DZ > 100 then
  563.                 if SData.DestCoordZ>Z then
  564.                   SData.Direction = 180
  565.                 elseif SData.DestCoordZ<Z then
  566.                   SData.Direction = 0
  567.                 end            
  568.                 Dist = DZ
  569.                 GetMinimumDistance()
  570.                 MaxDist = MinimumDistance + 127
  571.                 print(MaxDist .. " MaxDist")
  572.                 print(Dist .. " Dist")
  573.                 if Dist>MaxDist*100 then
  574.                   SData.Distance = MaxDist
  575.                 else
  576.                   SData.Distance = math.floor(Dist/100)
  577.                 end
  578.                 SaveData()
  579.                 Warp()
  580.                 sleep(10)
  581.               end    
  582.             end
  583.           else
  584.             print("go to Hyperspace")
  585.             rs.setOutput(Alarm, false)
  586.             warp.set_mode(5)
  587.             warp.do_jump()
  588.             sleep (10)
  589.           end        
  590.         end
  591.      
  592.  
  593.         function JumpToCoord()
  594.           autojumpStatistic()
  595.           SData.autojump = true
  596.           SaveData()
  597.           GoToSpace()
  598.          
  599.           print(SData.DestCoordX)          
  600.           DX  = math.abs(SData.DestCoordX - X)          
  601.           DZ  = math.abs(SData.DestCoordZ - Z)          
  602.           SData.Direction = 255
  603.           GetMinimumDistance()  
  604.           MaxDist = MinimumDistance+127
  605.           MAXDX =MaxDist*5
  606.           if DX>MAXDX or DZ>MAXDX then
  607.             print(MAXDX .. " to Hyperspace")
  608.             JumpInHyper()
  609.           else
  610.             if IsInHyper then
  611.               rs.setOutput(Alarm, false)
  612.               warp.set_mode(5)
  613.               warp.do_jump()
  614.             end
  615.           end  
  616.           if DX > MinimumDistance then            
  617.             if SData.DestCoordX>X then
  618.               SData.Direction = 255
  619.             elseif SData.DestCoordX<X then
  620.               SData.Direction = 90
  621.             end
  622.             Dist = DX
  623.             GetMinimumDistance()
  624.             MaxDist = MinimumDistance+127        
  625.             if Dist>MaxDist then
  626.               SData.Distance = MaxDist
  627.             else
  628.               SData.Distance = Dist
  629.             end
  630.             for i = 0,5 do
  631.               print("autojump in " .. 5-i .. "sec.")
  632.               sleep(1)  
  633.               i = i+1
  634.             end
  635.             SaveData()
  636.             Warp()
  637.             sleep(10)
  638.           else
  639.             SData.Direction = 180
  640.             GetMinimumDistance()
  641.             if DZ > MinimumDistance then
  642.               if SData.DestCoordZ>Z then
  643.                 SData.Direction = 180
  644.               elseif SData.DestCoordZ<Z then
  645.                 SData.Direction = 0
  646.               end            
  647.               Dist = DZ
  648.               GetMinimumDistance()
  649.               MaxDist = MinimumDistance + 127
  650.               if Dist>MaxDist then
  651.                 SData.Distance = MaxDist
  652.               else
  653.                 SData.Distance = Dist
  654.               end
  655.               for i = 0,5 do
  656.                 print("autojump in " .. 5-i .. "sec.")
  657.                 sleep(1)  
  658.                 i = i+1
  659.               end
  660.               SaveData()
  661.               Warp()
  662.               sleep(10)
  663.             else
  664.               SData.autojump = false  
  665.               SaveData()          
  666.             end
  667.           end
  668.         end
  669.  
  670.          
  671.         function SetDistance()
  672.           Clear()
  673.           ShowTitle("<====  Set distance  ====>")
  674.           SData.Distance = 0
  675.           GetMinimumDistance()
  676.           CalcRealDistance()
  677.           MaximumDistance = MinimumDistance + 127
  678.           if IsInHyper then
  679.             term.write("Distance * 100 (min "..MinimumDistance..", max "..MaximumDistance.."): ")
  680.           else
  681.             term.write("Distance (min "..MinimumDistance..", max "..MaximumDistance.."): ")
  682.           end
  683.           sleep(0.3)
  684.           SData.Distance = tonumber(read())
  685.           if SData.Distance == nil then SData.Distance = 1 end
  686.           if SData.Distance < MinimumDistance or SData.Distance > MaximumDistance then
  687.             SData.Distance = 1
  688.             ShowWarning("Wrong distance. Try again.")
  689.             os.pullEvent("key")
  690.             CalcRealDistance()
  691.           else
  692.             if not IsInHyper then
  693.               SData.Distance = SData.Distance - RealDistance
  694.             end
  695.             warp.set_distance(SData.Distance)
  696.             CalcRealDistance()
  697.           end
  698.           return 0
  699.         end
  700.          
  701.         function SetDirection()
  702.           local drun = true
  703.           while(drun) do
  704.           Clear()
  705.           ShowTitle("<==== Set direction ====>")
  706.           ShowDirection()
  707.           term.setCursorPos(1, 16)
  708.           SetColorTitle()
  709.           ShowMenu("Use directional keys")
  710.           ShowMenu("W/S keys for Up/Down")
  711.           ShowMenu("Enter - confirm")
  712.           SetColorDeflt()
  713.           local event, keycode = os.pullEvent("key")
  714.           if keycode == 200 then
  715.             SData.Direction = 0
  716.           elseif keycode == 17 then
  717.             SData.Direction = 1
  718.           elseif keycode == 203 then
  719.             SData.Direction = 90
  720.           elseif keycode == 205 then
  721.             SData.Direction = 255
  722.           elseif keycode == 208 then
  723.             SData.Direction = 180
  724.           elseif keycode == 31 then
  725.             SData.Direction = 2
  726.           elseif keycode == 28 then
  727.             drun = false
  728.           end
  729.           end
  730.         end
  731.          
  732.         function SetDimensions()
  733.           Clear()
  734.           sleep(0.3)
  735.           ShowTitle("<==== Set dimensions ====>")
  736.           term.write(" Front ("..GFront..") : ")
  737.           GFront = tonumber(read())
  738.           term.write(" Right ("..GRight..") : ")
  739.           GRight = tonumber(read())
  740.           term.write(" Up    ("..GUp..") : ")
  741.           GUp = tonumber(read())
  742.           term.write(" Back  ("..GBack..") : ")
  743.           GBack = tonumber(read())
  744.           term.write(" Left  ("..GLeft..") : ")
  745.           GLeft = tonumber(read())
  746.           term.write(" Down  ("..GDown..") : ")
  747.           GDown = tonumber(read())
  748.           term.write("Setting dimensions...")
  749.           warp.dim_setp(GFront, GRight, GUp)
  750.           warp.dim_setn(GBack, GLeft, GDown)
  751.           jumping()
  752.         end
  753.          
  754.         function Summon()
  755.           Clear()
  756.           ShowTitle("<==== Summon players ====>")
  757.           local players = Explode(",", warp.get_attached_players())
  758.           for i = 1, #players do
  759.             Show(i..". "..players[i])
  760.           end
  761.           SetColorTitle()
  762.           ShowMenu("Enter player number")
  763.           ShowMenu("or press enter to summon everyone")
  764.           SetColorDeflt()
  765.           sleep(0.3)
  766.           term.write(":")
  767.           local input = read()
  768.           if input == "" then
  769.             warp.summon_all()
  770.           else
  771.             input = tonumber(input)
  772.             warp.summon(input - 1)
  773.           end
  774.           return 0
  775.         end
  776.          
  777.         function JumpToBeacon()
  778.           Clear()
  779.           ShowTitle("<==== Jump to beacon ====>")
  780.           sleep(0.3)
  781.           term.write("Enter beacon frequency: ")
  782.           local freq = tostring(read())
  783.           rs.setOutput(Alarm, true)
  784.           if Confirm() then
  785.           rs.setOutput(Alarm, false)
  786.           warp.set_mode(4)
  787.           warp.set_beacon_frequency(freq)
  788.           warp.do_jump()
  789.           end
  790.           rs.setOutput(Alarm, false)
  791.           return 0
  792.         end
  793.          
  794.         function JumpToGate()
  795.           Clear()
  796.           ShowTitle("<==== Jump to JumpGate ====>")
  797.           sleep(0.3)
  798.           term.write("Enter jumpgate name: ")
  799.           local name = tostring(read())
  800.           rs.setOutput(Alarm, true)
  801.           if Confirm() then
  802.           rs.setOutput(Alarm, false)
  803.           warp.set_mode(6)
  804.           warp.set_target_jumpgate(name)
  805.           warp.do_jump()
  806.           end
  807.           rs.setOutput(Alarm, false)
  808.           return 0
  809.         end
  810.          
  811.         function SetShipName()
  812.           Clear()
  813.           sleep(0.3)
  814.           ShowTitle("<==== Set ship name ====>")
  815.           term.write("Enter ship name: ")
  816.           SData.Shipname = tostring(read())
  817.           os.setComputerLabel(SData.Shipname)
  818.           warp.set_core_frequency(SData.Shipname)
  819.           SaveData()
  820.           jumping()
  821.         end
  822.          
  823.         function statistic()
  824.           GFront, GRight, GUp = warp.dim_getp()
  825.           GBack, GLeft, GDown = warp.dim_getn()
  826.           IsInHyper = warp.is_in_hyperspace()
  827.           repeat
  828.           X = warp.get_x()
  829.           sleep(0.3)
  830.           until X ~= nil
  831.           Y = warp.get_y()
  832.           Z = warp.get_z()
  833.           Weight = warp.get_ship_size()
  834.           CalcRealDistance()
  835.           Clear()
  836.           ShowInfo()
  837.           term.setCursorPos(1, 15)
  838.           SetColorTitle()
  839.           ShowMenu("D - Dimensions, M - set MainCore, N - Ship name")
  840.           ShowMenu("S - Set Warp Data, J - Jump, G - Jump to JumpGate")
  841.           ShowMenu("B - Jump to Beacon, H -Jump to Hyperspace")
  842.           ShowMenu("C - Summon, X - Shutdown WarpCore and Exit")
  843.           ShowMenu("Press <Left> or <Right> to switch core")
  844.           ShowMenu("Press <Enter> to select core")
  845.           SetColorDeflt()    
  846.           sleep(0.3)
  847.           return 0
  848.         end
  849.          
  850.         function manctrl()
  851.           statistic()  
  852.           local event, keycode = os.pullEvent("key")  
  853.           if keycode == 31 then
  854.             SetDirection()
  855.             SetDistance()
  856.             SaveData()
  857.           elseif keycode == 50 then
  858.             SData.MainCore = SData.CurrentCore
  859.             SaveData()
  860.             statistic()
  861.           elseif keycode == 32 then
  862.             SetDimensions()
  863.             SaveData()
  864.            elseif multicore==true and (keycode == 203 or keycode == 205) then -- Left or right with wcores count > 1
  865.                                 if keycode == 203 then
  866.                                         if curCoreIndex==1 then
  867.                                                 curCoreIndex = #wcores
  868.                                         else
  869.                                                 curCoreIndex = curCoreIndex-1
  870.                                         end
  871.                                 elseif keycode == 205 then -- Right
  872.                                         if curCoreIndex==#wcores then
  873.                                                 curCoreIndex = 1
  874.                                         else
  875.                                                 curCoreIndex = curCoreIndex+1
  876.                                         end
  877.                                 end
  878.                                 warp = wcores[curCoreIndex]["core"]
  879.                                 SData["CurrentCore"] = wcores[curCoreIndex]["ID"]
  880.                                 SaveData()
  881.                                 statistic()
  882.           elseif keycode == 36 then
  883.             rs.setOutput(Alarm, true)
  884.             if Confirm() then
  885.               Warp()
  886.             end
  887.             rs.setOutput(Alarm, false)
  888.           elseif keycode == 46 then
  889.             Summon()
  890.           elseif keycode == 48 then
  891.             JumpToBeacon()
  892.           elseif keycode == 34 then
  893.             JumpToGate()
  894.           elseif keycode == 35 then
  895.             rs.setOutput(Alarm, true)
  896.             if Confirm() then
  897.               rs.setOutput(Alarm, false)
  898.               warp.set_mode(5)
  899.               warp.do_jump()
  900.             end
  901.             rs.setOutput(Alarm, false)
  902.           elseif keycode == 45 then
  903.             warp.set_mode(0)
  904.             Clear()
  905.             print("wish you good")
  906.             os.shutdown()
  907.           elseif keycode == 49 then
  908.             SetShipName()
  909.           end
  910.         end
  911.          
  912.         function jumping()
  913.           screen.clear()
  914.           feelScreen(colors.black,colors.white)
  915.           screen.setBackgroundColor(colors.blue)
  916.           screen.setCursorPos(backbutton_position.x, backbutton_position.y)
  917.           screen.write("BACK")
  918.           feelScreen(colors.black,colors.white)
  919.           screen.setCursorPos(GoJump_position.x , GoJump_position.y)
  920.           screen.setBackgroundColor(colors.cyan)
  921.           screen.write("GO JUMP")
  922.           feelScreen(colors.cyan,colors.white)
  923.           screen.setCursorPos(JumpToCoord_position.x, JumpToCoord_position.y)
  924.           screen.write("JUMP TO")
  925.           if las then
  926.             feelScreen(colors.black,colors.white)
  927.             screen.setCursorPos(automine_position.x , automine_position.y)
  928.             screen.setBackgroundColor(colors.cyan)
  929.             screen.write("AUTOMINE")
  930.          
  931.           end
  932.           feelScreen(colors.black,colors.white)
  933.           modemenu = "jumping"
  934.           SData.modemenu = "jumping"
  935.           SaveData()
  936.           statistic()
  937.           sleep(0.3)
  938.           return 0
  939.         end
  940.          
  941.         function autosum()
  942.           while summonloop do
  943.             local event, command=os.pullEvent("chat_command")
  944.             if (command=="sum1") then
  945.               bridge.clear()
  946.               bridge.addText(6,6,"summoning 1",0x777)
  947.               warp.summon(0)
  948.               bridge.clear()
  949.             end
  950.             if (command=="sum2")    then
  951.               bridge.clear()
  952.               bridge.addText(6,6,"summoning 2",0x777)
  953.               warp.summon(1)
  954.               bridge.clear()
  955.             end
  956.             sleep(3)
  957.           end
  958.           jumping()
  959.         end
  960.          
  961.          
  962.         function shipscan()
  963.           modemenu = "shipscan"
  964.           SData.modemenu = "shipscan"
  965.           SaveData()
  966.           screen.clear()
  967.           feelScreen(colors.black,colors.white)
  968.           screen.setBackgroundColor(colors.blue)
  969.           screen.setCursorPos(backbutton_position.x, backbutton_position.y)
  970.           screen.write("BACK")
  971.           feelScreen(colors.purple,colors.white)
  972.           screen.setCursorPos(shipsc_position.x , shipsc_position.y)
  973.           screen.write("SCAN")
  974.           feelScreen(colors.black,colors.white)
  975.           feelScreen(colors.purple,colors.white)
  976.           screen.setCursorPos(deployship_position.x , deployship_position.y)
  977.           screen.write("DEPLOY")
  978.           feelScreen(colors.black,colors.white)
  979.           feelScreen(colors.purple,colors.white)
  980.           screen.setCursorPos(deployship1_position.x , deployship1_position.y)
  981.           screen.write("1.MinePlat")
  982.           feelScreen(colors.black,colors.white)
  983.           feelScreen(colors.purple,colors.white)
  984.           screen.setCursorPos(deployship2_position.x , deployship2_position.y)
  985.           screen.write("2.PEKAFlower")
  986.           feelScreen(colors.black,colors.white)
  987.           feelScreen(colors.purple,colors.white)
  988.           screen.setCursorPos(deployship3_position.x , deployship3_position.y)
  989.           screen.write("3.TAXI")
  990.           feelScreen(colors.black,colors.white)
  991.           feelScreen(colors.purple,colors.white)
  992.           screen.setCursorPos(deployship4_position.x , deployship4_position.y)
  993.           screen.write("4.M.Ring")
  994.           feelScreen(colors.black,colors.white)
  995.         end
  996.          
  997.         function deployship(schema)              
  998.            print(schema)
  999.             if schema == SData.schematic then
  1000.               if SData.schematic ~= "" then
  1001.                 res,pw = shipscanner.deploy(SData.schematic,0,20,0)
  1002.                 print(res)
  1003.                 print(pw)
  1004.               end
  1005.             else
  1006.               if schema ~= "" then
  1007.                 res,pw = shipscanner.deploy(schema,0,20,0)
  1008.                 print(res)
  1009.                 print(pw)
  1010.               end
  1011.             end
  1012.         end
  1013.          
  1014.         function scship()
  1015.           --print("scship")
  1016.           print("energy level " .. tostring(shipscanner.energy()))
  1017.           feelScreen(colors.black,colors.white)
  1018.           screen.setBackgroundColor(colors.green)
  1019.           screen.setCursorPos(shipsc_position.x, shipsc_position.y+12)
  1020.           screen.write(shipscanner.energy())
  1021.           scanstrings = shipscanner.scan()
  1022.           print(scanstrings)
  1023.           FN =shipscanner.fileName()
  1024.           l = string.find(FN ," ")  
  1025.           while l ~= nil do
  1026.             FN = shipscanner.fileName()
  1027.             l = string.find(FN ," ")
  1028.             sleep(1)
  1029.             print("is scanning")
  1030.           end  
  1031.           print(FN)
  1032.           SData.schematic = FN
  1033.           SaveData()
  1034.           sleep(0.3)
  1035.           return 0
  1036.         end
  1037.          
  1038.         function radarscan()
  1039.           modemenu = "radar"
  1040.           screen.clear()
  1041.          
  1042.           feelScreen(colors.black,colors.white)
  1043.           screen.setBackgroundColor(colors.blue)
  1044.           screen.setCursorPos(backbutton_position.x, backbutton_position.y)
  1045.           screen.write("BACK")  
  1046.           feelScreen(colors.black,colors.white)
  1047.           radiusr = 1000
  1048.           print(radar.pos())
  1049.           RadarEnergyLevel = radar.getEnergyLevel()
  1050.           print(RadarEnergyLevel)
  1051.           if RadarEnergyLevel < radiusr * radiusr then
  1052.             print("Low energy level. Sasaj")
  1053.             screen.setBackgroundColor(colors.red)
  1054.             screen.setCursorPos(1 , backbutton_position.y + 4)
  1055.             screen.write("Low energy ")
  1056.             feelScreen(colors.black,colors.white)
  1057.             sleep(1)
  1058.             mainmenu()
  1059.           end
  1060.           screen.setBackgroundColor(colors.cyan)
  1061.           screen.setCursorPos(1 , backbutton_position.y + 2)
  1062.           screen.write("Energy " .. RadarEnergyLevel)
  1063.           feelScreen(colors.black,colors.white)
  1064.           sc = radar.scanRadius(radiusr)
  1065.           print(sc)
  1066.           --sleep(0.3)
  1067.           print("Scanning...")  
  1068.           rcount = radar.getResultsCount()
  1069.           if rcount > 0 then
  1070.             for i=0, rcount-1 do
  1071.               freq, x, y, z = radar.getResult(i)
  1072.               print("Find: "..freq.." ("..x.. " " .. y .. " " .. z .. ")")
  1073.               screen.setBackgroundColor(colors.blue)
  1074.               screen.setCursorPos(textcenter_position.x, textcenter_position.y -4)
  1075.               screen.write("Find: "..x.. " " .. y .. " " .. z)
  1076.               feelScreen(colors.black,colors.white)
  1077.             end
  1078.             mainmenu()
  1079.           else
  1080.             print("Nothing is found =(")
  1081.             screen.setBackgroundColor(colors.blue)
  1082.             screen.setCursorPos(textcenter_position.x, textcenter_position.y)
  1083.             screen.write("Nothing =(")
  1084.           end
  1085.           feelScreen(colors.black,colors.white)
  1086.           screen.setBackgroundColor(colors.green)
  1087.           screen.setCursorPos(radarscan_position.x , radarscan_position.y)
  1088.           screen.write("START RADAR")
  1089.           feelScreen(colors.black,colors.white)
  1090.           sleep (1)        
  1091.         end
  1092.          
  1093.         function touch_control()
  1094.           local event, side, xPos, yPos = os.pullEvent("monitor_touch")          
  1095.           if modemenu == "mine" then
  1096.             if xPos <= 10 and yPos >= screen_height-2 then
  1097.               startAll()
  1098.             elseif xPos >= stop_all_position.x and yPos >= stop_all_position.y then
  1099.               stopAll()
  1100.             elseif xPos >= lasermode_position.x -2 and xPos <= (lasermode_position.x + 5) and yPos == lasermode_position.y then
  1101.               setlasermode()
  1102.             elseif xPos >= backbutton_position.x  and xPos <= (backbutton_position.x + 10) and yPos == backbutton_position.y then
  1103.               sleep(0.2)
  1104.               mainmenu()
  1105.             end
  1106.             mining()
  1107.             sleep(0.2)
  1108.           elseif modemenu == "jumping" then  
  1109.             if xPos >= backbutton_position.x  and xPos <= (backbutton_position.x + 10) and yPos == backbutton_position.y then
  1110.              mainmenu()      
  1111.             elseif  xPos >= GoJump_position.x -1 and xPos <= GoJump_position.x +6 and yPos == GoJump_position.y then
  1112.               feelScreen(colors.black,colors.white)
  1113.               screen.setCursorPos(GoJump_position.x , GoJump_position.y)
  1114.               screen.setBackgroundColor(colors.green)
  1115.               screen.write("GO JUMP")
  1116.               Warp()  
  1117.               sleep(0.3)
  1118.             elseif  xPos >= automine_position.x -1 and xPos <= automine_position.x +10 and yPos == automine_position.y then
  1119.               if las then
  1120.                 feelScreen(colors.black,colors.white)
  1121.                 screen.setCursorPos(automine_position.x , automine_position.y)
  1122.                 screen.setBackgroundColor(colors.green)
  1123.                 screen.write("AUTOMINE")
  1124.                 sleep(0.3)
  1125.                 startAll()  
  1126.                 automine()
  1127.  
  1128.               end
  1129.             elseif  xPos >= JumpToCoord_position.x -1 and xPos <= JumpToCoord_position.x +6 and yPos == JumpToCoord_position.y then
  1130.               feelScreen(colors.black,colors.white)  
  1131.               SetCoord()  
  1132.               sleep(1)
  1133.             end
  1134.           elseif modemenu == "main" then
  1135.             if xPos >= mining_position.x -1 and xPos <= mining_position.x +10 and yPos == mining_position.y then
  1136.               if las then
  1137.                 mining()
  1138.               end
  1139.             elseif xPos >= jumping_position.x -1 and xPos <= jumping_position.x +10 and yPos == jumping_position.y then
  1140.               jumping()
  1141.             elseif  xPos >= shipscan_position.x -1 and xPos <= shipscan_position.x +10 and yPos == shipscan_position.y then                
  1142.               if shipsc then
  1143.                 shipscan()
  1144.               end
  1145.             elseif  xPos >= radar_position.x -1 and xPos <= radar_position.x +10 and yPos == radar_position.y then    
  1146.               if radar then            
  1147.                 radarscan()
  1148.               end
  1149.             end
  1150.           elseif modemenu == "automine" then
  1151.             if xPos >= backbutton_position.x  and xPos <= (backbutton_position.x + 10) and yPos == backbutton_position.y then
  1152.               stopAll()
  1153.               mainmenu()
  1154.             end
  1155.           elseif modemenu == "shipscan" then
  1156.             if xPos >= shipsc_position.x -1 and xPos <= shipsc_position.x +10 and yPos == shipsc_position.y then
  1157.               scship()      
  1158.             elseif xPos >= deployship_position.x-3  and xPos <= (deployship_position.x + 10) and yPos == deployship_position.y then
  1159.               deployship(SData.schematic)
  1160.             elseif xPos >= deployship1_position.x  and xPos <= (deployship1_position.x + 10) and yPos == deployship1_position.y then
  1161.               schema = "d1404472739316.schematic"
  1162.               deployship(schema)
  1163.             elseif xPos >= deployship2_position.x and xPos <= (deployship2_position.x + 10) and yPos == deployship2_position.y then
  1164.               schema = "default1407225353906.schematic"
  1165.               deployship(schema)
  1166.             elseif xPos >= deployship3_position.x  and xPos <= (deployship3_position.x + 10) and yPos == deployship3_position.y then
  1167.               schema = "taxi1407485902452.schematic"
  1168.               deployship(schema)
  1169.             elseif xPos >= deployship4_position.x  and xPos <= (deployship4_position.x + 10) and yPos == deployship4_position.y then
  1170.               schema = "default1409504631567.schematic"
  1171.               deployship(schema)
  1172.             elseif xPos >= backbutton_position.x  and xPos <= (backbutton_position.x + 10) and yPos == backbutton_position.y then
  1173.               mainmenu()
  1174.             end
  1175.           elseif modemenu == "radar" then
  1176.             if xPos >= radarscan_position.x -1 and xPos <= radarscan_position.x +10 and yPos == radarscan_position.y then
  1177.               feelScreen(colors.black,colors.white)
  1178.               screen.setCursorPos(radarscan_position.x , radarscan_position.y)
  1179.               screen.setBackgroundColor(colors.green)
  1180.               screen.write("START RADAR")
  1181.               sleep(0.3)
  1182.               radarscan()
  1183.             elseif xPos >= backbutton_position.x  and xPos <= (backbutton_position.x + 10) and yPos == backbutton_position.y then
  1184.               mainmenu()
  1185.             end
  1186.           elseif modemenu == "jtc" then
  1187.             if xPos >= backbutton_position.x  and xPos <= (backbutton_position.x + 10) and yPos == backbutton_position.y then
  1188.               SData.autojump = false
  1189.               SaveData()
  1190.               mainmenu()
  1191.             end
  1192.           end
  1193.          
  1194.           sleep(0.3)
  1195.           return 0  
  1196.         end
  1197.          
  1198.         function initwcore()
  1199.           if wcore then
  1200.             print("wcore is present")
  1201.               if mon ~= true then
  1202.                 print "need monitor"
  1203.                 return 0        
  1204.               else        
  1205.                 if fs.exists("shipdata.txt") then
  1206.                   ReadData()        
  1207.                 else
  1208.                   SData = {
  1209.                   Summon = false,
  1210.                   Distance = 1,
  1211.                   Direction = 0,
  1212.                   Shipname = "",
  1213.                   modemenu = "",
  1214.                   lasermode = "",
  1215.                   schematic = "",
  1216.                   CurrentCore = "",
  1217.                   MainCore = "",
  1218.                   autojump = "",
  1219.                   DestCoordX = "",
  1220.                   DestCoordY = "",
  1221.                   DestCoordZ = ""
  1222.                   }
  1223.                 end
  1224.                 SetColorDeflt()
  1225.                 if type(warp) ~= "table" then
  1226.                   ShowWarning("No warpcore controller detected")
  1227.                   os.pullEvent("key")
  1228.                   os.shutdown()
  1229.                 end
  1230.                 if SData.Shipname == "" then
  1231.                   SetShipName()
  1232.                 end
  1233.                 if SData.Summon then
  1234.                   warp.summon_all()
  1235.                 end
  1236.                 warp.set_mode(1)
  1237.                 if SData.Summon then
  1238.                   SData.Summon = false
  1239.                   SaveData()
  1240.                 end
  1241.                 if SData.autojump ==true then
  1242.                   statistic()
  1243.                   autojumpStatistic()
  1244.                   if IsInHyper then
  1245.                     JumpInHyper()
  1246.                   else
  1247.                     JumpToCoord()
  1248.                   end
  1249.                 end
  1250.                 if SData.lasermode ~= "mine" or  SData.lasermode ~= "quarry"  then
  1251.                   lasermode = "mine"
  1252.                   SData.lasermode  = "mine"
  1253.                   SaveData()      
  1254.                 end
  1255.                 lasermode = SData.lasermode
  1256.                 if SData.modemenu == "jumping" then
  1257.                   modemenu = "jumping"
  1258.                   jumping()
  1259.                 elseif SData.modemenu == "mine" then
  1260.                   modemenu = "mine"
  1261.                   mining()
  1262.                 elseif SData.modemenu == "automine" then
  1263.                   modemenu = "automine"
  1264.                   startAll()  
  1265.                   automine()
  1266.                 elseif SData.modemenu == "shipscan" then
  1267.                   modemenu = "shipscan"
  1268.                   shipscan()
  1269.                 else
  1270.                   modemenu = "main"
  1271.                   mainmenu()
  1272.                 end
  1273.               end
  1274.           else
  1275.             print ("need wcore controller")
  1276.           end  
  1277.         end
  1278.          
  1279.         function init()
  1280.           --sleep(5)
  1281.           local periList = peripheral.getNames()
  1282.           for i = 1, #periList do
  1283.             device=peripheral.getType(periList[i])
  1284.             print(device)
  1285.             sleep(0.1)
  1286.             if device == "monitor" then
  1287.               mon = true    
  1288.               screen = peripheral.wrap(periList[i])
  1289.               screen.setTextScale(MON_SCALE)
  1290.               screen_width, screen_height = screen.getSize()
  1291.               print("screensize:" .. tostring(screen_width) .."x".. tostring(screen_height))
  1292.               setScreenPosition()
  1293.             elseif device == "mininglaser" then
  1294.               las = true
  1295.               table.insert(lazors, periList[i])
  1296.             elseif device == "warpcore" then
  1297.                     nc = 1
  1298.                     if wcore == true then                  
  1299.                             multicore = true
  1300.                             sleep(1)
  1301.                             nc = nc+1
  1302.                             print("multicore")
  1303.                             sleep(0.1)
  1304.                             table.insert(wcores,{ID = nc,core = peripheral.wrap(periList[i])})
  1305.                             warp = wcores[nc]["core"]
  1306.                             warp.set_mode(1)
  1307.                     else
  1308.                                     wcore = true  
  1309.                                     warp = peripheral.wrap(periList[i])
  1310.                                     table.insert(wcores,{ID=nc,core = peripheral.wrap(periList[i])})
  1311.                                     warp.set_mode(1)
  1312.                     end            
  1313.                             curCoreIndex = #wcores
  1314.                            
  1315.                 wcores[#wcores]["core"].set_mode(1)
  1316.             elseif device == "openperipheral_glassesbridge" then
  1317.               bridge = peripheral.wrap(periList[i])
  1318.             elseif device == "modem" then
  1319.               m = true
  1320.               m = peripheral.wrap(periList[i])
  1321.             elseif device == "shipscanner" then
  1322.               shipsc = true
  1323.               shipscanner = peripheral.wrap(periList[i])        
  1324.             elseif device == "radar" then
  1325.               rad = true
  1326.               radar = peripheral.wrap(periList[i])          
  1327.             end
  1328.           end
  1329.         end
  1330.          
  1331.         function mainmenu()
  1332.           modemenu = "main"
  1333.           SData.modemenu = "main"
  1334.           SaveData()
  1335.           screen.clear()
  1336.           feelScreen(colors.orange,colors.cyan)
  1337.           screen.setCursorPos(title_position.x, title_position.y)
  1338.           screen.write("kopro-OS")
  1339.           screen.setCursorPos(title_position.x, title_position.y+1)
  1340.           screen.write("ver. 0.004")
  1341.           if las == true then
  1342.             feelScreen(colors.cyan,colors.white)
  1343.             screen.setCursorPos(mining_position.x, mining_position.y)
  1344.             screen.write("MINE")
  1345.           end
  1346.           if  shipsc == true then
  1347.             feelScreen(colors.cyan,colors.white)
  1348.             screen.setCursorPos(shipscan_position.x, shipscan_position.y)
  1349.             screen.write("SHIPSCAN")
  1350.           end
  1351.           feelScreen(colors.cyan,colors.white)
  1352.           screen.setCursorPos(jumping_position.x, jumping_position.y)
  1353.           screen.write("JUMP")  
  1354.  
  1355.           if rad == true then
  1356.             feelScreen(colors.cyan,colors.white)  
  1357.             screen.setCursorPos(radar_position.x, radar_position.y)
  1358.             screen.write("RADAR")
  1359.           end
  1360.           feelScreen(colors.orange,colors.white)
  1361.           sleep(0.5)            
  1362.           return 0  
  1363.         end
  1364.          
  1365.         init()
  1366.         initwcore()
  1367.          
  1368.         while true do
  1369.           if modemenu == "mine" then
  1370.             parallel.waitForAny( touch_control,mining)
  1371.           elseif modemenu == "automine" then
  1372.            parallel.waitForAny( touch_control,automine)
  1373.           elseif modemenu == "jumping" then
  1374.            parallel.waitForAny(touch_control,manctrl)
  1375.           elseif modemenu == "jtc" then
  1376.            parallel.waitForAny(touch_control,SetCoord)
  1377.           elseif modemenu == "main" then
  1378.            parallel.waitForAny( touch_control,mainmenu)
  1379.           elseif modemenu == "shipscan" then
  1380.            parallel.waitForAny( touch_control)
  1381.           elseif modemenu == "radar" then
  1382.            parallel.waitForAny( touch_control,radarscan)
  1383.           end    
  1384.         end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement