PHOBOSS

GPS_TRG_lib.lua

Apr 14th, 2022 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.18 KB | None | 0 0
  1. local thread = require 'thread'
  2. local term = require 'term'
  3. local event = require 'event'
  4. local component = require 'component'
  5. local modem = component.modem
  6.  
  7. local radar_targeting = require 'radar_targeting'
  8. local s_utils = require 'swarm_utilities'
  9. local GPS = require 'GPS'
  10. local flightform = require 'flight_formation'
  11. local vec_trunc,add = s_utils.vec_trunc,s_utils.add
  12.  
  13. local GPS_TRG = {}
  14.  
  15. function GPS_TRG.bcGPSTRGPos(tpBook,gpsC,rotAnglIntTable,axisTable,tiltAngleTable)
  16. modem.open(gpsC)
  17. modem.setStrength(math.huge)
  18. local gpsTable = {}
  19. local refreshGPSInterval = 5
  20. local refreshGPSCounter = 0
  21. event.listen("modem_message",function(_,_,r_addr,_,dist,msg,xg,yg,zg,...)
  22. if msg == "gps" then
  23. GPS.add2GPSTable(r_addr,xg,yg,zg,dist,gpsTable)
  24. end
  25. end)
  26. while true do
  27. --term.clear()
  28. local gpsPos = GPS.getGPSPos(gpsTable)
  29. if gpsPos then
  30. --print("gpsPos: ",gpsPos.x,gpsPos.y,gpsPos.z)
  31. gpsPos = vec_trunc(gpsPos)
  32. --print("gpsPos: ",gpsPos.x,gpsPos.y,gpsPos.z)
  33. for tport,tname in pairs(tpBook) do
  34. --print("tport: ",tport,"tname: ",tname)
  35. --local radPos = radar_targeting.getPlayerCoord(tname)
  36. local radPos = radar_targeting.getEntityCoord(tname)
  37. --print("tport: ",tport,"tname: ",tname,"radPos: ",radPos.c.x,radPos.c.y,radPos.c.z)
  38. if radPos then
  39. radPos.c = vec_trunc(radPos.c)
  40. local trgPos = add(radPos.c,gpsPos)
  41. --print("tport: ",tport,"tname: ",tname,"trgPos: ",trgPos.x,trgPos.y,trgPos.z)
  42. --modem.broadcast(tport,"trg",trgPos.x,trgPos.y,trgPos.z,axis,rotAnglInt,tiltAngle)
  43. modem.broadcast(tport,"trg",trgPos.x,trgPos.y,trgPos.z,axisTable[tport],rotAnglIntTable[tport],tiltAngleTable[tport])
  44. end
  45. end
  46. else
  47. print("GPS Out Of Range")
  48. end
  49. refreshGPSCounter,gpsTable = GPS.refreshGPSTable(gpsTable,refreshGPSCounter,refreshGPSInterval)
  50. os.sleep(0.5)
  51. end
  52.  
  53. end
  54.  
  55. function GPS_TRG.bcGPSTRGPosPRINT(tpBook,gpsC,rotAnglIntTable,axisTable,tiltAngleTable)
  56. modem.open(gpsC)
  57. modem.setStrength(math.huge)
  58. local gpsTable = {}
  59. local refreshGPSInterval = 5
  60. local refreshGPSCounter = 0
  61. event.listen("modem_message",function(_,_,r_addr,_,dist,msg,xg,yg,zg,...)
  62. if msg == "gps" then
  63. GPS.add2GPSTable(r_addr,xg,yg,zg,dist,gpsTable)
  64. end
  65. end)
  66. while true do
  67. term.clear()
  68. local gpsPos = GPS.getGPSPos(gpsTable)
  69. if gpsPos then
  70. print("gpsPos: ",gpsPos.x,gpsPos.y,gpsPos.z)
  71. gpsPos = vec_trunc(gpsPos)
  72. print("gpsPos: ",gpsPos.x,gpsPos.y,gpsPos.z)
  73. for tport,tname in pairs(tpBook) do
  74. --print("tport: ",tport,"tname: ",tname)
  75. --local radPos = radar_targeting.getPlayerCoord(tname)
  76. local radPos = radar_targeting.getEntityCoord(tname)
  77. --print("tport: ",tport,"tname: ",tname,"radPos: ",radPos.c.x,radPos.c.y,radPos.c.z)
  78. if radPos then
  79. radPos.c = vec_trunc(radPos.c)
  80. local trgPos = add(radPos.c,gpsPos)
  81. print("tport: ",tport,"tname: ",tname,"trgPos: ",trgPos.x,trgPos.y,trgPos.z,",rotAnglInt",rotAnglIntTable[tport])
  82. --modem.broadcast(tport,"trg",trgPos.x,trgPos.y,trgPos.z,axis,rotAnglInt,tiltAngle)
  83. modem.broadcast(tport,"trg",trgPos.x,trgPos.y,trgPos.z,axisTable[tport],rotAnglIntTable[tport],tiltAngleTable[tport])
  84. else
  85. print(tname," is out of radar Range")
  86. end
  87. end
  88. else
  89. print("GPS Out Of Range")
  90. end
  91. refreshGPSCounter,gpsTable = GPS.refreshGPSTable(gpsTable,refreshGPSCounter,refreshGPSInterval)
  92. os.sleep(0.5)
  93. end
  94.  
  95. end
  96.  
  97. function GPS_TRG.bcGPSRecall(tpBook,gpsC,PawnsC)
  98. modem.open(gpsC)
  99. modem.setStrength(math.huge)
  100. local gpsTable = {}
  101. local refreshGPSInterval = 5
  102. local refreshGPSCounter = 0
  103. event.listen("modem_message",function(_,_,r_addr,_,dist,msg,xg,yg,zg,...)
  104. if msg == "gps" then
  105. GPS.add2GPSTable(r_addr,xg,yg,zg,dist,gpsTable)
  106. end
  107. end)
  108. modem.broadcast(PawnsC,"formup",0,2,0,1)
  109. while true do
  110. term.clear()
  111. local gpsPos = GPS.getGPSPos(gpsTable)
  112. if gpsPos then
  113. gpsPos = vec_trunc(gpsPos)
  114. print("Recalling...")
  115. print("GPS Location: ",gpsPos.x,gpsPos.y,gpsPos.z)
  116. modem.broadcast(1,"trg",gpsPos.x,gpsPos.y,gpsPos.z)
  117. else
  118. print("GPS Out Of Range")
  119. end
  120. refreshGPSCounter,gpsTable = GPS.refreshGPSTable(gpsTable,refreshGPSCounter,refreshGPSInterval)
  121. os.sleep(0.5)
  122. end
  123.  
  124. end
  125.  
  126.  
  127. function GPS_TRG.bcStaticGPSPos(tport,gpsC,rotAnglIntTable,axisTable,tiltAngleTable)
  128. modem.open(gpsC)
  129. modem.setStrength(math.huge)
  130. local gpsTable = {}
  131. local refreshGPSInterval = 5
  132. local refreshGPSCounter = 0
  133. event.listen("modem_message",function(_,_,r_addr,_,dist,msg,xg,yg,zg,...)
  134. if msg == "gps" then
  135. GPS.add2GPSTable(r_addr,xg,yg,zg,dist,gpsTable)
  136. end
  137. end)
  138. repeat
  139. term.clear()
  140. print("..Static Formation..")
  141. local gpsPos = GPS.getGPSPos(gpsTable)
  142. if gpsPos then
  143. gpsPos = vec_trunc(gpsPos)
  144. print("GPS Formation Center: ",gpsPos.x,gpsPos.y,gpsPos.z)
  145. print("Broadcasting to trgChannel: ",tport)
  146. print("rotAnglInt: ",rotAnglIntTable[tport])
  147. --modem.broadcast(tport,"trg",gpsPos.x,gpsPos.y,gpsPos.z,axis,rotAnglInt,tiltAngle)
  148. modem.broadcast(tport,"trg",gpsPos.x,gpsPos.y,gpsPos.z,axisTable[tport],rotAnglIntTable[tport],tiltAngleTable[tport])
  149. else
  150. print("GPS Out Of Range")
  151. end
  152. refreshGPSCounter,gpsTable = GPS.refreshGPSTable(gpsTable,refreshGPSCounter,refreshGPSInterval)
  153. os.sleep(0.5)
  154. until gpsPos
  155. os.sleep(3)
  156. modem.close(gpsC)
  157. print("PAWNS:")
  158. flightform.printDronePool(false)
  159. flightform.printFFAssignment(Pawnffbook)
  160.  
  161. end
  162.  
  163.  
  164.  
  165. GPS_TRG.gpstrgThread = nil
  166.  
  167. function GPS_TRG.updateGPSTRGs(tpBook,gpsC,rotAngIntTbl,axisTbl,tiltAngleTbl) --**********************-- --only call this sparingly, don't want to stall other flight formations
  168. GPS_TRG.killGPSTRGThread(gpsC)
  169. GPS_TRG.gpstrgThread = thread.create(function(tpb,gpsC,rotAngIntTbl,axisTbl,tiltAngleTbl) print("threading") GPS_TRG.bcGPSTRGPos(tpb,gpsC,rotAngIntTbl,axisTbl,tiltAngleTbl) end,tpBook,gpsC,rotAngIntTbl,axisTbl,tiltAngleTbl)
  170. end
  171.  
  172. function GPS_TRG.updateGPSTRGsPRINT(tpBook,gpsC,rotAngIntTbl,axisTbl,tiltAngleTbl) --**********************-- --only call this sparingly, don't want to stall other flight formations
  173. GPS_TRG.killGPSTRGThread(gpsC)
  174. GPS_TRG.gpstrgThread = thread.create(function(tpb,gpsC,rotAngIntTbl,axisTbl,tiltAngleTbl) print("threading") GPS_TRG.bcGPSTRGPosPRINT(tpb,gpsC,rotAngIntTbl,axisTbl,tiltAngleTbl) end,tpBook,gpsC,rotAngIntTbl,axisTbl,tiltAngleTbl)
  175. end
  176.  
  177. function GPS_TRG.GPSRecall(tpBook,gpsC,PawnsC) --**********************-- --only call this sparingly, don't want to stall other flight formations
  178. GPS_TRG.killGPSTRGThread(gpsC)
  179. GPS_TRG.gpstrgThread = thread.create(function(tpb,gpsC,PawnsC) print("threading") GPS_TRG.bcGPSRecall(tpb,gpsC,PawnsC) end,tpBook,gpsC,PawnsC)
  180. end
  181.  
  182. function GPS_TRG.updateStaticGPS(tpBook,gpsC,rotAngIntTbl,axisTbl,tiltAngleTbl) --**********************--
  183. GPS_TRG.killGPSTRGThread(gpsC)
  184. GPS_TRG.gpstrgThread = thread.create(function(tpb,gpsC,rotAngIntTbl,axisTbl,tiltAngleTbl) print("threading") GPS_TRG.bcStaticGPSPos(tpb,gpsC,rotAngIntTbl,axisTbl,tiltAngleTbl) end,tpBook,gpsC,rotAngIntTbl,axisTbl,tiltAngleTbl)
  185. end
  186.  
  187. function GPS_TRG.killGPSTRGThread(gpsC) --**********************--
  188. if GPS_TRG.gpstrgThread then GPS_TRG.gpstrgThread:kill() modem.close(gpsC) end
  189. end
  190.  
  191.  
  192. return GPS_TRG
  193.  
Add Comment
Please, Sign In to add comment