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


init()
{
	level.mp_refraction_killstreak_duration = 25;
	/#
		//Used for tuning purposes. Please do not delete.
//		SetDvarIfUninitialized( "mp_refraction_killstreak_duration", 25 );
	#/
	
	level.mp_refraction_InUse = false;
	level.refraction_turrets_alive = 0;
	level.refraction_turrets_moved_down = 0;
	level.mp_refraction_owner = undefined;
	
	level.killstreakFuncs["mp_refraction"] = ::tryUseMPRefraction;
	level.mapKillStreak = "mp_refraction";
	level.mapKillstreakPickupString = &"MP_REFRACTION_MAP_KILLSTREAK_PICKUP";
	level.killstreakWieldWeapons[ "refraction_turret_mp" ] = "refraction_turret_mp";
	
	if ( !IsDefined( level.sentrySettings ) )
		level.sentrySettings = [];
	
	level.sentrySettings[ "refraction_turret" ] = spawnStruct();
	level.sentrySettings[ "refraction_turret" ].health =				999999;		// keep it from dying anywhere in code
	level.sentrySettings[ "refraction_turret" ].maxHealth =				1000;		// this is the health we'll check
	level.sentrySettings[ "refraction_turret" ].burstMin =				20;
	level.sentrySettings[ "refraction_turret" ].burstMax =				120;
	level.sentrySettings[ "refraction_turret" ].pauseMin =				0.15;
	level.sentrySettings[ "refraction_turret" ].pauseMax =				0.35;
	level.sentrySettings[ "refraction_turret" ].sentryModeOn =			"sentry";
	level.sentrySettings[ "refraction_turret" ].sentryModeOff =			"sentry_offline";
	level.sentrySettings[ "refraction_turret" ].timeOut =				90.0;
	level.sentrySettings[ "refraction_turret" ].spinupTime =			0.05;
	level.sentrySettings[ "refraction_turret" ].overheatTime =			8.0;
	level.sentrySettings[ "refraction_turret" ].cooldownTime =			0.1;
	level.sentrySettings[ "refraction_turret" ].fxTime =				0.3;
	level.sentrySettings[ "refraction_turret" ].streakName =			"sentry";
	level.sentrySettings[ "refraction_turret" ].weaponInfo =			"refraction_turret_mp";
	level.sentrySettings[ "refraction_turret" ].modelBase =				"ref_turret_01";
	level.sentrySettings[ "refraction_turret" ].sentryType =			"refraction_turret";
	level.sentrySettings[ "refraction_turret" ].modelPlacement =		"sentry_minigun_weak_obj";
	level.sentrySettings[ "refraction_turret" ].modelPlacementFailed =	"sentry_minigun_weak_obj_red";
	level.sentrySettings[ "refraction_turret" ].modelDestroyed =		"sentry_minigun_weak_destroyed";
	level.sentrySettings[ "refraction_turret" ].hintString =			&"SENTRY_PICKUP";
	level.sentrySettings[ "refraction_turret" ].headIcon =				true;
	level.sentrySettings[ "refraction_turret" ].teamSplash =			"used_sentry";
	level.sentrySettings[ "refraction_turret" ].shouldSplash =			false;
	level.sentrySettings[ "refraction_turret" ].voDestroyed =			"sentry_destroyed";
	
	level.refraction_turrets = turret_setup();
	
	level.turret_movement_sound = "mp_refraction_turret_movement1";
	level.turret_movement2_sound = "mp_refraction_turret_movement2";
	level.turret_movement3_sound = "mp_refraction_turret_movement3";
}


/*
=============
///ScriptDocBegin
"Name: tryUseMPRefraction( <lifeId> )"
"Summary: function called when a player tries to use the mp_refraction map-based killstreak"
"Module: Entity"
"CallOn: a player"
"MandatoryArg: <lifeId>: "
"Example: level.killstreakFuncs["mp_refraction"] = ::tryUseMPRefraction;"
"SPMP: MP"
///ScriptDocEnd
=============
*/
tryUseMPRefraction( lifeId, modules )
{
	if ( isDefined( level.mp_refraction_owner ) || level.mp_refraction_InUse )
	{
		self iPrintLnBold( &"MP_REFRACTION_IN_USE" );
		return false;
	}

	if ( self isUsingRemote() )
	{
		return false;
	}
	
	if ( self isAirDenied() )
	{
		return false;
	}
	
	if ( self isEMPed() )
	{
		return false;
	}

	result = setRefractionTurretPlayer( self );
	
	if ( IsDefined( result ) && result )
	{
		self maps\mp\_matchdata::logKillstreakEvent( "mp_refraction", self.origin );
	}
	
	return result;
}


/*
=============
///ScriptDocBegin
"Name: refractionTurretTimer()"
"Summary: notifies after mp_refraction_killstreak_duration is up."
"Module: Entity"
"CallOn: the level"
"Example: level thread refractionTurretTimer();"
"SPMP: MP"
///ScriptDocEnd
=============
*/
refractionTurretTimer()
{
	self endon( "game_ended" );
	
	/#
//		level.mp_refraction_killstreak_duration = GetDvarInt( "mp_refraction_killstreak_duration", 25 );
	#/
	wait_time = level.mp_refraction_killstreak_duration;
	
	if ( level.mp_refraction_owner _hasPerk( "specialty_blackbox" ) && IsDefined( level.mp_refraction_owner.specialty_blackbox_bonus ) )
	{
		wait_time *= level.mp_refraction_owner.specialty_blackbox_bonus;
	}
	
	while ( wait_time > 0 )
	{
		wait( 1 );
		maps\mp\gametypes\_hostmigration::waitTillHostMigrationDone();
		wait_time -= 1.0;
		
		//End this thread if the killstreak is no longer in use. For example, end it if all the turrets are killed.
		if ( level.mp_refraction_InUse == false )
		{
			return;
		}
	}
	
	//If the killstreak ended because of time, some turrets might still be alive. Notify death for all turrets to deactivate them.
	for ( i = 0; i < level.refraction_turrets.size; i++ )
	{
		level.refraction_turrets[i] notify( "fake_refraction_death" );			//Using "fake_refraction_death" instead of "death" because "death" would detrimentally end some functionality taken from _autosentry.gsc.
	}
}


/*
=============
///ScriptDocBegin
"Name: monitorRefractionKillstreakOwnership()"
"Summary: frees up the refraction killstreak when the killstreak time is up or all turrets are disabled."
"Module: Entity"
"CallOn: the level"
"Example: level thread monitorRefractionKillstreakOwnership()"
"SPMP: MP"
///ScriptDocEnd
=============
*/
monitorRefractionKillstreakOwnership()
{
	level endon( "game_ended" );
	
	//If any turrets are alive or any turrets are up... wait!
	while ( level.refraction_turrets_alive > 0 || level.refraction_turrets_moved_down < level.refraction_turrets.size )
	{
		wait( 0.05 );
	}
	
	unsetRefractionTurretPlayer();
}

setRefractionTurretPlayer( player )
{
	if( IsDefined( level.mp_refraction_owner ) )
		return false;
	
	level.mp_refraction_InUse = true;
	level.mp_refraction_owner = player;
	
	thread teamPlayerCardSplash( "used_mp_refraction", player );
	
	sentryType = "refraction_turret";
	
	//IPrintLnBold("Bleed Time");
	
	for ( i = 0; i < level.refraction_turrets.size; i++ )
	{
		level.refraction_turrets_alive++;
		level.refraction_turrets_moved_down = 0;		//All the turrets will move up, so we're setting this value to zero. It will be incremented back up to 4 when all the turrets move back down, either via time or death.
		Assert( IsDefined( level.refraction_turrets[i] ) );
		level.refraction_turrets[i] sentry_setOwner( player );
		level.refraction_turrets[i] SetLeftArc( 45 );
		level.refraction_turrets[i] SetRightArc( 45 );
		level.refraction_turrets[i] SetTopArc( 10 );
		level.refraction_turrets[i].shouldSplash = false;
		level.refraction_turrets[i].carriedBy = player;
		level.refraction_turrets[i] sentry_setPlaced();
		level.refraction_turrets[i] thread sentry_handleDamage();
		level.refraction_turrets[i] thread sentry_handleDeath();
		level.refraction_turrets[i] thread sentry_laserMark();
		level.refraction_turrets[i] thread aud_turrets_activate();
	}
	
	level thread refractionTurretTimer();
	level thread monitorRefractionKillstreakOwnership();
	

	return true;
}

