Advertisement
Guest User

Warpdrive Modified FHexu8FA

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