// IW6 GSC SOURCE
// Generated by https://github.com/xensik/gsc-tool

init()
{
    level.killstreakfuncs["aa_launcher"] = ::tryuseaalauncher;
    maps\mp\_laserguidedlauncher::lgm_init( "vfx/gameplay/mp/killstreaks/vfx_maaws_split", "vfx/gameplay/mp/killstreaks/vfx_maaws_homing" );
}

getaalaunchername()
{
    return "iw6_maaws_mp";
}

getaalauncherchildname()
{
    return "iw6_maawschild_mp";
}

getaalauncherhomingname()
{
    return "iw6_maawshoming_mp";
}

getaalauncherammo( var_0 )
{
    var_1 = getaalauncheruniqueindex( var_0 );
    var_2 = 0;

    if ( isdefined( var_0.pers["aaLauncherAmmo"][var_1] ) )
        var_2 = var_0.pers["aaLauncherAmmo"][var_1];

    return var_2;
}

clearaalauncherammo( var_0 )
{
    var_1 = getaalauncheruniqueindex( var_0 );
    var_0.pers["aaLauncherAmmo"][var_1] = undefined;
}

setaalauncherammo( var_0, var_1, var_2 )
{
    var_3 = getaalauncheruniqueindex( var_0 );
    var_0.pers["aaLauncherAmmo"][var_3] = var_1;

    if ( !isdefined( var_2 ) || var_2 )
    {
        if ( var_0 hasweapon( getaalaunchername() ) )
            var_0 setweaponammoclip( getaalaunchername(), var_1 );
    }
}

getaalauncheruniqueindex( var_0 )
{
    return var_0.pers["killstreaks"][var_0.killstreakindexweapon].kid;
}

tryuseaalauncher( var_0, var_1 )
{
    return useaalauncher( self, var_0 );
}

useaalauncher( var_0, var_1 )
{
    if ( !isdefined( self.pers["aaLauncherAmmo"] ) )
        self.pers["aaLauncherAmmo"] = [];

    if ( getaalauncherammo( var_0 ) == 0 )
        setaalauncherammo( self, 2, 0 );

    level thread monitorweaponswitch( var_0 );
    level thread monitorlauncherammo( var_0 );
    thread maps\mp\_laserguidedlauncher::lgm_firing_monitormissilefire( getaalaunchername(), getaalauncherchildname(), getaalauncherhomingname() );
    var_2 = 0;
    var_3 = var_0 common_scripts\utility::waittill_any_return( "aa_launcher_switch", "aa_launcher_empty", "death", "disconnect" );

    if ( var_3 == "aa_launcher_empty" )
    {
        var_0 common_scripts\utility::waittill_any( "weapon_change", "LGM_player_allMissilesDestroyed", "death", "disconnect" );
        var_2 = 1;
    }
    else
    {
        if ( var_0 hasweapon( getaalaunchername() ) && var_0 getammocount( getaalaunchername() ) == 0 )
            clearaalauncherammo( var_0 );

        if ( getaalauncherammo( var_0 ) == 0 )
            var_2 = 1;
    }

    var_0 notify( "aa_launcher_end" );
    maps\mp\_laserguidedlauncher::lgm_firing_endmissilefire();
    return var_2;
}

monitorweaponswitch( var_0 )
{
    var_0 endon( "death" );
    var_0 endon( "disconnect" );
    var_0 endon( "aa_launcher_empty" );
    var_0 endon( "aa_launcher_end" );
    var_1 = var_0 getcurrentweapon();

    while ( var_1 == getaalaunchername() )
        var_0 waittill( "weapon_change", var_1 );

    var_0 notify( "aa_launcher_switch" );
}

monitorlauncherammo( var_0 )
{
    var_0 endon( "death" );
    var_0 endon( "disconnect" );
    var_0 endon( "aa_launcher_switch" );
    var_0 endon( "aa_launcher_end" );
    setaalauncherammo( var_0, getaalauncherammo( var_0 ), 1 );

    for (;;)
    {
        var_0 waittill( "weapon_fired", var_1 );

        if ( var_1 != getaalaunchername() )
            continue;

        var_2 = var_0 getammocount( getaalaunchername() );
        setaalauncherammo( var_0, var_2, 0 );

        if ( getaalauncherammo( var_0 ) == 0 )
        {
            clearaalauncherammo( var_0 );
            var_0 notify( "aa_launcher_empty" );
            break;
        }
    }
}
