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

boneyard_killstreak_setup()
{
    level.ks_vertical = spawnstruct();
    level.ks_vertical.sfx = getent( "ks_vertical_org", "targetname" );
    level.ks_vertical.dam = getent( "ks_vertical_damage_vol", "targetname" );
    level.ks_vertical.destructibles = [ ( 481, -74, -100 ) ];
    level.ks_vertical.uses = 0;
    level.ks_vertical.max_uses = 1;
    level.ks_vertical.player = undefined;
    level.ks_vertical.team = undefined;
    level.ks_vertical.inflictor = getent( "vert_fire_ent", "targetname" );
    level.ks_vertical.ui_icon = [];
    level.ks_vertical.ui_icon[0] = "compass_icon_vf_idle";
    level.ks_vertical.ui_icon[1] = "compass_icon_vf_active";
    level.ks_vertical.ui_state = 0;
    level.ks_vertical.ui_elem = maps\mp\gametypes\_gameobjects::getnextobjid();
    objective_add( level.ks_vertical.ui_elem, "active", ( 381.5, 120, 254 ), level.ks_vertical.ui_icon[0] );
    objective_playermask_hidefromall( level.ks_vertical.ui_elem );
    level.alarm1_a = spawn( "script_origin", ( 1936, 231, 221 ) );
    level.alarm1_b = spawn( "script_origin", ( 520, -224, 199 ) );
    level.alarm1_c = spawn( "script_origin", ( 346, 150, 246 ) );
    level.alarm1_cp1 = spawn( "script_origin", ( 346, 150, 246 ) );
    level.alarm1_cp2 = spawn( "script_origin", ( 346, 150, 246 ) );
    level.alarm1_d = spawn( "script_origin", ( -1028, 534, 368 ) );
    level.fire_node1 = spawn( "script_origin", ( 1063, 112, -177 ) );
    level.fire_node1end = spawn( "script_origin", ( 1063, 112, -177 ) );
    level.fire_node2 = spawn( "script_origin", ( 1320, -439, -133 ) );
    level.fire_node2end = spawn( "script_origin", ( 1320, -439, -133 ) );
    level.fire_node3 = spawn( "script_origin", ( -283, 97, 16 ) );
    level.fire_node3end = spawn( "script_origin", ( -283, 97, 16 ) );
    common_scripts\utility::flag_init( "boneyard_killstreak_captured" );
    common_scripts\utility::flag_init( "boneyard_killstreak_can_kill" );
    common_scripts\utility::flag_init( "boneyard_killstreak_active" );
    common_scripts\utility::flag_init( "ks_vertical_alarm_on" );
    common_scripts\utility::flag_init( "ks_vertical_firing" );
    common_scripts\utility::flag_init( "boneyard_killstreak_endgame" );
    common_scripts\utility::flag_clear( "boneyard_killstreak_endgame" );
    thread ks_manage_spawns();
}

boneyardcustomcratefunc()
{
    level.allow_level_killstreak = maps\mp\_utility::allowlevelkillstreaks();

    if ( !level.allow_level_killstreak )
        return;

    maps\mp\killstreaks\_airdrop::addcratetype( "airdrop_assault", "f1_engine_fire", 200, maps\mp\killstreaks\_airdrop::killstreakcratethink, maps\mp\killstreaks\_airdrop::get_friendly_crate_model(), maps\mp\killstreaks\_airdrop::get_enemy_crate_model(), &"MP_BONEYARD_NS_F1_ENGINE_FIRE_PICKUP" );

    if ( isdefined( game["player_holding_level_killstreak"] ) && isalive( game["player_holding_level_killstreak"] ) )
    {
        level.ks_vertical.player = game["player_holding_level_killstreak"];
        level.ks_vertical.team = game["player_holding_level_killstreak"].pers["team"];
        common_scripts\utility::flag_set( "boneyard_killstreak_captured" );
        thread boneyard_killstreak_ui_watcher( level.ks_vertical, 0.1 );
    }
    else
        level thread boneyard_killstreak_watch_for_crate();
}

boneyard_killstreak_watch_for_crate()
{
    for (;;)
    {
        level waittill( "createAirDropCrate", var_0 );

        if ( isdefined( var_0 ) && isdefined( var_0.cratetype ) && var_0.cratetype == "f1_engine_fire" )
        {
            boneyard_killstreak_disable();
            var_1 = wait_for_capture( var_0 );

            if ( !isdefined( var_1 ) )
                boneyard_killstreak_enable( 200 );
            else
            {
                level.ks_vertical.player = var_1;
                level.ks_vertical.team = var_1.pers["team"];
                game["player_holding_level_killstreak"] = var_1;
                common_scripts\utility::flag_set( "boneyard_killstreak_captured" );
                thread boneyard_killstreak_ui_watcher( level.ks_vertical, 0.1 );
            }
        }
    }
}

