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

init_challenge_type()
{
    level.challenge_data = [];

    if ( !isdefined( level.challenge_scalar_func ) )
        level.challenge_scalar_func = ::default_challenge_scalar_func;

    if ( isdefined( level.challenge_registration_func ) )
        [[ level.challenge_registration_func ]]();

    if ( maps\mp\alien\_utility::is_true( level.include_default_challenges ) )
    {
        register_challenge( "spend_10k", 10000, 0, undefined, undefined, ::activate_spend_currency, ::deactivate_spend_currency, undefined, ::update_spend_currency );
        register_challenge( "spend_20k", 20000, 0, undefined, undefined, ::activate_spend_currency, ::deactivate_spend_currency, undefined, ::update_spend_currency );
        register_challenge( "kill_leper", 30, 0, undefined, undefined, ::activate_kill_leper, ::deactivate_kill_leper, undefined, ::update_kill_leper );
        register_challenge( "spend_no_money", 120, 1, undefined, undefined, ::activate_spend_no_money, ::default_resetsuccess, undefined, ::update_spend_no_money );
        register_challenge( "no_reloads", 60, 1, undefined, undefined, ::activate_no_reloads, ::default_resetsuccess, undefined, ::update_no_reloads );
        register_challenge( "no_abilities", 90, 1, undefined, undefined, ::activate_no_abilities, ::default_resetsuccess, undefined, ::update_no_abilities );
        register_challenge( "take_no_damage", undefined, 1, undefined, undefined, ::default_resetsuccess, ::default_resetsuccess, undefined, ::update_take_no_damage );
        register_challenge( "melee_5_goons", 5, 0, undefined, undefined, ::activate_melee_goons, ::deactivate_melee_goons, undefined, ::update_melee_goons );
        register_challenge( "melee_spitter", 1, 0, undefined, undefined, ::activate_melee_spitter, ::deactivate_melee_spitter, undefined, ::update_melee_spitter );
        register_challenge( "no_stuck_drill", undefined, 1, undefined, undefined, ::default_resetsuccess, ::default_resetsuccess, undefined, ::update_no_stuck_drill );
        register_challenge( "kill_10_with_propane", 10, 0, undefined, undefined, ::activate_kill_10_with_propane, ::deactivate_kill_10_with_propane, undefined, ::update_kill_10_with_propane );
        register_challenge( "stay_prone", 10, 0, undefined, undefined, ::activate_stay_prone, ::deactivate_stay_prone, undefined, ::update_stay_prone );
        register_challenge( "kill_10_with_traps", 10, 0, undefined, undefined, ::activate_kill_10_with_traps, ::deactivate_kill_10_with_traps, undefined, ::update_kill_10_with_traps );
        register_challenge( "avoid_minion_explosion", undefined, 1, undefined, undefined, ::activate_avoid_minion_exp, ::deactivate_avoid_minion_exp, undefined, ::update_avoid_minion_exp );
        register_challenge( "75_percent_accuracy", undefined, 1, ::seventyfive_percent_accuracy_success_test, undefined, ::activate_percent_accuracy, ::deactivate_percent_accuracy, undefined, ::update_75_percent_accuracy );
        register_challenge( "pistols_only", 10, 0, undefined, undefined, ::activate_use_weapon_challenge, ::default_resetsuccess, undefined, ::update_pistols_only );
        register_challenge( "shotguns_only", 10, 0, undefined, undefined, ::activate_use_weapon_challenge, ::deactivate_weapon_challenge_waypoints, undefined, ::update_shotguns_only );
        register_challenge( "snipers_only", 10, 0, undefined, undefined, ::activate_use_weapon_challenge, ::deactivate_weapon_challenge_waypoints, undefined, ::update_snipers_only );
        register_challenge( "lmgs_only", 10, 0, undefined, undefined, ::activate_use_weapon_challenge, ::deactivate_weapon_challenge_waypoints, undefined, ::update_lmgs_only );
        register_challenge( "ar_only", 10, 0, undefined, undefined, ::activate_use_weapon_challenge, ::deactivate_weapon_challenge_waypoints, undefined, ::update_ar_only );
        register_challenge( "smg_only", 10, 0, undefined, undefined, ::activate_use_weapon_challenge, ::deactivate_weapon_challenge_waypoints, undefined, ::update_smgs_only );
        register_challenge( "kill_10_with_turrets", 10, 0, undefined, undefined, ::activate_kill_10_with_turrets, ::deactivate_kill_10_with_turrets, undefined, ::update_kill_10_with_turrets );
        register_challenge( "kill_airborne_aliens", 5, 0, undefined, undefined, ::activate_kill_airborne_aliens, ::deactivate_kill_airborne_aliens, undefined, ::update_kill_airborne_aliens );
        register_challenge( "melee_only", undefined, 1, undefined, undefined, ::activate_melee_only, ::deactivate_melee_only, undefined, ::update_melee_only );
        register_challenge( "50_percent_accuracy", undefined, 1, ::fifty_percent_accuracy_success_test, undefined, ::activate_percent_accuracy, ::deactivate_percent_accuracy, undefined, ::update_50_percent_accuracy );
        register_challenge( "stay_within_area", 10, 0, undefined, ::pre_activate_stay_within_area, ::activate_stay_within_area, ::deactivate_stay_within_area, undefined, ::update_stay_within_area );
        register_challenge( "kill_10_in_30", 10, 0, undefined, undefined, ::activate_kill_10_in_30, ::default_resetsuccess, undefined, ::update_kill_10_in_30 );
        register_challenge( "protect_player", undefined, 1, undefined, undefined, ::activate_protect_a_player, ::deactivate_protect_a_player, undefined, ::update_protect_a_player );
        register_challenge( "no_laststand", undefined, 1, undefined, undefined, ::default_resetsuccess, ::default_resetsuccess, undefined, ::update_no_laststand );
        register_challenge( "no_bleedout", undefined, 1, undefined, undefined, ::default_resetsuccess, ::default_resetsuccess, undefined, ::update_no_bleedout );
        register_challenge( "challenge_failed", undefined, 0, undefined, undefined, ::default_resetsuccess, ::default_resetsuccess, undefined, undefined );
        register_challenge( "challenge_success", undefined, 0, undefined, undefined, ::default_resetsuccess, ::default_resetsuccess, undefined, undefined );
        register_challenge( "barrier_hive", undefined, 0, undefined, undefined, ::default_resetsuccess, ::default_resetsuccess, undefined, undefined );
    }

    init_alien_challenges_from_table();
    level.current_challenge_index = -1;
    level.current_challenge_progress_max = -1;
    level.current_challenge_progress_current = -1;
    level.current_challenge_percent = -1;
    level.current_challenge_target_player = -1;
    level.current_challenge_timer = -1;
    level.current_challenge_scalar = -1;
    level.current_challenge_title = -1;
    level.current_challenge_pre_challenge = 0;
    level.all_challenge_completed = 1;
    level.pre_challenge_active = 0;
    level.num_challenge_completed = 0;
}

