forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcybranunits.lua
More file actions
499 lines (409 loc) · 16.5 KB
/
cybranunits.lua
File metadata and controls
499 lines (409 loc) · 16.5 KB
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
-----------------------------------------------------------------
-- File : /lua/cybranunits.lua
-- Author(s):
-- Summary :
-- 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 EnergyStorageUnit = DefaultUnitsFile.EnergyStorageUnit
local LandFactoryUnit = DefaultUnitsFile.LandFactoryUnit
local SeaFactoryUnit = DefaultUnitsFile.SeaFactoryUnit
local SeaUnit = DefaultUnitsFile.SeaUnit
local ShieldLandUnit = DefaultUnitsFile.ShieldLandUnit
local ShieldStructureUnit = DefaultUnitsFile.ShieldStructureUnit
local StructureUnit = DefaultUnitsFile.StructureUnit
local QuantumGateUnit = DefaultUnitsFile.QuantumGateUnit
local RadarJammerUnit = DefaultUnitsFile.RadarJammerUnit
local CommandUnit = DefaultUnitsFile.CommandUnit
local Util = import('utilities.lua')
local EffectTemplate = import('/lua/EffectTemplates.lua')
local EffectUtil = import('EffectUtilities.lua')
local CreateCybranBuildBeams = EffectUtil.CreateCybranBuildBeams
-- AIR FACTORY STRUCTURES
CAirFactoryUnit = Class(AirFactoryUnit) {
CreateBuildEffects = function(self, unitBeingBuilt, order)
if not unitBeingBuilt then return end
WaitSeconds(0.1)
EffectUtil.CreateCybranFactoryBuildEffects(self, unitBeingBuilt, self:GetBlueprint().General.BuildBones, self.BuildEffectsBag)
end,
StartBuildFx = function(self, unitBeingBuilt)
if not unitBeingBuilt then return end
-- Start build process
if not self.BuildAnimManip then
self.BuildAnimManip = CreateAnimator(self)
self.BuildAnimManip:PlayAnim(self:GetBlueprint().Display.AnimationBuild, true):SetRate(0)
self.Trash:Add(self.BuildAnimManip)
end
self.BuildAnimManip:SetRate(1)
end,
StopBuildFx = function(self)
if self.BuildAnimManip then
self.BuildAnimManip:SetRate(0)
end
end,
OnPaused = function(self)
AirFactoryUnit.OnPaused(self)
self:StopBuildFx()
end,
OnUnpaused = function(self)
AirFactoryUnit.OnUnpaused(self)
if self:IsUnitState('Building') then
self:StartBuildFx(self:GetFocusUnit())
end
end,
}
-- AIR STAGING STRUCTURES
CAirStagingPlatformUnit = Class(AirStagingPlatformUnit) {}
-- AIR UNITS
CAirUnit = Class(AirUnit) {}
-- WALL STRUCTURES
CConcreteStructureUnit = Class(ConcreteStructureUnit) {}
-- CONSTRUCTION UNITS
CConstructionUnit = Class(ConstructionUnit){
OnStopBeingBuilt = function(self, builder, layer)
ConstructionUnit.OnStopBeingBuilt(self, builder, layer)
-- If created with F2 on land, then play the transform anim.
if self:GetCurrentLayer() == 'Water' then
self.TerrainLayerTransitionThread = self:ForkThread(self.TransformThread, true)
end
end,
LayerChangeTrigger = function(self, new, old)
if self:GetBlueprint().Display.AnimationWater then
if self.TerrainLayerTransitionThread then
self.TerrainLayerTransitionThread:Destroy()
self.TerrainLayerTransitionThread = nil
end
if old ~= 'None' then
self.TerrainLayerTransitionThread = self:ForkThread(self.TransformThread, (new == 'Water'))
end
end
end,
TransformThread = function(self, water)
if not self.TransformManipulator then
self.TransformManipulator = CreateAnimator(self)
self.Trash:Add(self.TransformManipulator)
end
if water then
self.TransformManipulator:PlayAnim(self:GetBlueprint().Display.AnimationWater)
self.TransformManipulator:SetRate(1)
self.TransformManipulator:SetPrecedence(0)
else
self.TransformManipulator:SetRate(-1)
self.TransformManipulator:SetPrecedence(0)
WaitFor(self.TransformManipulator)
self.TransformManipulator:Destroy()
self.TransformManipulator = nil
end
end,
CreateBuildEffects = function(self, unitBeingBuilt, order)
local buildbots = EffectUtil.SpawnBuildBots(self, unitBeingBuilt, self.BuildEffectsBag)
EffectUtil.CreateCybranBuildBeams(self, unitBeingBuilt, self.BuildEffectBones, self.BuildEffectsBag)
end,
}
-- ENERGY CREATION UNITS
CEnergyCreationUnit = Class(DefaultUnitsFile.EnergyCreationUnit) {
OnStopBeingBuilt = function(self, builder, layer)
DefaultUnitsFile.EnergyCreationUnit.OnStopBeingBuilt(self, builder, layer)
if self.AmbientEffects then
for k, v in EffectTemplate[self.AmbientEffects] do
CreateAttachedEmitter(self, 0, self.Army, v)
end
end
end,
}
-- ENERGY STORAGE STRUCTURES
CEnergyStorageUnit = Class(EnergyStorageUnit) {}
-- LAND FACTORY STRUCTURES
CLandFactoryUnit = Class(LandFactoryUnit) {
CreateBuildEffects = function(self, unitBeingBuilt, order)
if not unitBeingBuilt then return end
WaitSeconds(0.1)
EffectUtil.CreateCybranFactoryBuildEffects(self, unitBeingBuilt, self:GetBlueprint().General.BuildBones, self.BuildEffectsBag)
end,
StartBuildFx = function(self, unitBeingBuilt)
if not unitBeingBuilt then
unitBeingBuilt = self:GetFocusUnit()
end
-- Start build process
if not self.BuildAnimManip then
self.BuildAnimManip = CreateAnimator(self)
self.BuildAnimManip:PlayAnim(self:GetBlueprint().Display.AnimationBuild, true):SetRate(0)
self.Trash:Add(self.BuildAnimManip)
end
self.BuildAnimManip:SetRate(1)
end,
StopBuildFx = function(self)
if self.BuildAnimManip then
self.BuildAnimManip:SetRate(0)
end
end,
OnPaused = function(self)
LandFactoryUnit.OnPaused(self)
self:StopBuildFx(self:GetFocusUnit())
end,
OnUnpaused = function(self)
LandFactoryUnit.OnUnpaused(self)
if self:IsUnitState('Building') then
self:StartBuildFx(self:GetFocusUnit())
end
end,
}
-- LAND UNITS
CLandUnit = Class(DefaultUnitsFile.LandUnit) {}
-- MASS COLLECTION UNITS
CMassCollectionUnit = Class(DefaultUnitsFile.MassCollectionUnit) {}
-- MASS FABRICATION UNITS
CMassFabricationUnit = Class(DefaultUnitsFile.MassFabricationUnit) {}
-- MASS STORAGE UNITS
CMassStorageUnit = Class(DefaultUnitsFile.MassStorageUnit) {}
-- RADAR STRUCTURES
CRadarUnit = Class(DefaultUnitsFile.RadarUnit) {}
-- SONAR STRUCTURES
CSonarUnit = Class(DefaultUnitsFile.SonarUnit) {}
-- SEA FACTORY STRUCTURES
CSeaFactoryUnit = Class(SeaFactoryUnit) {
StartBuildingEffects = function(self, unitBeingBuilt)
local thread = self:ForkThread(EffectUtil.CreateCybranBuildBeams, unitBeingBuilt, self.BuildEffectBones, self.BuildEffectsBag)
unitBeingBuilt.Trash:Add(thread)
end,
OnPaused = function(self)
if not self.Dead and self:GetFractionComplete() == 1 then
self:StopUnitAmbientSound('ConstructLoop')
StructureUnit.StopBuildingEffects(self, self.UnitBeingBuilt)
self:StopArmsMoving()
end
StructureUnit.OnPaused(self)
end,
OnUnpaused = function(self)
if self:GetNumBuildOrders(categories.ALLUNITS) > 0 and not self:IsUnitState('Upgrading') and self:IsUnitState('Building') then
self:PlayUnitAmbientSound('ConstructLoop')
self:StartBuildingEffects(self.UnitBeingBuilt)
self:StartArmsMoving()
end
StructureUnit.OnUnpaused(self)
end,
OnStartBuild = function(self, unitBeingBuilt, order)
SeaFactoryUnit.OnStartBuild(self, unitBeingBuilt, order)
if order ~= 'Upgrade' then
self:StartArmsMoving()
end
end,
OnStopBuild = function(self, unitBuilding)
SeaFactoryUnit.OnStopBuild(self, unitBuilding)
if not self.Dead and self:GetFractionComplete() == 1 then
self:StopArmsMoving()
end
end,
OnFailedToBuild = function(self)
SeaFactoryUnit.OnFailedToBuild(self)
if not self.Dead and self:GetFractionComplete() == 1 then
self:StopArmsMoving()
end
end,
StartArmsMoving = function(self)
self.ArmsThread = self:ForkThread(self.MovingArmsThread)
end,
MovingArmsThread = function(self)
end,
StopArmsMoving = function(self)
if self.ArmsThread then
KillThread(self.ArmsThread)
self.ArmsThread = nil
end
end,
}
-- SEA UNITS
CSeaUnit = Class(SeaUnit) {}
-- SHIELD LAND UNITS
CShieldLandUnit = Class(ShieldLandUnit) {}
-- SHIELD STRUCTURES
CShieldStructureUnit = Class(ShieldStructureUnit) {}
-- STRUCTURES
CStructureUnit = Class(StructureUnit) {}
-- SUBMARINE UNITS
CSubUnit = Class(DefaultUnitsFile.SubUnit) {}
-- TRANSPORT BEACON UNITS
CTransportBeaconUnit = Class(DefaultUnitsFile.TransportBeaconUnit) {}
-- WALKING LAND UNITS
CWalkingLandUnit = DefaultUnitsFile.WalkingLandUnit
-- WALL STRUCTURES
CWallStructureUnit = Class(DefaultUnitsFile.WallStructureUnit) {}
-- CIVILIAN STRUCTURES
CCivilianStructureUnit = Class(CStructureUnit) {}
-- QUANTUM GATE UNITS
CQuantumGateUnit = Class(QuantumGateUnit) {}
-- RADAR JAMMER UNITS
CRadarJammerUnit = Class(RadarJammerUnit) {}
CConstructionEggUnit = Class(CStructureUnit) {
OnStopBeingBuilt = function(self, builder, layer)
LandFactoryUnit.OnStopBeingBuilt(self, builder, layer)
local bp = self:GetBlueprint()
local buildUnit = bp.Economy.BuildUnit
local pos = self:GetPosition()
local aiBrain = self:GetAIBrain()
self.Spawn = CreateUnitHPR(
buildUnit,
aiBrain.Name,
pos[1], pos[2], pos[3],
0, 0, 0
)
ForkThread(function()
self.OpenAnimManip = CreateAnimator(self)
self.Trash:Add(self.OpenAnimManip)
self.OpenAnimManip:PlayAnim(self:GetBlueprint().Display.AnimationOpen, false):SetRate(0.1)
self:PlaySound(bp.Audio['EggOpen'])
WaitFor(self.OpenAnimManip)
self.EggSlider = CreateSlider(self, 0, 0, -20, 0, 5)
self.Trash:Add(self.EggSlider)
self:PlaySound(bp.Audio['EggSink'])
WaitFor(self.EggSlider)
self:Destroy()
end
)
end,
OnKilled = function(self, instigator, type, overkillRatio)
if self.Spawn then overkillRatio = 1.1 end
CStructureUnit.OnKilled(self, instigator, type, overkillRatio)
end,
}
-- TODO: This should be made more general and put in defaultunits.lua in case other factions get similar buildings
-- CConstructionStructureUnit
CConstructionStructureUnit = Class(CStructureUnit) {
OnCreate = function(self)
-- Structure stuff
CStructureUnit.OnCreate(self)
local bp = self:GetBlueprint()
-- Construction stuff
self.EffectsBag = {}
if bp.General.BuildBones then
self:SetupBuildBones()
end
-- Save build effect bones for faster access when creating build effects
self.BuildEffectBones = bp.General.BuildBones.BuildEffectBones
-- Set up building animation
if bp.Display.AnimationOpen then
self.BuildingOpenAnim = bp.Display.AnimationOpen
end
self.AnimationManipulator = CreateAnimator(self)
self.Trash:Add(self.AnimationManipulator)
self.BuildingUnit = false
end,
OnStartBuild = function(self, unitBeingBuilt, order)
self.UnitBeingBuilt = unitBeingBuilt
self.UnitBuildOrder = order
self.BuildingUnit = true
self.AnimationManipulator:PlayAnim(self.BuildingOpenAnim, false):SetRate(1)
CStructureUnit.OnStartBuild(self, unitBeingBuilt, order)
end,
OnStopBeingBuilt = function(self, builder, layer)
CStructureUnit.OnStopBeingBuilt(self, builder, layer)
-- If created with F2 on land, then play the transform anim.
if self:GetCurrentLayer() == 'Water' then
self.TerrainLayerTransitionThread = self:ForkThread(self.TransformThread, true)
end
end,
CreateBuildEffects = function(self, unitBeingBuilt, order)
local buildbots = EffectUtil.SpawnBuildBots(self, unitBeingBuilt, table.getn(self.BuildEffectBones), self.BuildEffectsBag)
if buildbots then
EffectUtil.CreateCybranEngineerBuildEffects(self, self.BuildEffectBones, buildbots, self.BuildEffectsBag)
else
EffectUtil.CreateCybranBuildBeams(self, unitBeingBuilt, self.BuildEffectBones, self.BuildEffectsBag)
end
end,
-- This will only be called if not in StructureUnit's upgrade state
OnStopBuild = function(self, unitBeingBuilt)
CStructureUnit.OnStopBuild(self, unitBeingBuilt)
self.UnitBeingBuilt = nil
self.UnitBuildOrder = nil
self.BuildingUnit = false
self.AnimationManipulator:SetRate(-1)
end,
OnPaused = function(self)
-- When factory is paused take some action
self:StopUnitAmbientSound('ConstructLoop')
CStructureUnit.OnPaused(self)
if self.BuildingUnit then
CStructureUnit.StopBuildingEffects(self, self.UnitBeingBuilt)
end
end,
OnUnpaused = function(self)
if self.BuildingUnit then
self:PlayUnitAmbientSound('ConstructLoop')
CStructureUnit.StartBuildingEffects(self, self.UnitBeingBuilt, self.UnitBuildOrder)
end
CStructureUnit.OnUnpaused(self)
end,
OnProductionPaused = function(self)
if self:IsUnitState('Building') then
self:SetMaintenanceConsumptionInactive()
end
self:SetProductionActive(false)
end,
OnProductionUnpaused = function(self)
if self:IsUnitState('Building') then
self:SetMaintenanceConsumptionActive()
end
self:SetProductionActive(true)
end,
StartBuildingEffects = function(self, unitBeingBuilt, order)
CStructureUnit.StartBuildingEffects(self, unitBeingBuilt, order)
end,
StopBuildingEffects = function(self, unitBeingBuilt)
CStructureUnit.StopBuildingEffects(self, unitBeingBuilt)
end,
OnStopBuilderTracking = function(self)
CStructureUnit.OnStopBuilderTracking(self)
if self.StoppedBuilding then
self.StoppedBuilding = false
self.BuildArmManipulator:Disable()
self.BuildingOpenAnimManip:SetRate(-(self:GetBlueprint().Display.AnimationBuildRate or 1))
end
end,
CheckBuildRestriction = function(self, target_bp)
if self:CanBuild(target_bp.BlueprintId) then
return true
else
return false
end
end,
CreateReclaimEffects = function(self, target)
EffectUtil.PlayReclaimEffects(self, target, self.BuildEffectBones or {0, }, self.ReclaimEffectsBag)
end,
CreateReclaimEndEffects = function(self, target)
EffectUtil.PlayReclaimEndEffects(self, target)
end,
CreateCaptureEffects = function(self, target)
EffectUtil.PlayCaptureEffects(self, target, self.BuildEffectBones or {0, }, self.CaptureEffectsBag)
end,
}
-- CCommandUnit
-- Cybran Command Units (ACU and SCU) have stealth and cloak enhancements, toggles can be handled in one class
CCommandUnit = Class(CommandUnit) {
OnScriptBitSet = function(self, bit)
if bit == 8 then -- Cloak toggle
self:StopUnitAmbientSound('ActiveLoop')
self:SetMaintenanceConsumptionInactive()
self:DisableUnitIntel('ToggleBit8', 'Cloak')
self:DisableUnitIntel('ToggleBit8', 'RadarStealth')
self:DisableUnitIntel('ToggleBit8', 'RadarStealthField')
self:DisableUnitIntel('ToggleBit8', 'SonarStealth')
self:DisableUnitIntel('ToggleBit8', 'SonarStealthField')
end
end,
OnScriptBitClear = function(self, bit)
if bit == 8 then -- Cloak toggle
self:PlayUnitAmbientSound('ActiveLoop')
self:SetMaintenanceConsumptionActive()
self:EnableUnitIntel('ToggleBit8', 'Cloak')
self:EnableUnitIntel('ToggleBit8', 'RadarStealth')
self:EnableUnitIntel('ToggleBit8', 'RadarStealthField')
self:EnableUnitIntel('ToggleBit8', 'SonarStealth')
self:EnableUnitIntel('ToggleBit8', 'SonarStealthField')
end
end,
}