forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterranunits.lua
More file actions
699 lines (609 loc) · 27.1 KB
/
terranunits.lua
File metadata and controls
699 lines (609 loc) · 27.1 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
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
-- ****************************************************************************
-- **
-- ** File : /lua/terranunits.lua
-- ** Author(s): John Comes, Dave Tomandl, Gordon Duclos
-- **
-- ** Summary :
-- **
-- ** Copyright © 2005 Gas Powered Games, Inc. All rights reserved.
-- ****************************************************************************
---------------------------------------------------------------------------
-- TERRAN DEFAULT UNITS
---------------------------------------------------------------------------
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 LandUnit = DefaultUnitsFile.LandUnit
local HoverLandUnit = DefaultUnitsFile.HoverLandUnit
local MassCollectionUnit = DefaultUnitsFile.MassCollectionUnit
local MassFabricationUnit = DefaultUnitsFile.MassFabricationUnit
local MassStorageUnit = DefaultUnitsFile.MassStorageUnit
local RadarUnit = DefaultUnitsFile.RadarUnit
local SeaFactoryUnit = DefaultUnitsFile.SeaFactoryUnit
local SeaUnit = DefaultUnitsFile.SeaUnit
local ShieldLandUnit = DefaultUnitsFile.ShieldLandUnit
local ShieldStructureUnit = DefaultUnitsFile.ShieldStructureUnit
local SonarUnit = DefaultUnitsFile.SonarUnit
local StructureUnit = DefaultUnitsFile.StructureUnit
local SubUnit = DefaultUnitsFile.SubUnit
local WalkingLandUnit = DefaultUnitsFile.WalkingLandUnit
local WallStructureUnit = DefaultUnitsFile.WallStructureUnit
local QuantumGateUnit = DefaultUnitsFile.QuantumGateUnit
local RadarJammerUnit = DefaultUnitsFile.RadarJammerUnit
local ShieldSeaUnit = DefaultUnitsFile.ShieldSeaUnit
local TransportBeaconUnit = DefaultUnitsFile.TransportBeaconUnit
local EffectUtil = import('EffectUtilities.lua')
local CreateBuildCubeThread = EffectUtil.CreateBuildCubeThread
local CreateUEFBuildSliceBeams = EffectUtil.CreateUEFBuildSliceBeams
--------------------------------------------------------------
-- AIR FACTORY STRUCTURES
--------------------------------------------------------------
TAirFactoryUnit = Class(AirFactoryUnit) {
CreateBuildEffects = function(self, unitBeingBuilt, order)
WaitSeconds(0.1)
for _, v in self.BuildEffectBones do
self.BuildEffectsBag:Add(CreateAttachedEmitter(self, v, self.Army, '/effects/emitters/flashing_blue_glow_01_emit.bp'))
self.BuildEffectsBag:Add(self:ForkThread(EffectUtil.CreateDefaultBuildBeams, unitBeingBuilt, {v}, self.BuildEffectsBag))
end
end,
OnPaused = function(self)
AirFactoryUnit.OnPaused(self)
self:StopArmsMoving()
end,
OnUnpaused = function(self)
AirFactoryUnit.OnUnpaused(self)
if self:GetNumBuildOrders(categories.ALLUNITS) > 0 and not self:IsUnitState('Upgrading') then
self:StartArmsMoving()
end
end,
OnStartBuild = function(self, unitBeingBuilt, order)
AirFactoryUnit.OnStartBuild(self, unitBeingBuilt, order)
if order ~= 'Upgrade' then
self:StartArmsMoving()
end
end,
OnStopBuild = function(self, unitBuilding)
AirFactoryUnit.OnStopBuild(self, unitBuilding)
self:StopArmsMoving()
end,
OnFailedToBuild = function(self)
AirFactoryUnit.OnFailedToBuild(self)
self:StopArmsMoving()
end,
StartArmsMoving = function(self)
if not self.ArmsThread then
self.ArmsThread = self:ForkThread(self.MovingArmsThread)
end
end,
MovingArmsThread = function(self)
end,
StopArmsMoving = function(self)
if self.ArmsThread then
KillThread(self.ArmsThread)
self.ArmsThread = nil
end
end,
}
--------------------------------------------------------------
-- AIR STAGING STRUCTURES
--------------------------------------------------------------
TAirStagingPlatformUnit = Class(AirStagingPlatformUnit) {}
--------------------------------------------------------------
-- AIR UNITS
--------------------------------------------------------------
TAirUnit = Class(AirUnit) {}
--------------------------------------------------------------
-- WALL STRUCTURES
--------------------------------------------------------------
TConcreteStructureUnit = Class(ConcreteStructureUnit) {}
--------------------------------------------------------------
-- Construction Units
--------------------------------------------------------------
TConstructionUnit = Class(ConstructionUnit) {
CreateBuildEffects = function(self, unitBeingBuilt, order)
local UpgradesFrom = unitBeingBuilt:GetBlueprint().General.UpgradesFrom
-- If we are assisting an upgrading unit, or repairing a unit, play seperate effects
if (order == 'Repair' and not unitBeingBuilt:IsBeingBuilt()) or (UpgradesFrom and UpgradesFrom ~= 'none' and self:IsUnitState('Guarding'))then
EffectUtil.CreateDefaultBuildBeams(self, unitBeingBuilt, self.BuildEffectBones, self.BuildEffectsBag)
else
CreateUEFBuildSliceBeams(self, unitBeingBuilt, self.BuildEffectBones, self.BuildEffectsBag)
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,
}
--------------------------------------------------------------
-- ENERGY CREATION STRUCTURES
--------------------------------------------------------------
TEnergyCreationUnit = Class(EnergyCreationUnit) {}
--------------------------------------------------------------
-- ENERGY STORAGE STRUCTURES
--------------------------------------------------------------
TEnergyStorageUnit = Class(EnergyStorageUnit) {}
--------------------------------------------------------------
-- HOVER LAND UNITS
--------------------------------------------------------------
THoverLandUnit = Class(HoverLandUnit) {}
--------------------------------------------------------------
-- LAND FACTORY STRUCTURES
--------------------------------------------------------------
TLandFactoryUnit = Class(LandFactoryUnit) {
CreateBuildEffects = function(self, unitBeingBuilt, order)
WaitSeconds(0.1)
for _, v in self.BuildEffectBones do
self.BuildEffectsBag:Add(CreateAttachedEmitter(self, v, self.Army, '/effects/emitters/flashing_blue_glow_01_emit.bp'))
self.BuildEffectsBag:Add(self:ForkThread(EffectUtil.CreateDefaultBuildBeams, unitBeingBuilt, {v}, self.BuildEffectsBag))
end
end,
}
--------------------------------------------------------------
-- LAND UNITS
--------------------------------------------------------------
TLandUnit = Class(LandUnit) {}
--------------------------------------------------------------
-- MASS COLLECTION UNITS
--------------------------------------------------------------
TMassCollectionUnit = Class(MassCollectionUnit) {}
--------------------------------------------------------------
-- MASS FABRICATION STRUCTURES
--------------------------------------------------------------
TMassFabricationUnit = Class(MassFabricationUnit) {}
--------------------------------------------------------------
-- MASS STORAGE STRUCTURES
--------------------------------------------------------------
TMassStorageUnit = Class(MassStorageUnit) {}
--------------------------------------------------------------
-- MOBILE FACTORY UNIT
--------------------------------------------------------------
TMobileFactoryUnit = Class(LandUnit) {
StartBeingBuiltEffects = function(self, builder, layer)
self:SetMesh(self:GetBlueprint().Display.BuildMeshBlueprint, true)
if self:GetBlueprint().General.UpgradesFrom ~= builder.UnitId then
self:HideBone(0, true)
self.OnBeingBuiltEffectsBag:Add(self:ForkThread(CreateBuildCubeThread, builder, self.OnBeingBuiltEffectsBag))
end
end,
}
--------------------------------------------------------------
-- RADAR STRUCTURES
--------------------------------------------------------------
TRadarUnit = Class(RadarUnit) {}
--------------------------------------------------------------
-- SONAR STRUCTURES
--------------------------------------------------------------
TSonarUnit = Class(SonarUnit) {}
--------------------------------------------------------------
-- SEA FACTORY STRUCTURES
--------------------------------------------------------------
TSeaFactoryUnit = Class(SeaFactoryUnit) {
CreateBuildEffects = function(self, unitBeingBuilt, order)
WaitSeconds(0.1)
for _, v in self.BuildEffectBones do
self.BuildEffectsBag:Add(CreateAttachedEmitter(self, v, self.Army, '/effects/emitters/flashing_blue_glow_01_emit.bp'))
self.BuildEffectsBag:Add(self:ForkThread(EffectUtil.CreateDefaultBuildBeams, unitBeingBuilt, {v}, self.BuildEffectsBag))
end
end,
OnPaused = function(self)
SeaFactoryUnit.OnPaused(self)
self:StopArmsMoving()
end,
OnUnpaused = function(self)
SeaFactoryUnit.OnUnpaused(self)
if self:GetNumBuildOrders(categories.ALLUNITS) > 0 and not self:IsUnitState('Upgrading') then
self:StartArmsMoving()
end
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)
self:StopArmsMoving()
end,
OnFailedToBuild = function(self)
SeaFactoryUnit.OnFailedToBuild(self)
self:StopArmsMoving()
end,
StartArmsMoving = function(self)
if not self.ArmsThread then
self.ArmsThread = self:ForkThread(self.MovingArmsThread)
end
end,
MovingArmsThread = function(self)
end,
StopArmsMoving = function(self)
if self.ArmsThread then
KillThread(self.ArmsThread)
self.ArmsThread = nil
end
end,
}
--------------------------------------------------------------
-- SEA UNITS
--------------------------------------------------------------
TSeaUnit = Class(SeaUnit) {}
--------------------------------------------------------------
-- SHIELD LAND UNITS
--------------------------------------------------------------
TShieldLandUnit = Class(ShieldLandUnit) {}
--------------------------------------------------------------
-- SHIELD STRUCTURES
--------------------------------------------------------------
TShieldStructureUnit = Class(ShieldStructureUnit) {
StartBeingBuiltEffects = function(self,builder,layer)
self:SetMesh(self:GetBlueprint().Display.BuildMeshBlueprint, true)
if builder and EntityCategoryContains(categories.MOBILE, builder) then
self:HideBone(0, true)
self.OnBeingBuiltEffectsBag:Add(self:ForkThread(CreateBuildCubeThread, builder, self.OnBeingBuiltEffectsBag))
end
end,
}
--------------------------------------------------------------
-- STRUCTURES
--------------------------------------------------------------
TStructureUnit = Class(StructureUnit) {}
TRadarJammerUnit = Class(RadarJammerUnit) {
OnIntelEnabled = function(self)
if not self.MySpinner then
self.MySpinner = CreateRotator(self, 'Spinner', 'y', nil, 0, 45, 180)
self.Trash:Add(self.MySpinner)
end
RadarJammerUnit.OnIntelEnabled(self)
self.MySpinner:SetTargetSpeed(180)
end,
OnIntelDisabled = function(self)
RadarJammerUnit.OnIntelDisabled(self)
self.MySpinner:SetTargetSpeed(0)
end,
}
--------------------------------------------------------------
-- SUBMARINE UNITS
--------------------------------------------------------------
TSubUnit = Class(SubUnit) {}
--------------------------------------------------------------
-- TRANSPORT BEACON UNITS
--------------------------------------------------------------
TTransportBeaconUnit = Class(TransportBeaconUnit) {}
--------------------------------------------------------------
-- WALKING LAND UNITS
--------------------------------------------------------------
TWalkingLandUnit = Class(WalkingLandUnit) {}
--------------------------------------------------------------
-- WALL STRUCTURES
--------------------------------------------------------------
TWallStructureUnit = Class(WallStructureUnit) {}
--------------------------------------------------------------
-- CIVILIAN STRUCTURES
--------------------------------------------------------------
TCivilianStructureUnit = Class(StructureUnit) {}
--------------------------------------------------------------
-- QUANTUM GATE UNITS
--------------------------------------------------------------
TQuantumGateUnit = Class(QuantumGateUnit) {}
--------------------------------------------------------------
-- SHIELD SEA UNITS
--------------------------------------------------------------
TShieldSeaUnit = Class(ShieldSeaUnit) {}
--------------------------------------------------------------
-- Pod Tower Unit (Kennels)
--------------------------------------------------------------
TPodTowerUnit = Class(TStructureUnit) {
OnStopBeingBuilt = function(self, builder, layer)
TStructureUnit.OnStopBeingBuilt(self, builder, layer)
ChangeState(self, self.FinishedBeingBuilt)
end,
PodTransfer = function(self, pod, podData)
-- Set the pod as active, set new parent and creator for the pod, store the pod handle
if not self.PodData[pod.PodName].Active then
if not self.PodData then
self.PodData = {}
end
self.PodData[pod.PodName] = {}
self.PodData[pod.PodName].PodHandle = pod
self.PodData[pod.PodName].PodUnitID = podData.PodUnitID
self.PodData[pod.PodName].PodName = podData.PodName
self.PodData[pod.PodName].Active = podData.Active
self.PodData[pod.PodName].PodAttachpoint = podData.PodAttachpoint
self.PodData[pod.PodName].CreateWithUnit = podData.CreateWithUnit
pod:SetParent(self, pod.PodName)
end
end,
OnCaptured = function(self, captor)
-- Iterate through pod data and set up callbacks for transfer of pods.
-- We never get the handle to the new tower, so we set up a new unit capture trigger to do the same thing
-- not the most efficient thing ever but it makes for never having to update the capture codepath here
for k,v in self.PodData do
if v.Active then
v.Active = false
-- store off the pod name so we can give to new unit
local podName = k
local newPod = import('/lua/ScenarioFramework.lua').GiveUnitToArmy(v.PodHandle, captor.Army)
newPod.PodName = podName
-- create a callback for when the unit is flipped. set creator for the new pod to the new tower
self:AddUnitCallback(
function(newUnit, captor)
newUnit:PodTransfer(newPod, v)
end,
'OnCapturedNewUnit'
)
end
end
-- Calling the parent OnCaptured will cause all the callbacks to happen and happiness will reign !
TStructureUnit.OnCaptured(self, captor)
end,
OnDestroy = function(self)
TStructureUnit.OnDestroy(self)
-- Iterate through pod data, kill all the pods and set them inactive
if self.PodData then
for _, v in self.PodData do
if v.Active and not v.PodHandle.Dead then
v.PodHandle:Kill()
end
end
end
end,
OnStartBuild = function(self, unitBeingBuilt, order)
TStructureUnit.OnStartBuild(self,unitBeingBuilt,order)
local unitid = self:GetBlueprint().General.UpgradesTo
if unitBeingBuilt.UnitId == unitid and order == 'Upgrade' then
self.NowUpgrading = true
ChangeState(self, self.UpgradingState)
end
end,
NotifyOfPodDeath = function(self,podName)
self.PodData[podName].Active = false
end,
SetPodConsumptionRebuildRate = function(self, podData)
local bp = self:GetBlueprint()
-- Get build rate of tower
local buildRate = bp.Economy.BuildRate
local energy_rate = (podData.BuildCostEnergy / podData.BuildTime) * buildRate
local mass_rate = (podData.BuildCostMass / podData.BuildTime) * buildRate
-- Set Consumption - Buff system will replace this here
self:SetConsumptionPerSecondEnergy(energy_rate)
self:SetConsumptionPerSecondMass(mass_rate)
self:SetConsumptionActive(true)
end,
CreatePod = function(self, podName)
local location = self:GetPosition(self.PodData[podName].PodAttachpoint)
self.PodData[podName].PodHandle = CreateUnitHPR(self.PodData[podName].PodUnitID, self.Army, location[1], location[2], location[3], 0, 0, 0)
self.PodData[podName].PodHandle:SetParent(self, podName)
self.PodData[podName].Active = true
end,
OnTransportAttach = function(self, bone, attachee)
attachee:SetDoNotTarget(true)
self:PlayUnitSound('Close')
self:RequestRefreshUI()
local PodPresent = 0
for _, v in self.PodData or {} do
if v.Active then
PodPresent = PodPresent + 1
end
end
local PodAttached = 0
for _, v in self:GetCargo() do
PodAttached = PodAttached + 1
end
if PodAttached == PodPresent and self.OpeningAnimationStarted then
local bp = self:GetBlueprint()
if not self.OpenAnim then return end
self.OpenAnim:SetRate(1.5)
self.OpeningAnimationStarted = false
end
end,
OnTransportDetach = function(self, bone, attachee)
attachee:SetDoNotTarget(false)
self:PlayUnitSound('Open')
self:RequestRefreshUI()
if not self.OpeningAnimationStarted then
self.OpeningAnimationStarted = true
local bp = self:GetBlueprint()
if not self.OpenAnim then
self.OpenAnim = CreateAnimator(self)
self.Trash:Add(self.OpenAnim)
end
self.OpenAnim:PlayAnim(bp.Display.AnimationOpen, false):SetRate(2.0)
-- wait 5 ticks and stop the animation so that the doors stay open
ForkThread(function ()
coroutine.yield(5)
self.OpenAnim:SetRate(0)
end)
end
end,
FinishedBeingBuilt = State {
Main = function(self)
-- Wait one tick to make sure this wasn't captured and we don't create an extra pod
coroutine.yield(1)
-- Create the pod for the kennel. DO NOT ADD TO TRASH.
-- This pod may have to be passed to another unit after it upgrades. We cannot let the trash clean it up
-- when this unit is destroyed at the tail end of the upgrade. Make sure the unit dies properly elsewhere.
self.TowerCaptured = nil
local bp = self:GetBlueprint()
for _, v in bp.Economy.EngineeringPods do
if v.CreateWithUnit and not self.PodData[v.PodName].Active then
if not self.PodData then
self.PodData = {}
end
self.PodData[v.PodName] = table.copy(v)
self:CreatePod(v.PodName)
end
end
ChangeState(self, self.MaintainPodsState)
end,
},
MaintainPodsState = State {
Main = function(self)
self.MaintainState = true
if self.Rebuilding then
self:SetPodConsumptionRebuildRate(self.PodData[ self.Rebuilding ])
ChangeState(self, self.RebuildingPodState)
end
local bp = self:GetBlueprint()
while true and not self.Rebuilding do
for _, v in bp.Economy.EngineeringPods do
-- Check if all the pods are active
if not self.PodData[v.PodName].Active then
-- Cost of new pod
local podBP = self:GetAIBrain():GetUnitBlueprint(v.PodUnitID)
self.PodData[v.PodName].EnergyRemain = podBP.Economy.BuildCostEnergy
self.PodData[v.PodName].MassRemain = podBP.Economy.BuildCostMass
self.PodData[v.PodName].BuildCostEnergy = podBP.Economy.BuildCostEnergy
self.PodData[v.PodName].BuildCostMass = podBP.Economy.BuildCostMass
self.PodData[v.PodName].BuildTime = podBP.Economy.BuildTime
-- Enable consumption for the rebuilding
self:SetPodConsumptionRebuildRate(self.PodData[v.PodName])
-- Change to RebuildingPodState
self.Rebuilding = v.PodName
self:SetWorkProgress(0.01)
ChangeState(self, self.RebuildingPodState)
end
end
coroutine.yield(1)
end
end,
OnProductionPaused = function(self)
ChangeState(self, self.PausedState)
end,
},
RebuildingPodState = State {
Main = function(self)
local rebuildFinished = false
local podData = self.PodData[ self.Rebuilding ]
repeat
WaitTicks(1)
-- While the pod being built isn't finished
-- Update mass and energy given to new pod - update build bar
local fraction = self:GetResourceConsumed()
local energy = self:GetConsumptionPerSecondEnergy() * fraction * 0.1
local mass = self:GetConsumptionPerSecondMass() * fraction * 0.1
self.PodData[ self.Rebuilding ].EnergyRemain = self.PodData[ self.Rebuilding ].EnergyRemain - energy
self.PodData[ self.Rebuilding ].MassRemain = self.PodData[ self.Rebuilding ].MassRemain - mass
self:SetWorkProgress((self.PodData[ self.Rebuilding ].BuildCostMass - self.PodData[ self.Rebuilding ].MassRemain) / self.PodData[ self.Rebuilding ].BuildCostMass)
if (self.PodData[ self.Rebuilding ].EnergyRemain <= 0) and (self.PodData[ self.Rebuilding ].MassRemain <= 0) then
rebuildFinished = true
end
until rebuildFinished
-- create pod, deactivate consumption, clear building
self:CreatePod(self.Rebuilding)
self.Rebuilding = false
self:SetWorkProgress(0)
self:SetConsumptionPerSecondEnergy(0)
self:SetConsumptionPerSecondMass(0)
self:SetConsumptionActive(false)
ChangeState(self, self.MaintainPodsState)
end,
OnProductionPaused = function(self)
self:SetConsumptionPerSecondEnergy(0)
self:SetConsumptionPerSecondMass(0)
self:SetConsumptionActive(false)
ChangeState(self, self.PausedState)
end,
},
PausedState = State {
Main = function(self)
self.MaintainState = false
end,
OnProductionUnpaused = function(self)
ChangeState(self, self.MaintainPodsState)
end,
},
UpgradingState = State {
Main = function(self)
self:StopRocking()
local bp = self:GetBlueprint().Display
self:DestroyTarmac()
self:PlayUnitSound('UpgradeStart')
self:DisableDefaultToggleCaps()
if bp.AnimationUpgrade then
local unitBuilding = self.UnitBeingBuilt
self.AnimatorUpgradeManip = CreateAnimator(self)
self.Trash:Add(self.AnimatorUpgradeManip)
local fractionOfComplete = 0
self:StartUpgradeEffects(unitBuilding)
self.AnimatorUpgradeManip:PlayAnim(bp.AnimationUpgrade, false):SetRate(0)
while fractionOfComplete < 1 and not self.Dead do
fractionOfComplete = unitBuilding:GetFractionComplete()
self.AnimatorUpgradeManip:SetAnimationFraction(fractionOfComplete)
WaitTicks(1)
end
if not self.Dead then
self.AnimatorUpgradeManip:SetRate(1)
end
end
end,
OnProductionPaused = function(self)
self.MaintainState = false
end,
OnProductionUnpaused = function(self)
self.MaintainState = true
end,
OnStopBuild = function(self, unitBuilding)
TStructureUnit.OnStopBuild(self, unitBuilding)
self:EnableDefaultToggleCaps()
if unitBuilding:GetFractionComplete() == 1 then
NotifyUpgrade(self, unitBuilding)
self:StopUpgradeEffects(unitBuilding)
self:PlayUnitSound('UpgradeEnd')
-- Iterate through pod data and transfer pods to the new unit
for k,v in self.PodData or {} do
if v.Active then
unitBuilding:PodTransfer(v.PodHandle, v)
v.Active = false
end
end
self:Destroy()
end
end,
OnFailedToBuild = function(self)
TStructureUnit.OnFailedToBuild(self)
self:EnableDefaultToggleCaps()
self.AnimatorUpgradeManip:Destroy()
if self:GetCurrentLayer() == 'Water' then
self:StartRocking()
end
self:PlayUnitSound('UpgradeFailed')
self:PlayActiveAnimation()
self:CreateTarmac(true, true, true, self.TarmacBag.Orientation, self.TarmacBag.CurrentBP)
if self.MaintainState then
ChangeState(self, self.MaintainPodsState)
else
ChangeState(self, self.PausedState)
end
end,
},
}