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

#using_animtree("animated_props");

precache()
{
    level.heli_anims = [];
    level.heli_anims["heli_flyby_01"] = "mp_warhawk_heli_flyby_01";
    level.heli_anims["heli_flyby_02"] = "mp_warhawk_heli_flyby_02";
    level.heli_anims_length = [];
    level.heli_anims_length["heli_flyby_01"] = getanimlength( %mp_warhawk_heli_flyby_01 );
    level.heli_anims_length["heli_flyby_02"] = getanimlength( %mp_warhawk_heli_flyby_02 );
    level.air_raid_active = 0;
    precachempanim( "mp_warhawk_metal_door_open_in" );
    precachempanim( "mp_warhawk_metal_door_open_in_loop" );
    precachempanim( "mp_warhawk_metal_door_open_out" );
    precachempanim( "mp_warhawk_metal_door_open_out_loop" );
    precachempanim( "mp_frag_metal_door_chain" );
    common_scripts\utility::flag_init( "chain_broken" );
}

random_destruction_wait( var_0, var_1 )
{
    level endon( "random_destruction" );

    if ( !level.createfx_enabled )
    {
        var_2 = randomfloatrange( var_0, var_1 );
        wait( var_2 );
        level.next_random_mortar_index++;
        level notify( "random_destruction", level.randomdestructionindicies[level.next_random_mortar_index - 1] );
    }
}

random_destruction( var_0, var_1 )
{
    level endon( "stop_dynamic_events" );
    common_scripts\utility::waitframe();

    if ( !isdefined( level.destructible_array ) )
        level.destructible_array = common_scripts\utility::getstructarray( "random_destructible", "targetname" );

    random_destruction_preprocess( level.destructible_array );

    for (;;)
    {
        thread random_destruction_wait( var_0, var_1 );
        level waittill( "random_destruction", var_2 );

        if ( !isdefined( var_2 ) )
            continue;

        var_2 = var_2 - 1;

        if ( level.destructible_array[var_2].fired )
        {
            random_destruction_restore( var_2 );
            level.destructible_array[var_2].fired = 0;
        }
        else
        {
            random_destruction_destroy( var_2 );
            level.destructible_array[var_2].fired = 1;
        }

        if ( level.next_random_mortar_index >= level.randomdestructionindicies.size )
            break;
    }
}

random_destruction_restore( var_0 )
{
    var_1 = getentarray( level.destructible_array[var_0].target, "targetname" );

    foreach ( var_3 in var_1 )
    {
        switch ( var_3.script_noteworthy )
        {
            case "destructible_before":
                var_3 common_scripts\utility::trigger_on();
                break;
            case "destructible_after":
                var_3 common_scripts\utility::trigger_off();
                break;
            case "undefined":
            default:
                break;
        }
    }
}

exploders_explode_for_late_player()
{
    self endon( "disconnect" );

    if ( isdefined( level.exploders_cached ) )
    {
        var_0 = 0;

        foreach ( var_2 in level.exploders_cached )
        {
            common_scripts\utility::exploder( var_2.index, self, var_2.time );
            var_0++;

            if ( var_0 >= 4 )
            {
                wait 0.05;
                var_0 = 0;
            }
        }
    }
}

exploders_watch_late_players()
{
    for (;;)
    {
        level waittill( "connected", var_0 );
        var_0 thread exploders_explode_for_late_player();
    }
}

exploder_cache( var_0 )
{
    if ( !isdefined( level.exploders_cached ) )
        level.exploders_cached = [];

    var_1 = spawnstruct();
    var_1.index = var_0;
    var_1.time = level.time;
    level.exploders_cached[level.exploders_cached.size] = var_1;
}

random_destruction_destroy( var_0 )
{
    if ( !level.destructible_array[var_0].mortar_starts.size || !level.destructible_array[var_0].mortar_ends.size )
        return;

    var_1 = common_scripts\utility::random( level.destructible_array[var_0].mortar_starts );
    var_2 = common_scripts\utility::random( level.destructible_array[var_0].mortar_ends );
    random_mortars_fire( var_1.origin, var_2.origin, var_1.script_duration, undefined, 0, 0 );
    var_3 = getentarray( level.destructible_array[var_0].target, "targetname" );

    foreach ( var_5 in var_3 )
    {
        switch ( var_5.script_noteworthy )
        {
            case "destructible_before":
                var_5 maps\mp\_movers::notify_moving_platform_invalid();
                var_5 common_scripts\utility::trigger_off();
                break;
            case "destructible_after":
                var_5 common_scripts\utility::trigger_on();
                break;
            case "undefined":
            default:
                break;
        }
    }

    common_scripts\utility::exploder( 50 + var_0 );
    exploder_cache( 50 + var_0 );
    var_7 = common_scripts\utility::getstructarray( level.destructible_array[var_0].target, "targetname" );

    foreach ( var_5 in var_7 )
    {
        if ( isdefined( var_5.script_noteworthy ) && isdefined( level._effect[var_5.script_noteworthy] ) )
            playfx( level._effect[var_5.script_noteworthy], var_5.origin );
    }

    if ( isdefined( level.destructible_array[var_0].script_parameters ) )
    {
        var_10 = strtok( level.destructible_array[var_0].script_parameters, ";" );

        foreach ( var_12 in var_10 )
        {
            var_13 = strtok( var_12, "=" );

            if ( var_13.size != 2 )
                continue;

            switch ( var_13[0] )
            {
                case "play_sound":
                    playsoundatpos( level.destructible_array[var_0].origin, var_13[1] );
                    break;
                case "play_loopsound":
                    level.destructible_array[var_0].loop_sound_ent playloopsound( var_13[1] );
                    break;
                case "play_fx":
                    playfx( level._effect[var_13[1]], level.destructible_array[var_0].origin );
                    break;
                default:
                    break;
            }
        }
    }
}

random_destruction_preprocess( var_0 )
{
    level.next_random_mortar_index = 0;
    level.randomdestructionindicies = [];

    for ( var_1 = 0; var_1 < var_0.size; var_1++ )
        level.randomdestructionindicies[var_1] = var_1 + 1;

    level.randomdestructionindicies = common_scripts\utility::array_randomize( level.randomdestructionindicies );

    foreach ( var_3 in var_0 )
    {
        var_3.mortar_starts = [];
        var_3.mortar_ends = [];
        var_3.fired = 0;
        var_4 = [];
        var_5 = undefined;
        var_6 = undefined;
        var_7 = undefined;
        var_8 = undefined;
        var_9 = common_scripts\utility::getstructarray( var_3.target, "targetname" );

        foreach ( var_11 in var_9 )
        {
            switch ( var_11.script_noteworthy )
            {
                case "before_start_origin":
                    var_5 = var_11.origin;
                    break;
                case "before_end_origin":
                    var_6 = var_11.origin;
                    break;
                case "after_start_origin":
                    var_7 = var_11.origin;
                    break;
                case "after_end_origin":
                    var_8 = var_11.origin;
                    break;
                case "mortar_start":
                    var_3.mortar_starts[var_3.mortar_starts.size] = var_11;
                    break;
                case "mortar_end":
                    var_3.mortar_ends[var_3.mortar_ends.size] = var_11;
                    break;
                default:
                    break;
            }
        }

        var_13 = undefined;
        var_14 = undefined;

        if ( isdefined( var_5 ) && isdefined( var_6 ) )
            var_13 = var_6 - var_5;

        if ( isdefined( var_7 ) && isdefined( var_8 ) )
            var_14 = var_8 - var_7;

        var_15 = getentarray( var_3.target, "targetname" );

        foreach ( var_11 in var_15 )
        {
            switch ( var_11.script_noteworthy )
            {
                case "destructible_before":
                    var_4[var_4.size] = var_11;

                    if ( isdefined( var_13 ) )
                        var_11.origin = var_11.origin + var_13;

                    break;
                case "destructible_after":
                    if ( isdefined( var_14 ) )
                        var_11.origin = var_11.origin + var_14;

                    var_11 common_scripts\utility::trigger_off();
                    break;
                case "loop_sound_ent":
                    var_3.loop_sound_ent = var_11;
                    break;
                case "delete":
                    var_11 delete();
                    break;
                default:
                    break;
            }
        }

        if ( var_3.mortar_starts.size == 0 )
            var_3.mortar_starts = common_scripts\utility::getstructarray( "air_raid", "targetname" );

        if ( var_3.mortar_ends.size == 0 )
            var_3.mortar_ends = var_4;
    }
}

plane_crash()
{

}

plane_crash_init()
{
    if ( !isdefined( self.target ) )
        return;

    if ( !isdefined( self.script_animation ) || !isdefined( level.plane_crash_anims[self.script_animation] ) )
        return;

    var_0 = getentarray( self.target, "targetname" );
    var_1 = common_scripts\utility::getstructarray( self.target, "targetname" );
    var_2 = common_scripts\utility::array_combine( var_0, var_1 );

    foreach ( var_4 in var_2 )
    {
        if ( !isdefined( var_4.script_noteworthy ) )
            continue;

        switch ( var_4.script_noteworthy )
        {
            case "plane":
                self.plane = var_4;
                thread run_func_on_notify( "end", ::delete_ent, var_4 );
                break;
            case "scene_node":
                self.scene_node = var_4;

                if ( !isdefined( self.scene_node.angles ) )
                    self.scene_node.angles = ( 0, 0, 0 );

                break;
            case "show":
                var_4 hide();
                thread run_func_on_notify( var_4.script_parameters, ::show_ent, var_4 );
                break;
            case "show_trigger":
                var_4 common_scripts\utility::trigger_off();
                thread run_func_on_notify( var_4.script_parameters, ::show_trigger, var_4 );
                break;
            case "kill_players":
                thread run_func_on_notify( var_4.script_parameters, ::kill_players_touching_ent, var_4 );
                break;
            case "delete":
                thread run_func_on_notify( var_4.script_parameters, ::delete_ent, var_4 );
                break;
            case "fx":
                thread run_func_on_notify( var_4.script_parameters, ::play_fx, var_4 );
                break;
            case "trigger_fx":
                if ( isdefined( var_4.script_fxid ) && isdefined( level._effect[var_4.script_fxid] ) )
                {
                    var_5 = spawnfx( level._effect[var_4.script_fxid], var_4.origin, anglestoforward( var_4.angles ) );
                    thread run_func_on_notify( var_4.script_parameters, ::trigger_fx, var_5 );
                }

                break;
            default:
                break;
        }
    }

    if ( self.script_animation == "mp_warhawk_osprey_crash" )
    {
        thread run_func_on_notify( "start", ::play_fx_on_tag, "osprey_trail", "tag_engine_ri_fx2", self.plane );
        thread run_func_on_notify( "crash_sound", ::play_sound_on_ent, self.plane, "osprey_crash" );
        thread run_func_on_notify( "hit_watertower", ::play_sound_at_ent, self.plane, "osprey_hit_tower" );
        thread run_func_on_notify( "hit_ground", ::stop_fx_on_tag, "osprey_trail", "tag_engine_ri_fx2", self.plane );
    }
}

plan_crash_run( var_0 )
{
    level endon( "stop_dynamic_events" );

    if ( isdefined( var_0 ) )
        wait( var_0 );

    if ( isdefined( self.scene_node ) )
    {
        self.plane.origin = self.scene_node.origin;
        self.plane.angles = self.scene_node.angles;
    }

    self.plane scriptmodelplayanimdeltamotion( self.script_animation );
    thread run_anim_events( level.plane_crash_anims_events[self.script_animation] );
}

create_anim_event( var_0, var_1 )
{
    var_2 = spawnstruct();
    var_2.time = var_1;
    var_2.note = var_0;
    var_2.done = 0;
    return var_2;
}

run_anim_events( var_0 )
{
    var_1 = gettime();

    for (;;)
    {
        foreach ( var_3 in var_0 )
        {
            if ( var_3.done )
                continue;

            if ( ( gettime() - var_1 ) / 1000 >= var_3.time )
            {
                self notify( var_3.note );
                var_3.done = 1;

                if ( var_3.note == "end" )
                    return;
            }
        }

        wait 0.05;
    }
}

run_func_on_notify( var_0, var_1, var_2, var_3, var_4 )
{
    self waittill( var_0 );

    if ( isdefined( var_4 ) )
        self thread [[ var_1 ]]( var_2, var_3, var_4 );
    else if ( isdefined( var_3 ) )
        self thread [[ var_1 ]]( var_2, var_3 );
    else if ( isdefined( var_2 ) )
        self thread [[ var_1 ]]( var_2 );
    else
        self thread [[ var_1 ]]();
}

show_ent( var_0 )
{
    var_0 show();
}

show_trigger( var_0 )
{
    var_0 common_scripts\utility::trigger_on();
}

delete_ent( var_0 )
{
    var_0 delete();
}

play_sound_on_ent( var_0, var_1 )
{
    var_0 playsound( var_1 );
}

play_sound_at_ent( var_0, var_1 )
{
    playsoundatpos( var_0.origin, var_1 );
}

kill_players_touching_ent( var_0 )
{
    foreach ( var_2 in level.players )
    {
        if ( var_2 istouching( var_0 ) )
            var_2 maps\mp\_movers::mover_suicide();
    }
}

play_fx( var_0 )
{
    if ( !isdefined( var_0.script_fxid ) || !isdefined( level._effect[var_0.script_fxid] ) )
        return;

    playfx( level._effect[var_0.script_fxid], var_0.origin, anglestoforward( var_0.angles ) );
}

trigger_fx( var_0 )
{
    triggerfx( var_0 );
}

play_fx_on_tag( var_0, var_1, var_2 )
{
    playfxontag( common_scripts\utility::getfx( var_0 ), var_2, var_1 );
}

stop_fx_on_tag( var_0, var_1, var_2 )
{
    stopfxontag( common_scripts\utility::getfx( var_0 ), var_2, var_1 );
}

random_mortars_fire( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    var_6 = ( 0, 0, -800 );

    if ( !isdefined( var_2 ) )
        var_2 = randomfloatrange( 3, 4 );

    var_7 = trajectorycalculateinitialvelocity( var_0, var_1, var_6, var_2 );

    if ( isdefined( var_4 ) && var_4 )
    {
        var_8 = trajectorycomputedeltaheightattime( var_7[2], -1 * var_6[2], var_2 / 2 );
        var_9 = ( var_1 - var_0 ) / 2 + var_0 + ( 0, 0, var_8 );

        if ( bullettracepassed( var_9, var_1, 0, undefined ) )
        {
            thread random_mortars_fire_run( var_0, var_1, var_2, var_3, var_7, var_5 );
            return 1;
        }
        else
            return 0;
    }

    random_mortars_fire_run( var_0, var_1, var_2, var_3, var_7, var_5 );
}

random_mortars_fire_run( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    var_6 = 350;
    var_7 = random_mortars_get_model( var_0 );
    var_7.origin = var_0;
    var_7.in_use = 1;
    common_scripts\utility::waitframe();
    playfxontag( common_scripts\utility::getfx( "random_mortars_trail" ), var_7, "tag_fx" );
    var_7.angles = vectortoangles( var_4 ) * ( -1, 1, 1 );
    maps\mp\_utility::delaythread( var_2 - 2.0, ::random_mortars_incoming_sound, var_1 );
    var_7 movegravity( var_4, var_2 - 0.05 );
    var_7 waittill( "movedone" );

    if ( level.createfx_enabled && !isdefined( level.players ) )
        level.players = [];

    if ( isdefined( var_3 ) )
        var_7 radiusdamage( var_1, 250, 750, 500, var_3, "MOD_EXPLOSIVE", "warhawk_mortar_mp" );
    else
        var_7 radiusdamage( var_1, 140, 5, 5, undefined, "MOD_EXPLOSIVE", "warhawk_mortar_mp" );

    playrumbleonposition( "artillery_rumble", var_1 );

    foreach ( var_9 in level.players )
    {
        if ( var_9 maps\mp\_utility::isusingremote() )
            continue;

        if ( distance( var_1, var_9.origin ) > var_6 )
            continue;

        if ( var_9 damageconetrace( var_1 ) )
            var_9 thread maps\mp\gametypes\_shellshock::dirteffect( var_1 );
    }

    if ( var_5 )
        playfx( common_scripts\utility::getfx( "mortar_impact_00" ), var_1 );

    var_7 delete();
}

random_mortars_incoming_sound( var_0 )
{
    playsoundatpos( var_0, "mortar_incoming" );
}

random_mortars_get_target()
{
    var_0 = common_scripts\utility::getstructarray( self.target, "targetname" );

    if ( var_0.size == 0 )
        return undefined;

    var_1 = common_scripts\utility::random( var_0 );
    var_2 = var_1.origin;

    if ( isdefined( var_1.radius ) )
    {
        var_3 = anglestoforward( ( 0, randomfloatrange( 0, 360 ), 0 ) );
        var_2 = var_2 + var_3 * randomfloatrange( 0, var_1.radius );
    }

    return var_2;
}

random_mortars_get_model( var_0 )
{
    var_1 = spawn( "script_model", var_0 );
    var_1 setmodel( "projectile_rpg7" );
    return var_1;
}

draw_move_path()
{
    self endon( "movedone" );

    for (;;)
    {
        var_0 = self.origin;
        wait 0.5;
        thread maps\mp\_utility::drawline( var_0, self.origin, 600, ( 1, 0, 0 ) );
    }
}

draw_model_path()
{
    self endon( "movedone" );
    var_0 = [];

    for (;;)
    {
        wait 0.5;
        var_1 = spawn( "script_model", self.origin );
        var_1 setmodel( self.model );
        var_1.angles = self.angles;
        var_0[var_0.size] = var_1;
    }

    wait 10;

    foreach ( var_1 in var_0 )
        var_1 delete();
}

jet_flyby()
{
    var_0 = [];
    var_1 = common_scripts\utility::getstructarray( "jet_flyby_radial", "targetname" );
    var_2 = common_scripts\utility::array_combine( var_0, var_1 );

    foreach ( var_4 in var_2 )
        var_4.radial = var_4.targetname == "jet_flyby_radial";

    for (;;)
    {
        wait( randomfloatrange( 10, 20 ) );
        var_2 = common_scripts\utility::array_randomize( var_2 );

        for ( var_6 = 0; var_6 < var_2.size; var_6++ )
        {
            var_4 = var_2[var_6];
            var_7 = undefined;
            var_8 = undefined;

            if ( var_4.radial )
            {
                var_7 = spawnstruct();
                var_8 = spawnstruct();

                if ( !isdefined( var_4.radius ) )
                    var_4.radius = 8000;

                var_9 = ( 0, randomfloatrange( 0, 360 ), 0 );
                var_10 = anglestoforward( var_9 );
                var_7.origin = var_4.origin - var_4.radius * var_10;
                var_7.angles = ( var_9[0] + 3, var_9[1], 0 );
                var_8.origin = var_4.origin + var_4.radius * var_10;
                var_8.angles = ( var_9[0] + 5, var_9[1], 0 );

                if ( isdefined( var_4.height ) )
                {
                    var_7.origin = var_7.origin + ( 0, 0, randomfloatrange( 0, var_4.height ) );
                    var_8.origin = var_8.origin + ( 0, 0, randomfloatrange( 0, var_4.height ) );
                }
            }
            else
            {
                var_11 = common_scripts\utility::getstructarray( var_4.target, "targetname" );
                var_12 = common_scripts\utility::random( var_11 );

                if ( !isdefined( var_12 ) )
                    continue;

                var_7 = var_4;
                var_8 = var_12;
            }

            var_13 = randomfloatrange( 1500, 1600 );
            var_14 = distance( var_7.origin, var_8.origin );
            var_15 = var_14 / var_13;
            var_16 = spawn( "script_model", var_7.origin );
            var_16.angles = var_8.angles;
            var_16 setmodel( "vehicle_pavelow" );
            common_scripts\utility::waitframe();
            var_16 playloopsound( "cobra_helicopter_dying_loop" );
            var_16 moveto( var_8.origin, var_15 );
            var_16 rotateto( var_8.angles, var_15 );
            var_16 waittill( "movedone" );
            var_16 delete();
            wait( randomfloatrange( 10, 20 ) );
        }
    }
}

air_raid()
{
    level endon( "stop_dynamic_events" );
    common_scripts\utility::waitframe();
    level.air_raids = common_scripts\utility::getstructarray( "air_raid", "targetname" );

    foreach ( var_1 in level.air_raids )
    {
        if ( !isdefined( var_1.radius ) )
            var_1.radius = 300;

        var_1.current_end = 0;
        var_1.ends = [];

        for ( var_2 = var_1; isdefined( var_2.target ); var_1.ends[var_1.ends.size] = var_2 )
        {
            var_2 = common_scripts\utility::getstruct( var_2.target, "targetname" );

            if ( !isdefined( var_2.radius ) )
                var_2.radius = 100;
        }
    }

    for (;;)
    {
        level.air_raid_active = 0;
        level.air_raid_team_called = "none";
        level waittill( "warhawk_mortar_killstreak", var_4 );
        level.air_raid_active = 1;
        level.air_raid_team_called = var_4.team;
        thread air_raid_siren( 10 );
        wait 3;
        air_raid_fire( 0.5, 0.6, 25, var_4 );
    }
}

air_raid_siren( var_0 )
{
    if ( !isdefined( level.air_raid_siren_ent ) )
        level.air_raid_siren_ent = getent( "air_raid_siren", "targetname" );

    if ( isdefined( level.air_raid_siren_ent ) )
        level.air_raid_siren_ent playsound( "air_raid_siren" );

    wait( var_0 );

    if ( isdefined( level.air_raid_siren_ent ) )
        level.air_raid_siren_ent stopsounds();
}

air_raid_fire( var_0, var_1, var_2, var_3 )
{
    var_4 = gettime() + var_2 * 1000;
    level.air_raids = common_scripts\utility::array_randomize( level.air_raids );
    var_5 = 0;

    while ( var_4 > gettime() )
    {
        var_6 = 12;
        var_7 = 0;

        foreach ( var_9 in level.players )
        {
            if ( !maps\mp\_utility::isreallyalive( var_9 ) )
                continue;

            if ( level.teambased )
            {
                if ( var_9.team == level.air_raid_team_called )
                    continue;
            }
            else if ( isdefined( var_3 ) && var_9 == var_3 )
                continue;

            if ( var_9.spawntime + 8000 > gettime() )
                continue;

            var_10 = var_9 getvelocity();
            var_11 = randomfloatrange( 3, 4 );
            var_12 = var_9.origin + var_10 * var_11;
            var_13 = getnodesinradiussorted( var_12, 100, 0, 60 );

            foreach ( var_15 in var_13 )
            {
                if ( nodeexposedtosky( var_15 ) )
                {
                    var_16 = common_scripts\utility::random( level.air_raids );

                    if ( random_mortars_fire( var_16.origin, var_15.origin, undefined, var_3, 1, 1 ) )
                    {
                        wait( randomfloatrange( var_0, var_1 ) );
                        var_7++;
                        break;
                    }
                }
            }
        }

        while ( var_7 < var_6 )
        {
            var_16 = level.air_raids[var_5];
            var_5++;

            if ( var_5 >= level.air_raids.size )
                var_5 = 0;

            var_19 = var_16.ends[var_16.current_end];
            var_16.current_end++;

            if ( var_16.current_end >= var_16.ends.size )
                var_16.current_end = 0;

            var_20 = random_point_in_circle( var_16.origin, var_16.radius );
            var_21 = random_point_in_circle( var_19.origin, var_19.radius );
            thread random_mortars_fire( var_20, var_21, undefined, var_3, 0, 1 );
            wait( randomfloatrange( var_0, var_1 ) );
            var_7++;
        }
    }
}

random_point_in_circle( var_0, var_1 )
{
    if ( var_1 > 0 )
    {
        var_2 = anglestoforward( ( 0, randomfloatrange( 0, 360 ), 0 ) );
        var_3 = randomfloatrange( 0, var_1 );
        var_0 = var_0 + var_2 * var_3;
    }

    return var_0;
}

heli_anims()
{
    level endon( "stop_dynamic_events" );
    var_0 = common_scripts\utility::getstructarray( "heli_anim", "targetname" );

    if ( var_0.size == 0 )
        return;

    var_1 = var_0.size;

    foreach ( var_3 in var_0 )
    {
        if ( !isdefined( var_3.angles ) )
            var_3.angles = ( 0, 0, 0 );
    }

    for (;;)
    {
        var_1++;

        if ( var_1 >= var_0.size )
        {
            var_0 = common_scripts\utility::array_randomize( var_0 );
            var_1 = 0;
        }

        wait( randomfloatrange( 10, 20 ) );

        if ( level.air_raid_active )
            continue;

        var_3 = var_0[var_1];

        if ( !isdefined( var_3.script_animation ) || !isdefined( level.heli_anims[var_3.script_animation] ) || !isdefined( level.heli_anims_length[var_3.script_animation] ) )
            continue;

        var_5 = spawn( "script_model", var_3.origin );
        var_5.angles = var_3.angles;
        var_5 setmodel( "vehicle_battle_hind" );
        var_5 playloopsound( "heli_flyover" );
        var_5 scriptmodelplayanimdeltamotion( level.heli_anims[var_3.script_animation] );
        wait( level.heli_anims_length[var_3.script_animation] );
        var_5 delete();
    }
}

chain_gate_trigger_wait_damage( var_0 )
{
    self endon( "chain_gate_trigger_damage" );
    var_0 waittill( "damage", var_1, var_2, var_3, var_4, var_5 );
    self notify( "chain_gate_trigger_damage", var_1, var_2, var_3, var_4, var_5 );
}

chain_gate()
{
    var_0 = getent( "left_gate", "targetname" );
    var_1 = getent( "right_gate", "targetname" );
    var_2 = getent( "lock", "targetname" );
    var_3 = getent( "gate_clip", "targetname" );
    var_4 = getentarray( "gate_trigger", "targetname" );
    var_5 = spawn( "script_model", var_0.origin );
    var_5 setmodel( "generic_prop_raven" );
    var_5.angles = var_0.angles;
    common_scripts\utility::waitframe();
    var_3 connectpaths();
    common_scripts\utility::waitframe();
    var_0 linkto( var_5, "j_prop_1" );
    var_1 linkto( var_5, "j_prop_2" );
    common_scripts\utility::waitframe();
    var_6 = ( 0, 0, 0 );
    var_7 = 0;

    foreach ( var_9 in var_4 )
    {
        maps\mp\_utility::add_to_bot_damage_targets( var_9 );
        var_6 = var_6 + var_9.origin;
        var_7++;
    }

    var_6 = var_6 / var_7;
    level thread bot_outside_gate_watch();
    var_2 scriptmodelplayanim( "mp_frag_metal_door_chain" );
    var_0 setcandamage( 0 );
    var_0 setcanradiusdamage( 0 );
    var_1 setcandamage( 0 );
    var_1 setcanradiusdamage( 0 );
    var_2 setcandamage( 0 );
    var_2 setcanradiusdamage( 0 );

    foreach ( var_9 in var_4 )
        thread chain_gate_trigger_wait_damage( var_9 );

    self waittill( "chain_gate_trigger_damage", var_13, var_14, var_15, var_16, var_17 );
    var_2 playsound( "scn_breach_gate_lock" );

    if ( isexplosivedamagemod( var_17 ) )
        var_15 = var_6 - var_16;

    var_18 = var_15[0] > 0;
    var_2 delete();

    foreach ( var_9 in var_4 )
    {
        maps\mp\_utility::remove_from_bot_damage_targets( var_9 );
        var_9 delete();
    }

    common_scripts\utility::flag_set( "chain_broken" );

    if ( var_18 )
        var_5 scriptmodelplayanimdeltamotion( "mp_warhawk_metal_door_open_in" );
    else
        var_5 scriptmodelplayanimdeltamotion( "mp_warhawk_metal_door_open_out" );

    var_0 playsound( "scn_breach_gate_open_left" );
    var_1 playsound( "scn_breach_gate_open_right" );
    wait 0.5;
    common_scripts\utility::waitframe();
    var_3 delete();
}

bot_outside_gate_watch()
{
    level endon( "chain_broken" );
    var_0 = getentarray( "gate_trigger", "targetname" );
    var_1 = getent( "near_gate_volume", "targetname" );

    for (;;)
    {
        if ( isdefined( level.participants ) )
        {
            foreach ( var_3 in level.participants )
            {
                if ( isai( var_3 ) && var_3 istouching( var_1 ) )
                    var_0[0] maps\mp\_utility::set_high_priority_target_for_bot( var_3 );
            }
        }

        wait 1.0;
    }
}