register_challenge( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8, var_9, var_10 )
{
    var_11 = spawnstruct();
    var_11.ref = var_0;
    var_11.goal = var_1;
    var_11.default_success = var_2;
    var_11.issuccessfunc = ::default_issuccessfunc;

    if ( isdefined( var_3 ) )
        var_11.issuccessfunc = var_3;

    var_11.canactivatefunc = ::default_canactivatefunc;

    if ( isdefined( var_4 ) )
        var_11.canactivatefunc = var_4;

    var_11.activatefunc = var_5;
    var_11.deactivatefunc = var_6;
    var_11.failactivatefunc = ::default_failactivatefunc;

    if ( isdefined( var_7 ) )
        var_11.failactivatefunc = var_7;

    var_11.updatefunc = var_8;
    var_11.rewardfunc = ::default_rewardfunc;

    if ( isdefined( var_9 ) )
        var_11.rewardfunc = var_9;

    var_11.failfunc = ::default_failfunc;

    if ( isdefined( var_10 ) )
        var_11.failfunc = var_10;

    level.challenge_data[var_0] = var_11;
}

init_alien_challenges_from_table()
{
    var_0 = level.alien_challenge_table;
    var_1 = 0;
    var_2 = 1;
    var_3 = 99;
    var_4 = 1;
    var_5 = 2;
    var_6 = 6;
    var_7 = 7;
    var_8 = 8;

    for ( var_9 = var_2; var_9 <= var_3; var_9++ )
    {
        var_10 = tablelookup( var_0, var_1, var_9, var_4 );

        if ( var_10 == "" )
            break;

        var_11 = tablelookup( var_0, var_1, var_9, var_5 );
        var_12 = tablelookup( var_0, var_1, var_9, var_8 );
        level.challenge_data[var_10].allowed_cycles = var_11;
        level.challenge_data[var_10].allowedinsolo = int( tablelookup( var_0, var_1, var_9, var_6 ) );
        level.challenge_data[var_10].allowed_hives = var_12;
    }
}

default_canactivatefunc()
{
    return 1;
}

default_failactivatefunc()
{

}

default_issuccessfunc()
{
    return self.success;
}

default_failfunc()
{

}

default_resetsuccess()
{
    self.success = self.default_success;
}

default_rewardfunc()
{
    var_0 = 1;

    foreach ( var_2 in level.players )
        var_2 maps\mp\alien\_persistence::give_player_points( var_0 );
}

activate_spend_currency()
{
    activate_spend_money_progress();
}

deactivate_spend_currency()
{
    reset_spend_money_progress();
}

reset_spend_money_progress()
{
    default_resetsuccess();
    self.current_progress = 0;
}

activate_spend_money_progress()
{
    default_resetsuccess();
    self.current_progress = 0;
    self.goal = self.goal * 1000;
    update_challenge_progress( 0, self.goal );
}

update_spend_currency( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.current_progress = self.current_progress + var_0;

    if ( self.current_progress >= self.goal )
        self.success = 1;

    update_challenge_progress( self.current_progress, self.goal );

    if ( self.success )
        maps\mp\alien\_challenge::deactivate_current_challenge();
}

activate_kill_leper()
{
    default_resetsuccess();

    if ( !isdefined( level.current_cycle ) )
        level waittill( "alien_cycle_started" );

    self.leper = maps\mp\alien\_spawn_director::spawn_alien( "leper" );
    self.leper thread leper_watch_death();
    self.leper thread maps\mp\agents\alien\_alien_leper::leper_challenge_despawn( self.goal );
    var_0 = int( gettime() + 30000 );

    foreach ( var_2 in level.players )
        var_2 setclientomnvar( "ui_intel_timer", var_0 );

    level.current_challenge_timer = 30;
    level thread update_current_challenge_timer();
}

deactivate_kill_leper()
{
    default_resetsuccess();

    if ( isalive( self.leper ) )
    {
        self.leper thread maps\mp\agents\alien\_alien_leper::leper_despawn();
        self.leper = undefined;
    }
}

leper_watch_death()
{
    self waittill( "death", var_0, var_1, var_2 );

    if ( isdefined( var_0 ) && ( isplayer( var_0 ) || isdefined( var_0.classname ) && var_0.classname == "misc_turret" && isdefined( var_0.owner ) && var_0.owner isusingturret() ) )
        maps\mp\alien\_challenge::update_challenge( "kill_leper", "success" );
    else
        maps\mp\alien\_challenge::update_challenge( "kill_leper", "fail" );

    level notify( "stop_challenge_timer" );
    level.current_challenge_timer = -1;
}

update_kill_leper( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    if ( var_0 == "success" )
        self.success = 1;

    maps\mp\alien\_challenge::deactivate_current_challenge();
}

