#include common_scripts\utility;
#include maps\mp\_utility;
#include maps\mp\_audio;
#include maps\mp\_dynamic_events;


main()
{
	//SetLightingState( 2 );;	// keep this commented out - it's used for createfx purposes
	maps\mp\mp_refraction_precache::main();
	maps\createart\mp_refraction_art::main();
	maps\mp\mp_refraction_lighting::main();
	maps\mp\mp_refraction_fx::main();
	
	level.aerial_pathnode_offset = 600;
	level.aerial_pathnode_group_connect_dist = 300;
	
//	//ABlighting setup
//	SetLightingState( 1 );
	
	
	// Setting a map-specific OSP vision set.
	level.ospvisionset = "mp_refraction_osp";
	level.osplightset = "mp_refraction_osp";
	level.warbirdvisionset = "mp_refraction_osp";
	level.warbirdlightset = "mp_refraction_osp";
	level.vulcanvisionset = "mp_refraction_osp";
	level.vulcanlightset = "mp_refraction_osp";
	
	maps\mp\_load::main();
	level.alarmfx = loadfx("vfx/lights/light_red_pulse_fast");
	level.rain = loadfx( "vfx/rain/rain_volume_windy" );
	level thread common_scripts\_exploder::activate_clientside_exploder(10);
	
	maps\mp\_water::init();
	
 	maps\mp\_compass::setupMiniMap( "compass_map_mp_refraction" );	
	
	setdvar( "r_lightGridEnableTweaks", 1 );
	setdvar( "r_lightGridIntensity", 1.33 );
	
	thread set_lighting_values(); // after maps\mp\_load::main();
//	thread ab_lighting(); //to unhide elevator interior once it lands
	
	game["attackers"] = "allies";
	game["defenders"] = "axis";
	
//	/////////////////////////////////////////////////
//	//				PRECACHE
//	/////////////////////////////////////////////////
//
//	//Elevator Doors
//	PrecacheMpAnim( "ref_elevator_sliding_door_open" );
//	PrecacheMpAnim( "ref_elevator_sliding_door_open_collision" );
//	PreCacheModel( "ref_elevator_sliding_door_01" );
//	
//	//Locking Mechanism	
//	PrecacheMpAnim( "elevator_lock_parta" );
//	PreCacheModel( "ref_elevator_lock_parta" );
//	PrecacheMpAnim( "elevator_lock_partb" );
//	PreCacheModel( "ref_elevator_lock_partb" );
//	PrecacheMpAnim( "elevator_lock_partc" );
//	PreCacheModel( "ref_elevator_lock_partc" );
//	PrecacheMpAnim( "elevator_lock_partd" );
//	PreCacheModel( "ref_elevator_lock_partd" );
//	
//	PreCacheModel( "ref_elevator_support_clamp_01" );
//	PrecacheMpAnim( "elevator_support_clamp_anim" );
//	PrecacheMpAnim( "elevator_support_clamp_static" );
//	
//	PreCacheModel( "ref_base_piston_01" );
//	PreCacheModel( "ref_base_piston_02" );
//	PrecacheMpAnim( "elevator_piston_01" );
//	PrecacheMpAnim( "elevator_piston_02" );
//	
//	//Elevator Housing Plates
//	PrecacheMpAnim( "elevator_housing_plate_a" );
//	PreCacheModel( "ref_elevator_housing_plate" );
//	PrecacheMpAnim( "elevator_housing_plate_b" );
//	PreCacheModel( "ref_elevator_housing_plate_b" );
//	
//	//Shutters
//	PrecacheMpAnim( "elevator_shutters_open" );
//	PrecacheMpAnim( "elevator_shutters_close" );
//	PreCacheModel( "ref_elevator_shutters_01" );
//	
//	//Shockers
//	PrecacheMpAnim( "elevator_shock_absorber_up" );
//	PrecacheMpAnim( "elevator_shock_absorber_down" );
//	PreCacheModel( "ref_elevator_springs_machine_01" );
	
	level.mapCustomKillstreakFunc = ::refractionCustomKillstreakFunc;
	
	// OSP overrides
	level.orbitalSupportOverrideFunc = ::refractionCustomOSPFunc;
	
	// Remote Missile Height Override
	level.remote_missile_height_override = 16000;
	
	// Vulcan overrides
	level.orbitalLaserOverrideFunc = ::refractionVulcanCustomFunc;

//	/////////////////////////////////////////////////
//	//				DYNAMIC EVENT
//	/////////////////////////////////////////////////
//		
//	thread aud_setup_announce_speakers();
//	thread aud_speaker_test( 15 );
//	
//	thread setup_elevator_paths_and_spawns();
//	
//	level.elevator_max_z = 22824;
//	level.elevator_min_z = 2024;
//	level.elevator_anim_time = 11.0;
//	level.elevator_go_time = 30 - level.elevator_anim_time;
//	level thread DynamicEvent( ::dynamicEventStartFunc );
//	
//	level thread onRefractionPlayerConnect();
//	array_thread( GetEntArray( "elevator_alarm" , "targetname" ), ::elevator_alarms );
//	thread elevator_handle_kill_trigger();
	array_thread( getEntArray( "com_radar_dish", "targetname" ), ::radar_dish_rotate );
//	level.elevator_origin = spawn_tag_origin();
//	
//	/#
//	SetDvarIfUninitialized( "refraction_ascend_secs_before_event", 30);
//	#/
//	level.elevator_ascend = spawn_tag_origin();
//
//	thread handle_elevator_move();
//	level.elevator_hinge = GetEnt("elevator_hinge", "targetname");
//	Assert(IsDefined(level.elevator_hinge));
//	
//	level.elevator_hinge_base = GetEnt("elevator_hinge_base", "targetname");
//	Assert(IsDefined(level.elevator_hinge_base));
//	
//	level.elevator_hinge_model = GetEnt("elevator_hinge_model", "targetname");
//	Assert(IsDefined(level.elevator_hinge_model));
//	
//	level.elevator_hinge thread hinge_move();
//	level.elevator_hinge_model thread hinge_model_move();
//	
//	thread closeshutters();
//	thread shockabsorbers_closed();
}

