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

init()
{
    level.killstreakfuncs["drone_hive"] = ::tryusedronehive;
    level.dronemissilespawnarray = getentarray( "remoteMissileSpawn", "targetname" );

    foreach ( var_1 in level.dronemissilespawnarray )
        var_1.targetent = getent( var_1.target, "targetname" );
}

tryusedronehive( var_0, var_1, var_2, var_3, var_4 )
{
    self notify( "action_use" );
    level thread maps\mp\alien\_music_and_dialog::playvoforpredator( self );
    return usedronehive( self, var_0, var_1, var_2, var_3, var_4 );
}

usedronehive( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    var_0 maps\mp\_utility::setusingremote( "remotemissile" );
    self visionsetnakedforplayer( "black_bw", 0.75 );
    maps\mp\alien\_utility::restore_client_fog( 0 );
    thread maps\mp\_utility::set_visionset_for_watching_players( "black_bw", 0.75, 1.0 );
    level thread rundronehive( var_0, var_1, var_2, var_3, var_4, var_5 );
    level thread monitorgameend( var_0, var_1 );
    return 1;
}

rundronehive( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    var_0 endon( "killstreak_disowned" );
    level endon( "game_ended" );

    if ( !isdefined( var_3 ) )
        var_3 = "switchblade_rocket_mp";

    if ( !isdefined( var_2 ) )
        var_2 = 0;

    var_0 notifyonplayercommand( "missileTargetSet", "+attack" );
    var_6 = common_scripts\utility::getclosest( var_0.origin, level.dronemissilespawnarray );
    var_7 = var_6.origin;
    var_8 = var_0.origin;
    var_9 = vectornormalize( var_7 - var_8 );
    var_7 = var_9 * var_4 + var_8;
    var_10 = magicbullet( var_3, var_7, var_8, var_0 );
    var_10 setcandamage( 1 );

    if ( var_2 != 0 )
        var_10 disablemissileboosting();

    var_10.team = var_0.team;
    var_10.type = "remote";
    var_10.owner = var_0;
    var_10.entitynumber = var_10 getentitynumber();
    level.rockets[var_10.entitynumber] = var_10;
    level.remotemissileinprogress = 1;
    level thread monitordeath( var_10 );
    level thread monitorboost( var_10 );
    missileeyes( var_0, var_10, var_1 );
    var_0 notify( "action_use" );
    var_0 setclientomnvar( "ui_predator_missile", 1 );
    var_11 = 0;

    for (;;)
    {
        var_12 = var_10 common_scripts\utility::waittill_any_return( "death", "missileTargetSet" );

        if ( var_12 == "death" )
            break;

        if ( var_11 < var_2 )
        {
            level thread spawnswitchblade( var_10, var_11, var_5 );
            var_11++;
        }

        if ( var_11 == var_2 )
            var_10 enablemissileboosting();
    }

    var_0.turn_off_class_skill_activation = undefined;
    returnplayer( var_0, var_1 );
}

getenemytargets( var_0 )
{
    var_1 = [];

    foreach ( var_3 in level.agentarray )
    {
        if ( !isdefined( var_3.isactive ) || !var_3.isactive )
            continue;

        var_1[var_1.size] = var_3;
    }

    return var_1;
}

spawnswitchblade( var_0, var_1, var_2 )
{
    var_0.owner playlocalsound( "ammo_crate_use" );
    var_3 = anglestoforward( var_0.angles );
    var_4 = anglestoright( var_0.angles );
    var_5 = ( 35, 35, 35 );
    var_6 = ( 15000, 15000, 15000 );

    if ( var_1 )
        var_5 = var_5 * -1;

    var_7 = bullettrace( var_0.origin, var_0.origin + var_3 * var_6, 0, var_0 );
    var_6 = var_6 * var_7["fraction"];
    var_8 = var_0.origin + var_4 * var_5;
    var_9 = var_8 + var_3 * var_6;
    var_10 = var_0.owner getenemytargets( var_0.owner );
    var_11 = magicbullet( var_2, var_8, var_9, var_0.owner );
    var_12 = 262144;

    foreach ( var_14 in var_10 )
    {
        if ( distance2dsquared( var_14.origin, var_9 ) < var_12 )
        {
            var_11 missile_settargetent( var_14 );
            break;
        }
    }

    var_11 setcandamage( 1 );
    var_11.team = var_0.team;
    var_11.owner = var_0.owner;
    var_11.entitynumber = var_11 getentitynumber();
    level.rockets[var_11.entitynumber] = var_11;
    level thread monitordeath( var_0 );
}

getnextmissilespawnindex( var_0 )
{
    var_1 = var_0 + 1;

    if ( var_1 == level.dronemissilespawnarray.size )
        var_1 = 0;

    return var_1;
}

monitorboost( var_0 )
{
    var_0 endon( "death" );

    for (;;)
    {
        var_0.owner waittill( "missileTargetSet" );
        var_0 notify( "missileTargetSet" );
    }
}

missileeyes( var_0, var_1, var_2 )
{
    var_3 = 1.0;
    var_0 maps\mp\_utility::freezecontrolswrapper( 1 );

    if ( var_2 >= 1 )
        var_0 thread delayedfofoverlay();

    var_0 cameralinkto( var_1, "tag_origin" );
    var_0 controlslinkto( var_1 );
    var_0 visionsetmissilecamforplayer( "default", var_3 );
    var_0 maps\mp\_utility::set_visionset_for_watching_players( "default", var_3, undefined, 1 );
    var_0 visionsetmissilecamforplayer( game["thermal_vision_trinity"], 0.0 );
    level thread unfreezecontrols( var_0, var_3 );
}

delayedfofoverlay()
{
    self endon( "death" );
    self endon( "disconnect" );
    level endon( "game_ended" );
    maps\mp\gametypes\_hostmigration::waitlongdurationwithhostmigrationpause( 0.25 );
    self thermalvisionfofoverlayon();
}

unfreezecontrols( var_0, var_1, var_2 )
{
    var_0 endon( "disconnect" );
    wait( var_1 - 0.35 );
    var_0 maps\mp\_utility::freezecontrolswrapper( 0 );
}

monitordisownkillstreaks( var_0, var_1 )
{
    var_0 endon( "end_kill_streak" );
    var_0 waittill( "killstreak_disowned" );
    level thread returnplayer( var_0, var_1 );
}

monitorgameend( var_0, var_1 )
{
    var_0 endon( "end_kill_streak" );
    level waittill( "game_ended" );
    level thread returnplayer( var_0, var_1 );
}

monitordeath( var_0 )
{
    var_0 waittill( "death" );
    level.rockets[var_0.entitynumber] = undefined;
    level.remotemissileinprogress = undefined;
}

returnplayer( var_0, var_1 )
{
    if ( !isdefined( var_0 ) )
        return;

    var_0 setclientomnvar( "ui_predator_missile", 2 );
    var_0 notify( "end_kill_streak" );
    var_0 maps\mp\_utility::freezecontrolswrapper( 1 );

    if ( var_1 >= 1 )
        var_0 thermalvisionfofoverlayoff();

    var_0 controlsunlink();
    var_0 setexitpredatorvisionset();
    wait 0.95;
    var_0 cameraunlink();
    var_0 setclientomnvar( "ui_predator_missile", 0 );
    var_0 maps\mp\_utility::clearusingremote();

    if ( isdefined( var_0.last_weapon ) )
        var_0 switchtoweapon( var_0.last_weapon );
}

setexitpredatorvisionset()
{
    var_0 = 0.5;
    self visionsetnakedforplayer( "", var_0 );
    self visionsetstage( 0, var_0 );
}
