#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;

CONST_PYRAMID_RAMP_ANIM_TIME = 16.666;

main()
{
	maps\mp\mp_instinct_precache::main();
	maps\createart\mp_instinct_art::main();
	maps\mp\mp_instinct_fx::main();
//	SetLightingState(1);
	maps\mp\_load::main();
	maps\mp\mp_instinct_lighting::main();
	maps\mp\mp_instinct_aud::main();
	
	// Setting a map-specific OSP vision set.
	level.ospvisionset = "mp_instinct_osp";
	level.ospLightSet = "mp_instinct_osp";
	
	// Setting a map-specific warbird vision set.
	level.warbirdVisionSet = "mp_instinct_osp";
	
	maps\mp\_compass::setupMiniMap( "compass_map_mp_instinct" );
	
	game["attackers"] = "allies";
	game["defenders"] = "axis";
	
	level.aerial_pathnode_offset = 350;
	
	//level.mapCustomKillstreakFunc = ::instinctCustomKillstreakFunc;
	
	// OSP overrides
	level.orbitalSupportOverrideFunc = ::instinctCustomOSPFunc;
	
	//Precache
	PreCacheModel( "ins_crane_drilling_mechanism" );
	PreCacheModel( "ins_cave_drill" );
	PreCacheModel( "ins_generator_engine_01_fan" );
	
	//dynamic world
	level.river_drills = getentarray("river_drill", "targetname");
	level.cave_drills = getentarray("cave_drill", "targetname");
	level.cave_drills_inside = getentarray("cave_drill_inside", "targetname");
	level thread drilling_animation();
	level thread generator_fans();
	
//	//Dynamic Event Init
//	level instinct_DynamicEvent_init();
//	dynamic_pathing_init();
//	
//	//Dynamic Event Function
//	if (level.nextgen)
//		level thread DynamicEvent( ::instinct_DynamicEvent, undefined, ::instinct_DynamicEventEndState);
	level.goliath_bad_landing_volumes = getentarray( "goliath_bad_landing_volume", "targetname" ); 	
	
	SetDvar( "r_reactivemotionfrequencyscale", .5 );
	SetDvar( "r_reactivemotionamplitudescale", .5 );		
}

instinctCustomOSPFunc()
{
	level.orbitalsupportoverrides.spawnHeight 	= 9615;
	level.orbitalsupportoverrides.topArc 		= -35;
	level.orbitalsupportoverrides.rightArc		= 18;
	level.orbitalsupportoverrides.leftArc		= 18;

}

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", "2",
                 //"r_tonemapkey", "0"             
			 	 "r_tonemapLockAutoExposureAdjust", "0",
				 "r_tonemapAutoExposureAdjust", "0"                 
           );
             
        }
    }
}

//Dynamic Event

//watchDynamicEventStarted()
//{
//	level.dynamic_event_started = false;
//	level waittill( "dynamic_event_starting" );
//	level.dynamic_event_started = true; 
//}
//
//instinct_DynamicEvent_init()
//{	
//	level.dynamic_event_data = SpawnStruct();
//	
//	//get brushes that will be deleted during event
//	level.dynamic_event_data.damageArray = GetEntArray("pyramid_damage","targetname");
//	
//	//get inside cave drills
//	level.dynamic_event_data.inside_cave_drills = GetEntArray( "cave_drill_inside", "targetname" );
//	
//	//get damaged pyramid section and move it out of the world at start of match
//	level.dynamic_event_data.ramp_rubble_parent = spawn( "script_origin", (0,0,0) );
//	level.dynamic_event_data.rubble_ramp_array = GetEntArray( "pyramid_ramp_rubble","targetname" );
//	level thread setupPyramidRampRubble();
//	
//	level.dynamic_event_data.rubble_parent = spawn( "script_origin", (0,0,0) );
//	level.dynamic_event_data.rubbleArray = GetEntArray("pyramid_rubble","targetname");
//	level thread setupPyramidRubble();
//	
//	//get dynamic triggers from radiant
//	level.dynamic_event_data.triggerArray = GetEntArray("dynamic_death_trigger","targetname");
//	array_thread( level.dynamic_event_data.triggerArray, ::trigger_off );
//
//	level.dynamic_event_data.trigger2Array = GetEntArray("dynamic_death_trigger_02","targetname");
//	array_thread( level.dynamic_event_data.trigger2Array, ::trigger_off );
//	
//	level.dynamic_event_data.trigger3Array = GetEntArray("dynamic_death_trigger_03","targetname");
//	array_thread( level.dynamic_event_data.trigger3Array, ::trigger_off );
//	
//	//Rumble screen shakers
//	level.dynamic_event_data.screen_shakers = GetEntArray("pyramid_rumble", "targetname");
//	
//	level thread watchDynamicEventStarted();
//	level thread hide_rigid_bodies();
//}
//
//
//dynamic_pathing_init()
//{
//	rubble_targetname = GetEntArray( "pathing_lower_path_blockers", "targetname" );
//	rubble_target = GetEntArray( "pathing_lower_path_blockers", "target" );
//	
//	level.dynamic_pathing = SpawnStruct();
//	level.dynamic_pathing.lower_connectors = GetEntArray( "pathing_lower_connectors", "targetname" );
//	level.dynamic_pathing.upper_connectors = GetEntArray( "pathing_upper_connectors", "targetname" );
//	level.dynamic_pathing.upper_blockers = GetEntArray( "pathing_upper_path_blockers", "targetname" );
//	level.dynamic_pathing.lower_blockers = array_combine( rubble_target, rubble_targetname );
//	level.dynamic_pathing.lower_nodes = GetNodeArray( "pathing_lower_nodes", "targetname" );
//	level.dynamic_pathing.upper_nodes = GetNodeArray( "pathing_upper_nodes", "targetname" );
//
//	thread dynamic_pathing_main();
//}
//
//
//dynamic_pathing_main()
//{
//	thread dynamic_pathing_delete_node_geo();
//
//	//===================================================================
//	//							Pre-Event
//	//===================================================================
//	
//	level waittill( "instinct_dynamic_event_init_done" );
//	
//	thread dynamic_pathing_set_state( "pre_event" );
//	
//	level notify( "instinct_dynamic_pathing_pre_event_done" );
//	
//	//===================================================================
//	//							Post-Event
//	//===================================================================
//	
//	level waittill( "instinct_dynamic_event_end" );
//	
//	thread dynamic_pathing_set_state( "post_event" );
//	
//	if( level.gametype == "dom" )
//		maps\mp\gametypes\dom::flagSetup();
//}
//
//
//dynamic_pathing_set_state( state )
//{
//	switch ( state )
//	{
//		//==========================================================
//		case "pre_event":
//		//==========================================================
//			
//			// HACK: Start - Using script brushes for now to connect and disconnect pathnodes, will switch to Dis/ConnectNode() once it works
//			foreach( connector in level.dynamic_pathing.lower_connectors )
//			{
//				connector NotSolid();
//				connector ConnectPaths();
//			}
//			foreach( upper_connector in level.dynamic_pathing.upper_connectors )
//			{
//				upper_connector DisconnectPaths();
//				upper_connector NotSolid();
//			}
//			// HACK: End
//			
////			foreach ( lower_node in level.dynamic_pathing.lower_nodes )
////				lower_node ConnectNode();
////			foreach ( upper_node in level.dynamic_pathing.upper_nodes )
////				upper_node DisconnectNode();
//			
//			foreach ( lower_blocker in level.dynamic_pathing.lower_blockers )
//				lower_blocker ConnectPaths();
//			
//			if( level.gametype == "dom" )
//				thread rerun_flagSetup_for_Dom();
//			
//			break;
//		
//		//==========================================================
//		case "post_event":
//		//==========================================================
//			
//			// HACK: Start - Using script brushes for now to connect and disconnect pathnodes, will switch to Dis/ConnectNode() once it works
//			foreach( lower_connector in level.dynamic_pathing.lower_connectors )
//			{
//				lower_connector Solid();
//				lower_connector DisconnectPaths();
//				lower_connector NotSolid();
//			}
//			
//			foreach( upper_connector in level.dynamic_pathing.upper_connectors )
//			{
//				upper_connector NotSolid();
//				upper_connector ConnectPaths();
//			}
//			// HACK: End
//			
////			foreach ( lower_node in lower_nodes )
////				lower_node DisconnectNode();
////			foreach ( upper_node in upper_nodes )
////				upper_node ConnectNode();
//			
//			foreach( lower_blocker in level.dynamic_pathing.lower_blockers )
//			{
//				if( !IsRemovedEntity( lower_blocker ) )
//					lower_blocker DisconnectPaths();
//			}
//			
//			foreach ( blocker in level.dynamic_pathing.upper_blockers )
//				blocker ConnectPaths();
//			
//			break;
//		
//		//==========================================================
//		default:
//		//==========================================================
//			break;
//	}
//}
//
//
//dynamic_pathing_delete_node_geo()
//{
//	pathing_geo = GetEntArray( "pathing_node_geo", "targetname" );
//	foreach( geo in pathing_geo )
//		geo Delete();
//}
//
//
//rerun_flagSetup_for_Dom()
//{
//	level waittill( "prematch_done" );
//	maps\mp\gametypes\dom::flagSetup();
//}
//
//
//instinct_DynamicEventEndState()
//{
//	//TODO: vfx changes
//	//TODO: fix some missing triangles
//	
//	level notify( "end_drill_anims" );//end anims
//	foreach( drill in level.river_drills )
//		drill ScriptModelClearAnim();
//	foreach( drill in level.cave_drills )
//		drill ScriptModelClearAnim();
//	foreach( drill in level.cave_drills_inside )
//		drill ScriptModelClearAnim();
//	
//	thread ScriptableEndStateChange();
//	//thread exterior_explosion_animation( level.dynamic_event_data );
//	thread pyramidRampRubbleHandleGeo( level.dynamic_event_data );
//	thread spawnPyramidDamage(level.dynamic_event_data);
//	thread spawnPyramidRubble(level.dynamic_event_data);
//	thread spawnCaveTriggers(level.dynamic_event_data);
//	
//	level waittill( "instinct_dynamic_pathing_pre_event_done" );
//	level notify( "instinct_dynamic_event_end" );
//}
//
//instinct_DynamicEvent()
//{
//	animate_drills();
//
//	//pre explosion rumble and dust fall fx inside caves
//	thread pre_explosion_tremor(level.dynamic_event_data);
//	
//	//pigeons
//	thread maps\mp\mp_instinct_fx::pigeon_fx();
//	
//	//audio anouncer
//	thread aud_dynamic_event_announcer();
//	
//	//start flickering and emergency lights
//	thread ScriptableStateChange();
//	
//	//gas pipe bursts in cave
//	thread maps\mp\mp_instinct_fx::interior_gas_burst_fx();
//	thread maps\mp\mp_instinct_fx::interior_gas_rising_fx();
//	wait (24);
//	
//	//pre explosion rumble and gas burst fx
//	thread pre_explosion_gas_bursts_tremor(level.dynamic_event_data);	
//	thread maps\mp\mp_instinct_fx::exterior_gas_burst_fx();
//	wait (3);
//	
//	//interior explosion and fireball fx
//	thread interior_explosion_quake(level.dynamic_event_data);
//	thread maps\mp\mp_instinct_fx::hallway_fireball_fx();
//	wait (0.4);
//		
//	//exterior explosion and rockslide fx
//	thread maps\mp\mp_instinct_fx::pyramid_explosion_fx();
//	wait 0.6;
//	thread exterior_explosion_quake(level.dynamic_event_data);
//	thread exterior_explosion_animation( level.dynamic_event_data );
//	thread pyramidRampRubbleHandleGeo( level.dynamic_event_data );
//	thread spawnPyramidDamage(level.dynamic_event_data);
//	thread spawnPyramidRubble(level.dynamic_event_data);
//	thread spawnLongTriggers(level.dynamic_event_data);
//	thread spawnQuickTriggers(level.dynamic_event_data);
//	thread spawnCaveTriggers(level.dynamic_event_data);
//	
//	level notify( "instinct_dynamic_event_end" );
//}
//
//spawnPyramidDamage(dynamic_event_data)
//{
//	count = 0;
//	maxperfrm = 10;
//	foreach (damage in dynamic_event_data.damageArray) 
//	{		
//		damage Delete();
//		count++;
//		if ( count >= maxperfrm )
//		{
//			wait 0.05;
//			count = 0;
//		}
//	}
//	
//	foreach (damage in dynamic_event_data.inside_cave_drills) 
//	{		
//		damage Delete();
//		count++;
//		if ( count >= maxperfrm )
//		{
//			wait 0.05;
//			count = 0;
//		}
//	}	
//}
//
//spawnPyramidRubble(dynamic_event_data)
//{ 
//	assert( IsDefined( dynamic_event_data.rubble_parent ) );
//	
//	//script brushes to be moved into gameplay space during event	
//	dynamic_event_data.rubble_parent DontInterpolate();
//	dynamic_event_data.rubble_parent MoveX( -10000, .05 );	
//}
//
//
//setupPyramidRampRubble()
//{
//	dynamic_event_data = level.dynamic_event_data;
//	
//	assert( isDefined( dynamic_event_data.rubble_ramp_array ) );
//	assert( isDefined( dynamic_event_data.ramp_rubble_parent ) );
//	
//	count = 0;
//	maxperfrm = 10;
//	foreach ( rubble in dynamic_event_data.rubble_ramp_array ) 
//	{		
//		rubble LinkToSynchronizedParent( dynamic_event_data.ramp_rubble_parent );
//		count++;
//		if (count > maxperfrm)
//		{
//			wait 0.05;
//			count = 0;
//		}
//	}
//	dynamic_event_data.ramp_rubble_parent DontInterpolate();
//	dynamic_event_data.ramp_rubble_parent MoveX( -10000, .05 );
//	
//	wait( 0.1 );
//	
//	level notify( "instinct_dynamic_event_init_done" );
//}
//
//setupPyramidRubble()
//{
//	dynamic_event_data = level.dynamic_event_data;
//	
//	assert( isDefined( dynamic_event_data.rubbleArray ) );
//	assert( isDefined( dynamic_event_data.rubble_parent ) );
//	
//	count = 0;
//	maxperfrm = 10;
//	foreach (rubble in dynamic_event_data.rubbleArray) 
//	{
//		rubble LinkToSynchronizedParent( dynamic_event_data.rubble_parent );
//		count++;
//		if (count > maxperfrm)
//		{
//			wait 0.05;
//			count = 0;
//		}
//	}
//}
//
//pyramidRampRubbleHandleGeo( dynamic_event_data )
//{
//	if( !( GetDvar( "scr_dynamic_event_state", "on" ) == "endstate" ) )
//		wait( CONST_PYRAMID_RAMP_ANIM_TIME );
//	
//	//TODO: Matt Vitalone add fire end here
//	
//	//swap in state b lighting, hides undestroyed geo
//	SetLightingState(2);
//	
//	//script brushes to be moved into gameplay space during event
//	assert( IsDefined( dynamic_event_data.ramp_rubble_parent ) );
//	dynamic_event_data.ramp_rubble_parent DontInterpolate();
//	dynamic_event_data.ramp_rubble_parent.origin += ( 10000, 0, 0 );
//}
//
////death triggers for dynamic event
//
//spawnLongTriggers(dynamic_event_data)
//{	
//	foreach (trigger in dynamic_event_data.triggerArray) 	
//		trigger trigger_on();
//	
//	wait( CONST_PYRAMID_RAMP_ANIM_TIME );
//		
//	foreach (trigger in dynamic_event_data.triggerArray)
//		trigger trigger_off();
//}
//
//spawnQuickTriggers(dynamic_event_data)
//{
//	foreach (trigger2 in dynamic_event_data.trigger2Array)	
//		trigger2 trigger_on();
//
//	wait(1);
//		
//	foreach (trigger2 in dynamic_event_data.trigger2Array)
//		trigger2 trigger_off();
//}
//
//spawnCaveTriggers(dynamic_event_data)
//{
//	foreach (trigger3 in dynamic_event_data.trigger3Array) 		
//		trigger3 trigger_on();
//}
//
//
//////scriptable lights
//ScriptableStateChange()
//{
//	//flickering hanging lights
//	flickerLgtEnts = GetScriptableArray( "stateswap", "targetname" );
//	array_call( flickerLgtEnts, ::SetScriptablePartState, "static_part", "damaged" );
//	
//	//1st set of cave lanterns flicker
//	flickerAltLgtEnts = GetScriptableArray( "stateswap_alt", "targetname" );
//	array_call( flickerAltLgtEnts, ::SetScriptablePartState, "static_part", "damaged" );
//	
//	//2nd set of cave lanterns flicker
//	flickerAltLgtEnts = GetScriptableArray( "stateswap_alt2", "targetname" );
//	foreach ( flickerAltLgtEnt in flickerAltLgtEnts )
//	{
//		wait( .1 );
//		flickerAltLgtEnt SetScriptablePartState( "static_part", "damaged" );
//	}
//	
//	wait( 1 );
//	
//	//1st set of cave lanterns flicker
//	flickerAltLgtEnts = GetScriptableArray( "stateswap_alt", "targetname" );
//	array_call( flickerAltLgtEnts, ::SetScriptablePartState, "static_part", "healthy" );
//	
//	//2nd set of cave lanterns flicker
//	flickerAltLgtEnts = GetScriptableArray( "stateswap_alt2", "targetname" );
//	foreach ( flickerAltLgtEnt in flickerAltLgtEnts )
//	{
//		wait( .1 );
//		flickerAltLgtEnt SetScriptablePartState( "static_part", "healthy" );
//	}
//	
//	//hanging lights stop flickering
//	flickerLgtEnts = GetScriptableArray( "stateswap", "targetname" );
//	array_call( flickerLgtEnts, ::SetScriptablePartState, "static_part", "healthy" );
//	
//	wait( 2 );
//	
//	//1st set of cave lanterns flicker
//	flickerAltLgtEnts = GetScriptableArray( "stateswap_alt", "targetname" );
//	array_call( flickerAltLgtEnts, ::SetScriptablePartState, "static_part", "damaged" );
//	
//	//2nd set of cave lanterns flicker
//	flickerAltLgtEnts = GetScriptableArray( "stateswap_alt2", "targetname" );
//	foreach ( flickerAltLgtEnt in flickerAltLgtEnts )
//	{
//		wait( .1 );
//		flickerAltLgtEnt SetScriptablePartState( "static_part", "damaged" );
//	}
//	
//	//flicker hanging lights 
//	flickerLgtEnts = GetScriptableArray( "stateswap", "targetname" );
//	array_call( flickerLgtEnts, ::SetScriptablePartState, "static_part", "damaged" );
//	
//	wait( 1 );
//	
//	flickerAltLgtEnts = GetScriptableArray( "stateswap_alt2", "targetname" );
//	foreach ( flickerAltLgtEnt in flickerAltLgtEnts )
//	{
//		wait( .1 );
//		flickerAltLgtEnt SetScriptablePartState( "static_part", "healthy" );
//	}
//	
//	//hanging lights stop flickering
//	flickerLgtEnts = GetScriptableArray( "stateswap", "targetname" );
//	array_call( flickerLgtEnts, ::SetScriptablePartState, "static_part", "healthy" );
//	
//	wait( 2 );
//	
//	//1st set of cave lanterns alternate flicker state
//	flickerAltLgtEnts = GetScriptableArray( "stateswap_alt", "targetname" );
//	array_call( flickerAltLgtEnts, ::SetScriptablePartState, "static_part", "damaged_more" );
//	
//	//hanging lights alternate flicker state
//	flickerLgtEnts = GetScriptableArray( "stateswap", "targetname" );
//	array_call( flickerLgtEnts, ::SetScriptablePartState, "static_part", "damaged_more" );
//	
//	//2nd set of cave lanterns alternate flicker state
//	flickerAltLgtEnts = GetScriptableArray( "stateswap_alt2", "targetname" );
//	foreach ( flickerAltLgtEnt in flickerAltLgtEnts )
//	{
//		wait( .1 );
//		flickerAltLgtEnt SetScriptablePartState( "static_part", "damaged_more" );
//	}
//	
//	wait( 2.5 );
//	
//	///turn on tent sirens
//	OrangeSirenEnts = GetScriptableArray( "stateswap_siren", "targetname" );
//	array_call( OrangeSirenEnts, ::SetScriptablePartState, "static_part4", "siren_on" );
//	
//	//for flashing warning red lights
//	flashngRedEnts = GetScriptableArray( "stateswap_warning", "targetname" );
//	array_call( flashngRedEnts, ::SetScriptablePartState, "static_part1", "warning" );
//	
//	//1st set of cave lanterns destroyed state
//	flickerAltLgtEnts = GetScriptableArray( "stateswap_alt", "targetname" );
//	foreach ( flickerAltLgtEnt in flickerAltLgtEnts )
//	{
//		wait( .4 );
//		flickerAltLgtEnt SetScriptablePartState("static_part", "destroyed" );
//	}
//	
//	//2nd set of cave lanterns alternate damaged state
//	flickerAltLgtEnts = GetScriptableArray( "stateswap_alt2", "targetname" );
//	foreach ( flickerAltLgtEnt in flickerAltLgtEnts )
//	{
//		wait( .1 );
//		flickerAltLgtEnt SetScriptablePartState( "static_part", "destroyed" );
//	}
//	
//	wait( 4 );
//	
//	//hanging lights destroyed
//	flickerLgtEnts = GetScriptableArray( "stateswap", "targetname" );
//	
//	foreach ( flickerLgtEnt in flickerLgtEnts )
//	{
//		wait( .2 );
//		flickerLgtEnt SetScriptablePartState( "static_part", "destroyed" );
//	}
//	
//	
//	//turn off all other primary lights inside cave pre-event
//	CaveDynLgtEnts = GetScriptableArray( "stateswap_switch", "targetname" );
//	array_call( CaveDynLgtEnts, ::SetScriptablePartState, "static_part2", "off" );
//	
//	//1st set of cave lanterns final destroyed state
//	flickerAltLgtEnts = GetScriptableArray( "stateswap_alt", "targetname" );
//	foreach ( flickerAltLgtEnt in flickerAltLgtEnts )
//	{ 
//		wait( .5 );
//		flickerAltLgtEnt SetScriptablePartState( "static_part", "destroyed_complete" );
//	}
//	
//	//2nd set of cave lanterns destroyed state
//	flickerAltLgtEnts = GetScriptableArray( "stateswap_alt2", "targetname" );
//	foreach ( flickerAltLgtEnt in flickerAltLgtEnts )
//	{
//		wait( .5 );
//		flickerAltLgtEnt SetScriptablePartState( "static_part", "destroyed" );
//	}
//	
//	wait( 2 );
//	
//	//turn off warning red lights - go back to blue glow
//	flashngRedEnts = GetScriptableArray( "stateswap_warning", "targetname" );
//	array_call( flashngRedEnts, ::SetScriptablePartState, "static_part1", "healthy" );
//	
//	wait( 2 );
//	
//	//Hanging lights final destroyed state
//	flickerLgtEnts = GetScriptableArray( "stateswap", "targetname" );
//	array_call( flickerLgtEnts, ::SetScriptablePartState, "static_part", "destroyed_complete" );	
//	
//	///turn on fire lights
//	CaveFireLgtEnts = GetScriptableArray( "stateswap_switch3", "targetname" );
//	array_call( CaveFireLgtEnts, ::SetScriptablePartState, "static_part5", "fire_on" );
//	
//	//2nd set of cave lanterns final destroyed state
//	flickerAltLgtEnts = GetScriptableArray( "stateswap_alt2", "targetname" );
//	foreach ( flickerAltLgtEnt in flickerAltLgtEnts )
//	{
//		wait( .4 );
//		flickerAltLgtEnt SetScriptablePartState( "static_part", "destroyed_complete" );
//	}	
//
//}
//
//ScriptableEndStateChange()
//{
//	//turn off all other primary lights inside cave pre-event
//	CaveDynLgtEnts = GetScriptableArray( "stateswap_switch", "targetname" );
//	array_call( CaveDynLgtEnts, ::SetScriptablePartState, "static_part2", "off" );
//    
//	//turn on fire lights
//    CaveFireLgtEnts = GetScriptableArray( "stateswap_switch3", "targetname" );
//    array_call( CaveFireLgtEnts, ::SetScriptablePartState, "static_part5", "fire_on" );
//    
//	//turn on tent sirens
//	OrangeSirenEnts = GetScriptableArray( "stateswap_siren", "targetname" );
//	array_call( OrangeSirenEnts, ::SetScriptablePartState, "static_part4", "siren_on" );
//	
//	//Hanging lights final destroyed state
//	flickerLgtEnts = GetScriptableArray( "stateswap", "targetname" );
//	array_call( flickerLgtEnts, ::SetScriptablePartState, "static_part", "destroyed" ); 
//	
//	//1st set of cave lanterns final destroyed state
//	flickerAltLgtEnts = GetScriptableArray( "stateswap_alt", "targetname" );
//	flickerAltLgtEnts thread SetScriptablePartState_with_delay( .5, "static_part", "destroyed" );
//
//    //2nd set of cave lanterns final destroyed state
//	flickerAltLgtEnts = GetScriptableArray( "stateswap_alt2", "targetname" );
//	flickerAltLgtEnts thread SetScriptablePartState_with_delay( .4, "static_part", "destroyed" );
//}
//
//SetScriptablePartState_with_delay( delay, part, state, quietfail )
//{
//	assert( isArray( self ) );
//	assert( isDefined( delay ) );
//	
//	foreach( scriptable in self )
//	{
//		wait( delay );
//		scriptable SetScriptablePartState( part, state, quietfail );
//	}
//}
//
//pre_explosion_tremor(dynamic_event_data)
//{
//	
//	for ( i = 0; i < 5; i++ )
//	{
//	foreach (screen_shaker in dynamic_event_data.screen_shakers)
//		{
//			Earthquake(.1,4, screen_shaker.origin, 2000);
//			PhysicsJitter(screen_shaker.origin,2000, 1500, 150, 400);
//			screen_shaker playsound( "ins_pyramid_explode_shake" );
//			screen_shaker playsound( "ins_earthquake_alarm");
//		}
//	//IPrintLnBold ("cave_falling_debris");
//	thread maps\mp\mp_instinct_fx::cave_falling_debris_fx();
//	thread maps\mp\mp_instinct_fx::cave_rock_bouncing_fx();
//	wait (4);
//	}
//	
//	foreach (screen_shaker in dynamic_event_data.screen_shakers)
//		{
//			Earthquake(.14,5.5, screen_shaker.origin, 2000);
//			PhysicsJitter(screen_shaker.origin,2000, 1500, 150, 400);
//			
//			;
//			screen_shaker playsound( "ins_pyramid_explode_shake" );
//			screen_shaker playsound( "ins_earthquake_alarm");
//		}
//	//IPrintLnBold ("cave_falling_debris");
//	thread maps\mp\mp_instinct_fx::cave_falling_debris_fx();
//	thread maps\mp\mp_instinct_fx::cave_rock_bouncing_fx();
//}
//
//pre_explosion_gas_bursts_tremor(dynamic_event_data)
//{
//								
//	foreach (screen_shaker in dynamic_event_data.screen_shakers)
//	{
//	
//		Earthquake(.35,2, screen_shaker.origin, 2000);
//		PhysicsJitter(screen_shaker.origin,2000, 1500, 200, 400);
//		
//		
//		screen_shaker playsound( "ins_pyramid_explode_shake" );
//		screen_shaker playsound( "ins_earthquake_alarm");
//		//IPrintLnBold ("gas burst");
//	}
//	thread maps\mp\mp_instinct_fx::cave_falling_debris_fx();
//	thread maps\mp\mp_instinct_fx::cave_rock_bouncing_fx();
//}
//
//interior_explosion_quake(dynamic_event_data)
//{
//								
//	foreach (screen_shaker in dynamic_event_data.screen_shakers)
//	{
//		Earthquake(.4,1.2, screen_shaker.origin, 2000);
//		PhysicsJitter(screen_shaker.origin,2000, 1500, 300, 600);
//		
//	}
//	
//	foreach (screen_shaker in dynamic_event_data.screen_shakers)
//	{
//		screen_shaker playsound( "ins_pyramid_explode_shake" );
//		screen_shaker playsound( "ins_earthquake_alarm");
//
//		Earthquake(.1,4, screen_shaker.origin, 2000);
//		PhysicsJitter(screen_shaker.origin,2000, 1500, 400, 800);
//		
//	}
//}
//
//exterior_explosion_quake(dynamic_event_data)
//{
//								
//	foreach (screen_shaker in dynamic_event_data.screen_shakers)
//	{
//		screen_shaker playsound( "ins_pyramid_explode_shake" );
//		screen_shaker playsound( "ins_earthquake_alarm");
//
//		Earthquake(.5,1.6, screen_shaker.origin, 2000);
//		PhysicsJitter(screen_shaker.origin,2000, 1500, 500, 1000);
//		
//	
//	}
//	
//	thread maps\mp\mp_instinct_fx::stop_ambient_flare_fx();
//	
//}
//
//hide_rigid_bodies()
//{
//	wait(0.1);
//	pyramid_exterior_1 = getEnt("rigid_body_mesh_1", "targetname");
//	pyramid_exterior_2 = getEnt("rigid_body_mesh_2", "targetname");
//	pyramid_exterior_3 = getEnt("rigid_body_mesh_3", "targetname");
//	pyramid_exterior_4 = getEnt("rigid_body_mesh_4", "targetname");
//	pyramid_rubble_ramp = getEnt("rubble_ramp", "targetname");
//	pyramid_exterior_1 hide();
//	pyramid_exterior_2 hide();
//	pyramid_exterior_3 hide();
//	pyramid_exterior_4 hide();
//	pyramid_rubble_ramp hide();
//}
//
//exterior_explosion_animation( dynamic_event_data )
//{	
//	pyramid_exterior_1 = getEnt("rigid_body_mesh_1", "targetname");
//	pyramid_exterior_2 = getEnt("rigid_body_mesh_2", "targetname");
//	pyramid_exterior_3 = getEnt("rigid_body_mesh_3", "targetname");
//	pyramid_exterior_4 = getEnt("rigid_body_mesh_4", "targetname");
//	pyramid_rubble_ramp = getEnt("rubble_ramp", "targetname");
//	
//	pyramid_exterior_1 thread aud_dynamic_event_boom();
//	
//	pyramid_exterior_1.origin = (2105.719,-1453.111, 2133.478);
//	pyramid_exterior_2.origin = (1951.51, -1866.37, 2133.478);
//	pyramid_exterior_3.origin = (1869.571, -2214.039, 2133.478);
//	pyramid_exterior_4.origin = (1814.19, -2574.615, 2133.478);
//	pyramid_rubble_ramp.origin = (700, -1400, 1000);
//	
//	pyramid_exterior_1 show();
//	pyramid_exterior_2 show();
//	pyramid_exterior_3 show();
//	pyramid_exterior_4 show();
//	pyramid_rubble_ramp show();
//	
//	pyramid_exterior_1 ScriptModelPlayAnim("instinct_pyramid_exterior_1_anim");
//	pyramid_exterior_2 ScriptModelPlayAnim("instinct_pyramid_exterior_2_anim");
//	pyramid_exterior_3 ScriptModelPlayAnim("instinct_pyramid_exterior_3_anim");
//	pyramid_exterior_4 ScriptModelPlayAnim("instinct_pyramid_exterior_4_anim");
//	pyramid_rubble_ramp ScriptModelPlayAnim("instinct_pyramid_rubble_ramp_anim");
//	
//	wait( CONST_PYRAMID_RAMP_ANIM_TIME );
//	
//	pyramid_exterior_1 delete();
//	pyramid_exterior_2 delete();
//	pyramid_exterior_3 delete();
//	pyramid_exterior_4 delete();
//	pyramid_rubble_ramp delete();
//}

