//=============================================================================
// TrainingCTF.
//=============================================================================
class TrainingCTF expands CTFGame;

var PlayerPawn Trainee;
var VocalTranslator newTranslator;

function PreBeginPlay()
{
	Super.PreBeginPlay();
	InitialBots = 0;
}

event playerpawn Login
(
	string[32] Portal,
	string[120] Options,
	out string[80] Error,
	class<playerpawn> SpawnClass
)
{
	if ( SpawnClass == class'UnrealSpectator' )
		SpawnClass = class'CHSpectator';

	Trainee = Super.Login(Portal, Options, Error, SpawnClass);
	Trainee.PlayerReplicationInfo.TeamName = "Red";
	Trainee.PlayerReplicationInfo.Team = 0;

	GotoState('Welcome');

	return Trainee;
}

function AddDefaultInventory( pawn PlayerPawn )
{
	Super.AddDefaultInventory( PlayerPawn );
	newTranslator = Spawn(class'VocalTranslator');
	if( newTranslator != None )
	{
		newTranslator.bHeldItem = true;
		newTranslator.GiveTo( PlayerPawn );
		PlayerPawn.SelectedItem = newTranslator;
		newTranslator.PickupFunction(PlayerPawn);
	}
}

function ShowTranslator()
{
	newTranslator.bShowHint = True;
	newTranslator.Activate();
}

function HideTranslator()
{
	newTranslator.bShowHint = False;
	newTranslator.Activate();
}

function TranslatorMessage( string[255] Message )
{
	if (Message=="") 
		Return;
	newTranslator.bNewMessage = true;
	newTranslator.NewMessage = Message;
	//newTranslator.VocalMessageSound = VocalMessageSound;
	//PlaySound(NewMessageSound, SLOT_Misc);
}

function DrawTutIcon( texture Icon, int X, int Y )
{
	ChallengeHUD(Trainee.myHUD).DrawTutIcon(Icon, X, Y);
}

function StopTutIcon()
{
	ChallengeHUD(Trainee.myHUD).StopTutIcon();
}

state Welcome
{
	function Timer()
	{
		ShowTranslator();
		TranslatorMessage("Welcome to Capture the Flag combat training.  This tutorial will instruct you on the basic rules of CTF.  Tutorials on Deathmatch, Domination, and Assault are also available.");
		GoToState('HUDTraining');
	}

	function BeginState()
	{
		SetTimer(1.0, true);
	}
}

