Advertisement
Guest User

Untitled

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