Advertisement
Guest User

kopro-OS 0.007

a guest
Sep 16th, 2014
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 43.80 KB | None | 0 0
  1. MON_SCALE  = 0.5
  2. MIN_OFFSET = 2
  3. MAX_OFFSET = 250
  4. lazors     = {}
  5. states     = {}
  6. wcores     = {}
  7. camers     = {}
  8. heights    = {}
  9. step       = 12
  10. xOffset    = 2
  11. yOffset    = 4
  12. offset     = MIN_OFFSET
  13. lasN = 0
  14. print("loading...")
  15. sleep(2)
  16. Alarm = "top"
  17. Style = {
  18. CDeflt = colors.white,
  19. BGDeflt = colors.blue,
  20. CTitle = colors.black,
  21. BGTitle = colors.cyan,
  22. CWarn = colors.white,
  23. BGWarn = colors.red
  24. }
  25.  
  26. function setScreenPosition()
  27.   backbutton_position = {x = screen_width/2, y = 1}
  28.   start_all_position = {x = 1, y = screen_height-2}
  29.   stop_all_position  = {x = screen_width - 3, y = screen_height-2}
  30.   lasermode_position = {x = math.floor(screen_width/2 - 2), y = screen_height-4}
  31.   mining_position = {x=screen_width/2 - 2, y = screen_height/2-4}
  32.   jumping_position  = {x=screen_width/2 - 2, y = screen_height/2-2}
  33.   GoJump_position = {x=screen_width/2 - 3, y = screen_height/2}
  34.   JumpToCoord_position = {x=screen_width/2 - 3, y = screen_height/2+4}
  35.   automine_position = {x=screen_width/2 - 3, y = screen_height/2+2}
  36.   shipscan_position = {x=screen_width/2 - 3, y = screen_height/2+2}          
  37.   shipsc_position = {x=screen_width/2 - 2, y = screen_height/2-6}
  38.   deployship_position = {x=screen_width/2 - 3, y = screen_height/2-4}
  39.   deployship1_position = {x=2, y = screen_height/2-2}
  40.   deployship2_position = {x=2, y = screen_height/2}
  41.   deployship3_position = {x=2, y = screen_height/2+2}
  42.   deployship4_position = {x=2, y = screen_height/2+4}
  43.   radar_position = {x=screen_width/2 - 2, y = screen_height/2}
  44.   radarscan_position = {x=2, y = screen_height-2}
  45.   cloak_position = {x=5, y = screen_height/2+4}
  46.   camera_position = {x=5, y = screen_height/2+6}
  47.   title_position  = {x=1, y = 1}
  48.   textcenter_position = {x=1, y = screen_height/2}
  49.  
  50. end
  51.  
  52. function resetColorsScreen()
  53.   screen.setBackgroundColor(colors.black)
  54.   screen.setTextColor(colors.white)
  55. end
  56.  
  57. function setlasermode()
  58.   if lasermode == "mine" then
  59.     lasermode = "quarry"
  60.     print(lasermode)
  61.     SData.lasermode = lasermode
  62.     SaveData()
  63.   else
  64.     lasermode = "mine"
  65.     print(lasermode)
  66.     SData.lasermode = lasermode
  67.     SaveData()
  68.   end
  69.   minestatistic()
  70. end  
  71.  
  72. function start(laserNUM)
  73.   print("Calling laser "..lazors[laserNUM].." for start")
  74.   setOffset(laserNUM, offset)
  75.   m.callRemote(lazors[laserNUM], lasermode)
  76. end
  77.  
  78. function startAll()
  79.   for i =1 ,#lazors do
  80.    start(i)
  81.   end
  82. end
  83.  
  84. function stop(laserNUM)
  85.   print("Calling laser "..lazors[laserNUM].." for stop")
  86.   m.callRemote(lazors[laserNUM], "stop")
  87. end
  88.  
  89. function stopAll()
  90.   for i = 1 ,#lazors do
  91.    stop(i)
  92.   end
  93. end
  94.  
  95. function setOffset(laserNUM, offset)
  96.   m.callRemote(lazors[laserNUM], "offset", offset)
  97. end
  98.  
  99. function minestatistic()
  100.   screen.clear()
  101.   feelScreen(colors.black,colors.white)
  102.   qml = 0
  103.   lay = 0
  104.   lux = 0
  105.   min = 0
  106.   screen.setCursorPos(1 , 3)
  107.   screen.setBackgroundColor(colors.cyan)
  108.   screen.write( "LASERS      " .. #lazors)
  109.   feelScreen(colors.black,colors.white)
  110.   screen.setBackgroundColor(colors.blue)
  111.   screen.setCursorPos(start_all_position.x ,start_all_position.y)
  112.   if modemenu == "automine" then
  113.     screen.write("AUTOMINE")
  114.   else
  115.     screen.write("GO")
  116.     screen.setCursorPos(stop_all_position.x, stop_all_position.y)
  117.     screen.write("xXx")
  118.   end
  119.   screen.setBackgroundColor(colors.green)
  120.   screen.setCursorPos(lasermode_position.x, lasermode_position.y)
  121.   screen.write(lasermode)
  122.   feelScreen(colors.black,colors.white)
  123.   screen.setBackgroundColor(colors.blue)
  124.   screen.setCursorPos(backbutton_position.x, backbutton_position.y)
  125.   screen.write("BACK")
  126.   feelScreen(colors.black,colors.white)
  127.   for a = 1,#lazors do
  128.     mState, mEnergy, mLayer, mValuablesMined, mValuablesInLayer = m.callRemote(lazors[a], "state")
  129.     print(mState)  
  130.     if mState ~= "not mining"  then                
  131.       qml= qml+1
  132.       lay = lay + mLayer
  133.       lux = lux + mValuablesMined
  134.       min = min + mValuablesInLayer
  135.       if mEnergy == 0 then
  136.         screen.setCursorPos(1 , 11)
  137.         screen.setBackgroundColor(colors.red)
  138.         screen.write( "low energy L" ..a)
  139.         feelScreen(colors.black,colors.white)
  140.       end                
  141.     end
  142.   end  
  143.   screen.setCursorPos(1 , 5)
  144.   screen.setBackgroundColor(colors.green)
  145.   screen.write( "IN WORK     " .. qml)
  146.   feelScreen(colors.black,colors.white)  
  147.   print(qml)
  148.   if qml > 0 then
  149.     mLay = lay/qml
  150.     mLux = lux/qml
  151.     mmin = min*10/qml
  152.   end
  153.   screen.setCursorPos(1 , 7)
  154.   screen.setBackgroundColor(colors.blue)
  155.   screen.write( "LAYER    " .. tostring(mLay))
  156.   feelScreen(colors.black,colors.white)
  157.   screen.setCursorPos(1 , 9)
  158.   screen.setBackgroundColor(colors.blue)
  159.   screen.write( "MINE  " .. tostring(lux) .."/" .. tostring(mmin))
  160.   feelScreen(colors.black,colors.white)
  161.   sleep(1)
  162.  
  163. end
  164.  
  165. function mining()
  166.   modemenu = "mine"
  167.   SData.modemenu = "mine"  
  168.   SaveData()  
  169.   minestatistic()
  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.   SData.modemenu = "jtc"
  472.   SaveData()
  473.   screen.clear()
  474.   screen.setCursorPos(1 , 7)
  475.   screen.setBackgroundColor(colors.green)
  476.   screen.write( "set coord" )
  477.   screen.setCursorPos(1 , 8)
  478.   screen.write( "on comp" )
  479.   sleep(2)                    
  480.   if SData.autojump == true then
  481.     JumpToCoord()
  482.   end
  483.   Clear()          
  484.   ShowTitle("<====  Set DestCoords  ====>")          
  485.   term.write(" X ("..tostring(SData.DestCoordX)..") : ")
  486.   SData.DestCoordX = tonumber(read())
  487.   term.write(" Z ("..tostring(SData.DestCoordZ)..") : ")
  488.   SData.DestCoordZ = tonumber(read())
  489.   SaveData()
  490.  
  491.   sleep(0.3)
  492.   if Confirm() then
  493.     JumpToCoord()
  494.   end
  495. end
  496.  
  497. function GoToSpace()
  498.   autojumpStatistic()
  499.   if warp.is_in_space() then
  500.     SData.DestCoordY = 250
  501.     SData.Direction = 1
  502.     GetMinimumDistance()            
  503.     SaveData()
  504.     DY  = math.abs(SData.DestCoordY - Y)
  505.     if DY > MinimumDistance then            
  506.       if SData.DestCoordY>Y then
  507.         SData.Direction = 1
  508.       elseif SData.DestCoordY<Y then
  509.         SData.Direction = 0
  510.       end
  511.       Dist = DY
  512.       GetMinimumDistance()
  513.       MaxDist = MinimumDistance+127            
  514.       print(MaxDist .. " MaxDist")
  515.       print(Dist .. " Dist")
  516.       if Dist>MaxDist then
  517.         SData.Distance = MaxDist
  518.       else
  519.         SData.Distance = Dist
  520.       end
  521.       SaveData()
  522.       Warp()
  523.       sleep(10)
  524.     end
  525.   elseif not IsInHyper then
  526.     SData.Direction = 1
  527.     GetMinimumDistance()
  528.     MaxDist = MinimumDistance+127  
  529.     SData.Distance = MaxDist
  530.     SaveData()
  531.     Warp()
  532.     sleep(10)            
  533.   end
  534. end
  535.  
  536.  
  537. function JumpInHyper()
  538.   autojumpStatistic()
  539.   if IsInHyper then
  540.     print("in Hyperspace")
  541.     DX  = math.abs(SData.DestCoordX - X)
  542.     print(DX .. " alldistX")
  543.     DZ  = math.abs(SData.DestCoordZ - Z)
  544.     print(DZ .. " alldistZ")
  545.     SData.Direction = 255
  546.     GetMinimumDistance()
  547.  
  548.     if DX > 100 then            
  549.       if SData.DestCoordX>X then
  550.         SData.Direction = 255
  551.       elseif SData.DestCoordX<X then
  552.         SData.Direction = 90
  553.       end
  554.       Dist = DX
  555.       GetMinimumDistance()
  556.       MaxDist = MinimumDistance+127            
  557.       print(MaxDist .. " MaxDist")
  558.       print(Dist .. " Dist")
  559.       if Dist>MaxDist*100 then
  560.         SData.Distance = MaxDist
  561.       else
  562.         SData.Distance = math.floor(Dist/100)
  563.       end
  564.       SaveData()
  565.       Warp()
  566.       sleep(10)
  567.     else
  568.       SData.Direction = 180
  569.       GetMinimumDistance()
  570.       if DZ > 100 then
  571.         if SData.DestCoordZ>Z then
  572.           SData.Direction = 180
  573.         elseif SData.DestCoordZ<Z then
  574.           SData.Direction = 0
  575.         end            
  576.         Dist = DZ
  577.         GetMinimumDistance()
  578.         MaxDist = MinimumDistance + 127
  579.         print(MaxDist .. " MaxDist")
  580.         print(Dist .. " Dist")
  581.         if Dist>MaxDist*100 then
  582.           SData.Distance = MaxDist
  583.         else
  584.           SData.Distance = math.floor(Dist/100)
  585.         end
  586.         SaveData()
  587.         Warp()
  588.         sleep(10)
  589.       else
  590.         rs.setOutput(Alarm, false)
  591.         warp.set_mode(5)
  592.         warp.do_jump()
  593.         sleep (10)
  594.       end    
  595.     end
  596.   else
  597.     print("go to Hyperspace")
  598.     rs.setOutput(Alarm, false)
  599.     warp.set_mode(5)
  600.     warp.do_jump()
  601.     sleep (10)
  602.   end        
  603. end
  604.  
  605.  
  606. function JumpToCoord()
  607.   autojumpStatistic()
  608.   SData.autojump = true
  609.   SaveData()
  610.   GoToSpace()
  611.   print(SData.DestCoordX)          
  612.   DX  = math.abs(SData.DestCoordX - X)          
  613.   DZ  = math.abs(SData.DestCoordZ - Z)          
  614.   SData.Direction = 255
  615.   GetMinimumDistance()  
  616.   MaxDist = MinimumDistance+127
  617.   MAXDX =MaxDist*5
  618.   if DX>MAXDX or DZ>MAXDX then
  619.     print(MAXDX .. " to Hyperspace")
  620.     JumpInHyper()
  621.   else
  622.     if IsInHyper then
  623.       rs.setOutput(Alarm, false)
  624.       warp.set_mode(5)
  625.       warp.do_jump()
  626.     end
  627.   end  
  628.   if DX > MinimumDistance then            
  629.     if SData.DestCoordX>X then
  630.       SData.Direction = 255
  631.     elseif SData.DestCoordX<X then
  632.       SData.Direction = 90
  633.     end
  634.     Dist = DX
  635.     GetMinimumDistance()
  636.     MaxDist = MinimumDistance+127        
  637.     if Dist>MaxDist then
  638.       SData.Distance = MaxDist
  639.     else
  640.       SData.Distance = Dist
  641.     end
  642.     for i = 0,5 do
  643.       print("autojump in " .. 5-i .. "sec.")
  644.       sleep(1)  
  645.       i = i+1
  646.     end
  647.     SaveData()
  648.     Warp()
  649.     sleep(10)
  650.   else
  651.     SData.Direction = 180
  652.     GetMinimumDistance()
  653.     if DZ > MinimumDistance then
  654.       if SData.DestCoordZ>Z then
  655.         SData.Direction = 180
  656.       elseif SData.DestCoordZ<Z then
  657.         SData.Direction = 0
  658.       end            
  659.       Dist = DZ
  660.       GetMinimumDistance()
  661.       MaxDist = MinimumDistance + 127
  662.       if Dist>MaxDist then
  663.         SData.Distance = MaxDist
  664.       else
  665.         SData.Distance = Dist
  666.       end
  667.       for i = 0,5 do
  668.         print("autojump in " .. 5-i .. "sec.")
  669.         sleep(1)  
  670.         i = i+1
  671.       end
  672.       SaveData()
  673.       Warp()
  674.       sleep(10)
  675.     else
  676.       SData.autojump = false  
  677.       SaveData()          
  678.     end
  679.   end
  680. end
  681.  
  682.  
  683. function SetDistance()
  684.   Clear()
  685.   ShowTitle("<====  Set distance  ====>")
  686.   SData.Distance = 0
  687.   GetMinimumDistance()
  688.   CalcRealDistance()
  689.   MaximumDistance = MinimumDistance + 127
  690.   if IsInHyper then
  691.     term.write("Distance * 100 (min "..MinimumDistance..", max "..MaximumDistance.."): ")
  692.   else
  693.     term.write("Distance (min "..MinimumDistance..", max "..MaximumDistance.."): ")
  694.   end
  695.   sleep(0.3)
  696.   SData.Distance = tonumber(read())
  697.   if SData.Distance == nil then SData.Distance = 1 end
  698.   if SData.Distance < MinimumDistance or SData.Distance > MaximumDistance then
  699.     SData.Distance = 1
  700.     ShowWarning("Wrong distance. Try again.")
  701.     os.pullEvent("key")
  702.     CalcRealDistance()
  703.   else
  704.     if not IsInHyper then
  705.       SData.Distance = SData.Distance - RealDistance
  706.     end
  707.     warp.set_distance(SData.Distance)
  708.     CalcRealDistance()
  709.   end
  710.   return 0
  711. end
  712.  
  713. function SetDirection()
  714.   local drun = true
  715.   while(drun) do
  716.   Clear()
  717.   ShowTitle("<==== Set direction ====>")
  718.   ShowDirection()
  719.   term.setCursorPos(1, 16)
  720.   SetColorTitle()
  721.   ShowMenu("Use directional keys")
  722.   ShowMenu("W/S keys for Up/Down")
  723.   ShowMenu("Enter - confirm")
  724.   SetColorDeflt()
  725.   local event, keycode = os.pullEvent("key")
  726.   if keycode == 200 then
  727.     SData.Direction = 0
  728.   elseif keycode == 17 then
  729.     SData.Direction = 1
  730.   elseif keycode == 203 then
  731.     SData.Direction = 90
  732.   elseif keycode == 205 then
  733.     SData.Direction = 255
  734.   elseif keycode == 208 then
  735.     SData.Direction = 180
  736.   elseif keycode == 31 then
  737.     SData.Direction = 2
  738.   elseif keycode == 28 then
  739.     drun = false
  740.   end
  741.   end
  742. end
  743.  
  744. function SetDimensions()
  745.   Clear()
  746.   sleep(0.3)
  747.   ShowTitle("<==== Set dimensions ====>")
  748.   term.write(" Front ("..GFront..") : ")
  749.   GFront = tonumber(read())
  750.   term.write(" Right ("..GRight..") : ")
  751.   GRight = tonumber(read())
  752.   term.write(" Up    ("..GUp..") : ")
  753.   GUp = tonumber(read())
  754.   term.write(" Back  ("..GBack..") : ")
  755.   GBack = tonumber(read())
  756.   term.write(" Left  ("..GLeft..") : ")
  757.   GLeft = tonumber(read())
  758.   term.write(" Down  ("..GDown..") : ")
  759.   GDown = tonumber(read())
  760.   term.write("Setting dimensions...")
  761.   warp.dim_setp(GFront, GRight, GUp)
  762.   warp.dim_setn(GBack, GLeft, GDown)
  763.   jumping()
  764. end
  765.  
  766. function Summon()
  767.   Clear()
  768.   ShowTitle("<==== Summon players ====>")
  769.   local players = Explode(",", warp.get_attached_players())
  770.   for i = 1, #players do
  771.     Show(i..". "..players[i])
  772.   end
  773.   SetColorTitle()
  774.   ShowMenu("Enter player number")
  775.   ShowMenu("or press enter to summon everyone")
  776.   SetColorDeflt()
  777.   sleep(0.3)
  778.   term.write(":")
  779.   local input = read()
  780.   if input == "" then
  781.     warp.summon_all()
  782.   else
  783.     input = tonumber(input)
  784.     warp.summon(input - 1)
  785.   end
  786.   return 0
  787. end
  788.  
  789. function JumpToBeacon()
  790.   Clear()
  791.   ShowTitle("<==== Jump to beacon ====>")
  792.   sleep(0.3)
  793.   term.write("Enter beacon frequency: ")
  794.   local freq = tostring(read())
  795.   rs.setOutput(Alarm, true)
  796.   if Confirm() then
  797.   rs.setOutput(Alarm, false)
  798.   warp.set_mode(4)
  799.   warp.set_beacon_frequency(freq)
  800.   warp.do_jump()
  801.   end
  802.   rs.setOutput(Alarm, false)
  803.   return 0
  804. end
  805.  
  806. function JumpToGate()
  807.   Clear()
  808.   ShowTitle("<==== Jump to JumpGate ====>")
  809.   sleep(0.3)
  810.   term.write("Enter jumpgate name: ")
  811.   local name = tostring(read())
  812.   rs.setOutput(Alarm, true)
  813.   if Confirm() then
  814.   rs.setOutput(Alarm, false)
  815.   warp.set_mode(6)
  816.   warp.set_target_jumpgate(name)
  817.   warp.do_jump()
  818.   end
  819.   rs.setOutput(Alarm, false)
  820.   return 0
  821. end
  822.  
  823. function SetShipName()
  824.   Clear()
  825.   sleep(0.3)
  826.   ShowTitle("<==== Set ship name ====>")
  827.   term.write("Enter ship name: ")
  828.   SData.Shipname = tostring(read())
  829.   os.setComputerLabel(SData.Shipname)
  830.   warp.set_core_frequency(SData.Shipname)
  831.   SaveData()
  832.   jumping()
  833. end
  834.  
  835. function statistic()
  836.   GFront, GRight, GUp = warp.dim_getp()
  837.   GBack, GLeft, GDown = warp.dim_getn()
  838.   IsInHyper = warp.is_in_hyperspace()
  839.   repeat
  840.   X = warp.get_x()
  841.   sleep(0.3)
  842.   until X ~= nil
  843.   Y = warp.get_y()
  844.   Z = warp.get_z()
  845.   Weight = warp.get_ship_size()
  846.   CalcRealDistance()
  847.   Clear()
  848.   ShowInfo()
  849.   term.setCursorPos(1, 15)
  850.   SetColorTitle()
  851.   ShowMenu("D - Dimensions, M - set MainCore, N - Ship name")
  852.   ShowMenu("S - Set Warp Data, J - Jump, G - Jump to JumpGate")
  853.   ShowMenu("B - Jump to Beacon, H -Jump to Hyperspace")
  854.   ShowMenu("C - Summon, X - Shutdown WarpCore and Exit")
  855.   ShowMenu("Press <Left> or <Right> to switch core")
  856.   ShowMenu("Press <Enter> to select core")
  857.   SetColorDeflt()    
  858.   sleep(0.3)
  859.   return 0
  860. end
  861.  
  862. function manctrl()
  863.   statistic()  
  864.   local event, keycode = os.pullEvent("key")  
  865.   if keycode == 31 then
  866.     SetDirection()
  867.     SetDistance()
  868.     SaveData()
  869.   elseif keycode == 50 then
  870.     SData.MainCore = SData.CurrentCore
  871.     SaveData()
  872.     statistic()
  873.   elseif keycode == 32 then
  874.     SetDimensions()
  875.     SaveData()
  876.    elseif multicore==true and (keycode == 203 or keycode == 205) then -- Left or right with wcores count > 1
  877.       if keycode == 203 then
  878.               if curCoreIndex==1 then
  879.                       curCoreIndex = #wcores
  880.               else
  881.                       curCoreIndex = curCoreIndex-1
  882.               end
  883.       elseif keycode == 205 then -- Right
  884.               if curCoreIndex==#wcores then
  885.                       curCoreIndex = 1
  886.               else
  887.                       curCoreIndex = curCoreIndex+1
  888.               end
  889.       end
  890.       warp = wcores[curCoreIndex]["core"]
  891.       SData["CurrentCore"] = wcores[curCoreIndex]["ID"]
  892.       SaveData()
  893.       statistic()
  894.   elseif keycode == 36 then
  895.     rs.setOutput(Alarm, true)
  896.     if Confirm() then
  897.       Warp()
  898.     end
  899.     rs.setOutput(Alarm, false)
  900.   elseif keycode == 46 then
  901.     Summon()
  902.   elseif keycode == 48 then
  903.     JumpToBeacon()
  904.   elseif keycode == 34 then
  905.     JumpToGate()
  906.   elseif keycode == 35 then
  907.     rs.setOutput(Alarm, true)
  908.     if Confirm() then
  909.       rs.setOutput(Alarm, false)
  910.       warp.set_mode(5)
  911.       warp.do_jump()
  912.     end
  913.     rs.setOutput(Alarm, false)
  914.   elseif keycode == 45 then
  915.     warp.set_mode(0)
  916.     Clear()
  917.     print("wish you good")
  918.     os.shutdown()
  919.   elseif keycode == 49 then
  920.     SetShipName()
  921.   end
  922. end
  923.  
  924. function jumping()
  925.   screen.clear()
  926.   feelScreen(colors.black,colors.white)
  927.   screen.setBackgroundColor(colors.blue)
  928.   screen.setCursorPos(backbutton_position.x, backbutton_position.y)
  929.   screen.write("BACK")
  930.   feelScreen(colors.black,colors.white)
  931.   screen.setCursorPos(GoJump_position.x , GoJump_position.y)
  932.   screen.setBackgroundColor(colors.cyan)
  933.   screen.write("GO JUMP")
  934.   feelScreen(colors.cyan,colors.white)
  935.   screen.setCursorPos(JumpToCoord_position.x, JumpToCoord_position.y)
  936.   screen.write("JUMP TO")
  937.   if las then
  938.     feelScreen(colors.black,colors.white)
  939.     screen.setCursorPos(automine_position.x , automine_position.y)
  940.     screen.setBackgroundColor(colors.cyan)
  941.     screen.write("AUTOMINE")
  942.   end
  943.   feelScreen(colors.black,colors.white)
  944.   modemenu = "jumping"
  945.   SData.modemenu = "jumping"
  946.   SaveData()
  947.   statistic()
  948.   sleep(0.3)
  949.   return 0
  950. end
  951.  
  952. function autosum()
  953.   while summonloop do
  954.     local event, command=os.pullEvent("chat_command")
  955.     if (command=="sum1") then
  956.       bridge.clear()
  957.       bridge.addText(6,6,"summoning 1",0x777)
  958.       warp.summon(0)
  959.       bridge.clear()
  960.     end
  961.     if (command=="sum2")    then
  962.       bridge.clear()
  963.       bridge.addText(6,6,"summoning 2",0x777)
  964.       warp.summon(1)
  965.       bridge.clear()
  966.     end
  967.     sleep(3)
  968.   end
  969.   jumping()
  970. end
  971.  
  972.  
  973. function shipscan()
  974.   modemenu = "shipscan"
  975.   SData.modemenu = "shipscan"
  976.   SaveData()
  977.   screen.clear()
  978.   feelScreen(colors.black,colors.white)
  979.   screen.setBackgroundColor(colors.blue)
  980.   screen.setCursorPos(backbutton_position.x, backbutton_position.y)
  981.   screen.write("BACK")
  982.   feelScreen(colors.purple,colors.white)
  983.   screen.setCursorPos(shipsc_position.x , shipsc_position.y)
  984.   screen.write("SCAN")
  985.   feelScreen(colors.black,colors.white)
  986.   feelScreen(colors.purple,colors.white)
  987.   screen.setCursorPos(deployship_position.x , deployship_position.y)
  988.   screen.write("DEPLOY")
  989.   feelScreen(colors.black,colors.white)
  990.   feelScreen(colors.purple,colors.white)
  991.   screen.setCursorPos(deployship1_position.x , deployship1_position.y)
  992.   screen.write("1.MinePlat")
  993.   feelScreen(colors.black,colors.white)
  994.   feelScreen(colors.purple,colors.white)
  995.   screen.setCursorPos(deployship2_position.x , deployship2_position.y)
  996.   screen.write("2.PEKAFlower")
  997.   feelScreen(colors.black,colors.white)
  998.   feelScreen(colors.purple,colors.white)
  999.   screen.setCursorPos(deployship3_position.x , deployship3_position.y)
  1000.   screen.write("3.TAXI")
  1001.   feelScreen(colors.black,colors.white)
  1002.   feelScreen(colors.purple,colors.white)
  1003.   screen.setCursorPos(deployship4_position.x , deployship4_position.y)
  1004.   screen.write("4.M.Ring")
  1005.   feelScreen(colors.black,colors.white)
  1006. end
  1007.  
  1008. function deployship(schema)              
  1009.    print(schema)
  1010.     if schema == SData.schematic then
  1011.       if SData.schematic ~= "" then
  1012.         res,pw = shipscanner.deploy(SData.schematic,0,20,0)
  1013.         print(res)
  1014.         print(pw)
  1015.       end
  1016.     else
  1017.       if schema ~= "" then
  1018.         res,pw = shipscanner.deploy(schema,0,20,0)
  1019.         print(res)
  1020.         print(pw)
  1021.       end
  1022.     end
  1023. end
  1024.  
  1025. function scship()
  1026.   --print("scship")
  1027.   print("energy level " .. tostring(shipscanner.energy()))
  1028.   feelScreen(colors.black,colors.white)
  1029.   screen.setBackgroundColor(colors.green)
  1030.   screen.setCursorPos(shipsc_position.x, shipsc_position.y+12)
  1031.   screen.write(shipscanner.energy())
  1032.   scanstrings = shipscanner.scan()
  1033.   print(scanstrings)
  1034.   FN =shipscanner.fileName()
  1035.   l = string.find(FN ," ")  
  1036.   while l ~= nil do
  1037.     FN = shipscanner.fileName()
  1038.     l = string.find(FN ," ")
  1039.     sleep(1)
  1040.     print("is scanning")
  1041.   end  
  1042.   print(FN)
  1043.   SData.schematic = FN
  1044.   SaveData()
  1045.   sleep(0.3)
  1046.   return 0
  1047. end
  1048.  
  1049. function radarscan()
  1050.   modemenu = "radar"
  1051.   screen.clear()
  1052.  
  1053.   feelScreen(colors.black,colors.white)
  1054.   screen.setBackgroundColor(colors.blue)
  1055.   screen.setCursorPos(backbutton_position.x, backbutton_position.y)
  1056.   screen.write("BACK")  
  1057.   feelScreen(colors.black,colors.white)
  1058.   radiusr = 1000
  1059.   print(radar.pos())
  1060.   RadarEnergyLevel = radar.getEnergyLevel()
  1061.   print(RadarEnergyLevel)
  1062.   if RadarEnergyLevel < radiusr * radiusr then
  1063.     print("Low energy level. Sasaj")
  1064.     screen.setBackgroundColor(colors.red)
  1065.     screen.setCursorPos(1 , backbutton_position.y + 4)
  1066.     screen.write("Low energy ")
  1067.     feelScreen(colors.black,colors.white)
  1068.     sleep(1)
  1069.     mainmenu()
  1070.   end
  1071.   screen.setBackgroundColor(colors.cyan)
  1072.   screen.setCursorPos(1 , backbutton_position.y + 2)
  1073.   screen.write("Energy " .. RadarEnergyLevel)
  1074.   feelScreen(colors.black,colors.white)
  1075.   sc = radar.scanRadius(radiusr)
  1076.   print(sc)
  1077.   --sleep(0.3)
  1078.   print("Scanning...")  
  1079.   rcount = radar.getResultsCount()
  1080.   if rcount > 0 then
  1081.     for i=0, rcount-1 do
  1082.       freq, x, y, z = radar.getResult(i)
  1083.       print("Find: "..freq.." ("..x.. " " .. y .. " " .. z .. ")")
  1084.       screen.setBackgroundColor(colors.blue)
  1085.       screen.setCursorPos(textcenter_position.x, textcenter_position.y -4)
  1086.       screen.write("Find: "..x.. " " .. y .. " " .. z)
  1087.       feelScreen(colors.black,colors.white)
  1088.     end
  1089.     mainmenu()
  1090.   else
  1091.     print("Nothing is found =(")
  1092.     screen.setBackgroundColor(colors.blue)
  1093.     screen.setCursorPos(textcenter_position.x, textcenter_position.y)
  1094.     screen.write("Nothing =(")
  1095.   end
  1096.   feelScreen(colors.black,colors.white)
  1097.   screen.setBackgroundColor(colors.green)
  1098.   screen.setCursorPos(radarscan_position.x , radarscan_position.y)
  1099.   screen.write("START RADAR")
  1100.   feelScreen(colors.black,colors.white)
  1101.   sleep (1)        
  1102. end
  1103.  
  1104. function initcammon()
  1105.   --print("main")
  1106.   local fr = 1        
  1107.   for icam = 1, #camers do
  1108.     camera = camers[icam]["cm"]  
  1109.     camera.freq(fr)
  1110.     fr = fr + 1
  1111.     --print("camera " .. camera.freq(1))
  1112.     print("camera " .. camera.freq())
  1113.   end    
  1114.  
  1115. end
  1116.  
  1117. function monscreen()
  1118.   modemenu = "cmr"
  1119.   SData.modemenu = "cmr"
  1120.   SaveData()
  1121.   screen.clear()
  1122.   feelScreen(colors.black,colors.white)
  1123.   screen.setBackgroundColor(colors.blue)
  1124.   screen.setCursorPos(backbutton_position.x, backbutton_position.y)
  1125.   screen.write("BACK")
  1126.   screen.setCursorPos(5, 2)
  1127.   screen.setBackgroundColor(colors.red)
  1128.   screen.write ("VIDEO")
  1129.   if cam == true and cammon == true then
  1130.     for i=1, #camers do
  1131.       y=2*i+2
  1132.       heights[i]=y      
  1133.       screen.setCursorPos(4, y)    
  1134.       screen.setBackgroundColor(colors.blue)
  1135.       screen.write ("camera"..i)
  1136.       screen.setBackgroundColor(colors.black)
  1137.     end
  1138.   end
  1139. end
  1140.  
  1141. function activateChosenCamera()
  1142.   screen.clear()
  1143.   feelScreen(colors.black,colors.white)
  1144.   screen.setBackgroundColor(colors.blue)
  1145.   screen.setCursorPos(backbutton_position.x, backbutton_position.y)
  1146.   screen.write("BACK")
  1147.   screen.setCursorPos(5, 2)
  1148.   screen.setBackgroundColor(colors.red)
  1149.   screen.write ("VIDEO")
  1150.   for i=1, #camers do
  1151.     y=2*i+2        
  1152.     screen.setCursorPos(4, y)
  1153.     if  y == chosencamera then
  1154.       screen.setBackgroundColor(colors.green)
  1155.       cammonitor.freq(i)
  1156.       print("monitor frequency " .. cammonitor.freq())
  1157.     else
  1158.       screen.setBackgroundColor(colors.blue)
  1159.     end
  1160.     screen.write ("camera"..i)
  1161.     screen.setBackgroundColor(colors.black)
  1162.  
  1163.   end
  1164. end
  1165.  
  1166. function cloakscreen()
  1167.   modemenu = "cld"
  1168.   SData.modemenu = "cld"
  1169.   SaveData()
  1170.   screen.clear()
  1171.   feelScreen(colors.black,colors.white)
  1172.   screen.setBackgroundColor(colors.blue)
  1173.   screen.setCursorPos(backbutton_position.x, backbutton_position.y)
  1174.   screen.write("BACK")
  1175.   screen.setCursorPos(4, 3)
  1176.   screen.setBackgroundColor(colors.red)
  1177.   screen.write ("CLOAKING")
  1178.   screen.setBackgroundColor(colors.black)
  1179.   screen.setCursorPos(2, 5)
  1180.   screen.setBackgroundColor(colors.blue)
  1181.   cloakenergy  =  cloak.getEnergyLevel()
  1182.   screen.write ("ENERGY")
  1183.   screen.setCursorPos(2, 6)
  1184.   screen.write (cloakenergy)
  1185.   screen.setBackgroundColor(colors.black)
  1186.  
  1187.   local valid = cloak.isAssemblyValid()
  1188.   if  valid then  
  1189.     screen.setCursorPos(2, 8)
  1190.     screen.setBackgroundColor(colors.green)
  1191.     screen.write("assem.: ok")
  1192.   else
  1193.     screen.setCursorPos(2, 8)
  1194.       screen.setBackgroundColor(colors.red)
  1195.     screen.write("assem.: no")
  1196.   end
  1197.   screen.setBackgroundColor(colors.blue)
  1198.   screen.setCursorPos(2, 10)
  1199.   if FieldTier == 1 then
  1200.     screen.write ("TIER 1")
  1201.   else
  1202.     screen.write ("TIER 2")
  1203.   end
  1204.   screen.setCursorPos(4, 16)
  1205.   screen.setBackgroundColor(colors.green)
  1206.   screen.write ("START")
  1207.   screen.setCursorPos(4, 18)
  1208.   screen.setBackgroundColor(colors.red)
  1209.   screen.write ("STOP")
  1210.   screen.setBackgroundColor(colors.black)
  1211. end
  1212.  
  1213.  
  1214. function touch_control()
  1215.   local event, side, xPos, yPos = os.pullEvent("monitor_touch")          
  1216.   if modemenu == "mine" then
  1217.     mining()
  1218.     if xPos <= start_all_position.x+10 and yPos == start_all_position.y then
  1219.       startAll()
  1220.     elseif xPos >= stop_all_position.x and yPos == stop_all_position.y then
  1221.       stopAll()
  1222.     elseif  yPos == lasermode_position.y then
  1223.       setlasermode()
  1224.     elseif  yPos == backbutton_position.y then      
  1225.       mainmenu()
  1226.     end            
  1227.   elseif modemenu == "jumping" then  
  1228.     if xPos >= backbutton_position.x  and xPos <= (backbutton_position.x + 10) and yPos == backbutton_position.y then
  1229.      mainmenu()      
  1230.     elseif  yPos == GoJump_position.y then
  1231.       feelScreen(colors.black,colors.white)
  1232.       screen.setCursorPos(GoJump_position.x , GoJump_position.y)
  1233.       screen.setBackgroundColor(colors.green)
  1234.       screen.write("GO JUMP")
  1235.       Warp()  
  1236.       sleep(0.3)
  1237.     elseif  yPos == automine_position.y then
  1238.       if las then
  1239.         feelScreen(colors.black,colors.white)
  1240.         screen.setCursorPos(automine_position.x , automine_position.y)
  1241.         screen.setBackgroundColor(colors.green)
  1242.         screen.write("AUTOMINE")
  1243.         sleep(0.3)
  1244.         startAll()  
  1245.         automine()
  1246.       end
  1247.     elseif yPos == JumpToCoord_position.y then
  1248.       resetColorsScreen()
  1249.       SetCoord()      
  1250.     end
  1251.   elseif modemenu == "main" then
  1252.     resetColorsScreen()
  1253.     if yPos == mining_position.y then
  1254.       if las then
  1255.         resetColorsScreen()
  1256.         mining()
  1257.       end
  1258.     elseif  yPos == jumping_position.y then
  1259.       resetColorsScreen()
  1260.       jumping()
  1261.     elseif  yPos == shipscan_position.y then                
  1262.       if shipsc then
  1263.         resetColorsScreen()
  1264.         shipscan()
  1265.       end
  1266.     elseif yPos == radar_position.y then  
  1267.       resetColorsScreen()
  1268.       if radar then            
  1269.         radarscan()
  1270.       end
  1271.     elseif yPos == cloak_position.y then
  1272.       resetColorsScreen()
  1273.       if cldev then
  1274.         cloakscreen()
  1275.       end
  1276.     elseif yPos == camera_position.y then
  1277.       resetColorsScreen()
  1278.       if cam == true and cammon == true then
  1279.         monscreen()
  1280.       end
  1281.     end
  1282.   elseif modemenu == "automine" then
  1283.     resetColorsScreen()
  1284.     if xPos >= backbutton_position.x  and xPos <= (backbutton_position.x + 10) and yPos == backbutton_position.y then
  1285.       stopAll()
  1286.       mainmenu()
  1287.     end
  1288.   elseif modemenu == "shipscan" then
  1289.     resetColorsScreen()
  1290.     if  yPos == shipsc_position.y then
  1291.       scship()      
  1292.     elseif yPos == deployship_position.y then
  1293.       deployship(SData.schematic)
  1294.     elseif yPos == deployship1_position.y then
  1295.       schema = "d1404472739316.schematic"
  1296.       deployship(schema)
  1297.     elseif yPos == deployship2_position.y then
  1298.       schema = "default1407225353906.schematic"
  1299.       deployship(schema)
  1300.     elseif yPos == deployship3_position.y then
  1301.       schema = "taxi1407485902452.schematic"
  1302.       deployship(schema)
  1303.     elseif yPos == deployship4_position.y then
  1304.       schema = "default1409504631567.schematic"
  1305.       deployship(schema)
  1306.     elseif yPos == backbutton_position.y then
  1307.       mainmenu()
  1308.     end
  1309.   elseif modemenu == "radar" then
  1310.     resetColorsScreen()
  1311.     if yPos == radarscan_position.y then
  1312.       feelScreen(colors.black,colors.white)
  1313.       screen.setCursorPos(radarscan_position.x , radarscan_position.y)
  1314.       screen.setBackgroundColor(colors.green)
  1315.       screen.write("START RADAR")
  1316.       sleep(0.3)
  1317.       radarscan()
  1318.     elseif yPos == backbutton_position.y then
  1319.       mainmenu()
  1320.     end
  1321.   elseif modemenu == "jtc" then
  1322.     if yPos == backbutton_position.y then
  1323.       SData.autojump = false
  1324.       SaveData()
  1325.       mainmenu()
  1326.     end
  1327.   elseif modemenu == "cld" then
  1328.     if yPos == backbutton_position.y then
  1329.       mainmenu()            
  1330.     end
  1331.     if yPos == 10 then
  1332.         if FieldTier == 1 then
  1333.           FieldTier = 2
  1334.         else
  1335.           FieldTier = 1
  1336.         end
  1337.         cloakscreen()
  1338.     elseif yPos == 16 then
  1339.         cloak.setFieldFrequency(1122)
  1340.         cloak.setFieldTier(FieldTier)
  1341.         cloak.enableCloakingField()
  1342.         cloakscreen()
  1343.     elseif yPos == 18 then
  1344.         cloak.disableCloakingField()
  1345.         cloakscreen()
  1346.     end
  1347.    
  1348.   elseif modemenu == "cmr" then
  1349.     if yPos == backbutton_position.y then
  1350.       mainmenu()
  1351.     end
  1352.     for n=1, #heights do        
  1353.       if yPos == heights[n] then
  1354.         chosencamera = heights[n]
  1355.         print("chosencamera " .. n)
  1356.         activateChosenCamera()
  1357.       end
  1358.     end
  1359.   end
  1360.  
  1361.   sleep(0.3)
  1362.   return 0  
  1363. end
  1364.  
  1365. function initwcore()
  1366.   if wcore then
  1367.     print("wcore is present")
  1368.       if mon ~= true then
  1369.         print "need monitor"
  1370.         return 0        
  1371.       else        
  1372.         if fs.exists("shipdata.txt") then
  1373.           ReadData()        
  1374.         else
  1375.           SData = {
  1376.           Summon = false,
  1377.           Distance = 1,
  1378.           Direction = 0,
  1379.           Shipname = "",
  1380.           modemenu = "",
  1381.           lasermode = "",
  1382.           schematic = "",
  1383.           CurrentCore = "",
  1384.           MainCore = "",
  1385.           autojump = "",
  1386.           DestCoordX = "",
  1387.           DestCoordY = "",
  1388.           DestCoordZ = ""
  1389.           }
  1390.         end
  1391.         SetColorDeflt()
  1392.         if type(warp) ~= "table" then
  1393.           ShowWarning("No warpcore controller detected")
  1394.           os.pullEvent("key")
  1395.           os.shutdown()
  1396.         end
  1397.         if SData.Shipname == "" then
  1398.           SetShipName()
  1399.         end
  1400.         if SData.Summon then
  1401.           warp.summon_all()
  1402.         end
  1403.         warp.set_mode(1)
  1404.         if SData.Summon then
  1405.           SData.Summon = false
  1406.           SaveData()
  1407.         end
  1408.         if SData.autojump ==true then
  1409.           statistic()
  1410.           autojumpStatistic()
  1411.           if IsInHyper then
  1412.             JumpInHyper()
  1413.           else
  1414.             JumpToCoord()
  1415.           end
  1416.         end
  1417.         print("SData.lasermode " .. SData.lasermode)
  1418.         if SData.lasermode ~= "mine" or  SData.lasermode ~= "quarry"  then
  1419.           lasermode = "mine"
  1420.           SData.lasermode  = "mine"
  1421.           SaveData()      
  1422.         end
  1423.         lasermode = SData.lasermode
  1424.         if SData.modemenu == "jumping" then
  1425.           modemenu = "jumping"
  1426.           jumping()
  1427.         elseif SData.modemenu == "mine" then
  1428.           modemenu = "mine"
  1429.           mining()
  1430.         elseif SData.modemenu == "automine" then
  1431.           modemenu = "automine"
  1432.           startAll()  
  1433.           automine()
  1434.         elseif SData.modemenu == "shipscan" then
  1435.           modemenu = "shipscan"
  1436.           shipscan()
  1437.         else
  1438.           modemenu = "main"
  1439.           mainmenu()
  1440.         end
  1441.       end
  1442.   else
  1443.     print ("need wcore controller")
  1444.   end  
  1445. end
  1446.  
  1447. function init()
  1448.   --sleep(5)
  1449.   local camcount = 0
  1450.   local nc = 1
  1451.   local periList = peripheral.getNames()
  1452.   for i = 1, #periList do
  1453.  
  1454.     device=peripheral.getType(periList[i])
  1455.     print(device)
  1456.     local tableMethods = peripheral.getMethods(periList[i])
  1457.     local countOfMethods = table.maxn (tableMethods)
  1458.     print("methods: " .. countOfMethods)
  1459.     sleep(0.1)
  1460.     if device == "monitor" then
  1461.       if  countOfMethods == 1 then
  1462.         cammon = true
  1463.         cammonitor = peripheral.wrap(periList[i])
  1464.         initcammon()
  1465.       else
  1466.         mon = true    
  1467.         screen = peripheral.wrap(periList[i])
  1468.         screen.setTextScale(MON_SCALE)
  1469.         screen_width, screen_height = screen.getSize()
  1470.         print("screensize:" .. tostring(screen_width) .."x".. tostring(screen_height))
  1471.         setScreenPosition()
  1472.       end
  1473.      
  1474.     elseif device == "mininglaser" then
  1475.       las = true
  1476.       table.insert(lazors, periList[i])
  1477.     elseif device == "warpcore" then            
  1478.             if wcore == true then                  
  1479.               multicore = true
  1480.               sleep(1)
  1481.               nc = nc+1
  1482.               print("multicore")
  1483.               sleep(0.1)
  1484.               table.insert(wcores,{ID = nc,core = peripheral.wrap(periList[i])})
  1485.               warp = wcores[nc]["core"]
  1486.               warp.set_mode(1)
  1487.             else
  1488.               wcore = true  
  1489.               warp = peripheral.wrap(periList[i])
  1490.               table.insert(wcores,{ID=nc,core = peripheral.wrap(periList[i])})
  1491.               warp.set_mode(1)
  1492.             end            
  1493.         curCoreIndex = #wcores
  1494.                    
  1495.         wcores[#wcores]["core"].set_mode(1)
  1496.     elseif device == "openperipheral_glassesbridge" then
  1497.       bridge = peripheral.wrap(periList[i])
  1498.     elseif device == "modem" then
  1499.       m = true
  1500.       m = peripheral.wrap(periList[i])
  1501.     elseif device == "shipscanner" then
  1502.       shipsc = true
  1503.       shipscanner = peripheral.wrap(periList[i])        
  1504.     elseif device == "radar" then
  1505.       rad = true
  1506.       radar = peripheral.wrap(periList[i])  
  1507.     elseif device == "camera" then
  1508.         cam = true          
  1509.         camcount = camcount+1
  1510.         if multicam == true then        
  1511.           table.insert(camers,{ID = camcount,cm = peripheral.wrap(periList[i])})
  1512.                 --cammonitor = camers[mc]["cm"]
  1513.                 --print("camers " ..tostring(camers[camcount]) )
  1514.         else
  1515.           multicam = true
  1516.           table.insert(camers,{ID = camcount,cm = peripheral.wrap(periList[i])})
  1517.           --cammonitor = camers[mc]["cm"]
  1518.           --print("camers " ..tostring(camers[camcount]["cm"]) )
  1519.         end
  1520.     elseif device == "cloakingdevicecore" then
  1521.       print("found: "..device)
  1522.       cldev = true
  1523.       cloak = peripheral.wrap(periList[i])      
  1524.       print("energy: "..tostring(cloakenergy).."eu")  
  1525.       print("isAssemblyValid: "..tostring(cloak.isAssemblyValid()))              
  1526.     end
  1527.   end
  1528. end
  1529.  
  1530. function mainmenu()
  1531.   modemenu = "main"
  1532.   SData.modemenu = "main"
  1533.   SaveData()
  1534.   screen.clear()
  1535.   feelScreen(colors.orange,colors.cyan)
  1536.   screen.setCursorPos(title_position.x, title_position.y)
  1537.   screen.write("kopro-OS")
  1538.   screen.setCursorPos(title_position.x, title_position.y+1)
  1539.   screen.write("ver. 0.007")
  1540.   if las == true then
  1541.     feelScreen(colors.cyan,colors.white)
  1542.     screen.setCursorPos(mining_position.x, mining_position.y)
  1543.     screen.write("MINE")
  1544.     feelScreen(colors.orange,colors.cyan)
  1545.   end
  1546.   if  shipsc == true then
  1547.     feelScreen(colors.cyan,colors.white)
  1548.     screen.setCursorPos(shipscan_position.x, shipscan_position.y)
  1549.     screen.write("SHIPSCAN")
  1550.     feelScreen(colors.orange,colors.cyan)
  1551.   end
  1552.   feelScreen(colors.cyan,colors.white)
  1553.   screen.setCursorPos(jumping_position.x, jumping_position.y)
  1554.   screen.write("JUMP")
  1555.   feelScreen(colors.orange,colors.cyan)
  1556.   if rad == true then
  1557.     feelScreen(colors.cyan,colors.white)  
  1558.     screen.setCursorPos(radar_position.x, radar_position.y)
  1559.     screen.write("RADAR")
  1560.     feelScreen(colors.orange,colors.cyan)
  1561.   end
  1562.   if cam == true and cammon == true then
  1563.     feelScreen(colors.cyan,colors.white)  
  1564.     screen.setCursorPos(camera_position.x, camera_position.y)
  1565.     screen.write("CAMERA")
  1566.     feelScreen(colors.orange,colors.cyan)
  1567.   end
  1568.   if cldev == true then
  1569.     feelScreen(colors.cyan,colors.white)  
  1570.     screen.setCursorPos(cloak_position.x, cloak_position.y)
  1571.     screen.write("CLOAK")
  1572.     feelScreen(colors.orange,colors.cyan)
  1573.   end  
  1574.   feelScreen(colors.orange,colors.white)
  1575.   sleep(0.5)            
  1576.   return 0  
  1577. end
  1578.  
  1579. init()
  1580. initwcore()
  1581.  
  1582. while true do
  1583.   if modemenu == "jumping" then
  1584.     parallel.waitForAny(touch_control,manctrl)
  1585.   elseif modemenu == "jtc" then
  1586.     parallel.waitForAny(touch_control,SetCoord)
  1587.   else
  1588.     parallel.waitForAny( touch_control)
  1589.   end  
  1590. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement