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

init()
{
    level.lasedstrikeglow = loadfx( "fx/misc/laser_glow" );
    level.lasedstrikeexplode = loadfx( "fx/explosions/uav_advanced_death" );
    thread onplayerconnect();
}

onplayerconnect()
{
    for (;;)
    {
        level waittill( "connected", var_0 );
        var_0 thread onplayerspawned();
        var_0.soflamammoused = 0;
    }
}

onplayerspawned()
{
    self endon( "disconnect" );

    for (;;)
    {
        self waittill( "spawned_player" );
        thread watch_alien_soflam_usage();
        thread watch_alien_soflam_weaponswitch();
    }
}

watch_alien_soflam_weaponswitch()
{
    self endon( "disconnect" );
    self endon( "death" );

    for (;;)
    {
        self waittill( "weapon_change", var_0 );

        if ( var_0 == "aliensoflam_mp" )
            self setweaponammoclip( "aliensoflam_mp", 3 - self.soflamammoused );
    }
}

watch_alien_soflam_usage()
{
    self notify( "watchaliensoflamusage" );
    self endon( "watchaliensoflamusage" );
    level endon( "game_ended" );
    self endon( "disconnect" );

    while ( maps\mp\_utility::ischangingweapon() )
        wait 0.05;

    for (;;)
    {
        if ( self attackbuttonpressed() && self getcurrentweapon() == "aliensoflam_mp" && self adsbuttonpressed() && !self isusingturret() )
        {
            self weaponlocktargettooclose( 0 );
            self weaponlockfree();
            var_0 = gettargetpoint();

            if ( !isdefined( var_0 ) )
            {
                wait 0.05;
                continue;
            }

            if ( !isdefined( var_0[0] ) )
            {
                wait 0.05;
                continue;
            }

            var_1 = var_0[0];
            attacklasedtarget( var_1 );
        }

        wait 0.05;
    }
}

playlocksound()
{
    if ( isdefined( self.playinglocksound ) && self.playinglocksound )
        return;

    self playlocalsound( "javelin_clu_lock" );
    self.playinglocksound = 1;
    wait 0.75;
    self stoplocalsound( "javelin_clu_lock" );
    self.playinglocksound = 0;
}

playlockerrorsound()
{
    if ( isdefined( self.playinglocksound ) && self.playinglocksound )
        return;

    self playlocalsound( "javelin_clu_aquiring_lock" );
    self.playinglocksound = 1;
    wait 0.75;
    self stoplocalsound( "javelin_clu_aquiring_lock" );
    self.playinglocksound = 0;
}