aud_turrets_activate()
{
	thread snd_play_in_space( "turret_cover_explode", self.origin );
	thread snd_play_in_space( "turret_rise_start", self.origin );
}

/*
=============
///ScriptDocBegin
"Name: unsetRefractionTurretPlayer()"
"Summary: unsets the Refraction Turrets' owner - frees them up for someone else."
"Module: Entity"
"CallOn: N/A"
"Example: unsetRefractionTurretPlayer();"
"SPMP: MP"
///ScriptDocEnd
=============
*/
unsetRefractionTurretPlayer()
{
	level.mp_refraction_owner = undefined;
	level.mp_refraction_InUse = false;
}


turret_setup()  //GET ALL FOUR TURRETS
{
	turrets = getentarray( "turret_killer", "targetname" );
	
	assertEx( isDefined( turrets), "no entities found with targetname of turret killer" );
	
	foreach( turret in turrets )
	{
		parts = undefined;
		if( isDefined( turret.target ) )
			parts = getentarray( turret.target, "targetname" );
		
		assertEx( isDefined( parts), "no entities found with targetname of " + turret.target );
		
		foreach( part in parts )
		{
			if( isDefined( part.script_noteworthy ) && part.script_noteworthy == "turret_lifter" )
			{
				turret.lifter = part;
				continue;
			}
			else if( isDefined( part.script_noteworthy ) && part.script_noteworthy == "hatch" )
			{
				turret.hatch = part;
				continue;
			}
			else
				assertMsg( "no parts with targetname turret_lifter or hatch were found" );
		}
		
		assertEx( isDefined( turret.lifter), "no lifter entity found for turret" );
		assertEx( isDefined( turret.hatch), "no hatch entity found for turret" );
		
		turret.lifter.animUp = "ref_turret_gun_raise";
		turret.lifter.animDown = "ref_turret_gun_lower";
		turret.lifter.IdleUp = "ref_turret_gun_idle_up";
		turret.lifter.IdleDown = "ref_turret_gun_idle_down";
		
		turret.hatch.animUp = "ref_turret_hatch_raise";
		turret.hatch.animDown = "ref_turret_hatch_lower";
		turret.hatch.IdleUp = "ref_turret_hatch_idle_up";
		turret.hatch.IdleDown = "ref_turret_hatch_idle_down";
		
		turret.collision = SpawnStruct();
		collision = undefined;
		if( isDefined( turret.lifter.target ) )
			collision = getentarray( turret.lifter.target, "targetname" );
		
		assertEx( isDefined( collision), "no collision entities found with targetname of " + turret.target );
		
		foreach( collision_part in collision )
		{
			if( isDefined( collision_part.script_noteworthy ) )
			{
				switch( collision_part.script_noteworthy )
				{
					case "ref_turret_body_col":
						turret.collision.col_body = collision_part;
						break;
					case "ref_turret_head_col":
						turret.collision.col_head = collision_part;
						break;
					case "ref_turret_leg_r_col":
						turret.collision.col_leg_r = collision_part;
						break;
					case "ref_turret_leg_l_col":
						turret.collision.col_leg_l = collision_part;
						break;
					case "ref_turret_gun_col":
						turret.collision.col_gun = collision_part;
						break;
				}		
			}
		}
		
		turret.sound_tag =						spawn_tag_origin();
		turret.sound_tag.origin =				turret.origin + (0,0,24);
		turret SetDefaultDropPitch( 0 );
		sentryType = level.sentrySettings[ "refraction_turret" ].sentryType;
		turret sentry_initSentry( sentryType );		//HACK: I'm calling sentry_initSentry() to do initial setup for the turrets. The turrets don't have an owner yet.
		turret makeTurretSolid();			//We need to make turrets solid for them to be damageable...
		turret hide();
		
		turret.laser_tag =  Spawn( "script_model", turret.origin );
		turret.laser_tag SetModel( "tag_laser" );
	}
	
	return turrets;
}