refractionCustomKillstreakFunc()
{
	level.killstreakWeildWeapons["refraction_turret_mp"] = true;
	
	level thread maps\mp\killstreaks\streak_mp_refraction::init();
}

refractionCustomOSPFunc()
{
	level.orbitalsupportoverrides.spawnAngleMin 	= 260;
	level.orbitalsupportoverrides.spawnAngleMax 	= 350;
	level.orbitalsupportoverrides.turretPitch		= 50;
	level.orbitalsupportoverrides.topArc			= -38;
	level.orbitalsupportoverrides.spawnHeight 		= 10426;
}

refractionVulcanCustomFunc()
{
	level.orbitallaseroverrides.spawnPoint = ( 20, -500, 0 );
}

//onRefractionPlayerConnect()
//{
//	level endon( "game_ended" );
//	ui_ascend_screen = -1;
//	
//	while ( true )
//	{
//		level waittill( "connected", player );
//		
//		time_limit = maps\mp\_dynamic_events::getDynamicEventTimeLimit();
//		start_time = maps\mp\_dynamic_events::getDynamicEventStartTime();
//		
//		refraction_final_countdown = level.elevator_anim_time + time_limit - start_time - GetTime()/1000.0;
//		
//		// Set the visible countdown timer that appears in the level.
//		player SetClientOmnvar( "ui_ascend_countdown", refraction_final_countdown * 1000.0 + GetTime() );			//UI countdowns automatically subtract the current match time, so we have to add it back here with GetTime().
//	}
//}
//
//elevator_alarms()
//{ 
////	level waittill( "elevator_start_movement" );
//	wait ( 1 );
//	level waittill( "countdown_less_than_30" );
	//thread maps\mp\mp_refraction_fx::warning_sign_show_fx();
//	
	//fxobj = SpawnFx( level.alarmfx, self.origin );
	//triggerfx( fxobj, -1 );
//		   
//    //light pulse vfx on mechanism part b
    //thread maps\mp\mp_refraction_fx::part_b_mechanism_light_pulse_fx();
//    thread maps\mp\mp_refraction_fx::mechanism_center_lights_event_fx();
//	
//	//self thread play_alarm_sfx();
//	level waittill( "elevator_ended_movement" );
//
//	//turns off warning signs
//	thread maps\mp\mp_refraction_fx::warning_sign_hide_fx();
//	
	//fxobj delete();
