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

init()
{
    level.uplinks = [];
    level.killstreakfuncs["uplink"] = ::tryuseuplink;
    level.killstreakfuncs["uplink_support"] = ::tryuseuplink;
    level.comexpfuncs = [];
    level.comexpfuncs["giveComExpBenefits"] = ::givecomexpbenefits;
    level.comexpfuncs["removeComExpBenefits"] = ::removecomexpbenefits;
    level.comexpfuncs["getRadarStrengthForTeam"] = ::getradarstrengthforteam;
    level.comexpfuncs["getRadarStrengthForPlayer"] = ::getradarstrengthforplayer;
    unblockteamradar( "axis" );
    unblockteamradar( "allies" );
    level thread uplinktracker();
    level thread uplinkupdateeyeson();
    var_0 = spawnstruct();
    var_0.streakname = "uplink";
    var_0.weaponinfo = "ims_projectile_mp";
    var_0.modelbase = "mp_satcom";
    var_0.modelplacement = "mp_satcom_obj";
    var_0.modelplacementfailed = "mp_satcom_obj_red";
    var_0.modelbombsquad = "mp_satcom_bombsquad";
    var_0.hintstring = &"KILLSTREAKS_HINTS_UPLINK_PICKUP";
    var_0.placestring = &"KILLSTREAKS_HINTS_UPLINK_PLACE";
    var_0.cannotplacestring = &"KILLSTREAKS_HINTS_UPLINK_CANNOT_PLACE";
    var_0.headiconheight = 42;
    var_0.splashname = "used_uplink";
    var_0.lifespan = 30;
    var_0.maxhealth = 500;
    var_0.allowmeleedamage = 1;
    var_0.allowempdamage = 1;
    var_0.damagefeedback = "trophy";
    var_0.xppopup = "destroyed_uplink";
    var_0.destroyedvo = "satcom_destroyed";
    var_0.placementheighttolerance = 30.0;
    var_0.placementradius = 16.0;
    var_0.placementoffsetz = 16;
    var_0.onplaceddelegate = ::onplaced;
    var_0.oncarrieddelegate = ::oncarried;
    var_0.placedsfx = "mp_killstreak_satcom_deploy";
    var_0.activesfx = "mp_killstreak_satcom_loop";
    var_0.onmovingplatformcollision = ::uplink_override_moving_platform_death;
    var_0.ondeathdelegate = ::ondeath;
    var_0.ondestroyeddelegate = ::ondestroyed;
    var_0.deathvfx = loadfx( "vfx/gameplay/mp/killstreaks/vfx_ballistic_vest_death" );
    level.placeableconfigs["uplink"] = var_0;
    level.placeableconfigs["uplink_support"] = var_0;
}

uplinktracker()
{
    level endon( "game_ended" );

    for (;;)
    {
        level waittill( "update_uplink" );
        level childthread updatealluplinkthreads();
    }
}

updatealluplinkthreads()
{
    self notify( "updateAllUplinkThreads" );
    self endon( "updateAllUplinkThreads" );
    level childthread comexpnotifywatcher();

    if ( level.teambased )
    {
        level childthread updateteamuplink( "axis" );
        level childthread updateteamuplink( "allies" );
    }
    else
        level childthread updateplayeruplink();

    level childthread updatecomexpuplink();
}

comexpnotifywatcher()
{
    var_0 = [];

    if ( !level.teambased )
        level waittill( "radar_status_change_players" );
    else
    {
        while ( var_0.size < 2 )
        {
            level waittill( "radar_status_change", var_1 );
            var_0[var_0.size] = var_1;
        }
    }

    level notify( "start_com_exp" );
}