LinkCollisionToTurret(turret, ShouldLink)
{
	if(ShouldLink == false)
	{
		if( isDefined( turret.collision.col_body ) )
		turret.collision.col_body unlink();
		if( isDefined( turret.collision.col_head ) )
		turret.collision.col_head unlink();
		if( isDefined( turret.collision.col_leg_r ) )
		turret.collision.col_leg_r unlink();
		if( isDefined( turret.collision.col_leg_l ) )
		turret.collision.col_leg_l unlink();
		if( isDefined( turret.collision.col_gun ) )
		turret.collision.col_gun unlink();
	}
	else if(ShouldLink == true)
	{
		if( isDefined( turret.collision.col_body ) )
		turret.collision.col_body linkto( self, "tag_origin" );
		if( isDefined( turret.collision.col_head ) )
		turret.collision.col_head linkto( self, "tag_aim_animated" );
		if( isDefined( turret.collision.col_leg_r ) )
		turret.collision.col_leg_r linkto( self, "arm_r" );
		if( isDefined( turret.collision.col_leg_l ) )
		turret.collision.col_leg_l linkto( self, "arm_l" );
		if( isDefined( turret.collision.col_gun ) )
		turret.collision.col_gun linkto( self, "tag_barrel" );
	}
}

sentry_laserMark() //Monitor laser marking for each individual turret
{
	level endon ( "game_ended" );	
	
	self waittill( "refraction_turret_moved_up" );
	
	self.laser_tag LaserOn();
	self.laser_tag.origin = self GetTagOrigin( "tag_flash" );
	self.laser_tag.angles = self GetTagAngles( "tag_flash" );
	self.laser_tag LinkTo( self, "tag_flash" );
	
	self waittill( "fake_refraction_death" );
	
	self.laser_tag LaserOff( );
}

turret_moveUP()  //TURRETS MOVE UP FROM UNDERGROUND
{
	wait( RandomFloatRange( 1, 1.5 ) ); //make them not look too in sync
	
	self.killCamEnt = Spawn( "script_model", self GetTagOrigin( "tag_player" ) );
	self.killCamEnt SetScriptMoverKillCam( "explosive" );
	
	self.lifter LinkCollisionToTurret(self, true);
	
	alias_array = [];
	
	alias_array[ "ref_turret_raise_doors_start" ] 	= "ref_turret_raise_doors_start";
	alias_array[ "ref_turret_raise_doors_end" ] 	= "ref_turret_raise_doors_end";
	alias_array[ "ref_turret_down_start" ] 			= "ref_turret_down_start";
	alias_array[ "ref_turret_down_end" ] 			= "ref_turret_down_end";
	alias_array[ "ref_turret_doors_close_start" ] 	= "ref_turret_doors_close_start";
	alias_array[ "ref_turret_doors_close_end" ] 	= "ref_turret_doors_close_end";
	alias_array[ "ref_turret_barrell_ext_start" ] 	= "ref_turret_barrell_ext_start";	
	alias_array[ "ref_turret_barrell_ext_end" ] 	= "ref_turret_barrell_ext_end";	
	
	self.hatch ScriptModelPlayAnimDeltaMotion( self.hatch.animUp );
	self.lifter ScriptModelPlayAnimDeltaMotion( self.lifter.animUp, "ref_turret_raise_doors_start" );
	self.lifter thread snd_play_on_notetrack( alias_array, "ref_turret_raise_doors_start");
	// AUDIO
	
	self thread PlayFxTurretMoveUp();//TODO: These are temp
	self thread playAudioTurretMoveUp();//TODO: These are temp
	
	wait( 4.17 ); //HACK FOR ANIM LENGTH
	
	self.lifter LinkCollisionToTurret(self, false);
	self show();
	//self LinkCollisionToTurret(self, true);	//taking this out so collision doesn't kill dudes who stand against the turret while it's on
	self.lifter hide();
	
	self notify( "refraction_turret_moved_up" );
}

playFxTurretMoveUp()
{
	level thread common_scripts\_exploder::activate_clientside_exploder(1); //smoke fx
	level thread common_scripts\_exploder::activate_clientside_exploder(2);
	level thread common_scripts\_exploder::activate_clientside_exploder(3);
	level thread common_scripts\_exploder::activate_clientside_exploder(4);
	level thread common_scripts\_exploder::activate_clientside_exploder(5);
	level thread common_scripts\_exploder::activate_clientside_exploder(6);
	level thread common_scripts\_exploder::activate_clientside_exploder(7);
	level thread common_scripts\_exploder::activate_clientside_exploder(8);
}

playAudioTurretMoveUp()
{
	self.sound_tag thread Play_Sound_on_Tag( level.turret_movement_sound, "tag_origin" );
	
	wait(1);
	
	self.sound_tag thread Play_Sound_on_Tag(level.turret_movement2_sound,"tag_origin");
	
	wait(1);
	
	self.sound_tag thread Play_Sound_on_Tag(level.turret_movement3_sound,"tag_origin");
}


turret_moveDOWN(turret)
{
	wait( RandomFloatRange( 1, 1.5 ) ); //make them not look too in sync
	
	//self LinkCollisionToTurret(self, false); //taking this out so collision doesn't kill dudes who stand against the turret while it's on
	self.lifter show();
	self.lifter LinkCollisionToTurret(self, true);
	self hide();
	
	alias_array = [];
	
	alias_array[ "ref_turret_raise_doors_start" ] 	= "ref_turret_raise_doors_start";
	alias_array[ "ref_turret_raise_doors_end" ] 	= "ref_turret_raise_doors_end";
	alias_array[ "ref_turret_down_start" ] 			= "ref_turret_down_start";
	alias_array[ "ref_turret_down_end" ] 			= "ref_turret_down_end";
	alias_array[ "ref_turret_barrell_close_start" ] = "ref_turret_barrell_close_start";	
	alias_array[ "ref_turret_barrell_close_end" ] 	= "ref_turret_barrell_close_end";	
	alias_array[ "ref_turret_doors_close_start" ] 	= "ref_turret_doors_close_start";
	alias_array[ "ref_turret_doors_close_end" ] 	= "ref_turret_doors_close_end";
	alias_array[ "ref_turret_doors_lock_start" ] 	= "ref_turret_doors_lock_start";
	alias_array[ "ref_turret_doors_lock_end" ] 		= "ref_turret_doors_lock_end";	
	
	//steam vfx when turret moves down
	fx_angles = self.hatch.angles + ( -90, 0, 0 );
	noself_delayCall ( 4.1, ::PlayFx, getfx( "mp_ref_turret_steam_off" ), self.hatch.origin, AnglesToForward (fx_angles), AnglesToUp (fx_angles) ); //steam burst vfx on shut off
	self.hatch ScriptModelPlayAnimDeltaMotion( self.hatch.animDown );
	self.lifter ScriptModelPlayAnimDeltaMotion( self.lifter.animDown, "ref_turret_down_end" );
	
	self.lifter thread snd_play_on_notetrack( alias_array, "ref_turret_down_end");
	
	wait( 4.64 ); //HACK FOR ANIM LENGTH
	waittillframeend; //just to make sure the anim is done
	self.lifter LinkCollisionToTurret(self, false);
	level.refraction_turrets_moved_down++;
}


////////////////////////////////////
//STUFF TAKEN FROM _autosentry.gsc
////////////////////////////////////

sentry_setPlaced()
{
	self setSentryCarrier( undefined );
	
	self.carriedBy forceUseHintOff();
	self.carriedBy = undefined;

	if( IsDefined( self.owner ) )
		self.owner.isCarrying = false;
	
	self thread sentry_setActive();

	self playSound( "sentry_gun_plant" );

	self notify ( "placed" );
}

