#include common_scripts\utility;
#include common_scripts\_exploder;
#include maps\mp\_audio;

//////////////////////////////////////////////////////////////////////////////
// _snd_common_mp.gsc
// 
// This scriptfile is intended for common scripting for blacksmith (S1).
// This file is for sound designers to add message handlers or for minor
// prototype scripting systems, etc. Core systems go in their own files and
// need to be approved by the audio engineer and audio director.
//////////////////////////////////////////////////////////////////////////////
 
init()
{
	snd_message_init();
	register_common_mp_snd_messages();
	thread snd_mp_mix_init();	
}

snd_mp_mix_init()
{
	level._snd.dynamic_event_happened = false;
	
	// Set the Dyanmic Event Mix State to False by Default.
	//level._snd.dynamic_event_happened = false;
	
	// Setup Pre-Event Mix for Every Player that is present when the match starts.
    if(Isdefined (level.players) && level.players.size > 0)
    {
        foreach( player in level.players )
        {
            AssertEx( isdefined( player ), "isdefined( player )" );
            player clientaddsoundsubmix( "mp_init_mix" );
			wait( 0.05 );
            player clientaddsoundsubmix( "mp_pre_event_mix" );
			wait( 0.05 );
        }
    }
}


snd_mp_mix_post_event()
{
	level._snd.dynamic_event_happened = true;
    if(Isdefined (level.players) && level.players.size > 0)
    {
        foreach( player in level.players )
        {
            AssertEx( isdefined( player ), "isdefined( player )" );
			player clientclearsoundsubmix( "mp_pre_event_mix" );
			wait(0.05);
            player clientaddsoundsubmix( "mp_post_event_mix" );
			wait( 0.05 );
        }
    }
}


snd_mp_player_join()
{
	self clientaddsoundsubmix( "mp_init_mix" );
	if ( !isDefined(level._snd.dynamic_event_happened) || !level._snd.dynamic_event_happened)
	{
		self clientaddsoundsubmix( "mp_pre_event_mix" );
	}
	else
	{
		self clientclearsoundsubmix( "mp_pre_event_mix" );
		self clientaddsoundsubmix( "mp_post_event_mix" );
	}
}


//////////////////////////////////////////////////////////////////////////////
// SOUND MESSAGE
//////////////////////////////////////////////////////////////////////////////

snd_message_init()
{
	if(!IsDefined(level._snd))
		level._snd = SpawnStruct();
	
	if(!IsDefined( level._snd.messages ))
		level._snd.messages = [];	
}

snd_register_message( message, callback )
{
	assertEx( IsDefined( level._snd ), "Need to call snd_message_init() before calling this function." );
	assert( IsArray( level._snd.messages ) );
	level._snd.messages[message] = callback;
}

snd_music_message( message, arg1, arg2 )
{
	level notify( "stop_other_music" );
	level endon( "stop_other_music" );
	
	if ( IsDefined( arg2 ) )
		childthread snd_message( "snd_music_handler", message, arg1, arg2 );
	else if ( IsDefined( arg1 ) )
		childthread snd_message( "snd_music_handler", message, arg1 );
	else
		childthread snd_message( "snd_music_handler", message );
}

snd_message( message, arg1, arg2, arg3 )
{
	AssertEx( IsDefined( level._snd ), "Need to call snd_message_init() before calling this function." );
	Assert( IsArray( level._snd.messages ) );
	
	if ( IsDefined( level._snd.messages[message] ) )
	{
		if ( IsDefined( arg3 ) )
			thread [[ level._snd.messages[message] ]]( arg1, arg2, arg3 );
		else if ( IsDefined( arg2 ) )
			thread [[ level._snd.messages[message] ]]( arg1, arg2 );
		else if ( IsDefined( arg1 ) )
			thread [[ level._snd.messages[message] ]]( arg1 );
		else
			thread [[ level._snd.messages[message] ]]();
	}
}


//////////////////////////////////////////////////////////////////////////////
// COMMON MESSAGE HANDLERS
//////////////////////////////////////////////////////////////////////////////