updateteamuplink( var_0 )
{
    var_1 = getradarstrengthforteam( var_0 );
    var_2 = var_1 == 1;
    var_3 = var_1 >= 2;
    var_4 = var_1 >= 3;
    var_5 = var_1 >= 4;

    if ( var_3 )
        unblockteamradar( var_0 );

    if ( var_4 )
        level.radarmode[var_0] = "fast_radar";
    else
        level.radarmode[var_0] = "normal_radar";

    foreach ( var_7 in level.participants )
    {
        if ( !isdefined( var_7 ) )
            continue;

        if ( var_7.team != var_0 )
            continue;

        var_7.shouldbeeyeson = var_2;
        var_7 seteyesonuplinkenabled( var_2 );
        var_7.radarmode = level.radarmode[var_7.team];
        var_7.radarshowenemydirection = var_5;
        var_7 updatesatcomactiveomnvar( var_0 );
        wait 0.05;
    }

    setteamradar( var_0, var_3 );
    level notify( "radar_status_change", var_0 );
}

updateplayeruplink()
{
    foreach ( var_1 in level.participants )
    {
        if ( !isdefined( var_1 ) )
            continue;

        var_2 = getradarstrengthforplayer( var_1 );
        setplayerradareffect( var_1, var_2 );
        var_1 updatesatcomactiveomnvar();
        wait 0.05;
    }

    level notify( "radar_status_change_players" );
}

updatecomexpuplink()
{
    level waittill( "start_com_exp" );

    foreach ( var_1 in level.participants )
    {
        if ( !isdefined( var_1 ) )
            continue;

        var_1 givecomexpbenefits();
        wait 0.05;
    }
}

givecomexpbenefits()
{
    if ( maps\mp\_utility::_hasperk( "specialty_comexp" ) )
    {
        var_0 = getradarstrengthforcomexp( self );
        setplayerradareffect( self, var_0 );
        updatesatcomactiveomnvar();
    }
}

updatesatcomactiveomnvar( var_0 )
{
    var_1 = 0;

    if ( isdefined( var_0 ) )
        var_1 = getradarstrengthforteam( var_0 );
    else
        var_1 = getradarstrengthforplayer( self );

    if ( maps\mp\_utility::_hasperk( "specialty_comexp" ) )
        var_1 = getradarstrengthforcomexp( self );

    if ( var_1 > 0 )
        self setclientomnvar( "ui_satcom_active", 1 );
    else
        self setclientomnvar( "ui_satcom_active", 0 );
}

removecomexpbenefits()
{
    self.shouldbeeyeson = 0;
    self seteyesonuplinkenabled( 0 );
    self.radarshowenemydirection = 0;
    self.radarmode = "normal_radar";
    self.hasradar = 0;
    self.isradarblocked = 0;
}

setplayerradareffect( var_0, var_1 )
{
    var_2 = var_1 == 1;
    var_3 = var_1 >= 2;
    var_4 = var_1 >= 3;
    var_5 = var_1 >= 4;
    var_0.shouldbeeyeson = var_2;
    var_0 seteyesonuplinkenabled( var_2 );
    var_0.radarshowenemydirection = var_5;
    var_0.radarmode = "normal_radar";
    var_0.hasradar = var_3;
    var_0.isradarblocked = 0;

    if ( var_4 )
        var_0.radarmode = "fast_radar";
}

tryuseuplink( var_0, var_1 )
{
    var_2 = maps\mp\killstreaks\_placeable::giveplaceable( var_1 );

    if ( var_2 )
        maps\mp\_matchdata::logkillstreakevent( "uplink", self.origin );

    self.iscarrying = undefined;
    return var_2;
}

oncarried( var_0 )
{
    var_1 = self getentitynumber();

    if ( isdefined( level.uplinks[var_1] ) )
        stopuplink();
}

onplaced( var_0 )
{
    var_1 = level.placeableconfigs[var_0];
    self.owner notify( "uplink_deployed" );
    self setmodel( var_1.modelbase );
    self.immediatedeath = 0;
    self setotherent( self.owner );
    common_scripts\utility::make_entity_sentient_mp( self.owner.team, 1 );
    self.config = var_1;
    startuplink( 1 );
    thread watchempdamage();
}

startuplink( var_0 )
{
    adduplinktolevellist( self );
    thread playuplinkanimations( var_0 );
    self playloopsound( self.config.activesfx );
}

