Advertisement
pickar

autorun.lua

Jul 20th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.31 KB | None | 0 0
  1.  
  2. package.loaded.warpdriveCommons = nil
  3. local w = require("warpdriveCommons")
  4.  
  5. local event = require("event")
  6.  
  7. local data
  8.  
  9. require("component").gpu.bind(require("component").screen.address)
  10.  
  11. ----------- Ship support
  12.  
  13. local ship_x, ship_y, ship_z = 0, 0, 0
  14. local ship_front = 0
  15. local ship_right = 0
  16. local ship_up = 0
  17. local ship_back = 0
  18. local ship_left = 0
  19. local ship_down = 0
  20. local ship_isInHyper = false
  21. local ship_jumpCost = 0
  22. local ship_shipSize = 0
  23. local ship_movement = { 0, 0, 0 }
  24. local ship_rotationSteps = 0
  25. local ship_indexPlayer = 0
  26. local ship_indexTarget = 0
  27. local ship = nil
  28. local ship_actualDistance
  29.  
  30. function ship_read(parData)
  31.   data = parData
  32.   if data.ship_summon == nil then data.ship_summon = false; end
  33. end
  34.  
  35. function ship_boot()
  36.   if ship == nil then
  37.     return
  38.   end
  39.  
  40.   w.setColorNormal()
  41.   w.writeLn("Booting Ship")
  42.  
  43.   if data.ship_summon then
  44.     ship.summon_all()
  45.   end
  46.  
  47.   w.write("- internal parameters: ")
  48.   ship_front, ship_right, ship_up = ship.dim_positive()
  49.   ship_back, ship_left, ship_down = ship.dim_negative()
  50.   ship_isInHyper = ship.isInHyperspace()
  51.   ship_rotationSteps = ship.rotationSteps()
  52.   ship_movement = { ship.movement() }
  53.   if ship.direction ~= nil then
  54.     ship.direction(666)
  55.     ship.distance(0)
  56.   end
  57.   w.setColorSuccess()
  58.   w.writeLn("ok")
  59.  
  60.   w.setColorNormal()
  61.   w.write("- detecting Ship Core: ")
  62.   local timeout = 10
  63.   local isAttached
  64.   repeat
  65.     isAttached = ship.isAttached()
  66.     w.sleep(0.05)
  67.     timeout = timeout - 1
  68.   until isAttached ~= false or timeout < 0
  69.   if timeout < 0 then
  70.     w.setColorWarning()
  71.     w.writeLn("failed")
  72.     w.writeLn("")
  73.     w.writeLn("Ship Core shall be attached horizontally")
  74.     w.writeLn("with Ship Controller!")
  75.     w.setColorNormal()
  76.     w.sleep(6)
  77.     w.reboot()
  78.   else
  79.     w.setColorSuccess()
  80.     w.writeLn("linked")
  81.   end
  82.   w.sleep(0.2)
  83.  
  84.   w.setColorNormal()
  85.   w.write("- global position    : ")
  86.   timeout = 10
  87.   local pos
  88.   repeat
  89.     pos = ship.position()
  90.     w.sleep(0.05)
  91.     timeout = timeout - 1
  92.   until pos ~= nil or timeout < 0
  93.   ship_x, ship_y, ship_z = ship.position()
  94.   if timeout < 0 then
  95.     w.setColorWarning()
  96.     w.writeLn("failed")
  97.     w.writeLn("")
  98.     w.writeLn("Something is wrong here, rebooting...")
  99.     w.setColorNormal()
  100.     w.sleep(2)
  101.     w.reboot()
  102.   else
  103.     w.setColorSuccess()
  104.     w.writeLn("triangulated")
  105.   end
  106.   w.sleep(0.2)
  107.  
  108.   w.setColorNormal()
  109.   w.write("- integrity check    : ")
  110.   timeout = 10
  111.   repeat
  112.     ship_shipSize = ship.getShipSize()
  113.     w.sleep(0.05)
  114.     timeout = timeout - 1
  115.   until ship_shipSize ~= nil or timeout < 0
  116.   if timeout < 0 then
  117.     w.setColorWarning()
  118.     w.writeLn("failed")
  119.     w.writeLn("")
  120.     w.writeLn("Ship is too big? ignoring for now...")
  121.     w.setColorNormal()
  122.     w.sleep(1)
  123.   else
  124.     w.setColorSuccess()
  125.     w.writeLn("passed")
  126.   end
  127.  
  128.   ship.mode(1)
  129.   w.sleep(0.3)
  130. end
  131.  
  132. function ship_writeMovement()
  133.   local message = " Movement         = "
  134.   local count = 0
  135.   if ship_movement[1] > 0 then
  136.     message = message .. ship_movement[1] .. " front"
  137.     count = count + 1
  138.   elseif ship_movement[1] < 0 then
  139.     message = message .. (- ship_movement[1]) .. " back"
  140.     count = count + 1
  141.   end
  142.   if ship_movement[2] > 0 then
  143.     if count > 0 then message = message .. ", "; end
  144.     message = message .. ship_movement[2] .. " up"
  145.     count = count + 1
  146.   elseif ship_movement[2] < 0 then
  147.     if count > 0 then message = message .. ", "; end
  148.     message = message .. (- ship_movement[2]) .. " down"
  149.     count = count + 1
  150.   end
  151.   if ship_movement[3] > 0 then
  152.     if count > 0 then message = message .. ", "; end
  153.     message = message .. ship_movement[3] .. " right"
  154.     count = count + 1
  155.   elseif ship_movement[3] < 0 then
  156.     if count > 0 then message = message .. ", "; end
  157.     message = message .. (- ship_movement[3]) .. " left"
  158.     count = count + 1
  159.   end
  160.  
  161.   if ship_rotationSteps == 1 then
  162.     if count > 0 then message = message .. ", "; end
  163.     message = message .. "Turn right"
  164.     count = count + 1
  165.   elseif ship_rotationSteps == 2 then
  166.     if count > 0 then message = message .. ", "; end
  167.     message = message .. "Turn back"
  168.     count = count + 1
  169.   elseif ship_rotationSteps == 3 then
  170.     if count > 0 then message = message .. ", "; end
  171.     message = message .. "Turn left"
  172.     count = count + 1
  173.   end
  174.  
  175.   if count == 0 then
  176.     message = message .. "(none)"
  177.   end
  178.   w.writeLn(message)
  179. end
  180.  
  181. function ship_writeRotation()
  182.   if ship_rotationSteps == 0 then
  183.     w.writeLn(" Rotation         = Front    ")
  184.   elseif ship_rotationSteps == 1 then
  185.     w.writeLn(" Rotation         = Right +90")
  186.   elseif ship_rotationSteps == 2 then
  187.     w.writeLn(" Rotation         = Back 180 ")
  188.   elseif ship_rotationSteps == 3 then
  189.     w.writeLn(" Rotation         = Left -90 ")
  190.   end
  191. end
  192.  
  193. function ship_computeNewCoordinates(cx, cy, cz)
  194.   local res = { x = cx, y = cy, z = cz }
  195.   local dx, dy, dz = ship.getOrientation()
  196.   if dx == nil then
  197.     dx, dy, dz = 0, 0, 0
  198.   end
  199.   local worldMovement = { x = 0, y = 0, z = 0 }
  200.   worldMovement.x = dx * ship_movement[1] - dz * ship_movement[3]
  201.   worldMovement.y = ship_movement[2]
  202.   worldMovement.z = dz * ship_movement[1] + dx * ship_movement[3]
  203.   ship_actualDistance = math.ceil(math.sqrt(worldMovement.x * worldMovement.x + worldMovement.y * worldMovement.y + worldMovement.z * worldMovement.z))
  204.   ship_jumpCost = ship.getEnergyRequired(ship_actualDistance)
  205.   res.x = res.x + worldMovement.x
  206.   res.y = res.y + worldMovement.y
  207.   res.z = res.z + worldMovement.z
  208.   return res
  209. end
  210.  
  211. function ship_warp()
  212.   -- rs.setOutput(alarm_side, true)
  213.   if w.input_readConfirmation("Engage jump drive? (Y/n)") then
  214.     -- rs.setOutput(alarm_side, false)
  215.     ship.movement(ship_movement[1], ship_movement[2], ship_movement[3])
  216.     ship.rotationSteps(ship_rotationSteps)
  217.     ship.mode(1)
  218.     ship.jump()
  219.     -- ship = nil
  220.   end
  221.   -- rs.setOutput(alarm_side, false)
  222. end
  223.  
  224. function ship_page_setMovement()
  225.   w.page_begin("<==== Set ship movement ====>")
  226.   w.setCursorPos(1, 18)
  227.   w.setColorControl()
  228.   w.writeFullLine(" Enter jump distance on each axis (0-9)")
  229.   w.writeFullLine(" Enter 0 to keep position on that axis")
  230.   w.writeFullLine(" Use - or n keys to move in opposite direction")
  231.   w.writeFullLine(" Press Enter to save your selection")
  232.   w.setColorNormal()
  233.   w.setCursorPos(1, 3)
  234.  
  235.   ship_movement[1] = ship_page_setDistanceAxis(3, "Forward" , "Front", "Back", ship_movement[1], math.abs(ship_front + ship_back + 1))
  236.   ship_movement[2] = ship_page_setDistanceAxis(5, "Vertical", "Up"   , "Down", ship_movement[2], math.abs(ship_up + ship_down + 1))
  237.   ship_movement[3] = ship_page_setDistanceAxis(7, "Lateral" , "Right", "Left", ship_movement[3], math.abs(ship_left + ship_right + 1))
  238.   ship_movement = { ship.movement(ship_movement[1], ship_movement[2], ship_movement[3]) }
  239. end
  240.  
  241. function ship_page_setDistanceAxis(line, axis, positive, negative, userEntry, shipLength)
  242.   local maximumDistance = shipLength + ship.getMaxJumpDistance()
  243.   w.setColorDisabled()
  244.   w.setCursorPos(3, line + 1)
  245.   w.write(positive .. " is " .. ( shipLength + 1) .. " to " ..  maximumDistance .. " blocks      ")
  246.   w.setCursorPos(3, line + 2)
  247.   w.write(negative .. " is " .. (-shipLength - 1) .. " to " .. -maximumDistance .. " blocks      ")
  248.  
  249.   w.setColorNormal()
  250.   repeat
  251.     w.setCursorPos(1, line)
  252.     w.write(axis .. " movement: ")
  253.     userEntry = w.input_readNumber(userEntry)
  254.     if userEntry ~= 0 and (math.abs(userEntry) <= shipLength or math.abs(userEntry) > maximumDistance) then
  255.       w.status_showWarning("Wrong distance. Try again.")
  256.     end
  257.   until userEntry == 0 or (math.abs(userEntry) > shipLength and math.abs(userEntry) <= maximumDistance)
  258.   w.setCursorPos(1, line + 1)
  259.   w.clearLine()
  260.   w.setCursorPos(1, line + 2)
  261.   w.clearLine()
  262.  
  263.   return userEntry
  264. end
  265.  
  266. function ship_page_setRotation()
  267.   local inputAbort = false
  268.   local drun = true
  269.   w.page_begin("<==== Set ship rotation ====>")
  270.   w.setCursorPos(1, 19)
  271.   w.setColorControl()
  272.   w.writeFullLine(" Select ship rotation (Up, Down, Left, Right)")
  273.   w.writeFullLine(" Select Front to keep current orientation")
  274.   w.writeFullLine(" Press Enter to save your selection")
  275.   repeat
  276.     w.setCursorPos(1, 3)
  277.     w.setColorNormal()
  278.     ship_writeRotation()
  279.     local params = { event.pull() }
  280.     local eventName = params[1]
  281.     local address = params[2]
  282.     if address == nil then address = "none" end
  283.     local firstParam = params[3]
  284.     if firstParam == nil then firstParam = "none" end
  285.     if eventName == "key_down" then
  286.       local character = string.char(params[3])
  287.       local keycode = params[4]
  288.      
  289.       if keycode == 200 then
  290.         ship_rotationSteps = 0
  291.       elseif keycode == 203 then
  292.         ship_rotationSteps = 3
  293.       elseif keycode == 205 then
  294.         ship_rotationSteps = 1
  295.       elseif keycode == 208 then
  296.         ship_rotationSteps = 2
  297.       elseif keycode == 28 then
  298.         inputAbort = true
  299.       else
  300.         w.status_showWarning("Key " .. keycode .. " is invalid")
  301.       end
  302.     elseif eventName == "interrupted" then
  303.       inputAbort = true
  304.     elseif not w.event_handler(eventName, params[2]) then
  305.       w.status_showWarning("Event '" .. eventName .. "', " .. address .. " is unsupported")
  306.     end
  307.   until inputAbort
  308.   ship_rotationSteps = ship.rotationSteps(ship_rotationSteps)
  309. end
  310.  
  311. function ship_page_setDimensions()
  312.   w.page_begin("<==== Set ship dimensions ====>")
  313.   w.setCursorPos(1, 18)
  314.   w.setColorControl()
  315.   w.writeFullLine(" Enter ship size in blocks (0-9)")
  316.   w.writeFullLine(" First block next to Ship counts as 1")
  317.   w.writeFullLine(" Ship controller counts as 'Front = 1'")
  318.   w.writeFullLine(" Press Enter to save your selection")
  319.  
  320.   w.setCursorPos(1, 3)
  321.   w.setColorNormal()
  322.   w.write(" Front (".. ship_front ..") : ")
  323.   ship_front = w.input_readNumber(ship_front)
  324.   w.write(" Right (".. ship_right ..") : ")
  325.   ship_right = w.input_readNumber(ship_right)
  326.   w.write(" Up    (".. ship_up ..") : ")
  327.   ship_up = w.input_readNumber(ship_up)
  328.   w.write(" Back  (".. ship_back ..") : ")
  329.   ship_back = w.input_readNumber(ship_back)
  330.   w.write(" Left  (".. ship_left ..") : ")
  331.   ship_left = w.input_readNumber(ship_left)
  332.   w.write(" Down  (".. ship_down ..") : ")
  333.   ship_down = w.input_readNumber(ship_down)
  334.   w.write("Setting dimensions...")
  335.   ship_front, ship_right, ship_up = ship.dim_positive(ship_front, ship_right, ship_up)
  336.   ship_back, ship_left, ship_down = ship.dim_negative(ship_back, ship_left, ship_down)
  337.   ship_shipSize = ship.getShipSize()
  338.   if ship_shipSize == nil then ship_shipSize = 0 end
  339. end
  340.  
  341. function ship_page_summon() -- no longer used
  342.   w.page_begin("<==== Summon players ====>")
  343.   local stringPlayers, arrayPlayers = ship.getAttachedPlayers()
  344.   if stringPlayers == nil or #arrayPlayers == 0 then
  345.     w.writeLn("~ no players registered ~")
  346.     w.writeLn("")
  347.     w.setColorControl()
  348.     w.writeFullLine("Press enter to exit")
  349.     w.setColorNormal()
  350.     w.input_readNumber("")
  351.     return
  352.   end
  353.   for i = 1, #arrayPlayers do
  354.     w.writeLn(i .. ". " .. arrayPlayers[i])
  355.   end
  356.   w.setColorControl()
  357.   w.writeFullLine("Enter player number")
  358.   w.writeFullLine("or press enter to summon everyone")
  359.   w.setColorNormal()
  360.  
  361.   w.write(":")
  362.   local input = w.input_readNumber("")
  363.   if input == "" then
  364.     ship.summon_all()
  365.   else
  366.     input = tonumber(input)
  367.     ship.summon(input - 1)
  368.   end
  369. end
  370.  
  371. function ship_page_jumpToBeacon()
  372.   w.page_begin("<==== Jump to beacon ====>")
  373.  
  374.   w.write("Enter beacon frequency: ")
  375.   local freq = w.input_readText("")
  376.   -- rs.setOutput(alarm_side, true)
  377.   if w.input_readConfirmation() then
  378.     -- rs.setOutput(alarm_side, false)
  379.     ship.mode(4)
  380.     ship.beaconFrequency(freq)
  381.     ship.jump()
  382.     -- ship = nil
  383.   end
  384.   -- rs.setOutput(alarm_side, false)
  385. end
  386.  
  387. function ship_page_jumpToGate()
  388.   w.page_begin("<==== Jump through Jumpgate ====>")
  389.   w.writeLn("")
  390.   w.writeLn("Your ship should be already inside a jumpgate")
  391.  
  392.   w.setCursorPos(1, 20)
  393.   w.setColorControl()
  394.   w.writeFullLine("Enter target jumpgate name (a-z, 0-9)")
  395.   w.writeFullLine("Press enter to save jumpgate name")
  396.  
  397.   w.setCursorPos(1, 5)
  398.   w.setColorNormal()
  399.   w.write("Target jumpgate name: ")
  400.   local name = w.input_readText("")
  401.   -- rs.setOutput(alarm_side, true)
  402.   if w.input_readConfirmation("Engage gate jumping? (Y/n)") then
  403.     -- rs.setOutput(alarm_side, false)
  404.     ship.mode(6)
  405.     ship.targetJumpgate(name)
  406.     ship.jump()
  407.     -- ship = nil
  408.   end
  409.   -- rs.setOutput(alarm_side, false)
  410. end
  411.  
  412. function ship_page_controls()
  413.   w.page_begin(w.data_getName() .. " - Ship controls")
  414.   if ship == nil then
  415.     w.status_showWarning("No ship controller detected")
  416.   elseif ship.isAttached() ~= true then
  417.     w.status_showWarning("No ship core detected")
  418.   else
  419.     -- w.writeLn("")
  420.     ship_x, ship_y, ship_z = ship.position()
  421.     if ship_x == nil then
  422.       ship_x, ship_y, ship_z = 0, 0, 0
  423.     end
  424.     w.writeLn("Ship:")
  425.     w.writeLn(" Current position = " .. ship_x .. ", " .. ship_y .. ", " .. ship_z)
  426.     local energy, energyMax = ship.energy()
  427.     if energy == nil then energy = 0 end
  428.     if energyMax == nil or energyMax == 0 then energyMax = 1 end
  429.     w.writeLn(" Energy           = " .. math.floor(energy / energyMax * 100) .. " % (" .. energy .. " EU)")
  430.    
  431.     w.writeLn("")
  432.     -- w.writeLn("")
  433.     w.writeLn("Dimensions:")
  434.     w.writeLn(" Front, Right, Up = " .. w.format_integer(ship_front) .. ", " .. w.format_integer(ship_right) .. ", " .. w.format_integer(ship_up) .. " blocks")
  435.     w.writeLn(" Back, Left, Down = " .. w.format_integer(ship_back) .. ", " .. w.format_integer(ship_left) .. ", " .. w.format_integer(ship_down) .. " blocks")
  436.     w.writeLn(" Size             = " .. ship_shipSize .. " blocks")
  437.     w.writeLn("")
  438.     w.writeLn("Warp data:")
  439.     ship_writeMovement()
  440.     local dest = ship_computeNewCoordinates(ship_x, ship_y, ship_z)
  441.     w.writeLn(" Distance         = " .. ship_actualDistance .. " (" .. ship_jumpCost .. " EU, " .. math.floor(energy / ship_jumpCost) .. " jumps)")
  442.     w.writeLn(" Target position  = " .. w.format_integer(dest.x) .. ", " .. w.format_integer(dest.y) .. ", " .. w.format_integer(dest.z))
  443.   end
  444.  
  445.   w.setCursorPos(1, 20)
  446.   w.setColorControl()
  447.   w.writeFullLine(" set ship Name (N), Dimensions (D), Movement (M)")
  448.   if ship_isInHyper then
  449.     w.writeFullLine(" Jump to move ship (M/J), exit Hyperspace (H)")
  450.   else
  451.     w.writeFullLine(" Jump to move ship (M/J), enter Hyperspace (H)")
  452.   end
  453. end
  454.  
  455. function ship_key_controls(character, keycode)
  456.   if character == 'm' or character == 'M' then -- M
  457.     ship_page_setMovement()
  458.     ship_page_setRotation()
  459.     ship_warp()
  460.     return true
  461.   elseif character == 'd' or character == 'D' then -- D
  462.     ship_page_setDimensions()
  463.     return true
  464.   elseif character == 'j' or character == 'J' then -- J
  465.     ship_warp()
  466.     return true
  467.   elseif character == 'h' or character == 'H' then -- H
  468.     -- rs.setOutput(alarm_side, true)
  469.     if w.input_readConfirmation("Engage hyperdrive? (Y/n)") then
  470.       -- rs.setOutput(alarm_side, false)
  471.       ship.mode(5)
  472.       _, e = ship.energy()
  473.       if e > 50000000 then
  474.         ship.jump()
  475.       end
  476.       -- ship = nil
  477.     end
  478.     -- rs.setOutput(alarm_side, false)
  479.     return true
  480.   elseif character == 'n' or character == 'N' then
  481.     w.data_setName()
  482.     return true
  483.   end
  484.   return false
  485. end
  486.  
  487. function ship_writeArray(arrayValues, indexSelected)
  488.   if indexSelected then
  489.     indexSelected = (indexSelected + #arrayValues) % #arrayValues
  490.   end
  491.  
  492.   local indexSplit = math.ceil(#arrayValues / 2)
  493.   for i = 1, indexSplit do
  494.     if indexSelected and i == indexSelected + 1 then
  495.       w.setColorSelected()
  496.       w.write(">" .. string.sub(arrayValues[i] .. "                        ", 1, 24))
  497.       w.setColorNormal()
  498.     else
  499.       w.write(" " .. string.sub(arrayValues[i] .. "                        ", 1, 24))
  500.     end
  501.     if arrayValues[i + indexSplit] ~= nil then
  502.       if indexSelected and i + indexSplit == indexSelected + 1 then
  503.         w.setColorSelected()
  504.         w.writeLn(">" .. string.sub(arrayValues[i + indexSplit] .. "                        ", 1, 24))
  505.         w.setColorNormal()
  506.       else
  507.         w.writeLn(" " .. arrayValues[i + indexSplit])
  508.       end
  509.     else
  510.       w.writeLn("")
  511.     end
  512.   end
  513.   return indexSelected
  514. end
  515.  
  516. function ship_page_crew()
  517.   w.page_begin(w.data_getName() .. " - Ship crew")
  518.   if ship == nil then
  519.     w.status_showWarning("No ship controller detected")
  520.   elseif ship.isAttached() ~= true then
  521.     w.status_showWarning("No ship core detected")
  522.   else
  523.     w.writeLn("Attached players:")
  524.     local stringPlayers, _ = ship.getAttachedPlayers()
  525.     if stringPlayers == nil or stringPlayers == "" then
  526.       stringPlayers = "~ no registered player ~"
  527.     end
  528.     local arrayPlayers = w.data_splitString(stringPlayers, ",")
  529.     ship_indexPlayer = ship_writeArray(arrayPlayers, ship_indexPlayer)
  530.     w.writeLn("")
  531.     w.writeLn("Summon crew after short jump = " .. w.format_boolean(data.ship_summon, "YES", "no"))
  532. --    w.writeLn("")
  533. --    w.writeLn("Beacon jump: -admin only-")
  534.   end
  535.  
  536.   w.setCursorPos(1, 20)
  537.   w.setColorControl()
  538.   w.writeFullLine(" Summon all crew (S), Toggle summon after jump (T)")
  539.   w.writeFullLine(" select crew (arrows), summon selected crew (enter)")
  540. end
  541.  
  542. function ship_key_crew(character, keycode)
  543.   if character == 't' or character == 'T' then -- T
  544.     if data.ship_summon then
  545.       data.ship_summon = false
  546.     else
  547.       data.ship_summon = true
  548.     end
  549.     w.data_save()
  550.     return true
  551.   elseif character == 's' or character == 'S' then -- S
  552.     ship.summon_all()
  553.     return true
  554.   elseif keycode == 28 then -- Enter
  555.     local success, namePlayer = ship.summon(ship_indexPlayer)
  556.     if success then
  557.       w.status_showSuccess("Engaging teleportation for " .. namePlayer .. "...")
  558.     else
  559.       w.status_showWarning("Failed to summon crew member")
  560.     end
  561.     return true
  562.   elseif keycode == 200 or keycode == 203 or character == '-' then -- Up or Left or -
  563.     ship_indexPlayer = ship_indexPlayer - 1
  564.     return true
  565.   elseif keycode == 208 or keycode == 205 or character == '+' then -- Down or Right or +
  566.     ship_indexPlayer = ship_indexPlayer + 1
  567.     return true
  568.   end
  569.   return false
  570. end
  571.  
  572. function ship_page_navigation()
  573.   w.page_begin(w.data_getName() .. " - Ship navigation")
  574.   if ship == nil then
  575.     w.status_showWarning("No ship controller detected")
  576.   elseif ship.isAttached() ~= true then
  577.     w.status_showWarning("No ship core detected")
  578.   else
  579.     local locationCurrent = "somewhere..."  -- @TODO ship.getLocation()
  580.     w.writeLn("Current ship location        : " .. locationCurrent)
  581.     w.writeLn("Jumpgates or beacons in range:")
  582.     local stringTargets, _ = "not implemented", nil -- ship.getTargets()
  583.     if stringTargets == nil or stringTargets == "" then
  584.       stringTargets = "~ no beacon nor jumpgate in range ~"
  585.     end
  586.     local arrayTargets = w.data_splitString(stringTargets, ",")
  587.     ship_indexTarget = ship_writeArray(arrayTargets, ship_indexTarget)
  588. --    w.writeLn("")
  589. --    w.writeLn("Beacon jump: -admin only-")
  590.   end
  591.  
  592.   w.setCursorPos(1, 20)
  593.   w.setColorControl()
  594.   w.writeFullLine(" select target (arrows), register target (enter)")
  595.   w.writeFullLine(" jump through Gate (G)")
  596. end
  597.  
  598. function ship_key_navigation(character, keycode)
  599.   if keycode == 28 then -- Enter
  600. --    local success, xxx = ship.xxx(ship_indexTarget)
  601. --    if success then
  602. --      w.status_showSuccess("Engaging jumpgate jump to " .. xxx .. "...")
  603. --    else
  604. --      w.status_showWarning("Failed to summon crew member")
  605. --    end
  606.     return true
  607. --  elseif character == 'b' or character == 'B' then -- B
  608. --    ship_page_jumpToBeacon()
  609. --    return true
  610.   elseif character == 'g' or character == 'G' then -- G
  611.     ship_page_jumpToGate()
  612.     return true
  613.   elseif keycode == 200 or keycode == 203 or character == '-' then -- Up or Left or -
  614.     ship_indexTarget = ship_indexTarget - 1
  615.     return true
  616.   elseif keycode == 208 or keycode == 205 or character == '+' then -- Down or Right or +
  617.     ship_indexTarget = ship_indexTarget + 1
  618.     return true
  619.   end
  620.   return false
  621. end
  622.  
  623. function ship_register()
  624.   w.device_register("warpdriveShipController",
  625.       function(deviceType, address, wrap) ship = wrap end,
  626.       function() end)
  627.   w.event_register("shipCoreCooldownDone"  , function() w.status_showWarning("Ship core cooldown done")   return false end )
  628.   w.data_register("ship", ship_read, nil)
  629. end
  630.  
  631. ----------- connections status
  632.  
  633. function connections_page(isBooting)
  634.   w.page_begin(w.data_getName() .. " - Connections")
  635.  
  636.   w.writeLn("")
  637.  
  638.   if ship == nil then
  639.     w.setColorDisabled()
  640.     w.writeLn("No ship controller detected")
  641.   else
  642.     w.setColorSuccess()
  643.     w.writeLn("Ship controller detected")
  644.     if isBooting then
  645.       ship_boot()
  646.     end
  647.   end
  648. end
  649.  
  650. ----------- Boot sequence
  651.  
  652. w.page_setEndText(" Home (0), Controls (1), Crew (2), Navigation (3)")
  653. w.page_register('0', connections_page, nil)
  654. w.page_register('1', ship_page_controls, ship_key_controls)
  655. w.page_register('2', ship_page_crew, ship_key_crew)
  656. w.page_register('3', ship_page_navigation, ship_key_navigation)
  657. ship_register()
  658.  
  659. w.boot()
  660. w.run()
  661.  
  662. if data.ship_summon then
  663.   data.ship_summon = false
  664.   w.data_save()
  665. end
  666.  
  667. if ship ~= nil then
  668.   ship.mode(0)
  669. end
  670.  
  671. w.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement