From left to right.
wolf spider: single vulcan
huntsman: Energy cannon
Bola: kinetic munitions, smoke grenades
tarantula: twin linked energy cannon(fires 2 energy shots at 1 time)
birdkiller: slaved twin vulcans with independent vulcan mounted on top.
all 5 tanks, and their variant weapons systems are supported by 1 script
Code: Select all
-------------------------------------------------------
-- License: Public Domain
-- Author: Steve (Smoth) Smith
-- Date: 11/27/2012
-------------------------------------------------------
-- Piece names
base = piece 'base'
local treadCount = 4
weaponBarrel = {}
weaponSleeve = {}
weaponPiece = {}
twinLinkedPiece = {}
weaponTurret = {}
tankTreads = {}
-- State variables
isMoving, isAiming = false, false
local spGetUnitDefID = Spring.GetUnitDefID
local unitWeapons = {}
-- Signal definitions
local SIG_AIM = {2,4,8,16}
-- effects for emitters
local effectA = 1024
local function TreadAnimations()
local treadnum = 1
local lastTread = treadCount
-- get all my treads.
local counter = 1
while ( counter-1 < treadCount ) do
--Spring.Echo("treads"..counter)
tankTreads[counter] = piece ("treads"..counter)
counter = counter +1
end
-- Spring.Echo("tread count: " .. counter)
-- hide all tank treads
for treadNumber,_ in pairs(tankTreads) do
if treadNumber ~= lastTread then
Hide (tankTreads[treadNumber])
end
end
while( 1 ) do
-- moving animation
if(isMoving == true) then
--Spring.Echo(treadnum, lastTread)
Hide (tankTreads[lastTread])
Show (tankTreads[treadnum])
lastTread = treadnum
treadnum = treadnum + 1
if( treadnum == treadCount+1) then
treadnum = 1
end
end
Sleep (50)
end
end
function script.StartMoving()
isMoving = true
end
function script.StopMoving()
isMoving = false
end
local function getWeaponData()
weapons = UnitDefs[spGetUnitDefID(unitID)].weapons
local counter = 1
for k,v in pairs(weapons) do
Spring.Echo(" --= weapon number: " .. counter .. " =-- ")
unitWeapons[counter] = {}
if WeaponDefs[v.weaponDef].customParams.abilityweapon then
unitWeapons[counter].abilityWeapon = WeaponDefs[v.weaponDef].customParams.abilityweapon
weaponPiece[counter] = base
weaponBarrel[counter] = base
else
-- twinlinked covers when we have two barrels firing at 1 time
-- (such as a double barrel shotgun)
if WeaponDefs[v.weaponDef].customParams.twinlinked then
twinLinkedPiece[counter] = piece ("weapon".. counter .. "_a_2")
Spring.Echo(" weapon".. counter .. "_a_2")
end
weaponPiece[counter] = piece ("weapon".. counter .. "_a_1")
Spring.Echo(" weapon".. counter .. "_a_1")
weaponBarrel[counter] = piece ("weapon".. counter .. "_a_barrel")
--Spring.Echo(" weaponBarrel: weapon".. counter .. "_a_barrel")
weaponSleeve[counter] = piece ("weapon".. counter .. "_a_sleeve")
--Spring.Echo(" weaponSleeve: weapon".. counter .. "_a_sleeve")
if v.slavedTo ~= 0 then
unitWeapons[counter].slave = v.slavedTo
--Spring.Echo("slaveto", unitWeapons[counter].slave)
else
weaponTurret[counter] = piece ("weapon".. counter .. "_turret")
--Spring.Echo(" weapon".. counter .. "_turret")
end
end
if WeaponDefs[v.weaponDef].customParams.animation then
unitWeapons[counter].animation = WeaponDefs[v.weaponDef].customParams.animation
end
counter = counter +1
end
end
--------------------------------------------------------
--start ups :)
--------------------------------------------------------
function script.Create()
-- Initial State
StartThread(TreadAnimations)
getWeaponData()
end
function script.AimFromWeapon(weaponID)
return weaponBarrel[weaponID]
end
function script.QueryWeapon(weaponID)
return weaponPiece[weaponID]
end
-----------------------------------------------------------------------
--gun functions;
-----------------------------------------------------------------------
-----------------------------------------------------------------------
-- This coroutine is restarted with each time a unit reaims,
-- not the most efficient and should be optimized. Possible
-- augmentation needed to lus.
-----------------------------------------------------------------------
local function RestoreAfterDelay(weaponID)
Sleep(1000)
if (unitWeapons[weaponID].animation == "spinup")then
StopSpin (weaponBarrel[weaponID], z_axis, math.rad(50))
end
if(unitWeapons[weaponID].slave == nil) then
Turn(weaponTurret[weaponID], y_axis, 0, math.rad(90))
WaitForTurn(weaponTurret[weaponID], y_axis)
end
Turn(weaponSleeve[weaponID], x_axis, 0, math.rad(100))
WaitForTurn(weaponSleeve[weaponID], x_axis)
end
function script.AimWeapon(weaponID, heading, pitch)
if(unitWeapons[weaponID].abilityWeapon) then
return false
end
Signal(SIG_AIM[weaponID])
SetSignalMask(SIG_AIM[weaponID])
if (unitWeapons[weaponID].animation == "spinup")then
Spin(weaponBarrel[weaponID], z_axis, 20)
end
if(unitWeapons[weaponID].slave == nil) then
--Spring.Echo(weaponID, unitWeapons[weaponID].slave)
Turn(weaponTurret[weaponID], y_axis, heading, math.rad(20))
WaitForTurn(weaponTurret[weaponID], y_axis)
end
Turn(weaponSleeve[weaponID], x_axis, 0 - pitch, math.rad(100))
WaitForTurn(weaponSleeve[weaponID], x_axis)
StartThread(RestoreAfterDelay, weaponID)
return true
end
function LaunchSmoke()
EmitSfx(piece 'smoke', 2049)
end
function script.Shot(weaponID)
if (unitWeapons[weaponID].animation == "recoil")then
Move(weaponBarrel[weaponID], z_axis, -1)
EmitSfx(weaponPiece[weaponID], 1025)
Move(weaponBarrel[weaponID], z_axis, 0, 1)
else
EmitSfx(weaponPiece[weaponID], 1025)
end
-- if we have a twin linked barrel to fire
if twinLinkedPiece[weaponID] then
EmitSfx(twinLinkedPiece[weaponID], 2048)
EmitSfx(twinLinkedPiece[weaponID], 1025)
end
end
function script.Killed(recentDamage, maxHealth)
local severity = recentDamage/maxHealth
if (severity <= 99) then
return 3
else
return 0
end
end
(the above code is work in progress but I wanted to show it off, get over it)
also, in before store in gg. table.. I will, when I am done. Right now, this is the easier way.