Advertisement
drpepper240

PRYGEE 1.6.4

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