//}
//	//refraction_elevator_siren -- is now "refraction_elevator_alarm"
//	//dubai_elevator_heli_crash	
//	
///*	
//play_alarm_sfx()
//{
//	level endon( "elevator_ended_movement" );
//	
//	while (1) 
//	{
//		thread playSoundInSpace( "refraction_elevator_alarm", self.origin );	
//		wait (5); 
//	}
//}
//*/
//	
//elevator_handle_kill_trigger()
//{
//	elevator_kill_trigger = GetEntArray( "elevator_kill_trigger", "targetname");
//	
//	foreach (trig in elevator_kill_trigger)
//	{
//		trig trigger_off();
//	}
//
//	while (!isdefined(level.space_elevator) || !isdefined(level.elevator_triggerz))
//		wait 0.05;
//	
//	while (level.space_elevator.origin[2] > level.elevator_triggerz)
//		wait 0.05;
//    
//    foreach (trig in elevator_kill_trigger)
//	{
//		trig trigger_on();
//	}
//}
//
//dynamicEventStartFunc()
//{
//	// Change the state of the display screens in mp_refraction. 0 = show the countdown. 1 = show countdown in red. 2 = show an icon that indicates the elevator has arrived.
//	SetDvar( "ui_ascend_screen", 1 );
//	
//	level notify( "countdown_less_than_30" );
//	level notify( "aud_play_30_sec_warning" );
//	
//	//thread maps\mp\mp_refraction_fx::elevator_cloud_fx();
//	
//	level maps\mp\gametypes\_hostmigration::waittill_notify_or_timeout_hostmigration_pause( "none", level.elevator_go_time );
//	
//	level notify( "elevator_start_movement" );
//	
//	openshutters(); //opens shutters
//	
//	openplates(); //opens elevator housing plates
//	
//	while( level.space_elevator.origin[2] > level.space_elevator.org_origin[2] )
//	{
//		wait .05;
//	}
//	
//	// The elevator has landed, change the timer display.
//	SetDvar( "ui_ascend_screen", 2 );
//	
//	level notify( "elevator_ended_movement" );
//	
//	if( level.gametype == "ctf" )
//	{
//		foreach( teamFlag in level.teamFlags )
//		{
//			if( teamFlag maps\mp\gametypes\_gameobjects::isTouchingBadTrigger() )
//				teamFlag maps\mp\gametypes\ctf::returnFlag();
//		}
//	}
//		
//	thread rotateBrushModel();//rotate elevator hinge
//	
//	wait( 3 );
//	
//	moveclamps();//locks elevator hinge in place
//	
//	level notify( "aud_play_elevator_arrived" );
//}
//
//setup_elevator_paths_and_spawns()
//{
//	// Pre Event Setup
//	level waittill( "prematch_over" );
//	
//	set_pathing_and_spawn_state( "pre_event" );
//	delete_path_geo();
//	level.dynamicSpawns = ::GetListOfGoodSpawnPoints;
//		
//	if( level.gametype == "dom" )
//		maps\mp\gametypes\dom::flagSetup();
//	
//	// Event Start
//	level waittill( "dynamic_event_starting" );
//	set_pathing_and_spawn_state( "during_event" );
//	
//	// Event End
//	level waittill( "elevator_ended_movement" );
//	set_pathing_and_spawn_state( "post_event" );
//	
//	if( level.gametype == "dom" )
//	{
//		elevator_b_dom_move();
//		maps\mp\gametypes\dom::flagSetup();
//	}
//}
//
//delete_path_geo()
//{
//	// Delete platforms used for setting up the elevator pathing and spawns
//	elevator_path_geo = GetEntArray( "elevator_path_geo", "targetname" );
//	if( IsDefined( elevator_path_geo ) )
//	{ 
//		foreach ( platform in elevator_path_geo )
//			platform delete();
//	}
//}
//
//GetListOfGoodSpawnPoints( fullListOfSpawnPoints )
//{
//	goodpoints = [];
//	
//	// Getting all neutral spawns
//	foreach( spawnpoint in fullListOfSpawnPoints )
//	{
//		if( !IsDefined( spawnpoint.targetname ) || ( spawnpoint.targetname == "" ) )
//			goodpoints = add_to_array( goodpoints, spawnpoint );
//		else if( spawnpoint GetValidSpawns() == true )
//			goodpoints = add_to_array( goodpoints, spawnpoint );
//	}
//	return goodpoints;
//}
//
//GetValidSpawns()
//{
//	if( level.refraction_dynamic_spawns_state == "pre_event" )
//	{
//		if( self.targetname == "pre_event_spawn" )
//			return true;
//	}
//	else if( level.refraction_dynamic_spawns_state == "post_event" )
//	{
//		if( self.targetname == "post_event_spawn" )
//			return true;
//	}	
//	return false;
//}
//
//elevator_descend_move( deltaz )
//{	
//	if( !isdefined( level.space_elevator ) )
//	{
//		level.space_elevator = self;
//		level.space_elevator.org_origin = self.origin;
//		level.elevator_triggerz = self.origin[2] + 64;
//	}
//	self.origin = self.origin + (0,0,deltaz);
//	foreach ( part in self.elevator_parts )
//	{
//		part hide();
//	}
//	
//	level waittill( "elevator_start_movement" );
//	thread show_elevator_parts();
//	
//	//elevator descending trail fx
	//thread maps\mp\mp_refraction_fx::elevator_descent_fx();
//	
//	self thread audio_function_handler();
//	
//	self MoveTo( (self.origin[0],self.origin[1],self.origin[2] - deltaz), 12, 0, 8);
//	
//	//turns on flashing warning signs
////	thread maps\mp\mp_refraction_fx::warning_sign_show_fx();
//		
//	//turns on the fake light glows that shine through the elevator framework
	//thread maps\mp\mp_refraction_fx::elevator_shaft_fake_light_rays();
//	
//	//turns on the spark vfx on the elevator frame as elevator descends
	//thread maps\mp\mp_refraction_fx::elevator_descend_spark_fx();
//	
//	//turns off the rain inside the elevator housing
	//thread maps\mp\mp_refraction_fx::elevator_rain_off_fx();
	//thread maps\mp\mp_refraction_fx::elevator_steam_off_fx();
//	
//	//turns on the steam vfx between the walk-way and elevator when elevator has moved into position
	//thread maps\mp\mp_refraction_fx::elevator_wall_steam_rise_fx();
//	
//	//water splash vfx on walk way after elevator has moved into position
	//thread maps\mp\mp_refraction_fx::elevator_rm_dripping_water_fx();
//	
//	//wind gust and steam vfx when elevator lands
	//thread maps\mp\mp_refraction_fx::elevator_arrival_wind_gust_fx();
	//thread maps\mp\mp_refraction_fx::steam_vent_burst_fx();
//	
//	//descending light vfx in outer vent area when elevator nears its destination
	//thread maps\mp\mp_refraction_fx::elevator_outer_vent_lights_fx();
//}
//
//elevator_ascend_timer()
//{
//	level endon( "elevator_start_movement" );
//	
//	time_limit = maps\mp\_dynamic_events::getDynamicEventTimeLimit();
//	start_time = maps\mp\_dynamic_events::getDynamicEventStartTime();
//	
//	if ( !IsDefined( time_limit ) || !IsDefined( start_time ) )
//	{
//		time_limit = getDynamicEventTimeLimit();
//		start_time = getDynamicEventStartTime() + 180;
//		/#
//		start_time = getDynamicEventStartTime() + GetDvarInt( "refraction_ascend_secs_before_event" );
//		#/
//	}
//	
//	while( time_limit > start_time )
//	{
//		wait( 1 );
//		maps\mp\gametypes\_hostmigration::waitTillHostMigrationDone();
//		time_limit = time_limit - 1;
//		/#
//		start_time = getDynamicEventStartTime() + GetDvarInt( "refraction_ascend_secs_before_event" );
//		#/
//	}
//
//	level notify( "elevator_ascend_start" );
//}
//
//elevator_ascend_move( deltaz )
//{
//	thread elevator_ascend_timer();
//
//	level waittill_any( "elevator_start_movement", "elevator_ascend_start" );
//	
//	//start vfx as elevator ascends
	//thread maps\mp\mp_refraction_fx::elevator_ascend_fx();
//
//	topz = self.origin[2] + deltaz;
//	self MoveTo( (self.origin[0], self.origin[1], topz), 20, 8, 0);
//	
//	self thread aud_handle_elevator_ascend();
//	
//	shockabsorbers();
//
//	// wait for elevator to hit top
//	while ( topz > self.origin[2] )
//		wait 1;
//
//	// elevator hit top, hide it
//	foreach ( part in self.elevator_parts )
//		part hide();
//}
//
//show_elevator_parts()
//{
//	cnt = self.elevator_parts.size;
//	num_per_frame = cnt/20;
//	
//	cnt = 0;
//    foreach ( part in self.elevator_parts )
//	{
//    	part show();
//    	cnt++;
//    	if ( cnt > num_per_frame )
//    	{
//    		cnt = 0;
//    		wait 0.05;
//    	}
//	}
//}
//
//audio_function_handler()
//{
//    self thread aud_handle_elevator();
//    self thread aud_handle_elevator_end();
//    self thread aud_handle_clamps();
//	self thread aud_handle_hinges();	
//}
//
//aud_handle_elevator_ascend()
//{
//	thread snd_play_linked_loop( "elevator_move_lp", self );	
//	
//	thread snd_play_linked( "mp_ref_ele_main_platform_leave", self );
//	thread snd_play_linked( "mp_ref_ele_main_platform_leave_lyr", self );	
//}
//
//aud_handle_elevator()
//{
//	if ( IsDefined ( level.space_elevator ) )
//	{
//		elevator = self;
////		playSoundAtPos( ( 1, -241, 2690 ), "elevator_start" );
//		playSoundAtPos( ( -4, 1152, 2161 ), "mp_rfract_elevator_int" );
//		thread aud_elevator_doors_open();
//		
//		level.aud_elevator_is_moving = true;
//		elevator PlayLoopSound( "elevator_move_lp" );
//		
///*
//		-functions currently don't work in MP; save for later
//		elevator SetVolume( 0, 0.1 );
//		elevator ScaleVolume( 1, 3 );
//*/	
//
//		level waittill( "elevator_ended_movement" );
//		thread snd_play_in_space_delayed( "mp_ref_ele_main_platform_arrived", ( 3, 403, 2290 ), 0 );
//		level.aud_elevator_is_moving = false;
//		elevator StopLoopSound( "elevator_move_lp" );
//	}
//}
//
//aud_handle_elevator_end()
//{
//	if ( level.aud_elevator_is_moving == true )
//	{
//		wait( 10.8 );
//	
////		playSoundAtPos( ( 1, 27, 2351), "elevator_end" );
//	}
//}
//
//aud_elevator_doors_open()
//{
//	wait( 11.75 );
//	playSoundAtPos( ( -675, 467, 2122 ), "mp_rfract_elevator_door_open" );
//	playSoundAtPos( ( 669, 481, 2124 ), "mp_rfract_elevator_door_open" );
//	playSoundAtPos( ( 3, 187, 2330 ), "mp_rfract_elevator_door_open" );
//}
//
//aud_handle_hinges()
//{
//	level waittill ( "hinges_start_movement" );
//
//	// Center Clamps
//	thread snd_play_in_space_delayed( "mp_ref_ele_main_clamp_full",  ( -2, -484, 2361 ), 0.3 );
//	thread snd_play_in_space_delayed( "mp_ref_ele_left_arm_down_body",  ( -2, -484, 2361 ), 3 );	
//	thread snd_play_in_space_delayed( "mp_ref_ele_clamps_stress_01",  ( 369, -505, 2527 ), 2 );	
//	thread snd_play_in_space_delayed( "mp_ref_ele_clamps_stress_02",  ( 369, -505, 2527 ), 2 );	
//	thread snd_play_in_space_delayed( "mp_ref_ele_main_clamp_stop",  ( 369, -505, 2527 ), 5.5 );		
//	
//	// LEFT Side CLAMPS
//	thread snd_play_in_space_delayed( "mp_ref_ele_clamps_stress_03",  ( -996, -531, 2449 ), 8.9 );
//	thread snd_play_in_space_delayed( "mp_ref_ele_left_arm_down_start",  ( -996, -531, 2449 ), 7 );	
//	thread snd_play_in_space_delayed( "mp_ref_ele_left_arm_down_full",  ( -996, -531, 2449 ), 9.9 );
//	thread snd_play_in_space_delayed( "mp_ref_ele_clamps_stress_02",  ( -996, -531, 2449 ), 13.4 );	
//	thread snd_play_in_space_delayed( "mp_ref_ele_clamps_stress_03",  ( -996, -531, 2449 ), 13.4 );	
//	
//	
//	// Blue Spinny Power Thing Inside
//	//thread snd_play_in_space_delayed( "mp_ref_ele_clamps_stress_03",  ( -200, -527, 2254 ), 10.4 );		
//
//
//	// Blue Spinny Power Thing Outside
//	//thread snd_play_in_space_delayed( "mp_ref_ele_clamps_stress_03",  ( 558, -528, 2254 ), 10.4 );
//
//	
//	
//	
//	/*
//	// 3.3 SERVO MOVE MAIN CLAMP.
//		//thread snd_play_in_space_delayed( "mp_ref_ele_main_clamp_stop",  ( 369, -505, 2527 ), 5.75 );	
//
//	//left side (facing elevator);
//	thread snd_play_in_space_delayed( "elevator_hinges_start", ( -134, -270, 2390 ), 0 );	
//	
//	// right side (facing elevator)
//	thread snd_play_in_space_delayed( "elevator_hinges_start", ( 158, -270, 2390 ), 0 );	
//	
//	//platform
//	thread snd_play_in_space_delayed( "mp_rfract_platform", ( 3, -452, 2477 ), 0 );	
//	
//	//wait( 2.82 );
//	//right clamp
//	
//	thread snd_play_in_space_delayed( "mp_rfract_right_clamp", ( 369, -505, 2527 ), 2.82 );	
//
//	//wait( 1.68 );
//	//left clamp right part
//	thread snd_play_in_space_delayed( "mp_rfract_left_clamp", ( -659, -526, 2524 ), 4.5 );	
//
//	//wait( 5.96 );
//	//left clamp left part
//	thread snd_play_in_space_delayed( "mp_rfract_left_clamp_left_big", ( -879, -529, 2474 ), 10.46 );
//
//	//wait( 1 );
//	//left clamp small parts
//	thread snd_play_in_space_delayed( "mp_rfract_left_clamp_left_sml", ( -879, -529, 2474 ), 11.46 );
//
//	*/
//}
//
//aud_handle_clamps()
//{
//	level waittill( "clamps_start_movement" );
//	
//	// left clamp (facing elevator)
////	playSoundAtPos( ( -397, -523, 2452 ), "elevator_clamps_start" );
//	
//	// right clamp (facing elevator)
////	playSoundAtPos( ( 388, -523, 2452 ), "elevator_clamps_start" );
//}
//
//aud_handle_alarm()
//{
//	level endon( "elevator_ended_movement" );
//	
//	level waittill( "aud_play_30_sec_warning" );	
//	
//	while( 1 )
//	{
//		// Left Side Door
//		thread snd_play_in_space( "mp_ref_ele_main_platform_alarm", ( -1049, 92, 2234 ) );
//		
//		// Left Side hanging Sign
//		thread snd_play_in_space( "mp_ref_ele_main_platform_alarm", ( -398, 150, 2399 ) );
//		
//		// Right Side Hanging Sign.
//		thread snd_play_in_space( "mp_ref_ele_main_platform_alarm", ( 377, 128, 2379) );	
//		
//		wait( 4 );
//	} 
//}
//
//handle_elevator_move()
//{
//	deltaz = level.elevator_max_z - level.elevator_min_z;
//
//	level.elevator_origin.elevator_parts = getEntArray( "elevator_descend", "targetname" );
//	level.elevator_origin.origin = level.elevator_origin.elevator_parts[0].origin;
//	level.elevator_origin.angles = level.elevator_origin.elevator_parts[0].angles;
//	foreach ( part in level.elevator_origin.elevator_parts )
//	{
//		part.lightingstate = 1;
//		part LinkToSynchronizedParent( level.elevator_origin );
//	}
//	level.elevator_origin thread elevator_descend_move( deltaz );
//	
//	level.elevator_ascend.elevator_parts = getEntArray( "elevator_ascend", "targetname" );
//	level.elevator_ascend.origin = level.elevator_ascend.elevator_parts[0].origin;
//	level.elevator_ascend.angles = level.elevator_ascend.elevator_parts[0].angles;
//	foreach ( part in level.elevator_ascend.elevator_parts )
//	{
//		part LinkToSynchronizedParent( level.elevator_ascend );
//	}
//	level.elevator_ascend thread elevator_ascend_move( deltaz );
//}

