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

init()
{
    level.killstreakfuncs["high_value_target"] = ::tryusehighvaluetarget;
    level.hvts_active["axis"] = 0;
    level.hvts_active["allies"] = 0;
    game["dialog"]["hvt_gone"] = "hvt_gone";
}

tryusehighvaluetarget( var_0, var_1 )
{
    return usehighvaluetarget( self, var_0 );
}

reached_max_xp_multiplier()
{
    if ( level.teambased )
        return level.hvts_active[self.team] >= 4;
    else if ( isdefined( self.hvts_active ) )
        return self.hvts_active >= 2;

    return 0;
}

usehighvaluetarget( var_0, var_1 )
{
    if ( !maps\mp\_utility::isreallyalive( var_0 ) )
        return 0;

    if ( var_0.team == "spectator" )
        return 0;

    if ( reached_max_xp_multiplier() || isdefined( var_0.hvts_active ) && var_0.hvts_active >= 2 )
    {
        self iprintlnbold( &"KILLSTREAKS_HVT_MAX" );
        return 0;
    }

    var_0 thread sethighvaluetarget();
    level thread maps\mp\_utility::teamplayercardsplash( "used_hvt", var_0, var_0.team );
    return 1;
}

sethighvaluetarget()
{
    level endon( "game_ended" );
    self endon( "disconnect" );
    var_0 = self.team;
    increasexpboost();
    thread watchhvtowner( var_0 );
    maps\mp\gametypes\_hostmigration::waitlongdurationwithhostmigrationpause( 10 );

    if ( level.teambased )
        maps\mp\_utility::leaderdialog( "hvt_gone", var_0 );
    else
        maps\mp\_utility::leaderdialogonplayer( "hvt_gone" );

    if ( level.teambased )
        level decreasexpboost( var_0 );
    else
        decreasexpboost();
}

increasexpboost()
{
    var_0 = 0;

    if ( level.teambased )
    {
        level.hvts_active[self.team]++;
        var_0 = level.hvts_active[self.team];
        var_1 = self.team;
    }
    else
    {
        if ( !isdefined( self.hvts_active ) )
            self.hvts_active = 1;
        else
            self.hvts_active++;

        var_0 = self.hvts_active;
        var_1 = self getentitynumber();
    }

    var_2 = 1 + var_0 * 0.5;
    level.teamxpscale[var_1] = clamp( var_2, 1, 4 );
}

decreasexpboost( var_0 )
{
    var_1 = 0;

    if ( level.teambased )
    {
        if ( level.hvts_active[var_0] > 0 )
            level.hvts_active[var_0]--;

        var_1 = level.hvts_active[var_0];
        var_2 = var_0;
    }
    else
    {
        if ( self.hvts_active > 0 )
            self.hvts_active--;

        var_1 = self.hvts_active;
        var_2 = self getentitynumber();
    }

    var_3 = 1 + var_1 * 0.5;
    level.teamxpscale[var_2] = clamp( var_3, 1, 4 );
}

watchhvtowner( var_0 )
{
    level endon( "game_ended" );
    var_1 = common_scripts\utility::waittill_any_return( "disconnect", "joined_team", "joined_spectators" );

    if ( level.teambased )
        level decreasexpboost( var_0 );
    else if ( isdefined( self ) && var_1 != "disconnect" )
        decreasexpboost();
}