state HUDTraining
{
	function Timer()
	{
		TranslatorMessage("Let's start by learning about the Heads Up Display (HUD).  CTF adds a few new elements to the HUD you should be aware of.");
		GoToState('FragMeterTraining');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state FragMeterTraining
{
	function Timer()
	{
		local int X, Y;
		X = -74;
		Y = -64;

		DrawTutIcon(texture'MArrowR', X, Y);
		TranslatorMessage("Notice that your Frag count indicator is now represented by a red skull, instead of a white one.  This means that you are on the red team.  A blue skull would indicate that you were on the blue team.");
		GoToState('FlagStatusIcons');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state FlagStatusIcons
{
	function Timer()
	{
		local int X, Y;
		X = -90;
		Y = -128;

		StopTutIcon();
		DrawTutIcon(texture'MArrowR', X, Y);
		TranslatorMessage("The two flag icons indicate the status of the red and blue flags.  This allows you to obtain a quick overview of battlefield conditions.  We'll discuss the meaining of each flag status icon in a bit.");
		GoToState('TeamScores');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state TeamScores
{
	function Timer()
	{
		TranslatorMessage("Just to the left of each flag status icon, is that team's score.");
		GoToState('ScoreboardTransition');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state ScoreboardTransition
{
	function Timer()
	{
		StopTutIcon();
		ChallengeHUD(Trainee.myHUD).bForceScores = true;
		TranslatorMessage("Now lets look at the elements CTF adds to the scoreboard...");
		GoToState('ScoreboardTraining');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state ScoreboardTraining
{
	function Timer()
	{
		TranslatorMessage("Capture the Flag uses the standard Unreal teamplay scoreboard configuration.  The left column lists the red team players and scores and the right column lists the blue team players and scores.");
		GoToState('TeamScoreboard');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state TeamScoreboard
{
	function Timer()
	{
		TranslatorMessage("Notice your name and current score of 0 listed to the left.  Above your name is the name of your team.  Your team's current score is listed to the right of the team's name.");
		GoToState('FlagCarrier');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state FlagCarrier
{
	function Timer()
	{
		Trainee.PlayerReplicationInfo.HasFlag = CTFReplicationInfo(GameReplicationInfo).FlagList[0];
		TranslatorMessage("When a player in a CTF game is carrying the flag, a small dot will appear next to their name in the scoreboard.  This can be used to quickly determine which teammate to protect or which enemy to hunt down.");
		GoToState('GameRulesBegin');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state GameRulesBegin
{
	function Timer()
	{
		ChallengeHUD(Trainee.myHUD).bForceScores = false;		
		Trainee.PlayerReplicationInfo.HasFlag = None;
		TranslatorMessage("Now its time to learn the rules of Capture the Flag.");
		GoToState('RedBase');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state RedBase
{
	function Timer()
	{
		Trainee.SetLocation(vect(138, 1327, -84));
		Trainee.SetRotation(rot(62611, 42295, 0));
		Trainee.ViewRotation = rot(62611, 42295, 0);
		PlayTeleportEffect(Trainee, true, true);
		TranslatorMessage("Each CTF map has a red and a blue base.  This is red base.  Blue base is just down the hallway.  Each base contains a flag.");
		GoToState('FlagStandard');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state FlagStandard
{
	function Timer()
	{
		TranslatorMessage("In front of you is the red flag.  The object of CTF is to capture the enemy team's flag while defending your own.");
		GoToState('FirstTry');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state FirstTry
{
	function Timer()
	{
		TranslatorMessage("Let's give it a try.  Run to the blue base and touch their flag to pick it up.  Grab any equipment you find along the way.");
		GoToState('FreeRunning1');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state FreeRunning1
{
	function Tick(float DeltaTime)
	{
		Super.Tick(DeltaTime);

		if (Trainee.PlayerReplicationInfo.HasFlag != None)
		{
			GoToState('GotFlag');
		}
	}

	function Timer()
	{
		HideTranslator();
		SetTimer(0.0, false);
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state GotFlag
{
	function Timer()
	{
		ShowTranslator();
		TranslatorMessage("Great!  Now you have the enemy flag.  The flashing yellow message is to remind you that once you have the flag, you need to return it to your base to score.");
		GoToState('StatusIconChanged');
	}

	function BeginState()
	{
		SetTimer(3.0, true);
	}
}

state StatusIconChanged
{

	function Timer()
	{
		local int X, Y;
		X = -90;
		Y = -160;

		DrawTutIcon(texture'MArrowR', X, Y);
		TranslatorMessage("Notice the blue team flag status icon changed.  Now it indicates that a red team player is in possession of the flag.  Blue team is in trouble!");
		GoToState('Returning');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state Returning
{
	function Timer()
	{
		StopTutIcon();
		TranslatorMessage("Take the flag back to your base and touch the red flag to capture the blue flag and score.");
		GoToState('FreeRunning2');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state FreeRunning2
{
	function Tick(float DeltaTime)
	{
		Super.Tick(DeltaTime);

		if (Trainee.PlayerReplicationInfo.HasFlag == None)
		{
			GoToState('CapturedFlag');
		}
	}

	function Timer()
	{
		HideTranslator();
		SetTimer(0.0, false);
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state CapturedFlag
{
	function Timer()
	{
		ShowTranslator();
		TranslatorMessage("Great job!  You captured the enemy flag and scored a point for your team.  Wasn't so hard, now, was it?");
		GoToState('Harder');
	}

	function BeginState()
	{
		SetTimer(2.0, true);
	}
}

state Harder
{
	function Timer()
	{
		TranslatorMessage("Its about to get harder.  In a few seconds, I'm going to spawn two blue team bots and a red teammate you can practice with.");
		GoToState('LastStatusIcon');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state LastStatusIcon
{
	function Timer()
	{
		TranslatorMessage("There is one last status icon to tell you about.  If a player drops the flag while carrying it, his team's flag status icon will change to a flag lying down.");
		GoToState('HowtoReturn');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state HowtoReturn
{
	function Timer()
	{
		TranslatorMessage("If you find your flag lying on the ground after you kill an enemy who was carrying it, touch it to automatically return it to your base.");
		GoToState('Conclusion');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state Conclusion
{
	function Timer()
	{
		TranslatorMessage("This concludes the CTF tutorial.  Let me spawn those practice bots for you.  Good hunting!");
		GoToState('TutorialOver');
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

state TutorialOver
{
	function Timer()
	{
		HideTranslator();
		AddBot();
		AddBot();
		AddBot();
		SetTimer(0.0, false);
	}

	function BeginState()
	{
		SetTimer(10.0, true);
	}
}

defaultproperties
{
	Difficulty=0
	BeaconName="CTF-Tutorial"
	GameName="Combat Training: CTF"
	MapPrefix="CTF-Tutorial"
	MapListType=Class'BotPack.CTFTUTmaplist'
	StartUpMessage=""
}