register_common_mp_snd_messages()
{
	////////////////////////
	//EXO ABILITIES
	////////////////////////
	
	//EXO CLOAK
	snd_register_message( "mp_exo_cloak_activate",				::mp_exo_cloak_activate );
	snd_register_message( "mp_exo_cloak_deactivate",			::mp_exo_cloak_deactivate );
	
	//EXO HEALTH
	snd_register_message( "mp_exo_health_activate",				::mp_exo_health_activate );
	snd_register_message( "mp_exo_health_deactivate",			::mp_exo_health_deactivate );
	
	//EXO HOVER
	snd_register_message( "mp_regular_exo_hover",				::mp_regular_exo_hover );
	snd_register_message( "mp_suppressed_exo_hover",			::mp_suppressed_exo_hover );

	//EXO MUTE
	snd_register_message( "mp_exo_mute_activate",				::mp_exo_mute_activate );
	snd_register_message( "mp_exo_mute_deactivate",				::mp_exo_mute_deactivate );
	
	//EXO OVERCLOCK
	snd_register_message( "mp_exo_overclock_activate",			::mp_exo_overclock_activate );
	snd_register_message( "mp_exo_overclock_deactivate",		::mp_exo_overclock_deactivate );
	
	//EXO PING
	snd_register_message( "mp_exo_ping_activate",				::mp_exo_ping_activate );
	snd_register_message( "mp_exo_ping_deactivate",				::mp_exo_ping_deactivate );
	
	//EXO REPULSOR
	snd_register_message( "mp_exo_repulsor_activate",			::mp_exo_repulsor_activate );
	snd_register_message( "mp_exo_repulsor_deactivate",			::mp_exo_repulsor_deactivate );
	snd_register_message( "mp_exo_repulsor_repel",				::mp_exo_repulsor_repel );
	
	//EXO SHIELD
	snd_register_message( "mp_exo_shield_activate",				::mp_exo_shield_activate );	
	snd_register_message( "mp_exo_shield_deactivate",			::mp_exo_shield_deactivate );
	
	////////////////////////
	// KILLSTREAKS
	////////////////////////
	
	//GOLIATH
	snd_register_message( "goliath_pod_burst",					::mp_ks_goliath_pod_burst );
	snd_register_message( "goliath_death_explosion",			::mp_ks_goliath_death_explosion );
	snd_register_message( "goliath_self_destruct",				::mp_ks_goliath_self_destruct );	
	
	
	////////////////////////
	// WEAPONS
	////////////////////////
	
	//EXO KNIFE
	snd_register_message( "exo_knife_player_impact",			::mp_wpn_exo_knife_player_impact );
}

////////////////////////
//EXO CLOAK
////////////////////////
mp_exo_cloak_activate()
{
	//iprintlnbold( "EXO CLOAK ON" );
	self PlaySound( "mp_exo_cloak_activate" );	
}

mp_exo_cloak_deactivate()
{
	//iprintlnbold( "EXO CLOAK OFF" );
	self PlaySound( "mp_exo_cloak_deactivate" );
}

////////////////////////
//EXO HEALTH
////////////////////////
mp_exo_health_activate()
{
	self PlaySound( "mp_exo_stim_activate" );				// self = player
}

mp_exo_health_deactivate()
{
	self PlaySound( "mp_exo_stim_deactivate" );			// self = player
}

////////////////////////
//EXO HOVER
////////////////////////
mp_regular_exo_hover()
{
	// Activate Hover
	self PlaylocalSound( "mp_exo_hover_activate" );
	self PlaylocalSound( "mp_exo_hover_fuel" );
	
	self waittill( "stop_exo_hover_effects" );	
	
	// Deactivate
	self PlaylocalSound( "mp_exo_hover_deactivate" );
	self StopLocalSound( "mp_exo_hover_sup_fuel" );
}

mp_suppressed_exo_hover()
{
	// Activate Hover
	self PlaylocalSound( "mp_exo_hover_sup_activate" );
	self PlaylocalSound( "mp_exo_hover_sup_fuel" );

	self waittill( "stop_exo_hover_effects" );	
	
	// Deactivate
	self PlaylocalSound( "mp_exo_hover_sup_deactivate" );
	self StopLocalSound( "mp_exo_hover_sup_fuel" );
}