wait_for_capture( var_0 )
{
    var_1 = watch_for_air_drop_death( var_0 );
    return var_1;
}

watch_for_air_drop_death( var_0 )
{
    var_0 endon( "death" );
    var_0 waittill( "captured", var_1 );
    return var_1;
}

boneyard_killstreak_bot_use()
{
    if ( isdefined( level.ks_vertical.player ) && level.ks_vertical.player istouching( level.ks_vertical.dam ) )
        return 0;

    return common_scripts\utility::flag( "boneyard_killstreak_can_kill" );
}

boneyard_killstreak_enable( var_0 )
{
    if ( isdefined( game["player_holding_level_killstreak"] ) && isalive( game["player_holding_level_killstreak"] ) )
        return 0;

    maps\mp\killstreaks\_airdrop::changecrateweight( "airdrop_assault", "f1_engine_fire", var_0 );
}

boneyard_killstreak_disable()
{
    maps\mp\killstreaks\_airdrop::changecrateweight( "airdrop_assault", "f1_engine_fire", 0 );
}

boneyard_killstreak_endgame()
{
    level waittill( "game_cleanup" );
    maps\mp\gametypes\_gamelogic::waittillfinalkillcamdone();
    common_scripts\utility::flag_set( "boneyard_killstreak_endgame" );
    thread ks_vertical_warning_lights();
    thread sound_fire_loop_logic();
    thread ks_vertical_firing_fx();
    wait 10;
    common_scripts\utility::flag_clear( "boneyard_killstreak_endgame" );
}

sound_fire_loop_logic()
{
    level.fire_node1 playloopsound( "scn_fire_event_02_fire1_lp" );
    level.fire_node2 playloopsound( "scn_fire_event_02_fire2_lp" );
    level.fire_node3 playloopsound( "scn_fire_event_02_fire1_lp" );
    wait 10.23;
    level.fire_node1end playsound( "scn_fire_event_02_fire1" );
    level.fire_node2end playsound( "scn_fire_event_02_fire2" );
    level.fire_node3end playsound( "scn_fire_event_02_fire1" );
    level.fire_node1 stoploopsound();
    level.fire_node2 stoploopsound();
    level.fire_node3 stoploopsound();
}

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

    for (;;)
    {
        level waittill( "boneyard_killstreak_activate", var_0 );
        thread boneyard_killstreak_disable();
        game["player_holding_level_killstreak"] = undefined;
        common_scripts\utility::flag_set( "boneyard_killstreak_active" );
        level.ks_vertical.player = var_0;
        level.ks_vertical.team = var_0.pers["team"];
        wait 0.5;
        common_scripts\utility::flag_set( "ks_vertical_alarm_on" );
        thread ks_vertical_warning_alarm();
        thread ks_vertical_warning_lights();
        thread ks_vertical_firing_fx();
        wait 2;
        common_scripts\utility::flag_clear( "ks_vertical_alarm_on" );
        ks_vertical_fire();
        common_scripts\utility::flag_clear( "boneyard_killstreak_active" );

        if ( level.ks_vertical.uses == 0 )
        {
            common_scripts\utility::flag_clear( "boneyard_killstreak_captured" );
            objective_playermask_hidefromall( level.ks_vertical.ui_elem );
            level.ks_vertical.player = undefined;
            level.ks_vertical.team = undefined;
            thread boneyard_killstreak_enable( 100 );
        }
    }
}

boneyard_killstreak_ui_watcher( var_0, var_1 )
{
    level endon( "boneyard_killstreak_captured" );
    common_scripts\utility::flag_clear( "boneyard_killstreak_can_kill" );
    thread boneyard_killstreak_ui_on( var_0 );

    for (;;)
    {
        var_2 = var_0.dam getistouchingentities( level.characters );
        var_3 = 0;

        if ( level.teambased )
        {
            foreach ( var_5 in var_2 )
            {
                if ( maps\mp\_utility::isreallyalive( var_5 ) && var_5.pers["team"] != var_0.team )
                {
                    var_3 = 1;
                    break;
                }
            }
        }
        else
        {
            foreach ( var_5 in var_2 )
            {
                if ( maps\mp\_utility::isreallyalive( var_5 ) && ( var_5 != var_0.player || isdefined( var_5.owner ) && var_5.owner != var_0.player ) )
                {
                    var_3 = 1;
                    break;
                }
            }
        }

        if ( var_0.ui_state != var_3 )
        {
            var_0.ui_state = var_3;
            objective_icon( var_0.ui_elem, var_0.ui_icon[var_3] );

            if ( var_3 > 0 )
                common_scripts\utility::flag_set( "boneyard_killstreak_can_kill" );
            else
                common_scripts\utility::flag_clear( "boneyard_killstreak_can_kill" );
        }

        wait( var_1 );
    }
}

