MegiRicky

fireControlTerminal

Aug 11th, 2024 (edited)
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.57 KB | None | 0 0
  1. local monitor = peripheral.find("monitor")
  2. local radar = peripheral.find("sp_radar")
  3. local modem = peripheral.wrap("top")
  4. local leftRouter = peripheral.wrap("left")
  5. local rightRouter = peripheral.wrap("right")
  6. local frontRouter = peripheral.find("redrouter")
  7. local backRouter = peripheral.wrap("back")
  8. local bal = peripheral.find("ballistic_accelerator")
  9.  
  10. -- Ensure all required peripherals are connected
  11. if not monitor or not radar or not ship then
  12. error("Required peripherals are not attached")
  13. end
  14.  
  15. print("Do you need front and back router, 1 for yes,0 for no")
  16. local yesOrNo = io.read()
  17. local includeBowAndStern = false
  18. if yesOrNo == "1" then
  19. includeBowAndStern = true
  20. print("connect Front router for bow turret, disconnect back router, and press enter")
  21. io.read()
  22. frontRouter = peripheral.find("redrouter")
  23.  
  24. print("Connect back router and disconnect front router, then press enter")
  25. io.read()
  26. backRouter = peripheral.find("redrouter")
  27.  
  28. print("Connect front and back router, then press enter")
  29. io.read()
  30. end
  31.  
  32. monitor.setTextScale(0.5)
  33. monitor.clear()
  34.  
  35. local radarScale = 100
  36. local friendlyID = {289, 232}
  37. local targetPositions = {}
  38. local waypoints = {}
  39. local displayState = "radar" -- Initial display state
  40. local selectedTarget = nil
  41. local lockedTargetId = nil
  42. local lockedWaypoint = nil -- Variable to store the locked waypoint
  43. local projectileSpeed = 320 --m/s
  44.  
  45. -- Get channel data for cannons
  46. local function getChannelInput(prompt, default)
  47. print(prompt .. ", default: " .. default)
  48. local input = io.read()
  49. if input == "" then
  50. input = default
  51. end
  52. return tonumber(input)
  53. end
  54.  
  55. local port5inchChannel = getChannelInput("Input the port side cannon data channel", 900)
  56. local starboard5inchChannel = getChannelInput("Input the starboard side cannon data channel", 901)
  57. local bow15inchChannel = getChannelInput("Input the bow cannon data channel", 902)
  58. local stern15inchChannel = getChannelInput("Input the stern cannon data channel", 903)
  59.  
  60. if modem then
  61. modem.open(starboard5inchChannel)
  62. modem.open(port5inchChannel)
  63. modem.open(bow15inchChannel)
  64. modem.open(stern15inchChannel)
  65. end
  66.  
  67. local cannonData = {
  68. port5inch = {hitPosX = nil, hitPosY = nil, hitPosZ = nil, pitch = nil, yaw = nil, source = {} },
  69. starboard5inch = {hitPosX = nil, hitPosY = nil, hitPosZ = nil, pitch = nil, yaw = nil, source = {}},
  70. bow15inch = {hitPosX = nil, hitPosY = nil, hitPosZ = nil, pitch = nil, yaw = nil, source = {}},
  71. stern15inch = {hitPosX = nil, hitPosY = nil, hitPosZ = nil, pitch = nil, yaw = nil, source = {}},
  72. }
  73.  
  74. local cannonTarget = {
  75. port5inch = { type = nil, side = "port", id = nil, x = nil, y = nil, z = nil, yawAdjust = 0, pitchAdjust = 0 },
  76. starboard5inch = { type = nil, side = "starboard", id = nil, x = nil, y = nil, z = nil, yawAdjust = 0, pitchAdjust = 0 },
  77. bow15inch = { type = nil, side = "bow", id = nil, x = nil, y = nil, z = nil, yawAdjust = 0, pitchAdjust = 0},
  78. stern15inch = { type = nil, side = "stern", id = nil, x = nil, y = nil, z = nil, yawAdjust = 0, pitchAdjust = 0},
  79. }
  80.  
  81. local function checkFriendly(ID)
  82. local friendly = false
  83. for _, id in ipairs(friendlyID) do
  84. if tonumber(ID) == tonumber(id) then
  85. friendly = true
  86. break
  87. end
  88. end
  89. return friendly
  90. end
  91.  
  92. local w, h = monitor.getSize()
  93.  
  94. local function drawControls()
  95. local w, h = monitor.getSize()
  96. monitor.setCursorPos(1, h-1)
  97. monitor.write(" ")
  98. monitor.setCursorPos(1, h)
  99. monitor.write(" ")
  100. monitor.setCursorPos(1, h-1)
  101. monitor.write("Scale: ")
  102. monitor.setCursorPos(8, h-1)
  103. monitor.write("-")
  104. monitor.setCursorPos(10, h-1)
  105. monitor.write("+")
  106. monitor.setCursorPos(1, h-2)
  107. monitor.write("Stop locking")
  108.  
  109. local segmentLength = radarScale / 2
  110. local scaleText
  111. if segmentLength >= 1000 then
  112. scaleText = string.format("%.1f km", segmentLength / 1000)
  113. else
  114. scaleText = string.format("%d m", segmentLength)
  115. end
  116.  
  117. monitor.setCursorPos(1, h)
  118. monitor.write("Segment Length: " .. scaleText)
  119.  
  120. -- Add button to navigate to waypoint page
  121. monitor.setCursorPos(w-10, h-1)
  122. monitor.write("Waypoints")
  123.  
  124. -- Add button to navigate to the cannon adjustment page
  125. monitor.setCursorPos(w-18, h-1)
  126. monitor.write("Adjust Cannon")
  127. end
  128.  
  129. local function drawControls()
  130. local w, h = monitor.getSize()
  131. monitor.setCursorPos(1, h-1)
  132. monitor.write(" ")
  133. monitor.setCursorPos(1, h)
  134. monitor.write(" ")
  135. monitor.setCursorPos(1, h-1)
  136. monitor.write("Scale: ")
  137. monitor.setCursorPos(8, h-1)
  138. monitor.write("-")
  139. monitor.setCursorPos(10, h-1)
  140. monitor.write("+")
  141. monitor.setCursorPos(1, h-2)
  142. monitor.write("Stop locking")
  143.  
  144. local segmentLength = radarScale / 2
  145. local scaleText
  146. if segmentLength >= 1000 then
  147. scaleText = string.format("%.1f km", segmentLength / 1000)
  148. else
  149. scaleText = string.format("%d m", segmentLength)
  150. end
  151.  
  152. monitor.setCursorPos(1, h)
  153. monitor.write("Segment Length: " .. scaleText)
  154.  
  155. -- Add button to navigate to waypoint page at the bottom right corner
  156. monitor.setCursorPos(w-10, h-1)
  157. monitor.write("Waypoints")
  158.  
  159. -- Add button to navigate to the cannon adjustment page at the top right corner
  160. monitor.setCursorPos(w-13, 1)
  161. monitor.write("Adjust Cannon")
  162. end
  163.  
  164. local function addWaypoint(x, y, z, color)
  165. local newWaypoint = {
  166. x = x,
  167. y = y,
  168. z = z,
  169. color = color or colors.purple
  170. }
  171. table.insert(waypoints, newWaypoint)
  172. end
  173.  
  174. local function drawWaypointPage()
  175. local w, h = monitor.getSize()
  176. monitor.clear()
  177. monitor.setCursorPos(1, 1)
  178. monitor.write("Waypoint Page")
  179. monitor.setCursorPos(1, 3)
  180. monitor.write("Enter coordinates (x, y, z) and color:")
  181. monitor.setCursorPos(1, 4)
  182. monitor.write("Format: x,y,z,color")
  183. monitor.setCursorPos(1, 5)
  184. monitor.write("Colors: red, yellow, green, blue, purple")
  185. monitor.setCursorPos(1, h-1)
  186. monitor.write("Enter to submit, Back to cancel.")
  187. end
  188.  
  189. local function drawCannonAdjustmentPage()
  190. local w, h = monitor.getSize()
  191. monitor.clear()
  192. monitor.setCursorPos(1, 1)
  193. monitor.write("Cannon Pitch and Yaw Adjustment")
  194.  
  195. local cannonNames = {
  196. {name = "Port 5 inch", data = cannonData.port5inch, target = cannonTarget.port5inch},
  197. {name = "Starboard 5 inch", data = cannonData.starboard5inch, target = cannonTarget.starboard5inch},
  198. {name = "Bow 15 inch", data = cannonData.bow15inch, target = cannonTarget.bow15inch},
  199. {name = "Stern 15 inch", data = cannonData.stern15inch, target = cannonTarget.stern15inch}
  200. }
  201.  
  202. local yOffset = 3
  203.  
  204. for _, cannon in ipairs(cannonNames) do
  205. monitor.setCursorPos(1, yOffset)
  206. monitor.write(cannon.name .. ":")
  207.  
  208. monitor.setCursorPos(1, yOffset + 1)
  209. monitor.write("Current: pitch: " .. (cannon.data.pitch and string.format("%.2f", cannon.data.pitch) or "N/A"))
  210. monitor.setCursorPos(26, yOffset + 1)
  211. monitor.write("yaw: " .. (cannon.data.yaw and string.format("%.2f", cannon.data.yaw) or "N/A"))
  212.  
  213. monitor.setCursorPos(1, yOffset + 2)
  214. monitor.write("Adjustment: pitch: " .. (cannon.target.pitchAdjust and string.format("%.2f", cannon.target.pitchAdjust) or "N/A"))
  215. monitor.setCursorPos(26, yOffset + 2)
  216. monitor.write("yaw: " .. (cannon.target.yawAdjust and string.format("%.2f", cannon.target.yawAdjust) or "N/A"))
  217.  
  218. monitor.setCursorPos(1, yOffset + 3)
  219. monitor.write("[pitch +] [pitch -]")
  220. monitor.setCursorPos(w - 30, yOffset + 3)
  221. monitor.write("[yaw +] [yaw -]")
  222.  
  223. yOffset = yOffset + 6 -- Move down for the next cannon
  224. end
  225.  
  226. monitor.setCursorPos(1, h)
  227. monitor.write("Back")
  228. end
  229.  
  230.  
  231.  
  232. local function drawRadarBackground(centerX, centerY, radius, shipYawRadians)
  233. local aspectRatio = 1.5
  234. local segmentLength = radarScale / 4
  235. local pixelPerSegmentX = w / 4
  236. local pixelPerSegmentY = h / 4
  237.  
  238. -- Draw the grid
  239. for i = 0, w - pixelPerSegmentX, pixelPerSegmentX do
  240. -- Vertical lines
  241. for y = 1, h - 2 do -- Leave space for the scale display at the bottom
  242. monitor.setCursorPos(i, y)
  243. monitor.write("|")
  244. end
  245. end
  246.  
  247. for j = 0, h - pixelPerSegmentY, pixelPerSegmentY do
  248. -- Horizontal lines
  249. for x = 1, w do
  250. monitor.setCursorPos(x, j)
  251. monitor.write("-")
  252. end
  253. end
  254.  
  255. -- Draw the circle
  256. for i = 0, 360, 5 do
  257. local rad = i * (math.pi / 180)
  258. local x = centerX + (radius * math.sin(rad)) * aspectRatio
  259. local y = centerY + radius * math.cos(rad)
  260. monitor.setCursorPos(math.floor(x + 0.5), math.floor(y + 0.5))
  261. monitor.write(".")
  262. end
  263.  
  264. -- Draw the crosshair
  265. for y = centerY - radius, centerY + radius do
  266. monitor.setCursorPos(centerX, y)
  267. monitor.write("|")
  268. end
  269.  
  270. local trueBearing = (math.deg(shipYawRadians) + 360) % 360 - 180
  271. if trueBearing < 0 then
  272. trueBearing = trueBearing + 360
  273. end
  274. local textPos = centerY - radius + 10
  275. if textPos > 0 then
  276. monitor.setCursorPos(centerX - (#tostring(math.floor(trueBearing)) + 2) / 2, textPos)
  277. monitor.write(tostring(math.floor(trueBearing)) .. "°")
  278. end
  279.  
  280. local directions = {"N", "W", "S", "E"}
  281. local dirAngles = {0, 90, 180, 270}
  282.  
  283. for index, dir in ipairs(directions) do
  284. local dirRad = (dirAngles[index] + math.deg(shipYawRadians)) * (math.pi / 180)
  285. local dirX = centerX + (radius * math.sin(dirRad)) * aspectRatio
  286. local dirY = centerY + radius * math.cos(dirRad)
  287. monitor.setCursorPos(math.floor(dirX + 0.5), math.floor(dirY + 0.5))
  288. monitor.write(dir)
  289. end
  290.  
  291. -- Display segment length
  292. monitor.setCursorPos(1, centerY + radius + 2)
  293. monitor.write("Segment Length: " .. segmentLength .. " meters")
  294. end
  295.  
  296. local function drawTargetOnCircle(centerX, centerY, radius, relX, relY, aspectRatio)
  297. local dx = relX - centerX
  298. local dy = relY - centerY
  299. local mag = math.sqrt((dx / aspectRatio)^2 + dy^2)
  300.  
  301. if (mag > radius) then
  302. local intersectX = centerX + ((dx / mag) * radius) * aspectRatio
  303. local intersectY = centerY + (dy / mag) * radius
  304. return intersectX, intersectY
  305. else
  306. return relX, relY
  307. end
  308. end
  309.  
  310. local function drawCannonCrosshair(centerX, centerY, radius, aspectRatio)
  311. local pos = ship.getWorldspacePosition()
  312. local shipYawRadians = math.atan2(-ship.getRotationMatrix()[1][3], ship.getRotationMatrix()[3][3])
  313. if shipYawRadians < 0 then shipYawRadians = shipYawRadians + 2 * math.pi end
  314. -- Function to calculate relative yaw in degrees from ship's facing
  315. local function relativeYaw(dx, dz)
  316. local angle = math.atan2(dx, dz)
  317. local relativeAngle = angle + shipYawRadians - math.pi
  318. if relativeAngle < -math.pi then
  319. relativeAngle = relativeAngle + 2 * math.pi
  320. elseif relativeAngle >= math.pi then
  321. relativeAngle = relativeAngle - 2 * math.pi
  322. end
  323. return math.deg(relativeAngle)
  324. end
  325.  
  326. local function drawCrosshairForCannon(cannonData, color)
  327. if cannonData.hitPosX and cannonData.hitPosZ then
  328. local dx = cannonData.hitPosX - pos.x
  329. local dz = cannonData.hitPosZ - pos.z
  330. local cannonYaw = relativeYaw(dx, dz)
  331. local distance = math.sqrt(dx^2 + dz^2)
  332. local scaledDistance = (distance / radarScale) * radius
  333. local relX = centerX + (scaledDistance * math.sin(math.rad(cannonYaw))) * aspectRatio
  334. local relY = centerY + scaledDistance * math.cos(math.rad(cannonYaw))
  335. relX, relY = drawTargetOnCircle(centerX, centerY, radius, relX, relY, aspectRatio)
  336. monitor.setCursorPos(math.floor(relX + 0.5), math.floor(relY + 0.5))
  337. monitor.setBackgroundColor(color)
  338. monitor.write("X")
  339. monitor.setBackgroundColor(colors.black)
  340. return cannonYaw
  341. end
  342. return nil
  343. end
  344.  
  345. -- Draw crosshair and check range for each cannon
  346. local portYaw = drawCrosshairForCannon(cannonData.port5inch, colors.red)
  347. if portYaw and not(portYaw > 225 and portYaw < 330) then
  348. monitor.setCursorPos(1, 1)
  349. monitor.write("Warning: Port cannon may hit the ship!")
  350. end
  351.  
  352. local starboardYaw = drawCrosshairForCannon(cannonData.starboard5inch, colors.blue)
  353. if starboardYaw and not(starboardYaw > 30 and starboardYaw < 135) then
  354. monitor.setCursorPos(1, 2)
  355. monitor.write("Warning: Starboard cannon may hit the ship!")
  356. end
  357.  
  358. local bowYaw = drawCrosshairForCannon(cannonData.bow15inch, colors.green)
  359. if bowYaw and not(bowYaw > 120 and bowYaw < 240) then
  360. monitor.setCursorPos(1, 3)
  361. monitor.write("Warning: Bow cannon may hit the ship!")
  362. end
  363.  
  364. local sternYaw = drawCrosshairForCannon(cannonData.stern15inch, colors.yellow)
  365. if sternYaw and not(sternYaw > 300 or sternYaw < 60) then
  366. monitor.setCursorPos(1, 4)
  367. monitor.write("Warning: Stern cannon may hit the ship!")
  368. end
  369. end
  370.  
  371. local function calculateRelativeAngle(objectAngle, shipYawRadians)
  372. local relativeAngle = objectAngle + shipYawRadians - math.pi
  373. if relativeAngle < -math.pi then
  374. relativeAngle = relativeAngle + 2 * math.pi
  375. elseif relativeAngle >= math.pi then
  376. relativeAngle = relativeAngle - 2 * math.pi
  377. end
  378. return relativeAngle
  379. end
  380.  
  381. local function drawRadarDisplay()
  382. local w, h = monitor.getSize()
  383. local centerX, centerY = math.floor(w / 2), math.floor(h / 2)
  384. local radius = math.min(centerX, centerY) - 1
  385. local aspectRatio = 1.2
  386.  
  387. local matrix = ship.getRotationMatrix()
  388. local shipYawRadians = math.atan2(-matrix[1][3], matrix[3][3])
  389. if (shipYawRadians < 0) then
  390. shipYawRadians = shipYawRadians + 2 * math.pi
  391. end
  392.  
  393. drawRadarBackground(centerX, centerY, radius, shipYawRadians)
  394. monitor.setCursorPos(centerX, centerY)
  395. monitor.write("+")
  396.  
  397. drawCannonCrosshair(centerX, centerY, radius, aspectRatio)
  398.  
  399. local pos = ship.getWorldspacePosition()
  400. local results = radar.scanForShips(10000)
  401. targetPositions = {}
  402. for _, object in ipairs(results) do
  403. local x = object.pos.x - pos.x
  404. local z = object.pos.z - pos.z
  405. local distance = math.sqrt(x^2 + z^2)
  406. local objectAngle = math.atan2(x, z)
  407. local relativeAngle = calculateRelativeAngle(objectAngle, shipYawRadians)
  408.  
  409. local scaledDistance = (distance / radarScale) * radius
  410. local relX = centerX + (scaledDistance * math.sin(relativeAngle)) * aspectRatio
  411. local relY = centerY + scaledDistance * math.cos(relativeAngle)
  412.  
  413. relX, relY = drawTargetOnCircle(centerX, centerY, radius, relX, relY, aspectRatio)
  414.  
  415. if (object.mass > 20000 and distance > 5) then
  416. if (distance > radarScale) then
  417. monitor.setTextColor(colors.lightBlue)
  418. else
  419. monitor.setTextColor(colors.red)
  420. end
  421. if (checkFriendly(object.id)) then
  422. monitor.setBackgroundColor(colors.blue)
  423. elseif (object.mass > 1000000) then
  424. monitor.setBackgroundColor(colors.orange)
  425. elseif (math.sqrt(object.velocity.x ^ 2 + object.velocity.y ^ 2 + object.velocity.z ^ 2) > 30) then
  426. monitor.setBackgroundColor(colors.red)
  427. else
  428. monitor.setBackgroundColor(colors.yellow)
  429. end
  430. monitor.setCursorPos(math.floor(relX + 0.5), math.floor(relY + 0.5))
  431. monitor.write("o")
  432. monitor.setTextColor(colors.green)
  433. monitor.setBackgroundColor(colors.black)
  434.  
  435. table.insert(targetPositions, {x = math.floor(relX + 0.5), y = math.floor(relY + 0.5), data = object})
  436. end
  437. end
  438.  
  439. -- Draw waypoints
  440. for index, waypoint in ipairs(waypoints) do
  441. local wpX = waypoint.x - pos.x
  442. local wpZ = waypoint.z - pos.z
  443. local distance = math.sqrt(wpX^2 + wpZ^2)
  444. local wpAngle = math.atan2(wpX, wpZ)
  445. local relativeAngle = calculateRelativeAngle(wpAngle, shipYawRadians)
  446.  
  447. local scaledDistance = (distance / radarScale) * radius
  448. local relX = centerX + (scaledDistance * math.sin(relativeAngle)) * aspectRatio
  449. local relY = centerY + scaledDistance * math.cos(relativeAngle)
  450.  
  451. relX, relY = drawTargetOnCircle(centerX, centerY, radius, relX, relY, aspectRatio)
  452.  
  453. monitor.setBackgroundColor(waypoint.color)
  454. monitor.setCursorPos(math.floor(relX + 0.5), math.floor(relY + 0.5))
  455. monitor.write("W")
  456. monitor.setBackgroundColor(colors.black)
  457.  
  458. 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}})
  459. end
  460. end
  461.  
  462. local function displayTargetInfo(target)
  463. local w, h = monitor.getSize()
  464. local pos = ship.getWorldspacePosition()
  465.  
  466. monitor.clear()
  467. monitor.setCursorPos(1, h-12)
  468. monitor.write("Target Info")
  469. monitor.setCursorPos(1, h-11)
  470.  
  471. local targetPosX, targetPosY, targetPosZ
  472. if target.type == "waypoint" then
  473. monitor.write("Type: Waypoint")
  474. targetPosX, targetPosY, targetPosZ = target.x, target.y, target.z
  475. monitor.setCursorPos(1, h-7)
  476. monitor.write("Coordinate: " .. target.x .. ", "..target.y..", ".. target.z)
  477. else
  478. monitor.write("ID: " .. target.id)
  479. targetPosX, targetPosY, targetPosZ = target.pos.x, target.pos.y, target.pos.z
  480. monitor.setCursorPos(1, h-10)
  481. monitor.write("Mass: " .. target.mass)
  482. monitor.setCursorPos(1, h-9)
  483. monitor.write("Velocity: " .. string.format("%.2f, %.2f, %.2f", target.velocity.x, target.velocity.y, target.velocity.z))
  484. monitor.setCursorPos(1, h-8)
  485. monitor.write("Position: " .. string.format("%.2f, %.2f, %.2f", target.pos.x, target.pos.y, target.pos.z))
  486. end
  487.  
  488. local distance = math.sqrt((targetPosX - pos.x)^2 + (targetPosZ - pos.z)^2)
  489. local dx = targetPosX - pos.x
  490. local dz = targetPosZ - pos.z
  491. local bearing = (math.deg(math.atan2(dz, dx)) + 360) % 360 - 270
  492. if bearing < 0 then
  493. bearing = bearing + 360
  494. end
  495.  
  496. monitor.setCursorPos(1, h-7)
  497. monitor.write("Distance: " .. string.format("%.2f", distance) .. " meters")
  498. monitor.setCursorPos(1, h-6)
  499. monitor.write("Bearing: " .. string.format("%.2f", bearing) .. "°")
  500.  
  501. if target.type ~= "waypoint" then
  502. local type = "unknown"
  503. local hostile = "hostile"
  504. if target.mass > 1000000 then
  505. type = "ship"
  506. elseif math.sqrt(target.velocity.x ^ 2 + target.velocity.y ^ 2 + target.velocity.z ^ 2) > 30 then
  507. type = "Flying missile / plane"
  508. else
  509. type = "unknown"
  510. end
  511. if checkFriendly(target.id) then
  512. hostile = "friendly"
  513. else
  514. hostile = "hostile"
  515. end
  516. monitor.setCursorPos(1, h-5)
  517. monitor.write("Type: " .. hostile .. " " .. type)
  518. end
  519.  
  520. if target.type == "waypoint" then
  521. monitor.setCursorPos(1, h-5)
  522. monitor.write("[Lock Waypoint with port gun]")
  523. monitor.setCursorPos(1, h-4)
  524. monitor.write("[Lock Waypoint with starboard gun]")
  525. monitor.setCursorPos(1, h-3)
  526. monitor.write("[Lock Waypoint with bow gun]")
  527. monitor.setCursorPos(1, h-2)
  528. monitor.write("[Lock Waypoint with stern gun]")
  529. else
  530. monitor.setCursorPos(1, h-5)
  531. monitor.write("[Lock Target with port gun]")
  532. monitor.setCursorPos(1, h-4)
  533. monitor.write("[Lock Target with starboard gun]")
  534. monitor.setCursorPos(1, h-3)
  535. monitor.write("[Lock Target with bow gun]")
  536. monitor.setCursorPos(1, h-2)
  537. monitor.write("[Lock Target with stern gun]")
  538. end
  539. monitor.setCursorPos(1, h)
  540. monitor.write("Back")
  541. end
  542.  
  543. local function handleTouch()
  544. local w, h = monitor.getSize()
  545. while true do
  546. local event, side, x, y = os.pullEvent("monitor_touch")
  547. if displayState == "radar" then
  548. if y == h-1 and x >= 8 and x <= 9 then
  549. radarScale = math.max(100, radarScale - 100)
  550. drawControls()
  551. drawRadarDisplay()
  552. elseif y == h-1 and x >= 10 and x <= 11 then
  553. radarScale = math.min(10000, radarScale + 100)
  554. drawControls()
  555. drawRadarDisplay()
  556. elseif y == h-1 and x >= w-10 and x <= w then
  557. displayState = "waypoints"
  558. monitor.clear()
  559. drawWaypointPage()
  560. print("Enter waypoint coordinates (x, y, z, color), color options: red, yellow, green, blue:")
  561. local input = read()
  562. local x, y, z, color = input:match("([^,]+),([^,]+),([^,]+),([^,]*)")
  563. local colorValue = colors.purple
  564. if color then
  565. local colorMap = {
  566. purple = colors.purple,
  567. red = colors.red,
  568. yellow = colors.yellow,
  569. green = colors.green,
  570. blue = colors.blue,
  571. white = colors.white,
  572. orange = colors.orange,
  573. lightBlue = colors.lightBlue,
  574. lime = colors.lime,
  575. pink = colors.pink,
  576. gray = colors.gray,
  577. lightGray = colors.lightGray,
  578. cyan = colors.cyan,
  579. purple = colors.purple,
  580. brown = colors.brown,
  581. black = colors.black
  582. }
  583. colorValue = colorMap[color] or colors.purple
  584. end
  585. if x and y and z then
  586. addWaypoint(tonumber(x), tonumber(y), tonumber(z), colorValue)
  587. end
  588. displayState = "radar"
  589. monitor.clear()
  590. drawControls()
  591. drawRadarDisplay()
  592. elseif y == 1 and x >= w-13 and x <= w then
  593. displayState = "adjustCannon"
  594. monitor.clear()
  595. drawCannonAdjustmentPage()
  596. elseif y == h-2 and x < 10 then
  597. cannonTarget.port5inch = { type = nil, side = "port", id = nil, x = nil, y = nil, z = nil, pitchAdjust = 0, yawAdjust = 0 }
  598. cannonTarget.starboard5inch = { type = nil, side = "starboard", id = nil, x = nil, y = nil, z = nil, pitchAdjust = 0, yawAdjust = 0 }
  599. cannonTarget.bow15inch = { type = nil, side = "bow", id = nil, x = nil, y = nil, z = nil, pitchAdjust = 0, yawAdjust = 0 }
  600. cannonTarget.stern15inch = { type = nil, side = "stern", id = nil, x = nil, y = nil, z = nil, pitchAdjust = 0, yawAdjust = 0 }
  601. monitor.setCursorPos(1, 1)
  602. monitor.clear()
  603. drawRadarDisplay()
  604. monitor.write("Locking stopped.")
  605. else
  606. for _, target in ipairs(targetPositions) do
  607. if x == target.x and y == target.y then
  608. selectedTarget = target.data
  609. displayState = "targetInfo"
  610. displayTargetInfo(selectedTarget)
  611. break
  612. end
  613. end
  614. end
  615. elseif displayState == "targetInfo" then
  616. if y == h and x >= 1 and x <= 4 then
  617. -- Back button
  618. displayState = "radar"
  619. monitor.clear()
  620. drawRadarDisplay()
  621. elseif y == h-5 and x >= 1 and x <= 28 then
  622. -- Lock with port cannon
  623. if selectedTarget.type == "waypoint" then
  624. cannonTarget.port5inch.type = "waypoint"
  625. cannonTarget.port5inch.x = selectedTarget.x
  626. cannonTarget.port5inch.y = selectedTarget.y
  627. cannonTarget.port5inch.z = selectedTarget.z
  628. cannonTarget.port5inch.id = nil
  629. else
  630. cannonTarget.port5inch.id = selectedTarget.id
  631. cannonTarget.port5inch.type = "target"
  632. cannonTarget.port5inch.x = nil
  633. cannonTarget.port5inch.y = nil
  634. cannonTarget.port5inch.z = nil
  635. end
  636. displayState = "radar"
  637. monitor.clear()
  638. drawRadarDisplay()
  639. monitor.setCursorPos(1, 1)
  640. monitor.write("Target locked: " .. (selectedTarget.type == "waypoint" and "Waypoint" or selectedTarget.id))
  641. elseif y == h-4 and x >= 1 and x <= 32 then
  642. -- Lock with starboard cannon
  643. if selectedTarget.type == "waypoint" then
  644. cannonTarget.starboard5inch.type = "waypoint"
  645. cannonTarget.starboard5inch.x = selectedTarget.x
  646. cannonTarget.starboard5inch.y = selectedTarget.y
  647. cannonTarget.starboard5inch.z = selectedTarget.z
  648. cannonTarget.starboard5inch.id = nil
  649. else
  650. cannonTarget.starboard5inch.id = selectedTarget.id
  651. cannonTarget.starboard5inch.type = "target"
  652. cannonTarget.starboard5inch.x = nil
  653. cannonTarget.starboard5inch.y = nil
  654. cannonTarget.starboard5inch.z = nil
  655. end
  656. displayState = "radar"
  657. monitor.clear()
  658. drawRadarDisplay()
  659. monitor.setCursorPos(1, 1)
  660. monitor.write("Target locked: " .. (selectedTarget.type == "waypoint" and "Waypoint" or selectedTarget.id))
  661. elseif y == h-3 and x >= 1 and x <= 22 then
  662. -- Lock with bow cannon
  663. if selectedTarget.type == "waypoint" then
  664. cannonTarget.bow15inch.type = "waypoint"
  665. cannonTarget.bow15inch.x = selectedTarget.x
  666. cannonTarget.bow15inch.y = selectedTarget.y
  667. cannonTarget.bow15inch.z = selectedTarget.z
  668. cannonTarget.bow15inch.id = nil
  669. else
  670. cannonTarget.bow15inch.id = selectedTarget.id
  671. cannonTarget.bow15inch.type = "target"
  672. cannonTarget.bow15inch.x = nil
  673. cannonTarget.bow15inch.y = nil
  674. cannonTarget.bow15inch.z = nil
  675. end
  676. displayState = "radar"
  677. monitor.clear()
  678. drawRadarDisplay()
  679. monitor.setCursorPos(1, 1)
  680. monitor.write("Target locked: " .. (selectedTarget.type == "waypoint" and "Waypoint" or selectedTarget.id))
  681. elseif y == h-2 and x >= 1 and x <= 22 then
  682. -- Lock with stern cannon
  683. if selectedTarget.type == "waypoint" then
  684. cannonTarget.stern15inch.type = "waypoint"
  685. cannonTarget.stern15inch.x = selectedTarget.x
  686. cannonTarget.stern15inch.y = selectedTarget.y
  687. cannonTarget.stern15inch.z = selectedTarget.z
  688. cannonTarget.stern15inch.id = nil
  689. else
  690. cannonTarget.stern15inch.id = selectedTarget.id
  691. cannonTarget.stern15inch.type = "target"
  692. cannonTarget.stern15inch.x = nil
  693. cannonTarget.stern15inch.y = nil
  694. cannonTarget.stern15inch.z = nil
  695. end
  696. displayState = "radar"
  697. monitor.clear()
  698. drawRadarDisplay()
  699. monitor.setCursorPos(1, 1)
  700. monitor.write("Target locked: " .. (selectedTarget.type == "waypoint" and "Waypoint" or selectedTarget.id))
  701. end
  702. elseif displayState == "adjustCannon" then
  703. -- Back button
  704. if y == h and x >= 1 and x <= 4 then
  705. displayState = "radar"
  706. monitor.clear()
  707. drawRadarDisplay()
  708. end
  709.  
  710. -- Detect pitch and yaw adjustment button presses
  711. local yOffset = 3
  712. local buttonWidth = 10
  713. for i, cannonName in ipairs({"port5inch", "starboard5inch", "bow15inch", "stern15inch"}) do
  714. if y == yOffset + 3 then
  715. if x >= 1 and x <= 10 then
  716. -- Increase pitch
  717. cannonTarget[cannonName].pitchAdjust = cannonTarget[cannonName].pitchAdjust + 0.1
  718. elseif x >= 11 and x <= 20 then
  719. -- Decrease pitch
  720. cannonTarget[cannonName].pitchAdjust = cannonTarget[cannonName].pitchAdjust - 0.1
  721. elseif x >= w - 30 and x <= w - 20 then
  722. -- Increase yaw
  723. cannonTarget[cannonName].yawAdjust = cannonTarget[cannonName].yawAdjust + 0.1
  724. elseif x >= w - 19 and x <= w - 9 then
  725. -- Decrease yaw
  726. cannonTarget[cannonName].yawAdjust = cannonTarget[cannonName].yawAdjust - 0.1
  727. end
  728. monitor.clear()
  729. drawCannonAdjustmentPage()
  730. end
  731. yOffset = yOffset + 6
  732. end
  733. end
  734. end
  735. end
  736.  
  737. local function modemMessage()
  738. while true do
  739. if modem then
  740. local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  741. if channel == port5inchChannel then
  742. cannonData.port5inch.hitPosX = message.x
  743. cannonData.port5inch.hitPosY = message.y
  744. cannonData.port5inch.hitPosZ = message.z
  745. cannonData.port5inch.pitch = message.cannonPitch
  746. cannonData.port5inch.yaw = message.cannonYaw
  747. cannonData.port5inch.source = message.source
  748. elseif channel == starboard5inchChannel then
  749. cannonData.starboard5inch.hitPosX = message.x
  750. cannonData.starboard5inch.hitPosY = message.y
  751. cannonData.starboard5inch.hitPosZ = message.z
  752. cannonData.starboard5inch.pitch = message.cannonPitch
  753. cannonData.starboard5inch.yaw = message.cannonYaw
  754. cannonData.starboard5inch.source = message.source
  755. elseif channel == bow15inchChannel then
  756. cannonData.bow15inch.hitPosX = message.x
  757. cannonData.bow15inch.hitPosY = message.y
  758. cannonData.bow15inch.hitPosZ = message.z
  759. cannonData.bow15inch.pitch = message.cannonPitch
  760. cannonData.bow15inch.yaw = message.cannonYaw
  761. cannonData.bow15inch.source = message.source
  762. elseif channel == stern15inchChannel then
  763. cannonData.stern15inch.hitPosX = message.x
  764. cannonData.stern15inch.hitPosY = message.y
  765. cannonData.stern15inch.hitPosZ = message.z
  766. cannonData.stern15inch.pitch = message.cannonPitch
  767. cannonData.stern15inch.yaw = message.cannonYaw
  768. cannonData.stern15inch.source = message.source
  769. end
  770. else
  771. sleep()
  772. end
  773. end
  774. end
  775.  
  776. local function calculateRange(angle, u, cd, g, c_est, vm)
  777. local radians = math.rad(angle)
  778. local u = vm/20
  779. local part1 = u * math.cos(radians) / math.log(cd)
  780. local part2 = ((g * cd) / (g * cd + (1 - cd) * u * math.sin(radians))) ^ (2 + c_est * vm * math.sin(radians)) - 1
  781. local XR = part1 * part2
  782.  
  783. return XR
  784. end
  785.  
  786. local function findBestPitch(targetX, targetY, targetZ, sourceX, sourceY, sourceZ, initialVelocity, g, cd, c_est, vm)
  787. local bestLowPitch = nil
  788. local bestHighPitch = nil
  789. local bestLowDistance = math.huge
  790. local bestHighDistance = math.huge
  791. local targetDistance = math.sqrt((targetX - sourceX)^2 + (targetZ - sourceZ)^2)
  792.  
  793. for pitch = 0, 70, 0.01 do -- Iterate over pitch angles
  794. local calculatedRange = calculateRange(pitch, initialVelocity, cd, g, c_est, vm)
  795. local distanceDifference = math.abs(calculatedRange - targetDistance)
  796.  
  797. -- Find the low-angle solution
  798. if pitch <= 30 then
  799. if distanceDifference < bestLowDistance then
  800. bestLowDistance = distanceDifference
  801. bestLowPitch = pitch
  802. end
  803. -- Find the high-angle solution
  804. elseif pitch > 30 then
  805. if distanceDifference < bestHighDistance then
  806. bestHighDistance = distanceDifference
  807. bestHighPitch = pitch
  808. end
  809. end
  810. end
  811.  
  812. -- If the target is within 400 blocks, prioritize the low-angle solution
  813. if targetDistance <= 830 then
  814. return bestLowPitch or bestLowPitch
  815. else
  816. return bestHighPitch or bestLowPitch
  817. end
  818. end
  819.  
  820. local function aimCannon(targetPos, targetVel, sourceX, sourceY, sourceZ, currentPitch, currentYaw, side)
  821. if sourceX and sourceY and sourceZ and currentPitch and currentYaw then
  822. -- Set the gravitational constant and muzzle velocity based on the turret type
  823. local g, vm
  824. if side == "port" or side == "starboard" then
  825. g = 0.04
  826. vm = 330
  827. elseif side == "bow" or side == "stern" then
  828. g = 0.05
  829. vm = 280
  830. end
  831.  
  832. -- Calculate future position of the target
  833. local dx = targetPos.x - sourceX
  834. local dy = targetPos.y - sourceY
  835. local dz = targetPos.z - sourceZ
  836. local distance = math.sqrt(dx^2 + dy^2 + dz^2)
  837. local estimateTime = distance / vm / 2
  838. local estimateX = targetPos.x + targetVel.x * estimateTime
  839. local estimateY = targetPos.y + targetVel.y * estimateTime
  840. local estimateZ = targetPos.z + targetVel.z * estimateTime
  841.  
  842. dx = estimateX - sourceX
  843. dy = estimateY - sourceY
  844. dz = estimateZ - sourceZ
  845.  
  846. local horizontalDistance = math.sqrt(dx^2 + dz^2)
  847.  
  848. -- Use the custom formula to find the best pitch
  849. local pitch = findBestPitch(estimateX, estimateY, estimateZ, sourceX, sourceY, sourceZ, vm, g, 0.99, 0.0028, vm)
  850. local yaw = math.deg(math.atan2(-dx, dz)) + 180
  851. print(pitch)
  852. if pitch < 30 then
  853. pitch = pitch + math.deg(math.atan2(dy, horizontalDistance))
  854. end
  855. local adjustedPitch, adjustedYaw
  856. -- Apply pitch and yaw adjustments specific to the cannon
  857. if side == "port" or side == "starboard" then
  858. adjustedPitch = pitch + cannonTarget[side.."5inch"].pitchAdjust
  859. adjustedYaw = yaw + cannonTarget[side.."5inch"].yawAdjust
  860. elseif side == "bow" or side == "stern" then
  861. adjustedPitch = pitch + cannonTarget[side.."15inch"].pitchAdjust
  862. adjustedYaw = yaw + cannonTarget[side.."15inch"].yawAdjust
  863. end
  864. print(side.." adjustedPitch: "..adjustedPitch)
  865. -- Calculate angle differences
  866. local deltaYaw = (adjustedYaw - currentYaw + 180) % 360 - 180
  867. local deltaPitch = adjustedPitch - currentPitch
  868.  
  869. -- Determine which router to use based on side
  870. local yawRouter, pitchRouter
  871. if side == "port" then
  872. yawRouter = leftRouter
  873. pitchRouter = leftRouter -- Adjust this if pitch is controlled by a different mechanism
  874. elseif side == "starboard" then
  875. yawRouter = rightRouter
  876. pitchRouter = rightRouter -- Adjust this if pitch is controlled by a different mechanism
  877. elseif side == "bow" then
  878. yawRouter = frontRouter
  879. pitchRouter = frontRouter
  880. elseif side == "stern" then
  881. yawRouter = backRouter
  882. pitchRouter = backRouter
  883. end
  884.  
  885. local yaw_tolerance = 0.3
  886. local pitch_tolerance = 0.08
  887. --yaw adjustment
  888. if math.abs(deltaYaw) > yaw_tolerance then
  889. if deltaYaw < 0 then
  890. print("Turning left")
  891. yawRouter.setOutput("right", false)
  892. if math.abs(deltaYaw) < 10 then
  893. local turnTime = math.max(math.abs(deltaYaw) / 6,0.1)
  894. yawRouter.setOutput("left", true)
  895. sleep(turnTime)
  896. yawRouter.setOutput("left", false)
  897. else
  898. yawRouter.setOutput("left", true)
  899. end
  900. elseif deltaYaw > 0 then
  901. print("Turning right")
  902. yawRouter.setOutput("left", false)
  903. if math.abs(deltaYaw) < 10 then
  904. local turnTime = math.max(math.abs(deltaYaw) / 6,0.1)
  905. yawRouter.setOutput("right", true)
  906. sleep(turnTime)
  907. yawRouter.setOutput("right", false)
  908. else
  909. yawRouter.setOutput("right", true)
  910. end
  911. end
  912. else
  913. yawRouter.setOutput("right", false)
  914. yawRouter.setOutput("left", false)
  915. end
  916. --pitch adjustment
  917. if math.abs(deltaPitch) > pitch_tolerance then
  918. if deltaPitch > 0 then
  919. print("Adjusting pitch up")
  920. pitchRouter.setOutput("front", false)
  921. if math.abs(deltaPitch) < 5 then
  922. local turnTime = math.max(math.abs(deltaPitch) / 3,0.1)
  923. pitchRouter.setOutput("top", true)
  924. sleep(turnTime)
  925. pitchRouter.setOutput("top", false)
  926. else
  927. pitchRouter.setOutput("top", true)
  928. end
  929. else
  930. print("Adjusting pitch down")
  931. pitchRouter.setOutput("top", false)
  932. if math.abs(deltaPitch) < 5 then
  933. local turnTime = math.max(math.abs(deltaPitch) / 3,0.1)
  934. pitchRouter.setOutput("front", true)
  935. sleep(turnTime)
  936. pitchRouter.setOutput("front", false)
  937. else
  938. pitchRouter.setOutput("front", true)
  939. end
  940. end
  941. else
  942. pitchRouter.setOutput("front", false)
  943. pitchRouter.setOutput("top", false)
  944. end
  945. end
  946. end
  947.  
  948. local function aimPortCannonContinuous()
  949. while true do
  950. local cannon = cannonTarget.port5inch
  951. if cannon.type then
  952. local target
  953. monitor.setCursorPos(1,3)
  954. if cannon.type=="waypoint" then
  955. monitor.write("Port waypoint locked: "..cannon.x.." , "..cannon.y.." , "..cannon.z)
  956. else
  957. monitor.write("Port ship locked: "..cannon.id)
  958. end
  959. if cannon.type == "waypoint" then
  960. target = {pos = {x = cannon.x, y = cannon.y, z = cannon.z}, velocity = {x = 0, y = 0, z = 0}}
  961. else -- handling target
  962. local scanResults = radar.scanForShips(5000)
  963. for _, object in ipairs(scanResults) do
  964. if object.id == cannon.id then
  965. target = object
  966. break
  967. end
  968. end
  969. end
  970.  
  971. if target and target.pos then
  972. aimCannon(target.pos, target.velocity, cannonData.port5inch.source.x, cannonData.port5inch.source.y, cannonData.port5inch.source.z, cannonData.port5inch.pitch, cannonData.port5inch.yaw, "port", 330)
  973. end
  974. else
  975. if leftRouter.setOutput then
  976. -- Ensure that outputs are reset when not actively aiming
  977. leftRouter.setOutput("top", false)
  978. leftRouter.setOutput("left", false)
  979. leftRouter.setOutput("right", false)
  980. leftRouter.setOutput("front", false)
  981. end
  982. end
  983. sleep() -- Adjust sleep duration based on required reaction time
  984. end
  985. end
  986.  
  987. local function aimStarboardCannonContinuous()
  988. while true do
  989. local cannon = cannonTarget.starboard5inch
  990. if cannon.type then
  991. local target
  992. monitor.setCursorPos(1,4)
  993. if cannon.type=="waypoint" then
  994. monitor.write("Starboard waypoint locked: "..cannon.x.." , "..cannon.y.." , "..cannon.z)
  995. else
  996. monitor.write("Starboard ship locked: "..cannon.id)
  997. end
  998. if cannon.type == "waypoint" then
  999. target = {pos = {x = cannon.x, y = cannon.y, z = cannon.z}, velocity = {x = 0, y = 0, z = 0}}
  1000. else -- handling target
  1001. local scanResults = radar.scanForShips(5000)
  1002. for _, object in ipairs(scanResults) do
  1003. if object.id == cannon.id then
  1004. target = object
  1005. break
  1006. end
  1007. end
  1008. end
  1009.  
  1010. if target and target.pos then
  1011. aimCannon(target.pos, target.velocity, cannonData.starboard5inch.source.x, cannonData.starboard5inch.source.y, cannonData.starboard5inch.source.z, cannonData.starboard5inch.pitch, cannonData.starboard5inch.yaw, "starboard", 330)
  1012. end
  1013. else
  1014. if rightRouter.setOutput then
  1015. -- Ensure that outputs are reset when not actively aiming
  1016. rightRouter.setOutput("top", false)
  1017. rightRouter.setOutput("left", false)
  1018. rightRouter.setOutput("right", false)
  1019. rightRouter.setOutput("front", false)
  1020. end
  1021. end
  1022. sleep()
  1023. end
  1024. end
  1025.  
  1026. local function aimBowCannonContinuous()
  1027. while true do
  1028. local cannon = cannonTarget.bow15inch
  1029. if frontRouter then
  1030. if cannon.type then
  1031. local target
  1032. monitor.setCursorPos(1,5)
  1033. if cannon.type=="waypoint" then
  1034. monitor.write("Bow waypoint locked: "..cannon.x.." , "..cannon.y.." , "..cannon.z)
  1035. else
  1036. monitor.write("Bow ship locked: "..cannon.id)
  1037. end
  1038. if cannon.type == "waypoint" then
  1039. target = {pos = {x = cannon.x, y = cannon.y, z = cannon.z}, velocity = {x = 0, y = 0, z = 0}}
  1040. else -- handling target
  1041. local scanResults = radar.scanForShips(5000)
  1042. for _, object in ipairs(scanResults) do
  1043. if object.id == cannon.id then
  1044. target = object
  1045. break
  1046. end
  1047. end
  1048. end
  1049.  
  1050. if target and target.pos then
  1051. aimCannon(target.pos, target.velocity, cannonData.bow15inch.source.x, cannonData.bow15inch.source.y, cannonData.bow15inch.source.z, cannonData.bow15inch.pitch, cannonData.bow15inch.yaw, "bow", 280)
  1052. end
  1053. else
  1054. if frontRouter and frontRouter.setOutput then
  1055. -- Ensure that outputs are reset when not actively aiming
  1056. frontRouter.setOutput("top", false)
  1057. frontRouter.setOutput("left", false)
  1058. frontRouter.setOutput("right", false)
  1059. frontRouter.setOutput("front", false)
  1060. end
  1061. end
  1062. end
  1063. sleep()
  1064. end
  1065. end
  1066.  
  1067. local function aimSternCannonContinuous()
  1068. while true do
  1069. local cannon = cannonTarget.stern15inch
  1070. if backRouter then
  1071. if cannon.type then
  1072. local target
  1073. monitor.setCursorPos(1,6)
  1074. if cannon.type=="waypoint" then
  1075. monitor.write("Stern waypoint locked: "..cannon.x.." , "..cannon.y.." , "..cannon.z)
  1076. else
  1077. monitor.write("Stern ship locked: "..cannon.id)
  1078. end
  1079. if cannon.type == "waypoint" then
  1080. target = {pos = {x = cannon.x, y = cannon.y, z = cannon.z}, velocity = {x = 0, y = 0, z = 0}}
  1081. else -- handling target
  1082. local scanResults = radar.scanForShips(5000)
  1083. for _, object in ipairs(scanResults) do
  1084. if object.id == cannon.id then
  1085. target = object
  1086. break
  1087. end
  1088. end
  1089. end
  1090.  
  1091. if target and target.pos then
  1092. aimCannon(target.pos, target.velocity, cannonData.stern15inch.source.x, cannonData.stern15inch.source.y, cannonData.stern15inch.source.z, cannonData.stern15inch.pitch, cannonData.stern15inch.yaw, "stern", 280)
  1093. end
  1094. else
  1095. if backRouter and backRouter.setOutput then
  1096. -- Ensure that outputs are reset when not actively aiming
  1097. backRouter.setOutput("top", false)
  1098. backRouter.setOutput("left", false)
  1099. backRouter.setOutput("right", false)
  1100. backRouter.setOutput("front", false)
  1101. end
  1102. end
  1103. end
  1104. sleep()
  1105. end
  1106. end
  1107.  
  1108. parallel.waitForAny(
  1109. function()
  1110. -- Main loop
  1111. while true do
  1112. if displayState == "radar" then
  1113. monitor.clear()
  1114. monitor.setTextScale(0.5)
  1115. drawRadarDisplay()
  1116. drawControls()
  1117. elseif displayState == "targetInfo" and selectedTarget then
  1118. displayTargetInfo(selectedTarget)
  1119. elseif displayState == "adjustCannon" then
  1120. monitor.clear()
  1121. drawCannonAdjustmentPage()
  1122. end
  1123. sleep(0.1) -- Adjust this duration if needed
  1124. end
  1125. end,
  1126. handleTouch,
  1127. modemMessage,
  1128. aimPortCannonContinuous,
  1129. aimStarboardCannonContinuous,
  1130. includeBowAndStern and aimBowCannonContinuous or function() while true do sleep(1) end end,
  1131. includeBowAndStern and aimSternCannonContinuous or function() while true do sleep(1) end end
  1132. )
  1133.  
  1134.  
  1135.  
Advertisement
Add Comment
Please, Sign In to add comment