-----------------------------------------------------------------------------
--   File     :  /mods/4DC_V0.8/hook/projectiles/SBOOtheTacticalBomb02/SBOOtheTacticalBomb02_script.lua
--
--   Author(s):  Gordon Duclos, Aaron Lundquist
--
--   Modded by:  Resin_Smoker (Aug, 2011)
--
--   Summary  :  Othe Tactical Bomb Projectile script, for unit xsa0202
--               Modified for bouncing projectiles (death blossom)
--
--   Copyright © 2011 Gas Powered Games, Inc.  All rights reserved.
-----------------------------------------------------------------------------

SBOOtheTacticalProj = import('/lua/seraphimprojectiles.lua').SOtheTacticalBomb 
local EffectTemplate = import('/lua/EffectTemplates.lua')
local RandomFloat = import('/lua/utilities.lua').GetRandomFloat

SBOOtheTacticalBomb02 = Class(SBOOtheTacticalProj) {     
    OnImpact = function(self, TargetType, TargetEntity)
        if not self:BeenDestroyed() then
            if TargetType ~= 'Unit' then               
                local ChildProjectileBP = '/mods/4dc_v0.8/hook/projectiles/sifthunthoartilleryshell02/SIFThunthoArtilleryShell02_proj.bp'       
                local vx, vy, vz = self:GetVelocity()                       
                -- Create several other projectiles in a dispersal pattern
                local numProjectiles = 12
                -- Rescale the Damage and Radius vs the number of projectiles to be created
                self.DamageData.DamageAmount = self.DamageData.DamageAmount / numProjectiles or 1
                self.DamageData.DamageRadius = 1
                -- Calculate the spread
                local angle = (2*math.pi) / numProjectiles
                local angleInitial = RandomFloat( 0, angle )               
                local angleVariation = angle * ((360 / numProjectiles) / 100)
                local spreadMulti = nil                             
                local xVec = 0
                local yVec = -vy
                local zVec = 0                     
                for i = 0, (numProjectiles -1) do
                    -- Stagger the projectile spread to create three seperate layers of bomblets           
                    if spreadMulti == nil or spreadMulti == 1.2 then               
                        spreadMulti = 0.6
                    elseif spreadMulti == 0.6 then               
                        spreadMulti = 0.9
                    elseif spreadMulti == 0.9 then                     
                        spreadMulti = 1.2                         
                    end
                    -- Launch projectiles at angles away from split location                                         
                    xVec = (math.sin(angleInitial + (i*angle))) * spreadMulti
                    zVec = (math.cos(angleInitial + (i*angle))) * spreadMulti                                       
                    local proj = self:CreateChildProjectile(ChildProjectileBP)
                    proj:SetVelocity(xVec,yVec,zVec)
                    proj:SetVelocity(3 + spreadMulti)
                    proj:PassDamageData(self.DamageData)           
                end
            end   
            SBOOtheTacticalProj.OnImpact(self, TargetType, TargetEntity)                 
        end
    end,
}
TypeClass = SBOOtheTacticalBomb02    