Advertisement
Guest User

warp drive no warp controler or warp core

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