radar_dish_rotate()
{
	speed = 0;
	time = 40000;

	speed_multiplier = 1.0;
	if( isdefined( self.speed ) )
	{
		speed_multiplier = self.speed;
	}
	
	speed = 70; //randomfloatrange( 80, 120 );

	if( isdefined( self.script_noteworthy ) && (self.script_noteworthy=="lockedspeed") )
		wait 0;
	else
		wait randomfloatrange( 0, 1 );

	while ( true )
    {
       	self rotatevelocity( ( 0, speed, 0 ), time );
        wait time;
    }
}

set_lighting_values()
{
    if ( IsUsingHDR() )
    {        while (true)
        {
            level waittill("connected", player);               // we need to set the dvars for each player as he connects.
            player SetClientDvars(
                "r_tonemap", "1"
                );
                /*"r_tonemapadaptspeed", ".07",
                "r_tonemapkey", "0.05",
                "r_veil", "1",
                "r_veilstrength", ".15",
                "r_tonemapexposure", "-10",
				"r_tonemapmaxexposure", "10.25",
				"r_ssaoPower", "12.0",
				"r_ssaoStrength", "0.45",
				"r_ssaominstrengthdepth", "25.0",
				"r_ssaomaxstrengthdepth", "40.0"
				*/
         	
            //Controling how much SSAO there is in the scene
//			setdvar ("r_ssaoPower", "3.5");
//			setdvar ("r_ssaoBlurRadius", "1.5");
        }
    }
}

