-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathdynassault.lua
More file actions
386 lines (336 loc) · 10.9 KB
/
Copy pathdynassault.lua
File metadata and controls
386 lines (336 loc) · 10.9 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
include "constants.lua"
local dyncomm = include('dynamicCommander.lua')
_G.dyncomm = dyncomm
--------------------------------------------------------------------------------
-- pieces
--------------------------------------------------------------------------------
local pieceMap = Spring.GetUnitPieceMap(unitID)
local HAS_GATTLING = pieceMap.rgattlingflare and true or false
local HAS_BONUS_CANNON = pieceMap.bonuscannonflare and true or false
local torso = piece 'torso'
local rcannon_flare= HAS_GATTLING and piece('rgattlingflare') or piece('rcannon_flare')
local barrels = HAS_GATTLING and piece 'barrels' or nil
local lcannon_flare = HAS_BONUS_CANNON and piece('bonuscannonflare') or piece('lnanoflare')
local lnanoflare = piece 'lnanoflare'
local lnanohand = piece 'lnanohand'
local larm = piece 'larm'
local rarm = piece 'rarm'
local pelvis = piece 'pelvis'
local rupleg = piece 'rupleg'
local lupleg = piece 'lupleg'
local rhand = piece 'rhand'
local lleg = piece 'lleg'
local lfoot = piece 'lfoot'
local rleg = piece 'rleg'
local rfoot = piece 'rfoot'
local smokePiece = {torso}
local nanoPieces = {lnanoflare}
--------------------------------------------------------------------------------
-- constants
--------------------------------------------------------------------------------
local SIG_WALK = 1
local SIG_LASER = 2
local SIG_DGUN = 4
local SIG_RESTORE_LASER = 8
local SIG_RESTORE_DGUN = 16
local SIG_RESTORE_TORSO = 32
local TORSO_SPEED_YAW = math.rad(300)
local ARM_SPEED_PITCH = math.rad(180)
local ARM_PERPENDICULAR = math.rad(90)
local RESTORE_DELAY = 2500
local resetRestoreTorso = false
--------------------------------------------------------------------------------
-- vars
--------------------------------------------------------------------------------
local isLasering, isDgunning = false, false
local restoreHeading, restorePitch = 0, 0
local starBLaunchers = {}
local wepTable = UnitDefs[unitDefID].weapons
wepTable.n = nil
for index, weapon in pairs(wepTable) do
local weaponDef = WeaponDefs[weapon.weaponDef]
if weaponDef.type == "StarburstLauncher" then
starBLaunchers[index] = true
--Spring.Echo("sbl found")
end
end
--------------------------------------------------------------------------------
-- Walking
--------------------------------------------------------------------------------
local PACE_MULT = 0.7
local BASE_VELOCITY = UnitDefNames.benzcom1.speed or 1.25*30
local VELOCITY = UnitDefs[unitDefID].speed or BASE_VELOCITY
local PACE = 2*PACE_MULT * VELOCITY/BASE_VELOCITY
local SLEEP_TIME = 360/PACE_MULT
local walkCycle = 1 -- Alternate between 1 and 2
local walkAngle = {
{ -- Moving forwards
{
hip = {math.rad(-12), math.rad(35) * PACE},
leg = {math.rad(80), math.rad(100) * PACE},
foot = {math.rad(5), math.rad(40) * PACE},
arm = {math.rad(-10), math.rad(10) * PACE},
},
{
hip = {math.rad(-40), math.rad(50) * PACE},
leg = {math.rad(10), math.rad(100) * PACE},
foot = {math.rad(-5), math.rad(140) * PACE},
},
},
{ -- Moving backwards
{
hip = {math.rad(2), math.rad(50) * PACE},
leg = {math.rad(2), math.rad(40) * PACE},
foot = {math.rad(8), math.rad(20) * PACE},
arm = {math.rad(10), math.rad(15) * PACE},
},
{
hip = {math.rad(20), math.rad(25) * PACE},
leg = {math.rad(35), math.rad(35) * PACE},
foot = {math.rad(-10), math.rad(80) * PACE},
}
},
}
local function Walk()
Signal(SIG_WALK)
SetSignalMask(SIG_WALK)
while true do
walkCycle = 3 - walkCycle
local speedMult = math.max(0.05, GG.att_MoveChange[unitID] or 1)*dyncomm.GetPace()
local left = walkAngle[walkCycle]
local right = walkAngle[3 - walkCycle]
-----------------------------------------------------------------------------------
Turn(lupleg, x_axis, left[1].hip[1], left[1].hip[2] * speedMult)
Turn(lleg, x_axis, left[1].leg[1], left[1].leg[2] * speedMult)
Turn(lfoot, x_axis, left[1].foot[1], left[1].foot[2] * speedMult)
Turn(rupleg, x_axis, right[1].hip[1], right[1].hip[2] * speedMult)
Turn(rleg, x_axis, right[1].leg[1], right[1].leg[2] * speedMult)
Turn(rfoot, x_axis, right[1].foot[1], right[1].foot[2] * speedMult)
if not (isLasering or isDgunning) then
Turn(larm, x_axis, left[1].arm[1], left[1].arm[2] * speedMult)
Turn(rarm, x_axis, right[1].arm[1], right[1].arm[2] * speedMult)
end
Sleep(SLEEP_TIME / speedMult)
-----------------------------------------------------------------------------------
Turn(lupleg, x_axis, left[2].hip[1], left[2].hip[2] * speedMult)
Turn(lleg, x_axis, left[2].leg[1], left[2].leg[2] * speedMult)
Turn(lfoot, x_axis, left[2].foot[1], left[2].foot[2] * speedMult)
Turn(rupleg, x_axis, right[2].hip[1], right[2].hip[2] * speedMult)
Turn(rleg, x_axis, right[2].leg[1], right[2].leg[2] * speedMult)
Turn(rfoot, x_axis, right[2].foot[1], right[2].foot[2] * speedMult)
if not (isLasering or isDgunning) then
Turn(torso, z_axis, -0.1*(walkCycle - 1.5), 0.12 * speedMult)
end
Sleep(SLEEP_TIME / speedMult)
end
end
local function RestoreLegs()
Signal(SIG_WALK)
SetSignalMask(SIG_WALK)
Move(pelvis, y_axis, 0, 1)
Turn(lupleg, x_axis, 0, math.rad(200))
Turn(lleg, x_axis, 0, math.rad(200))
Turn(lfoot, x_axis, 0, math.rad(200))
Turn(rupleg, x_axis, 0, math.rad(200))
Turn(rleg, x_axis, 0, math.rad(200))
Turn(rfoot, x_axis, 0, math.rad(200))
Turn(torso, y_axis, 0, math.rad(200))
if not (isLasering or isDgunning) then
Turn(larm, x_axis, 0, math.rad(200))
Turn(rarm, x_axis, 0, math.rad(200))
Turn(torso, z_axis, 0, math.rad(200))
end
end
function script.StartMoving()
StartThread(Walk)
end
function script.StopMoving()
StartThread(RestoreLegs)
end
--------------------------------------------------------------------------------
-- Aiming
--------------------------------------------------------------------------------
local function RestoreTorsoAim()
Turn(torso, y_axis, restoreHeading, TORSO_SPEED_YAW)
end
local function RestoreTorsoAfterDelay(sleepTime)
local counter = (sleepTime or RESTORE_DELAY)
while true do
if counter > 0 and not Spring.GetUnitIsStunned(unitID) then
counter = counter - 100
end
if resetRestoreTorso then
resetRestoreTorso = false
counter = (sleepTime or RESTORE_DELAY)
end
if counter <= 0 then
RestoreTorsoAim()
end
Sleep(100)
end
end
local function RestoreLaser()
resetRestoreTorso = true
Signal(SIG_RESTORE_LASER)
SetSignalMask(SIG_RESTORE_LASER)
Sleep(RESTORE_DELAY)
isLasering = false
Turn(rarm, x_axis, restorePitch, ARM_SPEED_PITCH)
Turn(rhand, x_axis, 0, ARM_SPEED_PITCH)
if HAS_GATTLING then
Spin(barrels, z_axis, 100)
Sleep(200)
Turn(barrels, z_axis, 0, ARM_SPEED_PITCH)
end
end
local function RestoreDGun()
resetRestoreTorso = true
Signal(SIG_RESTORE_DGUN)
SetSignalMask(SIG_RESTORE_DGUN)
Sleep(RESTORE_DELAY)
isDgunning = false
Turn(larm, x_axis, 0, ARM_SPEED_PITCH)
Turn(lnanohand, x_axis, 0, ARM_SPEED_PITCH)
end
local dgunAim = false
local function PrioritiseDgun()
dgunAim = true
Sleep(500)
dgunAim = false
end
function script.AimWeapon(num, heading, pitch)
local weaponNum = dyncomm.GetWeapon(num)
if weaponNum == 1 and not dgunAim then
Signal(SIG_LASER)
SetSignalMask(SIG_LASER)
isLasering = true
if pitch > math.rad(-45) then
Turn(rarm, x_axis, -pitch, ARM_SPEED_PITCH)
Turn(rhand, x_axis, 0, ARM_SPEED_PITCH)
else
Turn(rarm, x_axis, math.rad(-18), ARM_SPEED_PITCH)
Turn(rhand, x_axis, math.rad(18) -pitch, ARM_SPEED_PITCH)
end
Turn(torso, y_axis, heading, TORSO_SPEED_YAW)
WaitForTurn(torso, y_axis)
WaitForTurn(rarm, x_axis)
StartThread(RestoreLaser)
return true
elseif weaponNum == 2 then
if dyncomm.IsManualFire(num) and not dgunAim then
StartThread(PrioritiseDgun)
end
if starBLaunchers[num] then
pitch = ARM_PERPENDICULAR
end
Signal(SIG_DGUN)
SetSignalMask(SIG_DGUN)
isDgunning = true
if pitch > math.rad(-45) then
Turn(larm, x_axis, -pitch, ARM_SPEED_PITCH)
Turn(lnanohand, x_axis, 0, ARM_SPEED_PITCH)
else
Turn(larm, x_axis, math.rad(-18), ARM_SPEED_PITCH)
Turn(lnanohand, x_axis, math.rad(18) -pitch, ARM_SPEED_PITCH)
end
--Turn(larm, x_axis, math.min(math.rad(-18), -pitch), ARM_SPEED_PITCH)
--Turn(lnanohand, x_axis, math.max(0, math.rad(18) -pitch), ARM_SPEED_PITCH)
Turn(torso, y_axis, heading, TORSO_SPEED_YAW)
WaitForTurn(torso, y_axis)
WaitForTurn(lnanohand, x_axis)
StartThread(RestoreDGun)
return true
elseif weaponNum == 3 then
return true
end
return false
end
function script.FireWeapon(num)
local weaponNum = dyncomm.GetWeapon(num)
if weaponNum == 1 then
dyncomm.EmitWeaponFireSfx(rcannon_flare, num)
elseif weaponNum == 2 then
dyncomm.EmitWeaponFireSfx(lcannon_flare, num)
dgunAim = false
end
end
function script.Shot(num)
local weaponNum = dyncomm.GetWeapon(num)
if weaponNum == 1 then
dyncomm.EmitWeaponShotSfx(rcannon_flare, num)
elseif weaponNum == 2 then
dyncomm.EmitWeaponShotSfx(lcannon_flare, num)
end
end
function script.AimFromWeapon(num)
if dyncomm.IsManualFire(num) then
if dyncomm.GetWeapon(num) == 1 then
return rcannon_flare
elseif dyncomm.GetWeapon(num) == 2 then
return lcannon_flare
end
end
return pelvis
end
function script.QueryWeapon(num)
if dyncomm.GetWeapon(num) == 1 then
return rcannon_flare
elseif dyncomm.GetWeapon(num) == 2 then
return lcannon_flare
end
return pelvis
end
function script.StopBuilding()
SetUnitValue(COB.INBUILDSTANCE, 0)
Turn(larm, x_axis, 0, ARM_SPEED_PITCH)
restoreHeading, restorePitch = 0, 0
StartThread(RestoreDGun)
end
function script.StartBuilding(heading, pitch)
restoreHeading, restorePitch = heading, pitch
Turn(larm, x_axis, math.rad(-30) - pitch, ARM_SPEED_PITCH)
if not (isDgunning) then Turn(torso, y_axis, heading, TORSO_SPEED_YAW) end
SetUnitValue(COB.INBUILDSTANCE, 1)
end
function script.Create()
dyncomm.Create()
Hide(rcannon_flare)
Hide(lnanoflare)
-- Turn(larm, x_axis, math.rad(30))
-- Turn(rarm, x_axis, math.rad(-10))
-- Turn(rhand, x_axis, math.rad(41))
-- Turn(lnanohand, x_axis, math.rad(36))
StartThread(GG.Script.SmokeUnit, unitID, smokePiece)
StartThread(RestoreTorsoAfterDelay)
Spring.SetUnitNanoPieces(unitID, nanoPieces)
end
function script.Killed(recentDamage, maxHealth)
local severity = recentDamage/maxHealth
if severity < 0.5 then
Explode(torso, SFX.NONE)
Explode(larm, SFX.NONE)
Explode(rarm, SFX.NONE)
Explode(pelvis, SFX.NONE)
Explode(lupleg, SFX.NONE)
Explode(rupleg, SFX.NONE)
Explode(lnanoflare, SFX.NONE)
Explode(rhand, SFX.NONE)
Explode(lleg, SFX.NONE)
Explode(rleg, SFX.NONE)
dyncomm.SpawnModuleWrecks(1)
dyncomm.SpawnWreck(1)
else
Explode(torso, SFX.SHATTER)
Explode(larm, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
Explode(rarm, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
Explode(pelvis, SFX.SHATTER)
Explode(lupleg, SFX.SHATTER)
Explode(rupleg, SFX.SHATTER)
Explode(lnanoflare, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
Explode(rhand, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
Explode(lleg, SFX.SHATTER)
Explode(rleg, SFX.SHATTER)
dyncomm.SpawnModuleWrecks(2)
dyncomm.SpawnWreck(2)
end
end