MegiRicky

vectorVLSconsole.lua

Nov 16th, 2024 (edited)
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.30 KB | None | 0 0
  1. local monitor = peripheral.find("monitor")
  2. local radar = peripheral.find("sp_radar")
  3. local modem = peripheral.wrap("right")
  4.  
  5. -- Ensure all required peripherals are connected
  6. if not monitor or not radar or not ship then
  7. error("Required peripherals are not attached")
  8. end
  9.  
  10. monitor.setTextScale(0.5)
  11. monitor.clear()
  12.  
  13. local radarScale = 500
  14. local friendlyID = {289, 232}
  15. local targetPositions = {}
  16. local waypoints = {}
  17. local displayState = "radar" -- Initial display state
  18. local selectedTarget = nil
  19. local lockedTargetId = nil
  20. local lockedWaypoint = nil -- Variable to store the locked waypoint
  21. local projectileSpeed = 320 --m/s
  22.  
  23. local missileId = 1
  24. local missileLaunched = {}
  25. local controls = {
  26. fireMissile = {}
  27. }
  28.  
  29. -- Get channel data for cannons
  30. local function getChannelInput(prompt, default)
  31. print(prompt .. ", default: " .. default)
  32. local input = io.read()
  33. if input == "" then
  34. input = default
  35. end
  36. return tonumber(input)
  37. end
  38.  
  39. local controlChannel = getChannelInput("Input the missile control channel", 1300)
  40. modem.open(controlChannel)
  41.  
  42. local function checkFriendly(ID)
  43. local friendly = false
  44. for _, id in ipairs(friendlyID) do
  45. if tonumber(ID) == tonumber(id) then
  46. friendly = true
  47. break
  48. end
  49. end
  50. return friendly
  51. end
  52.  
  53. local w, h = monitor.getSize()
  54.  
  55. local function drawControls()
  56. local w, h = monitor.getSize()
  57. monitor.setCursorPos(1, h-1)
  58. monitor.write(" ")
  59. monitor.setCursorPos(1, h)
  60. monitor.write(" ")
  61. monitor.setCursorPos(1, h-1)
  62. monitor.write("Scale: ")
  63. monitor.setCursorPos(8, h-1)
  64. monitor.write("-")
  65. monitor.setCursorPos(10, h-1)
  66. monitor.write("+")
  67. monitor.setCursorPos(1, h-2)
  68. monitor.write("Stop locking")
  69.  
  70. local segmentLength = radarScale / 2
  71. local scaleText
  72. if segmentLength >= 1000 then
  73. scaleText = string.format("%.1f km", segmentLength / 1000)
  74. else
  75. scaleText = string.format("%d m", segmentLength)
  76. end
  77.  
  78. monitor.setCursorPos(1, h)
  79. monitor.write("Segment Length: " .. scaleText)
  80.  
  81. -- Add button to navigate to waypoint page
  82. monitor.setCursorPos(w-10, h-1)
  83. monitor.write("Waypoints")
  84.  
  85. -- Add button to navigate to the cannon adjustment page
  86. monitor.setCursorPos(w-18, h-1)
  87. monitor.write("Adjust Cannon")
  88. end
  89.  
  90. local function drawControls()
  91. local w, h = monitor.getSize()
  92. monitor.setCursorPos(1, h-1)
  93. monitor.write(" ")
  94. monitor.setCursorPos(1, h)
  95. monitor.write(" ")
  96. monitor.setCursorPos(1, h-1)
  97. monitor.write("Scale: ")
  98. monitor.setCursorPos(8, h-1)
  99. monitor.write("-")
  100. monitor.setCursorPos(10, h-1)
  101. monitor.write("+")
  102. monitor.setCursorPos(1, h-2)
  103. monitor.write("Stop locking")
  104.  
  105. local segmentLength = radarScale / 2
  106. local scaleText
  107. if segmentLength >= 1000 then
  108. scaleText = string.format("%.1f km", segmentLength / 1000)
  109. else
  110. scaleText = string.format("%d m", segmentLength)
  111. end
  112.  
  113. monitor.setCursorPos(1, h)
  114. monitor.write("Segment Length: " .. scaleText)
  115.  
  116. -- Add button to navigate to waypoint page at the bottom right corner
  117. monitor.setCursorPos(w-10, h-1)
  118. monitor.write("Waypoints")
  119.  
  120. -- Add button to navigate to the cannon adjustment page at the top right corner
  121. monitor.setCursorPos(w-13, 1)
  122. monitor.write("Adjust Cannon")
  123. end
  124.  
  125. local function addWaypoint(x, y, z, color)
  126. local newWaypoint = {
  127. x = x,
  128. y = y,
  129. z = z,
  130. color = color or colors.purple
  131. }
  132. table.insert(waypoints, newWaypoint)
  133. end
  134.  
  135. local function drawWaypointPage()
  136. local w, h = monitor.getSize()
  137. monitor.clear()
  138. monitor.setCursorPos(1, 1)
  139. monitor.write("Waypoint Page")
  140. monitor.setCursorPos(1, 3)
  141. monitor.write("Enter coordinates (x, y, z) and color:")
  142. monitor.setCursorPos(1, 4)
  143. monitor.write("Format: x,y,z,color")
  144. monitor.setCursorPos(1, 5)
  145. monitor.write("Colors: red, yellow, green, blue, purple")
  146. monitor.setCursorPos(1, h-1)
  147. monitor.write("Enter to submit, Back to cancel.")
  148. end
  149.  
  150. local function drawCannonAdjustmentPage()
  151. local w, h = monitor.getSize()
  152. monitor.clear()
  153. monitor.setCursorPos(1, 1)
  154. monitor.write("Cannon Pitch and Yaw Adjustment")
  155.  
  156. local cannonNames = {
  157. {name = "Port 5 inch", data = cannonData.port5inch, target = cannonTarget.port5inch},
  158. {name = "Starboard 5 inch", data = cannonData.starboard5inch, target = cannonTarget.starboard5inch},
  159. {name = "Bow 15 inch", data = cannonData.bow15inch, target = cannonTarget.bow15inch},
  160. {name = "Stern 15 inch", data = cannonData.stern15inch, target = cannonTarget.stern15inch}
  161. }
  162.  
  163. local yOffset = 3
  164.  
  165. for _, cannon in ipairs(cannonNames) do
  166. monitor.setCursorPos(1, yOffset)
  167. monitor.write(cannon.name .. ":")
  168.  
  169. monitor.setCursorPos(1, yOffset + 1)
  170. monitor.write("Current: pitch: " .. (cannon.data.pitch and string.format("%.2f", cannon.data.pitch) or "N/A"))
  171. monitor.setCursorPos(26, yOffset + 1)
  172. monitor.write("yaw: " .. (cannon.data.yaw and string.format("%.2f", cannon.data.yaw) or "N/A"))
  173.  
  174. monitor.setCursorPos(1, yOffset + 2)
  175. monitor.write("Adjustment: pitch: " .. (cannon.target.pitchAdjust and string.format("%.2f", cannon.target.pitchAdjust) or "N/A"))
  176. monitor.setCursorPos(26, yOffset + 2)
  177. monitor.write("yaw: " .. (cannon.target.yawAdjust and string.format("%.2f", cannon.target.yawAdjust) or "N/A"))
  178.  
  179. monitor.setCursorPos(1, yOffset + 3)
  180. monitor.write("[pitch +] [pitch -]")
  181. monitor.setCursorPos(w - 30, yOffset + 3)
  182. monitor.write("[yaw +] [yaw -]")
  183.  
  184. yOffset = yOffset + 6 -- Move down for the next cannon
  185. end
  186.  
  187. monitor.setCursorPos(1, h)
  188. monitor.write("Back")
  189. end
  190.  
  191. local function drawRadarBackground(centerX, centerY, radius, shipYawRadians)
  192. local aspectRatio = 1.5
  193. local segmentLength = radarScale / 4
  194. local pixelPerSegmentX = w / 4
  195. local pixelPerSegmentY = h / 4
  196.  
  197. -- Draw the grid
  198. for i = 0, w - pixelPerSegmentX, pixelPerSegmentX do
  199. -- Vertical lines
  200. for y = 1, h - 2 do -- Leave space for the scale display at the bottom
  201. monitor.setCursorPos(i, y)
  202. monitor.write("|")
  203. end
  204. end
  205.  
  206. for j = 0, h - pixelPerSegmentY, pixelPerSegmentY do
  207. -- Horizontal lines
  208. for x = 1, w do
  209. monitor.setCursorPos(x, j)
  210. monitor.write("-")
  211. end
  212. end
  213.  
  214. -- Draw the circle
  215. for i = 0, 360, 5 do
  216. local rad = i * (math.pi / 180)
  217. local x = centerX + (radius * math.sin(rad)) * aspectRatio
  218. local y = centerY + radius * math.cos(rad)
  219. monitor.setCursorPos(math.floor(x + 0.5), math.floor(y + 0.5))
  220. monitor.write(".")
  221. end
  222.  
  223. -- Draw the crosshair
  224. for y = centerY - radius, centerY + radius do
  225. monitor.setCursorPos(centerX, y)
  226. monitor.write("|")
  227. end
  228.  
  229. local trueBearing = (math.deg(shipYawRadians) + 360) % 360 - 180
  230. if trueBearing < 0 then
  231. trueBearing = trueBearing + 360
  232. end
  233. local textPos = centerY - radius + 10
  234. if textPos > 0 then
  235. monitor.setCursorPos(centerX - (#tostring(math.floor(trueBearing)) + 2) / 2, textPos)
  236. monitor.write(tostring(math.floor(trueBearing)) .. "°")
  237. end
  238.  
  239. local directions = {"N", "W", "S", "E"}
  240. local dirAngles = {0, 90, 180, 270}
  241.  
  242. for index, dir in ipairs(directions) do
  243. local dirRad = (dirAngles[index] + math.deg(shipYawRadians)) * (math.pi / 180)
  244. local dirX = centerX + (radius * math.sin(dirRad)) * aspectRatio
  245. local dirY = centerY + radius * math.cos(dirRad)
  246. monitor.setCursorPos(math.floor(dirX + 0.5), math.floor(dirY + 0.5))
  247. monitor.write(dir)
  248. end
  249.  
  250. -- Display segment length
  251. monitor.setCursorPos(1, centerY + radius + 2)
  252. monitor.write("Segment Length: " .. segmentLength .. " meters")
  253. end
  254.  
  255. local function drawTargetOnCircle(centerX, centerY, radius, relX, relY, aspectRatio)
  256. local dx = relX - centerX
  257. local dy = relY - centerY
  258. local mag = math.sqrt((dx / aspectRatio)^2 + dy^2)
  259.  
  260. if (mag > radius) then
  261. local intersectX = centerX + ((dx / mag) * radius) * aspectRatio
  262. local intersectY = centerY + (dy / mag) * radius
  263. return intersectX, intersectY
  264. else
  265. return relX, relY
  266. end
  267. end
  268.  
  269. local function drawCannonCrosshair(centerX, centerY, radius, aspectRatio)
  270. local pos = ship.getWorldspacePosition()
  271. local shipYawRadians = math.atan2(-ship.getRotationMatrix()[1][3], ship.getRotationMatrix()[3][3])
  272. if shipYawRadians < 0 then shipYawRadians = shipYawRadians + 2 * math.pi end
  273. -- Function to calculate relative yaw in degrees from ship's facing
  274. local function relativeYaw(dx, dz)
  275. local angle = math.atan2(dx, dz)
  276. local relativeAngle = angle + shipYawRadians - math.pi
  277. if relativeAngle < -math.pi then
  278. relativeAngle = relativeAngle + 2 * math.pi
  279. elseif relativeAngle >= math.pi then
  280. relativeAngle = relativeAngle - 2 * math.pi
  281. end
  282. return math.deg(relativeAngle)
  283. end
  284. end
  285.  
  286. local function calculateRelativeAngle(objectAngle, shipYawRadians)
  287. local relativeAngle = objectAngle + shipYawRadians - math.pi
  288. if relativeAngle < -math.pi then
  289. relativeAngle = relativeAngle + 2 * math.pi
  290. elseif relativeAngle >= math.pi then
  291. relativeAngle = relativeAngle - 2 * math.pi
  292. end
  293. return relativeAngle
  294. end
  295.  
  296. local function drawRadarDisplay()
  297. local w, h = monitor.getSize()
  298. local centerX, centerY = math.floor(w / 2), math.floor(h / 2)
  299. local radius = math.min(centerX, centerY) - 1
  300. local aspectRatio = 1.2
  301.  
  302. local matrix = ship.getRotationMatrix()
  303. local shipYawRadians = math.atan2(-matrix[1][3], matrix[3][3])
  304. if (shipYawRadians < 0) then
  305. shipYawRadians = shipYawRadians + 2 * math.pi
  306. end
  307.  
  308. drawRadarBackground(centerX, centerY, radius, shipYawRadians)
  309. monitor.setCursorPos(centerX, centerY)
  310. monitor.write("+")
  311.  
  312. drawCannonCrosshair(centerX, centerY, radius, aspectRatio)
  313.  
  314. local pos = ship.getWorldspacePosition()
  315. local results = radar.scanForShips(10000)
  316. targetPositions = {}
  317. for _, object in ipairs(results) do
  318. local x = object.pos.x - pos.x
  319. local z = object.pos.z - pos.z
  320. local distance = math.sqrt(x^2 + z^2)
  321. local objectAngle = math.atan2(x, z)
  322. local relativeAngle = calculateRelativeAngle(objectAngle, shipYawRadians)
  323.  
  324. local scaledDistance = (distance / radarScale) * radius
  325. local relX = centerX + (scaledDistance * math.sin(relativeAngle)) * aspectRatio
  326. local relY = centerY + scaledDistance * math.cos(relativeAngle)
  327.  
  328. relX, relY = drawTargetOnCircle(centerX, centerY, radius, relX, relY, aspectRatio)
  329.  
  330. if (object.mass > 2000 and distance > 5) then
  331. if (distance > radarScale) then
  332. monitor.setTextColor(colors.lightBlue)
  333. else
  334. monitor.setTextColor(colors.red)
  335. end
  336. if (checkFriendly(object.id)) then
  337. monitor.setBackgroundColor(colors.blue)
  338. elseif (object.mass > 1000000) then
  339. monitor.setBackgroundColor(colors.orange)
  340. elseif (math.sqrt(object.velocity.x ^ 2 + object.velocity.y ^ 2 + object.velocity.z ^ 2) > 30) then
  341. monitor.setBackgroundColor(colors.red)
  342. else
  343. monitor.setBackgroundColor(colors.yellow)
  344. end
  345. monitor.setCursorPos(math.floor(relX + 0.5), math.floor(relY + 0.5))
  346. monitor.write("o")
  347. monitor.setTextColor(colors.green)
  348. monitor.setBackgroundColor(colors.black)
  349.  
  350. table.insert(targetPositions, {x = math.floor(relX + 0.5), y = math.floor(relY + 0.5), data = object})
  351. end
  352. end
  353.  
  354. -- Draw waypoints
  355. for index, waypoint in ipairs(waypoints) do
  356. local wpX = waypoint.x - pos.x
  357. local wpZ = waypoint.z - pos.z
  358. local distance = math.sqrt(wpX^2 + wpZ^2)
  359. local wpAngle = math.atan2(wpX, wpZ)
  360. local relativeAngle = calculateRelativeAngle(wpAngle, shipYawRadians)
  361.  
  362. local scaledDistance = (distance / radarScale) * radius
  363. local relX = centerX + (scaledDistance * math.sin(relativeAngle)) * aspectRatio
  364. local relY = centerY + scaledDistance * math.cos(relativeAngle)
  365.  
  366. relX, relY = drawTargetOnCircle(centerX, centerY, radius, relX, relY, aspectRatio)
  367.  
  368. monitor.setBackgroundColor(waypoint.color)
  369. monitor.setCursorPos(math.floor(relX + 0.5), math.floor(relY + 0.5))
  370. monitor.write("W")
  371. monitor.setBackgroundColor(colors.black)
  372.  
  373. table.insert(targetPositions, {x = math.floor(relX + 0.5), y = math.floor(relY + 0.5), data = {type = "waypoint", x = waypoint.x,y = waypoint.y, z = waypoint.z, index = index}})
  374. end
  375. end
  376.  
  377. local function displayTargetInfo(target)
  378. local w, h = monitor.getSize()
  379. local pos = ship.getWorldspacePosition()
  380.  
  381. monitor.clear()
  382. monitor.setCursorPos(1, h-12)
  383. monitor.write("Target Info")
  384. monitor.setCursorPos(1, h-11)
  385.  
  386. local targetPosX, targetPosY, targetPosZ
  387. if target.type == "waypoint" then
  388. monitor.write("Type: Waypoint")
  389. targetPosX, targetPosY, targetPosZ = target.x, target.y, target.z
  390. monitor.setCursorPos(1, h-7)
  391. monitor.write("Coordinate: " .. target.x .. ", "..target.y..", ".. target.z)
  392. else
  393. monitor.write("ID: " .. target.id)
  394. targetPosX, targetPosY, targetPosZ = target.pos.x, target.pos.y, target.pos.z
  395. monitor.setCursorPos(1, h-10)
  396. monitor.write("Mass: " .. target.mass)
  397. monitor.setCursorPos(1, h-9)
  398. monitor.write("Velocity: " .. string.format("%.2f, %.2f, %.2f", target.velocity.x, target.velocity.y, target.velocity.z))
  399. monitor.setCursorPos(1, h-8)
  400. monitor.write("Position: " .. string.format("%.2f, %.2f, %.2f", target.pos.x, target.pos.y, target.pos.z))
  401. end
  402.  
  403. local distance = math.sqrt((targetPosX - pos.x)^2 + (targetPosZ - pos.z)^2)
  404. local dx = targetPosX - pos.x
  405. local dz = targetPosZ - pos.z
  406. local bearing = (math.deg(math.atan2(dz, dx)) + 360) % 360 - 270
  407. if bearing < 0 then
  408. bearing = bearing + 360
  409. end
  410.  
  411. monitor.setCursorPos(1, h-7)
  412. monitor.write("Distance: " .. string.format("%.2f", distance) .. " meters")
  413. monitor.setCursorPos(1, h-6)
  414. monitor.write("Bearing: " .. string.format("%.2f", bearing) .. "°")
  415.  
  416. if target.type ~= "waypoint" then
  417. local type = "unknown"
  418. local hostile = "hostile"
  419. if target.mass > 1000000 then
  420. type = "ship"
  421. elseif math.sqrt(target.velocity.x ^ 2 + target.velocity.y ^ 2 + target.velocity.z ^ 2) > 30 then
  422. type = "Flying missile / plane"
  423. else
  424. type = "unknown"
  425. end
  426. if checkFriendly(target.id) then
  427. hostile = "friendly"
  428. else
  429. hostile = "hostile"
  430. end
  431. monitor.setCursorPos(1, h-5)
  432. monitor.write("Type: " .. hostile .. " " .. type)
  433. end
  434.  
  435. if target.type == "waypoint" then
  436. monitor.setCursorPos(1, h-3)
  437. monitor.write("[LAUNCH MISSILE]")
  438. else
  439. monitor.setCursorPos(1, h-3)
  440. monitor.write("[LAUNCH MISSILE]")
  441. end
  442. monitor.setCursorPos(1, h)
  443. monitor.write("Back")
  444. end
  445.  
  446. local function launchMissile(targetType,targetId,targetPos)
  447. if type(controls.fireMissile) ~= "table" then
  448. controls.fireMissile = {}
  449. end
  450.  
  451. local currentMissileId = missileId
  452. -- Assign a table to this missile's ID in fireMissile, marking it as launched
  453. if targetType == "ship" then
  454. controls.fireMissile[currentMissileId] = {launch = true, type = targetType, id = targetId}
  455. else
  456. controls.fireMissile[currentMissileId] = {launch = true, type = targetType, pos = targetPos}
  457. end
  458. missileLaunched[currentMissileId] = true -- Mark this missile as launched
  459. print("Launching missile:", currentMissileId)
  460. print(textutils.serialize(controls))
  461.  
  462. missileId = missileId + 1 -- Increment missile ID for next launch
  463. end
  464.  
  465. local function handleTouch()
  466. local w, h = monitor.getSize()
  467. while true do
  468. local event, side, x, y = os.pullEvent("monitor_touch")
  469. if displayState == "radar" then
  470. if y == h-1 and x >= 8 and x <= 9 then
  471. radarScale = math.max(100, radarScale - 100)
  472. drawControls()
  473. drawRadarDisplay()
  474. elseif y == h-1 and x >= 10 and x <= 11 then
  475. radarScale = math.min(10000, radarScale + 100)
  476. drawControls()
  477. drawRadarDisplay()
  478. elseif y == h-1 and x >= w-10 and x <= w then
  479. displayState = "waypoints"
  480. monitor.clear()
  481. drawWaypointPage()
  482. print("Enter waypoint coordinates (x, y, z, color), color options: red, yellow, green, blue:")
  483. local input = read()
  484. local x, y, z, color = input:match("([^,]+),([^,]+),([^,]+),([^,]*)")
  485. local colorValue = colors.purple
  486. if color then
  487. local colorMap = {
  488. purple = colors.purple,
  489. red = colors.red,
  490. yellow = colors.yellow,
  491. green = colors.green,
  492. blue = colors.blue,
  493. white = colors.white,
  494. orange = colors.orange,
  495. lightBlue = colors.lightBlue,
  496. lime = colors.lime,
  497. pink = colors.pink,
  498. gray = colors.gray,
  499. lightGray = colors.lightGray,
  500. cyan = colors.cyan,
  501. purple = colors.purple,
  502. brown = colors.brown,
  503. black = colors.black
  504. }
  505. colorValue = colorMap[color] or colors.purple
  506. end
  507. if x and y and z then
  508. addWaypoint(tonumber(x), tonumber(y), tonumber(z), colorValue)
  509. end
  510. displayState = "radar"
  511. monitor.clear()
  512. drawControls()
  513. drawRadarDisplay()
  514. elseif y == 1 and x >= w-13 and x <= w then
  515. displayState = "adjustCannon"
  516. monitor.clear()
  517. drawCannonAdjustmentPage()
  518. elseif y == h-2 and x < 10 then
  519. cannonTarget.port5inch = { type = nil, side = "port", id = nil, x = nil, y = nil, z = nil, pitchAdjust = 0, yawAdjust = 0 }
  520. cannonTarget.starboard5inch = { type = nil, side = "starboard", id = nil, x = nil, y = nil, z = nil, pitchAdjust = 0, yawAdjust = 0 }
  521. cannonTarget.bow15inch = { type = nil, side = "bow", id = nil, x = nil, y = nil, z = nil, pitchAdjust = 0, yawAdjust = 0 }
  522. cannonTarget.stern15inch = { type = nil, side = "stern", id = nil, x = nil, y = nil, z = nil, pitchAdjust = 0, yawAdjust = 0 }
  523. monitor.setCursorPos(1, 1)
  524. monitor.clear()
  525. drawRadarDisplay()
  526. monitor.write("Locking stopped.")
  527. else
  528. for _, target in ipairs(targetPositions) do
  529. if x == target.x and y == target.y then
  530. selectedTarget = target.data
  531. displayState = "targetInfo"
  532. displayTargetInfo(selectedTarget)
  533. break
  534. end
  535. end
  536. end
  537. elseif displayState == "targetInfo" then
  538. if y == h and x >= 1 and x <= 4 then
  539. -- Back button
  540. displayState = "radar"
  541. monitor.clear()
  542. drawRadarDisplay()
  543. elseif y == h-3 and x >= 1 and x <= 32 then
  544. -- Launch missile
  545. local missileTarget = {}
  546. if selectedTarget.type == "waypoint" then
  547. launchMissile("waypoint",nil,selectedTarget)
  548. modem.transmit(controlChannel, controlChannel, controls)
  549. else
  550. launchMissile("ship",selectedTarget.id)
  551. modem.transmit(controlChannel, controlChannel, controls)
  552. end
  553. displayState = "radar"
  554. monitor.clear()
  555. drawRadarDisplay()
  556. monitor.setCursorPos(1, 1)
  557. monitor.write("Target locked: " .. (selectedTarget.type == "waypoint" and "Waypoint" or selectedTarget.id))
  558. end
  559. elseif displayState == "adjustCannon" then
  560. -- Back button
  561. if y == h and x >= 1 and x <= 4 then
  562. displayState = "radar"
  563. monitor.clear()
  564. drawRadarDisplay()
  565. end
  566.  
  567. -- Detect pitch and yaw adjustment button presses
  568. local yOffset = 3
  569. local buttonWidth = 10
  570. for i, cannonName in ipairs({"port5inch", "starboard5inch", "bow15inch", "stern15inch"}) do
  571. if y == yOffset + 3 then
  572. if x >= 1 and x <= 10 then
  573. -- Increase pitch
  574. cannonTarget[cannonName].pitchAdjust = cannonTarget[cannonName].pitchAdjust + 0.1
  575. elseif x >= 11 and x <= 20 then
  576. -- Decrease pitch
  577. cannonTarget[cannonName].pitchAdjust = cannonTarget[cannonName].pitchAdjust - 0.1
  578. elseif x >= w - 30 and x <= w - 20 then
  579. -- Increase yaw
  580. cannonTarget[cannonName].yawAdjust = cannonTarget[cannonName].yawAdjust + 0.1
  581. elseif x >= w - 19 and x <= w - 9 then
  582. -- Decrease yaw
  583. cannonTarget[cannonName].yawAdjust = cannonTarget[cannonName].yawAdjust - 0.1
  584. end
  585. monitor.clear()
  586. drawCannonAdjustmentPage()
  587. end
  588. yOffset = yOffset + 6
  589. end
  590. end
  591. end
  592. end
  593.  
  594. local function modemMessage()
  595. while true do
  596. if modem then
  597. local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  598. if channel == port5inchChannel then
  599. cannonData.port5inch.hitPosX = message.x
  600. cannonData.port5inch.hitPosY = message.y
  601. cannonData.port5inch.hitPosZ = message.z
  602. cannonData.port5inch.pitch = message.cannonPitch
  603. cannonData.port5inch.yaw = message.cannonYaw
  604. cannonData.port5inch.source = message.source
  605. elseif channel == starboard5inchChannel then
  606. cannonData.starboard5inch.hitPosX = message.x
  607. cannonData.starboard5inch.hitPosY = message.y
  608. cannonData.starboard5inch.hitPosZ = message.z
  609. cannonData.starboard5inch.pitch = message.cannonPitch
  610. cannonData.starboard5inch.yaw = message.cannonYaw
  611. cannonData.starboard5inch.source = message.source
  612. elseif channel == bow15inchChannel then
  613. cannonData.bow15inch.hitPosX = message.x
  614. cannonData.bow15inch.hitPosY = message.y
  615. cannonData.bow15inch.hitPosZ = message.z
  616. cannonData.bow15inch.pitch = message.cannonPitch
  617. cannonData.bow15inch.yaw = message.cannonYaw
  618. cannonData.bow15inch.source = message.source
  619. elseif channel == stern15inchChannel then
  620. cannonData.stern15inch.hitPosX = message.x
  621. cannonData.stern15inch.hitPosY = message.y
  622. cannonData.stern15inch.hitPosZ = message.z
  623. cannonData.stern15inch.pitch = message.cannonPitch
  624. cannonData.stern15inch.yaw = message.cannonYaw
  625. cannonData.stern15inch.source = message.source
  626. end
  627. else
  628. sleep()
  629. end
  630. end
  631. end
  632.  
  633. local function controlsSending()
  634. while true do
  635. modem.transmit(controlChannel, controlChannel, controls)
  636. sleep()
  637. end
  638. end
  639.  
  640. parallel.waitForAny(
  641. function()
  642. -- Main loop
  643. while true do
  644. if displayState == "radar" then
  645. monitor.clear()
  646. monitor.setTextScale(0.5)
  647. drawRadarDisplay()
  648. drawControls()
  649. elseif displayState == "targetInfo" and selectedTarget then
  650. displayTargetInfo(selectedTarget)
  651. elseif displayState == "adjustCannon" then
  652. monitor.clear()
  653. drawCannonAdjustmentPage()
  654. end
  655. sleep(0.1)
  656. -- Adjust this duration if needed
  657. end
  658. end,
  659. handleTouch,
  660. modemMessage,
  661. controlsSending
  662. )
  663.  
  664.  
  665.  
Advertisement
Add Comment
Please, Sign In to add comment