forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EffectUtilities.lua
1841 lines (1557 loc) · 74.2 KB
/
EffectUtilities.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
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-----------------------------------------------------------------
-- File : /lua/EffectUtilities.lua
-- Author(s): Gordon Duclos
-- Summary : Effect Utility functions for scripts.
-- Copyright © 2006 Gas Powered Games, Inc. All rights reserved.
-----------------------------------------------------------------
local util = import('utilities.lua')
local Entity = import('/lua/sim/Entity.lua').Entity
local EffectTemplate = import('/lua/EffectTemplates.lua')
local RandomFloat = import('/lua/utilities.lua').GetRandomFloat
function CreateEffects(obj, army, EffectTable)
local emitters = {}
for _, v in EffectTable do
table.insert(emitters, CreateEmitterAtEntity(obj, army, v))
end
return emitters
end
function CreateEffectsWithOffset(obj, army, EffectTable, x, y, z)
local emitters = {}
for _, v in EffectTable do
table.insert(emitters, CreateEmitterAtEntity(obj, army, v):OffsetEmitter(x, y, z))
end
return emitters
end
function CreateEffectsWithRandomOffset(obj, army, EffectTable, xRange, yRange, zRange)
local emitters = {}
for _, v in EffectTable do
table.insert(emitters, CreateEmitterOnEntity(obj, army, v):OffsetEmitter(util.GetRandomOffset(xRange, yRange, zRange, 1)))
end
return emitters
end
function CreateBoneEffects(obj, bone, army, EffectTable)
local emitters = {}
for _, v in EffectTable do
table.insert(emitters, CreateEmitterAtBone(obj, bone, army, v))
end
return emitters
end
function CreateBoneEffectsOffset(obj, bone, army, EffectTable, x, y, z)
local emitters = {}
for _, v in EffectTable do
table.insert(emitters, CreateEmitterAtBone(obj, bone, army, v):OffsetEmitter(x, y, z))
end
return emitters
end
function CreateBoneTableEffects(obj, BoneTable, army, EffectTable)
for _, vBone in BoneTable do
for _, vEffect in EffectTable do
table.insert(emitters, CreateEmitterAtBone(obj, vBone, army, vEffect))
end
end
end
function CreateBoneTableRangedScaleEffects(obj, BoneTable, EffectTable, army, ScaleMin, ScaleMax)
for _, vBone in BoneTable do
for _, vEffect in EffectTable do
CreateEmitterAtBone(obj, vBone, army, vEffect):ScaleEmitter(util.GetRandomFloat(ScaleMin, ScaleMax))
end
end
end
function CreateRandomEffects(obj, army, EffectTable, NumEffects)
local NumTableEntries = table.getn(EffectTable)
local emitters = {}
for i = 1, NumEffects do
table.insert(emitters, CreateEmitterOnEntity(obj, army, EffectTable[util.GetRandomInt(1, NumTableEntries)]))
end
return emitters
end
function ScaleEmittersParam(Emitters, param, minRange, maxRange)
for _, v in Emitters do
v:SetEmitterParam(param, util.GetRandomFloat(minRange, maxRange))
end
end
function CreateBuildCubeThread(unitBeingBuilt, builder, OnBeingBuiltEffectsBag)
local bp = unitBeingBuilt:GetBlueprint()
local mul = 1.15
local xPos, yPos, zPos = unpack(unitBeingBuilt:GetPosition())
local proj = nil
yPos = yPos + (bp.Physics.MeshExtentsOffsetY or 0)
local x = bp.Physics.MeshExtentsX or (bp.Footprint.SizeX * mul)
local z = bp.Physics.MeshExtentsZ or (bp.Footprint.SizeZ * mul)
local y = bp.Physics.MeshExtentsY or (0.5 + (x + z) * 0.1)
-- Create a quick glow effect at location where unit is goig to be built
proj = unitBeingBuilt:CreateProjectile('/effects/Entities/UEFBuildEffect/UEFBuildEffect02_proj.bp', 0, 0, 0, nil, nil, nil)
proj:SetScale(x * 1.05, y * 0.2, z * 1.05)
WaitSeconds(0.1)
if unitBeingBuilt.Dead then
return
end
local BuildBaseEffect = unitBeingBuilt:CreateProjectile('/effects/Entities/UEFBuildEffect/UEFBuildEffect03_proj.bp', 0, 0, 0, nil, nil, nil)
OnBeingBuiltEffectsBag:Add(BuildBaseEffect)
unitBeingBuilt.Trash:Add(BuildBaseEffect)
Warp(BuildBaseEffect, Vector(xPos, yPos - y, zPos))
BuildBaseEffect:SetScale(x, y, z)
BuildBaseEffect:SetVelocity(0, 1.4 * y, 0)
WaitSeconds(0.8)
if unitBeingBuilt.Dead then
return
end
if not BuildBaseEffect:BeenDestroyed() then
BuildBaseEffect:SetVelocity(0)
end
unitBeingBuilt:ShowBone(0, true)
unitBeingBuilt:HideLandBones()
unitBeingBuilt.BeingBuiltShowBoneTriggered = true
local lComplete = unitBeingBuilt:GetFractionComplete()
WaitSeconds(0.3)
if unitBeingBuilt.Dead then
return
end
-- Create glow slice cuts and resize base cube
local slice = nil
local SlicePeriod = 1.2
local cComplete = unitBeingBuilt:GetFractionComplete()
while not unitBeingBuilt.Dead and cComplete < 1.0 do
if lComplete < cComplete and not BuildBaseEffect:BeenDestroyed() then
proj = BuildBaseEffect:CreateProjectile('/effects/Entities/UEFBuildEffect/UEFBuildEffect02_proj.bp', 0, y * (1 - cComplete), 0, nil, nil, nil)
OnBeingBuiltEffectsBag:Add(proj)
slice = math.abs(lComplete - cComplete)
proj:SetScale(x, y * slice, z)
BuildBaseEffect:SetScale(x, y * (1 - cComplete), z)
end
WaitSeconds(SlicePeriod)
if unitBeingBuilt.Dead then
break
end
lComplete = cComplete
cComplete = unitBeingBuilt:GetFractionComplete()
end
end
function CreateUEFUnitBeingBuiltEffects(builder, unitBeingBuilt, BuildEffectsBag)
local army = builder:GetArmy()
local buildAttachBone = builder:GetBlueprint().Display.BuildAttachBone
BuildEffectsBag:Add(CreateAttachedEmitter(builder, buildAttachBone, army, '/effects/emitters/uef_mobile_unit_build_01_emit.bp'))
end
function CreateUEFBuildSliceBeams(builder, unitBeingBuilt, BuildEffectBones, BuildEffectsBag)
local army = builder:GetArmy()
local BeamBuildEmtBp = '/effects/emitters/build_beam_01_emit.bp'
local buildbp = unitBeingBuilt:GetBlueprint()
local x, y, z = unpack(unitBeingBuilt:GetPosition())
y = y + (buildbp.Physics.MeshExtentsOffsetY or 0)
-- Create a projectile for the end of build effect and warp it to the unit
local BeamEndEntity = unitBeingBuilt:CreateProjectile('/effects/entities/UEFBuild/UEFBuild01_proj.bp', 0, 0, 0, nil, nil, nil)
BuildEffectsBag:Add(BeamEndEntity)
-- Create build beams
if BuildEffectBones ~= nil then
local beamEffect = nil
for i, BuildBone in BuildEffectBones do
BuildEffectsBag:Add(AttachBeamEntityToEntity(builder, BuildBone, BeamEndEntity, -1, army, BeamBuildEmtBp))
BuildEffectsBag:Add(CreateAttachedEmitter(builder, BuildBone, army, '/effects/emitters/flashing_blue_glow_01_emit.bp'))
end
end
-- Determine beam positioning on build cube, this should match sizes of CreateBuildCubeThread
local mul = 1.15
local ox = buildbp.Physics.MeshExtentsX or (buildbp.Footprint.SizeX * mul)
local oz = buildbp.Physics.MeshExtentsZ or (buildbp.Footprint.SizeZ * mul)
local oy = (buildbp.Physics.MeshExtentsY or (0.5 + (ox + oz) * 0.1))
ox = ox * 0.5
oz = oz * 0.5
-- Determine the the 2 closest edges of the build cube and use those for the location of our laser
local VectorExtentsList = { Vector(x + ox, y + oy, z + oz), Vector(x + ox, y + oy, z - oz), Vector(x - ox, y + oy, z + oz), Vector(x - ox, y + oy, z - oz) }
local endVec1 = util.GetClosestVector(builder:GetPosition(), VectorExtentsList)
for k, v in VectorExtentsList do
if v == endVec1 then
table.remove(VectorExtentsList, k)
end
end
local endVec2 = util.GetClosestVector(builder:GetPosition(), VectorExtentsList)
local cx1, cy1, cz1 = unpack(endVec1)
local cx2, cy2, cz2 = unpack(endVec2)
-- Determine a the velocity of our projectile, used for the scaning effect
local velX = 2 * (endVec2.x - endVec1.x)
local velY = 2 * (endVec2.y - endVec1.y)
local velZ = 2 * (endVec2.z - endVec1.z)
if unitBeingBuilt:GetFractionComplete() == 0 then
Warp(BeamEndEntity, Vector((cx1 + cx2) * 0.5, ((cy1 + cy2) * 0.5) - oy, (cz1 + cz2) * 0.5))
WaitSeconds(0.8)
end
local flipDirection = true
-- Warp our projectile back to the initial corner and lower based on build completeness
while not builder:BeenDestroyed() and not unitBeingBuilt:BeenDestroyed() do
if flipDirection then
Warp(BeamEndEntity, Vector(cx1, (cy1 - (oy * unitBeingBuilt:GetFractionComplete())), cz1))
BeamEndEntity:SetVelocity(velX, velY, velZ)
flipDirection = false
else
Warp(BeamEndEntity, Vector(cx2, (cy2 - (oy * unitBeingBuilt:GetFractionComplete())), cz2))
BeamEndEntity:SetVelocity(-velX, -velY, -velZ)
flipDirection = true
end
WaitSeconds(0.6)
end
end
function CreateUEFCommanderBuildSliceBeams(builder, unitBeingBuilt, BuildEffectBones, BuildEffectsBag)
local army = builder:GetArmy()
local BeamBuildEmtBp = '/effects/emitters/build_beam_01_emit.bp'
local buildbp = unitBeingBuilt:GetBlueprint()
local x, y, z = unpack(unitBeingBuilt:GetPosition())
y = y + (buildbp.Physics.MeshExtentsOffsetY or 0)
-- Create a projectile for the end of build effect and warp it to the unit
local BeamEndEntity = unitBeingBuilt:CreateProjectile('/effects/entities/UEFBuild/UEFBuild01_proj.bp', 0, 0, 0, nil, nil, nil)
local BeamEndEntity2 = unitBeingBuilt:CreateProjectile('/effects/entities/UEFBuild/UEFBuild01_proj.bp', 0, 0, 0, nil, nil, nil)
BuildEffectsBag:Add(BeamEndEntity)
BuildEffectsBag:Add(BeamEndEntity2)
-- Create build beams
if BuildEffectBones ~= nil then
local beamEffect = nil
for i, BuildBone in BuildEffectBones do
BuildEffectsBag:Add(AttachBeamEntityToEntity(builder, BuildBone, BeamEndEntity, -1, army, BeamBuildEmtBp))
BuildEffectsBag:Add(AttachBeamEntityToEntity(builder, BuildBone, BeamEndEntity2, -1, army, BeamBuildEmtBp))
BuildEffectsBag:Add(CreateAttachedEmitter(builder, BuildBone, army, '/effects/emitters/flashing_blue_glow_01_emit.bp'))
end
end
-- Determine beam positioning on build cube, this should match sizes of CreateBuildCubeThread
local mul = 1.15
local ox = buildbp.Physics.MeshExtentsX or (buildbp.Footprint.SizeX * mul)
local oz = buildbp.Physics.MeshExtentsZ or (buildbp.Footprint.SizeZ * mul)
local oy = (buildbp.Physics.MeshExtentsY or (0.5 + (ox + oz) * 0.1))
ox = ox * 0.5
oz = oz * 0.5
-- Determine the the 2 closest edges of the build cube and use those for the location of our laser
local VectorExtentsList = { Vector(x + ox, y + oy, z + oz), Vector(x + ox, y + oy, z - oz), Vector(x - ox, y + oy, z + oz), Vector(x - ox, y + oy, z - oz) }
local endVec1 = util.GetClosestVector(builder:GetPosition(), VectorExtentsList)
for k, v in VectorExtentsList do
if v == endVec1 then
table.remove(VectorExtentsList, k)
end
end
local endVec2 = util.GetClosestVector(builder:GetPosition(), VectorExtentsList)
local cx1, cy1, cz1 = unpack(endVec1)
local cx2, cy2, cz2 = unpack(endVec2)
-- Determine a the velocity of our projectile, used for the scaning effect
local velX = 2 * (endVec2.x - endVec1.x)
local velY = 2 * (endVec2.y - endVec1.y)
local velZ = 2 * (endVec2.z - endVec1.z)
if unitBeingBuilt:GetFractionComplete() == 0 then
Warp(BeamEndEntity, Vector(cx1, cy1 - oy, cz1))
Warp(BeamEndEntity2, Vector(cx2, cy2 - oy, cz2))
WaitSeconds(0.8)
end
local flipDirection = true
-- Warp our projectile back to the initial corner and lower based on build completeness
while not builder:BeenDestroyed() and not unitBeingBuilt:BeenDestroyed() do
if flipDirection then
Warp(BeamEndEntity, Vector(cx1, (cy1 - (oy * unitBeingBuilt:GetFractionComplete())), cz1))
BeamEndEntity:SetVelocity(velX, velY, velZ)
Warp(BeamEndEntity2, Vector(cx2, (cy2 - (oy * unitBeingBuilt:GetFractionComplete())), cz2))
BeamEndEntity2:SetVelocity(-velX, -velY, -velZ)
flipDirection = false
else
Warp(BeamEndEntity, Vector(cx2, (cy2 - (oy * unitBeingBuilt:GetFractionComplete())), cz2))
BeamEndEntity:SetVelocity(-velX, -velY, -velZ)
Warp(BeamEndEntity2, Vector(cx1, (cy1 - (oy * unitBeingBuilt:GetFractionComplete())), cz1))
BeamEndEntity2:SetVelocity(velX, velY, velZ)
flipDirection = true
end
WaitSeconds(0.6)
end
end
function CreateDefaultBuildBeams(builder, unitBeingBuilt, BuildEffectBones, BuildEffectsBag)
local BeamBuildEmtBp = '/effects/emitters/build_beam_01_emit.bp'
local ox, oy, oz = unpack(unitBeingBuilt:GetPosition())
local BeamEndEntity = Entity()
local army = builder:GetArmy()
BuildEffectsBag:Add(BeamEndEntity)
Warp(BeamEndEntity, Vector(ox, oy, oz))
local BuildBeams = {}
-- Create build beams
if BuildEffectBones ~= nil then
local beamEffect = nil
for i, BuildBone in BuildEffectBones do
local beamEffect = AttachBeamEntityToEntity(builder, BuildBone, BeamEndEntity, -1, army, BeamBuildEmtBp)
table.insert(BuildBeams, beamEffect)
BuildEffectsBag:Add(beamEffect)
end
end
CreateEmitterOnEntity(BeamEndEntity, builder:GetArmy(), '/effects/emitters/sparks_08_emit.bp')
local waitTime = util.GetRandomFloat(0.3, 1.5)
while not builder:BeenDestroyed() and not unitBeingBuilt:BeenDestroyed() do
local x, y, z = builder.GetRandomOffset(unitBeingBuilt, 1)
Warp(BeamEndEntity, Vector(ox + x, oy + y, oz + z))
WaitSeconds(waitTime)
end
end
function CreateAeonBuildBaseThread(unitBeingBuilt, builder, EffectsBag)
local bp = unitBeingBuilt:GetBlueprint()
local x, y, z = unpack(unitBeingBuilt:GetPosition())
local mul = 0.5
local sx = bp.Physics.MeshExtentsX or bp.Footprint.SizeX * mul
local sz = bp.Physics.MeshExtentsZ or bp.Footprint.SizeZ * mul
local sy = bp.Physics.MeshExtentsY or sx + sz
local slice = nil
WaitSeconds(0.1)
-- Create a pool mercury that slow draws into the build unit
local BuildBaseEffect = unitBeingBuilt:CreateProjectile('/effects/entities/AeonBuildEffect/AeonBuildEffect01_proj.bp', nil, 0, 0, nil, nil, nil)
BuildBaseEffect:SetScale(sx, sy * 1.5, sz)
Warp(BuildBaseEffect, Vector(x, y, z))
BuildBaseEffect:SetOrientation(unitBeingBuilt:GetOrientation(), true)
unitBeingBuilt.Trash:Add(BuildBaseEffect)
EffectsBag:Add(BuildBaseEffect)
CreateEmitterOnEntity(BuildBaseEffect, builder:GetArmy(), '/effects/emitters/aeon_being_built_ambient_01_emit.bp')
:SetEmitterCurveParam('X_POSITION_CURVE', 0, sx * 1.5)
:SetEmitterCurveParam('Z_POSITION_CURVE', 0, sz * 1.5)
CreateEmitterOnEntity(BuildBaseEffect, builder:GetArmy(), '/effects/emitters/aeon_being_built_ambient_03_emit.bp')
:ScaleEmitter((sx + sz) * 0.3)
local slider = CreateSlider(unitBeingBuilt, 0)
slider:SetWorldUnits(true)
slider:SetGoal(0, -sy, 0)
slider:SetSpeed(-1)
local fraction = unitBeingBuilt:GetFractionComplete()
while not unitBeingBuilt.Dead and fraction < 1 do
scale = 1.2 - math.pow(fraction, 4)
BuildBaseEffect:SetScale(sx * scale, 1.5 * sy * scale, sz * scale)
slider:SetGoal(0, (fraction * sy - sy), 0)
WaitSeconds(0.1)
fraction = unitBeingBuilt:GetFractionComplete()
end
slider:Destroy()
BuildBaseEffect:Destroy()
end
function CreateCybranBuildBeams(builder, unitBeingBuilt, BuildEffectBones, BuildEffectsBag)
WaitSeconds(0.2)
local army = builder:GetArmy()
local BeamBuildEmtBp = '/effects/emitters/build_beam_02_emit.bp'
local BeamEndEntities = {}
local ox, oy, oz = unpack(unitBeingBuilt:GetPosition())
if BuildEffectBones then
for i, BuildBone in BuildEffectBones do
local beamEnd = Entity()
builder.Trash:Add(beamEnd)
table.insert(BeamEndEntities, beamEnd)
BuildEffectsBag:Add(beamEnd)
Warp(beamEnd, Vector(ox, oy, oz))
CreateEmitterOnEntity(beamEnd, army, EffectTemplate.CybranBuildSparks01)
CreateEmitterOnEntity(beamEnd, army, EffectTemplate.CybranBuildFlash01)
BuildEffectsBag:Add(AttachBeamEntityToEntity(builder, BuildBone, beamEnd, -1, army, BeamBuildEmtBp))
end
end
while not builder:BeenDestroyed() and not unitBeingBuilt:BeenDestroyed() do
for _, v in BeamEndEntities do
local x, y, z = builder.GetRandomOffset(unitBeingBuilt, 1)
if v and not v:BeenDestroyed() then
Warp(v, Vector(ox + x, oy + y, oz + z))
end
end
WaitSeconds(0.2)
end
end
function SpawnBuildBots(builder, unitBeingBuilt, BuildEffectsBag)
-- Buildbots are scaled: ~ 1 pr 15 units of BP
-- clamped to a max of 10 to avoid insane FPS drop
-- with mods that modify BP
local numBots = math.min(math.ceil((10 + builder:GetBuildRate()) / 15), 10)
if not builder.buildBots then
builder.buildBots = {}
end
local builderArmy = builder:GetArmy()
local unitBeingBuiltArmy = unitBeingBuilt:GetArmy()
-- If is new, won't spawn build bots if they might accidentally capture the unit
if builderArmy == unitBeingBuiltArmy or IsHumanUnit(unitBeingBuilt) then
for k, b in builder.buildBots do
if b:BeenDestroyed() then
builder.buildBots[k] = nil
end
end
local numUnits = numBots - table.getsize(builder.buildBots)
if numUnits > 0 then
local x, y, z = unpack(builder:GetPosition())
local qx, qy, qz, qw = unpack(builder:GetOrientation())
local angleInitial = 180
local VecMul = 0.5
local xVec = 0
local yVec = builder:GetBlueprint().SizeY * 0.5
local zVec = 0
local angle = (2 * math.pi) / numUnits
-- Launch projectiles at semi-random angles away from the sphere, with enough
-- initial velocity to escape sphere core
for i = 0, (numUnits - 1) do
xVec = math.sin(angleInitial + (i * angle)) * VecMul
zVec = math.cos(angleInitial + (i * angle)) * VecMul
local bot = CreateUnit('ura0001', builderArmy, x + xVec, y + yVec, z + zVec, qx, qy, qz, qw, 'Air')
-- Make build bots unkillable
bot:SetCanTakeDamage(false)
bot:SetCanBeKilled(false)
bot.spawnedBy = builder
table.insert(builder.buildBots, bot)
end
end
for _, bot in builder.buildBots do
ChangeState(bot, bot.BuildState)
end
return builder.buildBots
end
end
function CreateCybranEngineerBuildEffects(builder, BuildBones, BuildBots, BuildEffectsBag)
-- Create build constant build effect for each build effect bone defined
if BuildBones and BuildBots then
local army = builder:GetArmy()
for _, vBone in BuildBones do
for _, vEffect in EffectTemplate.CybranBuildUnitBlink01 do
BuildEffectsBag:Add(CreateAttachedEmitter(builder, vBone, army, vEffect))
end
WaitSeconds(util.GetRandomFloat(0.2, 1))
end
if builder:BeenDestroyed() then
return
end
local i = 1
for _, vBot in BuildBots do
if not vBot or vBot:BeenDestroyed() then
continue
end
BuildEffectsBag:Add(AttachBeamEntityToEntity(builder, BuildBones[i], vBot, -1, army, '/effects/emitters/build_beam_03_emit.bp'))
i = i + 1
end
end
end
function CreateCybranFactoryBuildEffects(builder, unitBeingBuilt, BuildBones, BuildEffectsBag)
local BuildEffects = {
'/effects/emitters/sparks_03_emit.bp',
'/effects/emitters/flashes_01_emit.bp',
}
local UnitBuildEffects = {
'/effects/emitters/build_cybran_spark_flash_04_emit.bp',
'/effects/emitters/build_sparks_blue_02_emit.bp',
}
local army = builder:GetArmy()
CreateCybranBuildBeams(builder, unitBeingBuilt, BuildBones.BuildEffectBones, BuildEffectsBag)
for _, vB in BuildBones.BuildEffectBones do
for _, vE in BuildEffects do
BuildEffectsBag:Add(CreateAttachedEmitter(builder, vB, army, vE))
end
end
BuildEffectsBag:Add(CreateAttachedEmitter(builder, BuildBones.BuildAttachBone, army, '/effects/emitters/cybran_factory_build_01_emit.bp'))
-- Add sparks to the collision box of the unit being built
local sx, sy, sz = 0
while not unitBeingBuilt.Dead and unitBeingBuilt:GetFractionComplete() < 1 do
sx, sy, sz = unitBeingBuilt:GetRandomOffset(1)
for _, vE in UnitBuildEffects do
CreateEmitterOnEntity(unitBeingBuilt, army, vE):OffsetEmitter(sx, sy, sz)
end
WaitSeconds(util.GetRandomFloat(0.1, 0.6))
end
end
function CreateAeonConstructionUnitBuildingEffects(builder, unitBeingBuilt, BuildEffectsBag)
local army = builder:GetArmy()
BuildEffectsBag:Add(CreateEmitterOnEntity(builder, army, '/effects/emitters/aeon_build_01_emit.bp'))
local beamEnd = Entity()
BuildEffectsBag:Add(beamEnd)
Warp(beamEnd, unitBeingBuilt:GetPosition())
for _, v in EffectTemplate.AeonBuildBeams01 do
local beamEffect = AttachBeamEntityToEntity(builder, 0, beamEnd, -1, army, v)
beamEffect:SetEmitterParam('POSITION_Z', 0.45)
BuildEffectsBag:Add(beamEffect)
end
end
function CreateAeonCommanderBuildingEffects(builder, unitBeingBuilt, BuildEffectBones, BuildEffectsBag)
local army = builder:GetArmy()
local beamEnd = Entity()
BuildEffectsBag:Add(beamEnd)
Warp(beamEnd, unitBeingBuilt:GetPosition())
for _, vBone in BuildEffectBones do
BuildEffectsBag:Add(CreateAttachedEmitter(builder, vBone, army, '/effects/emitters/aeon_build_02_emit.bp'))
for _, v in EffectTemplate.AeonBuildBeams01 do
local beamEffect = AttachBeamEntityToEntity(builder, vBone, beamEnd, -1, army, v)
BuildEffectsBag:Add(beamEffect)
end
end
end
function CreateAeonFactoryBuildingEffects(builder, unitBeingBuilt, BuildEffectBones, BuildBone, EffectsBag)
local bp = unitBeingBuilt:GetBlueprint()
local army = builder:GetArmy()
local x, y, z = unpack(builder:GetPosition(BuildBone))
local mul = 1
local sx = bp.Physics.MeshExtentsX or bp.Footprint.SizeX * mul
local sz = bp.Physics.MeshExtentsZ or bp.Footprint.SizeZ * mul
local sy = bp.Physics.MeshExtentsY or sx + sz
local slice = nil
-- Create a pool mercury that slow draws into the build unit
local BuildBaseEffect = unitBeingBuilt:CreateProjectile('/effects/entities/AeonBuildEffect/AeonBuildEffect01_proj.bp', 0, 0, 1, nil, nil, nil)
BuildBaseEffect:SetScale(sx, 1.5 * sy, sz)
Warp(BuildBaseEffect, Vector(x, y - 0.05, z))
unitBeingBuilt.Trash:Add(BuildBaseEffect)
EffectsBag:Add(BuildBaseEffect)
CreateEmitterOnEntity(BuildBaseEffect, builder:GetArmy(), '/effects/emitters/aeon_being_built_ambient_02_emit.bp')
:SetEmitterCurveParam('X_POSITION_CURVE', 0, sx * 1.5)
:SetEmitterCurveParam('Z_POSITION_CURVE', 0, sz * 1.5)
CreateEmitterOnEntity(BuildBaseEffect, builder:GetArmy(), '/effects/emitters/aeon_being_built_ambient_03_emit.bp')
:ScaleEmitter((sx + sz) * 0.3)
for _, vBone in BuildEffectBones do
EffectsBag:Add(CreateAttachedEmitter(builder, vBone, army, '/effects/emitters/aeon_build_03_emit.bp'))
for _, vBeam in EffectTemplate.AeonBuildBeams02 do
local beamEffect = AttachBeamEntityToEntity(builder, vBone, builder, BuildBone, army, vBeam)
EffectsBag:Add(beamEffect)
end
end
local slider = CreateSlider(unitBeingBuilt, 0)
unitBeingBuilt.Trash:Add(slider)
EffectsBag:Add(slider)
slider:SetWorldUnits(true)
slider:SetSpeed(-1)
slider:SetGoal(0, -sy * 0.5, 0)
local fraction = unitBeingBuilt:GetFractionComplete()
local scale
while not unitBeingBuilt.Dead and fraction < 1 and not IsDestroyed(slider) do
scale = 1 - math.pow(fraction, 2)
BuildBaseEffect:SetScale(sx * scale, 1.5 * sy * scale, sz * scale)
slider:SetGoal(0, 0.5 * (fraction * sy - sy), 0)
WaitSeconds(0.1)
fraction = unitBeingBuilt:GetFractionComplete()
end
slider:Destroy()
BuildBaseEffect:Destroy()
end
function CreateSeraphimUnitEngineerBuildingEffects(builder, unitBeingBuilt, BuildEffectBones, BuildEffectsBag)
local army = builder:GetArmy()
for _, vBone in BuildEffectBones do
BuildEffectsBag:Add(CreateAttachedEmitter(builder, vBone, army, '/effects/emitters/seraphim_build_01_emit.bp'))
for _, v in EffectTemplate.SeraphimBuildBeams01 do
local beamEffect = AttachBeamEntityToEntity(builder, vBone, unitBeingBuilt, -1, army, v)
BuildEffectsBag:Add(beamEffect)
end
end
end
function CreateSeraphimFactoryBuildingEffects(builder, unitBeingBuilt, BuildEffectBones, BuildBone, EffectsBag)
local bp = unitBeingBuilt:GetBlueprint()
local army = builder:GetArmy()
local x, y, z = unpack(builder:GetPosition(BuildBone))
local mul = 1
local sx = bp.Physics.MeshExtentsX or bp.Footprint.SizeX * mul
local sz = bp.Physics.MeshExtentsZ or bp.Footprint.SizeZ * mul
local sy = bp.Physics.MeshExtentsY or sx + sz
local slice = nil
-- Create a pool mercury that slow draws into the build unit
local BuildBaseEffect = unitBeingBuilt:CreateProjectile('/effects/entities/SeraphimBuildEffect01/SeraphimBuildEffect01_proj.bp', nil, 0, 0, nil, nil, nil)
BuildBaseEffect:SetScale(sx, 1, sz)
BuildBaseEffect:SetOrientation(unitBeingBuilt:GetOrientation(), true)
Warp(BuildBaseEffect, Vector(x, y - 0.05, z))
unitBeingBuilt.Trash:Add(BuildBaseEffect)
EffectsBag:Add(BuildBaseEffect)
for _, vBone in BuildEffectBones do
EffectsBag:Add(CreateAttachedEmitter(builder, vBone, army, '/effects/emitters/seraphim_build_01_emit.bp'))
for _, vBeam in EffectTemplate.SeraphimBuildBeams01 do
EffectsBag:Add(AttachBeamEntityToEntity(builder, vBone, unitBeingBuilt, -1, army, vBeam))
EffectsBag:Add(CreateAttachedEmitter(unitBeingBuilt, -1, builder:GetArmy(), '/effects/emitters/seraphim_being_built_ambient_02_emit.bp'))
EffectsBag:Add(CreateAttachedEmitter(unitBeingBuilt, -1, builder:GetArmy(), '/effects/emitters/seraphim_being_built_ambient_03_emit.bp'))
EffectsBag:Add(CreateAttachedEmitter(unitBeingBuilt, -1, builder:GetArmy(), '/effects/emitters/seraphim_being_built_ambient_04_emit.bp'))
EffectsBag:Add(CreateAttachedEmitter(unitBeingBuilt, -1, builder:GetArmy(), '/effects/emitters/seraphim_being_built_ambient_05_emit.bp'))
end
end
local slider = CreateSlider(unitBeingBuilt, 0)
unitBeingBuilt.Trash:Add(slider)
EffectsBag:Add(slider)
slider:SetWorldUnits(true)
slider:SetGoal(0, sy, 0)
slider:SetSpeed(-1)
WaitFor(slider)
if not unitBeingBuilt.Dead then
slider:SetGoal(0, 0, 0)
slider:SetSpeed(0.05)
end
-- Wait till we are 80% done building, then snap our slider to
while not unitBeingBuilt.Dead and unitBeingBuilt:GetFractionComplete() < 0.8 do
WaitSeconds(0.5)
end
if not unitBeingBuilt.Dead then
if not BuildBaseEffect:BeenDestroyed() then
BuildBaseEffect:SetScaleVelocity(-0.6, -0.6, -0.6)
end
if not slider:BeenDestroyed() then
slider:SetSpeed(2)
end
WaitSeconds(0.5)
end
if not slider:BeenDestroyed() then
slider:Destroy()
end
if not BuildBaseEffect:BeenDestroyed() then
BuildBaseEffect:Destroy()
end
end
function CreateSeraphimBuildThread(unitBeingBuilt, builder, EffectsBag, scaleFactor)
local bp = unitBeingBuilt:GetBlueprint()
local x, y, z = unpack(unitBeingBuilt:GetPosition())
local mul = 0.5
local sx = bp.Physics.MeshExtentsX or bp.Footprint.SizeX * mul
local sz = bp.Physics.MeshExtentsZ or bp.Footprint.SizeZ * mul
local sy = bp.Physics.MeshExtentsY or sx + sz
local slice = nil
WaitSeconds(0.1)
local BuildBaseEffect = unitBeingBuilt:CreateProjectile('/effects/entities/SeraphimBuildEffect01/SeraphimBuildEffect01_proj.bp', nil, 0, 0, nil, nil, nil)
BuildBaseEffect:SetScale(sx, 1, sz)
BuildBaseEffect:SetOrientation(unitBeingBuilt:GetOrientation(), true)
Warp(BuildBaseEffect, Vector(x, y, z))
unitBeingBuilt.Trash:Add(BuildBaseEffect)
EffectsBag:Add(BuildBaseEffect)
local BuildEffectBaseEmitters = {
'/effects/emitters/seraphim_being_built_ambient_01_emit.bp',
}
local BuildEffectsEmitters = {
'/effects/emitters/seraphim_being_built_ambient_02_emit.bp',
'/effects/emitters/seraphim_being_built_ambient_03_emit.bp',
'/effects/emitters/seraphim_being_built_ambient_04_emit.bp',
'/effects/emitters/seraphim_being_built_ambient_05_emit.bp',
}
local AdjustedEmitters = {}
local effect = nil
for _, vEffect in BuildEffectsEmitters do
effect = CreateAttachedEmitter(unitBeingBuilt, -1, builder:GetArmy(), vEffect):ScaleEmitter(scaleFactor)
table.insert(AdjustedEmitters, effect)
EffectsBag:Add(effect)
end
for _, vEffect in BuildEffectBaseEmitters do
effect = CreateAttachedEmitter(BuildBaseEffect, -1, builder:GetArmy(), vEffect):ScaleEmitter(scaleFactor)
table.insert(AdjustedEmitters, effect)
EffectsBag:Add(effect)
end
-- Poll the unit being built every 0.5 a second to adjust the effects to match
local fractionComplete = unitBeingBuilt:GetFractionComplete()
local unitScaleMetric = unitBeingBuilt:GetFootPrintSize() * 0.65
while not unitBeingBuilt.Dead and fractionComplete < 1.0 do
WaitSeconds(0.5)
fractionComplete = unitBeingBuilt:GetFractionComplete()
for _, vEffect in AdjustedEmitters do
vEffect:ScaleEmitter(scaleFactor + (unitScaleMetric * fractionComplete))
end
end
-- The flash can now be seen only by the player owning the building, his allies or enemies who
-- have a visual of the building.
local unitsArmy = unitBeingBuilt:GetArmy()
local focusArmy = GetFocusArmy()
if focusArmy == -1 or IsAlly(unitsArmy, focusArmy) then
CreateLightParticle(unitBeingBuilt, -1, unitBeingBuilt:GetArmy(), unitBeingBuilt:GetFootPrintSize() * 7, 8, 'glow_02', 'ramp_blue_22')
elseif IsEnemy(unitsArmy, focusArmy) then
local blip = unitBeingBuilt:GetBlip(focusArmy)
if blip ~= nil and blip:IsSeenNow(focusArmy) then
CreateLightParticle(unitBeingBuilt, -1, unitBeingBuilt:GetArmy(), unitBeingBuilt:GetFootPrintSize() * 7, 8, 'glow_02', 'ramp_blue_22')
end
end
WaitSeconds(0.5)
BuildBaseEffect:Destroy()
end
function CreateSeraphimBuildBaseThread(unitBeingBuilt, builder, EffectsBag)
CreateSeraphimBuildThread(unitBeingBuilt, builder, EffectsBag, 1)
end
function CreateSeraphimExperimentalBuildBaseThread(unitBeingBuilt, builder, EffectsBag)
CreateSeraphimBuildThread(unitBeingBuilt, builder, EffectsBag, 2)
end
function CreateAdjacencyBeams(unit, adjacentUnit, AdjacencyBeamsBag)
local info = {
Unit = adjacentUnit,
Trash = TrashBag(),
}
table.insert(AdjacencyBeamsBag, info)
local uBp = unit:GetBlueprint()
local aBp = adjacentUnit:GetBlueprint()
local army = unit:GetArmy()
local faction = uBp.General.FactionName
-- Determine which effects we will be using
local nodeMesh = nil
local beamEffect = nil
local emitterNodeEffects = {}
local numNodes = 2
local nodeList = {}
local validAdjacency = true
local unitPos = unit:GetPosition()
local adjPos = adjacentUnit:GetPosition()
-- Create hub start/end and all midpoint nodes
local unitHub = {
entity = Entity{},
pos = unit:GetPosition(),
}
local adjacentHub = {
entity = Entity{},
pos = adjacentUnit:GetPosition(),
}
local spec = {
Owner = unit,
}
if faction == 'Aeon' then
nodeMesh = '/effects/entities/aeonadjacencynode/aeonadjacencynode_mesh'
beamEffect = '/effects/emitters/adjacency_aeon_beam_0' .. util.GetRandomInt(1, 3) .. '_emit.bp'
numNodes = 3
elseif faction == 'Cybran' then
nodeMesh = '/effects/entities/cybranadjacencynode/cybranadjacencynode_mesh'
beamEffect = '/effects/emitters/adjacency_cybran_beam_01_emit.bp'
elseif faction == 'UEF' then
nodeMesh = '/effects/entities/uefadjacencynode/uefadjacencynode_mesh'
beamEffect = '/effects/emitters/adjacency_uef_beam_01_emit.bp'
elseif faction == 'Seraphim' then
nodeMesh = '/effects/entities/seraphimadjacencynode/seraphimadjacencynode_mesh'
table.insert(emitterNodeEffects, EffectTemplate.SAdjacencyAmbient01)
if util.GetDistanceBetweenTwoVectors(unitHub.pos, adjacentHub.pos) < 2.5 then
numNodes = 1
else
numNodes = 3
table.insert(emitterNodeEffects, EffectTemplate.SAdjacencyAmbient02)
table.insert(emitterNodeEffects, EffectTemplate.SAdjacencyAmbient03)
end
end
for i = 1, numNodes do
local node =
{
entity = Entity(spec),
pos = {0, 0, 0},
mesh = nil,
}
node.entity:SetVizToNeutrals('Intel')
node.entity:SetVizToEnemies('Intel')
table.insert(nodeList, node)
end
local verticalOffset = 0.05
-- Move Unit Pos towards adjacent unit by bounding box size
local uBpSizeX = uBp.SizeX * 0.5
local uBpSizeZ = uBp.SizeZ * 0.5
local aBpSizeX = aBp.SizeX * 0.5
local aBpSizeZ = aBp.SizeZ * 0.5
-- To Determine positioning, need to use the bounding box or skirt size
local uBpSkirtX = uBp.Physics.SkirtSizeX * 0.5
local uBpSkirtZ = uBp.Physics.SkirtSizeZ * 0.5
local aBpSkirtX = aBp.Physics.SkirtSizeX * 0.5
local aBpSkirtZ = aBp.Physics.SkirtSizeZ * 0.5
-- Get edge corner positions, {TOP, LEFT, BOTTOM, RIGHT}
local unitSkirtBounds = {
unitHub.pos[3] - uBpSkirtZ,
unitHub.pos[1] - uBpSkirtX,
unitHub.pos[3] + uBpSkirtZ,
unitHub.pos[1] + uBpSkirtX,
}
local adjacentSkirtBounds = {
adjacentHub.pos[3] - aBpSkirtZ,
adjacentHub.pos[1] - aBpSkirtX,
adjacentHub.pos[3] + aBpSkirtZ,
adjacentHub.pos[1] + aBpSkirtX,
}
-- Figure out the best matching ogrid position on units bounding box
-- depending on it's skirt size
-- Unit bottom or top skirt is aligned to adjacent unit
if unitSkirtBounds[3] == adjacentSkirtBounds[1] or unitSkirtBounds[1] == adjacentSkirtBounds[3] then
local sharedSkirtLower = unitSkirtBounds[4] - (unitSkirtBounds[4] - adjacentSkirtBounds[2])
local sharedSkirtUpper = unitSkirtBounds[4] - (unitSkirtBounds[4] - adjacentSkirtBounds[4])
local sharedSkirtLen = sharedSkirtUpper - sharedSkirtLower
-- Depending on shared skirt bounds, determine the position of unit hub
-- Find out how many times the shared skirt fits into the unit hub shared skirt
local numAdjSkirtsOnUnitSkirt = (uBpSkirtX * 2) / sharedSkirtLen
local numUnitSkirtsOnAdjSkirt = (aBpSkirtX * 2) / sharedSkirtLen
-- Z-offset, offset adjacency hub positions the proper direction
if unitSkirtBounds[3] == adjacentSkirtBounds[1] then
unitHub.pos[3] = unitHub.pos[3] + uBpSizeZ
adjacentHub.pos[3] = adjacentHub.pos[3] - aBpSizeZ
else -- unitSkirtBounds[1] == adjacentSkirtBounds[3]
unitHub.pos[3] = unitHub.pos[3] - uBpSizeZ
adjacentHub.pos[3] = adjacentHub.pos[3] + aBpSizeZ
end
-- X-offset, Find the shared adjacent x position range
-- If we have more than skirt on this section, then we need to adjust the x position of the unit hub
if numAdjSkirtsOnUnitSkirt > 1 or numUnitSkirtsOnAdjSkirt < 1 then
local uSkirtLen = (unitSkirtBounds[4] - unitSkirtBounds[2]) * 0.5 -- Unit skirt length
local uGridUnitSize = (uBpSizeX * 2) / uSkirtLen -- Determine one grid of adjacency along that length
local xoffset = math.abs(unitSkirtBounds[2] - adjacentSkirtBounds[2]) * 0.5 -- Get offset of the unit along the skirt
unitHub.pos[1] = (unitHub.pos[1] - uBpSizeX) + (xoffset * uGridUnitSize) + (uGridUnitSize * 0.5) -- Now offset the position of adjacent point
end
-- If we have more than skirt on this section, then we need to adjust the x position of the adjacent hub
if numUnitSkirtsOnAdjSkirt > 1 or numAdjSkirtsOnUnitSkirt < 1 then
local aSkirtLen = (adjacentSkirtBounds[4] - adjacentSkirtBounds[2]) * 0.5 -- Adjacent unit skirt length
local aGridUnitSize = (aBpSizeX * 2) / aSkirtLen -- Determine one grid of adjacency along that length ??
local xoffset = math.abs(adjacentSkirtBounds[2] - unitSkirtBounds[2]) * 0.5 -- Get offset of the unit along the adjacent unit
adjacentHub.pos[1] = (adjacentHub.pos[1] - aBpSizeX) + (xoffset * aGridUnitSize) + (aGridUnitSize * 0.5) -- Now offset the position of adjacent point
end
-- Unit right or top left is aligned to adjacent unit
elseif unitSkirtBounds[4] == adjacentSkirtBounds[2] or unitSkirtBounds[2] == adjacentSkirtBounds[4] then
local sharedSkirtLower = unitSkirtBounds[3] - (unitSkirtBounds[3] - adjacentSkirtBounds[1])
local sharedSkirtUpper = unitSkirtBounds[3] - (unitSkirtBounds[3] - adjacentSkirtBounds[3])
local sharedSkirtLen = sharedSkirtUpper - sharedSkirtLower
-- Depending on shared skirt bounds, determine the position of unit hub
-- Find out how many times the shared skirt fits into the unit hub shared skirt
local numAdjSkirtsOnUnitSkirt = (uBpSkirtX * 2) / sharedSkirtLen
local numUnitSkirtsOnAdjSkirt = (aBpSkirtX * 2) / sharedSkirtLen
-- X-offset
if unitSkirtBounds[4] == adjacentSkirtBounds[2] then
unitHub.pos[1] = unitHub.pos[1] + uBpSizeX
adjacentHub.pos[1] = adjacentHub.pos[1] - aBpSizeX
else -- unitSkirtBounds[2] == adjacentSkirtBounds[4]
unitHub.pos[1] = unitHub.pos[1] - uBpSizeX
adjacentHub.pos[1] = adjacentHub.pos[1] + aBpSizeX
end
-- Z-offset, Find the shared adjacent x position range
-- If we have more than skirt on this section, then we need to adjust the x position of the unit hub
if numAdjSkirtsOnUnitSkirt > 1 or numUnitSkirtsOnAdjSkirt < 1 then
local uSkirtLen = (unitSkirtBounds[3] - unitSkirtBounds[1]) * 0.5 -- Unit skirt length
local uGridUnitSize = (uBpSizeZ * 2) / uSkirtLen -- Determine one grid of adjacency along that length
local zoffset = math.abs(unitSkirtBounds[1] - adjacentSkirtBounds[1]) * 0.5 -- Get offset of the unit along the skirt
unitHub.pos[3] = (unitHub.pos[3] - uBpSizeZ) + (zoffset * uGridUnitSize) + (uGridUnitSize * 0.5) -- Now offset the position of adjacent point
end
-- If we have more than skirt on this section, then we need to adjust the x position of the adjacent hub
if numUnitSkirtsOnAdjSkirt > 1 or numAdjSkirtsOnUnitSkirt < 1 then
local aSkirtLen = (adjacentSkirtBounds[3] - adjacentSkirtBounds[1]) * 0.5 -- Adjacent unit skirt length
local aGridUnitSize = (aBpSizeZ * 2) / aSkirtLen -- Determine one grid of adjacency along that length ??
local zoffset = math.abs(adjacentSkirtBounds[1] - unitSkirtBounds[1]) * 0.5 -- Get offset of the unit along the adjacent unit
adjacentHub.pos[3] = (adjacentHub.pos[3] - aBpSizeZ) + (zoffset * aGridUnitSize) + (aGridUnitSize * 0.5) -- Now offset the position of adjacent point
end
end
-- Setup our midpoint positions
if faction == 'Aeon' or faction == 'Seraphim' then
local DirectionVec = util.GetDifferenceVector(unitHub.pos, adjacentHub.pos)
local Dist = util.GetDistanceBetweenTwoVectors(unitHub.pos, adjacentHub.pos)
local PerpVec = util.Cross(DirectionVec, Vector(0, 0.35, 0))
local segmentLen = 1 / (numNodes + 1)
local halfDist = Dist * 0.5
if util.GetRandomInt(0, 1) == 1 then
PerpVec[1] = -PerpVec[1]
PerpVec[2] = -PerpVec[2]
PerpVec[3] = -PerpVec[3]
end
local offsetMul = 0.15
for i = 1, numNodes do
local segmentMul = i * segmentLen
if segmentMul <= 0.5 then
offsetMul = offsetMul + 0.12
else
offsetMul = offsetMul - 0.12
end
nodeList[i].pos = {
unitHub.pos[1] - (DirectionVec[1] * segmentMul) - (PerpVec[1] * offsetMul),
nil,
unitHub.pos[3] - (DirectionVec[3] * segmentMul) - (PerpVec[3] * offsetMul),
}
end
elseif faction == 'Cybran' then
if unitPos[1] == adjPos[1] or unitPos[3] == adjPos[3] then
local Dist = util.GetDistanceBetweenTwoVectors(unitHub.pos, adjacentHub.pos)
local DirectionVec = util.GetScaledDirectionVector(unitHub.pos, adjacentHub.pos, util.GetRandomFloat(0.35, Dist * 0.48))
DirectionVec[2] = 0
local PerpVec = util.Cross(DirectionVec, Vector(0, util.GetRandomFloat(0.2, 0.35), 0))
if util.GetRandomInt(0, 1) == 1 then
PerpVec[1] = -PerpVec[1]
PerpVec[2] = -PerpVec[2]
PerpVec[3] = -PerpVec[3]
end
-- Initialize 2 midpoint segments
nodeList[1].pos = {unitHub.pos[1] - DirectionVec[1], unitHub.pos[2] - DirectionVec[2], unitHub.pos[3] - DirectionVec[3]}
nodeList[2].pos = {adjacentHub.pos[1] + DirectionVec[1], adjacentHub.pos[2] + DirectionVec[2], adjacentHub.pos[3] + DirectionVec[3]}
-- Offset beam positions
nodeList[1].pos[1] = nodeList[1].pos[1] - PerpVec[1]