Advertisement
Guest User

kopro OS

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