Advertisement
Guest User

a

a guest
Apr 24th, 2015
201
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   RealDistance = SData.Distance + MinimumDistance
  113.  
  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.   else
  162.   Show(" Summon after     = No")
  163.  end
  164. end
  165.  
  166. function Confirm()
  167.  ShowWarning("Are you sure? (y/n)")
  168.  local event, keycode = os.pullEvent("key")
  169.  if keycode == 21 then
  170.   return true
  171.  else
  172.   return false
  173.  end
  174. end
  175.  
  176. function Warp()
  177.  rs.setOutput(Alarm, false)
  178.  sleep(1)
  179.  warp.set_direction(SData.Direction)
  180.  if IsInHyper then
  181.   warp.set_mode(2)
  182.  else
  183.   warp.set_mode(1)
  184.  end
  185.  warp.do_jump()
  186. end
  187.  
  188. function SetDistance()
  189.  Clear()
  190.  ShowTitle("<====  Set distance  ====>")
  191.  SData.Distance = 0
  192.  CalcRealDistance()
  193.  MaximumDistance = MinimumDistance + 127
  194.  if IsInHyper then
  195.   term.write("Distance * 100 (min "..MinimumDistance..", max "..MaximumDistance.."): ")
  196.  else
  197.   term.write("Distance (min "..MinimumDistance..", max "..MaximumDistance.."): ")
  198.  end
  199.  sleep(0.3)
  200.  SData.Distance = tonumber(read())
  201.  if SData.Distance == nil then SData.Distance = 1 end
  202.  if SData.Distance < MinimumDistance or SData.Distance > MaximumDistance then
  203.   SData.Distance = 1
  204.   ShowWarning("Wrong distance. Try again.")
  205.   os.pullEvent("key")
  206.   CalcRealDistance()
  207.  else
  208.   if not IsInHyper then
  209.    SData.Distance = SData.Distance - RealDistance
  210.   end
  211.   warp.set_distance(SData.Distance)
  212.   CalcRealDistance()
  213.  end
  214. end
  215.  
  216. function SetDirection()
  217.  local drun = true
  218.  while(drun) do
  219.   Clear()
  220.   ShowTitle("<==== Set direction ====>")
  221.   ShowDirection()
  222.   term.setCursorPos(1, 16)
  223.   SetColorTitle()
  224.   ShowMenu("Use directional keys")
  225.   ShowMenu("W/S keys for Up/Down")
  226.   ShowMenu("Enter - confirm")
  227.   SetColorDeflt()
  228.   local event, keycode = os.pullEvent("key")
  229.   if keycode == 200 then
  230.    SData.Direction = 0
  231.   elseif keycode == 17 then
  232.    SData.Direction = 1
  233.   elseif keycode == 203 then
  234.    SData.Direction = 90
  235.   elseif keycode == 205 then
  236.    SData.Direction = 255
  237.   elseif keycode == 208 then
  238.    SData.Direction = 180
  239.   elseif keycode == 31 then
  240.    SData.Direction = 2
  241.   elseif keycode == 28 then
  242.    drun = false
  243.   end
  244.  end
  245. end
  246.  
  247. function SetDimensions()
  248.  Clear()
  249.  sleep(0.3)
  250.  ShowTitle("<==== Set dimensions ====>")
  251.  term.write(" Front ("..GFront..") : ")
  252.  GFront = tonumber(read())
  253.  term.write(" Right ("..GRight..") : ")
  254.  GRight = tonumber(read())
  255.  term.write(" Up    ("..GUp..") : ")
  256.  GUp = tonumber(read())
  257.  term.write(" Back  ("..GBack..") : ")
  258.  GBack = tonumber(read())
  259.  term.write(" Left  ("..GLeft..") : ")
  260.  GLeft = tonumber(read())
  261.  term.write(" Down  ("..GDown..") : ")
  262.  GDown = tonumber(read())
  263.  term.write("Setting dimensions...")
  264.  warp.dim_setp(GFront, GRight, GUp)
  265.  warp.dim_setn(GBack, GLeft, GDown)
  266. end
  267.  
  268. function Summon()
  269.  Clear()
  270.  ShowTitle("<==== Summon players ====>")
  271.  local players = Explode(",", warp.get_attached_players())
  272.  for i = 1, #players do
  273.   Show(i..". "..players[i])
  274.  end
  275.  SetColorTitle()
  276.  ShowMenu("Enter player number")
  277.  ShowMenu("or press enter to summon everyone")
  278.  SetColorDeflt()
  279.  sleep(0.3)
  280.  term.write(":")
  281.  local input = read()
  282.  if input == "" then
  283.   warp.summon_all()
  284.  else
  285.   input = tonumber(input)
  286.   warp.summon(input - 1)
  287.  end
  288. end
  289.  
  290. function JumpToBeacon()
  291.  Clear()
  292.  ShowTitle("<==== Jump to beacon ====>")
  293.  sleep(0.3)
  294.  term.write("Enter beacon frequency: ")
  295.  local freq = tostring(read())
  296.  rs.setOutput(Alarm, true)
  297.  if Confirm() then
  298.   rs.setOutput(Alarm, false)
  299.   warp.set_mode(4)
  300.   warp.set_beacon_frequency(freq)
  301.   warp.do_jump()
  302.  end
  303.  rs.setOutput(Alarm, false)
  304. end
  305.  
  306. function JumpToGate()
  307.  Clear()
  308.  ShowTitle("<==== Jump to JumpGate ====>")
  309.  sleep(0.3)
  310.  term.write("Enter jumpgate name: ")
  311.  local name = tostring(read())
  312.  rs.setOutput(Alarm, true)
  313.  if Confirm() then
  314.   rs.setOutput(Alarm, false)
  315.   warp.set_mode(6)
  316.   warp.set_target_jumpgate(name)
  317.   warp.do_jump()
  318.  end
  319.  rs.setOutput(Alarm, false)
  320. end
  321.  
  322. function SetShipName()
  323.  Clear()
  324.  ShowTitle("<==== Set ship name ====>")
  325.  sleep(0.3)
  326.  term.write("Enter ship name: ")
  327.  SData.Shipname = tostring(read())
  328.  os.setComputerLabel(SData.Shipname)
  329.  SaveData()
  330.  os.reboot()
  331. end
  332.  
  333. if fs.exists("shipdata.txt") then
  334.  ReadData()
  335. else
  336.  SData = {
  337.   Summon = false,
  338.   Distance = 1,
  339.   Direction = 0,
  340.   Shipname = ""
  341.  }
  342. end
  343.  
  344. SetColorDeflt()
  345.  
  346. Side = { "bottom", "top", "back", "left", "right" }
  347. for i = 1,5 do  
  348.  end
  349. end
  350.  
  351. if SData.Shipname == "" then
  352.  SetShipName()
  353. end
  354.  
  355. Title = "<Jump-S 1.6.1 \""..SData.Shipname.."\">"
  356.  
  357. if SData.Summon then
  358.  warp.summon_all()
  359. end
  360.  
  361. GFront, GRight, GUp = warp.dim_getp()
  362. GBack, GLeft, GDown = warp.dim_getn()
  363. IsInHyper = warp.is_in_hyperspace()
  364. repeat
  365.  X = warp.get_x()
  366.  sleep(0.3)
  367. until X ~= nil
  368. Y = warp.get_y()
  369. Z = warp.get_z()
  370. Weight = warp.get_ship_size()
  371.  
  372. CalcRealDistance()
  373.  
  374. warp.set_mode(1)
  375.  
  376. mainloop = true
  377. while(mainloop) do
  378.  Clear()
  379.  ShowInfo()
  380.  term.setCursorPos(1, 15)
  381.  SetColorTitle()
  382.  ShowMenu("D - Dimensions, M - Toggle summon, N - Ship name")
  383.  ShowMenu("S - Set Warp Data, J - Jump, G - Jump to JumpGate")
  384.  ShowMenu("B - Jump to Beacon, H -Jump to Hyperspace")
  385.  ShowMenu("C - Summon, X - Shutdown WarpCore and Exit")
  386.  SetColorDeflt()
  387.  local event, keycode = os.pullEvent("key")
  388.  if keycode == 31 then
  389.   SetDirection()
  390.   SetDistance()
  391.   SaveData()
  392.  elseif keycode == 50 then
  393.   if SData.Summon then
  394.    SData.Summon = false
  395.   else
  396.    SData.Summon = true
  397.   end
  398.   SaveData()
  399.  elseif keycode == 32 then
  400.   SetDimensions()
  401.   SaveData()
  402.  elseif keycode == 36 then
  403.   rs.setOutput(Alarm, true)
  404.   if Confirm() then
  405.    Warp()
  406.   end
  407.   rs.setOutput(Alarm, false)
  408.  elseif keycode == 46 then
  409.   Summon()
  410.  elseif keycode == 48 then
  411.   JumpToBeacon()
  412.  elseif keycode == 34 then
  413.   JumpToGate()
  414.  elseif keycode == 35 then
  415.   rs.setOutput(Alarm, true)
  416.   if Confirm() then
  417.    rs.setOutput(Alarm, false)
  418.    warp.set_mode(5)
  419.    warp.do_jump()
  420.   end
  421.   rs.setOutput(Alarm, false)
  422.  elseif keycode == 45 then
  423.   mainloop = false
  424.  elseif keycode == 49 then
  425.   SetShipName()
  426.  end
  427. end
  428.  
  429. if SData.Summon then
  430.  SData.Summon = false
  431.  SaveData()
  432. end
  433. Clear()
  434. print("wish you good")
  435. warp.set_mode(0)
  436. sleep(0.5)
  437. os.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement