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

outline_init()
{
    level.outline_watch_list = [];
    level.outline_pillage_watch_list = [];
    level.outline_weapon_watch_list = [];
    level.outline_drill_watch_list = [];
    level.outline_hive_watch_list = [];
    level.outline_drill_preplant_watch_list = [];
}

outline_monitor()
{
    self endon( "disconnect" );
    level endon( "game_ended" );
    self waittill( "spawned" );
    childthread outline_monitor_think();
}

outline_monitor_think()
{
    for (;;)
    {
        player_outline();
        common_scripts\utility::waitframe();
        item_outline();
        common_scripts\utility::waitframe();
        item_outline_pillage();
        common_scripts\utility::waitframe();
        intel_outline();
        common_scripts\utility::waitframe();
        item_outline_weapon_monitor();
        common_scripts\utility::waitframe();
        item_outline_drill_monitor();
        common_scripts\utility::waitframe();
        hive_outline_monitor();
        common_scripts\utility::waitframe();
        drill_preplant_outline_monitor();
        common_scripts\utility::waitframe();
    }
}

update_drill_outline()
{
    level common_scripts\utility::waittill_any_timeout( 1, "drill_spawned" );

    foreach ( var_1 in level.players )
    {
        var_2 = var_1 get_item_outline_color( level.drill );

        if ( var_2 == 3 || var_2 == 4 )
        {
            enable_outline_for_player( level.drill, var_1, var_2, 0, "high" );
            continue;
        }

        disable_outline_for_player( level.drill, var_1 );
    }
}

player_outline()
{
    self endon( "refresh_outline" );

    foreach ( var_1 in level.players )
    {
        if ( self == var_1 )
            continue;

        if ( should_put_player_outline_on( var_1 ) )
        {
            enable_outline_for_player( var_1, self, get_color_index_player( var_1 ), 0, "high" );
            continue;
        }

        disable_outline_for_player( var_1, self );
    }
}

set_alien_outline()
{
    self endon( "unset_adrenaline" );
    self endon( "switchblade_over" );
    self endon( "disconnect" );
    self endon( "death" );
    level endon( "game_ended" );

    for (;;)
    {
        foreach ( var_1 in maps\mp\alien\_spawnlogic::get_alive_enemies() )
        {
            if ( isdefined( level.kraken ) && var_1 == level.kraken )
                continue;

            if ( isdefined( var_1.agent_type ) && var_1.agent_type == "kraken_tentacle" )
                continue;

            if ( isdefined( var_1.damaged_by_players ) )
                continue;

            if ( isdefined( var_1.marked_for_challenge ) )
                continue;

            if ( isdefined( var_1.pet ) )
                continue;
            else if ( !isdefined( var_1.no_outline_on_alien ) )
            {
                if ( isdefined( var_1.feral_occludes ) )
                {
                    enable_outline_for_player( var_1, self, 4, 1, "high" );
                    continue;
                }

                enable_outline_for_player( var_1, self, 4, 0, "high" );
            }
        }

        wait 0.5;
    }
}

unset_alien_outline()
{
    foreach ( var_1 in maps\mp\alien\_spawnlogic::get_alive_enemies() )
    {
        if ( isdefined( var_1.damaged_by_players ) )
            continue;

        if ( isdefined( var_1.marked_for_challenge ) )
            continue;

        if ( !isdefined( var_1.pet ) )
            disable_outline_for_player( var_1, self );
    }
}

hive_outline_monitor()
{
    self endon( "refresh_outline" );

    foreach ( var_2, var_1 in level.outline_hive_watch_list )
    {
        enable_outline_for_player( var_1, self, 4, 1, "medium" );

        if ( var_2 % 10 == 0 )
            common_scripts\utility::waitframe();
    }
}

drill_preplant_outline_monitor()
{
    self endon( "refresh_outline" );

    foreach ( var_2, var_1 in level.outline_drill_preplant_watch_list )
    {
        if ( !isdefined( var_1 ) )
            continue;

        if ( should_put_drill_outline_on( var_1 ) )
            enable_outline_for_player( var_1, self, 3, 0, "high" );
        else
            disable_outline_for_player( var_1, self );

        if ( var_2 % 6 == 0 )
            common_scripts\utility::waitframe();
    }
}

item_outline()
{
    self endon( "refresh_outline" );

    foreach ( var_3, var_1 in level.outline_watch_list )
    {
        if ( !isdefined( var_1 ) )
            continue;

        var_2 = get_item_outline_color( var_1 );

        if ( var_2 == 3 )
            enable_outline_for_player( var_1, self, get_color_index_item( var_1 ), 1, "low" );
        else if ( var_2 == 4 )
            enable_outline_for_player( var_1, self, 4, 1, "low" );
        else
            disable_outline_for_player( var_1, self );

        if ( var_3 % 6 == 0 )
            common_scripts\utility::waitframe();
    }
}