////////////////////////
//EXO MUTE DEVICE
////////////////////////
mp_exo_mute_activate()
{
	self PlayLocalSound( "mp_exo_mute_activate" );				// self = player
}

mp_exo_mute_deactivate()
{
	self PlayLocalSound( "mp_exo_mute_deactivate" );			// self = player
}

////////////////////////
//EXO OVERCLOCK
////////////////////////
mp_exo_overclock_activate()
{
	//self PlaySound( "mp_exo_overclock_bed" );
	self PlaySound( "mp_exo_overclock_activate" );	
}

mp_exo_overclock_deactivate()
{
	//self PlaySound( "mp_exo_overclock_bed" );
	self PlaySound( "mp_exo_overclock_deactivate" );	
}

////////////////////////
//EXO PING
////////////////////////
mp_exo_ping_activate()
{
	self PlayLocalSound( "mp_exo_ping_activate" );
	//self PlayLocalSound( "mp_exo_ping_bed" );
}

mp_exo_ping_deactivate()
{
	//self StopLocalSound( "mp_exo_ping_bed" );
	self PlaySound( "mp_exo_ping_deactivate" );			
}

////////////////////////
//EXO REPULSOR
////////////////////////
mp_exo_repulsor_activate()
{
	self PlaySound( "mp_exo_trophy_activate" );
	//self PlayLocalSound( "mp_exo_trophy_bed" );	
}

mp_exo_repulsor_deactivate()
{
	//self PlaySound( "mp_exo_trophy_bed" );
	self PlaySound( "mp_exo_trophy_deactivate" );	
}

mp_exo_repulsor_repel()
{
	playSoundAtPos( self.origin, "mp_exo_trophy_intercept" );	
}

////////////////////////
//EXO SHIELD
////////////////////////
mp_exo_shield_activate()
{
	self PlaySound( "mp_exo_shield_activate" );
	//playSoundAtPos( self.origin, "mp_exo_shield_activate_npc" );		// self = player
}

mp_exo_shield_deactivate()
{
	self PlaySound( "mp_exo_shield_deactivate" );
	//playSoundAtPos( self.origin, "mp_exo_shield_deactivate_npc" );	
}

////////////////////////
//WEAPONS
////////////////////////

mp_wpn_exo_knife_player_impact()
{
	playSoundAtPos( self.origin, "wpn_combatknife_stab_npc" );
}

////////////////////////
//KILLSTREAKS
////////////////////////
mp_ks_goliath_pod_burst()
{
	self PlayLocalSound( "goliath_suit_up_pod_burst" );
}

mp_ks_goliath_death_explosion()
{
	self playsound( "goliath_death_destruct" );	
}

mp_ks_goliath_self_destruct()
{
	self playsound( "goliath_death_destruct" );	
}

