Advertisement
PHOBOSS

Swarm2.lua

Mar 23rd, 2022 (edited)
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.02 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local serialization= require("serialization")
  4. local computer= require("computer")
  5. local thread= require("thread")
  6. local term= require("term")
  7. local modem = component.modem
  8. --local Tn = component.navigation
  9. --local Tr = component.radar
  10. local QueensChannel = 2412
  11. local QueensResponseChannel = 2402
  12. local PawnsChannel = 2413
  13. local PawnsResponseChannel = 2403
  14.  
  15. local drone_is_queen = true
  16.  
  17. --custom libraries
  18. local s_utils = require("swarm_utilities")
  19. local q_firmware = require("queen_firmware")
  20. local flightform = require("flight_formation")
  21. local radar_targeting = require("radar_targeting")
  22. local GPS = require("GPS")
  23. local GPS_TRG = require("GPS_TRG")
  24. local p_firmware = require("pawn_firmware")
  25.  
  26. modem.open(QueensResponseChannel)
  27. modem.open(PawnsResponseChannel)
  28. --[[
  29. modem.broadcast(PawnsChannel,"Sr= component.proxy(component.list('radar')())")
  30. modem.broadcast(PawnsChannel,"Sn= component.proxy(component.list('navigation')())")
  31. modem.broadcast(PawnsChannel,"Sd= component.proxy(component.list('drone')())")
  32. modem.broadcast(PawnsChannel,"function sleep(timeout) checkArg(1, timeout, 'number', 'nil') local deadline = computer.uptime() + (timeout or 0) repeat computer.pullSignal(deadline - computer.uptime()) until computer.uptime() >= deadline end")
  33. ]]
  34.  
  35. flightformation={}
  36. ffbook={flightformation}
  37. ffbook[2]={}
  38. ffbook[3]={}
  39. --form1 = {{13,2,-2},{-13,2,-2},{0,2,13}} --bad y gps value
  40. --form1 = {{3,8,-2},{-3,14,-2},{0,20,3}} -- bad xz gps values
  41. --form1 = {{10,8,-10},{-10,14,0},{5,20,10}}
  42. --form1 = {{0,0,0},{5,5,0},{0,10,10},{-15,15,0},{0,20,-20}}
  43. --form1 = {{0,0,0},{2,2,0},{0,4,4},{-8,8,0},{0,10,-10},{12,12,0},{0,14,14},{-16,16,0}}--golden ratio Spiral
  44. actualSatForm = {{0,25,-3},{0,25,3},{3,22,0},{-3,22,0}}-- ComputerCraft Heresy --(Tetrahedron) -- it's actually good for xz coordinates
  45. --satff={}
  46. --compensatedSatForm = {{0,25,-2},{0,25,3},{2,22,0},{-3,22,0}}
  47. --form1 = {{0,35,-3},{0,30,3},{3,20,0},{-3,25,0}}
  48. --form1 = {{0,35,-5},{0,30,2},{5,20,0},{-2,25,0}}
  49. --form2 = {{-2,10,2},{2,15,2},{0,2,0}}
  50. --form3 = {{-2,20,-2},{2,25,-2}}
  51. --form2 = {{-10,10,10},{10,12,10},{0,5,0}}
  52. --form3 = {{-10,14,-10},{10,16,-10}}
  53. form2 = {{3,0,0},{0,3,0},{0,0,3},{3,0,3},{-3,0,-3}}
  54. form3 = {{-3,0,0},{0,-3,0},{0,0,-3},{3,3,3},{-3,-3,-3}}
  55.  
  56. --*************--
  57. --[[
  58. The radar has an inaccuracy where it recognises two blocks as zeroes in each axis.
  59. Drones positioned in coordinates with positive axis components around a target player are actually a block extra away from the origin
  60. the given formation array is thus compensated in the formUP function from the flight_formation library
  61. ]]
  62. --*************--
  63.  
  64. fbook={actualSatForm,form2,form3}
  65. dynamic_fbook = fbook
  66.  
  67.  
  68. print("Bingus30")
  69. function printSwarmStats()
  70. term.clear()
  71. print("QUEENS:")
  72. flightform.printDronePool(drone_is_queen)
  73. flightform.printFFAssignment(ffbook)
  74. end
  75.  
  76.  
  77. local gpsChannel = 2
  78. --local trgChannel = 3
  79.  
  80.  
  81. --trgPortBook = {}--{[trgport]="target"} multiple to fixed single relationship
  82. trgPortBook = {[3]="Bingus",[4]="Floppa",[5]="FloppaMi",[7]="FloppaNi"}
  83.  
  84. Pawnffbook = {}
  85. Pawnffbook[1] = {}
  86. --Pawnform1 = {{3,2,-2},{-3,2,-2},{0,2,3}}
  87. Pawnform1 = {{0,2,0}}
  88. Pawnfbook = {Pawnform1}
  89. Pawndynamic_fbook = Pawnfbook
  90.  
  91.  
  92. function printSwarmStatsPawn()
  93. term.clear()
  94. print("PAWNS:")
  95. flightform.printDronePool(false)
  96. flightform.printFFAssignment(Pawnffbook)
  97. end
  98.  
  99. while true do
  100. local cmd=io.read()
  101. if not cmd then return end
  102. if(cmd == "F") then
  103. q_firmware.broadcastFirmWare(QueensChannel)
  104. os.sleep(0.5)
  105. elseif(cmd == "G") then
  106. modem.broadcast(QueensChannel,"stop")
  107. modem.broadcast(QueensChannel,"go","ph0")
  108. os.sleep(0.5)
  109. elseif(cmd == "B") then
  110. modem.broadcast(QueensChannel,"stop")
  111. modem.broadcast(QueensChannel,"bzz","ph0")
  112. os.sleep(0.5)
  113. elseif(cmd == "M") then
  114. modem.broadcast(QueensChannel,"stop")
  115. modem.broadcast(QueensChannel,"move","",0,3,0)
  116. os.sleep(0.5)
  117.  
  118.  
  119. elseif(cmd == "P") then --refreshFormation
  120. flightform.populatePool(QueensChannel,drone_is_queen)
  121. os.sleep(0.5)
  122. printSwarmStats()
  123. os.sleep(0.5)
  124.  
  125. elseif(cmd == "T") then
  126. flightform.refreshFFT(ffbook,dynamic_fbook,QueensChannel,drone_is_queen)
  127. flightform.formFF(ffbook[1],dynamic_fbook[1],QueensChannel,drone_is_queen)
  128. flightform.QformUP("ph0",ffbook[1],QueensChannel)
  129. printSwarmStats()
  130. os.sleep(0.5)
  131. elseif(cmd == "Q") then
  132. flightform.refreshFFT(ffbook,dynamic_fbook,QueensChannel,drone_is_queen)
  133. flightform.formFF(ffbook[2],dynamic_fbook[2],QueensChannel,drone_is_queen)
  134. flightform.formFF(ffbook[3],dynamic_fbook[3],QueensChannel,drone_is_queen)
  135. flightform.QformUP("ph0",ffbook[2],QueensChannel)
  136. flightform.QformUP("ph0",ffbook[3],QueensChannel)
  137. printSwarmStats()
  138. os.sleep(0.5)
  139. elseif(cmd == "E") then
  140. for i = 1,#ffbook do
  141. flightform.breakFormation(ffbook[i],dynamic_fbook[i],QueensChannel,drone_is_queen)
  142. end
  143. printSwarmStats()
  144. os.sleep(0.5)
  145. elseif(cmd == "R") then --refreshFormation
  146. flightform.refreshFFT(ffbook,dynamic_fbook,QueensChannel,drone_is_queen)
  147. printSwarmStats()
  148. os.sleep(0.5)
  149. elseif(cmd == "PRINTQ") then --printGroup
  150. printSwarmStats()
  151. os.sleep(0.5)
  152. elseif(cmd == "S") then
  153. modem.broadcast(QueensChannel,"stop")
  154. event.ignore("modem_message",msg_handler)
  155. os.sleep(0.5)
  156. elseif(cmd == "HUSH") then
  157. modem.broadcast(QueensChannel,"HUSH")
  158. os.sleep(0.5)
  159.  
  160.  
  161.  
  162. elseif(cmd == "GPS") then
  163. for addr,c in pairs(ffbook[1]) do
  164. print(addr,c)
  165. modem.send(addr,QueensChannel,"setgpspos",_,c[1],c[2],c[3])
  166. end
  167. modem.broadcast(QueensChannel,"startgps")
  168. os.sleep(0.5)
  169. elseif(cmd == "TRG") then
  170. GPS_TRG.updateGPSTRGs(trgPortBook,gpsChannel)
  171. os.sleep(0.5)
  172.  
  173. elseif(cmd == "K") then
  174. GPS_TRG.killGPSTRGThread(gpsChannel)
  175. os.sleep(0.5)
  176.  
  177.  
  178.  
  179.  
  180.  
  181. elseif(cmd == "A") then -- form triangle on Floppa with PAWNS
  182. flightform.refreshFFT(Pawnffbook,Pawndynamic_fbook,PawnsChannel,false)
  183. flightform.formFF(Pawnffbook[1],Pawndynamic_fbook[1],PawnsChannel,false)
  184. flightform.PformUP(4,Pawnffbook[1],PawnsChannel)
  185. printSwarmStatsPawn()
  186. os.sleep(0.5)
  187. elseif(cmd == "FP") then
  188. p_firmware.broadcastFirmWare(PawnsChannel)
  189. os.sleep(0.5)
  190. elseif(cmd == "EP") then
  191. for i = 1,#Pawnffbook do
  192. flightform.breakFormation(Pawnffbook[i],Pawndynamic_fbook[i],PawnsChannel,false)
  193. end
  194. printSwarmStatsPawn()
  195. os.sleep(0.5)
  196. elseif(cmd == "RP") then --refreshFormation
  197. flightform.refreshFFT(Pawnffbook,Pawndynamic_fbook,PawnsChannel,false)
  198. printSwarmStatsPawn()
  199. os.sleep(0.5)
  200. elseif(cmd == "PRINTP") then
  201. printSwarmStatsPawn()
  202. os.sleep(0.5)
  203. elseif(cmd == "SP") then
  204. modem.broadcast(PawnsChannel,"stop")
  205. os.sleep(0.5)
  206. elseif(cmd == "HUSHP") then
  207. modem.broadcast(PawnsChannel,"HUSH")
  208. os.sleep(0.5)
  209.  
  210.  
  211.  
  212.  
  213.  
  214. elseif(cmd == "EXIT") then
  215. flightform.closeFlighFormComms()
  216. GPS_TRG.killGPSTRGThread(gpsChannel)
  217. os.exit()
  218. else
  219. modem.broadcast(QueensChannel,cmd)
  220. end
  221. end
  222.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement