-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathbomberassault.lua
More file actions
203 lines (185 loc) · 5.86 KB
/
Copy pathbomberassault.lua
File metadata and controls
203 lines (185 loc) · 5.86 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
local bomb = piece('bomb');
local bombEmit = piece('bombEmit');
local exhaustLeft = piece('exhaustLeft');
local exhaustRight = piece('exhaustRight');
local exhaustTop = piece('exhaustTop');
local hull = piece('hull');
local petalLeft = piece('petalLeft');
local petalRear = piece('petalRear');
local petalRight = piece('petalRight');
local turbineLeft = piece('turbineLeft');
local turbineRight = piece('turbineRight');
local turbineTop = piece('turbineTop');
local wingLeftFront = piece('wingLeftFront');
local wingLeftRear = piece('wingLeftRear');
local wingRightFront = piece('wingRightFront');
local wingRightRear = piece('wingRightRear');
local wingTopFront = piece('wingTopFront');
local wingTopRear = piece('wingTopRear');
local smokePiece = {exhaustTop, exhaustRight, exhaustLeft}
local CMD_AIR_MANUALFIRE = Spring.Utilities.CMD.AIR_MANUALFIRE
local manualfireWeapon = tonumber(UnitDefs[unitDefID].customParams.air_manual_fire_weapon)
include "bombers.lua"
include "constants.lua"
local manualTarget_p1 = false
local manualTarget_p2 = false
local manualTarget_p3 = false
local rangeChanged = false
local THERMITE_NUM, FAKE_GUN_NUM, THERMITE_TRUERANGE, THERMITE_ALT_RANGE
for i = 1, #UnitDefs[unitDefID].weapons do
local weapondef = WeaponDefs[UnitDefs[unitDefID].weapons[i].weaponDef]
if weapondef == WeaponDefNames["bomberassault_thermite_bomb"] then
THERMITE_NUM = i
THERMITE_TRUERANGE = weapondef.customParams.truerange
THERMITE_ALT_RANGE = weapondef.customParams.fakerange
end
if weapondef == WeaponDefNames["bomberassault_zeppelin_bomb"] then
FAKE_GUN_NUM = i
end
end
function ReammoComplete()
Show(bomb)
end
local function AirManualFireThread()
local unitFollow = 0
while true do
local cmdID, cmdOpts, cmdTag, cp_1, cp_2, cp_3 = Spring.GetUnitCurrentCommand(unitID)
if cmdID == CMD_AIR_MANUALFIRE then
if cp_3 then
Spring.SetUnitTarget(unitID, cp_1, cp_2, cp_3, false, false, manualfireWeapon)
manualTarget_p1 = cp_1
manualTarget_p2 = cp_2
manualTarget_p3 = cp_3
elseif unitFollow then
if cp_1 and Spring.ValidUnitID(cp_1) then
local tx, ty, tz = CallAsTeam(Spring.GetUnitTeam(unitID),
function ()
local _,_,_, _,_,_, tx, ty, tz = Spring.GetUnitPosition(cp_1, true, true)
if tx then
ty = math.max(0, Spring.GetGroundHeight(tx, tz))
return tx, ty, tz
end
end)
if tx then
Spring.SetUnitTarget(unitID, tx, ty, tz, false, false, manualfireWeapon)
manualTarget_p1 = tx
manualTarget_p2 = ty
manualTarget_p3 = tz
end
end
end
else
manualTarget_p1 = false
manualTarget_p2 = false
manualTarget_p3 = false
end
--else
--
--end
unitFollow = (unitFollow + 1)%3
Sleep(33)
end
end
local function IsManualFireTargetValid()
local targetType, isUser, targetParams = Spring.GetUnitWeaponTarget(unitID, manualfireWeapon)
if targetType == 2 then
if targetParams and targetParams[1] == manualTarget_p1 and
targetParams[2] == manualTarget_p2 and targetParams[3] == manualTarget_p3 then
return true
end
end
return false
end
--function script.Deactivate()
-- StopSpin(turbineTop, z_axis, 0.5);
-- StopSpin(turbineLeft, z_axis, 0.5);
-- StopSpin(turbineRight, z_axis, 0.5);
--end
--function script.Activate()
-- Spin(turbineTop, z_axis, 8,2);
-- Spin(turbineLeft, z_axis, 8,2);
-- Spin(turbineRight, z_axis, -8,2);
--end
function script.Create()
StartThread(GG.Script.SmokeUnit, unitID, smokePiece)
StartThread(AirManualFireThread)
Move(bomb, y_axis, -8)
Move(bombEmit, y_axis, -6)
end
function script.QueryWeapon(num)
return bombEmit
end
function script.AimFromWeapon(num)
return bombEmit
end
function script.AimWeapon(num, heading, pitch)
if RearmBlockShot() then
return false
end
if num == manualfireWeapon then
return IsManualFireTargetValid()
end
return true
end
function script.FireWeapon(num)
Hide(bomb)
Sleep(66)
Reload()
end
function script.BlockShot(num, targetID)
if num == FAKE_GUN_NUM or
(num == manualfireWeapon and not IsManualFireTargetValid()) or
(GetUnitValue(COB.CRASHING) == 1) or
RearmBlockShot() then
return true
end
if num == THERMITE_NUM then
rangeChanged = true
Spring.SetUnitWeaponState(unitID, THERMITE_NUM, "range", THERMITE_ALT_RANGE)
end
return false
end
function script.EndBurst()
if rangeChanged then
rangeChanged = false
Spring.SetUnitWeaponState(unitID, THERMITE_NUM, "range", THERMITE_TRUERANGE)
end
end
function script.Killed(recentDamage, maxHealth)
local severity = recentDamage/maxHealth
if severity <= .25 then
Explode(turbineLeft, SFX.FALL + SFX.SMOKE + SFX.FIRE)
Explode(turbineLeft, SFX.FIRE)
Explode(wingLeftFront, SFX.FALL + SFX.SMOKE + SFX.FIRE)
Explode(wingLeftRear, SFX.FALL + SFX.SMOKE + SFX.FIRE)
return 1
elseif severity <= .50 then
Explode(turbineLeft, SFX.FALL + SFX.SMOKE + SFX.FIRE)
Explode(turbineLeft, SFX.EXPLODE)
Explode(wingLeftFront, SFX.FALL + SFX.SMOKE + SFX.FIRE)
Explode(wingLeftRear, SFX.FALL + SFX.SMOKE + SFX.FIRE)
Explode(hull, SFX.SHATTER)
return 1
elseif severity <= 0.75 then
Explode(turbineLeft, SFX.EXPLODE + SFX.SMOKE + SFX.FIRE)
Explode(turbineLeft, SFX.EXPLODE)
Explode(wingLeftFront, SFX.FALL + SFX.SMOKE + SFX.FIRE)
Explode(wingLeftRear, SFX.FALL + SFX.SMOKE + SFX.FIRE)
Explode(hull, SFX.SHATTER)
return 1
else
Explode(turbineLeft, SFX.EXPLODE + SFX.SMOKE + SFX.FIRE)
Explode(turbineLeft, SFX.EXPLODE)
Explode(wingLeftFront, SFX.EXPLODE + SFX.SMOKE + SFX.FIRE)
Explode(wingLeftRear, SFX.EXPLODE + SFX.SMOKE + SFX.FIRE)
Explode(turbineRight, SFX.EXPLODE + SFX.SMOKE + SFX.FIRE)
Explode(turbineRight, SFX.EXPLODE)
Explode(wingRightFront, SFX.EXPLODE + SFX.SMOKE + SFX.FIRE)
Explode(wingRightRear, SFX.EXPLODE + SFX.SMOKE + SFX.FIRE)
Explode(turbineTop, SFX.EXPLODE)
Explode(wingTopFront, SFX.EXPLODE + SFX.SMOKE + SFX.FIRE)
Explode(wingTopRear, SFX.EXPLODE + SFX.SMOKE + SFX.FIRE)
Explode(hull, SFX.SHATTER)
return 2
end
end