//=============================================================================
// ControlPoint.
//=============================================================================
class ControlPoint expands NavigationPoint;

// Red Team
#exec MESH IMPORT MESH=DomR ANIVFILE=MODELS\DomR_a.3d DATAFILE=MODELS\DomR_d.3d X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=DomR X=0 Y=0 Z=0
#exec MESH SEQUENCE MESH=DomR SEQ=All  STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=DomR SEQ=DomR STARTFRAME=0 NUMFRAMES=1
#exec MESHMAP NEW   MESHMAP=DomR MESH=DomR
#exec MESHMAP SCALE MESHMAP=DomR X=0.1 Y=0.1 Z=0.2
#exec MESHMAP SETTEXTURE MESHMAP=DomR NUM=0 TEXTURE=RedSkin

// Blue Team
#exec MESH IMPORT MESH=DomB ANIVFILE=MODELS\DomB_a.3d DATAFILE=MODELS\DomB_d.3d X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=DomB X=0 Y=0 Z=0
#exec MESH SEQUENCE MESH=DomB SEQ=All  STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=DomB SEQ=DomB STARTFRAME=0 NUMFRAMES=1
#exec MESHMAP NEW   MESHMAP=DomB MESH=DomB
#exec MESHMAP SCALE MESHMAP=DomB X=0.1 Y=0.1 Z=0.2
#exec MESHMAP SETTEXTURE MESHMAP=DomB NUM=0 TEXTURE=BlueSkin

// Neutral
#exec MESH IMPORT MESH=DomN ANIVFILE=MODELS\DomN_a.3d DATAFILE=MODELS\DomN_d.3d X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=DomN X=0 Y=0 Z=0
#exec MESH SEQUENCE MESH=DomN SEQ=All  STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=DomN SEQ=DomN STARTFRAME=0 NUMFRAMES=1
#exec TEXTURE IMPORT NAME=JDomN0 FILE=MODELS\ChromX.PCX GROUP=Skins FLAGS=2 // Skin
#exec MESHMAP NEW   MESHMAP=DomN MESH=DomN
#exec MESHMAP SCALE MESHMAP=DomN X=0.1 Y=0.1 Z=0.2
#exec MESHMAP SETTEXTURE MESHMAP=DomN NUM=0 TEXTURE=JDomN0

#exec AUDIO IMPORT FILE="Sounds\Domination\teleprt28.WAV" NAME="ControlSound" GROUP="Domination"
#exec AUDIO IMPORT FILE="Sounds\Domination\uLNitro1.WAV" NAME="WarningSound" GROUP="Domination"

var TeamInfo ControllingTeam;
var Pawn Controller;
var() Name RedEvent;
var() Name BlueEvent;
var() Name GreenEvent;
var() Name GoldEvent;
var() Name NeutralEvent;
var() bool bSelfDisplayed;
var() localized String[32] PointName;
var() Sound ControlSound;	//FIXME NEED A SOUND
var   int ScoreTime;
var   bool bScoreReady;

replication
{
	// Variables the server should send to the client.
	reliable if( Role==ROLE_Authority )
		ControllingTeam, bScoreReady, ScoreTime;
}

function PostBeginPlay()
{
	if ( !Level.Game.IsA('Domination') )
		return;
	else
	{
		Super.PostBeginPlay();
		bHidden = !bSelfDisplayed;
	}
}

function Touch(Actor Other)
{
	if ( !Other.IsA('Pawn') || !Pawn(Other).bIsPlayer || !Level.Game.IsA('Domination') )
		return;

	Controller = Pawn(Other);
	UpdateStatus();
}

function UpdateStatus()
{
	local Actor A;
	local Name E;
	local TeamInfo NewTeam;
	local TeamGamePlus T;

	T = TeamGamePlus(Level.Game);
	if ( Controller == None )
		NewTeam = None;
	else
        NewTeam = T.GetTeam(Controller.PlayerReplicationInfo.Team);

	if ( NewTeam == ControllingTeam )
		return;

	ControllingTeam = NewTeam;
	if ( ControllingTeam != None )
	{
		PlaySound(ControlSound, SLOT_None, 6.0);
		BroadcastMessage(PointName$" now controlled by "$ControllingTeam.TeamName, true, 'CriticalEvent');
		if ( Controller.IsA('Bot') )
			Bot(Controller).SendTeamMessage(None, 'OTHER', 11, 15);
		else if ( DeathMatchPlus(Level.Game).bRatedGame
					&& (Controller == DeathMatchPlus(Level.Game).RatedPlayer) )
				DeathMatchPlus(Level.Game).bFulfilledSpecial = true;
	}
	if ( bSelfDisplayed )
	{
		bHidden = false;
		PlaySound(sound'ControlSound',,12.0);
	}
	if ( ControllingTeam == None )
	{
		bScoreReady = false;
		E = NeutralEvent;
		if ( bSelfDisplayed ) 
		{
			Mesh = mesh'DomN';
			Texture=texture'JDomN0';
			LightHue=0;
		    LightSaturation=69;
		}
	}	
	else if ( Controller.PlayerReplicationInfo.Team == T.TEAM_Red )
	{
		E = RedEvent;
		ScoreTime = 1;
		SetTimer(1.0, true);
		if ( bSelfDisplayed )
		{
			Mesh = mesh'DomR';
			Texture = texture'RedSkin';
			LightBrightness=255;
			LightHue=0;
		    LightSaturation=0;
		}
	}
	else if ( Controller.PlayerReplicationInfo.Team == T.TEAM_Blue )
	{
		E = BlueEvent;
		ScoreTime = 1;
		SetTimer(1.0, true);
		if ( bSelfDisplayed )
		{
			Mesh = mesh'DomB';
			Texture = texture'BlueSkin'; 
			LightHue=170;
		    LightSaturation=0;
		}
	}
	else if ( Controller.PlayerReplicationInfo.Team == T.TEAM_Green )
	{
		E = GreenEvent;
		ScoreTime = 1;
		SetTimer(1.0, true);
		if ( bSelfDisplayed )
		{
			Mesh=mesh'DomN';
			Texture=texture'JDomN0';
			LightHue=170;
		    LightSaturation=69;
		}
	}
	else if ( Controller.PlayerReplicationInfo.Team == T.TEAM_Gold )
	{
		E = GoldEvent;
		ScoreTime = 1;
		SetTimer(1.0, true);
		if ( bSelfDisplayed )
		{
			Mesh=mesh'DomN';
			Texture=texture'JDomN0';
			LightHue=170;
		    LightSaturation=69;
		}
	}
	if ( E != '' )
		foreach AllActors(class'Actor', A, E )
		 Trigger(self, Controller);
}

function Timer()
{
	ScoreTime++;
	if (ScoreTime <= 10)
		bScoreReady = false;
	else {
		ScoreTime = 0;
		bScoreReady = true;
		SetTimer(0.0, false);
	}
}

defaultproperties
{
	PointName="Position"
	bStatic=false
	bCollideActors=true
	bSelfDisplayed=true
	Mesh=mesh'DomN'
    Texture=texture'JDomN0'
    DrawScale=0.4
	bUnlit=true
    SoundRadius=64
    SoundVolume=255
    bFixedRotationDir=True
    RotationRate=(Yaw=5000)
    DesiredRotation=(Yaw=30000)
	bAlwaysRelevant=true
	LightType=LT_SubtlePulse
	LightEffect=LE_NonIncidence
	Physics=PHYS_Rotating
	DrawType=DT_Mesh
	Style=STY_Normal
	bMeshEnviroMap=true
	LightBrightness=255;
	LightRadius=8;
    LightHue=170
    LightSaturation=69
}
