#include maps\mp\_utility;
#include maps\mp\gametypes\_hud_util;
#include common_scripts\utility;
#include maps\mp\agents\_agent_utility;
#include maps\mp\gametypes\_damage;
#include maps\mp\agents\_scriptedAgents;
#include maps\mp\_dynamic_events;
#include maps\mp\_audio;


main()
{
	PreCacheModel( "archery_target_fr" );
	PreCacheModel( "bc_target_dummy_base" );
	PreCacheModel( "training_target_opfor1" );
	PreCacheModel( "training_target_civ1" );
	PreCacheShader( "ac130_overlay_pip_vignette_vlobby" );
	PreCacheShader( "ac130_overlay_pip_vignette_vlobby_cao" );
	maps\mp\mp_vlobby_room_precache::main();
	maps\createart\mp_vlobby_room_art::main();
	maps\mp\mp_vlobby_room_fx::main();
	
	//setting an initial lighting state
	//SetLightingState(2);
	
	maps\mp\_load::main();
	maps\mp\mp_vlobby_room_lighting::main();
	maps\mp\mp_vlobby_room_aud::main();
	
	//maps\mp\_compass::setupMiniMap( "compass_map_mp_virtual_lobby" );
	//SetLightingState(2);
	
	game["attackers"] = "allies";
	game["defenders"] = "axis";
	level.vl_dof_based_on_focus = ::vl_dof_based_on_focus;
	level.vl_handle_mode_change = ::vl_handle_mode_change;
	level.vl_lighting_setup = ::vl_lighting_setup;
//	level.vl_dof_cac_weapon = ::Set_CAC_DOF;
	thread vl_ground_setup();
	maps\mp\_vl_base::vl_init();
	
	level.dof_tuner = spawnstruct();
	level.dof_tuner.FStopPerUnit = 0.25;
	level.dof_tuner.scaler = -0.3; 
	level.dof_tuner.fStopBase = 3;	

	thread fade_from_black();
}

fade_from_black()
{
	level waittill("connected", player);

	/*
	if ( !IsDefined( player.BlackFade ) )
	{
		player.BlackFade = newClientHudElem( player );
		player.BlackFade.x = 0;
		player.BlackFade.y = 0;
		player.BlackFade setshader( "black", 640, 480 );
		player.BlackFade.alignX = "left";
		player.BlackFade.alignY = "top";
		player.BlackFade.horzAlign = "fullscreen";
		player.BlackFade.vertAlign = "fullscreen";
		player.BlackFade.alpha = 1;
	}
	*/
	
	player waittill("fade_in");
	
	player clientaddsoundsubmix( "mp_no_foley", 1 );
	
	/*
	wait(1.5);
	
	// waiting for notify from camera script to know when ready to fade in 
	//	player.StrikeWhiteFade.alpha = 0;
	player.BlackFade FadeOverTime( 1 );
	player.BlackFade.alpha = 0;
	*/
}


vl_ground_setup()
{
	fromEnt = GetEnt("teleport_from", "targetname");
	toEnt = GetEnt("teleport_to", "targetname");
	
	
	//vlobby_ref_ground_b
	ground_b_bsps = GetEntArray("vlobby_floor_b", "targetname");
	foreach (ground_b_bsp in ground_b_bsps)
	{
		ground_b_bsp.origin += toent.origin - froment.origin;
		//ground_b_bsp.origin += ground_b_bsp.origin - (0, 0, 4624);
	}	
	//vlobby_ref_ground_a
	ground_a_bsps = GetEntArray("vlobby_floor_a", "targetname");
	foreach (ground_a_bsp in ground_a_bsps)
	{
		ground_a_bsp hide();
	}
}
	
vl_lighting_setup()
{
	player = self;
	//player SetDepthOfField( 5, 39, 1100, 1502.29, 7.5, 4.675 );
	player EnablePhysicalDepthOfFieldScripting();
	if( level.nextgen )
		player SetPhysicalDepthOfField( 0.613159, 89.8318, level.camParams.DOF_Time, level.camParams.DOF_Time * 2 );
	else
		player SetPhysicalDepthOfField( 4.01284, 95.2875, level.camParams.DOF_Time, level.camParams.DOF_Time * 2 );
	
}

vl_dof_based_on_focus(Dist)
{
	dof_time = level.camParams.DOF_Time;
	player = self;	
	
	Dist2Tgt = Dist;
	player = self;
	FStopPerUnit = level.dof_tuner.FStopPerUnit; // the smaller this number the more blurry it gets
	scaler = level.dof_tuner.scaler;
	fStopBase = level.dof_tuner.fStopBase; // base default fstop to be scaled a distance of 72?
	if(level.currentgen)
	{
		fStopBase += 2; 
	}
	BaseDistance = 104;
	
	result = ((BaseDistance - Dist2Tgt) * FStopPerUnit);
	fStop = fStopBase + result + (result * scaler);

	if(fStop < 0.125)
	{
		fStop = 0.125;	
	}
	else if(fStop > 128)
	{
		fStop = 128;	
	}
		player SetPhysicalDepthOfField( fStop, Dist2Tgt, dof_time, dof_time * 2 );
}

vl_handle_mode_change( mode, newmode, camParams )
{
	player = self;
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	////////// if the mode we are leaving was the mode below, check to see if we should change any post fx.  
	/// 		mode is the current mode we are in not the mode we are going to be in after this function runs.  newmode is
	/// 		is the mode we are transitioning to.
	/// 
	
	if ( mode == "cac" )
	{
		player SetDefaultPostFX();
	}
	else if ( mode == "cao" )
	{
	}
	
	////
	////
	///////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////
	///////   This is for the newmode that we are going to.  Checks newmode and then changes post FX depending on what newmode we want to go to.
	/// 		This will ovewrite any settings that get set above if the newmode changes the same post fx here. 
	/// 
	
	if (newmode == "cac")
	{
		player VisionSetNakedForPlayer("mp_vlobby_room_cac", 0);
		player LightSetForPlayer("mp_vl_create_a_class");
		// player SetPhysicalDepthOfField( 16, 164, 0.25, 0.25 );
	//	player Set_CAC_DOF();
	}
	else if ( newmode == "cao" )
	{
		if( level.nextgen )
			player SetPhysicalDepthOfField( 1.223, 156.419, level.camParams.DOF_Time, level.camParams.DOF_Time );
		else
			player SetPhysicalDepthOfField( 3.223, 156.419, level.camParams.DOF_Time, level.camParams.DOF_Time );
	}
	else if ( newmode == "prelobby" )
	{
		player SetDefaultDOF();
		player SetDefaultPostFX();
	}
	else if (mode == "prelobby_members")
	{	// shouldn't be used right now.
	}
	else if (mode == "prelobby_loadout")
	{	// shouldn't be used right now.
	}
	else if (mode == "prelobby_loot")
	{	// shouldn't be used right now.
	}
	else if (newmode == "game_lobby")
	{
		player SetDefaultPostFX();
		player maps\mp\_vl_camera::Set_Avatar_DOF();
	}
	else if (mode == "startmenu")
	{	// shouldn't be used right now.
	}
	else if (mode == "transition")
	{	// shouldn't be used right now.
	}
	else if ( newmode == "clanprofile" )
	{
		player SetDefaultDOF();
		player SetDefaultPostFX();
	}

	////
	////
	///////////////////////////////////////////////////////////////////////////////////////////////////////////
}

SetDefaultPostFX()
{
	player = self;
	player VisionSetNakedForPlayer("mp_vlobby_room", 0);
	player LightSetForPlayer("mp_vlobby_room");
}
SetDefaultDOF()
{
	///////////////////////////////////////////////
	//////////////  vl_dof_based_on_focus() should overide DOF for each camera position when looking at lobby avatars/characters
	player = self;
	if( level.nextgen )
		player SetPhysicalDepthOfField( 0.613159, 89.8318, level.camParams.DOF_Time, level.camParams.DOF_Time );
	else
		player SetPhysicalDepthOfField( 4.01284, 95.2875, level.camParams.DOF_Time, level.camParams.DOF_Time );
}