//ab_lighting()
//{
//	level waittill("elevator_ended_movement");
//	SetLightingState( 2 );
//}
//
////Moves B Domination Flag into the elevator after the elevator has touched down.
//elevator_b_dom_move()
//{
//	if (IsDefined(level.domFlags))
//	{
//		foreach (flag in level.domFlags)
//		{
//			if (flag.label == "_b")
//			{
//				//Resetting the B Dom Flag to neutral.
//				oldTeam = flag maps\mp\gametypes\_gameobjects::getOwnerTeam();
//				
//				if (oldTeam != "neutral")
//				{
//					flag maps\mp\gametypes\_gameobjects::setOwnerTeam( "neutral" );
//					flag maps\mp\gametypes\_gameobjects::set2DIcon( "enemy", "waypoint_captureneutral_b" );
//					flag maps\mp\gametypes\_gameobjects::set3DIcon( "enemy", "waypoint_captureneutral_b" );
//					flag.visuals[0] setModel( game["flagmodels"]["neutral"] );
//					
//					thread playSoundOnPlayers("mp_war_objective_lost", oldTeam);
//					maps\mp\gametypes\dom::statusDialog( "lost_b", oldTeam, true );
//					
//					level.bestSpawnFlag[ oldTeam ] = flag.levelFlag;
//				}
//				
//				// hide the dom point
//				flag maps\mp\gametypes\_gameobjects::setVisibleTeam( "none" );
//				flag.visuals[0] hide();
//				
//				//Moving the B Dom Flag into the elevator.
//				post_event_flag_b_origin = getent( "post_event_flag_b_origin", "targetname" );
//				flag maps\mp\gametypes\_gameobjects::move_use_object( post_event_flag_b_origin.origin, (0,0,100) );
//				
//				// show the domPoint again
//				flag.visuals[0] show();
//				flag maps\mp\gametypes\_gameobjects::setVisibleTeam( "any" );
//			}
//		}
//	}
//}
//
//hinge_move()
//{	
//	deltaz = level.elevator_max_z - level.elevator_min_z;
//   
//    level.elevator_hinge_base.origin =  level.elevator_hinge_base.origin + (0,0,deltaz);
//    self.origin = self.origin + (0,0,deltaz);
//   
////    self hide();
////	level.elevator_hinge_base hide();
//
//    level waittill( "elevator_start_movement" );
//    
//    self show();
//    level.elevator_hinge_base show();
//
//    self MoveTo( (self.origin[0],self.origin[1],self.origin[2] - deltaz), 12, 0, 8);
//    level.elevator_hinge_base MoveTo( (level.elevator_hinge_base.origin[0],level.elevator_hinge_base.origin[1],level.elevator_hinge_base.origin[2] - deltaz), 12, 0, 8);
//}
//
//hinge_model_move()
//{	
//	deltaz = level.elevator_max_z - level.elevator_min_z;
//   
//    self.origin = self.origin + (0,0,deltaz);
//   
////    self hide();
//
//    level waittill( "elevator_start_movement" );
//    
//    self show();
//    level.elevator_hinge_model ScriptModelPlayAnim("elevator_support_clamp_static");
//
//    self MoveTo( (self.origin[0],self.origin[1],self.origin[2] - deltaz), 12, 0, 8);
//}
//
//rotateBrushModel()
//{
//	level notify( "hinges_start_movement" );
//
//	//rotate brush model
//	level.elevator_hinge RotateTo( (level.elevator_hinge.angles + ( 0,0,90 )),3,1,2 );
//	level.elevator_hinge_base RotateTo( (level.elevator_hinge.angles + ( 0,0,90 )),3,1,2 );
//	level.elevator_hinge_model ScriptModelClearAnim("elevator_support_clamp_static");
//	level.elevator_hinge_model ScriptModelPlayAnim("elevator_support_clamp_anim");
//	
//	thread elevator_base_lock_location();
//	
//	//turn on steam release vfx as elevator cage rotates into position
//	//thread maps\mp\mp_refraction_fx::elevator_cage_steam_fx();
//	
//	//play sparks vfx on clamps
	//thread maps\mp\mp_refraction_fx::elevator_clamps_spark_fx();
//	
//	//play steam exhaust vfx on mechanism
	//thread maps\mp\mp_refraction_fx::elevator_mechanism_steam_fx();
//	
//	wait 0.05;	// trying to prevent hitching
//	
//	//dblair - this is needed because of networking issues
//	partsPerTick = level.elevator_origin.elevator_parts.size / 20;
//	cnt = 0;
//	foreach ( part in level.elevator_origin.elevator_parts )
//	{
//		part Unlink();
//		part SetCanSpawnVehiclesOn( true );
//		cnt++;
//		if ( cnt >= partsPerTick )
//		{	// spread out the unlink
//			cnt = 0;
//			wait 0.05;
//		}
//	}
//
//	//get elevator doors
//	elevator_door_a = getent("elevator_sliding_door_a", "target");
//	elevator_door_b = getent("elevator_sliding_door_b", "target");
//	elevator_door_c = getent("elevator_sliding_door_c", "target");
//	
//	//get elevator doors tags and collisions
//	elevator_door_a_tag = getent("elevator_sliding_door_a_tag", "target");
//	elevator_door_a_tag ScriptModelClearAnim();
//	elevator_door_a_tag.origin = elevator_door_a.origin;
//	elevator_door_a_tag.angles = elevator_door_a.angles;
//		
//	elevator_door_a_collision = getent("elevator_sliding_door_a_collision", "target");
//	elevator_door_a_collision LinkToSynchronizedParent(elevator_door_a_tag, "tag_origin");
//
//	//decompression steam vfx when doors open
	//thread maps\mp\mp_refraction_fx::open_sliding_doors_fx();
