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

intro_sequence_precache()
{
    common_scripts\utility::flag_init( "intro_sequence_complete" );

    switch ( level.script )
    {
        case "mp_alien_town":
            town_intro_precache();
            break;
        default:
            break;
    }
}

play_intro_sequence( var_0 )
{
    switch ( level.script )
    {
        case "mp_alien_town":
            level thread alien_town_intro( var_0 );
            break;
        default:
            break;
    }
}

town_intro_precache()
{
    alien_town_intro_precache_props();
    alien_town_intro_precache_characters();
}

alien_town_intro_precache_characters()
{
    precachempanim( "alien_town_intro_boss" );
    precachempanim( "alien_town_intro_pilot" );
}

alien_town_intro_precache_props()
{
    precachempanim( "alien_town_intro_chopper" );
    precachempanim( "alien_town_intro_drill" );
}

#using_animtree("animated_props");

alien_town_intro( var_0 )
{
    level waittill( "introscreen_over" );
    var_1 = ( 2830.46, -398.027, 707.026 );
    var_2 = getent( "helicoptercoll", "targetname" );
    var_3 = spawnhelicopter( var_0, var_1, var_2.angles + ( 0, 180, 0 ), "nh90_alien_intro", "tag_origin_vehicle" );
    var_4 = spawn( "script_model", var_1 );
    var_4.angles = var_2.angles;
    var_4 setmodel( "vehicle_nh90_interior2" );
    thread sfx_intro_heli_takeoff( var_3 );
    var_3 setmodel( "tag_origin_vehicle" );
    level.intro_heli = var_4;
    var_5 = spawn_model( "mp_body_us_rangers_assault_a_urban", var_4, "TAG_GUY1", ( 0, 0, 0 ) );
    var_5 setmodel( "mp_body_us_rangers_assault_a_urban" );
    var_6 = spawn_model( "head_mp_head_a", var_5, "J_spine4", ( 0, 0, 0 ) );
    var_7 = spawn_model( "mp_body_us_rangers_assault_a_urban", var_4, "tag_driver", ( 0, 0, 0 ) );
    var_8 = spawn_model( "head_mp_head_a", var_7, "J_spine4", ( 0, 0, 0 ) );
    var_9 = spawn_model( "mp_laser_drill", var_4, "TAG_GUY1", ( 0, 0, 0 ) );
    thread sfx_intro_npc_foley( var_5 );
    var_4 scriptmodelplayanimdeltamotion( "alien_town_intro_chopper" );
    var_7 scriptmodelplayanim( "alien_town_intro_pilot" );
    var_8 scriptmodelplayanim( "alien_town_intro_pilot" );
    var_5 scriptmodelplayanim( "alien_town_intro_boss" );
    var_6 scriptmodelplayanim( "alien_town_intro_boss" );
    var_9 scriptmodelplayanim( "alien_town_intro_drill" );
    thread sfx_intro_heli_drop_drill( var_9 );
    var_2 thread wait_to_delete();
    wait( getanimlength( %alien_town_intro_drill ) );
    var_9 scriptmodelclearanim();
    var_9 delete();
    level thread mp_alien_town_intro_drill_setup();
    level thread kill_heli( var_3 );
    wait( getanimlength( %alien_town_intro_chopper ) );
    var_7 scriptmodelclearanim();
    var_8 scriptmodelclearanim();
    var_5 scriptmodelclearanim();
    var_6 scriptmodelclearanim();
    var_4 scriptmodelclearanim();
    var_5 delete();
    var_6 delete();
    var_7 delete();
    var_8 delete();
    var_4 delete();
}

wait_to_delete()
{
    level endon( "game_ended" );
    var_0 = 16.5;
    wait( var_0 );
    self delete();
}

kill_heli( var_0 )
{
    wait 10;
    var_0 vehicle_setspeed( 50, 10 );
    var_0 setvehgoalpos( var_0.origin + ( 0, 0, 1600 ) );
    wait 10;
    var_0 delete();
}

spawn_model( var_0, var_1, var_2, var_3 )
{
    var_4 = spawn( "script_model", ( 0, 0, 0 ) );
    var_4 setmodel( var_0 );
    var_4.origin = var_1 gettagorigin( var_2 );
    var_4.angles = var_1 gettagangles( var_2 ) + var_3;
    var_4 linkto( var_1, var_2 );
    return var_4;
}

intro_sequence_enabled()
{
    if ( maps\mp\alien\_utility::is_chaos_mode() )
        return 0;

    return getdvarint( "scr_alien_intro", 1 ) == 1;
}

mp_alien_town_intro_drill_setup()
{
    level.initial_drill_origin = ( 2834.27, -243.002, 524.068 );
    level.initial_drill_angles = ( 0.995, -103.877, 1.287 );
    level notify( "spawn_intro_drill" );
    wait 8;
    common_scripts\utility::flag_set( "intro_sequence_complete" );
}

sfx_intro_heli_takeoff( var_0 )
{
    var_0 vehicle_turnengineoff();
    var_0 playsound( "alien_heli_intro_takeoff" );
}

sfx_intro_heli_drop_drill( var_0 )
{
    wait( getanimlength( %alien_town_intro_drill ) - 0.5 );
    var_0 playsound( "alien_heli_drill_drop" );
}

sfx_intro_npc_foley( var_0 )
{
    wait 2.53;
    var_0 playsound( "alien_heli_npc_foley" );
}