/* END OF FILE /////////////////////////////////////////////////////////////////
880888888880.G@888@888888888;t88GL808888Gf00CC00LC00888880088ft88888G88808808808
8888@@@88888.L@8@@888888@880.f88L88888880f00G8CG00088800888000LC0888888808808888
888@@@@88888G088@@888888;:f.i@888f08888GtC0G001000000000088GG8CCG888888800808888
888@@@@088880t,.10@@@@801.,C88888888GG080G8800000000000000GtC0LLfG88888888888888
088@@@@008@888GfttL1i1tC8888888GG088888888800C0G00000000CCGG0GL1tt88888888888888
888@@@88CG888888888888888@88@L088888888888880GG0G0000000000GCL1:i108888888888888
@88@@@888CtL88888888888888888t88888888088888GtLG00CCGGGGGGGCL1..:1C8880888888888
@8@@@@8880GGftC088880LLL0888880888888CG80080CfGGGG080CLfLLfi.,..:1G8888888888888
@@@@@@888800GGGGC888888808888888888880000GG0CLLfffG0888ffLf1i,..,iC8888888888888
@@@@@@88@888888800t88888CG8888888888080000GCCLf1tLGCG888GGCf1: .,iG0880888888888
@@@@@@@@8888800000iCG08088888888888808G0GGGCCfLfLLLLt10880GLfLGC1L0088G088888888
@@@8@@@@8888800000GfttC88888888888888888000GGCCf1fttf1:i8000G00GfC00080888888888
@@@@@@@@8888800000008888888888@@888888888888888800GCL1;:,,fLCfLLfG00008880888888
8@@@@@@@@88800000000888@88888888888888888800GGG008888Ci;;;i1it8Cf000008088888888
88@@@@@@@8888800088888888888888888888000GGCCLLLLLLCC088811it0888G888888080888888
@@@@@@@@@8888888888888888888888000GGCCCLLfftfLCCfttffLG8088088888088888008880000
@@88@@@8@88888008888@@888880000GGCLLLfffttffft1iii;iitLC008G888888888GLt1088880G
8888888888888888888888@@8888880GGCLLffffft111tfCCCCGGG0000G08888888880LfC08880GG
@888888@88888808888888@808888888880CLfC8888888888880000GCCLC08888888801LC08800CL
@88888888888880888888880GG80CG00G0Liii1L0888880GfffffftttLGGG88888888CfCG080CCGf
@8888808888888888800000GGCLLCLtt1ii:,,:;1t1tt1iiii11iiii1L00088088880fLL008Cff11
8888080888888888880GCLfffft11t1;::;:..:;i;,,,:;;;;::,::itC0C08088880GLC8800C1tCt
8888000088888888080CLt1i;:;::,,,::::..,;i;:,........,,;ifC0C080800f08L88800GtfGL
@@8800G080888888080Cf1i;:,,,,.,,:;:,..,;i1i:,......,,:itCG000G0001CGC088888GtfCf
@@88888080000888800Cf1;::,,,,,,,;;,,..,;i1t1:,..,,,:;itLG0000GCGGLGL088888880000
@@88800008000808888GL1;;:,,,,,,:,,,,...:;;1i;:,,,,:;itLCG00000GGCLG0888888888888
@@@88888808888888880Ct1;::::::::1GGfi;1C080f:;;:::;i1tLG0880000GLLG0888888888888
@@8888888808888888880Cti;::;;;:,,iii1L0GGCfi;:;i;;ii1fC08880000LCGG0008888888888
@@@8888888888888888880Cti;:;;,,:1fft1f11fCCL1i;;iiii1fG088800LtCCCG0008888888888
@@@88888888@88888888800Cti;iii1ii1ttt;itftti1fff11iitC0880G11CCLGG000088888888@@
@@@@@@888@@@@88888888800Ct111itt;:,,,,,,::;itLCCCLi1C088ftCGGLCGC00808888@8@8@@@
@@@@@@@@@@@@@@@8888880880GftL1;;;:;1ffft11iii1ttCCLG088G0f1GG00GGG80008888888@@@
@@@@@@@@@@@@@@@@888880888800CLfffCGGCGGGCGGCCCCCG00088000LCC08800888800088888888
@@@@@@@@@@@@@@@@@@8888G88888888808800000000888888000G0G0G0G088888888880088808888
@@@@@@@@@@@@@@@@@@88@880888888081tC088888GCCCGGCGGGGGC0000088888888888888808888@
@@@@@@@@@@@@@@@@@@@@88888@88888@800G08888888888888888C00008888888888888888G8888@
@@@@@@@@@@@@@@@@@@@@80G8888@@@@@@@@@@8888888888888880800G88@8@@@@@8888888008888@
@@@@@@@@@@@@@@@@@@@@@@8880@8@@@@@@@@@8@@@@88888888000888888888@@@88888888G80888@
@@@@@@@@@@@@@@@@@@@@@@@8888888@@@@@@@@@@@@@@88@888@G888888888888888888888080888@
@@@@@@@@@@@@@@@@@@@@@@@@88888@@@@@@@@@@@@@@@@8@888008888888888888888888808888888
@@@@@@@@@@@@@@@@@@@@@@@^^^this guy is an idiot^^^^@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@^^^no i'm isnt^^^^@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/