river_drilling_animation()
{
	level endon( "game_ended" );
	
	river_drill_fx = spawn_tag_origin();
	river_drill_exhaust_fx = spawn_tag_origin();
	river_drill_earthquake_fx = spawn_tag_origin();
	river_drill_dust_fx = spawn_tag_origin();
	
	wait (.05);
	river_drill_fx show();
	river_drill_exhaust_fx show();
	river_drill_earthquake_fx show();
	river_drill_dust_fx show();
	
	wait (0.4);
	
	//river_drill_fx.origin = (0,0,0);
	river_drill_fx LinkTo (self, "poundee", (75,0,400), (0,0,0));
	river_drill_exhaust_fx LinkTo (self, "poundee", (75,0,400), (90,0,90));
	river_drill_earthquake_fx LinkTo (self, "tag_origin", (0,0,100), (0,0,0));
	river_drill_dust_fx LinkTo (self, "tag_origin", (0,0,-100), (270,180,90));

	noself_delayCall( 1, ::PlayFXOnTag, getfx( "diesel_drill_smk_loop" ), river_drill_fx, "tag_origin" );
	wait (0.1);

	while( true )
	{
		Earthquake(.15,1, river_drill_earthquake_fx.origin, 500);
//		Earthquake(.15,1, cave_drill_earthquake_fx.origin, 500);
		noself_delayCall( .4, ::PlayFXOnTag, getfx( "drill_impact_dust" ), river_drill_dust_fx, "tag_origin" );
		wait (2);
		noself_delayCall( .4, ::PlayFXOnTag, getfx( "diesel_drill_smk_ring" ), river_drill_exhaust_fx, "tag_origin" );
		
	}
	
//	if (level.dynamic_event_started == true)
//	{
//		noself_delayCall( 0.1, ::StopFXOnTag, getfx( "diesel_drill_smk_loop" ), river_drill_fx, "tag_origin" );
//		//StopClientExploder(172);
//	}
}