activate_spend_no_money()
{
    default_resetsuccess();
    var_0 = int( gettime() + self.goal * 1000 );

    foreach ( var_2 in level.players )
        var_2 setclientomnvar( "ui_intel_timer", var_0 );

    level.current_challenge_timer = self.goal;
    level thread update_current_challenge_timer();
    level thread spend_no_money_timer( self );
}

spend_no_money_timer( var_0 )
{
    level endon( "game_ended" );
    var_0 endon( "fail" );
    wait( var_0.goal );
    var_0.success = 1;
    level notify( "stop_challenge_timer" );
    maps\mp\alien\_challenge::deactivate_current_challenge();
}

update_spend_no_money( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.success = 0;
    self notify( "fail" );
    level notify( "stop_challenge_timer" );
    maps\mp\alien\_challenge::deactivate_current_challenge();
}

activate_no_reloads()
{
    default_resetsuccess();
    var_0 = int( gettime() + self.goal * 1000 );
    level.current_challenge_timer = self.goal;
    level thread update_current_challenge_timer();
    level thread no_reload_timer( self );

    foreach ( var_2 in level.players )
    {
        var_2 setclientomnvar( "ui_intel_timer", var_0 );
        var_2 thread wait_for_reload();
    }
}

no_reload_timer( var_0 )
{
    level endon( "stop_watching_reload" );
    wait( var_0.goal );
    var_0.success = 1;
    maps\mp\alien\_challenge::deactivate_current_challenge();
    level notify( "stop_challenge_timer" );
    level notify( "stop_watching_reload" );
}

wait_for_reload()
{
    level endon( "stop_watching_reload" );
    self waittill( "reload" );
    maps\mp\alien\_challenge::update_challenge( "no_reloads" );
    level notify( "stop_watching_reload" );
}

update_no_reloads( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.success = 0;
    maps\mp\alien\_challenge::deactivate_current_challenge();
    level notify( "stop_challenge_timer" );
}

activate_no_abilities()
{
    default_resetsuccess();
    var_0 = int( gettime() + self.goal * 1000 );
    level.current_challenge_timer = self.goal;
    level thread update_current_challenge_timer();
    level thread no_abilities_timer( self );

    foreach ( var_2 in level.players )
    {
        var_2 setclientomnvar( "ui_intel_timer", var_0 );
        var_2 thread wait_for_ability_use();
    }
}

no_abilities_timer( var_0 )
{
    level endon( "stop_watching_ability_use" );
    wait( var_0.goal );
    var_0.success = 1;
    maps\mp\alien\_challenge::deactivate_current_challenge();
    level notify( "stop_challenge_timer" );
    level notify( "stop_watching_ability_use" );
}

wait_for_ability_use()
{
    level endon( "stop_watching_ability_use" );
    common_scripts\utility::waittill_any( "action_finish_used", "class_skill_used" );
    maps\mp\alien\_challenge::update_challenge( "no_abilities" );
    level notify( "stop_watching_ability_use" );
}

update_no_abilities( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.success = 0;
    maps\mp\alien\_challenge::deactivate_current_challenge();
    level notify( "stop_challenge_timer" );
}

update_take_no_damage( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.success = 0;
    maps\mp\alien\_challenge::deactivate_current_challenge();
}

nodamage_rewardfunc()
{
    var_0 = 250;

    foreach ( var_2 in level.players )
        var_2 thread maps\mp\alien\_persistence::give_player_currency( var_0 );
}

activate_melee_goons()
{
    reset_melee_goons_progress();
    update_challenge_progress( 0, self.goal );
}

deactivate_melee_goons()
{
    reset_melee_goons_progress();
}

reset_melee_goons_progress()
{
    default_resetsuccess();
    self.current_progress = 0;
}

update_melee_goons( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.current_progress = self.current_progress + var_0;

    if ( self.current_progress >= self.goal )
        self.success = 1;

    var_9 = self.goal - self.current_progress;
    update_challenge_progress( self.current_progress, self.goal );

    if ( self.success )
        maps\mp\alien\_challenge::deactivate_current_challenge();
}

activate_melee_spitter()
{
    reset_melee_spitter_progress();
}

deactivate_melee_spitter()
{
    reset_melee_spitter_progress();
}

reset_melee_spitter_progress()
{
    default_resetsuccess();
    self.current_progress = 0;
}

update_melee_spitter( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.current_progress = self.current_progress + var_0;

    if ( self.current_progress >= self.goal )
        self.success = 1;

    if ( self.success )
        maps\mp\alien\_challenge::deactivate_current_challenge();
}

update_no_stuck_drill( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.success = 0;
    maps\mp\alien\_challenge::deactivate_current_challenge();
}

update_no_laststand( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.success = 0;
    maps\mp\alien\_challenge::deactivate_current_challenge();
}

update_no_bleedout( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.success = 0;
    maps\mp\alien\_challenge::deactivate_current_challenge();
}

activate_kill_10_with_propane()
{
    reset_kill_10_with_propane_progress();
    update_challenge_progress( 0, self.goal );
}

deactivate_kill_10_with_propane()
{
    reset_kill_10_with_propane_progress();
}

reset_kill_10_with_propane_progress()
{
    default_resetsuccess();
    self.current_progress = 0;
}

update_kill_10_with_propane( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.current_progress = self.current_progress + var_0;

    if ( self.current_progress >= self.goal )
        self.success = 1;

    var_9 = self.goal - self.current_progress;
    update_challenge_progress( self.current_progress, self.goal );

    if ( self.success )
        maps\mp\alien\_challenge::deactivate_current_challenge();
}

activate_kill_10_with_traps()
{
    reset_kill_10_with_traps_progress();
    update_challenge_progress( 0, self.goal );
}

deactivate_kill_10_with_traps()
{
    reset_kill_10_with_traps_progress();
}

reset_kill_10_with_traps_progress()
{
    default_resetsuccess();
    self.current_progress = 0;
}

update_kill_10_with_traps( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.current_progress = self.current_progress + var_0;

    if ( self.current_progress >= self.goal )
        self.success = 1;

    var_9 = self.goal - self.current_progress;
    update_challenge_progress( self.current_progress, self.goal );

    if ( self.success )
        maps\mp\alien\_challenge::deactivate_current_challenge();
}

activate_stay_prone()
{
    reset_stay_prone_progress();
    update_challenge_progress( 0, self.goal );
}

deactivate_stay_prone()
{
    reset_stay_prone_progress();
}

reset_stay_prone_progress()
{
    default_resetsuccess();
    self.current_progress = 0;
}

update_stay_prone( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.current_progress = self.current_progress + var_0;

    if ( self.current_progress >= self.goal )
        self.success = 1;

    var_9 = self.goal - self.current_progress;
    update_challenge_progress( self.current_progress, self.goal );

    if ( self.success )
        maps\mp\alien\_challenge::deactivate_current_challenge();
}

activate_protect_a_player()
{
    default_resetsuccess();
    var_0 = [];

    foreach ( var_2 in level.players )
    {
        if ( isalive( var_2 ) && !var_2 maps\mp\alien\_utility::is_in_laststand() )
            var_0[var_0.size] = var_2;
    }

    var_4 = common_scripts\utility::random( var_0 );

    foreach ( var_2 in level.players )
    {
        var_6 = var_4 getentitynumber();
        var_2 setclientomnvar( "ui_intel_target_player", var_6 );
    }

    level.current_challenge_target_player = var_4 getentitynumber();
    var_4 maps\mp\_entityheadicons::setheadicon( var_4.team, "waypoint_defend", ( 0, 0, 72 ), 4, 4, undefined, undefined, undefined, 1, undefined, 0 );
    level thread watch_target_player( var_4, self );
    level thread watch_drill_detonated( var_4, self );
}

watch_target_player( var_0, var_1 )
{
    level endon( "drill_detonated" );
    var_0 common_scripts\utility::waittill_any( "death", "last_stand", "disconnect" );
    var_0 remove_head_icon();
    var_1.success = 0;
    update_protect_a_player();
}

update_protect_a_player()
{
    maps\mp\alien\_challenge::deactivate_current_challenge();

    foreach ( var_1 in level.players )
        var_1 setclientomnvar( "ui_intel_target_player", -1 );

    level.current_challenge_target_player = -1;
}

watch_drill_detonated( var_0, var_1 )
{
    var_0 endon( "death" );
    var_0 endon( "last_stand" );
    var_0 endon( "disconnect" );
    level waittill( "drill_detonated" );
    var_0 remove_head_icon();
    update_protect_a_player();
}

remove_head_icon()
{
    foreach ( var_2, var_1 in self.entityheadicons )
    {
        if ( !isdefined( var_1 ) )
            continue;

        var_1 destroy();
    }
}

deactivate_protect_a_player()
{
    default_resetsuccess();
}

activate_avoid_minion_exp()
{
    default_resetsuccess();
}

deactivate_avoid_minion_exp()
{
    default_resetsuccess();
}

update_avoid_minion_exp( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.success = 0;
    maps\mp\alien\_challenge::deactivate_current_challenge();
}

update_75_percent_accuracy( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.total_shots_hit++;
}

seventyfive_percent_accuracy_success_test( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    return self.current_accuracy >= 75;
}

fifty_percent_accuracy_success_test( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    return self.current_accuracy >= 50;
}

update_50_percent_accuracy( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.total_shots_hit++;
}

activate_percent_accuracy()
{
    default_resetsuccess();
    self.total_shots_fired = 0;
    self.total_shots_hit = 0;
    self.current_accuracy = 0;
    self.is_updating = 0;
    level thread track_percent_accuracy_shots_fired( self );
    level thread update_percent_accuracy( self );
    update_challenge_percent( 0 );
}

deactivate_percent_accuracy()
{
    default_resetsuccess();
    self.total_shots_fired = 0;
    self.total_shots_hit = 0;
    level notify( "deactivate_track_accuracy" );
}

activate_use_weapon_challenge()
{
    setup_challenge_waypoints( self );
    default_resetsuccess();
    self.current_progress = 0;
    update_challenge_progress( 0, self.goal );
}

update_pistols_only( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    if ( maps\mp\_utility::getweaponclass( var_0 ) == "weapon_pistol" || maps\mp\alien\_utility::is_true( var_2 ) )
        self.current_progress++;

    update_challenge_progress( self.current_progress, self.goal );

    if ( self.current_progress >= self.goal )
    {
        self.success = 1;
        maps\mp\alien\_challenge::deactivate_current_challenge();
    }
}

update_shotguns_only( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    if ( maps\mp\_utility::getweaponclass( var_0 ) == "weapon_shotgun" || maps\mp\alien\_utility::is_true( var_2 ) )
        self.current_progress++;

    update_challenge_progress( self.current_progress, self.goal );

    if ( self.current_progress >= self.goal )
    {
        self.success = 1;
        maps\mp\alien\_challenge::deactivate_current_challenge();
    }
}

update_snipers_only( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    if ( maps\mp\_utility::getweaponclass( var_0 ) == "weapon_sniper" || maps\mp\alien\_utility::is_true( var_2 ) )
        self.current_progress++;

    update_challenge_progress( self.current_progress, self.goal );

    if ( self.current_progress >= self.goal )
    {
        self.success = 1;
        maps\mp\alien\_challenge::deactivate_current_challenge();
    }
}

update_lmgs_only( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    if ( maps\mp\_utility::getweaponclass( var_0 ) == "weapon_lmg" || maps\mp\alien\_utility::is_true( var_2 ) )
        self.current_progress++;

    update_challenge_progress( self.current_progress, self.goal );

    if ( self.current_progress >= self.goal )
    {
        self.success = 1;
        maps\mp\alien\_challenge::deactivate_current_challenge();
    }
}