//	
//	elevator_door_a ScriptModelPlayAnimDeltaMotion("ref_elevator_sliding_door_open");
//	elevator_door_a_tag ScriptModelPlayAnimDeltaMotion("ref_elevator_sliding_door_open_collision");
//	wait 0.05;	// spread out the animations starting by a frame to help prevent hitch
//	
//	elevator_door_b_tag = getent("elevator_sliding_door_b_tag", "target");
//	elevator_door_b_tag ScriptModelClearAnim();
//	elevator_door_b_tag.origin = elevator_door_b.origin;
//	elevator_door_b_tag.angles = elevator_door_b.angles;
//		
//	elevator_door_b_collision = getent("elevator_sliding_door_b_collision", "target");
//	elevator_door_b_collision LinkToSynchronizedParent(elevator_door_b_tag, "tag_origin");
//
//	elevator_door_b ScriptModelPlayAnimDeltaMotion("ref_elevator_sliding_door_open");
//	elevator_door_b_tag ScriptModelPlayAnimDeltaMotion("ref_elevator_sliding_door_open_collision");
//	wait 0.05;	// spread out the animations starting by a frame to help prevent hitch
//	
//	elevator_door_c_tag = getent("elevator_sliding_door_c_tag", "target");
//	elevator_door_c_tag ScriptModelClearAnim();
//	elevator_door_c_tag.origin = elevator_door_c.origin;
//	elevator_door_c_tag.angles = elevator_door_c.angles;
//		
//	elevator_door_c_collision = getent("elevator_sliding_door_c_collision", "target");
//	elevator_door_c_collision LinkToSynchronizedParent(elevator_door_c_tag, "tag_origin");
//
//	elevator_door_c ScriptModelPlayAnimDeltaMotion("ref_elevator_sliding_door_open");
//	elevator_door_c_tag ScriptModelPlayAnimDeltaMotion("ref_elevator_sliding_door_open_collision");
//}
//
//set_pathing_and_spawn_state( state )
//{
//	switch ( state )
//	{
//		//==========================================================
//		case "pre_event":
//		//==========================================================
//		
//			elevator_door_a = getent( "elevator_sliding_door_a_collision", "target" );
//			elevator_door_b = getent( "elevator_sliding_door_b_collision", "target" );
//			elevator_door_c = getent( "elevator_sliding_door_c_collision", "target" );
//			
//			elevator_outer_floor = getentarray( "ele_outer_floor", "target" );
//			path_blockers_pre_event = getentarray( "path_blocker_pre_event", "targetname" );
//			
//			sight_lines = getentarray( "elev_sight_line", "targetname" );
//			
//			foreach ( part in elevator_outer_floor )
//				part ConnectPaths();
//			
//			// Link lower paths through the doors
//			elevator_door_a ConnectPaths();
//			elevator_door_b ConnectPaths();
//			elevator_door_c ConnectPaths();
//			
//			foreach ( blocker in path_blockers_pre_event )
//				blocker NotSolid();
//			
//			foreach (clip in sight_lines)
//			{
//				clip SetAISightLineVisible(0);
//				clip Hide();
//				clip NotSolid();
//				clip ConnectPaths();
//			}
//			
//			
//			level.refraction_dynamic_spawns_state = "pre_event";
//			break;
//		
//		//==========================================================
//		case "during_event":
//		//==========================================================
//		
//			level.refraction_dynamic_spawns_state = "during_event";
//			break;
//		
//		//==========================================================
//		case "post_event":
//		//==========================================================
//		
//			elevator_outer_floor = getentarray( "ele_outer_floor", "target" );
//			path_blockers_pre_event = getentarray( "path_blocker_pre_event", "targetname" );
//			sight_lines = getentarray( "elev_sight_line", "targetname" );
//			
//			foreach ( blocker_pre in path_blockers_pre_event )
//				blocker_pre ConnectPaths();
//			
//			foreach ( blocker in elevator_outer_floor )
//				blocker DisconnectPaths();
//			
//			foreach (clip in sight_lines)
//			{
//				clip SetAISightLineVisible(1);
//				clip Show();
//				clip DisconnectPaths();
//			}
//				
//			
//			thread set_spawn_state_delayed( "post_event", 8 );
//			break;
//		
//		//==========================================================
//		default:
//		//==========================================================
//		
//			break;
//	}
//}
//
//set_spawn_state_delayed( state, delay_length )
//{
//	if( !IsDefined( delay_length ) )
//		delay_length = 0;
//			
//	wait( delay_length );
//	level.refraction_dynamic_spawns_state = state;
//}
//
//elevator_base_lock_location()
//{
//	wait 3;
//	
//	level.elevator_hinge_base MoveTo( (level.elevator_hinge_base.origin[0],level.elevator_hinge_base.origin[1],level.elevator_hinge_base.origin[2] - 140), 3.5, 0, 1);
//}
//
//#using_animtree( "animated_props" );
//moveClamps()
//{
//	wait(0.05);
//	Lock_part_a = getent("elevator_lock_a", "targetname");
//	Lock_part_b = getent("elevator_lock_b", "targetname");
//	Lock_part_c = getent("elevator_lock_c", "targetname");
//	Lock_part_d = getent("elevator_lock_d", "targetname");
//	
//	Lock_part_a ScriptModelPlayAnim("elevator_lock_parta");
//	Lock_part_b ScriptModelPlayAnim("elevator_lock_partb");
//	Lock_part_c ScriptModelPlayAnim("elevator_lock_partc");
//	Lock_part_d ScriptModelPlayAnim("elevator_lock_partd");
//	
//	ClampCollision = getent("clamp_collision", "targetname");
//	ClampCollision MoveZ(-10000,2);
//	
//	ClampCollision2 = getent("clamp_collision_2", "targetname");
//	ClampCollision2 MoveZ(-10000,2);
//	
//	//Piston Animations
//	pistons_01 = getentarray("piston_01", "targetname");
//	pistons_02 = getentarray("piston_02", "targetname");
//	
//	foreach(piston in pistons_01)
//	{
//		piston ScriptModelPlayAnim("elevator_piston_01");
//	}	
//	
//	foreach(piston2 in pistons_02)
//	{
//		piston2 ScriptModelPlayAnim("elevator_piston_02");
//	}	
//	
//	//turns on light glows attached to mechanism part b
    //thread maps\mp\mp_refraction_fx::part_b_mechanism_light_glow_fx();