item_outline_pillage()
{
    self endon( "refresh_outline" );

    foreach ( var_3, var_1 in level.outline_pillage_watch_list )
    {
        if ( !isdefined( var_1 ) )
            continue;

        var_2 = get_pillage_item_outline_color( var_1 );

        if ( var_2 == 3 )
            enable_outline_for_player( var_1, self, 3, 0, "low" );
        else if ( var_2 == 4 )
            enable_outline_for_player( var_1, self, 4, 0, "low" );
        else
            disable_outline_for_player( var_1, self );

        if ( var_3 % 10 == 0 )
            common_scripts\utility::waitframe();
    }
}

intel_outline()
{
    if ( isdefined( level.intel_outline_func ) )
        [[ level.intel_outline_func ]]();
}

item_outline_weapon_monitor()
{
    self endon( "refresh_outline" );

    foreach ( var_4, var_1 in level.outline_weapon_watch_list )
    {
        if ( !isdefined( var_1 ) )
            continue;

        var_2 = 1;
        var_3 = get_weapon_outline_color( var_1 );

        if ( var_3 == 3 )
            enable_outline_for_player( var_1, self, get_color_index_item( var_1, var_2 ), 1, "low" );
        else if ( var_3 == 4 )
            enable_outline_for_player( var_1, self, 4, 1, "low" );
        else
            disable_outline_for_player( var_1, self );

        if ( var_4 % 6 == 0 )
            common_scripts\utility::waitframe();
    }
}

item_outline_drill_monitor()
{
    if ( isdefined( level.item_outline_drill_monitor_override ) )
    {
        [[ level.item_outline_drill_monitor_override ]]();
        return;
    }

    self endon( "refresh_outline" );
    var_0 = undefined;

    foreach ( var_2 in level.outline_drill_watch_list )
    {
        var_3 = ( level.drill.health - 20000 ) / ( level.drill.maxhealth - 20000 );

        if ( var_3 < 0.75 )
        {
            if ( should_put_drill_outline_on( var_2 ) )
                enable_outline_for_player( var_2, self, get_drill_widget_color( var_2 ), 0, "high" );
            else
                disable_outline_for_player( var_2, self );
        }
        else
            disable_outline_for_player( var_2, self );

        if ( isdefined( level.drill ) && var_2 == level.drill )
        {
            var_4 = get_drill_widget_color( var_2 );

            if ( isdefined( var_0 ) && var_0 == var_4 )
                continue;

            var_0 = var_4;
        }
    }
}

get_drill_widget_color( var_0 )
{
    var_1 = ( level.drill.health - 20000 ) / ( level.drill.maxhealth - 20000 );

    if ( var_1 <= 0.3 )
        return 4;
    else if ( var_1 <= 0.75 )
        return 5;
    else if ( var_1 <= 1 )
        return 3;
    else
        return 0;
}

get_color_index_item( var_0, var_1 )
{
    if ( maps\mp\alien\_utility::has_pistols_only_relic_and_no_deployables() && maps\mp\alien\_utility::is_true( var_1 ) )
        var_2 = level.pistol_ammo_cost;
    else
        var_2 = var_0.cost;

    if ( maps\mp\alien\_persistence::player_has_enough_currency( var_2 ) || maps\mp\alien\_utility::is_true( var_0.enabled ) )
        return 3;
    else
        return 4;
}

get_color_index_player( var_0 )
{
    var_1 = var_0.health / 100;

    if ( var_1 <= 0.33 || var_0.inlaststand )
        return 4;
    else if ( var_1 <= 0.66 )
        return 5;
    else if ( var_1 <= 1.0 )
        return 3;
    else
        return 0;
}

get_item_outline_color( var_0 )
{
    if ( isdefined( var_0.classname ) && var_0.classname == "misc_turret" && isdefined( var_0.owner ) )
        return 0;

    var_1 = distancesquared( self.origin, var_0.origin ) < 122500;

    if ( !var_1 )
        return 0;

    if ( maps\mp\alien\_utility::has_special_weapon() )
    {
        if ( isdefined( var_0.targetname ) && ( var_0.targetname == "fire_trap_barrel" || var_0.targetname == "puddle_generator" || var_0.targetname == "fence_generator" ) )
            return 3;
        else if ( isdefined( var_0.classname ) && var_0.classname == "misc_turret" )
            return 3;
        else
            return 4;
    }
    else if ( maps\mp\alien\_utility::is_holding_deployable() )
        return 4;

    return 3;
}

get_pillage_item_outline_color( var_0 )
{
    if ( !isdefined( var_0 ) )
        return 0;

    var_1 = distancesquared( self.origin, var_0.origin ) < 27225;

    if ( !var_1 )
        return 0;

    if ( isdefined( var_0.is_locker ) && var_0.is_locker && !isdefined( self.locker_key ) )
        return 0;

    if ( maps\mp\alien\_utility::is_holding_deployable() || maps\mp\alien\_utility::has_special_weapon() )
        return 4;

    return 3;
}

