View difference between Paste ID: 6WUUTgQc and qMDJ9rMf
SHOW: | | - or go back to the newest paste.
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 Tn = component.navigation
7+
8
--local Tn = component.navigation
9
local Tr = component.radar
10
local QueensChannel = 2412
11
local QueensResponseChannel = 2402
12
local SoldiersChannel = 2413
13
local SoldiersResponseChannel = 2403
14-
--local q_firmware = require("queen_firmware")
14+
15-
--local flightform = require("flight_formation")
15+
local drone_is_queen = true
16
17-
modem.open(QueensChannel)
17+
18
local s_utils = require("swarm_utilities")
19-
--q_firmware.broadcastFirmWare(QueensChannel)
19+
local q_firmware = require("queen_firmware")
20-
function Q_FIRMWARE()
20+
local flightform = require("flight_formation")
21-
modem.broadcast(QueensChannel,
21+
22-
[[
22+
modem.open(QueensResponseChannel)
23-
Qr= component.proxy(component.list('radar')())
23+
24-
Qn= component.proxy(component.list('navigation')())
24+
modem.open(SoldiersResponseChannel)
25-
Qd= component.proxy(component.list('drone')())
25+
26-
Qm= component.proxy(component.list('modem')())
26+
27-
QueensChannel = 2412
27+
28-
Qm.open(QueensChannel)
28+
29-
]]
29+
30-
)
30+
31
flightformation={}
32-
modem.broadcast(QueensChannel,
32+
33-
[[
33+
34-
function sleep(timeout) 
34+
35-
	checkArg(1, timeout, 'number', 'nil')
35+
36-
	local deadline = computer.uptime() + (timeout or 0)
36+
37-
	repeat
37+
38-
		computer.pullSignal(deadline - computer.uptime())
38+
39-
	until computer.uptime() >= deadline
39+
40
41-
]]
41+
42-
)
42+
43
44-
modem.broadcast(QueensChannel,
44+
45-
[[
45+
46
local trgChannel = 2472
47
48-
	for k,v in ipairs(Qr.getPlayers()) do 
48+
49
function gpsBroadcast(gps_port)
50
	while true do
51
		modem.broadcast(gps_port,"gps",0,0,0)
52
		--print("broadcasting..")
53
		os.sleep()
54
	end
55-
]]
55+
56-
)
56+
57-
modem.broadcast(QueensChannel,
57+
58-
[[
58+
59-
function move(x,y,z) 
59+
60-
	checkArg(1,x,'number','nil')
60+
61-
	checkArg(1,y,'number','nil')
61+
62-
	checkArg(1,z,'number','nil')
62+
63-
	if x and y and z then
63+
64-
			Qd.setLightColor(0x00FFAF)
64+
65-
			Qd.move(x,y,z)
65+
66
		gpsThread:kill()
67
	end
68-
]]
68+
69-
)
69+
70-
modem.broadcast(QueensChannel,
70+
71-
[[
71+
72-
function sub_vec(A,B) return {A[1]-B[1],A[2]-B[2],A[3]-B[3]} end
72+
73-
function math.trunc(v)
73+
74-
    local t = math.modf(v)
74+
75-
	return t
75+
76
	end
77-
function vec_trunc(A)
77+
78-
	if A then
78+
79-
		return {math.trunc(A[1]),math.trunc(A[2]),math.trunc(A[3])}
79+
80
function trgBroadcast(e_name)
81-
	return nil
81+
82
		local player_co = getPlayerCoord(e_name)
83-
function navMoveToPlayer(e_name)
83+
84-
	checkArg(1,e_name,"string","nil")
84+
85-
	local trgPos = {Qn.getPosition()},stp
85+
86-
 
86+
87-
	if not trgPos[1] then Qd.setLightColor(0xFF0000) return "Out Of\nRange" end
87+
88-
 
88+
89-
	trgPos = vec_trunc(trgPos)
89+
90-
	local mv = {0,0,0}
90+
91-
	local mapRange = Qn.getRange()
91+
92-
 
92+
93-
	repeat
93+
94-
		local v = getPlayerCoord(e_name)
94+
95-
		v = vec_trunc(v)
95+
96-
		local Qnpos = {Qn.getPosition()}
96+
97-
		if Qnpos[1] then
97+
98-
			Qnpos = vec_trunc(Qnpos)
98+
99-
			local Qpn = {Qnpos[1] + v[1], Qnpos[2] + v[2] + 2, Qnpos[3] + v[3]}
99+
100-
			mv = sub_vec(Qpn,trgPos)
100+
101-
			if math.abs(Qpn[1]) < mapRange-5 and math.abs(Qpn[3]) < mapRange-5 then
101+
102-
				Qd.move(mv[1],mv[2],mv[3])
102+
function printSwarmStats()
103-
				trgPos = Qpn
103+
	term.clear()
104-
			end
104+
	flightform.printDronePool(drone_is_queen)
105-
		else
105+
	flightform.printFFAssignment(ffbook)
106-
			Qd.setLightColor(0xFF0000)
106+
107-
			Qd.setStatusText("Out Of\nRange")
107+
108-
			Qd.move(-mv[1],-mv[2],-mv[3])
108+
109
	local cmd=io.read()
110-
		stp = select(6,computer.pullSignal(0.5))
110+
111-
	until stp == "stop"
111+
112-
	return Qd.name()
112+
		q_firmware.broadcastFirmWare(QueensChannel)
113
    	os.sleep(0.5)
114-
]]
114+
115-
)
115+
116-
modem.broadcast(QueensChannel,
116+
117-
[[
117+
118-
function navSwarmPlayer(e_name)
118+
119-
	checkArg(1,e_name,"string","nil")
119+
120-
	local trgPos = {Qn.getPosition()},stp
120+
121-
 
121+
122-
	if not trgPos[1] then Qd.setLightColor(0xFF0000) return "Out Of\nRange" end
122+
123-
 
123+
124-
	trgPos = vec_trunc(trgPos)
124+
125-
	local mv = {0,0,0}
125+
126-
	local mapRange = Qn.getRange()
126+
127-
 
127+
128-
	repeat
128+
129-
		local v = getPlayerCoord(e_name)
129+
		flightform.populatePool(QueensChannel,drone_is_queen)
130-
		v = vec_trunc(v)
130+
		printSwarmStats()
131-
		local Qnpos = {Qn.getPosition()}
131+
132-
		if Qnpos[1] then
132+
133-
			Qnpos = vec_trunc(Qnpos)
133+
134-
			local Qpn = {Qnpos[1] + v[1] +math.random(-3,3), Qnpos[2] + v[2] +math.random(-3,3), Qnpos[3] + v[3]+math.random(-3,3)}
134+
		flightform.formFF(ffbook[1],dynamic_fbook[1],QueensChannel,drone_is_queen)
135-
			mv = sub_vec(Qpn,trgPos)
135+
		flightform.formUP("ph0",ffbook[1],dynamic_fbook[1],QueensChannel)
136-
			if math.abs(Qpn[1]) < mapRange-5 and math.abs(Qpn[3]) < mapRange-5 then
136+
		printSwarmStats()
137-
				Qd.move(mv[1],mv[2],mv[3])
137+
138-
				trgPos = Qpn
138+
139-
			end
139+
		flightform.formFF(ffbook[2],dynamic_fbook[2],QueensChannel,drone_is_queen)
140-
		else
140+
		flightform.formFF(ffbook[3],dynamic_fbook[3],QueensChannel,drone_is_queen)
141-
			Qd.setLightColor(0xFF0000)
141+
		flightform.formUP("ph0",ffbook[2],dynamic_fbook[2],QueensChannel)
142-
			Qd.setStatusText("Out Of\nRange")
142+
		flightform.formUP("ph0",ffbook[3],dynamic_fbook[3],QueensChannel)
143-
			Qd.move(-mv[1],-mv[2],-mv[3])
143+
		printSwarmStats()
144
	    os.sleep(0.5)
145-
		stp = select(6,computer.pullSignal(0.5))
145+
146-
	until stp == "stop"
146+
147-
	return Qd.name()
147+
			flightform.breakFormation(ffbook[i],dynamic_fbook[i],QueensChannel,drone_is_queen)
148
		end
149-
]]
149+
		printSwarmStats()
150-
)
150+
151-
modem.broadcast(QueensChannel,
151+
152-
[[
152+
153-
local cc = 1
153+
			flightform.refreshFFT(ffbook[i],dynamic_fbook[i],QueensChannel,drone_is_queen)
154-
isFree = true
154+
155-
function replyInv(add)
155+
		printSwarmStats()
156-
	if isFree then
156+
157-
		Qd.setLightColor(0xFF00BB)
157+
158-
		Qm.send(add,QueensChannel,"pkme")
158+
		printSwarmStats()
159-
		--Qd.setStatusText(tostring(cc)) 
159+
160-
		cc=cc+1
160+
161
	elseif(cmd == "GPS") then
162
		toggleGPSBroadCast(gpsChannel)
163-
]]
163+
164-
)
164+
165-
modem.broadcast(QueensChannel,
165+
166-
[[
166+
167-
acts = {
167+
168-
	["go"] = function(r_add,tag,x,y,z) Qd.setLightColor(0x00FF00) Qd.setStatusText(navMoveToPlayer(tag)) end,
168+
169-
    ["bzz"] = function(r_add,tag,x,y,z) Qd.setLightColor(0x0000FF) Qd.setStatusText(navSwarmPlayer(tag)) end,
169+
170-
	["move"] = function(r_add,tag,x,y,z) move(x,y,z) end,
170+
171-
	["inv"] = function(r_add,tag,x,y,z) replyInv(r_add) end,
171+
172-
	["commit"] = function(r_add,tag,x,y,z) Qd.setLightColor(0xFF1F00) isFree = false Qd.setStatusText("cmt "..tostring(isFree)) end,
172+
	elseif(cmd == "HUSH") then
173-
	["uncommit"] = function(r_add,tag,x,y,z) isFree = true end,
173+
		modem.broadcast(QueensChannel,"HUSH")
174-
	["uok"] = function(r_add,tag,x,y,z) Qd.setLightColor(0x77FF77) isFree = true Qm.send(r_add,QueensChannel,"actv") end,
174+
175-
	["formup"] = function(r_add,tag,x,y,z) Qd.setLightColor(0x0011FF) Qd.setStatusText(navMoveToPlayerWOffset(tag,x,y,z)) end,
175+
176-
	["HUSH"] = function(r_add,tag,x,y,z) computer.shutdown() end
176+
177-
}
177+
		flightform.closeFlighFormComms()
178-
]]
178+
		if gpsThread then
179-
)
179+
			gpsThread:kill()
180-
modem.broadcast(QueensChannel,
180+
181-
[[
181+
		if trgThread then
182-
gpsChannel = 2
182+
			trgThread:kill()
183-
trgChannel = 2472
183+
184-
function QgpsBroadcast()
184+
185-
	Qm.broadcast(gpsChannel,"Qgps")
185+
186
    	modem.broadcast(QueensChannel,cmd)
187-
]]
187+
188-
)
188+
189-
modem.broadcast(QueensChannel,
189+