update_ar_only( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    if ( maps\mp\_utility::getweaponclass( var_0 ) == "weapon_assault" || maps\mp\alien\_utility::is_true( var_2 ) )
        self.current_progress++;

    update_challenge_progress( self.current_progress, self.goal );

    if ( self.current_progress >= self.goal )
    {
        self.success = 1;
        maps\mp\alien\_challenge::deactivate_current_challenge();
    }
}

update_smgs_only( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    if ( maps\mp\_utility::getweaponclass( var_0 ) == "weapon_smg" || maps\mp\alien\_utility::is_true( var_2 ) )
        self.current_progress++;

    update_challenge_progress( self.current_progress, self.goal );

    if ( self.current_progress >= self.goal )
    {
        self.success = 1;
        maps\mp\alien\_challenge::deactivate_current_challenge();
    }
}

activate_kill_10_with_turrets()
{
    reset_kill_10_with_turrets_progress();
    update_challenge_progress( 0, self.goal );
}

deactivate_kill_10_with_turrets()
{
    reset_kill_10_with_turrets_progress();
}

reset_kill_10_with_turrets_progress()
{
    default_resetsuccess();
    self.current_progress = 0;
}

update_kill_10_with_turrets( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.current_progress = self.current_progress + var_0;

    if ( self.current_progress >= self.goal )
        self.success = 1;

    var_9 = self.goal - self.current_progress;
    update_challenge_progress( self.current_progress, self.goal );

    if ( self.success )
        maps\mp\alien\_challenge::deactivate_current_challenge();
}

activate_kill_airborne_aliens()
{
    reset_kill_airborne_aliens_progress();
    update_challenge_progress( 0, self.goal );
}

deactivate_kill_airborne_aliens()
{
    reset_kill_airborne_aliens_progress();
}

reset_kill_airborne_aliens_progress()
{
    default_resetsuccess();
    self.current_progress = 0;
}

update_kill_airborne_aliens( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.current_progress = self.current_progress + var_0;

    if ( self.current_progress >= self.goal )
        self.success = 1;

    var_9 = self.goal - self.current_progress;
    update_challenge_progress( self.current_progress, self.goal );

    if ( self.success )
        maps\mp\alien\_challenge::deactivate_current_challenge();
}

activate_melee_only()
{
    reset_melee_only_progress();
}

deactivate_melee_only()
{
    reset_melee_only_progress();
}

reset_melee_only_progress()
{
    default_resetsuccess();
}

update_melee_only( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.success = 0;
    maps\mp\alien\_challenge::deactivate_current_challenge();
}

pre_activate_stay_within_area()
{
    var_0 = get_challenge_ring_location( level.current_hive_name );
    var_1 = bullettrace( var_0 + ( 0, 0, 20 ), var_0 - ( 0, 0, 20 ), 0, undefined, 1, 0, 1, 1 );
    self.ring_ent = spawn( "script_model", var_1["position"] );
    self.ring_ent setmodel( "tag_origin" );
    wait 0.1;
    self.ring_fx = playfxontag( level._effect["challenge_ring"], self.ring_ent, "tag_origin" );
    return 1;
}

activate_stay_within_area()
{
    default_resetsuccess();
    self.current_progress = 0;
    self.distance_check = 22500;
    update_challenge_progress( 0, self.goal );
}

update_stay_within_area( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    if ( abs( var_1[2] - self.ring_ent.origin[2] ) > 75 )
        return;

    var_9 = distancesquared( var_1, self.ring_ent.origin );

    if ( var_9 > self.distance_check )
        return;

    self.current_progress++;

    if ( self.current_progress >= self.goal )
        self.success = 1;

    var_10 = self.goal - self.current_progress;
    update_challenge_progress( self.current_progress, self.goal );

    if ( self.success )
        maps\mp\alien\_challenge::deactivate_current_challenge();
}

deactivate_stay_within_area()
{
    level notify( "ring_challenge_ended" );
    self.current_progress = 0;
    self.ring_ent delete();
    self.ring_fx = undefined;

    if ( isdefined( level.ring_waypoint_icon ) )
        level.ring_waypoint_icon destroy();

    default_resetsuccess();
}

activate_kill_10_in_30()
{
    default_resetsuccess();
    self.current_progress = 0;
    var_0 = int( gettime() + 30000 );

    foreach ( var_2 in level.players )
        var_2 setclientomnvar( "ui_intel_timer", var_0 );

    level.current_challenge_timer = 30;
    level thread update_current_challenge_timer();
    update_challenge_progress( 0, self.goal );
    level thread kill_10_in_30_timer( self );
}

kill_10_in_30_timer( var_0 )
{
    level endon( "game_ended" );
    self endon( "success" );
    wait 30;
    self.success = 0;
    maps\mp\alien\_challenge::deactivate_current_challenge();
}

update_kill_10_in_30( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.current_progress = self.current_progress + var_0;

    if ( self.current_progress >= self.goal )
    {
        self.success = 1;
        self notify( "success" );
    }

    var_9 = self.goal - self.current_progress;
    update_challenge_progress( self.current_progress, self.goal );

    if ( self.success )
        maps\mp\alien\_challenge::deactivate_current_challenge();
}