get_weapon_outline_color( var_0 )
{
    var_1 = distancesquared( self.origin, var_0.origin ) < 1000000;

    if ( !var_1 )
        return 0;

    if ( maps\mp\alien\_utility::is_chaos_mode() && maps\mp\alien\_chaos::is_weapon_recently_picked_up( self, var_0.weapon_ref ) )
        return 4;

    if ( maps\mp\alien\_utility::is_holding_deployable() )
        return 4;

    if ( !maps\mp\alien\_utility::is_true( var_0.is_recipe_table ) && maps\mp\alien\_prestige::prestige_getpistolsonly() == 1 && !maps\mp\alien\_prestige::prestige_getnodeployables() == 1 )
        return 4;

    if ( isdefined( level.get_custom_weapon_outline_func ) && [[ level.get_custom_weapon_outline_func ]]( var_0 ) )
        return 4;

    if ( maps\mp\alien\_utility::has_special_weapon() && !maps\mp\alien\_utility::is_true( var_0.is_recipe_table ) )
    {
        if ( isdefined( level.drill ) && var_0 == level.drill )
            return 3;
        else
            return 4;
    }

    return 3;
}

should_put_drill_outline_on( var_0 )
{
    var_1 = distancesquared( self.origin, var_0.origin ) < 1000000;

    if ( !var_1 )
        return 0;

    return 1;
}

should_put_player_outline_on( var_0 )
{
    if ( !isalive( var_0 ) || !isdefined( var_0.maxhealth ) || !var_0.maxhealth )
        return 0;

    var_1 = distancesquared( self.origin, var_0.origin ) > 2250000;

    if ( var_1 )
        return 1;

    var_2 = !bullettracepassed( self geteye(), var_0 geteye(), 0, self );
    return var_2;
}

add_to_outline_watch_list( var_0, var_1 )
{
    var_0.cost = var_1;
    level.outline_watch_list[level.outline_watch_list.size] = var_0;
}

remove_from_outline_watch_list( var_0 )
{
    level.outline_watch_list = common_scripts\utility::array_remove( level.outline_watch_list, var_0 );
    thread remove_outline( var_0 );
}

add_to_drill_preplant_watch_list( var_0 )
{
    level.outline_drill_preplant_watch_list[level.outline_drill_preplant_watch_list.size] = var_0;
}

remove_from_drill_preplant_watch_list( var_0 )
{
    level.outline_drill_preplant_watch_list = common_scripts\utility::array_remove( level.outline_drill_preplant_watch_list, var_0 );
    thread remove_outline( var_0 );
}

add_to_outline_hive_watch_list( var_0 )
{
    level.outline_hive_watch_list[level.outline_hive_watch_list.size] = var_0;
}

remove_from_outline_hive_watch_list( var_0 )
{
    level.outline_hive_watch_list = common_scripts\utility::array_remove( level.outline_hive_watch_list, var_0 );
    thread remove_outline( var_0 );
}

add_to_outline_pillage_watch_list( var_0, var_1 )
{
    if ( !common_scripts\utility::array_contains( level.outline_pillage_watch_list, var_0 ) )
    {
        var_0.cost = var_1;
        level.outline_pillage_watch_list[level.outline_pillage_watch_list.size] = var_0;
    }
}

remove_from_outline_pillage_watch_list( var_0 )
{
    level.outline_pillage_watch_list = common_scripts\utility::array_remove( level.outline_pillage_watch_list, var_0 );
    thread remove_outline( var_0 );
}

add_to_outline_weapon_watch_list( var_0, var_1 )
{
    var_0.cost = var_1;
    level.outline_weapon_watch_list[level.outline_weapon_watch_list.size] = var_0;
}

remove_from_outline_weapon_watch_list( var_0 )
{
    level.outline_weapon_watch_list = common_scripts\utility::array_remove( level.outline_weapon_watch_list, var_0 );
    thread remove_outline( var_0 );
}

add_to_outline_drill_watch_list( var_0, var_1 )
{
    var_0.cost = var_1;
    level.outline_drill_watch_list[level.outline_drill_watch_list.size] = var_0;
}

remove_from_outline_drill_watch_list( var_0 )
{
    level.outline_drill_watch_list = common_scripts\utility::array_remove( level.outline_drill_watch_list, var_0 );
    thread remove_outline( var_0 );
}

remove_outline( var_0 )
{
    if ( !isdefined( var_0 ) )
        return;

    foreach ( var_2 in level.players )
    {
        if ( isdefined( var_2 ) )
        {
            var_2 notify( "refresh_outline" );
            disable_outline_for_player( var_0, var_2 );
        }
    }
}

enable_outline_for_players( var_0, var_1, var_2, var_3, var_4 )
{
    var_0 hudoutlineenableforclients( var_1, var_2, var_3 );
}

enable_outline_for_player( var_0, var_1, var_2, var_3, var_4 )
{
    var_0 hudoutlineenableforclient( var_1, var_2, var_3 );
}

disable_outline_for_players( var_0, var_1 )
{
    var_0 hudoutlinedisableforclients( var_1 );
}

disable_outline_for_player( var_0, var_1 )
{
    var_0 hudoutlinedisableforclient( var_1 );
}

enable_outline( var_0, var_1, var_2 )
{
    var_0 hudoutlineenable( var_1, var_2 );
}

disable_outline( var_0 )
{
    var_0 hudoutlinedisable();
}

outline_proto_enabled()
{
    return getdvarint( "enable_outline_proto" ) == 1;
}

is_host( var_0 )
{
    return var_0 ishost();
}
