forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseraphimunits.lua
598 lines (518 loc) · 22 KB
/
seraphimunits.lua
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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
-----------------------------------------------------------------
-- File : /cdimage/lua/seraphimunits.lua
-- Author(s): Dru Staltman, Jessica St. Croix
-- Summary : Units for Seraphim
-- Copyright © 2005 Gas Powered Games, Inc. All rights reserved.
-----------------------------------------------------------------
local DefaultUnitsFile = import('defaultunits.lua')
local AirFactoryUnit = DefaultUnitsFile.AirFactoryUnit
local AirStagingPlatformUnit = DefaultUnitsFile.AirStagingPlatformUnit
local AirUnit = DefaultUnitsFile.AirUnit
local ConcreteStructureUnit = DefaultUnitsFile.ConcreteStructureUnit
local ConstructionUnit = DefaultUnitsFile.ConstructionUnit
local EnergyCreationUnit = DefaultUnitsFile.EnergyCreationUnit
local EnergyStorageUnit = DefaultUnitsFile.EnergyStorageUnit
local LandFactoryUnit = DefaultUnitsFile.LandFactoryUnit
local MassCollectionUnit = DefaultUnitsFile.MassCollectionUnit
local MassFabricationUnit = DefaultUnitsFile.MassFabricationUnit
local MassStorageUnit = DefaultUnitsFile.MassStorageUnit
local RadarUnit = DefaultUnitsFile.RadarUnit
local SeaFactoryUnit = DefaultUnitsFile.SeaFactoryUnit
local ShieldHoverLandUnit = DefaultUnitsFile.ShieldHoverLandUnit
local ShieldLandUnit = DefaultUnitsFile.ShieldLandUnit
local ShieldStructureUnit = DefaultUnitsFile.ShieldStructureUnit
local SonarUnit = DefaultUnitsFile.SonarUnit
local StructureUnit = DefaultUnitsFile.StructureUnit
local QuantumGateUnit = DefaultUnitsFile.QuantumGateUnit
local RadarJammerUnit = DefaultUnitsFile.RadarJammerUnit
local WeaponFile = import('/lua/sim/DefaultWeapons.lua')
local DefaultBeamWeapon = WeaponFile.DefaultBeamWeapon
local EffectTemplate = import('/lua/EffectTemplates.lua')
local EffectUtil = import('/lua/EffectUtilities.lua')
-- AIR STRUCTURES
SAirFactoryUnit = Class(AirFactoryUnit) {
StartBuildFx = function(self, unitBeingBuilt)
local BuildBones = self:GetBlueprint().General.BuildBones.BuildEffectBones
local thread = self:ForkThread(EffectUtil.CreateSeraphimFactoryBuildingEffects, unitBeingBuilt, BuildBones, 'Attachpoint', self.BuildEffectsBag)
unitBeingBuilt.Trash:Add(thread)
end,
FinishBuildThread = function(self, unitBeingBuilt, order)
self:SetBusy(true)
self:SetBlockCommandQueue(true)
if unitBeingBuilt and not unitBeingBuilt.Dead and EntityCategoryContains(categories.AIR, unitBeingBuilt) then
unitBeingBuilt:DetachFrom(true)
local bp = self:GetBlueprint()
self:DetachAll(bp.Display.BuildAttachBone or 0)
end
self:DestroyBuildRotator()
if order ~= 'Upgrade' then
ChangeState(self, self.RollingOffState)
else
self:SetBusy(false)
self:SetBlockCommandQueue(false)
end
end,
CreateRollOffEffects = function(self)
local army = self:GetArmy()
local unitB = self.UnitBeingBuilt
if not self.ReleaseEffectsBag then self.ReleaseEffectsBag = {} end
for _, v in self.RollOffBones do
local fx = AttachBeamEntityToEntity(self, v, unitB, -1, army, EffectTemplate.TTransportBeam01)
table.insert(self.ReleaseEffectsBag, fx)
self.Trash:Add(fx)
fx = AttachBeamEntityToEntity(unitB, -1, self, v, army, EffectTemplate.TTransportBeam02)
table.insert(self.ReleaseEffectsBag, fx)
self.Trash:Add(fx)
fx = CreateEmitterAtBone(self, v, army, EffectTemplate.TTransportGlow01)
table.insert(self.ReleaseEffectsBag, fx)
self.Trash:Add(fx)
end
end,
DestroyRollOffEffects = function(self)
for _, v in self.ReleaseEffectsBag do
v:Destroy()
end
self.ReleaseEffectsBag = {}
end,
RollOffUnit = function(self)
if EntityCategoryContains(categories.AIR, self.UnitBeingBuilt) then
local spin, x, y, z = self:CalculateRollOffPoint()
local units = {self.UnitBeingBuilt}
self.MoveCommand = IssueMove(units, Vector(x, y, z))
end
end,
RolloffBody = function(self)
self:SetBusy(true)
local unitBuilding = self.UnitBeingBuilt
-- If the unit being built isn't an engineer use normal rolloff
if not EntityCategoryContains(categories.LAND, unitBuilding) then
AirFactoryUnit.RolloffBody(self)
else
-- Engineers need to be slid off the factory
local bp = self:GetBlueprint()
if not self.AttachmentSliderManip then
self.AttachmentSliderManip = CreateSlider(self, bp.Display.BuildAttachBone or 0)
end
self:CreateRollOffEffects()
self.AttachmentSliderManip:SetSpeed(50) -- Was 30, increased to help engineers move faster off of it
self.AttachmentSliderManip:SetGoal(0, 0, 60)
WaitFor(self.AttachmentSliderManip)
self.AttachmentSliderManip:SetGoal(0, -55, 60)
WaitFor(self.AttachmentSliderManip)
if not unitBuilding.Dead then
unitBuilding:DetachFrom(true)
self:DetachAll(bp.Display.BuildAttachBone or 0)
end
if self.AttachmentSliderManip then
self.AttachmentSliderManip:Destroy()
self.AttachmentSliderManip = nil
end
self:DestroyRollOffEffects()
self:SetBusy(false)
ChangeState(self, self.IdleState)
end
end,
OnStartBuild = function(self, unitBeingBuilt, order)
-- Set goal for rotator
local unitid = self:GetBlueprint().General.UpgradesTo
if unitBeingBuilt:GetUnitId() == unitid and order == 'Upgrade' then
-- Stop pods that exist in the upgraded unit
local savedAngle
if self.Rotator1 then
savedAngle = self.Rotator1:GetCurrentAngle()
self.Rotator1:SetGoal(savedAngle)
unitBeingBuilt.Rotator1:SetCurrentAngle(savedAngle)
unitBeingBuilt.Rotator1:SetGoal(savedAngle)
-- Freeze the next rotator to 0, since that's where it will be
unitBeingBuilt.Rotator2:SetCurrentAngle(0)
unitBeingBuilt.Rotator2:SetGoal(0)
end
if self.Rotator2 then
savedAngle = self.Rotator2:GetCurrentAngle()
self.Rotator2:SetGoal(savedAngle)
unitBeingBuilt.Rotator2:SetCurrentAngle(savedAngle)
unitBeingBuilt.Rotator2:SetGoal(savedAngle)
unitBeingBuilt.Rotator3:SetCurrentAngle(0)
unitBeingBuilt.Rotator3:SetGoal(0)
end
end
AirFactoryUnit.OnStartBuild(self, unitBeingBuilt, order)
end,
UpgradingState = State(AirFactoryUnit.UpgradingState) {
OnStopBuild = function(self, unitBuilding)
if unitBuilding:GetFractionComplete() == 1 then
-- Start halted rotators on upgraded unit
if unitBuilding.Rotator1 then
unitBuilding.Rotator1:ClearGoal()
end
if unitBuilding.Rotator2 then
unitBuilding.Rotator2:ClearGoal()
end
if unitBuilding.Rotator3 then
unitBuilding.Rotator3:ClearGoal()
end
end
AirFactoryUnit.UpgradingState.OnStopBuild(self, unitBuilding)
end,
OnFailedToBuild = function(self)
AirFactoryUnit.UpgradingState.OnFailedToBuild(self)
-- Failed to build, so resume rotators
if self.Rotator1 then
self.Rotator1:ClearGoal()
self.Rotator1:SetSpeed(5)
end
if self.Rotator2 then
self.Rotator2:ClearGoal()
self.Rotator2:SetSpeed(5)
end
end,
},
}
-- AIR UNITS
SAirUnit = Class(AirUnit) {
ContrailEffects = {'/effects/emitters/contrail_ser_polytrail_01_emit.bp'}
}
-- AIR STAGING STRUCTURES
SAirStagingPlatformUnit = Class(AirStagingPlatformUnit) {}
-- WALL STRUCTURES
SConcreteStructureUnit = Class(ConcreteStructureUnit) {
AdjacencyBeam = false,
}
-- Construction Units
SConstructionUnit = Class(ConstructionUnit) {
OnCreate = function(self)
ConstructionUnit.OnCreate(self)
if self.BuildingOpenAnim then
if self.BuildArm2Manipulator then
self.BuildArm2Manipulator:Disable()
end
end
end,
CreateBuildEffects = function(self, unitBeingBuilt, order)
EffectUtil.CreateSeraphimUnitEngineerBuildingEffects(self, unitBeingBuilt, self:GetBlueprint().General.BuildBones.BuildEffectBones, self.BuildEffectsBag)
end,
SetupBuildBones = function(self)
ConstructionUnit.SetupBuildBones(self)
local bp = self:GetBlueprint()
local buildbones = bp.General.BuildBones
if self.BuildArmManipulator then
self.BuildArmManipulator:SetAimingArc(buildbones.YawMin or -180, buildbones.YawMax or 180, buildbones.YawSlew or 360, buildbones.PitchMin or -90, buildbones.PitchMax or 90, buildbones.PitchSlew or 360)
end
if bp.General.BuildBonesAlt1 then
self.BuildArm2Manipulator = CreateBuilderArmController(self, bp.General.BuildBonesAlt1.YawBone or 0 , bp.General.BuildBonesAlt1.PitchBone or 0, bp.General.BuildBonesAlt1.AimBone or 0)
self.BuildArm2Manipulator:SetAimingArc(bp.General.BuildBonesAlt1.YawMin or -180, bp.General.BuildBonesAlt1.YawMax or 180, bp.General.BuildBonesAlt1.YawSlew or 360, bp.General.BuildBonesAlt1.PitchMin or -90, bp.General.BuildBonesAlt1.PitchMax or 90, bp.General.BuildBonesAlt1.PitchSlew or 360)
self.BuildArm2Manipulator:SetPrecedence(5)
if self.BuildingOpenAnimManip and self.Build2ArmManipulator then
self.BuildArm2Manipulator:Disable()
end
self.Trash:Add(self.BuildArm2Manipulator)
end
end,
BuildManipulatorSetEnabled = function(self, enable)
ConstructionUnit.BuildManipulatorSetEnabled(self, enable)
if not self or self.Dead then return end
if not self.BuildArm2Manipulator then return end
if enable then
self.BuildArm2Manipulator:Enable()
else
self.BuildArm2Manipulator:Disable()
end
end,
WaitForBuildAnimation = function(self, enable)
if self.BuildArmManipulator then
WaitFor(self.BuildingOpenAnimManip)
if enable then
self:BuildManipulatorSetEnabled(enable)
end
end
end,
OnStopBuilderTracking = function(self)
ConstructionUnit.OnStopBuilderTracking(self)
if self.StoppedBuilding then
self:BuildManipulatorSetEnabled(disable)
end
end,
}
-- ENERGY CREATION UNITS
SEnergyCreationUnit = Class(EnergyCreationUnit) {
OnCreate = function(self)
EnergyCreationUnit.OnCreate(self)
self.NumUsedAdjacentUnits = 0
end,
OnStopBeingBuilt = function(self, builder, layer)
EnergyCreationUnit.OnStopBeingBuilt(self, builder, layer)
local army = self:GetArmy()
if self.AmbientEffects then
for k, v in EffectTemplate[self.AmbientEffects] do
CreateAttachedEmitter(self, 0, army, v)
end
end
end,
}
-- ENERGY STORAGE STRUCTURES
SEnergyStorageUnit = Class(EnergyStorageUnit) {}
-- HOVERING LAND UNITS
SHoverLandUnit = Class(DefaultUnitsFile.HoverLandUnit) {
FxHoverScale = 1,
HoverEffects = nil,
HoverEffectBones = nil,
}
-- LAND FACTORY STRUCTURES
SLandFactoryUnit = Class(LandFactoryUnit) {
StartBuildFx = function(self, unitBeingBuilt)
local BuildBones = self:GetBlueprint().General.BuildBones.BuildEffectBones
local thread = self:ForkThread(EffectUtil.CreateSeraphimFactoryBuildingEffects, unitBeingBuilt, BuildBones, 'Attachpoint', self.BuildEffectsBag)
unitBeingBuilt.Trash:Add(thread)
end,
OnStartBuild = function(self, unitBeingBuilt, order)
-- Set goal for rotator
local unitid = self:GetBlueprint().General.UpgradesTo
if unitBeingBuilt:GetUnitId() == unitid and order == 'Upgrade' then
-- Stop pods that exist in the upgraded unit
local savedAngle
if self.Rotator1 then
savedAngle = self.Rotator1:GetCurrentAngle()
self.Rotator1:SetGoal(savedAngle)
unitBeingBuilt.Rotator1:SetCurrentAngle(savedAngle)
unitBeingBuilt.Rotator1:SetGoal(savedAngle)
-- Freeze the next rotator to 0, since that's where it will be
unitBeingBuilt.Rotator2:SetCurrentAngle(0)
unitBeingBuilt.Rotator2:SetGoal(0)
end
if self.Rotator2 then
savedAngle = self.Rotator2:GetCurrentAngle()
self.Rotator2:SetGoal(savedAngle)
unitBeingBuilt.Rotator2:SetCurrentAngle(savedAngle)
unitBeingBuilt.Rotator2:SetGoal(savedAngle)
unitBeingBuilt.Rotator3:SetCurrentAngle(0)
unitBeingBuilt.Rotator3:SetGoal(0)
end
end
LandFactoryUnit.OnStartBuild(self, unitBeingBuilt, order)
end,
UpgradingState = State(LandFactoryUnit.UpgradingState) {
OnStopBuild = function(self, unitBuilding)
if unitBuilding:GetFractionComplete() == 1 then
-- Start halted rotators on upgraded unit
if unitBuilding.Rotator1 then
unitBuilding.Rotator1:ClearGoal()
end
if unitBuilding.Rotator2 then
unitBuilding.Rotator2:ClearGoal()
end
if unitBuilding.Rotator3 then
unitBuilding.Rotator3:ClearGoal()
end
end
LandFactoryUnit.UpgradingState.OnStopBuild(self, unitBuilding)
end,
OnFailedToBuild = function(self)
LandFactoryUnit.UpgradingState.OnFailedToBuild(self)
-- Failed to build, so resume rotators
if self.Rotator1 then
self.Rotator1:ClearGoal()
self.Rotator1:SetSpeed(5)
end
if self.Rotator2 then
self.Rotator2:ClearGoal()
self.Rotator2:SetSpeed(5)
end
end,
},
}
-- LAND UNITS
SLandUnit = Class(DefaultUnitsFile.LandUnit) {}
-- MASS COLLECTION UNITS
SMassCollectionUnit = Class(MassCollectionUnit) {}
-- MASS FABRICATION STRUCTURES
SMassFabricationUnit = Class(MassFabricationUnit) {}
-- MASS STORAGE UNITS
SMassStorageUnit = Class(MassStorageUnit) {}
-- RADAR STRUCTURES
SRadarUnit = Class(RadarUnit) {}
-- RADAR STRUCTURES
SSonarUnit = Class(SonarUnit) {}
-- SEA FACTORY STRUCTURES
SSeaFactoryUnit = Class(SeaFactoryUnit) {
StartBuildFx = function(self, unitBeingBuilt)
local BuildBones = self:GetBlueprint().General.BuildBones.BuildEffectBones
local thread = self:ForkThread(EffectUtil.CreateSeraphimFactoryBuildingEffects, unitBeingBuilt, BuildBones, 'Attachpoint', self.BuildEffectsBag)
unitBeingBuilt.Trash:Add(thread)
end,
OnStartBuild = function(self, unitBeingBuilt, order)
-- Set goal for rotator
local unitid = self:GetBlueprint().General.UpgradesTo
if unitBeingBuilt:GetUnitId() == unitid and order == 'Upgrade' then
-- Stop pods that exist in the upgraded unit
local savedAngle
if self.Rotator1 then
savedAngle = self.Rotator1:GetCurrentAngle()
self.Rotator1:SetGoal(savedAngle)
unitBeingBuilt.Rotator1:SetCurrentAngle(savedAngle)
unitBeingBuilt.Rotator1:SetGoal(savedAngle)
-- Freeze the next rotator to 0, since that's where it will be
unitBeingBuilt.Rotator2:SetCurrentAngle(0)
unitBeingBuilt.Rotator2:SetGoal(0)
end
if self.Rotator2 then
savedAngle = self.Rotator2:GetCurrentAngle()
self.Rotator2:SetGoal(savedAngle)
unitBeingBuilt.Rotator2:SetCurrentAngle(savedAngle)
unitBeingBuilt.Rotator2:SetGoal(savedAngle)
unitBeingBuilt.Rotator3:SetCurrentAngle(0)
unitBeingBuilt.Rotator3:SetGoal(0)
end
end
SeaFactoryUnit.OnStartBuild(self, unitBeingBuilt, order)
end,
UpgradingState = State(SeaFactoryUnit.UpgradingState) {
OnStopBuild = function(self, unitBuilding)
if unitBuilding:GetFractionComplete() == 1 then
-- Start halted rotators on upgraded unit
if unitBuilding.Rotator1 then
unitBuilding.Rotator1:ClearGoal()
end
if unitBuilding.Rotator2 then
unitBuilding.Rotator2:ClearGoal()
end
if unitBuilding.Rotator3 then
unitBuilding.Rotator3:ClearGoal()
end
end
SeaFactoryUnit.UpgradingState.OnStopBuild(self, unitBuilding)
end,
OnFailedToBuild = function(self)
SeaFactoryUnit.UpgradingState.OnFailedToBuild(self)
-- Failed to build, so resume rotators
if self.Rotator1 then
self.Rotator1:ClearGoal()
self.Rotator1:SetSpeed(5)
end
if self.Rotator2 then
self.Rotator2:ClearGoal()
self.Rotator2:SetSpeed(5)
end
end,
},
}
-- SEA UNITS
SSeaUnit = Class(DefaultUnitsFile.SeaUnit) {}
-- SHIELD LAND UNITS
SShieldHoverLandUnit = Class(ShieldHoverLandUnit) {}
-- SHIELD LAND UNITS
SShieldLandUnit = Class(ShieldLandUnit) {}
-- SHIELD STRUCTURES
SShieldStructureUnit = Class(ShieldStructureUnit) {
OnShieldEnabled = function(self)
ShieldStructureUnit.OnShieldEnabled(self)
if not self.AnimationManipulator then
self.AnimationManipulator = CreateAnimator(self)
self.Trash:Add(self.AnimationManipulator)
self.AnimationManipulator:PlayAnim(self:GetBlueprint().Display.AnimationActivate, false)
end
self.AnimationManipulator:SetRate(1)
end,
OnShieldDisabled = function(self)
ShieldStructureUnit.OnShieldDisabled(self)
if not self.AnimationManipulator then return end
self.AnimationManipulator:SetRate(-1)
end,
}
-- STRUCTURES
SStructureUnit = Class(StructureUnit) {}
-- SUBMARINE UNITS
SSubUnit = Class(DefaultUnitsFile.SubUnit) {
IdleSubBones = {},
IdleSubEffects = {}
}
-- TRANSPORT BEACON UNITS
STransportBeaconUnit = Class(DefaultUnitsFile.TransportBeaconUnit) {}
-- WALKING LAND UNITS
SWalkingLandUnit = DefaultUnitsFile.WalkingLandUnit
-- WALL STRUCTURES
SWallStructureUnit = Class(DefaultUnitsFile.WallStructureUnit) {}
-- CIVILIAN STRUCTURES
SCivilianStructureUnit = Class(SStructureUnit) {}
-- QUANTUM GATE UNITS
SQuantumGateUnit = Class(QuantumGateUnit) {}
-- RADAR JAMMER UNITS
SRadarJammerUnit = Class(RadarJammerUnit) {}
-- Seraphim energy ball units
SEnergyBallUnit = Class(SHoverLandUnit) {
timeAlive = 0,
OnCreate = function(self)
SHoverLandUnit.OnCreate(self)
self:SetCanTakeDamage(false)
self:SetCanBeKilled(false)
self:PlayUnitSound('Spawn')
ChangeState(self, self.KillingState)
end,
KillingState = State {
LifeThread = function(self)
WaitSeconds(self:GetBlueprint().Lifetime)
ChangeState(self, self.DeathState)
end,
Main = function(self)
local bp = self:GetBlueprint()
local aiBrain = self:GetAIBrain()
-- Queue up random moves
local x, y,z = unpack(self:GetPosition())
for i = 1, 100 do
IssueMove({self}, {x + Random(-bp.MaxMoveRange, bp.MaxMoveRange), y, z + Random(-bp.MaxMoveRange, bp.MaxMoveRange)})
end
-- Weapon information
local weaponMaxRange = bp.Weapon[1].MaxRadius
local weaponMinRange = bp.Weapon[1].MinRadius or 0
local beamLifetime = bp.Weapon[1].BeamLifetime or 1
local reaquireTime = bp.Weapon[1].RequireTime or 0.5
local weapon = self:GetWeapon(1)
self:ForkThread(self.LifeThread)
while true do
local location = self:GetPosition()
local targets = aiBrain:GetUnitsAroundPoint(categories.LAND - categories.UNTARGETABLE, location, weaponMaxRange)
local filteredUnits = {}
for k, v in targets do
if VDist3(location, v:GetPosition()) >= weaponMinRange and v ~= self then
table.insert(filteredUnits, v)
end
end
local target = filteredUnits[Random(1, table.getn(filteredUnits))]
if target then
weapon:SetTargetEntity(target)
else
weapon:SetTargetGround({location[1] + Random(-20, 20), location[2], location[3] + Random(-20, 20)})
end
-- Wait a tick to let the target update awesomely.
WaitSeconds(.1)
self.timeAlive = self.timeAlive + .1
weapon:FireWeapon()
WaitSeconds(beamLifetime)
DefaultBeamWeapon.PlayFxBeamEnd(weapon, weapon.Beams[1].Beam)
WaitSeconds(reaquireTime)
end
end,
ComputeWaitTime = function(self)
local timeLeft = self:GetBlueprint().Lifetime - self.timeAlive
local maxWait = 75
if timeLeft < 7.5 and timeLeft > 2.5 then
maxWait = timeLeft * 10
end
local waitTime = timeLeft
if timeLeft > 2.5 then
waitTime = Random(5, maxWait)
end
self.timeAlive = self.timeAlive + (waitTime * .1)
WaitSeconds(waitTime * .1)
end,
},
DeathState = State {
Main = function(self)
self:SetCanBeKilled(true)
if self:GetCurrentLayer() == 'Water' then
self:PlayUnitSound('HoverKilledOnWater')
end
self:PlayUnitSound('Destroyed')
self:Destroy()
end,
},
}