sentry_setActive()
{
	self turret_moveUP();
	
	self setCanDamage( true );		//Make the turrets damageable AFTER they have finished moving up.
	self setCanRadiusDamage( true );
	
	self SetMode( level.sentrySettings[ self.sentryType ].sentryModeOn );
	
	if( level.sentrySettings[ self.sentryType ].headIcon )
	{
		if ( level.teamBased )
			self maps\mp\_entityheadicons::setTeamHeadIcon( self.team, (0,0,95) );
		else
			self maps\mp\_entityheadicons::setPlayerHeadIcon( self.owner, (0,0,95) );
	}
}


//HACK: I removed all references to the owner argument. This is because the sentry doesn't have an owner when it is first created.
sentry_initSentry( sentryType ) // self == sentry, turret, sam
{
	self.sentryType = sentryType;
	self.canBePlaced = true;

	self setModel( level.sentrySettings[ self.sentryType ].modelBase );
	self makeTurretInoperable();
	self SetDefaultDropPitch( 0.0 );	// setting this mainly prevents Turret_RestoreDefaultDropPitch() from running

	self setTurretModeChangeWait( true );

	self maps\mp\killstreaks\_autosentry::sentry_setInactive();
	
	self thread maps\mp\killstreaks\_autosentry::sentry_handleUse();
	self thread maps\mp\killstreaks\_autosentry::sentry_attackTargets();
}


sentry_handleDeath()
{
	self waittill ( "fake_refraction_death" );

	// this handles cases of deletion
	if ( !IsDefined( self ) )
		return;

	self maps\mp\killstreaks\_autosentry::sentry_setInactive();
	self SetSentryOwner( undefined );
	self SetTurretMinimapVisible( false );
	
//	//Turning off the turrets' head icons. This is added functionality for the mp_refraction turrets.
//	if( level.sentrySettings[ self.sentryType ].headIcon )
//	{
//		if ( level.teamBased )
//			self maps\mp\_entityheadicons::setTeamHeadIcon( "none", (0,0,0) );
//		else
//			self maps\mp\_entityheadicons::setPlayerHeadIcon( "none", (0,0,0) );
//	}
	
	self setCanDamage( false );		//Make the turrets non-damageable when they fake die.
	self setCanRadiusDamage( false );
	
	self.laser_tag LaserOff( );
	
	self turret_moveDOWN();
	
	level.refraction_turrets_alive--;
	
	if ( IsDefined( self.killCamEnt ) )
		self.killCamEnt Delete();
}


/*
=============
///ScriptDocBegin
"Name: sentry_setOwner( <owner> )"
"Summary: sets the owner of the spawned turret."
"Module: Entity"
"CallOn: a turret spawned by SpawnTurret()."
"MandatoryArg: <owner>: the player that used the refraction killstreak"
"Example: level.refraction_turrets[i]["spawned_turret"] sentry_setOwner( player );"
"SPMP: MP"
///ScriptDocEnd
=============
*/
sentry_setOwner( owner )
{
	self.owner = owner;
	
	self SetSentryOwner( self.owner );
	self SetTurretMinimapVisible( true, self.sentryType );
	
	if ( level.teamBased && IsDefined( owner ) )
	{
		self.team = self.owner.team;
		self setTurretTeam( self.team );
	}
	
	self thread sentry_handleOwnerDisconnect();
}


/*
=============
///ScriptDocBegin
"Name: sentry_handleOwnerDisconnect()"
"Summary: notifies death for this turret (self) if its owner disconnects."
"Module: Entity"
"CallOn: a turret spawned by SpawnTurret()."
"Example: self thread sentry_handleOwnerDisconnect();"
"SPMP: MP"
///ScriptDocEnd
=============
*/
sentry_handleOwnerDisconnect()
{
	level endon ( "game_ended" );
	self endon( "fake_refraction_death" );			//Ending this thread if the turret (self) dies by other means (damage, time).
	
	self.owner waittill_any( "disconnect", "joined_team", "joined_spectators" );
	
	self notify( "fake_refraction_death" );
}


