-
Notifications
You must be signed in to change notification settings - Fork 0
/
NAVI
480 lines (439 loc) · 10.3 KB
/
NAVI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
@name NAVI BFW-official-Squadrontest
@inputs Hip:entity Torso:entity #alignment
@inputs Bsl Bsr R1 R2 R3 Batter Target Targ:entity Enable AimPos:vector #[ Pos to aim at]#
@outputs Sx Sy Steer ReloadRockets Ang:angle Deploy W S Tdist M1 M2 M3 Timer Raise Facing X Lookin Y TurnUp TurnDown HardLeft HardRight TurnLeft TurnRight Dang
@persist Rocketpodspeed Tdist Persue Dang Timer Facing Fang TurnUp TurnDown Bob
@persist T TRUE FALSE E:entity
@persist UDsens LRsens UDsensH LRsensH X Y
@persist UpLimit DownLimit Close
@persist Master:entity SC CreationTime Frm
@persist Squadron:array SlaveE2s:array SquadID DesiredPos:vector #<-------- only for slave e2s
@trigger Enable
# if(duped())
# {
# reset()
# }
if(first())
{
E=entity()
TRUE=1
FALSE=0# why would you ever change these
UDsens=2 #u/d sensitivity
LRsens=2
UDsensH=9#15 #hard turn has an H
LRsensH=9#15
UpLimit=45 #I tried making soft limit for bfw head turning
DownLimit=-45
Close = 500 #how much personal space to give our target
CreationTime = systime()
##############################
#Dunnah toucheh this
Sy=FALSE
Sx=FALSE
holoCreate(FALSE)
holoAng(FALSE,E:angles())
holoParent(FALSE,E)
holoModel(FALSE,"models/sprops/misc/axis_plane.mdl")
dsJoinGroup(owner():steamID()+"NAVI_BFW") # incase multiple people on the server are using this same e2
dsSetScope(10)
##############################
function number clk_(Millis_:number, Go_:number) # oooooooooooo clock
{
local TimerName = Millis_:toString()
if(clk(TimerName))
{
return TRUE
}
elseif(Go_)
{
timer(TimerName, Millis_)
return FALSE
}
}
function goLeft(Hard_)
{
HardRight = FALSE
HardLeft = FALSE
Facing = FALSE
TurnRight = FALSE
TurnLeft = TRUE
Steer = -0.5
if(Hard_)
{
HardLeft = TRUE
Steer = -TRUE
}
}
function goRight(Hard_)
{ #same as above but right instead of left
Facing = FALSE
TurnRight = TRUE
TurnLeft = FALSE
HardRight = FALSE
HardLeft = FALSE
Steer = 0.5
if(Hard_)
{
HardRight = TRUE
Steer = TRUE
}
}
function number straight()
{
# Facing = TRUE
TurnRight = FALSE
TurnLeft = FALSE
HardRight = FALSE
HardLeft = FALSE
Steer = FALSE
Deploy=TRUE
return TRUE
}
function look_up(Hard_)
{
TurnUp = TRUE
TurnDown = FALSE
Lookin = FALSE
if(Hard_)
{
}
}
function look_down(Hard_)
{
TurnUp = TRUE
TurnDown = FALSE
Lookin = FALSE
if(Hard_)
{
}
}
function number look()
{
Lookin = TRUE
TurnUp = FALSE
TurnDown = FALSE
return 1
}
function go(Go_)
{
#[ if(clk_(27,Go_)) #how do I turn B0ss?
{]#
if(Dang < -2.0)
{ #am walke left
goLeft(FALSE)
}
if(Dang < -15.0)
{ #am walkeh super left
goLeft(TRUE)
}
if(Dang > 2.0)
{
goRight(FALSE)
}
if (Dang > 15.0)
{
goRight(TRUE)
}
if(Dang>=-2&&Dang<=2)
{ #Hey im going straight at the thing!
straight()
}
if(Fang > 1.0)
{
look_up(FALSE)
}
elseif(Fang < -1.0)
{
look_down(FALSE)
}
else
{
Lookin=TRUE
look()
}
W=TRUE #testing purposes
}
function number follow(Follow_,Pos_:vector)
{
if(Hip&Torso)
{
if(Targ){
#[if(clk_(25,TRUE)){]#
Dang = Hip:bearing(Pos_)
Fang = Torso:elevation(Pos_)
#[ elseif(clk_(26,TRUE)){]#
Dang = E:bearing(Pos_)
Fang = E:elevation(Pos_)
}
}
return TRUE
}
function void obstacleAvoidance(Avoid_)
{
if(clk_(20,Avoid_))
{
if(Bsr<50)
{
W = FALSE
Steer=1
timer("settle",2000)
}
if(Bsl<50)
{
W = FALSE
Steer=1
timer("settle",2000)
}
if(clk("settle"))
{
W = FALSE
Steer=0
}
}
}
function void rocketLogic(Dothelogics_)
{
if(clk_(Rocketpodspeed,Dothelogics_))#Podspeed you magnificent rocket
{ ###force the launching of rockets
if(Batter)
{
ReloadRockets=FALSE
Timer++
}
if(Timer==50&&Batter&&R1)
{
M1=TRUE
M3=FALSE
Timer++
}
if(Timer==100&&Batter&&R2)
{
M1=FALSE
M2=TRUE
Timer++
}
if(Timer==150&&Batter&&R3)
{
M3=TRUE
M2=FALSE
Timer++
timer("m2",800)
}
if(Timer>450)
{
Timer=FALSE
}
if(R1==TRUE&R2==TRUE&R3==TRUE)#if all rockets reload,
{
Ready=TRUE
}
if(R1==FALSE&&R2==FALSE&&R3==FALSE)
{
Ready=FALSE
}
else
{
M1=FALSE
M2=FALSE
M3=FALSE
Timer=FALSE
ReloadRockets=TRUE
}
if(R1==FALSE&&R2==FALSE&&R3==FALSE)
{
Ready=FALSE
}
else
{
M1=FALSE
M2=FALSE
M3=FALSE
Timer=FALSE
ReloadRockets=TRUE
}
if(Facing&&Lookin&&R1&&R2&&R3&&Tdist<=6500)
{
Raise=TRUE
}
else
{
Raise=FALSE
}
}
}
function void idManagement()
{
local Time = systime()
if(!Master:isValid())
{
if(first())
{ #request status at start
dsSend("leader_check",owner():steamID()+"NAVI_BFW",1)
}
elseif(Time - CreationTime >= 0.5)
{ #if no one replies in 0.5 second, become master chip and alert any other spawned chips
Master = E
dsSend("i_am",owner():steamID()+"NAVI_BFW",E)
print(E:id() + " becoming master chip")
}
}
if(dsClk("i_am"))
{ #receiving who the master chip is
local IncomingData = dsGetEntity()
if(Master:isValid())
{
if(IncomingData != Master)
{
#[
uh oh, multiple chips were spawned at once with no master
]#
error("multiple chips spawned at the exact same time. master/slave system confused. spawn 1 master first before doing this")
}
}
else
{
#chip needs master, found it.
Master = dsGetEntity()
print("chip " + E:id() + " swearing loyalty to " + Master:id())
}
}
if(dsClk("leader_check") & Master == E)
{ #if this chip is the master chip, tell them whats up
dsSend("i_am",owner():steamID()+"NAVI_BFW",E)
}
################################arrays >_<
if(Master == E){
if(clk_(1000,TRUE)){ #if this chip is the master, compile the list of slave e2s every second
SlaveE2s = dsProbe(owner():steamID()+"NAVI_BFW")
dsSend("slaveList",owner():steamID()+"NAVI_BFW",SlaveE2s)
}
}else{
if(dsClk("slaveList")){
SlaveE2s = dsGetArray()
}
}
}
function void think()
{
if(Targ)
{
Tdist= Targ:pos():distance(E:pos())
}
if(TurnUp)
{
Y=Y+UDsens
Y=$Y*UDsens+Y#dont ask me later, its a sort of smoother :v
}
if(Y>UpLimit)
{
Y=UpLimit#that soft quota for the head
}
elseif(TurnDown)
{
Y=Y-UDsens
Y=$Y*-UDsens+Y
}
if(Y<DownLimit)
{
Y=DownLimit
}
if(TurnLeft)
{
X=X-LRsens
X=$X*-LRsens+X
}
elseif(TurnRight)
{
X=X+LRsens
X=$X*LRsens+X
}
else
{
}
if(HardRight)
{
X=X+LRsensH
X=$X*LRsensH+X
}
elseif(HardLeft)
{
X=X-LRsensH
X=$X*-LRsensH+X
}
else
{}
#Ang = E:angles() Wait why is this here
}
function number whoAmI() {
for(I=1,SlaveE2s:count()){
if(SlaveE2s[I,entity] == entity()){
# that me!
return I
}
}
return FALSE
}
function formation()
{
SC = SlaveE2s:count()
if(Master == entity()){ # if this is the master, broadcast positions
local RowSize =2
local XOffset = -100
local XSpacing = 700
local YOffset = 0
local YSpacing = 700
if(changed(SC)){
local SCChange = $SC
if(SCChange > 0){ #if we gained
Squadron = array()
for(I=1,SC){ #creation of new holos
local CleanDivide = int(I/RowSize) == I/RowSize
local X = CleanDivide ? RowSize - 1 : I % RowSize - 1
local Y = CleanDivide ? I/RowSize - 1 : int(I/RowSize)
#[
I 1,2,3,4,5, 6,7,8,9,10, 11,12,13,14,15
X 0,1,2,3,4, 0,1,2,3,4, 0, 1, 2, 3, 4
Y 0,0,0,0,0, 1,1,1,1,1, 2, 2, 2, 2, 2
I/X 0.1-1 1.1-2 2.1-3
]#
local Pos = vec(X*XSpacing + XOffset,Y*YSpacing + YOffset,0)
Squadron[I,vector] = Pos
if(!holoEntity(I):isValid()){ #debug holos
holoCreate(I)
holoParent(I,entity())
holoPos(I,entity():toWorld(Pos))
}
}
dsSend("squadron",owner():steamID()+"NAVI_BFW",Squadron)
}else{ #if we lost
#delete old holos
for(I=SC+1,SC+abs(SCChange)){
holoDelete(I)
}
}
}
}else{ #this chip is a slave, find its place in the broadcasted formation
if(dsClk("squadron")){
Squadron = dsGetArray()
}
if(changed(SC)){ #squad count changed, recheck current id
SquadID = whoAmI()
}
if(SquadID){
DesiredPos = Master:toWorld(Squadron[SquadID,vector])
}
}
}
}
interval(32)
idManagement()
formation()
if(Master==E){
follow(1,Targ:pos())
}
else{
follow(1,DesiredPos)
}
think()
go(1)
obstacleAvoidance(1)