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

init()
{
    while ( !isdefined( game["allies"] ) )
        wait 0.05;

    game["music"]["spawn_allies"] = maps\mp\gametypes\_teams::getteamvoiceprefix( "allies" ) + "spawn_music";
    game["music"]["defeat_allies"] = maps\mp\gametypes\_teams::getteamvoiceprefix( "allies" ) + "defeat_music";
    game["music"]["victory_allies"] = maps\mp\gametypes\_teams::getteamvoiceprefix( "allies" ) + "victory_music";
    game["music"]["winning_allies"] = "null";
    game["music"]["losing_allies"] = maps\mp\gametypes\_teams::getteamvoiceprefix( "allies" ) + "losing_music";
    game["voice"]["allies"] = maps\mp\gametypes\_teams::getteamvoiceprefix( "allies" ) + "1mc_";
    game["music"]["spawn_axis"] = maps\mp\gametypes\_teams::getteamvoiceprefix( "axis" ) + "spawn_music";
    game["music"]["defeat_axis"] = maps\mp\gametypes\_teams::getteamvoiceprefix( "axis" ) + "defeat_music";
    game["music"]["victory_axis"] = maps\mp\gametypes\_teams::getteamvoiceprefix( "axis" ) + "victory_music";
    game["music"]["winning_axis"] = "null";
    game["music"]["losing_axis"] = maps\mp\gametypes\_teams::getteamvoiceprefix( "axis" ) + "losing_music";
    game["voice"]["axis"] = maps\mp\gametypes\_teams::getteamvoiceprefix( "axis" ) + "1mc_";
    game["music"]["losing_time"] = "mp_time_running_out_losing";
    game["music"]["suspense"] = [];
    game["music"]["suspense"][game["music"]["suspense"].size] = "mp_suspense_01";
    game["music"]["suspense"][game["music"]["suspense"].size] = "mp_suspense_02";
    game["music"]["suspense"][game["music"]["suspense"].size] = "mp_suspense_03";
    game["music"]["suspense"][game["music"]["suspense"].size] = "mp_suspense_04";
    game["music"]["suspense"][game["music"]["suspense"].size] = "mp_suspense_05";
    game["music"]["suspense"][game["music"]["suspense"].size] = "mp_suspense_06";
    game["dialog"]["push_forward"] = "pushforward";
    game["music"]["nuke_music"] = "nuke_music";
    common_scripts\utility::flag_init( "alien_music_playing" );
    common_scripts\utility::flag_init( "exfil_music_playing" );
    level thread onplayerconnect();
    level thread musiccontroller();
    level thread ongameended();
    level initalienvosystem();
    level thread scriptable_vo_handler();
}

initalienvosystem()
{
    level.alien_vo_priority_level = [ "high", "medium", "low" ];
}

onplayerconnect()
{
    for (;;)
    {
        level waittill( "connected", var_0 );
        var_0 thread onplayerspawned();
        var_0 thread initandstartvosystem();
    }
}

onplayerspawned()
{
    self endon( "disconnect" );
    self waittill( "spawned_player" );

    if ( level.script != "mp_alien_last" && ( !level.splitscreen || level.splitscreen && !isdefined( level.playedstartingmusic ) ) )
    {
        if ( !self issplitscreenplayer() || self issplitscreenplayerprimary() )
            self playlocalsound( game["music"]["spawn_" + self.team] );

        if ( level.splitscreen )
            level.playedstartingmusic = 1;
    }
}

ongameended()
{
    level waittill( "game_win", var_0 );

    if ( level.teambased )
    {
        if ( level.splitscreen )
        {
            if ( var_0 == "allies" )
                wait 0.01;
            else if ( var_0 == "axis" )
            {
                foreach ( var_2 in level.players )
                {
                    if ( common_scripts\utility::flag( "alien_music_playing" ) )
                    {
                        var_2 stoplocalsound( "mp_suspense_01" );
                        var_2 stoplocalsound( "mp_suspense_02" );
                        var_2 stoplocalsound( "mp_suspense_03" );
                        var_2 stoplocalsound( "mp_suspense_04" );
                        var_2 stoplocalsound( "mp_suspense_05" );
                        var_2 stoplocalsound( "mp_suspense_06" );
                        var_2 stoplocalsound( "mus_alien_newwave" );
                        common_scripts\utility::flag_clear( "alien_music_playing" );
                    }
                }

                common_scripts\utility::flag_set( "alien_music_playing" );
                maps\mp\_utility::playsoundonplayers( game["music"]["defeat_allies"], "axis" );
            }
            else
                maps\mp\_utility::playsoundonplayers( game["music"]["nuke_music"] );
        }
        else if ( var_0 == "allies" )
            wait 0.01;
        else if ( var_0 == "axis" )
        {
            foreach ( var_2 in level.players )
            {
                if ( common_scripts\utility::flag( "alien_music_playing" ) )
                {
                    var_2 stoplocalsound( "mp_suspense_01" );
                    var_2 stoplocalsound( "mp_suspense_02" );
                    var_2 stoplocalsound( "mp_suspense_03" );
                    var_2 stoplocalsound( "mp_suspense_04" );
                    var_2 stoplocalsound( "mp_suspense_05" );
                    var_2 stoplocalsound( "mp_suspense_06" );
                    var_2 stoplocalsound( "mus_alien_newwave" );
                    common_scripts\utility::flag_clear( "alien_music_playing" );
                }
            }

            common_scripts\utility::flag_set( "alien_music_playing" );
            maps\mp\_utility::playsoundonplayers( game["music"]["victory_axis"], "axis" );
            maps\mp\_utility::playsoundonplayers( game["music"]["defeat_allies"], "allies" );
        }
        else
            maps\mp\_utility::playsoundonplayers( game["music"]["nuke_music"] );
    }
    else
    {
        foreach ( var_2 in level.players )
        {
            if ( var_2 issplitscreenplayer() && !var_2 issplitscreenplayerprimary() )
                continue;

            if ( var_2.pers["team"] != "allies" && var_2.pers["team"] != "axis" )
            {
                var_2 playlocalsound( game["music"]["nuke_music"] );
                continue;
            }

            if ( isdefined( var_0 ) && isplayer( var_0 ) && var_2 == var_0 )
            {
                var_2 playlocalsound( game["music"]["victory_" + var_2.pers["team"]] );
                continue;
            }

            if ( !level.splitscreen )
                var_2 playlocalsound( game["music"]["defeat_" + var_2.pers["team"]] );
        }
    }
}

musiccontroller()
{
    level endon( "game_ended" );
    thread suspensemusic();
    level waittill( "match_ending_soon", var_0 );

    if ( maps\mp\_utility::getwatcheddvar( "roundlimit" ) == 1 || game["roundsPlayed"] == maps\mp\_utility::getwatcheddvar( "roundlimit" ) - 1 )
    {
        if ( !level.splitscreen )
        {
            if ( var_0 == "time" )
            {
                if ( level.teambased )
                {
                    if ( game["teamScores"]["allies"] > game["teamScores"]["axis"] )
                        maps\mp\_utility::playsoundonplayers( game["music"]["losing_axis"], "axis" );
                    else if ( game["teamScores"]["axis"] > game["teamScores"]["allies"] )
                        maps\mp\_utility::playsoundonplayers( game["music"]["losing_allies"], "allies" );
                }
                else
                    maps\mp\_utility::playsoundonplayers( game["music"]["losing_time"] );
            }
            else if ( var_0 == "score" )
            {
                if ( level.teambased )
                {
                    if ( game["teamScores"]["allies"] > game["teamScores"]["axis"] )
                        maps\mp\_utility::playsoundonplayers( game["music"]["losing_axis"], "axis" );
                    else if ( game["teamScores"]["axis"] > game["teamScores"]["allies"] )
                        maps\mp\_utility::playsoundonplayers( game["music"]["losing_allies"], "allies" );
                }
                else
                {
                    var_1 = maps\mp\gametypes\_gamescore::gethighestscoringplayer();
                    var_2 = maps\mp\gametypes\_gamescore::getlosingplayers();
                    var_3[0] = var_1;
                    var_1 playlocalsound( game["music"]["winning_" + var_1.pers["team"]] );

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

                        var_5 playlocalsound( game["music"]["losing_" + var_5.pers["team"]] );
                    }
                }
            }

            level waittill( "match_ending_very_soon" );
        }
    }
    else if ( !level.hardcoremode )
        maps\mp\_utility::playsoundonplayers( game["music"]["losing_allies"] );
}

suspensemusic()
{
    level endon( "game_ended" );
    level endon( "match_ending_soon" );
    level endon( "nuke_went_off" );

    if ( isdefined( level.nosuspensemusic ) && level.nosuspensemusic )
        return;

    var_0 = game["music"]["suspense"].size;
    wait 120;

    for (;;)
    {
        wait( randomfloatrange( 60, 90 ) );

        if ( !common_scripts\utility::flag( "alien_music_playing" ) )
            maps\mp\_utility::playsoundonplayers( game["music"]["suspense"][randomint( var_0 )] );
    }
}

alienplayerpainbreathingsound()
{
    level endon( "game_ended" );
    self endon( "death" );
    self endon( "disconnect" );
    self endon( "joined_team" );
    self endon( "joined_spectators" );
    wait 2;

    for (;;)
    {
        wait 0.2;

        if ( shouldplaypainbreathingsound() )
        {
            if ( self hasfemalecustomizationmodel() )
                self playlocalsound( "Fem_breathing_hurt" );
            else
                self playlocalsound( "breathing_hurt_alien" );

            wait 0.784;
            wait( 0.1 + randomfloat( 0.8 ) );
        }
    }
}

shouldplaypainbreathingsound()
{
    if ( maps\mp\gametypes\aliens::ishealthregendisabled() || maps\mp\_utility::isusingremote() || isdefined( self.breathingstoptime ) && gettime() < self.breathingstoptime || self.health > self.maxhealth * self.healthregenmaxpercent * 0.55 )
        return 0;
    else
        return 1;
}

playmusicbeforereachlayer( var_0 )
{
    var_1 = "mus_alien_newwave";
    var_2 = 8.5;

    if ( var_0 <= var_2 )
        return;

    wait( var_0 - var_2 );

    if ( !common_scripts\utility::flag( "alien_music_playing" ) )
        level thread play_alien_music( var_1 );
}

playvofordowned( var_0 )
{
    if ( maps\mp\alien\_utility::isplayingsolo() )
        return;

    var_1 = var_0.vo_prefix + "downed";
    var_0 thread play_vo_on_player( var_1 );
}

playvoforrevived( var_0 )
{
    var_1 = var_0.vo_prefix + "reviving";
    var_0 thread play_vo_on_player( var_1 );
}

playvoforwavestart()
{
    wait 3;
    var_0 = maps\mp\alien\_utility::get_array_of_valid_players();

    if ( var_0.size < 1 )
        return;

    var_1 = common_scripts\utility::random( var_0 );
    var_2 = var_1.vo_prefix + "trouble";
    var_1 play_vo_on_player( var_2 );
}

playvoforbombdetonate( var_0 )
{
    level endon( "drill_planted" );
    level endon( "stop_post_hive_vo" );

    if ( isdefined( level.next_hive_vo_cycle ) && level.cycle_count < level.next_hive_vo_cycle )
        return;

    if ( !isdefined( level.next_hive_vo_cycle ) )
        level.next_hive_vo_cycle = level.cycle_count + randomintrange( 5, 8 );

    if ( isdefined( level.should_play_next_hive_vo_func ) )
    {
        if ( ![[ level.should_play_next_hive_vo_func ]]() )
            return;
    }

    var_1 = 0;

    while ( maps\mp\agents\_agent_utility::getactiveagentsoftype( "alien" ).size > 0 )
    {
        wait 1;
        var_1++;

        if ( var_1 > 30 )
            return;
    }

    if ( var_0 maps\mp\alien\_utility::is_door() || var_0 maps\mp\alien\_utility::is_door_hive() )
    {
        level notify( "dlc_vo_notify", "open_door_move", var_0 );
        wait 5;
    }
    else
    {
        play_vo_when_aliens_dead();
        wait 3;

        if ( randomint( 100 ) > 40 )
        {
            play_vo_for_get_to_crater();
            wait 5;
        }

        if ( level.cycle_count > 1 )
        {
            playposthivevo();
            wait 5;
        }
    }

    play_vo_for_grab_drill();
    wait 60;
    play_vo_for_next_hive( var_0 );
}

play_vo_for_next_hive( var_0 )
{
    var_1 = maps\mp\alien\_utility::get_array_of_valid_players();

    if ( var_1.size < 1 )
        return;

    var_2 = common_scripts\utility::random( var_1 );
    var_3 = var_2.vo_prefix + "attack_hive_next";
    var_2 play_vo_on_player( var_3, undefined, 10 );
}

play_vo_for_get_to_crater()
{
    var_0 = maps\mp\alien\_utility::get_array_of_valid_players();

    if ( var_0.size < 1 )
        return;

    var_1 = common_scripts\utility::random( var_0 );

    if ( isdefined( var_1 ) && isalive( var_1 ) )
    {
        var_2 = var_1.vo_prefix + "stayready";
        var_1 play_vo_on_player( var_2 );
    }
}

play_vo_for_grab_drill()
{
    var_0 = maps\mp\alien\_utility::get_array_of_valid_players();

    if ( var_0.size < 1 )
        return;

    foreach ( var_2 in var_0 )
    {
        if ( isdefined( level.drill_carrier ) && level.drill_carrier == var_2 )
            return;
    }

    var_2 = common_scripts\utility::random( var_0 );
    var_4 = var_2.vo_prefix + "get_drill";

    if ( !soundexists( var_4 ) )
        var_4 = var_2.vo_prefix + "order_grab_drill";

    var_2 play_vo_on_player( var_4, undefined, 10 );
}

playvoforintro()
{
    var_0 = maps\mp\alien\_utility::get_array_of_valid_players();

    if ( var_0.size < 1 )
        return;

    var_1 = common_scripts\utility::random( var_0 );

    if ( level.players.size == 1 )
    {
        var_2 = var_1.vo_prefix + "intro";
        var_1 thread play_solo_vo( var_2 );
        return;
    }

    foreach ( var_1 in var_0 )
    {
        if ( isdefined( level.drill_carrier ) && level.drill_carrier == var_1 )
            return;
    }

    var_2 = var_1.vo_prefix + "intro";
    var_1 play_vo_on_player( var_2 );
}

play_vo_when_aliens_dead()
{
    level endon( "drill_planted" );
    wait 1;
    var_0 = maps\mp\alien\_utility::get_array_of_valid_players();

    if ( var_0.size < 1 )
        return;

    var_1 = common_scripts\utility::random( var_0 );
    var_2 = [ "destroyed", "area_clear", "destroyed_hive_area" ];
    var_1 play_vo_on_player( var_1.vo_prefix + common_scripts\utility::random( var_2 ) );
}

playposthivevo()
{
    var_0 = maps\mp\alien\_utility::get_array_of_valid_players();

    if ( var_0.size < 1 )
        return;

    var_1 = common_scripts\utility::random( var_0 );
    var_1 play_vo_on_player( var_1.vo_prefix + "destroyed_hive" );
}

playvoforblockerhivereward()
{
    var_0 = [ "so_alien_plt_hivereward", "so_alien_plt_hivereward2" ];
    play_pilot_vo( common_scripts\utility::random( var_0 ) );
}

playvoforblockerhive()
{
    var_0 = maps\mp\alien\_utility::get_array_of_valid_players();

    if ( var_0.size > 0 )
    {
        var_1 = common_scripts\utility::random( var_0 );
        var_1 play_vo_on_player( var_1.vo_prefix + "explode_lung" );
    }

    var_2 = 0;

    while ( maps\mp\agents\_agent_utility::getactiveagentsoftype( "alien" ).size > 0 )
    {
        wait 1;
        var_2++;

        if ( var_2 > 30 )
            return;
    }

    var_3 = 0;
    var_0 = maps\mp\alien\_utility::get_array_of_valid_players();

    if ( var_0.size < 1 )
        return;

    var_1 = common_scripts\utility::random( var_0 );

    foreach ( var_1 in var_0 )
    {
        if ( var_1 hasweapon( "alienbomb_mp" ) )
            var_3 = 1;
    }

    if ( !var_3 )
    {
        var_6 = var_1.vo_prefix + "get_drill";
        var_1 play_vo_on_player( var_6 );
    }

    wait 1;

    if ( isdefined( var_1 ) && isalive( var_1 ) )
    {
        var_6 = var_1.vo_prefix + "stayready";
        var_1 play_vo_on_player( var_6 );
    }
}

playvoforbombplant( var_0 )
{
    if ( maps\mp\alien\_utility::isplayingsolo() )
        return;

    if ( !isdefined( var_0 ) || !isalive( var_0 ) || var_0 maps\mp\alien\_utility::is_in_laststand() )
        return;

    var_1 = var_0.vo_prefix + "place_drill";
    var_0 play_vo_on_player( var_1 );
}

playvoforspitterspawn( var_0 )
{
    wait 3;

    if ( !isdefined( var_0 ) )
        return;

    var_1 = maps\mp\alien\_utility::get_array_of_valid_players( 1, var_0.origin );

    if ( var_1.size < 1 )
        return;

    var_2 = var_1[0];
    var_3 = [ var_2.vo_prefix + "near_spitter", var_2.vo_prefix + "inbound_spitters" ];
    var_2 play_vo_on_player( common_scripts\utility::random( var_3 ) );
}

playvoforqueenspawn( var_0 )
{
    wait 3;

    if ( !isdefined( var_0 ) )
        return;

    var_1 = maps\mp\alien\_utility::get_array_of_valid_players( 1, var_0.origin );

    if ( var_1.size < 1 )
        return;

    var_2 = var_1[0];
    var_3 = [ var_2.vo_prefix + "near_queen", var_2.vo_prefix + "inbound_queen" ];
    var_2 play_vo_on_player( common_scripts\utility::random( var_3 ) );
}

playvoforincomingchopperblockerhive()
{
    var_0 = [ "so_alien_plt_morefirepower", "so_alien_blockerhive" ];
    play_pilot_vo( common_scripts\utility::random( var_0 ) );
}

playvoforprovidingcoveratblockerhive()
{
    var_0 = [ "so_alien_plt_providecover", "so_alien_plt_incomming2" ];
    play_pilot_vo( common_scripts\utility::random( var_0 ) );
}

playvoforchoppertakingdamage()
{
    var_0 = [ "so_alien_plt_providecover2", "so_alien_plt_scorpiondamage" ];
    play_pilot_vo( common_scripts\utility::random( var_0 ) );
}

playvoforchoppertakingtoomuchdamage()
{
    play_pilot_vo( "so_alien_plt_toomuchheat" );
}

handlefirstelitearrival( var_0 )
{
    if ( level.script != "mp_alien_town" || maps\mp\alien\_utility::is_chaos_mode() )
        return;

    foreach ( var_2 in level.players )
    {
        if ( common_scripts\utility::flag( "alien_music_playing" ) )
        {
            var_2 stoplocalsound( "mp_suspense_01" );
            var_2 stoplocalsound( "mp_suspense_02" );
            var_2 stoplocalsound( "mp_suspense_03" );
            var_2 stoplocalsound( "mp_suspense_04" );
            var_2 stoplocalsound( "mp_suspense_05" );
            var_2 stoplocalsound( "mp_suspense_06" );
            var_2 stoplocalsound( "mus_alien_newwave" );
            common_scripts\utility::flag_clear( "alien_music_playing" );
        }

        if ( !common_scripts\utility::flag( "exfil_music_playing" ) )
            level thread play_alien_music( "mus_alien_queen" );
    }
}

handlelastelitedeath( var_0 )
{

}

play_nuke_set_music()
{
    foreach ( var_1 in level.players )
    {
        if ( common_scripts\utility::flag( "alien_music_playing" ) )
        {
            var_1 stoplocalsound( "mp_suspense_01" );
            var_1 stoplocalsound( "mp_suspense_02" );
            var_1 stoplocalsound( "mp_suspense_03" );
            var_1 stoplocalsound( "mp_suspense_04" );
            var_1 stoplocalsound( "mp_suspense_05" );
            var_1 stoplocalsound( "mp_suspense_06" );
            var_1 stoplocalsound( "mus_alien_newwave" );
            var_1 stoplocalsound( "mus_alien_queen" );
            common_scripts\utility::flag_clear( "alien_music_playing" );
        }

        level thread play_alien_music( "mus_alien_nukeset" );
        common_scripts\utility::flag_set( "exfil_music_playing" );
    }
}

play_exfil_music()
{
    foreach ( var_1 in level.players )
    {
        if ( common_scripts\utility::flag( "alien_music_playing" ) )
        {
            var_1 stoplocalsound( "mus_alien_nukeset" );
            common_scripts\utility::flag_clear( "alien_music_playing" );
        }

        var_1 playlocalsound( "mus_alien_exfil" );
        common_scripts\utility::flag_set( "exfil_music_playing" );
    }
}

play2dspawnsound()
{

}

playvofordrilldamaged()
{
    if ( level.script == "mp_alien_last" )
    {
        level notify( "dlc_vo_notify", "conduit_attack" );
        return;
    }

    var_0 = 15000;
    var_1 = gettime();

    if ( !isdefined( level.next_bomb_damage_vo_time ) || level.next_bomb_damage_vo_time < var_1 )
    {
        level.next_bomb_damage_vo_time = var_1 + randomintrange( var_0, var_0 + 5000 );
        var_2 = maps\mp\alien\_utility::get_array_of_valid_players();
        var_3 = common_scripts\utility::random( var_2 );

        if ( !isdefined( var_3 ) )
            return;

        if ( maps\mp\alien\_utility::isplayingsolo() )
        {
            var_4 = var_3.vo_prefix + "drill_attacked";
            var_5 = var_4 + "_solo";

            if ( soundexists( var_5 ) )
            {
                var_3 thread play_solo_vo( var_4, undefined, 10 );
                return;
            }
        }

        var_4 = var_3.vo_prefix + "drill_attacked";
        var_3 play_vo_on_player( var_4, "high", 10 );
    }
}