stopuplink()
{
    maps\mp\gametypes\_weapons::stopblinkinglight();
    self scriptmodelclearanim();

    if ( isdefined( self.bombsquadmodel ) )
        self.bombsquadmodel scriptmodelclearanim();

    removeuplinkfromlevellist( self );
    self stoploopsound();
}

#using_animtree("animated_props");

playuplinkanimations( var_0 )
{
    self endon( "emp_damage" );
    self endon( "death" );
    self endon( "carried" );

    if ( var_0 )
    {
        var_1 = getnotetracktimes( %satcom_killstreak, "stop anim" );
        var_2 = getanimlength( %satcom_killstreak );
        self scriptmodelplayanim( "Satcom_killStreak" );

        if ( isdefined( self.bombsquadmodel ) )
            self.bombsquadmodel scriptmodelplayanim( "Satcom_killStreak" );

        wait( var_1[0] * var_2 );
    }

    self scriptmodelplayanim( "Satcom_killStreak_idle" );

    if ( isdefined( self.bombsquadmodel ) )
        self.bombsquadmodel scriptmodelplayanim( "Satcom_killStreak_idle" );

    thread maps\mp\gametypes\_weapons::doblinkinglight( "tag_fx" );
}

ondestroyed( var_0, var_1, var_2, var_3 )
{
    var_1 notify( "destroyed_equipment" );
}

ondeath( var_0, var_1, var_2, var_3 )
{
    maps\mp\gametypes\_weapons::stopblinkinglight();
    maps\mp\gametypes\_weapons::equipmentdeathvfx();
    removeuplinkfromlevellist( self );
    self scriptmodelclearanim();

    if ( !self.immediatedeath )
        wait 3.0;

    maps\mp\gametypes\_weapons::equipmentdeletevfx();
}

adduplinktolevellist( var_0 )
{
    var_1 = var_0 getentitynumber();
    level.uplinks[var_1] = var_0;
    level notify( "update_uplink" );
}

removeuplinkfromlevellist( var_0 )
{
    var_1 = var_0 getentitynumber();
    level.uplinks[var_1] = undefined;
    level notify( "update_uplink" );
}

getradarstrengthforteam( var_0 )
{
    var_1 = 0;

    foreach ( var_3 in level.uplinks )
    {
        if ( isdefined( var_3 ) && var_3.team == var_0 )
            var_1++;
    }

    if ( var_1 == 0 && isdefined( level.helisnipereyeson ) && level.helisnipereyeson.team == var_0 )
        var_1++;

    return clamp( var_1, 0, 4 );
}

getradarstrengthforplayer( var_0 )
{
    var_1 = 0;

    foreach ( var_3 in level.uplinks )
    {
        if ( isdefined( var_3 ) )
        {
            if ( isdefined( var_3.owner ) )
            {
                if ( var_3.owner.guid == var_0.guid )
                    var_1++;

                continue;
            }

            var_4 = var_3 getentitynumber();
            level.uplinks[var_4] = undefined;
        }
    }

    if ( !level.teambased && var_1 > 0 )
        var_1++;

    return clamp( var_1, 0, 4 );
}

getradarstrengthforcomexp( var_0 )
{
    var_1 = 0;

    foreach ( var_3 in level.uplinks )
    {
        if ( isdefined( var_3 ) )
            var_1++;
    }

    if ( !level.teambased && var_1 > 0 )
        var_1++;

    return clamp( var_1, 0, 4 );
}

uplink_override_moving_platform_death( var_0 )
{
    self.immediatedeath = 1;
    self notify( "death" );
}

watchempdamage()
{
    self endon( "death" );
    level endon( "game_ended" );

    for (;;)
    {
        self waittill( "emp_damage", var_0, var_1 );
        maps\mp\gametypes\_weapons::equipmentempstunvfx();
        stopuplink();
        wait( var_1 );
        startuplink( 0 );
    }
}

uplinkupdateeyeson()
{
    level endon( "game_ended" );

    for (;;)
    {
        level waittill( "player_spawned", var_0 );
        var_1 = isdefined( var_0.shouldbeeyeson ) && var_0.shouldbeeyeson;
        var_0 seteyesonuplinkenabled( var_1 );
    }
}