update_alien_death_challenges( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    if ( !isdefined( level.current_challenge ) )
        return;

    var_9 = level.current_challenge;

    if ( isdefined( level.custom_death_challenge_func ) )
    {
        var_10 = self [[ level.custom_death_challenge_func ]]( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 );

        if ( !maps\mp\alien\_utility::is_true( var_10 ) )
            return;
    }

    var_11 = isdefined( var_1 ) && isplayer( var_1 );
    var_12 = isdefined( var_1 );
    var_13 = isdefined( var_0 ) && isplayer( var_0 );
    var_14 = isdefined( var_0 );
    var_15 = maps\mp\alien\_utility::get_alien_type();
    var_16 = isdefined( var_4 );
    var_17 = 0;

    if ( var_16 )
        var_17 = is_explosive_kill( var_4 );

    var_18 = 0;

    if ( var_14 )
        var_18 = maps\mp\alien\_utility::is_trap( var_0 );

    switch ( var_9 )
    {
        case "snipers_only":
        case "shotguns_only":
        case "lmgs_only":
        case "smg_only":
        case "ar_only":
        case "pistols_only":
            if ( var_16 && var_3 != "MOD_MELEE" )
            {
                var_19 = is_arc_death( var_0, var_1, var_12, var_11, var_14, var_13 );

                if ( !var_14 || var_13 || var_19 )
                {
                    if ( var_19 )
                        maps\mp\alien\_challenge::update_challenge( var_9, var_4, var_3, var_19 );
                    else
                        maps\mp\alien\_challenge::update_challenge( var_9, var_4, var_3 );
                }
            }

            break;
        case "melee_5_goons":
            if ( var_15 == "goon" && var_11 && var_3 == "MOD_MELEE" )
                maps\mp\alien\_challenge::update_challenge( "melee_5_goons", 1 );

            break;
        case "melee_spitter":
            if ( var_15 == "spitter" && var_11 && var_3 == "MOD_MELEE" )
                maps\mp\alien\_challenge::update_challenge( "melee_spitter", 1 );

            break;
        case "melee_only":
            if ( var_11 && var_3 != "MOD_MELEE" )
                maps\mp\alien\_challenge::update_challenge( "melee_only" );

            break;
        case "kill_airborne_aliens":
            if ( var_11 && isdefined( self.trajectoryactive ) && self.trajectoryactive )
                maps\mp\alien\_challenge::update_challenge( "kill_airborne_aliens", 1 );
            else if ( var_11 && ( maps\mp\alien\_utility::is_true( self.in_air ) || var_15 == "bomber" ) && var_3 != "MOD_SUICIDE" )
                maps\mp\alien\_challenge::update_challenge( "kill_airborne_aliens", 1 );
            else if ( var_11 && var_15 == "ancestor" )
                maps\mp\alien\_challenge::update_challenge( "kill_airborne_aliens", 1 );

            break;
        case "stay_prone":
            if ( ( var_11 || var_13 ) && var_1 getstance() == "prone" )
                maps\mp\alien\_challenge::update_challenge( "stay_prone", 1 );

            break;
        case "kill_10_with_turrets":
            if ( var_11 && var_16 && maps\mp\alien\_damage::isalienturret( var_4 ) )
                maps\mp\alien\_challenge::update_challenge( "kill_10_with_turrets", 1 );
            else if ( var_12 && isdefined( var_1.classname ) && var_1.classname == "misc_turret" && var_16 && maps\mp\alien\_damage::isalienturret( var_4 ) )
                maps\mp\alien\_challenge::update_challenge( "kill_10_with_turrets", 1 );

            break;
        case "stay_within_area":
            if ( var_11 )
                maps\mp\alien\_challenge::update_challenge( "stay_within_area", self.origin, var_1.origin );

            break;
        case "kill_10_in_30":
            if ( var_11 )
                maps\mp\alien\_challenge::update_challenge( "kill_10_in_30", 1 );

            break;
        case "kill_10_with_propane":
            if ( var_16 && var_4 == "alienpropanetank_mp" )
                maps\mp\alien\_challenge::update_challenge( "kill_10_with_propane", 1 );
            else if ( var_14 && isdefined( var_0.classname ) && var_0.classname == "trigger_radius" )
                maps\mp\alien\_challenge::update_challenge( "kill_10_with_propane", 1 );

            break;
        case "kill_10_with_traps":
            if ( var_18 )
                maps\mp\alien\_challenge::update_challenge( "kill_10_with_traps", 1 );

            break;
    }
}

is_arc_death( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    return var_2 && var_3 && var_4 && !var_5 && isdefined( var_1.stun_struct ) && isdefined( var_1.stun_struct.attack_bolt ) && var_0 == var_1.stun_struct.attack_bolt;
}

update_alien_damage_challenge( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8, var_9, var_10 )
{
    if ( !isdefined( level.current_challenge ) )
        return;

    if ( level.current_challenge == "melee_only" && var_4 != "MOD_MELEE" && !maps\mp\alien\_utility::is_flaming_stowed_riotshield_damage( var_4, var_5, var_0 ) && isplayer( var_1 ) )
        maps\mp\alien\_challenge::update_challenge( "melee_only" );

    if ( isdefined( var_1 ) && isplayer( var_1 ) )
    {
        if ( isdefined( level.custom_damage_challenge_func ) )
        {
            var_11 = self [[ level.custom_damage_challenge_func ]]( var_0, var_1, var_2, var_4, var_5, var_7, var_8, var_9, var_10 );

            if ( !maps\mp\alien\_utility::is_true( var_11 ) )
                return;
        }

        var_1 endon( "disconnect" );
        common_scripts\utility::waitframe();

        if ( isdefined( var_1.fired_weapon ) )
        {
            if ( isdefined( var_5 ) && var_5 == "alienpropanetank_mp" || var_5 == "spore_pet_beam_mp" )
                return;

            if ( isdefined( var_0 ) && isdefined( var_0.classname ) && var_0.classname == "trigger_radius" )
                return;

            if ( isdefined( var_4 ) && var_4 == "MOD_MELEE" )
                return;

            if ( var_3 & 8 )
                return;

            if ( maps\mp\alien\_damage::isaliennonmannedturret( var_5 ) )
                return;

            if ( var_4 == "MOD_EXPLOSIVE_BULLET" && var_8 == "none" )
                return;

            if ( isdefined( var_5 ) && var_5 == "alienims_projectile_mp" )
                return;

            if ( isdefined( var_5 ) && maps\mp\_utility::getweaponclass( var_5 ) == "weapon_shotgun" )
                var_1.fired_weapon = undefined;

            if ( isdefined( level.current_challenge ) )
            {
                if ( level.current_challenge == "75_percent_accuracy" )
                    maps\mp\alien\_challenge::update_challenge( "75_percent_accuracy", 1 );
                else if ( level.current_challenge == "50_percent_accuracy" )
                    maps\mp\alien\_challenge::update_challenge( "50_percent_accuracy", 1 );
            }

            var_1.fired_weapon = undefined;
        }
    }
}