//Drilling Mechanism
drilling_animation()
{
	level endon( "end_drill_anims" );
	
	wait( 1 );
	animate_drills();
}

animate_drills()
{
	if( isDefined( level.river_drills ) )
		array_thread (level.river_drills,  ::update_river_drill_anim);
	
	if( isDefined( level.cave_drills ) )
		array_thread (level.cave_drills, ::update_cave_drill_anim);
	
	if( isDefined( level.cave_drills_inside ) )
		array_thread (level.cave_drills_inside, ::update_cave_drill_anim_inside);
}

update_river_drill_anim()
{
	level endon( "end_drill_anims" );
	time_offset = RandomFloat(2);
	
	wait( .05 );//waiting for the notify
//	if (level.dynamic_event_started == true)
//	{
//		self notify( "lagos_dyn_event" );
//		self thread aud_piledriver_shake_and_break();
//		self ScriptModelClearAnim();
//		self ScriptModelPlayAnimDeltaMotion("ins_drilling_machine_dyn_event");
//		thread maps\mp\mp_instinct_fx::drill_damage_fx();
//	}
//	else
//	{
		wait (time_offset);
		ScriptModelPlayAnimWithNotify(self, "ins_drilling_machine", "ps_ins_piledriver_hit", "ins_piledriver_hit", "end_drill_anims", "stop_sequencing_notetracks", "lagos_dyn_event" );
		self thread river_drilling_animation();
//	} 
}
//
//aud_piledriver_shake_and_break()
//{
//	wait(1.5);
//	self thread snd_play_linked( "emt_hydraulics_release", self );
//	self thread snd_play_linked( "ins_piledriver_shake_break", self );	
//	wait(1);
//	self thread snd_play_linked( "ins_piledriver_shake_dying", self );	
//	self thread snd_play_linked( "emt_hydraulics_release", self );
//	wait(1);
//	self thread snd_play_linked( "ins_piledriver_shake_break", self );	
//	self thread snd_play_linked( "ins_piledriver_shake_dying_02", self );	
//	self thread snd_play_linked( "emt_hydraulics_release", self );
//	wait(1);
//	self thread snd_play_linked( "emt_hydraulics_release", self );
//	wait(2);
//	self thread snd_play_linked( "ins_piledriver_shake_dying_02", self );
//	self thread snd_play_linked( "emt_hydraulics_release", self );
//	self thread snd_play_linked( "ins_piledriver_shake_break", self );	
//	wait(4);
//	self thread snd_play_linked( "ins_piledriver_shake_break", self );	
//	wait(2);
//	self thread snd_play_linked( "ins_piledriver_shake_dying", self );	
//
//}