boneyard_killstreak_ui_on( var_0 )
{
    var_1 = var_0.player getentitynumber();
    objective_playermask_showto( var_0.ui_elem, var_1 );
    wait 0.2;
    objective_playermask_hidefromall( level.ks_vertical.ui_elem );
    wait 0.3;
    objective_playermask_showto( var_0.ui_elem, var_1 );
    wait 0.2;
    objective_playermask_hidefromall( level.ks_vertical.ui_elem );
    wait 0.3;
    objective_playermask_showto( var_0.ui_elem, var_1 );
}

ks_vertical_fire()
{
    level endon( "game_ended" );
    common_scripts\utility::flag_set( "ks_vertical_firing" );
    badplace_brush( "bad_vert_fire", 10, level.ks_vertical.dam, "allies", "axis" );

    for ( var_0 = 0; var_0 < 20; var_0++ )
    {
        wait 0.5;
        maps\mp\gametypes\_hostmigration::waittillhostmigrationdone();
        var_1 = level.ks_vertical.player;

        if ( !isdefined( level.ks_vertical.player ) || !isplayer( level.ks_vertical.player ) )
            var_1 = undefined;

        thread damage_characters( level.ks_vertical, var_1, 90 );
        thread damage_targets( level.ks_vertical, var_1, level.remote_uav, 150 );
        thread damage_targets( level.ks_vertical, var_1, level.placedims, 150 );
        thread damage_targets( level.ks_vertical, var_1, level.uplinks, 150 );
        thread damage_targets( level.ks_vertical, var_1, level.turrets, 150 );
        thread damage_targets( level.ks_vertical, var_1, level.balldrones, 150 );
        thread damage_targets( level.ks_vertical, var_1, level.mines, 150 );
        thread damage_targets( level.ks_vertical, var_1, level.deployable_box["deployable_vest"], 150 );
        thread damage_targets( level.ks_vertical, var_1, level.deployable_box["deployable_ammo"], 150 );

        foreach ( var_3 in level.ks_vertical.destructibles )
            radiusdamage( var_3, 1, 45, 45, var_1 );
    }

    if ( !isdefined( level.exploder_queue ) || !isdefined( level.exploder_queue[108] ) || gettime() - level.exploder_queue[108].time > 25000 )
    {
        maps\mp\mp_boneyard_ns::mp_exploder( 108 );
        thread sound_fire_loops();
    }

    common_scripts\utility::flag_clear( "ks_vertical_firing" );
}

sound_fire_loops()
{
    var_0 = spawn( "script_origin", ( 574, 228, -110 ) );
    var_1 = spawn( "script_origin", ( 533, -7, -118 ) );
    var_2 = spawn( "script_origin", ( 264, 221, -101 ) );
    var_3 = spawn( "script_origin", ( 299, 1, -109 ) );
    var_4 = spawn( "script_origin", ( 574, 228, -110 ) );
    var_5 = spawn( "script_origin", ( 533, -7, -118 ) );
    var_6 = spawn( "script_origin", ( 264, 221, -101 ) );
    var_7 = spawn( "script_origin", ( 299, 1, -109 ) );
    var_0 playloopsound( "fire_small_01" );
    var_1 playloopsound( "fire_small_01" );
    var_2 playloopsound( "fire_small_01" );
    var_3 playloopsound( "fire_small_01" );
    wait 24.8;
    var_4 playsound( "fire_small_out" );
    var_5 playsound( "fire_small_out" );
    var_6 playsound( "fire_small_out" );
    var_7 playsound( "fire_small_out" );
    wait 0.2;
    var_0 stoploopsound();
    var_1 stoploopsound();
    var_2 stoploopsound();
    var_3 stoploopsound();
    wait 0.1;
    var_0 delete();
    var_1 delete();
    var_2 delete();
    var_3 delete();
}

