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

init()
{
    level.nukevisionset = "alien_nuke";
    level.nukevisionsetfailed = "alien_nuke_blast";

    if ( level.script == "mp_alien_last" )
        level._effect["nuke_flash"] = loadfx( "vfx/moments/alien/player_nuke_flash_alien_last" );
    else
        level._effect["nuke_flash"] = loadfx( "fx/explosions/player_death_nuke_flash_alien" );

    setdvarifuninitialized( "scr_nukeTimer", 10 );
    setdvarifuninitialized( "scr_nukeCancelMode", 0 );
    level.nuketimer = getdvarint( "scr_nukeTimer" );
    level.cancelmode = getdvarint( "scr_nukeCancelMode" );
    level.nukeinfo = spawnstruct();
    level.nukeinfo.xpscalar = 2;
    level.nukedetonated = undefined;
    level thread onplayerconnect();
}

delaythread_nuke( var_0, var_1 )
{
    level endon( "nuke_cancelled" );
    maps\mp\gametypes\_hostmigration::waitlongdurationwithhostmigrationpause( var_0 );
    thread [[ var_1 ]]();
}

donukesimple()
{
    level.nukeinfo.player = self;
    level.nukeinfo.team = self.pers["team"];
    level.nukeincoming = 1;
    level thread delaythread_nuke( level.nuketimer - 3.3, ::nukesoundincoming );
    level thread delaythread_nuke( level.nuketimer, ::nukesoundexplosion );
    level thread delaythread_nuke( level.nuketimer, ::nukeslowmo );
    level thread delaythread_nuke( level.nuketimer, ::nukeeffects );
    level thread delaythread_nuke( level.nuketimer + 0.25, ::nukevision );
    level thread delaythread_nuke( level.nuketimer + 1.5, ::nukedeath );

    if ( !isdefined( level.nuke_soundobject ) )
    {
        level.nuke_soundobject = spawn( "script_origin", ( 0, 0, 1 ) );
        level.nuke_soundobject hide();
    }
}

nukedeath()
{
    level notify( "nuke_death" );
}

nukesoundincoming()
{
    level endon( "nuke_cancelled" );

    if ( isdefined( level.nuke_soundobject ) )
        level.nuke_soundobject playsound( "nuke_incoming" );
}

nukesoundexplosion()
{
    level endon( "nuke_cancelled" );

    if ( isdefined( level.nuke_soundobject ) )
    {
        level.nuke_soundobject playsound( "nuke_explosion" );
        level.nuke_soundobject playsound( "nuke_wave" );
    }
}

nukeeffects()
{
    level endon( "nuke_cancelled" );
    level.nukedetonated = 1;

    foreach ( var_1 in level.players )
    {
        var_2 = anglestoforward( var_1.angles );
        var_2 = ( var_2[0], var_2[1], 0 );
        var_2 = vectornormalize( var_2 );
        var_3 = 5000;
        var_4 = var_1.origin + var_2 * var_3;

        if ( isdefined( level.nukeloc ) )
            var_4 = level.nukeloc;

        var_5 = ( 0, var_1.angles[1] + 180, 90 );

        if ( isdefined( level.nukeangles ) )
            var_5 = level.nukeangles;

        var_6 = spawn( "script_model", var_4 );
        var_6 setmodel( "tag_origin" );
        var_6.angles = var_5;
        var_6 thread nukeeffect( var_1 );
    }
}

nukeeffect( var_0 )
{
    level endon( "nuke_cancelled" );
    var_0 endon( "disconnect" );
    common_scripts\utility::waitframe();
    playfxontagforclients( level._effect["nuke_flash"], self, "tag_origin", var_0 );
}

nukeslowmo()
{
    level endon( "nuke_cancelled" );
    setslowmotion( 1.0, 0.25, 0.5 );
    level waittill( "nuke_death" );
    setslowmotion( 0.25, 1, 2.0 );
}

nukevision()
{
    level endon( "nuke_cancelled" );
    level.nukevisioninprogress = 1;
    var_0 = 0.75;

    foreach ( var_2 in level.players )
    {
        if ( isdefined( var_2.sessionstate ) && var_2.sessionstate == "spectator" )
        {
            var_3 = var_2 getspectatingplayer();

            if ( isdefined( var_3 ) )
            {
                if ( isdefined( var_3.nuke_escaped ) && var_3.nuke_escaped )
                    var_2 set_vision_for_nuke_escaped( var_0 );
                else
                    var_2 set_vision_for_nuke_failed( var_0 );
            }
            else
                var_2 set_vision_for_nuke_failed( var_0 );

            continue;
        }

        if ( isdefined( var_2.nuke_escaped ) && var_2.nuke_escaped )
        {
            var_2 set_vision_for_nuke_escaped( var_0 );
            continue;
        }

        var_2 set_vision_for_nuke_failed( var_0 );
    }

    fog_nuke( var_0 );
}

set_vision_for_nuke_escaped( var_0 )
{
    self visionsetnakedforplayer( level.nukevisionset, var_0 );
    self visionsetpainforplayer( level.nukevisionset );
}

set_vision_for_nuke_failed( var_0 )
{
    playfxontagforclients( level._effect["vfx/moments/alien/nuke_fail_screen_flash"], self, "tag_eye", self );
    self visionsetnakedforplayer( level.nukevisionsetfailed, var_0 );
    self visionsetpainforplayer( level.nukevisionsetfailed );
}

fog_nuke( var_0 )
{
    if ( !isdefined( level.nuke_fog_setting ) )
        return;

    var_1 = level.nuke_fog_setting;
    setexpfog( var_1.startdist, var_1.halfwaydist, var_1.red, var_1.green, var_1.blue, var_1.hdrcolorintensity, var_1.maxopacity, var_0, var_1.sunred, var_1.sungreen, var_1.sunblue, var_1.hdrsuncolorintensity, var_1.sundir, var_1.sunbeginfadeangle, var_1.sunendfadeangle, var_1.normalfogscale, var_1.skyfogintensity, var_1.skyfogminangle, var_1.skyfogmaxangle );
}

restore_fog( var_0 )
{
    if ( !isdefined( level.restore_fog_setting ) )
        return;

    var_1 = level.restore_fog_setting;
    setexpfog( var_1.startdist, var_1.halfwaydist, var_1.red, var_1.green, var_1.blue, var_1.hdrcolorintensity, var_1.maxopacity, var_0, var_1.sunred, var_1.sungreen, var_1.sunblue, var_1.hdrsuncolorintensity, var_1.sundir, var_1.sunbeginfadeangle, var_1.sunendfadeangle, var_1.normalfogscale, var_1.skyfogintensity, var_1.skyfogminangle, var_1.skyfogmaxangle );
}

nukeearthquake()
{
    level endon( "nuke_cancelled" );
    level waittill( "nuke_death" );
}

onplayerconnect()
{
    for (;;)
    {
        level waittill( "connected", var_0 );
        var_0 thread onplayerspawned();
    }
}

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

    for (;;)
    {
        self waittill( "spawned_player" );

        if ( isdefined( level.nukedetonated ) )
            self visionsetnakedforplayer( level.nukevisionset, 0 );
    }
}
