forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDRA0202_Script.lua
137 lines (118 loc) · 4.3 KB
/
DRA0202_Script.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
--****************************************************************************
--**
--** File : /cdimage/units/DRA0202/DRA0202_script.lua
--** Author(s): Dru Staltman, Eric Williamson
--**
--** Summary : Cybran Bomber Fighter Script
--**
--** Copyright © 2005 Gas Powered Games, Inc. All rights reserved.
--****************************************************************************
local CAirUnit = import("/lua/cybranunits.lua").CAirUnit
local CAAMissileNaniteWeapon = import("/lua/cybranweapons.lua").CAAMissileNaniteWeapon
local CIFMissileCorsairWeapon = import("/lua/cybranweapons.lua").CIFMissileCorsairWeapon
-- upvalaue for perfomance
local TrashBagAdd = TrashBag.Add
local WaitSeconds = WaitSeconds
local EntityCategoryContains = EntityCategoryContains
local CreateRotator = CreateRotator
---@class DRA0202 : CAirUnit
DRA0202 = ClassUnit(CAirUnit) {
Weapons = {
AntiAirMissiles = ClassWeapon(CAAMissileNaniteWeapon) {},
GroundMissile = ClassWeapon(CIFMissileCorsairWeapon) {
IdleState = State (CIFMissileCorsairWeapon.IdleState) {
Main = function(self)
CIFMissileCorsairWeapon.IdleState.Main(self)
end,
OnGotTarget = function(self)
if self.unit:IsUnitState('Moving') then
self.unit:SetSpeedMult(1.0)
else
self.unit:SetBreakOffTriggerMult(2.0)
self.unit:SetBreakOffDistanceMult(8.0)
self.unit:SetSpeedMult(0.67)
CIFMissileCorsairWeapon.IdleState.OnGotTarget(self)
end
end,
},
OnGotTarget = function(self)
local unit = self.unit
if unit:IsUnitState('Moving') then
unit:SetSpeedMult(1.0)
else
unit:SetBreakOffTriggerMult(2.0)
unit:SetBreakOffDistanceMult(8.0)
unit:SetSpeedMult(0.67)
CIFMissileCorsairWeapon.OnGotTarget(self)
end
end,
OnLostTarget = function(self)
local unit = self.unit
unit:SetBreakOffTriggerMult(1.0)
unit:SetBreakOffDistanceMult(1.0)
unit:SetSpeedMult(1.0)
CIFMissileCorsairWeapon.OnLostTarget(self)
end,
},
},
OnStopBeingBuilt = function(self,builder,layer)
CAirUnit.OnStopBeingBuilt(self,builder,layer)
self:SetMaintenanceConsumptionInactive()
self:SetScriptBit('RULEUTC_StealthToggle', true)
self:RequestRefreshUI()
end,
RotateWings = function(self, target)
local trash = self.Trash
if not self.LWingRotator then
self.LWingRotator = CreateRotator(self, 'B01', 'x')
TrashBagAdd(trash, self.LWingRotator)
end
if not self.RWingRotator then
self.RWingRotator = CreateRotator(self, 'B03', 'x')
TrashBagAdd(trash,self.RWingRotator)
end
local fighterAngle = 0
local bomberAngle = -90
local wingSpeed = 45
if target and EntityCategoryContains(categories.AIR, target) then
if self.LWingRotator then
self.LWingRotator:SetSpeed(wingSpeed)
self.LWingRotator:SetGoal(-fighterAngle)
end
if self.RWingRotator then
self.RWingRotator:SetSpeed(wingSpeed)
self.RWingRotator:SetGoal(fighterAngle)
end
else
if self.LWingRotator then
self.LWingRotator:SetSpeed(wingSpeed)
self.LWingRotator:SetGoal(-bomberAngle)
end
if self.RWingRotator then
self.RWingRotator:SetSpeed(wingSpeed)
self.RWingRotator:SetGoal(bomberAngle)
end
end
end,
OnCreate = function(self)
CAirUnit.OnCreate(self)
local trash = self.Trash
TrashBagAdd(trash,ForkThread(self.MonitorWings,self))
end,
MonitorWings = function(self)
local airTarget
while self and not self.Dead do
local airTargetWeapon = self:GetWeaponByLabel('AntiAirMissiles')
if airTargetWeapon then
airTarget = airTargetWeapon:GetCurrentTarget()
end
if airTarget then
self:RotateWings(airTarget)
else
self:RotateWings(nil)
end
WaitSeconds(1)
end
end,
}
TypeClass = DRA0202