Advertisement
Guest User

sw

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