is_explosive_kill( var_0 )
{
    switch ( var_0 )
    {
        case "iw6_alienmk324_mp":
        case "iw6_alienmk323_mp":
        case "iw6_alienmk322_mp":
        case "iw6_alienmk321_mp":
        case "iw6_alienmk32_mp":
        case "alienclaymore_mp":
        case "aliensemtex_mp":
        case "alienbetty_mp":
            return 1;
        default:
            return 0;
    }
}

clear_last_alien_damaged_time()
{
    self endon( "disconnect" );
    wait 0.05;
    self.last_alien_damaged_time = undefined;
}

update_alien_weapon_challenges( var_0, var_1 )
{
    if ( !isdefined( level.current_challenge ) )
        return;

    switch ( level.current_challenge )
    {
        case "snipers_only":
        case "shotguns_only":
        case "lmgs_only":
        case "smg_only":
        case "ar_only":
        case "pistols_only":
            maps\mp\alien\_challenge::update_challenge( level.current_challenge, var_0, var_1 );
            break;
        default:
            return;
    }
}

update_challenge_progress( var_0, var_1 )
{
    foreach ( var_3 in level.players )
    {
        var_3 setclientomnvar( "ui_intel_progress_current", int( var_0 ) );
        var_3 setclientomnvar( "ui_intel_progress_max", int( var_1 ) );
    }

    level.current_challenge_progress_max = var_1;
    level.current_challenge_progress_current = var_0;
}

update_challenge_percent( var_0 )
{
    foreach ( var_2 in level.players )
        var_2 setclientomnvar( "ui_intel_percent", var_0 );

    level.current_challenge_percent = var_0;
}

update_percent_accuracy( var_0 )
{
    level endon( "deactivate_track_accuracy" );
    var_1 = 0;
    var_2 = 0;

    for (;;)
    {
        if ( var_0.total_shots_hit == 0 && var_0.total_shots_fired == 0 || var_0.total_shots_fired < 1 )
        {
            wait 0.25;
            continue;
        }

        var_3 = int( var_0.total_shots_hit / var_0.total_shots_fired * 10000 );

        if ( var_3 > 10000 )
            var_3 = 10000;

        var_4 = var_3 / 100;
        var_0.current_accuracy = var_4;

        if ( var_3 == var_1 )
        {
            var_2++;

            if ( var_2 > 2 )
            {
                update_challenge_percent( var_3 );
                var_2 = 0;
            }
        }
        else
            var_2 = 0;

        wait 0.05;
        var_1 = var_3;
    }
}

fail_challenge( var_0 )
{
    var_0.success = 0;
    maps\mp\alien\_challenge::deactivate_current_challenge();
}

track_percent_accuracy_shots_fired( var_0 )
{
    foreach ( var_2 in level.players )
    {
        if ( !isalive( var_2 ) )
            continue;

        var_2 thread track_percent_accuracy_shots_fired_internal( var_0 );
    }
}

track_percent_accuracy_shots_fired_internal( var_0 )
{
    level endon( "deactivate_track_accuracy" );
    self endon( "disconnect" );
    self endon( "death" );
    childthread track_percent_accuracy_misc_shots_fired( var_0 );

    for (;;)
    {
        self waittill( "weapon_fired", var_1 );

        if ( !weapon_should_count_towards_accuracy_challenge( var_1 ) )
            continue;

        self.fired_weapon = 1;
        var_0.total_shots_fired++;
    }
}

track_percent_accuracy_misc_shots_fired( var_0 )
{
    level endon( "deactivate_track_accuracy" );
    self endon( "disconnect" );
    self endon( "death" );

    for (;;)
    {
        common_scripts\utility::waittill_any( "turret_fire", "nx1_large_fire" );
        self.fired_weapon = 1;
        var_0.total_shots_fired++;
    }
}

update_current_challenge_timer()
{
    level endon( "stop_challenge_timer" );

    while ( level.current_challenge_timer > 0 )
    {
        wait 0.1;
        level.current_challenge_timer = level.current_challenge_timer - 0.1;
    }
}

weapon_should_count_towards_accuracy_challenge( var_0 )
{
    switch ( var_0 )
    {
        case "alien_turret_marker_mp":
        case "alienpropanetank_mp":
        case "aliendeployable_crate_marker_mp":
        case "switchblade_laptop_mp":
        case "mortar_detonator_mp":
        case "alienbomb_mp":
        case "alienclaymore_mp":
        case "alientrophy_mp":
        case "deployable_vest_marker_mp":
        case "bouncingbetty_mp":
            return 0;
    }

    return 1;
}

get_challenge_scalar( var_0 )
{
    return [[ level.challenge_scalar_func ]]( var_0 );
}

