Guest User

kopro OS ver. 0.002

a guest
Jul 4th, 2014
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 27.54 KB | None | 0 0
  1. MON_SCALE  = 0.5
  2. MIN_OFFSET = 2
  3. MAX_OFFSET = 250
  4. lazors     = {}
  5. states     = {}
  6. step       = 12
  7. xOffset    = 2
  8. yOffset    = 4
  9. offset     = MIN_OFFSET
  10. lasN = 0
  11. print("loading...")
  12. sleep(2)
  13. Alarm = "top"
  14. Style = {
  15. CDeflt = colors.white,
  16. BGDeflt = colors.blue,
  17. CTitle = colors.black,
  18. BGTitle = colors.cyan,
  19. CWarn = colors.white,
  20. BGWarn = colors.red
  21. }
  22.  
  23. function setScreenPosition()
  24.   backbutton_position = {x = screen_width/2, y = 1}
  25.   start_all_position = {x = 1, y = screen_height-2}
  26.   stop_all_position  = {x = screen_width - 3, y = screen_height-2}
  27.   lasermode_position = {x = math.floor(screen_width/2 - 2), y = screen_height-4}
  28.   mining_position = {x=screen_width/2 - 2, y = screen_height/2-4}
  29.   jumping_position  = {x=screen_width/2 - 2, y = screen_height/2-2}
  30.   GoJump_position = {x=screen_width/2 - 3, y = screen_height/2}
  31.   automine_position = {x=screen_width/2 - 3, y = screen_height/2+2}
  32.   shipscan_position = {x=screen_width/2 - 3, y = screen_height/2+2}  
  33.   deployship_position = {x=screen_width/2 - 3, y = screen_height/2+1}
  34.   shipsc_position = {x=screen_width/2 - 2, y = screen_height/2-2}
  35.   radar_position = {x=screen_width/2 - 2, y = screen_height/2}
  36.   radarscan_position = {x=2, y = screen_height-2}
  37.   title_position  = {x=1, y = 1}
  38.   textcenter_position = {x=1, y = screen_height/2}
  39. end
  40.  
  41. function resetColorsScreen()
  42.   screen.setBackgroundColor(colors.black)
  43.   screen.setTextColor(colors.white)
  44. end
  45.  
  46. function setlasermode()
  47.   if lasermode == "mine" then
  48.   lasermode = "quarry"
  49.   print(lasermode)
  50.   SData.lasermode = lasermode
  51.   SaveData()
  52.   else
  53.   lasermode = "mine"
  54.   print(lasermode)
  55.   SData.lasermode = lasermode
  56.   SaveData()
  57.   end
  58. end  
  59.  
  60. function start(laserNUM)
  61.   print("Calling laser "..lazors[laserNUM].." for start")
  62.   setOffset(laserNUM, offset)
  63.   m.callRemote(lazors[laserNUM], lasermode)
  64. end
  65.  
  66. function startAll()
  67.   for i =1 ,#lazors do
  68.    start(i)
  69.   end
  70. end
  71.  
  72. function stop(laserNUM)
  73.   print("Calling laser "..lazors[laserNUM].." for stop")
  74.   m.callRemote(lazors[laserNUM], "stop")
  75. end
  76.  
  77. function stopAll()
  78.   for i = 1 ,#lazors do
  79.    stop(i)
  80.   end
  81. end
  82.  
  83. function setOffset(laserNUM, offset)
  84.   m.callRemote(lazors[laserNUM], "offset", offset)
  85. end
  86.  
  87. function minestatistic()
  88.   screen.clear()
  89.   feelScreen(colors.black,colors.white)
  90.   qml = 0
  91.   lay = 0
  92.   lux = 0
  93.   min = 0
  94.   screen.setCursorPos(1 , 3)
  95.   screen.setBackgroundColor(colors.cyan)
  96.   screen.write( "LASERS      " .. #lazors)
  97.   feelScreen(colors.black,colors.white)
  98.   screen.setBackgroundColor(colors.blue)
  99.   screen.setCursorPos(start_all_position.x ,start_all_position.y)
  100.   if modemenu == "automine" then
  101.     screen.write("AUTOMINE")
  102.   else
  103.     screen.write("GO")
  104.     screen.setCursorPos(stop_all_position.x, stop_all_position.y)
  105.     screen.write("xXx")
  106.   end
  107.  
  108.   screen.setBackgroundColor(colors.green)
  109.   screen.setCursorPos(lasermode_position.x, lasermode_position.y)
  110.   screen.write(lasermode)
  111.   feelScreen(colors.black,colors.white)
  112.   screen.setBackgroundColor(colors.blue)
  113.   screen.setCursorPos(backbutton_position.x, backbutton_position.y)
  114.   screen.write("BACK")
  115.   feelScreen(colors.black,colors.white)
  116.   for a = 1,#lazors do
  117.     mState, mEnergy, mLayer, mValuablesMined, mValuablesInLayer = m.callRemote(lazors[a], "state")
  118.     print(mState)  
  119.     if mState ~= "not mining"  then                
  120.       qml= qml+1
  121.       lay = lay + mLayer
  122.       lux = lux + mValuablesMined
  123.       min = min + mValuablesInLayer
  124.       if mEnergy == 0 then
  125.         screen.setCursorPos(1 , 11)
  126.         screen.setBackgroundColor(colors.red)
  127.         screen.write( "low energy L" ..a)
  128.         feelScreen(colors.black,colors.white)
  129.       end                
  130.     end
  131.   end  
  132.   screen.setCursorPos(1 , 5)
  133.   screen.setBackgroundColor(colors.green)
  134.   screen.write( "IN WORK     " .. qml)
  135.   feelScreen(colors.black,colors.white)  
  136.   print(qml)
  137.   if qml > 0 then
  138.     mLay = lay/qml
  139.     mLux = lux/qml
  140.     mmin = min*10/qml
  141.   end
  142.   screen.setCursorPos(1 , 7)
  143.   screen.setBackgroundColor(colors.blue)
  144.   screen.write( "LAYER    " .. tostring(mLay))
  145.   feelScreen(colors.black,colors.white)
  146.   screen.setCursorPos(1 , 9)
  147.   screen.setBackgroundColor(colors.blue)
  148.   screen.write( "MINE  " .. tostring(lux) .."/" .. tostring(mmin))
  149.   feelScreen(colors.black,colors.white)
  150.   sleep(0.5)
  151.   return 0  
  152. end
  153.  
  154. function mining()
  155.   modemenu = "mine"
  156.   SData.modemenu = "mine"
  157.   SData.lasermode = lasermode;
  158.   SaveData()
  159.   screen.clear()
  160.   minestatistic()
  161.   sleep(0.5)
  162.   return 0
  163. end
  164.  
  165.  
  166. function automine()
  167.   modemenu = "automine"
  168.   SData.modemenu = "automine"
  169.   SData.lasermode  = lasermode
  170.   SaveData()
  171.  
  172.   minestatistic()
  173.  
  174.   if qml == 0 then
  175.     stopAll()
  176.     sleep(3)
  177.     Warp()
  178.     sleep(10)
  179.   end
  180.   sleep(0.5)
  181.   return 0
  182. end
  183.  
  184. function feelScreen(bcolor,tcolor)
  185.   screen.setBackgroundColor(bcolor)
  186.   screen.setTextColor(tcolor)
  187. end
  188.  
  189. function SetColorDeflt()
  190.   term.setBackgroundColor(Style.BGDeflt)
  191.   term.setTextColor(Style.CDeflt)
  192. end
  193.  
  194. function SetColorTitle()
  195.   term.setBackgroundColor(Style.BGTitle)
  196.   term.setTextColor(Style.CTitle)
  197. end
  198.  
  199. function SetColorWarn()
  200.   term.setBackgroundColor(Style.BGWarn)
  201.   term.setTextColor(Style.CWarn)
  202. end
  203.  
  204. function Clear()
  205.   term.clear()
  206.   term.setCursorPos(1,1)
  207. end
  208.  
  209. function Show(Text)
  210.   term.write(Text)
  211.   local xt,yt = term.getCursorPos()
  212.   term.setCursorPos(1, yt+1)
  213. end
  214.  
  215. function ShowTitle(Text)
  216.   SetColorTitle()
  217.   term.setCursorPos(12, 1)
  218.   Show(Text)
  219.   SetColorDeflt()
  220. end
  221.  
  222. function ShowMenu(Text)
  223.   term.write(Text)
  224.   local xt, yt = term.getCursorPos()
  225.   for i = xt, 51 do
  226.     term.write(" ")
  227.   end
  228.   term.setCursorPos(1, yt+1)
  229. end
  230.  
  231. function ShowWarning(Text)
  232.   SetColorWarn()
  233.   term.setCursorPos(10, 19)
  234.   term.write(" "..Text.." ")
  235.   SetColorDeflt()
  236. end
  237.  
  238. function SaveData()
  239.   local file = fs.open("shipdata.txt", "w")
  240.   file.writeLine(textutils.serialize(SData))
  241.   file.close()
  242. end
  243.  
  244. function ReadData()
  245.   local file = fs.open("shipdata.txt", "r")
  246.   SData = textutils.unserialize(file.readAll())
  247.   file.close()
  248. end
  249.  
  250. function Explode(d, p)
  251.   local t, ll
  252.   t = {}
  253.   ll = 0
  254.   if(#p == 1) then return {p} end
  255.   while true do
  256.     l = string.find(p ,d, ll, true)
  257.     if l ~= nil then
  258.       table.insert(t, string.sub(p, ll, l-1))
  259.       ll = l+1
  260.     else
  261.       table.insert(t, string.sub(p, ll))
  262.       break
  263.     end
  264.   end
  265.   return t
  266. end
  267.  
  268. function ShowDirection()
  269.   if SData.Direction == 1 then
  270.     Show(" Direction        = Up")
  271.     elseif SData.Direction == 2 then
  272.     Show(" Direction        = Down")
  273.     elseif SData.Direction == 0 then
  274.     Show(" Direction        = Front")
  275.     elseif SData.Direction == 180 then
  276.     Show(" Direction        = Back")
  277.     elseif SData.Direction == 90 then
  278.     Show(" Direction        = Left")
  279.     elseif SData.Direction == 255 then
  280.     Show(" Direction        = Right")
  281.   end
  282.   return 0
  283. end
  284.  
  285. function CalcRealDistance()
  286.   if IsInHyper then
  287.     RealDistance = SData.Distance * 100
  288.     MinimumDistance = 1
  289.     JumpCost = (1000 * Weight) + (1000 * SData.Distance)
  290.   else
  291.     if SData.Direction == 1 or SData.Direction == 2 then
  292.       MinimumDistance = GUp + GDown
  293.       RealDistance = SData.Distance + MinimumDistance
  294.     elseif SData.Direction == 0 or SData.Direction == 180 then
  295.       MinimumDistance = GFront + GBack
  296.       RealDistance = SData.Distance + MinimumDistance
  297.     elseif SData.Direction == 90 or SData.Direction == 255 then
  298.       MinimumDistance = GLeft + GRight
  299.       RealDistance = SData.Distance + MinimumDistance
  300.     end
  301.     MinimumDistance = MinimumDistance + 1
  302.     JumpCost = (10 * Weight) + (100 * SData.Distance)
  303.   end
  304.   return 0
  305. end
  306.  
  307. function CalcNewCoords(cx, cy, cz)
  308.   local res = {x=cx, y=cy, z=cz}
  309.   if SData.Direction == 1 then
  310.     res.y = res.y + RealDistance
  311.   elseif SData.Direction == 2 then
  312.     res.y = res.y - RealDistance
  313.   end
  314.   local dx = warp.get_dx()
  315.   local dz = warp.get_dz()
  316.   if dx ~= 0 then
  317.     if SData.Direction == 0 then
  318.       res.x = res.x + (RealDistance * dx)
  319.     elseif SData.Direction == 180 then
  320.       res.x = res.x - (RealDistance * dx)
  321.     elseif SData.Direction == 90 then
  322.       res.z = res.z + (RealDistance * dx)
  323.     elseif SData.Direction == 255 then
  324.       res.z = res.z - (RealDistance * dx)
  325.     end
  326.   else
  327.     if SData.Direction == 0 then
  328.       res.z = res.z + (RealDistance * dz)
  329.     elseif SData.Direction == 180 then
  330.       res.z = res.z - (RealDistance * dz)
  331.     elseif SData.Direction == 90 then
  332.       res.x = res.x + (RealDistance * dz)
  333.     elseif SData.Direction == 255 then
  334.       res.x = res.x - (RealDistance * dz)
  335.     end
  336.   end
  337.   return res
  338. end
  339.  
  340. function ShowInfo()
  341.   Title = "<Jump-S 1.7.0 \""..SData.Shipname.."\">"
  342.   ShowTitle(Title)
  343.   Show("Core:")
  344.   Show(" x, y, z          = "..X..", "..Y..", "..Z)
  345.   local energy = warp.get_energy_level()
  346.   Show(" Energy           = "..math.floor(energy / 1000000).." % ("..energy.."EU)")
  347.   Show(" Attached players = "..warp.get_attached_players())
  348.   Show("Dimensions:")
  349.   Show(" Front, Right, Up = "..GFront..", "..GRight..", "..GUp)
  350.   Show(" Back, Left, Down = "..GBack..", "..GLeft..", "..GDown)
  351.   Show(" Size             = "..Weight.." blocks")
  352.   Show("Warp data:")
  353.   ShowDirection()
  354.   local dest = CalcNewCoords(X, Y, Z)
  355.   Show(" Distance         = "..RealDistance.." ("..JumpCost.."EU, "..math.floor(energy/JumpCost).." jumps)")
  356.   Show(" Dest.coordinates = "..dest.x..", "..dest.y..", "..dest.z)
  357.   if SData.Summon then
  358.     Show(" Summon after     = Yes")
  359.   else
  360.     Show(" Summon after     = No")
  361.   end
  362. end
  363.  
  364. function Confirm()
  365.   ShowWarning("Are you sure? (y/n)")
  366.   local event, keycode = os.pullEvent("key")
  367.   if keycode == 21 then
  368.     return true
  369.   else
  370.     return false
  371.   end
  372.   Clear()
  373.   statloop = true
  374. end
  375.  
  376. function Warp()
  377.   rs.setOutput(Alarm, false)  
  378.   warp.set_direction(SData.Direction)
  379.   if IsInHyper then
  380.     warp.set_mode(2)
  381.   else
  382.     warp.set_mode(1)
  383.   end
  384.   warp.do_jump()
  385.   return 0
  386. end
  387.  
  388. function SetDistance()
  389.   Clear()
  390.   ShowTitle("<====  Set distance  ====>")
  391.   SData.Distance = 0
  392.   CalcRealDistance()
  393.   MaximumDistance = MinimumDistance + 127
  394.   if IsInHyper then
  395.     term.write("Distance * 100 (min "..MinimumDistance..", max "..MaximumDistance.."): ")
  396.   else
  397.     term.write("Distance (min "..MinimumDistance..", max "..MaximumDistance.."): ")
  398.   end
  399.   sleep(0.3)
  400.   SData.Distance = tonumber(read())
  401.   if SData.Distance == nil then SData.Distance = 1 end
  402.   if SData.Distance < MinimumDistance or SData.Distance > MaximumDistance then
  403.     SData.Distance = 1
  404.     ShowWarning("Wrong distance. Try again.")
  405.     os.pullEvent("key")
  406.     CalcRealDistance()
  407.   else
  408.     if not IsInHyper then
  409.       SData.Distance = SData.Distance - RealDistance
  410.     end
  411.     warp.set_distance(SData.Distance)
  412.     CalcRealDistance()
  413.   end
  414.   return 0
  415. end
  416.  
  417. function SetDirection()
  418.   local drun = true
  419.   while(drun) do
  420.   Clear()
  421.   ShowTitle("<==== Set direction ====>")
  422.   ShowDirection()
  423.   term.setCursorPos(1, 16)
  424.   SetColorTitle()
  425.   ShowMenu("Use directional keys")
  426.   ShowMenu("W/S keys for Up/Down")
  427.   ShowMenu("Enter - confirm")
  428.   SetColorDeflt()
  429.   local event, keycode = os.pullEvent("key")
  430.   if keycode == 200 then
  431.     SData.Direction = 0
  432.   elseif keycode == 17 then
  433.     SData.Direction = 1
  434.   elseif keycode == 203 then
  435.     SData.Direction = 90
  436.   elseif keycode == 205 then
  437.     SData.Direction = 255
  438.   elseif keycode == 208 then
  439.     SData.Direction = 180
  440.   elseif keycode == 31 then
  441.     SData.Direction = 2
  442.   elseif keycode == 28 then
  443.     drun = false
  444.   end
  445.   end
  446. end
  447.  
  448. function SetDimensions()
  449.   Clear()
  450.   sleep(0.3)
  451.   ShowTitle("<==== Set dimensions ====>")
  452.   term.write(" Front ("..GFront..") : ")
  453.   GFront = tonumber(read())
  454.   term.write(" Right ("..GRight..") : ")
  455.   GRight = tonumber(read())
  456.   term.write(" Up    ("..GUp..") : ")
  457.   GUp = tonumber(read())
  458.   term.write(" Back  ("..GBack..") : ")
  459.   GBack = tonumber(read())
  460.   term.write(" Left  ("..GLeft..") : ")
  461.   GLeft = tonumber(read())
  462.   term.write(" Down  ("..GDown..") : ")
  463.   GDown = tonumber(read())
  464.   term.write("Setting dimensions...")
  465.   warp.dim_setp(GFront, GRight, GUp)
  466.   warp.dim_setn(GBack, GLeft, GDown)
  467.   jumping()
  468. end
  469.  
  470. function Summon()
  471.   Clear()
  472.   ShowTitle("<==== Summon players ====>")
  473.   local players = Explode(",", warp.get_attached_players())
  474.   for i = 1, #players do
  475.     Show(i..". "..players[i])
  476.   end
  477.   SetColorTitle()
  478.   ShowMenu("Enter player number")
  479.   ShowMenu("or press enter to summon everyone")
  480.   SetColorDeflt()
  481.   sleep(0.3)
  482.   term.write(":")
  483.   local input = read()
  484.   if input == "" then
  485.     warp.summon_all()
  486.   else
  487.     input = tonumber(input)
  488.     warp.summon(input - 1)
  489.   end
  490.   return 0
  491. end
  492.  
  493. function JumpToBeacon()
  494.   Clear()
  495.   ShowTitle("<==== Jump to beacon ====>")
  496.   sleep(0.3)
  497.   term.write("Enter beacon frequency: ")
  498.   local freq = tostring(read())
  499.   rs.setOutput(Alarm, true)
  500.   if Confirm() then
  501.   rs.setOutput(Alarm, false)
  502.   warp.set_mode(4)
  503.   warp.set_beacon_frequency(freq)
  504.   warp.do_jump()
  505.   end
  506.   rs.setOutput(Alarm, false)
  507.   return 0
  508. end
  509.  
  510. function JumpToGate()
  511.   Clear()
  512.   ShowTitle("<==== Jump to JumpGate ====>")
  513.   sleep(0.3)
  514.   term.write("Enter jumpgate name: ")
  515.   local name = tostring(read())
  516.   rs.setOutput(Alarm, true)
  517.   if Confirm() then
  518.   rs.setOutput(Alarm, false)
  519.   warp.set_mode(6)
  520.   warp.set_target_jumpgate(name)
  521.   warp.do_jump()
  522.   end
  523.   rs.setOutput(Alarm, false)
  524.   return 0
  525. end
  526.  
  527. function SetShipName()
  528.   Clear()
  529.   sleep(0.3)
  530.   ShowTitle("<==== Set ship name ====>")
  531.   term.write("Enter ship name: ")
  532.   SData.Shipname = tostring(read())
  533.   os.setComputerLabel(SData.Shipname)
  534.   warp.set_core_frequency(SData.Shipname)
  535.   SaveData()
  536.   mainmenu()
  537. end
  538.  
  539. function statistic()
  540.   GFront, GRight, GUp = warp.dim_getp()
  541.   GBack, GLeft, GDown = warp.dim_getn()
  542.   IsInHyper = warp.is_in_hyperspace()
  543.   repeat
  544.   X = warp.get_x()
  545.   sleep(0.3)
  546.   until X ~= nil
  547.   Y = warp.get_y()
  548.   Z = warp.get_z()
  549.   Weight = warp.get_ship_size()
  550.   CalcRealDistance()
  551.   Clear()
  552.   ShowInfo()
  553.   term.setCursorPos(1, 15)
  554.   SetColorTitle()
  555.   ShowMenu("D - Dimensions, M - Toggle summon, N - Ship name")
  556.   ShowMenu("S - Set Warp Data, J - Jump, G - Jump to JumpGate")
  557.   ShowMenu("B - Jump to Beacon, H -Jump to Hyperspace")
  558.   ShowMenu("C - Summon, X - Shutdown WarpCore and Exit")
  559.   SetColorDeflt()    
  560.   sleep(0.3)
  561.   return 0
  562. end
  563.  
  564. function manctrl()
  565.   statistic()  
  566.   local event, keycode = os.pullEvent("key")  
  567.   if keycode == 31 then
  568.     SetDirection()
  569.     SetDistance()
  570.     SaveData()
  571.   elseif keycode == 50 then
  572.     if SData.Summon then
  573.       SData.Summon = false
  574.     else
  575.       SData.Summon = true
  576.     end
  577.     SaveData()
  578.   elseif keycode == 32 then
  579.     SetDimensions()
  580.     SaveData()
  581.   elseif keycode == 36 then
  582.     rs.setOutput(Alarm, true)
  583.     if Confirm() then
  584.       Warp()
  585.     end
  586.     rs.setOutput(Alarm, false)
  587.   elseif keycode == 46 then
  588.     Summon()
  589.   elseif keycode == 48 then
  590.     JumpToBeacon()
  591.   elseif keycode == 34 then
  592.     JumpToGate()
  593.   elseif keycode == 35 then
  594.     rs.setOutput(Alarm, true)
  595.     if Confirm() then
  596.       rs.setOutput(Alarm, false)
  597.       warp.set_mode(5)
  598.       warp.do_jump()
  599.     end
  600.     rs.setOutput(Alarm, false)
  601.   elseif keycode == 45 then
  602.     warp.set_mode(0)
  603.     Clear()
  604.     print("wish you good")
  605.     os.shutdown()
  606.   elseif keycode == 49 then
  607.     SetShipName()
  608.   end
  609. end
  610.  
  611. function jumping()
  612.   screen.clear()
  613.   feelScreen(colors.black,colors.white)
  614.   screen.setBackgroundColor(colors.blue)
  615.   screen.setCursorPos(backbutton_position.x, backbutton_position.y)
  616.   screen.write("BACK")
  617.   feelScreen(colors.black,colors.white)
  618.   screen.setCursorPos(GoJump_position.x , GoJump_position.y)
  619.   screen.setBackgroundColor(colors.cyan)
  620.   screen.write("GO JUMP")
  621.   if las then
  622.     feelScreen(colors.black,colors.white)
  623.     screen.setCursorPos(automine_position.x , automine_position.y)
  624.     screen.setBackgroundColor(colors.cyan)
  625.     screen.write("AUTOMINE")
  626.  
  627.   end
  628.   feelScreen(colors.black,colors.white)
  629.   modemenu = "jumping"
  630.   SData.modemenu = "jumping"
  631.   SaveData()
  632.   statistic()
  633.   sleep(0.3)
  634.   return 0
  635. end
  636.  
  637. function autosum()
  638.   while summonloop do
  639.     local event, command=os.pullEvent("chat_command")
  640.     if (command=="sum1") then
  641.       bridge.clear()
  642.       bridge.addText(6,6,"summoning 1",0x777)
  643.       warp.summon(0)
  644.       bridge.clear()
  645.     end
  646.     if (command=="sum2")    then
  647.       bridge.clear()
  648.       bridge.addText(6,6,"summoning 2",0x777)
  649.       warp.summon(1)
  650.       bridge.clear()
  651.     end
  652.     sleep(3)
  653.   end
  654.   jumping()
  655. end
  656.  
  657.  
  658. function shipscan()
  659.   modemenu = "shipscan"
  660.   SData.modemenu = "shipscan"
  661.   SaveData()
  662.   screen.clear()
  663.   feelScreen(colors.black,colors.white)
  664.   screen.setBackgroundColor(colors.blue)
  665.   screen.setCursorPos(backbutton_position.x, backbutton_position.y)
  666.   screen.write("BACK")
  667.   feelScreen(colors.purple,colors.white)
  668.   screen.setCursorPos(shipsc_position.x , shipsc_position.y)
  669.   screen.write("SCAN")
  670.   feelScreen(colors.black,colors.white)
  671.   feelScreen(colors.purple,colors.white)
  672.   screen.setCursorPos(deployship_position.x , deployship_position.y)
  673.   screen.write("DEPLOY")
  674.   feelScreen(colors.black,colors.white)
  675. end
  676.  
  677. function deployship()
  678.   print(SData.schematic)
  679.   if SData.schematic ~= "" then
  680.     res,pw = shipscanner.deployShipFromSchematic(SData.schematic,0,30,0)
  681.     print(res)
  682.     print(pw)
  683.   end
  684.  
  685. end
  686.  
  687. function scship()
  688.   --print("scship")
  689.   print("energy level " .. tostring(shipscanner.getEnergyLevel()))
  690.   feelScreen(colors.black,colors.white)
  691.   screen.setBackgroundColor(colors.green)
  692.   screen.setCursorPos(shipsc_position.x, shipsc_position.y+8)
  693.   screen.write(shipscanner.getEnergyLevel())
  694.   scanstrings = shipscanner.scanShip()
  695.   print(scanstrings)
  696.   FN = shipscanner.getSchematicFileName()
  697.   l = string.find(FN ," ")  
  698.   while l ~= nil do
  699.     FN = shipscanner.getSchematicFileName()
  700.     l = string.find(FN ," ")
  701.     sleep(1)
  702.     print("is scanning")
  703.   end  
  704.   print(FN)
  705.   SData.schematic = FN
  706.   SaveData()
  707.   sleep(0.3)
  708.   return 0
  709. end
  710.  
  711. function radarscan()
  712.   modemenu = "radar"
  713.   screen.clear()
  714.  
  715.   feelScreen(colors.black,colors.white)
  716.   screen.setBackgroundColor(colors.blue)
  717.   screen.setCursorPos(backbutton_position.x, backbutton_position.y)
  718.   screen.write("BACK")  
  719.   feelScreen(colors.black,colors.white)
  720.   radiusr = 1000
  721.   print(radar.pos())
  722.   RadarEnergyLevel = radar.getEnergyLevel()
  723.   print(RadarEnergyLevel)
  724.   if RadarEnergyLevel < radiusr * radiusr then
  725.     print("Low energy level. Sasaj")
  726.     screen.setBackgroundColor(colors.red)
  727.     screen.setCursorPos(1 , backbutton_position.y + 4)
  728.     screen.write("Low energy ")
  729.     feelScreen(colors.black,colors.white)
  730.     sleep(1)
  731.     mainmenu()
  732.   end
  733.   screen.setBackgroundColor(colors.cyan)
  734.   screen.setCursorPos(1 , backbutton_position.y + 2)
  735.   screen.write("Energy " .. RadarEnergyLevel)
  736.   feelScreen(colors.black,colors.white)
  737.   sc = radar.scanRadius(radiusr)
  738.   print(sc)
  739.   --sleep(0.3)
  740.   print("Scanning...")  
  741.   rcount = radar.getResultsCount()
  742.   if rcount > 0 then
  743.     for i=0, rcount-1 do
  744.       freq, x, y, z = radar.getResult(i)
  745.       print("Find: "..freq.." ("..x.. " " .. y .. " " .. z .. ")")
  746.       screen.setBackgroundColor(colors.blue)
  747.       screen.setCursorPos(textcenter_position.x, textcenter_position.y -4)
  748.       screen.write("Find: "..x.. " " .. y .. " " .. z)
  749.       feelScreen(colors.black,colors.white)
  750.     end
  751.     mainmenu()
  752.   else
  753.     print("Nothing is found =(")
  754.     screen.setBackgroundColor(colors.blue)
  755.     screen.setCursorPos(textcenter_position.x, textcenter_position.y)
  756.     screen.write("Nothing =(")
  757.   end
  758.   feelScreen(colors.black,colors.white)
  759.   screen.setBackgroundColor(colors.green)
  760.   screen.setCursorPos(radarscan_position.x , radarscan_position.y)
  761.   screen.write("START RADAR")
  762.   feelScreen(colors.black,colors.white)
  763.   sleep (1)
  764.  
  765. end
  766.  
  767. function touch_control()
  768.   local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  769.   if modemenu == "mine" then
  770.     if xPos <= 10 and yPos >= screen_height-2 then
  771.       startAll()
  772.     elseif xPos >= stop_all_position.x and yPos >= stop_all_position.y then
  773.       stopAll()
  774.     elseif xPos >= lasermode_position.x -2 and xPos <= (lasermode_position.x + 5) and yPos == lasermode_position.y then
  775.       setlasermode()
  776.     elseif xPos >= backbutton_position.x  and xPos <= (backbutton_position.x + 10) and yPos == backbutton_position.y then
  777.       sleep(0.2)
  778.       mainmenu()
  779.     end
  780.     mining()
  781.     sleep(0.2)
  782.   elseif modemenu == "jumping" then  
  783.     if xPos >= backbutton_position.x  and xPos <= (backbutton_position.x + 10) and yPos == backbutton_position.y then
  784.      mainmenu()      
  785.     elseif  xPos >= GoJump_position.x -1 and xPos <= GoJump_position.x +6 and yPos == GoJump_position.y then
  786.       feelScreen(colors.black,colors.white)
  787.       screen.setCursorPos(GoJump_position.x , GoJump_position.y)
  788.       screen.setBackgroundColor(colors.green)
  789.       screen.write("GO JUMP")
  790.       Warp()  
  791.       sleep(0.3)
  792.     elseif  xPos >= automine_position.x -1 and xPos <= automine_position.x +10 and yPos == automine_position.y then
  793.       if las then
  794.         feelScreen(colors.black,colors.white)
  795.         screen.setCursorPos(automine_position.x , automine_position.y)
  796.         screen.setBackgroundColor(colors.green)
  797.         screen.write("AUTOMINE")
  798.         sleep(0.3)
  799.         startAll()  
  800.         automine()
  801.       end
  802.     end
  803.   elseif modemenu == "main" then
  804.     if xPos >= mining_position.x -1 and xPos <= mining_position.x +10 and yPos == mining_position.y then
  805.       if las then
  806.         mining()
  807.       end
  808.     elseif xPos >= jumping_position.x -1 and xPos <= jumping_position.x +10 and yPos == jumping_position.y then
  809.       jumping()
  810.     elseif  xPos >= shipscan_position.x -1 and xPos <= shipscan_position.x +10 and yPos == shipscan_position.y then                
  811.       if shipsc then
  812.         shipscan()
  813.       end
  814.     elseif  xPos >= radar_position.x -1 and xPos <= radar_position.x +10 and yPos == radar_position.y then    
  815.       if radar then            
  816.         radarscan()
  817.       end
  818.     end
  819.   elseif modemenu == "automine" then
  820.     if xPos >= backbutton_position.x  and xPos <= (backbutton_position.x + 10) and yPos == backbutton_position.y then
  821.       stopAll()
  822.       mainmenu()
  823.     end
  824.   elseif modemenu == "shipscan" then
  825.     if xPos >= shipsc_position.x -1 and xPos <= shipsc_position.x +10 and yPos == shipsc_position.y then
  826.       scship()      
  827.     elseif xPos >= deployship_position.x-3  and xPos <= (deployship_position.x + 10) and yPos == deployship_position.y then
  828.       deployship()
  829.     elseif xPos >= backbutton_position.x  and xPos <= (backbutton_position.x + 10) and yPos == backbutton_position.y then
  830.       mainmenu()
  831.     end
  832.   elseif modemenu == "radar" then
  833.     if xPos >= radarscan_position.x -1 and xPos <= radarscan_position.x +10 and yPos == radarscan_position.y then
  834.       feelScreen(colors.black,colors.white)
  835.       screen.setCursorPos(radarscan_position.x , radarscan_position.y)
  836.       screen.setBackgroundColor(colors.green)
  837.       screen.write("START RADAR")
  838.       sleep(0.3)
  839.       radarscan()
  840.     elseif xPos >= backbutton_position.x  and xPos <= (backbutton_position.x + 10) and yPos == backbutton_position.y then
  841.       mainmenu()
  842.     end
  843.   end
  844.  
  845.   sleep(0.3)
  846.   return 0  
  847. end
  848.  
  849. function initwcore()
  850.   if wcore then
  851.     print("wcore is present")
  852.       if mon ~= true then
  853.         print "need monitor"
  854.         return 0
  855.  
  856.       else
  857.  
  858.         if fs.exists("shipdata.txt") then
  859.           ReadData()        
  860.         else
  861.           SData = {
  862.           Summon = false,
  863.           Distance = 1,
  864.           Direction = 0,
  865.           Shipname = "",
  866.           modemenu = "",
  867.           lasermode = "",
  868.           schematic = ""
  869.           }
  870.         end
  871.         SetColorDeflt()
  872.         if type(warp) ~= "table" then
  873.           ShowWarning("No warpcore controller detected")
  874.           os.pullEvent("key")
  875.           os.shutdown()
  876.         end
  877.         if SData.Shipname == "" then
  878.           SetShipName()
  879.         end
  880.         if SData.Summon then
  881.           warp.summon_all()
  882.         end
  883.         warp.set_mode(1)
  884.         if SData.Summon then
  885.           SData.Summon = false
  886.           SaveData()
  887.         end
  888.         if SData.lasermode ~= "mine" or  SData.lasermode ~= "quarry"  then
  889.           lasermode = "mine"
  890.           SData.lasermode  = "mine"
  891.           SaveData()      
  892.         end
  893.         lasermode = SData.lasermode
  894.         if SData.modemenu == "jumping" then
  895.           modemenu = "jumping"
  896.           jumping()
  897.         elseif SData.modemenu == "mine" then
  898.           modemenu = "mine"
  899.           mining()
  900.         elseif SData.modemenu == "automine" then
  901.           modemenu = "automine"
  902.           startAll()  
  903.           automine()
  904.         elseif SData.modemenu == "shipscan" then
  905.           modemenu = "shipscan"
  906.           shipscan()
  907.         else
  908.           modemenu = "main"
  909.           mainmenu()
  910.         end
  911.       end
  912.   else
  913.     print ("need wcore controller")
  914.   end  
  915. end
  916.  
  917. function init()
  918.   local periList = peripheral.getNames()
  919.   for i = 1, #periList do
  920.     device=peripheral.getType(periList[i])
  921.     print(device)
  922.     sleep(0.1)
  923.     if device == "monitor" then
  924.       mon = true    
  925.       screen = peripheral.wrap(periList[i])
  926.       screen.setTextScale(MON_SCALE)
  927.       screen_width, screen_height = screen.getSize()
  928.       print("screensize:" .. tostring(screen_width) .."x".. tostring(screen_height))
  929.       setScreenPosition()
  930.     elseif device == "mininglaser" then
  931.       las = true
  932.       table.insert(lazors, periList[i])
  933.     elseif device == "warpcore" then  
  934.       wcore = true  
  935.       warp = peripheral.wrap(periList[i])
  936.     elseif device == "openperipheral_glassesbridge" then
  937.       bridge = peripheral.wrap(periList[i])
  938.     elseif device == "modem" then
  939.       m = true
  940.       m = peripheral.wrap(periList[i])
  941.     elseif device == "shipscanner" then
  942.       shipsc = true
  943.       shipscanner = peripheral.wrap(periList[i])        
  944.     elseif device == "radar" then
  945.       rad = true
  946.       radar = peripheral.wrap(periList[i])          
  947.     end
  948.   end
  949. end
  950.  
  951. function mainmenu()
  952.   modemenu = "main"
  953.   SData.modemenu = "main"
  954.   SaveData()
  955.   screen.clear()
  956.   feelScreen(colors.orange,colors.cyan)
  957.   screen.setCursorPos(title_position.x, title_position.y)
  958.   screen.write("kopro-OS")
  959.   screen.setCursorPos(title_position.x, title_position.y+1)
  960.   screen.write("ver. 0.002")
  961.   if las == true then
  962.     feelScreen(colors.cyan,colors.white)
  963.     screen.setCursorPos(mining_position.x, mining_position.y)
  964.     screen.write("MINE")
  965.   end
  966.   if  shipsc == true then
  967.     feelScreen(colors.cyan,colors.white)
  968.     screen.setCursorPos(shipscan_position.x, shipscan_position.y)
  969.     screen.write("SHIPSCAN")
  970.   end
  971.   feelScreen(colors.cyan,colors.white)
  972.   screen.setCursorPos(jumping_position.x, jumping_position.y)
  973.   screen.write("JUMP")  
  974.   if rad == true then
  975.     feelScreen(colors.cyan,colors.white)  
  976.     screen.setCursorPos(radar_position.x, radar_position.y)
  977.     screen.write("RADAR")
  978.   end
  979.   feelScreen(colors.orange,colors.white)
  980.   sleep(0.5)            
  981.   return 0  
  982. end
  983.  
  984. init()
  985. initwcore()
  986.  
  987. while true do
  988.   if modemenu == "mine" then
  989.     parallel.waitForAny( touch_control,mining)
  990.   elseif modemenu == "automine" then
  991.    parallel.waitForAny( touch_control,automine)
  992.   elseif modemenu == "jumping" then
  993.    parallel.waitForAny(touch_control,manctrl)
  994.   elseif modemenu == "main" then
  995.    parallel.waitForAny( touch_control,mainmenu)
  996.   elseif modemenu == "shipscan" then
  997.    parallel.waitForAny( touch_control)
  998.   elseif modemenu == "radar" then
  999.    parallel.waitForAny( touch_control,radarscan)
  1000.   end    
  1001. end
Advertisement
Add Comment
Please, Sign In to add comment