Advertisement
Guest User

start

a guest
Jan 19th, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.26 KB | None | 0 0
  1. print("loading...")
  2.  
  3. -- set alarm side if you need this
  4. Alarm = "top"
  5.  
  6. Style = {
  7.  CDeflt = colors.white,
  8.  BGDeflt = Colors.blue,
  9.  CTitle = Colors.black,
  10.  BGTitle = Colors.cyan,
  11.  CWarn = Colors.white,
  12.  BGWarn = Colors.red
  13. }
  14.  
  15. function SetColorDeflt()
  16.  term.setBackgroundColor(Style.BGDeflt)
  17.  term.setTextColor(Style.CDeflt)
  18. end
  19.  
  20. function SetColorTitle()
  21.  term.setBackgroundColor(Style.BGTitle)
  22.  term.setTextColor(Style.CTitle)
  23. end
  24.  
  25. function SetColorWarn()
  26.  term.setBackgroundColor(Style.BGWarn)
  27.  term.setTextColor(Style.CWarn)
  28. end
  29.  
  30. function Clear()
  31.  term.clear()
  32.  term.setCursorPos(1,1)
  33. end
  34.  
  35. function Show(Text)
  36.  term.write(Text)
  37.  local xt,yt = term.getCursorPos()
  38.  term.setCursorPos(1, yt+1)
  39. end
  40.  
  41. function ShowTitle(Text)
  42.  SetColorTitle()
  43.  term.setCursorPos(12, 1)
  44.  Show(Text)
  45.  SetColorDeflt()
  46. end
  47.  
  48. function ShowMenu(Text)
  49.  term.write(Text)
  50.  local xt, yt = term.getCursorPos()
  51.  for i = xt, 51 do
  52.   term.write(" ")
  53.  end
  54.  term.setCursorPos(1, yt+1)
  55. end
  56.  
  57. function ShowWarning(Text)
  58.   SetColorWarn()
  59.   term.setCursorPos(10, 19)
  60.   term.write(" "..Text.." ")
  61.   SetColorDeflt()
  62. end
  63.  
  64. function SaveData()
  65.  local file = fs.open("shipdata.txt", "w")
  66.  file.writeLine(textutils.serialize(SData))
  67.  file.close()
  68. end
  69.  
  70. function ReadData()
  71.  local file = fs.open("shipdata.txt", "r")
  72.  SData = textutils.unserialize(file.readAll())
  73.  file.close()
  74. end
  75.  
  76. function Explode(d, p)
  77.  local t, ll
  78.  t = {}
  79.  ll = 0
  80.  if(#p == 1) then return {p} end
  81.  while true do
  82.   l = string.find(p ,d, ll, true)
  83.   if l ~= nil then
  84.    table.insert(t, string.sub(p, ll, l-1))
  85.    ll = l+1
  86.   else
  87.    table.insert(t, string.sub(p, ll))
  88.    break
  89.   end
  90.  end
  91.  return t
  92. end
  93.  
  94. function ShowDirection()
  95.  if SData.Direction == 1 then
  96.   Show(" Direction        = Up")
  97.  elseif SData.Direction == 2 then
  98.   Show(" Direction        = Down")
  99.  elseif SData.Direction == 0 then
  100.   Show(" Direction        = Front")
  101.  elseif SData.Direction == 180 then
  102.   Show(" Direction        = Back")
  103.  elseif SData.Direction == 90 then
  104.   Show(" Direction        = Left")
  105.  elseif SData.Direction == 255 then
  106.   Show(" Direction        = Right")
  107.  end
  108. end
  109.  
  110. function CalcRealDistance()
  111.  if IsInHyper then
  112.   RealDistance = SData.Distance * 100
  113.   MinimumDistance = 1
  114.   JumpCost = (1000 * Weight) + (1000 * SData.Distance)
  115.  else
  116.   if SData.Direction == 1 or SData.Direction == 2 then
  117.    MinimumDistance = GUp + GDown
  118.    RealDistance = SData.Distance + MinimumDistance
  119.   elseif SData.Direction == 0 or SData.Direction == 180 then
  120.    MinimumDistance = GFront + GBack
  121.    RealDistance = SData.Distance + MinimumDistance
  122.   elseif SData.Direction == 90 or SData.Direction == 255 then
  123.    MinimumDistance = GLeft + GRight
  124.    RealDistance = SData.Distance + MinimumDistance
  125.   end
  126.   MinimumDistance = MinimumDistance + 1
  127.   JumpCost = (10 * Weight) + (100 * SData.Distance)
  128.  end
  129. end
  130.  
  131. function CalcNewCoords(cx, cy, cz)
  132.  local res = {x=cx, y=cy, z=cz}
  133.  if SData.Direction == 1 then
  134.   res.y = res.y + RealDistance
  135.  elseif SData.Direction == 2 then
  136.   res.y = res.y - RealDistance
  137.  end
  138.  local dx = warp.get_dx()
  139.  local dz = warp.get_dz()
  140.  if dx ~= 0 then
  141.   if SData.Direction == 0 then
  142.    res.x = res.x + (RealDistance * dx)
  143.   elseif SData.Direction == 180 then
  144.    res.x = res.x - (RealDistance * dx)
  145.   elseif SData.Direction == 90 then
  146.    res.z = res.z + (RealDistance * dx)
  147.   elseif SData.Direction == 255 then
  148.    res.z = res.z - (RealDistance * dx)
  149.   end
  150.  else
  151.   if SData.Direction == 0 then
  152.    res.z = res.z + (RealDistance * dz)
  153.   elseif SData.Direction == 180 then
  154.    res.z = res.z - (RealDistance * dz)
  155.   elseif SData.Direction == 90 then
  156.    res.x = res.x + (RealDistance * dz)
  157.   elseif SData.Direction == 255 then
  158.    res.x = res.x - (RealDistance * dz)
  159.   end
  160.  end
  161.  return res
  162. end
  163.  
  164. function ShowInfo()
  165.  ShowTitle(Title)
  166.  Show("Core:")
  167.  Show(" x, y, z          = "..X..", "..Y..", "..Z)
  168.  local energy = warp.get_energy_level()
  169.  Show(" Energy           = "..math.floor(energy / 1000000).." % ("..energy.."EU)")
  170.  Show(" Attached players = "..warp.get_attached_players())
  171.  Show("Dimensions:")
  172.  Show(" Front, Right, Up = "..GFront..", "..GRight..", "..GUp)
  173.  Show(" Back, Left, Down = "..GBack..", "..GLeft..", "..GDown)
  174.  Show(" Size             = "..Weight.." blocks")
  175.  Show("Warp data:")
  176.  ShowDirection()
  177.  local dest = CalcNewCoords(X, Y, Z)
  178.  Show(" Distance         = "..RealDistance.." ("..JumpCost.."EU, "..math.floor(energy/JumpCost).." jumps)")
  179.  Show(" Dest.coordinates = "..dest.x..", "..dest.y..", "..dest.z)
  180.  if SData.Summon then
  181.   Show(" Summon after     = Yes")
  182.  else
  183.   Show(" Summon after     = No")
  184.  end
  185. end
  186.  
  187. function Confirm()
  188.  ShowWarning("Are you sure? (y/n)")
  189.  local event, keycode = os.pullEvent("key")
  190.  if keycode == 21 then
  191.   return true
  192.  else
  193.   return false
  194.  end
  195. end
  196.  
  197. function Warp()
  198.  rs.setOutput(Alarm, false)
  199.  sleep(1)
  200.  warp.set_direction(SData.Direction)
  201.  if IsInHyper then
  202.   warp.set_mode(2)
  203.  else
  204.   warp.set_mode(1)
  205.  end
  206.  warp.do_jump()
  207. end
  208.  
  209. function SetDistance()
  210.  Clear()
  211.  ShowTitle("<====  Set distance  ====>")
  212.  SData.Distance = 0
  213.  CalcRealDistance()
  214.  MaximumDistance = MinimumDistance + 127
  215.  if IsInHyper then
  216.   term.write("Distance * 100 (min "..MinimumDistance..", max "..MaximumDistance.."): ")
  217.  else
  218.   term.write("Distance (min "..MinimumDistance..", max "..MaximumDistance.."): ")
  219.  end
  220.  sleep(0.3)
  221.  SData.Distance = tonumber(read())
  222.  if SData.Distance == nil then SData.Distance = 1 end
  223.  if SData.Distance < MinimumDistance or SData.Distance > MaximumDistance then
  224.   SData.Distance = 1
  225.   ShowWarning("Wrong distance. Try again.")
  226.   os.pullEvent("key")
  227.   CalcRealDistance()
  228.  else
  229.   if not IsInHyper then
  230.    SData.Distance = SData.Distance - RealDistance
  231.   end
  232.   warp.set_distance(SData.Distance)
  233.   CalcRealDistance()
  234.  end
  235. end
  236.  
  237. function SetDirection()
  238.  local drun = true
  239.  while(drun) do
  240.   Clear()
  241.   ShowTitle("<==== Set direction ====>")
  242.   ShowDirection()
  243.   term.setCursorPos(1, 16)
  244.   SetColorTitle()
  245.   ShowMenu("Use directional keys")
  246.   ShowMenu("W/S keys for Up/Down")
  247.   ShowMenu("Enter - confirm")
  248.   SetColorDeflt()
  249.   local event, keycode = os.pullEvent("key")
  250.   if keycode == 200 then
  251.    SData.Direction = 0
  252.   elseif keycode == 17 then
  253.    SData.Direction = 1
  254.   elseif keycode == 203 then
  255.    SData.Direction = 90
  256.   elseif keycode == 205 then
  257.    SData.Direction = 255
  258.   elseif keycode == 208 then
  259.    SData.Direction = 180
  260.   elseif keycode == 31 then
  261.    SData.Direction = 2
  262.   elseif keycode == 28 then
  263.    drun = false
  264.   end
  265.  end
  266. end
  267.  
  268. function SetDimensions()
  269.  Clear()
  270.  sleep(0.3)
  271.  ShowTitle("<==== Set dimensions ====>")
  272.  term.write(" Front ("..GFront..") : ")
  273.  GFront = tonumber(read())
  274.  term.write(" Right ("..GRight..") : ")
  275.  GRight = tonumber(read())
  276.  term.write(" Up    ("..GUp..") : ")
  277.  GUp = tonumber(read())
  278.  term.write(" Back  ("..GBack..") : ")
  279.  GBack = tonumber(read())
  280.  term.write(" Left  ("..GLeft..") : ")
  281.  GLeft = tonumber(read())
  282.  term.write(" Down  ("..GDown..") : ")
  283.  GDown = tonumber(read())
  284.  term.write("Setting dimensions...")
  285.  warp.dim_setp(GFront, GRight, GUp)
  286.  warp.dim_setn(GBack, GLeft, GDown)
  287. end
  288.  
  289. function Summon()
  290.  Clear()
  291.  ShowTitle("<==== Summon players ====>")
  292.  local players = Explode(",", warp.get_attached_players())
  293.  for i = 1, #players do
  294.   Show(i..". "..players[i])
  295.  end
  296.  SetColorTitle()
  297.  ShowMenu("Enter player number")
  298.  ShowMenu("or press enter to summon everyone")
  299.  SetColorDeflt()
  300.  sleep(0.3)
  301.  term.write(":")
  302.  local input = read()
  303.  if input == "" then
  304.   warp.summon_all()
  305.  else
  306.   input = tonumber(input)
  307.   warp.summon(input - 1)
  308.  end
  309. end
  310.  
  311. function JumpToBeacon()
  312.  Clear()
  313.  ShowTitle("<==== Jump to beacon ====>")
  314.  sleep(0.3)
  315.  term.write("Enter beacon frequency: ")
  316.  local freq = tostring(read())
  317.  rs.setOutput(Alarm, true)
  318.  if Confirm() then
  319.   rs.setOutput(Alarm, false)
  320.   warp.set_mode(4)
  321.   warp.set_beacon_frequency(freq)
  322.   warp.do_jump()
  323.  end
  324.  rs.setOutput(Alarm, false)
  325. end
  326.  
  327. function JumpToGate()
  328.  Clear()
  329.  ShowTitle("<==== Jump to JumpGate ====>")
  330.  sleep(0.3)
  331.  term.write("Enter jumpgate name: ")
  332.  local name = tostring(read())
  333.  rs.setOutput(Alarm, true)
  334.  if Confirm() then
  335.   rs.setOutput(Alarm, false)
  336.   warp.set_mode(6)
  337.   warp.set_target_jumpgate(name)
  338.   warp.do_jump()
  339.  end
  340.  rs.setOutput(Alarm, false)
  341. end
  342.  
  343. function SetShipName()
  344.  Clear()
  345.  ShowTitle("<==== Set ship name ====>")
  346.  sleep(0.3)
  347.  term.write("Enter ship name: ")
  348.  SData.Shipname = tostring(read())
  349.  os.setComputerLabel(SData.Shipname)
  350.  warp.set_core_frequency(SData.Shipname)
  351.  SaveData()
  352.  os.reboot()
  353. end
  354.  
  355. if fs.exists("shipdata.txt") then
  356.  ReadData()
  357. else
  358.  SData = {
  359.   Summon = false,
  360.   Distance = 1,
  361.   Direction = 0,
  362.   Shipname = ""
  363.  }
  364. end
  365.  
  366. SetColorDeflt()
  367.  
  368. Side = { "bottom", "top", "back", "left", "right" }
  369. for i = 1,5 do
  370.  if peripheral.getType(Side[i]) == "warpcore" then
  371.   warp = peripheral.wrap(Side[i])
  372.   break
  373.  end
  374. end
  375.  
  376. if type(warp) ~= "table" then
  377.  ShowWarning("No warpcore controller detected")
  378.  os.pullEvent("key")
  379.  os.shutdown()
  380. end
  381.  
  382. if SData.Shipname == "" then
  383.  SetShipName()
  384. end
  385.  
  386. Title = "<Jump-S 1.6.1 \""..SData.Shipname.."\">"
  387.  
  388. if SData.Summon then
  389.  warp.summon_all()
  390. end
  391.  
  392. GFront, GRight, GUp = warp.dim_getp()
  393. GBack, GLeft, GDown = warp.dim_getn()
  394. IsInHyper = warp.is_in_hyperspace()
  395. repeat
  396.  X = warp.get_x()
  397.  sleep(0.3)
  398. until X ~= nil
  399. Y = warp.get_y()
  400. Z = warp.get_z()
  401. Weight = warp.get_ship_size()
  402.  
  403. CalcRealDistance()
  404.  
  405. warp.set_mode(1)
  406.  
  407. mainloop = true
  408. while(mainloop) do
  409.  Clear()
  410.  ShowInfo()
  411.  term.setCursorPos(1, 15)
  412.  SetColorTitle()
  413.  ShowMenu("D - Dimensions, M - Toggle summon, N - Ship name")
  414.  ShowMenu("S - Set Warp Data, J - Jump, G - Jump to JumpGate")
  415.  ShowMenu("B - Jump to Beacon, H -Jump to Hyperspace")
  416.  ShowMenu("C - Summon, X - Shutdown WarpCore and Exit")
  417.  SetColorDeflt()
  418.  local event, keycode = os.pullEvent("key")
  419.  if keycode == 31 then
  420.   SetDirection()
  421.   SetDistance()
  422.   SaveData()
  423.  elseif keycode == 50 then
  424.   if SData.Summon then
  425.    SData.Summon = false
  426.   else
  427.    SData.Summon = true
  428.   end
  429.   SaveData()
  430.  elseif keycode == 32 then
  431.   SetDimensions()
  432.   SaveData()
  433.  elseif keycode == 36 then
  434.   rs.setOutput(Alarm, true)
  435.   if Confirm() then
  436.    Warp()
  437.   end
  438.   rs.setOutput(Alarm, false)
  439.  elseif keycode == 46 then
  440.   Summon()
  441.  elseif keycode == 48 then
  442.   JumpToBeacon()
  443.  elseif keycode == 34 then
  444.   JumpToGate()
  445.  elseif keycode == 35 then
  446.   rs.setOutput(Alarm, true)
  447.   if Confirm() then
  448.    rs.setOutput(Alarm, false)
  449.    warp.set_mode(5)
  450.    warp.do_jump()
  451.   end
  452.   rs.setOutput(Alarm, false)
  453.  elseif keycode == 45 then
  454.   mainloop = false
  455.  elseif keycode == 49 then
  456.   SetShipName()
  457.  end
  458. end
  459.  
  460. if SData.Summon then
  461.  SData.Summon = false
  462.  SaveData()
  463. end
  464. Clear()
  465. print("wish you good")
  466. warp.set_mode(0)
  467. sleep(0.5)
  468. os.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement