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

bridge_main()
{
    bridge_precache();
    common_scripts\utility::waitframe();

    if ( getdvar( "r_reflectionProbeGenerate" ) == "1" )
        return;

    level.bridge_device = spawnstruct();
    level.bridge_device maps\mp\mp_ca_red_river_bridge_device::bridge_device_init();
    maps\mp\mp_ca_red_river_bridge_device::bridge_extras_init( level.bridge_device );
    level.bridge = spawnstruct();
    level.bridge bridge_init();
    level.bridge thread bridge_wait_explode();
}

bridge_precache()
{
    precachempanim( "mp_ca_red_river_bridge_01" );
    precachempanim( "mp_ca_red_river_bridge_02" );
    precachempanim( "mp_ca_red_river_bridge_03" );
}

#using_animtree("animated_props");

bridge_init()
{
    self.bridge_anim_time = 0.0;
    self.bridge_anim_time = max( self.bridge_anim_time, getanimlength( %mp_ca_red_river_bridge_01 ) );
    self.bridge_anim_time = max( self.bridge_anim_time, getanimlength( %mp_ca_red_river_bridge_02 ) );
    self.bridge_anim_time = max( self.bridge_anim_time, getanimlength( %mp_ca_red_river_bridge_03 ) );
    self.bridge_wholeents = getentarray( "bridge_whole", "targetname" );
    self.bridge_destroyedents = getentarray( "bridge_destroyed", "targetname" );
    bridge_hideparts( self.bridge_destroyedents );
    level.bridge_animated_models = getentarray( "bridge_animated_model", "targetname" );
    bridge_hideparts( level.bridge_animated_models );
    level.bridge_scriptables = getscriptablearray( "bridge_animated_model", "targetname" );

    foreach ( var_1 in level.bridge_scriptables )
        var_1 hide();

    level.bridgepathnodes = getent( "bridgePathNodes", "targetname" );
    clearpath( level.bridgepathnodes );
    level.destroypathnodes = getent( "destroyPathNodes", "targetname" );
    blockpath( level.destroypathnodes );
}

bridge_showparts( var_0 )
{
    foreach ( var_2 in var_0 )
    {
        var_2 show();
        var_2 solid();
    }
}

bridge_hideparts( var_0 )
{
    foreach ( var_2 in var_0 )
    {
        var_2 hide();
        var_2 notsolid();
        var_2 maps\mp\_movers::notify_moving_platform_invalid();
    }
}

bridge_wait_explode()
{
    level waittill( "bridge_trigger_explode" );
    level.bridge_device notify( "bridge_exploded" );
    maps\mp\_utility::playsoundonplayers( "scn_bridge_explo_2d" );
    thread common_scripts\utility::play_sound_in_space( "scn_bridge_explo_boom_left", ( -484, -733, 90 ) );
    thread common_scripts\utility::play_sound_in_space( "scn_bridge_explo_boom_right", ( 143, -824, 60 ) );
    bridge_play_fx();
    wait 0.15;

    if ( isdefined( self.bridge_destroyedents ) )
        bridge_showparts( self.bridge_destroyedents );

    if ( isdefined( self.bridge_wholeents ) )
        bridge_hideparts( self.bridge_wholeents );

    clearpath( level.destroypathnodes );
    blockpath( level.bridgepathnodes );

    foreach ( var_1 in level.bridge_animated_models )
    {
        var_1 show();
        var_1 solid();

        if ( isdefined( var_1.animation ) )
            var_1 scriptmodelplayanim( var_1.animation );
    }

    foreach ( var_4 in level.bridge_scriptables )
    {
        var_4 show();
        var_4 setscriptablepartstate( 0, "destroyed" );
    }

    wait( self.bridge_anim_time );
}

bridge_play_fx()
{
    common_scripts\utility::exploder( 11 );
    common_scripts\utility::exploder( 12 );
    playloopsoundatpos( ( -941.022, -712.704, -133.546 ), "emt_red_fire_explo_med1_lp" );
    playloopsoundatpos( ( -389.143, -886.295, -174.497 ), "emt_red_fire_explo_med2_lp" );
    playloopsoundatpos( ( -283.364, -531.226, 73.5775 ), "emt_red_fire_explo_med3_lp" );
    playloopsoundatpos( ( 103.789, -379.687, 116.523 ), "emt_red_fire_explo_lrg_pole_lp" );
    playloopsoundatpos( ( 244.235, -335.982, 33.3856 ), "emt_red_fire_explo_lrg_pole_lp" );
    playloopsoundatpos( ( -371.551, -1141.23, 27.313 ), "emt_red_fire_explo_sm_lp" );
    level thread bridge_fx_waitforconnections();
}

playloopsoundatpos( var_0, var_1 )
{
    common_scripts\utility::play_loopsound_in_space( var_1, var_0 );
}

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

    for (;;)
    {
        level waittill( "connected", var_0 );
        var_0 childthread bridge_fx_playonconnection();
    }
}

bridge_fx_playonconnection()
{
    self endon( "disconnect" );
    common_scripts\utility::waittill_any( "joined_team", "luinotifyserver" );
    common_scripts\utility::exploder( 11, self, 0 );

    if ( isdefined( level.nukedetonated ) )
    {
        self visionsetnakedforplayer( "", 0 );
        maps\mp\killstreaks\_nuke::setnukeaftermathvision( 0 );
    }
    else
        self visionsetnakedforplayer( "mp_ca_red_river_exploded", 0 );
}

clearpath( var_0 )
{
    if ( isdefined( var_0 ) )
    {
        var_0 connectpaths();
        var_0 hide();
        var_0 notsolid();
    }
}

blockpath( var_0 )
{
    if ( isdefined( var_0 ) )
    {
        var_0 show();
        var_0 solid();
        var_0 disconnectpaths();
    }
}