damage_characters( var_0, var_1, var_2 )
{
    var_3 = var_0.dam getistouchingentities( level.characters );

    foreach ( var_5 in var_3 )
    {
        if ( can_kill_character( var_0, var_5 ) )
        {
            if ( isplayer( var_5 ) )
            {
                if ( isdefined( var_0.player ) && var_5 == var_0.player )
                    var_5 maps\mp\gametypes\_damage::finishplayerdamagewrapper( var_0.inflictor, var_1, var_2, 0, "MOD_EXPLOSIVE", "none", var_5.origin, ( 0, 0, 1 ), "none", 0, 0 );
                else
                    var_5 dodamage( var_2, var_0.inflictor.origin, var_1, var_0.inflictor, "MOD_EXPLOSIVE" );
            }
            else if ( isdefined( var_5.owner ) && var_5.owner == var_0.player )
                var_5 maps\mp\agents\_agents::on_agent_player_damaged( undefined, undefined, var_2, 0, "MOD_EXPLOSIVE", "none", var_5.origin, ( 0, 0, 1 ), "none", 0 );
            else
                var_5 maps\mp\agents\_agents::on_agent_player_damaged( var_0.inflictor, var_1, var_2, 0, "MOD_EXPLOSIVE", "none", var_5.origin, ( 0, 0, 1 ), "none", 0 );
        }
        else if ( isdefined( var_5 ) && maps\mp\_utility::isreallyalive( var_5 ) )
        {
            if ( isplayer( var_5 ) )
                var_5 maps\mp\gametypes\_damage::callback_playerdamage( undefined, undefined, 1, 0, "MOD_EXPLOSIVE", "none", var_5.origin, ( 0, 0, 1 ), "none", 0 );
            else
                var_5 maps\mp\agents\_agents::on_agent_player_damaged( undefined, undefined, 1, 0, "MOD_EXPLOSIVE", "none", var_5.origin, ( 0, 0, 1 ), "none", 0 );
        }

        wait 0.05;
    }
}

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

    if ( level.teambased )
    {
        if ( isdefined( var_0.player ) && var_1 == var_0.player )
            return 1;
        else if ( isdefined( var_0.player ) && isdefined( var_1.owner ) && var_1.owner == var_0.player )
            return 1;
        else if ( isdefined( var_0.team ) && var_1.team == var_0.team )
            return 0;
    }

    return 1;
}

damage_targets( var_0, var_1, var_2, var_3 )
{
    var_4 = "MOD_EXPLOSIVE";
    var_5 = "none";
    var_6 = ( 0, 0, 0 );
    var_7 = ( 0, 0, 0 );
    var_8 = "";
    var_9 = "";
    var_10 = "";
    var_11 = undefined;
    var_12 = var_0.dam getistouchingentities( var_2 );

    foreach ( var_14 in var_12 )
    {
        if ( !isdefined( var_14 ) )
            continue;

        if ( isdefined( var_14.owner ) && var_14.owner == var_1 )
            var_14 notify( "damage", var_3, var_1, var_6, var_7, var_4, var_8, var_9, var_10, var_11, var_5 );
        else if ( level.teambased && isdefined( var_0.team ) && isdefined( var_14.team ) && var_14.team == var_0.team )
            continue;

        var_14 notify( "damage", var_3, var_1, var_6, var_7, var_4, var_8, var_9, var_10, var_11, var_5 );
        wait 0.05;
    }
}

ks_vertical_warning_alarm()
{
    level.ks_vertical.sfx playsound( "emt_boneyard_ns_close_alarm_01" );
    thread sound_vertical_fire_logic();
}

sound_vertical_fire_logic()
{
    level.alarm1_c playsound( "scn_fire_event_02" );
    wait 1.76;
    level.alarm1_cp1 playsound( "scn_fire_event_02b" );
    thread sound_fire_loop_logic();
    wait 10;
    level.alarm1_cp2 playsound( "scn_fire_event_02c" );
}

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

    while ( common_scripts\utility::flag( "boneyard_killstreak_active" ) || common_scripts\utility::flag( "boneyard_killstreak_endgame" ) )
    {
        if ( level.teambased && isdefined( level.ks_vertical.team ) )
        {
            foreach ( var_1 in level.players )
            {
                if ( var_1.pers["team"] == level.ks_vertical.team )
                {
                    activateclientexploder( 19, var_1 );
                    continue;
                }

                activateclientexploder( 18, var_1 );
            }
        }
        else
            maps\mp\mp_boneyard_ns::mp_exploder( 18 );

        wait 0.5;
    }
}

ks_vertical_firing_fx()
{
    maps\mp\mp_boneyard_ns::mp_exploder( 91 );
    wait 2;
    maps\mp\mp_boneyard_ns::mp_exploder( 90 );

    for ( var_0 = 0; var_0 < 5; var_0++ )
    {
        maps\mp\mp_boneyard_ns::mp_exploder( 92 );
        wait 2;
    }

    maps\mp\mp_boneyard_ns::mp_exploder( 93 );
}

ks_manage_spawns()
{
    for (;;)
    {
        common_scripts\utility::flag_wait( "boneyard_killstreak_captured" );
        level.dynamicspawns = ::filter_spawn_points;
        common_scripts\utility::flag_waitopen( "boneyard_killstreak_captured" );
        level.dynamicspawns = undefined;
    }
}

filter_spawn_points( var_0 )
{
    var_1 = [];

    foreach ( var_3 in var_0 )
    {
        if ( isdefined( var_3.script_noteworthy ) && var_3.script_noteworthy == "ks_danger_spawn" )
            continue;

        var_1[var_1.size] = var_3;
    }

    return var_1;
}