playvofordrillhalfway()
{
    if ( level.script == "mp_alien_last" )
    {
        level notify( "dlc_vo_notify", "last_vo", "conduit_halfway" );
        return;
    }

    var_0 = maps\mp\alien\_utility::get_array_of_valid_players();

    if ( var_0.size < 1 )
        return;

    var_1 = common_scripts\utility::random( var_0 );
    var_2 = var_1.vo_prefix + "drill_halfway";
    var_1 play_vo_on_player( var_2, undefined, 10 );
}

playvofordrilloffline()
{
    return;
}

playvoforsentry( var_0, var_1 )
{
    if ( maps\mp\alien\_utility::isplayingsolo() )
        return;

    var_2 = "turret_generic";

    switch ( var_1 )
    {
        case "grenade":
            var_2 = "turret_grenade";
            break;
        case "minigun":
            var_2 = "turret_minigun";
            break;
        case "sentry":
            var_2 = "sentry";
    }

    var_3 = var_0.vo_prefix + "online_" + var_2;
    var_0 thread play_vo_on_player( var_3 );
}

playvoforims( var_0 )
{
    if ( maps\mp\alien\_utility::isplayingsolo() )
        return;

    var_1 = var_0.vo_prefix + "online_ims";
    var_0 play_vo_on_player( var_1 );
}

playvofordrone( var_0 )
{
    if ( maps\mp\alien\_utility::isplayingsolo() )
        return;

    var_1 = var_0.vo_prefix + "online_drone";
    var_0 play_vo_on_player( var_1 );
}

playvoformortarstrike( var_0 )
{
    if ( maps\mp\alien\_utility::isplayingsolo() )
        return;

    var_1 = var_0.vo_prefix + "inbound_mortar";
    var_0 play_vo_on_player( var_1 );
}

playvoforpredator( var_0 )
{
    if ( maps\mp\alien\_utility::isplayingsolo() )
        return;

    var_1 = var_0.vo_prefix + "inbound_missile";
    var_0 play_vo_on_player( var_1 );
}

playvoforteamammo( var_0 )
{
    var_1 = var_0.vo_prefix + "drop_ammo";

    if ( maps\mp\alien\_utility::isplayingsolo() )
    {
        if ( randomint( 100 ) > 50 )
            return;

        var_1 = var_0.vo_prefix + "equip_ammo_solo";
    }

    var_0 thread play_vo_on_player( var_1 );
}

playvoforspecialammo( var_0 )
{
    var_1 = var_0.vo_prefix + "ready_specialammo";

    if ( maps\mp\alien\_utility::isplayingsolo() )
    {
        if ( randomint( 100 ) > 50 )
            return;

        var_1 = var_0.vo_prefix + "equip_ammo_solo";
    }

    var_0 thread play_vo_on_player( var_1 );
}

playvoforteamboost( var_0 )
{
    var_1 = var_0.vo_prefix + "deployed_boosters";

    if ( maps\mp\alien\_utility::isplayingsolo() )
    {
        if ( randomint( 100 ) > 50 )
            return;

        var_1 = var_0.vo_prefix + "equip_ammo_solo";
    }

    var_0 thread play_vo_on_player( var_1 );
}

playvoforsupportitems( var_0 )
{
    var_1 = var_0.vo_prefix + "inform_supportitems";

    if ( maps\mp\alien\_utility::isplayingsolo() )
    {
        if ( randomint( 100 ) > 50 )
            return;

        var_1 = var_0.vo_prefix + "equip_ammo_solo";
    }

    var_0 thread play_vo_on_player( var_1 );
}

playvoforrandombox( var_0 )
{
    var_1 = var_0.vo_prefix + "inform_supplies";

    if ( maps\mp\alien\_utility::isplayingsolo() )
    {
        if ( randomint( 100 ) > 50 )
            return;

        var_1 = var_0.vo_prefix + "equip_ammo_solo";
    }

    var_0 thread play_vo_on_player( var_1 );
}

playvoforteamarmor( var_0 )
{
    var_1 = var_0.vo_prefix + "drop_armor";

    if ( randomint( 100 ) > 50 )
        var_1 = var_0.vo_prefix + "inform_armor";

    if ( maps\mp\alien\_utility::isplayingsolo() )
    {
        if ( randomint( 100 ) > 50 )
            return;

        var_1 = var_0.vo_prefix + "equip_ammo_solo";
    }

    var_0 thread play_vo_on_player( var_1 );
}

playvofordeathmachine( var_0 )
{
    var_1 = var_0.vo_prefix + "online_machine_death";
    var_0 play_vo_on_player( var_1 );
}

playvoforwarmachine( var_0 )
{
    var_1 = var_0.vo_prefix + "online_machine_war";
    var_0 play_vo_on_player( var_1 );
}

playvoformeteor()
{
    var_0 = 30000;
    var_1 = gettime();

    if ( !isdefined( level.next_meteor_vo_time ) || level.next_meteor_vo_time < var_1 )
    {
        level.next_meteor_vo_time = var_1 + randomintrange( var_0, var_0 + 5000 );
        var_2 = maps\mp\alien\_utility::get_array_of_valid_players();
        var_3 = common_scripts\utility::random( var_2 );

        if ( !isdefined( var_3 ) )
            return;

        var_4 = var_3.vo_prefix + "inbound_meteor";
        var_3 play_vo_on_player( var_4 );
    }
}

playvoforminions()
{
    var_0 = 30000;
    var_1 = gettime();

    if ( !isdefined( level.next_minion_vo_time ) || level.next_minion_vo_time < var_1 )
    {
        level.next_minion_vo_time = var_1 + randomintrange( var_0, var_0 + 5000 );
        var_2 = maps\mp\alien\_utility::get_array_of_valid_players();

        if ( var_2.size < 1 )
            return;

        var_3 = common_scripts\utility::random( var_2 );
        var_4 = var_3.vo_prefix + "inbound_minions";
        var_3 play_vo_on_player( var_4 );
    }
}

playvofortrapactivation( var_0, var_1 )
{
    var_2 = var_0.vo_prefix + "activated_trap_generic";

    switch ( var_1 )
    {
        case "traps_fire":
            var_2 = var_0.vo_prefix + "activated_trap_fire";
            break;
        case "traps_fence":
            var_2 = var_0.vo_prefix + "online_electricfence";
    }

    var_0 thread play_vo_on_player( var_2 );
}

playvoforpillage( var_0 )
{
    var_1 = var_0.vo_prefix + "good_loot";

    if ( alias_2d_version_exists( var_0, var_1 ) )
        var_0 playlocalsound( get_alias_2d_version( var_0, var_1 ) );
    else if ( soundexists( var_1 ) )
        var_0 playlocalsound( var_1 );
}

playvofordrillhot()
{
    if ( level.script == "mp_alien_last" )
    {
        level notify( "dlc_vo_notify", "last_vo", "conduit_damaged" );
        return;
    }

    var_0 = maps\mp\alien\_utility::get_array_of_valid_players( 1, level.drill.origin );

    if ( var_0.size < 1 )
        return;

    var_1 = var_0[0];
    var_2 = var_1.vo_prefix + "drill_hot";
    var_1 thread play_vo_on_player( var_2, undefined, 10 );
}

playvofornukearmed( var_0 )
{
    var_1 = maps\mp\alien\_utility::get_array_of_valid_players( 1, level.drill.origin );

    if ( var_1.size < 1 )
        return;

    var_0 = var_1[0];
    var_2 = var_0.vo_prefix + "nuke_armed";
    var_0 thread play_vo_on_player( var_2 );
    level thread playvofornukecountdown();
}

playvofornukecountdown()
{
    wait 10;
    var_0 = maps\mp\alien\_utility::get_array_of_valid_players( 1, level.drill.origin );

    if ( var_0.size < 1 )
        return;

    var_1 = var_0[0];
    var_2 = var_1.vo_prefix + "nuke_countdown";
    var_1 thread play_vo_on_player( var_2 );
}

playvofor30seconds()
{
    var_0 = maps\mp\alien\_utility::get_array_of_valid_players( 1, level.drill.origin );

    if ( var_0.size < 1 )
        return;

    var_1 = var_0[0];
    var_2 = var_1.vo_prefix + "30_seconds";
    var_1 thread play_vo_on_player( var_2 );
    wait 5;
    level thread playvoforgettolz();
}

playvofor10seconds()
{
    var_0 = maps\mp\alien\_utility::get_array_of_valid_players( 1, level.drill.origin );

    if ( var_0.size < 1 )
        return;

    var_1 = var_0[0];
    var_2 = var_1.vo_prefix + "10_seconds";
    var_1 thread play_vo_on_player( var_2 );
}

playvoforgettolz()
{
    var_0 = maps\mp\alien\_utility::get_array_of_valid_players( 1, level.drill.origin );

    if ( var_0.size < 1 )
        return;

    var_1 = common_scripts\utility::random( var_0 );
    var_2 = var_1.vo_prefix + "gettolz";
    var_1 thread play_vo_on_player( var_2 );
}

playvoforattackchopper( var_0 )
{
    var_1 = var_0.vo_prefix + "inbound_chopper";
    var_0 thread play_vo_on_player( var_1 );
}

playvoforattackchopperincoming()
{
    play_pilot_vo( "so_alien_plt_teamcallin" );
}

playvoforattackchopperleaving()
{
    play_pilot_vo( "so_alien_plt_hivesuccess" );
}

playmedicclassskillvo( var_0 )
{
    var_1 = var_0.vo_prefix + "medic_skill";
    var_0 thread play_vo_on_player( var_1 );
}

playengineerclassskillvo( var_0 )
{
    var_1 = var_0.vo_prefix + "engr_skill";
    var_0 thread play_vo_on_player( var_1 );
}

playweaponclassskillvo( var_0 )
{
    var_1 = var_0.vo_prefix + "weap_skill";
    var_0 thread play_vo_on_player( var_1 );
}

playtankclassskillvo( var_0 )
{
    var_1 = var_0.vo_prefix + "tank_skill";
    var_0 thread play_vo_on_player( var_1 );
}

playrandomvoline( var_0, var_1, var_2, var_3 )
{
    var_4 = randomint( var_0.size );
    var_5 = var_0[var_4];
    playvotoallplayers( var_5, var_1, var_2, var_3 );
}

play_vo_on_player( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    add_to_vo_system( var_0, var_1, var_2, var_3, var_4, var_5 );
}

playvotoallplayers( var_0, var_1, var_2, var_3, var_4 )
{
    foreach ( var_6 in level.players )
        var_6 add_to_vo_system( var_0, var_1, var_2, var_3, var_4 );
}

add_to_vo_system( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    thread add_to_vo_system_internal( var_0, var_1, var_2, var_3, var_4, var_5 );
}

add_to_vo_system_internal( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    var_1 = get_validated_priority( var_1 );
    var_6 = create_vo_data( var_0, var_2, var_4, var_5 );

    if ( should_interrupt_vo_system( var_3 ) )
    {
        add_to_interrupt_vo( var_6 );

        if ( is_vo_system_playing() )
            interrupt_current_vo();
    }
    else
        add_to_queue_at_priority( var_6, var_1 );

    if ( !is_vo_system_playing() )
        play_vo_system();
}

get_validated_priority( var_0 )
{
    if ( !isdefined( var_0 ) )
        return level.alien_vo_priority_level[level.alien_vo_priority_level.size - 1];

    return var_0;
}

play_vo_system()
{
    self notify( "play_VO_system" );
}

interrupt_current_vo()
{
    self stoplocalsound( get_current_vo_alias() );
    self notify( "interrupt_current_VO" );
}

start_vo_system()
{
    self endon( "disconnect" );
    level endon( "game_ended" );

    for (;;)
    {
        var_0 = get_vo_to_play();

        if ( !isdefined( var_0 ) )
        {
            set_vo_system_playing( 0 );
            self waittill( "play_VO_system" );

            if ( is_vo_system_paused() )
                self waittill( "unpause_VO_system" );

            continue;
        }

        set_vo_system_playing( 1 );
        set_vo_currently_playing( var_0 );
        play_vo( var_0 );
        pause_between_vo( var_0 );
        unset_vo_currently_playing();
    }
}

playvoforscriptable( var_0 )
{
    var_1 = 45000;
    var_2 = gettime();

    if ( !isdefined( level.next_scriptable_vo_time ) || level.next_scriptable_vo_time < var_2 )
    {
        if ( isdefined( level.next_scriptable_vo_time ) )
        {
            if ( randomint( 100 ) < 60 )
                return;
        }

        level.next_scriptable_vo_time = var_2 + randomintrange( var_1, var_1 + 5000 );
        var_3 = maps\mp\alien\_utility::get_array_of_valid_players();
        var_4 = common_scripts\utility::random( var_3 );

        if ( !isdefined( var_4 ) )
            return;

        switch ( var_0 )
        {
            case "scriptable_alien_lynx_jump":
            case "scriptable_alien_tatra_t815_jump":
                var_5 = var_4.vo_prefix + "alien_approach_truck";
                var_4 play_vo_on_player( var_5 );
                break;
        }
    }
}

play_vo( var_0 )
{
    self endon( "interrupt_current_VO" );

    if ( self.sessionstate != "playing" )
        return;

    var_1 = var_0.alias;

    if ( !soundexists( var_1 ) )
    {
        wait 0.1;
        return;
    }

    if ( maps\mp\alien\_utility::is_in_laststand() && !( issubstr( var_1, "downed" ) || issubstr( var_1, "last_stand" ) ) )
        return;

    self.vo_system_playing_vo = 1;

    foreach ( var_3 in level.players )
    {
        if ( var_3 issplitscreenplayer() && !var_3 issplitscreenplayerprimary() )
            continue;

        if ( var_3 == self )
        {
            if ( alias_2d_version_exists( var_3, var_1 ) )
                var_3 playlocalsound( get_alias_2d_version( var_3, var_1 ) );
            else
                var_3 playlocalsound( var_1 );

            continue;
        }

        if ( !maps\mp\alien\_utility::is_true( var_0.only_local ) )
            self playsoundtoplayer( var_1, var_3 );
    }

    wait( get_sound_length( var_1 ) );
    self.vo_system_playing_vo = 0;
}

create_vo_data( var_0, var_1, var_2, var_3 )
{
    var_4 = 999;
    var_5 = 1.5;
    var_6 = 3;
    var_7 = spawnstruct();
    var_7.alias = var_0;

    if ( !isdefined( var_1 ) )
        var_1 = var_4;

    var_7.expire_time = gettime() + var_1 * 1000;

    if ( !isdefined( var_2 ) )
        var_2 = randomfloatrange( var_5, var_6 );

    var_7.pause_time = var_2;

    if ( maps\mp\alien\_utility::is_true( var_3 ) )
        var_7.only_local = 1;
    else
        var_7.only_local = 0;

    return var_7;
}

get_vo_to_play()
{
    var_0 = retrieve_interrupt_vo();

    if ( isdefined( var_0 ) )
        return var_0;

    foreach ( var_3, var_2 in level.alien_vo_priority_level )
    {
        var_0 = retrieve_vo_from_queue( var_2 );

        if ( isdefined( var_0 ) )
            return var_0;
    }

    return undefined;
}

retrieve_interrupt_vo()
{
    var_0 = self.vo_system.interrupt_vo;
    reset_interrupt_vo();
    return var_0;
}

retrieve_vo_from_queue( var_0 )
{
    remove_expired_vo_from_queue( var_0 );
    return pop_first_vo_out_of_queue( var_0 );
}

pop_first_vo_out_of_queue( var_0 )
{
    var_1 = self.vo_system.vo_queue[var_0][0];

    if ( !isdefined( var_1 ) )
        return var_1;

    var_2 = [];

    for ( var_3 = 1; var_3 < self.vo_system.vo_queue[var_0].size; var_3++ )
    {
        if ( !isdefined( self.vo_system.vo_queue[var_0][var_3] ) )
            break;

        var_2[var_3 - 1] = self.vo_system.vo_queue[var_0][var_3];
    }

    self.vo_system.vo_queue[var_0] = var_2;
    return var_1;
}