/*
=============
///ScriptDocBegin
"Name: sentry_handleDamage()"
"Summary: handles the death of a turret spawned by SpawnTurret()"
"Module: Entity"
"CallOn: a turret spawned by SpawnTurret()."
"Example: self thread sentry_handleDamage();"
"SPMP: MP"
///ScriptDocEnd
=============
*/
sentry_handleDamage()
{
	self endon( "fake_refraction_death" );
	level endon( "game_ended" );
	
	self.health = level.sentrySettings[ self.sentryType ].health;
	self.maxHealth = level.sentrySettings[ self.sentryType ].maxHealth;
	self.damageTaken = 0; // how much damage has it taken
	
	while ( true )
	{
		self waittill( "damage", damage, attacker, direction_vec, point, meansOfDeath, modelName, tagName, partName, iDFlags, weapon );
		
		// don't allow people to destroy equipment on their team if FF is off
		if ( !maps\mp\gametypes\_weapons::friendlyFireCheck( self.owner, attacker ) )
			continue;
		
		if ( IsDefined( iDFlags ) && ( iDFlags & level.iDFLAGS_PENETRATION ) )
			self.wasDamagedFromBulletPenetration = true;
		
		// up the damage for airstrikes, stealth bombs, and bomb sites			//Don't need this from original in _autosentry.gsc.
//		switch( weapon )
//		{
//		case "artillery_mp":
//		case "stealth_bomb_mp":
//			damage *= 4;
//			break;
//		case "bomb_site_mp":
//			damage = self.maxHealth;
//			break;
//		}
//		
//		if ( meansOfDeath == "MOD_MELEE" )
//			self.damageTaken += self.maxHealth;
//		
//		modifiedDamage = damage;
//		if ( isPlayer( attacker ) )
//		{
//			attacker maps\mp\gametypes\_damagefeedback::updateDamageFeedback( "sentry" );
//			
//			if ( attacker _hasPerk( "specialty_armorpiercing" ) )
//			{
//				modifiedDamage = damage * level.armorPiercingMod;
//			}
//		}
		
//		// in case we are shooting from a remote position, like being in the osprey gunner shooting this
//		if( IsDefined( attacker.owner ) && IsPlayer( attacker.owner ) )
//		{
//			attacker.owner maps\mp\gametypes\_damagefeedback::updateDamageFeedback( "sentry" );
//		}
		
		modifiedDamage = 0;
		
		if( IsDefined( weapon ) )
		{
			shortWeapon = maps\mp\_utility::strip_suffix( weapon, "_lefthand" );

			switch( shortWeapon )
			{
//				case "ac130_105mm_mp":
//				case "ac130_40mm_mp":
//				case "stinger_mp":
//				case "remotemissile_projectile_mp":
//					self.largeProjectileDamage = true;
//					modifiedDamage = self.maxHealth + 1;
//					break;
//					
//				case "artillery_mp":
//				case "stealth_bomb_mp":
//					self.largeProjectileDamage = false;
//					modifiedDamage += ( damage * 4 );
//					break;
//				
//				case "bomb_site_mp":
				case "emp_grenade_mp":
				case "emp_grenade_var_mp":
					self.largeProjectileDamage = false;
					modifiedDamage = self.maxHealth + 1;
					if ( isPlayer( attacker ) )
					{
						attacker maps\mp\gametypes\_damagefeedback::updateDamageFeedback( "sentry" );
					}
					break;
				default:
					modifiedDamage = 0;
					break;
			}
			
			maps\mp\killstreaks\_killstreaks::killstreakHit( attacker, weapon, self );
		}

		self.damageTaken += modifiedDamage;

		if ( self.damageTaken >= self.maxHealth )
		{
			thread maps\mp\gametypes\_missions::vehicleKilled( self.owner, self, undefined, attacker, damage, meansOfDeath, weapon );
			
			if ( isPlayer( attacker ) && (!IsDefined(self.owner) || attacker != self.owner) )
			{
				level thread maps\mp\gametypes\_rank::awardGameEvent( "kill", attacker, weapon, undefined, meansOfDeath );	
			}
			
			if ( IsDefined( self.owner ) )
				self.owner thread leaderDialogOnPlayer( level.sentrySettings[ self.sentryType ].voDestroyed, undefined, undefined, self.origin );
			
			self notify( "fake_refraction_death" );
			return;
		}
	}
}