//}
//
//shockabsorbers()
//{
//	absorbers = getentarray("shock_absorber", "targetname");
//	
//	foreach(absorber in absorbers)
//	{
//		absorber ScriptModelPlayAnim("elevator_shock_absorber_up");
//	}
//}
//
//shockabsorbers_closed()
//{
//	absorbers = getentarray("shock_absorber", "targetname");
//	
//	foreach(absorber in absorbers)
//	{
//		absorber ScriptModelPlayAnim("elevator_shock_absorber_down");
//	}	
//}
//
//closeshutters()
//{
//	ref_shutters = getentarray("ref_elevator_shutters", "targetname");
//	
//	foreach(shutter in ref_shutters)
//	{
//		shutter ScriptModelPlayAnim("elevator_shutters_close");
//	}	
//}
//
//openshutters()
//{
//	ref_shutters = getentarray("ref_elevator_shutters", "targetname");
//	
//	foreach(shutter in ref_shutters)
//	{
//		shutter ScriptModelPlayAnim("elevator_shutters_open");
//	}
//	
	//thread maps\mp\mp_refraction_fx::open_shutters_fx();
//}
//
//openplates()
//{
//	//housing animations
//	plate_a_array = getentarray("housing_plate_a", "targetname");
//	plate_b_array = getentarray("housing_plate_b", "targetname");
//	
//	offset = RandomFloatRange (6,9);
//	wait(offset);
//		
//	
//	foreach(plate_a in plate_a_array)
//	{
//		plate_a ScriptModelPlayAnim("elevator_housing_plate_a");
//	}
//	
//	foreach(plate_b in plate_b_array)
//	{
//		plate_b ScriptModelPlayAnim("elevator_housing_plate_b");
//	}
//	
	//thread maps\mp\mp_refraction_fx::open_plates_fx();
//}
//
//aud_speaker_test( waittime )
//{
//	wait waittime;
//	
//	while(1)
//	{
//	 	level notify( "aud_play_30_sec_warning" );	
//	 	wait 15;
//	 	level notify( "aud_play_elevator_arrived" );
//	 	wait 20;
//	}
//}
//
//aud_setup_announce_speakers()
//{
//	level.speakers_int = [];
//	level.speakers_ext = [];
//	
//	// Interior Speakers
//	int_speaker_hangar_building = ( 1484, -1476, 2476 );
//	int_speaker_side_building_sml = ( 2203, 497, 2368 );
//	level.speakers_int = [ int_speaker_hangar_building, int_speaker_side_building_sml ];	
//	
//	// Exterior Speakers
//	ext_speaker_center_main = ( 1,353,3052 );
//	ext_speaker_elevator_shaft = ( 112, 1472, 3052 );
//	level.speakers_ext = [ ext_speaker_center_main, ext_speaker_elevator_shaft ];
//	
//	thread aud_monitor_30sec_warning( level.speakers_int, level.speakers_ext );
//	thread aud_monitor_elevator_arrived( level.speakers_int, level.speakers_ext );
//	thread aud_handle_alarm();	
//}
//
//aud_monitor_30sec_warning( int_speakers, ext_speakers )
//{
//	while(1)
//	{
//		level waittill( "aud_play_30_sec_warning" );
//		
//		// Play 2d versions
//		snd_play_in_space( "announce_ascend_incoming_int", (0,0,0) );
//		snd_play_in_space( "announce_ascend_incoming_ext", (0,0,0) );
//		
//		wait( 1 );
//	}
//}
//
//aud_monitor_elevator_arrived( int_speakers, ext_speakers )
//{
//	while(1)
//	{
//		level waittill( "aud_play_elevator_arrived" );
//		
//		
//		wait(13.75);
//		//2d Version
//		snd_play_in_space( "announce_ascend_arrived_int", ( 0,0,0 ) );
//		snd_play_in_space( "announce_ascend_arrived_ext", ( 0,0,0 ) );		
//		
//		wait( 1 );
//	}
//}