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

init()
{
    level.teamemped["allies"] = 0;
    level.teamemped["axis"] = 0;
    level.empplayer = undefined;
    level.emptimeout = 10.0;
    level.emptimeremaining = int( level.emptimeout );
    level.killstreakfuncs["jammer"] = ::emp_use;
    level thread onplayerconnect();
}

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

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

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

        if ( maps\mp\killstreaks\_emp_common::shouldplayerbeaffectedbyemp() )
            maps\mp\killstreaks\_emp_common::applyperplayerempeffects();
    }
}

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

    for (;;)
    {
        self waittill( "death" );
        maps\mp\killstreaks\_emp_common::stopempjamsequenceimmediate();
    }
}

emp_use( var_0, var_1 )
{
    var_2 = self.pers["team"];

    if ( level.teambased )
    {
        var_3 = level.otherteam[var_2];
        thread emp_jamteam( var_3 );
    }
    else
        thread emp_jamplayers( self );

    maps\mp\_matchdata::logkillstreakevent( "jammer", self.origin );
    self notify( "used_emp" );
    level notify( "emp_used" );
    return 1;
}

emp_jamteam( var_0 )
{
    level endon( "game_ended" );
    wait 0.5;
    thread maps\mp\_utility::teamplayercardsplash( "used_jammer", self );
    level notify( "EMP_JamTeam" + var_0 );
    level endon( "EMP_JamTeam" + var_0 );
    level.teamemped[var_0] = 1;

    foreach ( var_2 in level.players )
    {
        var_2 maps\mp\killstreaks\_emp_common::applyperplayerempeffects_ondetonate();

        if ( var_2 maps\mp\killstreaks\_emp_common::shouldplayerbeaffectedbyemp() )
            var_2 maps\mp\killstreaks\_emp_common::applyperplayerempeffects();
    }

    level thread maps\mp\killstreaks\_emp_common::applyglobalempeffects();
    level notify( "emp_update" );
    level destroygroundobjects( self, var_0 );
    level thread keepemptimeremaining();
    maps\mp\gametypes\_hostmigration::waitlongdurationwithhostmigrationpause( level.emptimeout );
    level.teamemped[var_0] = 0;

    foreach ( var_2 in level.players )
    {
        if ( var_2.team == var_0 && !var_2 maps\mp\killstreaks\_emp_common::shouldplayerbeaffectedbyemp() )
            var_2 maps\mp\killstreaks\_emp_common::removeperplayerempeffects();
    }

    level notify( "emp_update" );
}

emp_jamplayers( var_0 )
{
    level notify( "EMP_JamPlayers" );
    level endon( "EMP_JamPlayers" );
    wait 0.5;

    if ( !isdefined( var_0 ) )
        return;

    level.empplayer = var_0;

    foreach ( var_2 in level.players )
    {
        var_2 maps\mp\killstreaks\_emp_common::applyperplayerempeffects_ondetonate();

        if ( var_2 maps\mp\killstreaks\_emp_common::shouldplayerbeaffectedbyemp() )
            var_2 maps\mp\killstreaks\_emp_common::applyperplayerempeffects();
    }

    level thread maps\mp\killstreaks\_emp_common::applyglobalempeffects();
    level notify( "emp_update" );
    level.empplayer thread empplayerffadisconnect();
    level destroygroundobjects( var_0 );
    level thread keepemptimeremaining();
    maps\mp\gametypes\_hostmigration::waitlongdurationwithhostmigrationpause( level.emptimeout );
    level.empplayer = undefined;

    foreach ( var_2 in level.players )
    {
        if ( ( !isdefined( var_0 ) || var_2 != var_0 ) && !var_2 maps\mp\killstreaks\_emp_common::shouldplayerbeaffectedbyemp() )
            var_2 maps\mp\killstreaks\_emp_common::removeperplayerempeffects();
    }

    level notify( "emp_update" );
    level notify( "emp_ended" );
}

keepemptimeremaining()
{
    level notify( "keepEMPTimeRemaining" );
    level endon( "keepEMPTimeRemaining" );
    level endon( "emp_ended" );

    for ( level.emptimeremaining = int( level.emptimeout ); level.emptimeremaining; level.emptimeremaining-- )
        wait 1.0;
}

empplayerffadisconnect()
{
    level endon( "EMP_JamPlayers" );
    level endon( "emp_ended" );
    self waittill( "disconnect" );
    level notify( "emp_update" );
}

destroygroundobjects( var_0, var_1 )
{
    maps\mp\killstreaks\_killstreaks::destroytargetarray( var_0, var_1, "killstreak_emp_mp", level.turrets );
    maps\mp\killstreaks\_killstreaks::destroytargetarray( var_0, var_1, "killstreak_emp_mp", level.placedims );
    maps\mp\killstreaks\_killstreaks::destroytargetarray( var_0, var_1, "killstreak_emp_mp", level.balldrones );
    thread maps\mp\killstreaks\_killstreaks::destroytargetarray( var_0, var_1, "killstreak_emp_mp", level.uplinks );
    maps\mp\killstreaks\_killstreaks::destroytargetarray( var_0, var_1, "killstreak_emp_mp", level.mines );
}