remove_expired_vo_from_queue( var_0 )
{
    var_1 = gettime();
    var_2 = [];

    foreach ( var_5, var_4 in self.vo_system.vo_queue[var_0] )
    {
        if ( !vo_expired( var_4, var_1 ) )
            var_2[var_2.size] = self.vo_system.vo_queue[var_0][var_5];
    }

    self.vo_system.vo_queue[var_0] = var_2;
}

initandstartvosystem()
{
    init_vo_system();
    thread start_vo_system();
}

init_vo_system()
{
    var_0 = spawnstruct();
    var_0.vo_currently_playing = undefined;
    var_0.interrupt_vo = undefined;
    var_0.is_playing = 0;
    var_1 = [];

    foreach ( var_4, var_3 in level.alien_vo_priority_level )
        var_1[var_3] = [];

    var_0.vo_queue = var_1;
    self.vo_system = var_0;
}

pause_between_vo( var_0 )
{
    if ( is_vo_system_paused() )
        self waittill( "unpause_VO_system" );

    if ( var_0.pause_time > 0 )
        wait( var_0.pause_time );
}

is_vo_system_paused()
{
    return maps\mp\alien\_utility::is_true( self.pause_vo_system );
}

pause_vo_system( var_0 )
{
    foreach ( var_2 in var_0 )
        var_2.pause_vo_system = 1;
}

unpause_vo_system( var_0 )
{
    foreach ( var_2 in var_0 )
        var_2.pause_vo_system = 0;

    foreach ( var_2 in var_0 )
        var_2 notify( "unpause_VO_system" );
}

vo_expired( var_0, var_1 )
{
    return var_1 > var_0.expire_time;
}

add_to_queue_at_priority( var_0, var_1 )
{
    self.vo_system.vo_queue[var_1][self.vo_system.vo_queue[var_1].size] = var_0;
}

is_vo_system_playing()
{
    return self.vo_system.is_playing;
}

set_vo_system_playing( var_0 )
{
    self.vo_system.is_playing = var_0;
}

set_vo_currently_playing( var_0 )
{
    self.vo_system.vo_currently_playing = var_0;
}

unset_vo_currently_playing()
{
    self.vo_system.vo_currently_playing = undefined;
}

should_interrupt_vo_system( var_0 )
{
    return isdefined( var_0 ) && var_0;
}

add_to_interrupt_vo( var_0 )
{
    self.vo_system.interrupt_vo = var_0;
}

get_current_vo_alias()
{
    return self.vo_system.vo_currently_playing.alias;
}

reset_interrupt_vo()
{
    self.vo_system.interrupt_vo = undefined;
}

scriptable_vo_handler()
{
    level endon( "game_ended" );
    level.scriptable_vo_played = [];

    for (;;)
    {
        level waittill( "scriptable", var_0 );
        level thread playvoforscriptable( var_0 );
    }
}

player_pain_vo()
{
    var_0 = 1500;
    var_1 = gettime();

    if ( !isdefined( self.next_pain_vo_time ) )
        self.next_pain_vo_time = var_1 + randomintrange( var_0, var_0 + 2000 );
    else if ( var_1 < self.next_pain_vo_time )
        return;

    if ( self.vo_prefix == "p1_" )
        self playlocalsound( "female_death_american_1_plr" );

    if ( self.vo_prefix == "p2_" )
        self playlocalsound( "generic_death_american_1_plr" );

    if ( self.vo_prefix == "p3_" )
        self playlocalsound( "generic_death_american_2_plr" );

    if ( self.vo_prefix == "p4_" )
        self playlocalsound( "generic_death_american_3_plr" );

    self.next_pain_vo_time = var_1 + randomintrange( var_0, var_0 + 1500 );
}

play_pilot_vo( var_0 )
{
    var_1 = get_sound_length( var_0 );
    self playsound( var_0 );
    wait( var_1 );
}

play_alien_music( var_0 )
{
    if ( common_scripts\utility::flag( "alien_music_playing" ) )
        return;

    var_1 = get_sound_length( var_0 );
    common_scripts\utility::flag_set( "alien_music_playing" );

    foreach ( var_3 in level.players )
    {
        if ( maps\mp\_utility::isreallyalive( var_3 ) )
            var_3 playlocalsound( var_0 );
    }

    wait( var_1 );
    common_scripts\utility::flag_clear( "alien_music_playing" );
}

get_sound_length( var_0 )
{
    return lookupsoundlength( var_0 ) / 1000;
}

ext_last_stand_sfx()
{
    self playlocalsound( "mantle_cloth_plr_24_up" );
    wait 0.65;

    if ( self hasfemalecustomizationmodel() )
        self playlocalsound( "Fem_breathing_better" );
    else
        self playlocalsound( "breathing_better" );
}

play_solo_vo( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    var_6 = var_0 + "_solo";

    if ( soundexists( var_6 ) )
        play_vo_on_player( var_6 );
}

alias_2d_version_exists( var_0, var_1 )
{
    var_2 = get_alias_2d_version( var_0, var_1 );
    return soundexists( var_2 );
}

get_alias_2d_version( var_0, var_1 )
{
    var_2 = getsubstr( var_1, var_0.vo_prefix.size );
    return var_0.vo_prefix + "plr_" + var_2;
}

remove_vo_data( var_0, var_1 )
{
    var_2 = [];

    foreach ( var_5, var_4 in self.vo_system.vo_queue[var_1] )
    {
        if ( !( var_4.alias == self.vo_prefix + var_0 || var_4.alias == self.vo_prefix + "plr_" + var_0 ) )
            var_2[var_2.size] = self.vo_system.vo_queue[var_1][var_5];
    }

    self.vo_system.vo_queue[var_1] = var_2;
}