update_cave_drill_anim()
{
	
	time_offset = RandomFloat(2);
	
	wait( .05);//waiting for the notify
//	if (level.dynamic_event_started == true)
//	{
//		self notify( "lagos_dyn_event" );
//		self thread aud_piledriver_shake_and_break();
//		self ScriptModelClearAnim();
//		self ScriptModelPlayAnimDeltaMotion("ins_cave_drill_broken");
//		wait (1);
//		StopClientExploder(170); //turns off smoke on cave drills and some water drips in cave
//		StopClientExploder(172); //turns off cave drill rock impact vfx 
//	}
//	else
//	{
		wait (time_offset);
		ScriptModelPlayAnimWithNotify(self, "ins_cave_drill_idle", "ins_piledriver_cave_hit", "ins_piledriver_cave_hit", "end_drill_anims", "stop_sequencing_notetracks", "lagos_dyn_event" );
		if( IsDefined( self.script_noteworthy) && self.script_noteworthy == "impact_fx" )
		{
			//common_scripts\_exploder::activate_clientside_exploder(172);
			wait (0.5);
			thread maps\mp\mp_instinct_fx::cave_drill_rock_impact_fx();
		}
//	} 
		
}


update_cave_drill_anim_inside()
{
	level endon( "end_drill_anims" );
	
//	if (level.dynamic_event_started == true)
//	{
//		self notify( "lagos_dyn_event" );
//	}
//	else
//	{
	time_offset = RandomFloat(2);

	wait (time_offset);
		ScriptModelPlayAnimWithNotify(self, "ins_cave_drill_idle", "ins_piledriver_cave_hit", "ins_piledriver_cave_hit", "end_drill_anims", "stop_sequencing_notetracks", "lagos_dyn_event" );
//	}

}

//aud_dynamic_event_announcer()
//{
//	wait(0.75);
//	thread play_sound_in_space( "ins_pyramid_explode_announcer", (0,0,0) );
//	wait(10);
//	thread play_sound_in_space( "ins_pyramid_explode_announcer", (0,0,0) );
//}
//
//aud_dynamic_event_boom()
//{
//	rocks = self;
//	rocks playsound( "ins_pyramid_explode_big" );
//	rocks playsound( "ins_pyramid_explode_debris_rock_01" );
//}

generator_fans()
{
	fans = GetEntarray("generator_fans", "targetname");
	
	foreach (fan in fans)
	{
		fan ScriptModelPlayAnim( "ins_generator_fan" );
	}
	
}