attacklasedtarget( var_0 )
{
    var_1 = undefined;
    var_2 = undefined;
    var_3 = 6000;
    var_4 = ( 0, 0, var_3 );
    var_5 = 3000;
    var_6 = anglestoforward( self.angles );
    var_7 = self.origin;
    var_8 = var_7 + var_4 + var_6 * var_5 * -1;
    var_9 = 0;
    var_10 = bullettrace( var_0 + ( 0, 0, var_3 ), var_0, 0 );

    if ( var_10["fraction"] > 0.99 )
    {
        var_9 = 1;
        var_8 = var_0 + ( 0, 0, var_3 );
    }

    if ( !var_9 )
    {
        var_10 = bullettrace( var_0 + ( 300, 0, var_3 ), var_0, 0 );

        if ( var_10["fraction"] > 0.99 )
        {
            var_9 = 1;
            var_8 = var_0 + ( 300, 0, var_3 );
        }
    }

    if ( !var_9 )
    {
        var_10 = bullettrace( var_0 + ( 0, 300, var_3 ), var_0, 0 );

        if ( var_10["fraction"] > 0.99 )
        {
            var_9 = 1;
            var_8 = var_0 + ( 0, 300, var_3 );
        }
    }

    if ( !var_9 )
    {
        var_10 = bullettrace( var_0 + ( 0, -300, var_3 ), var_0, 0 );

        if ( var_10["fraction"] > 0.99 )
        {
            var_9 = 1;
            var_8 = var_0 + ( 0, -300, var_3 );
        }
    }

    if ( !var_9 )
    {
        var_10 = bullettrace( var_0 + ( 300, 300, var_3 ), var_0, 0 );

        if ( var_10["fraction"] > 0.99 )
        {
            var_9 = 1;
            var_8 = var_0 + ( 300, 300, var_3 );
        }
    }

    if ( !var_9 )
    {
        var_10 = bullettrace( var_0 + ( -300, 0, var_3 ), var_0, 0 );

        if ( var_10["fraction"] > 0.99 )
        {
            var_9 = 1;
            var_8 = var_0 + ( -300, 0, var_3 );
        }
    }

    if ( !var_9 )
    {
        var_10 = bullettrace( var_0 + ( -300, -300, var_3 ), var_0, 0 );

        if ( var_10["fraction"] > 0.99 )
        {
            var_9 = 1;
            var_8 = var_0 + ( -300, -300, var_3 );
        }
    }

    if ( !var_9 )
    {
        var_10 = bullettrace( var_0 + ( 300, -300, var_3 ), var_0, 0 );

        if ( var_10["fraction"] > 0.99 )
        {
            var_9 = 1;
            var_8 = var_0 + ( 300, -300, var_3 );
        }
    }

    if ( !var_9 )
    {
        for ( var_11 = 0; var_11 < 5; var_11++ )
        {
            var_3 = var_3 / 2;
            var_4 = ( 0, 0, var_3 );
            var_8 = self.origin + var_4 + var_6 * var_5 * -1;
            var_12 = bullettrace( var_0, var_8, 0 );

            if ( var_12["fraction"] > 0.99 )
            {
                var_9 = 1;
                break;
            }

            wait 0.05;
        }
    }

    if ( !var_9 )
    {
        for ( var_11 = 0; var_11 < 5; var_11++ )
        {
            var_3 = var_3 * 2.5;
            var_4 = ( 0, 0, var_3 );
            var_8 = self.origin + var_4 + var_6 * var_5 * -1;
            var_12 = bullettrace( var_0, var_8, 0 );

            if ( var_12["fraction"] > 0.99 )
            {
                var_9 = 1;
                break;
            }

            wait 0.05;
        }
    }

    if ( !var_9 )
    {
        thread canthittarget();
        return 0;
    }

    var_1 = spawnfx( level.lasedstrikeglow, var_0 );
    thread playlocksound();
    self weaponlockfinalize( var_0, ( 0, 0, 0 ), 0 );
    thread update_soflam_ammocount();
    var_13 = magicbullet( "aliensoflam_missle_mp", var_8, var_0, self );
    var_13 missile_settargetent( var_1 );
    thread looptriggeredeffect( var_1, var_13 );
    self weaponlockfree();
    var_13 waittill( "death" );

    if ( isdefined( var_1 ) )
        var_1 delete();

    earthquake( 0.4, 1, var_0, 850 );
    return 1;
}

looptriggeredeffect( var_0, var_1 )
{
    var_1 endon( "death" );
    level endon( "game_ended" );

    for (;;)
    {
        triggerfx( var_0 );
        wait 0.5;
    }
}

canthittarget()
{
    thread playlockerrorsound();
    self weaponlocktargettooclose( 1 );
}

gettargetpoint()
{
    var_0 = self geteye();
    var_1 = self getplayerangles();
    var_2 = anglestoforward( var_1 );
    var_3 = var_0 + var_2 * 15000;
    var_4 = bullettrace( var_0, var_3, 0, undefined );

    if ( var_4["surfacetype"] == "none" )
        return undefined;

    if ( var_4["surfacetype"] == "default" )
        return undefined;

    var_5 = [];
    var_5[0] = var_4["position"];
    var_5[1] = var_4["normal"];
    return var_5;
}

update_soflam_ammocount()
{
    self.soflamammoused++;
    self setweaponammoclip( "aliensoflam_mp", 3 - self.soflamammoused );

    if ( self.soflamammoused >= 3 )
    {
        self.soflamammoused = 0;
        self takeweapon( "aliensoflam_mp" );

        if ( !maps\mp\alien\_utility::is_true( self.has_special_weapon ) && !maps\mp\alien\_utility::is_true( self.is_holding_deployable ) )
            self switchtoweapon( self getweaponslistprimaries()[0] );
    }
}