default_challenge_scalar_func( var_0 )
{
    switch ( var_0 )
    {
        case "snipers_only":
        case "shotguns_only":
        case "lmgs_only":
        case "smg_only":
        case "ar_only":
        case "pistols_only":
            switch ( level.players.size )
            {
                case 1:
                    return 15;
                case 2:
                    return 20;
                case 4:
                case 3:
                    return 25;
            }
        case "kill_10_with_turrets":
        case "kill_10_with_traps":
        case "kill_10_with_propane":
            switch ( level.players.size )
            {
                case 1:
                    return 5;
                case 4:
                case 3:
                case 2:
                    return 10;
            }
        case "kill_10_in_30":
            switch ( level.players.size )
            {
                case 1:
                    return 5;
                case 4:
                case 3:
                case 2:
                    return 10;
            }
        case "stay_within_area":
            switch ( level.players.size )
            {
                case 1:
                    return 10;
                case 4:
                case 3:
                case 2:
                    return 20;
            }
        case "kill_airborne_aliens":
            switch ( level.players.size )
            {
                case 1:
                    return 3;
                case 4:
                case 3:
                case 2:
                    return 5;
            }
        case "stay_prone":
            switch ( level.players.size )
            {
                case 1:
                    return 15;
                case 4:
                case 3:
                case 2:
                    return 25;
            }
        case "spend_20k":
            switch ( level.players.size )
            {
                case 1:
                    return 6;
                case 2:
                    return 10;
                case 3:
                    return 15;
                case 4:
                    return 20;
            }
        case "spend_10k":
            switch ( level.players.size )
            {
                case 1:
                    return 6;
                case 4:
                case 3:
                case 2:
                    return 10;
            }
        case "melee_5_goons":
            switch ( level.players.size )
            {
                case 1:
                    return 5;
                case 2:
                    return 10;
                case 3:
                    return 10;
                case 4:
                    return 15;
            }
    }

    return undefined;
}

show_barrier_hive_intel()
{
    var_0 = 52;
    var_1 = 2;

    foreach ( var_3 in level.players )
    {
        var_3 setclientomnvar( "ui_intel_title", var_1 );
        var_3 setclientomnvar( "ui_intel_active_index", var_0 );
    }

    level.current_challenge_title = var_1;
    level.current_challenge_index = var_0;
}

hide_barrier_hive_intel()
{
    foreach ( var_1 in level.players )
    {
        var_1 setclientomnvar( "ui_intel_active_index", -1 );
        var_1 setclientomnvar( "ui_intel_title", -1 );
    }

    level.current_challenge_title = -1;
    level.current_challenge_index = -1;
}

get_challenge_ring_location( var_0 )
{
    if ( isdefined( level.challenge_ring_location_func ) )
        return [[ level.challenge_ring_location_func ]]( var_0 );

    return undefined;
}

create_challenge_waypoints( var_0 )
{
    var_1 = "waypoint_alien_weapon_challenge";
    var_2 = 14;
    var_3 = 14;
    var_4 = 0.75;
    var_5 = var_0.origin;

    if ( level.script == "mp_alien_armory" )
        var_4 = 0;

    var_6 = maps\mp\alien\_hud::make_waypoint( var_1, var_2, var_3, var_4, var_5 );
    return var_6;
}

setup_challenge_waypoints( var_0 )
{
    var_1 = maps\mp\alien\_utility::get_current_area_name();
    var_2 = level.current_challenge;

    if ( var_2 == "pistols_only" )
        return;

    var_3 = get_challenge_weapons( var_1, var_2 );
    self.challenge_weapons = [];

    foreach ( var_5 in var_3 )
        self.challenge_weapons[self.challenge_weapons.size] = maps\mp\_utility::getbaseweaponname( var_5 );
}

get_challenge_weapons( var_0, var_1 )
{
    var_2 = get_weapon_class_for_current_challenge( var_1 );

    if ( !isdefined( var_2 ) && var_1 == "semi_autos_only" )
        var_2 = [ "weapon_dmr", "weapon_sniper" ];

    var_3 = [];
    var_4 = [];

    foreach ( var_6 in level.world_items )
    {
        if ( level.script == "mp_alien_armory" )
        {
            if ( isdefined( var_6.script_noteworthy ) && var_6.script_noteworthy == "weapon_iw6_aliendlc15_mp" )
            {
                var_6.areas = [];
                var_6.areas[0] = "checkpoint";
            }
        }

        if ( isdefined( var_6.areas ) && var_6.areas[0] == var_0 )
        {
            if ( !isdefined( var_6.script_noteworthy ) )
                continue;

            var_7 = getsubstr( var_6.script_noteworthy, 7 );
            var_8 = maps\mp\_utility::getweaponclass( var_7 );

            if ( isarray( var_2 ) )
            {
                if ( common_scripts\utility::array_contains( var_2, var_8 ) )
                {
                    var_3[var_3.size] = var_7;
                    var_9 = create_challenge_waypoints( var_6 );
                    var_4[var_4.size] = var_9;
                }

                continue;
            }

            if ( var_2 != var_8 )
                continue;

            var_3[var_3.size] = var_7;
            var_9 = create_challenge_waypoints( var_6 );
            var_4[var_4.size] = var_9;
        }
    }

    self.waypoints = var_4;
    return var_3;
}

get_weapon_class_for_current_challenge( var_0 )
{
    switch ( var_0 )
    {
        case "ar_only":
            return "weapon_assault";
        case "snipers_only":
            return "weapon_sniper";
        case "smg_only":
            return "weapon_smg";
        case "lmgs_only":
            return "weapon_lmg";
        case "shotguns_only":
            return "weapon_shotgun";
    }
}

deactivate_weapon_challenge_waypoints()
{
    if ( isdefined( self ) && isdefined( self.waypoints ) )
    {
        foreach ( var_1 in self.waypoints )
            var_1 destroy();
    }

    default_resetsuccess();
}

focus_fire_update_alien_outline( var_0 )
{
    foreach ( var_0 in level.players )
    {
        if ( common_scripts\utility::array_contains( self.damaged_by_players, var_0 ) )
        {
            if ( isdefined( var_0.isferal ) && var_0.isferal )
                maps\mp\alien\_outline_proto::enable_outline_for_player( self, var_0, 4, 0, "high" );
            else
                maps\mp\alien\_outline_proto::disable_outline_for_player( self, var_0 );

            continue;
        }

        maps\mp\alien\_outline_proto::enable_outline_for_player( self, var_0, 0, 0, "high" );
    }
}
