//=============================================================================
// NukeSiren
// by SK
//=============================================================================
class NukeSiren expands sgBuilding;

var float SirenRange;
var float TurnOffRange;
var bool bAlreadySounding;

simulated event Timer()
{
	CheckForNukers();
	Super.Timer();	
}

simulated function FinishBuilding()
{
Super.FinishBuilding();
SetTimer(0.5, True);
}

function CheckForNukers()
{
	local PlayerPawn p;
	
	SirenRange = 2048*(1+Grade);
	TurnOffRange = SirenRange + 1024;
	
	if (!bAlreadySounding)
		{
			foreach RadiusActors(Class'PlayerPawn', p, SirenRange)
			{
				if( p.PlayerReplicationInfo == None ){ continue;}
				if( sgNukeLauncher(p.FindInventoryType(class'sgNukeLauncher')) == None ){ continue;}
				if (p.PlayerReplicationInfo.Team != Team && sgNukeLauncher(p.FindInventoryType(class'sgNukeLauncher')).AmmoType.AmmoAmount > 0)
					{
						SoundTheAlarm();
					}
			}
		}
	else
		{
			foreach RadiusActors(Class'PlayerPawn', p, TurnOffRange)
			{
				if( p.PlayerReplicationInfo == None ){ continue;}
				if( sgNukeLauncher(p.FindInventoryType(class'sgNukeLauncher')) == None ){ continue;}
				if (p.PlayerReplicationInfo.Team != Team && sgNukeLauncher(p.FindInventoryType(class'sgNukeLauncher')).AmmoType.AmmoAmount > 0)
					{
						return;
					}
				else
					{
						TurnOffAlarm();
					}
			}
		}
}

function SoundTheAlarm()
{
	local Pawn p;

	if (bDisabledByEMP){return;}
	
	
	AlertLight(true);
	bAlreadySounding=True;
	for ( p = Level.PawnList; p != None; p = p.nextPawn )
	{
	 if ( p.IsA('TournamentPlayer' ) && p.PlayerReplicationInfo.Team == Team && !p.PlayerReplicationInfo.bIsSpectator )
	 {
	  TournamentPlayer(P).ReceiveLocalizedMessage(Class'NukeAlert');
	 }
	}
}

function TurnOffAlarm()
{

	AlertLight(false);
	bAlreadySounding=False;

}

function AlertLight(bool on)
{
	if ( on == true && !bDisabledByEMP)
		{
			LightEffect=LE_Cylinder;
			LightBrightness=255;
			LightSaturation=1;
			LightPeriod=8;

			if ( Team == 0 )
				LightHue=2;
			else
				LightHue=150;

			LightRadius=32;
			LightSaturation=0;
			LightType=LT_Pulse;
		}
    else
		LightType=LT_None;
}

defaultproperties
{
    BuildingName="Nuke Siren"
    BuildCost=1200
    BuildTime=20.00
    MaxEnergy=12000.00
    Energy=12000.00
    SpriteScale=0.75
    Model=LodMesh'UnrealShare.UrnM'
    SpriteRedTeam=Texture'SiegeUltimateRC7UB01Media.U.BuildingMaps.MotionAlarmSpriteT0'
    SpriteBlueTeam=Texture'SiegeUltimateRC7UB01Media.U.BuildingMaps.MotionAlarmSpriteT1'
    SpriteGreenTeam=Texture'SiegeUltimateRC7UB01Media.U.BuildingMaps.MotionAlarmSpriteT2'
    SpriteYellowTeam=Texture'SiegeUltimateRC7UB01Media.U.BuildingMaps.MotionAlarmSpriteT3'
    DSofMFX=3.20
    NumOfMFX=3
    MFXrotX=(Pitch=4096,Yaw=0,Roll=4096),
    Fatness=183
    MultiSkins(0)=Texture'SiegeUltimateRC7UB01Media.U.BuildingMaps.MotionAlarmSpriteT0'
    MultiSkins(1)=Texture'SiegeUltimateRC7UB01Media.U.BuildingMaps.MotionAlarmSpriteT1'
    MultiSkins(2)=Texture'SiegeUltimateRC7UB01Media.GFX.sgContSpriteT2'
    MultiSkins(3)=Texture'SiegeUltimateRC7UB01Media.GFX.sgContSpriteT3'
    CollisionRadius=48.00
    CollisionHeight=48.00
}
