//=============================================================================
// EndOfMatch
//=============================================================================
class EndOfMatch expands UnrealShortMenu
	localized
	config;

var localized string[240] SuccessMessage;
var localized string[240] FailureMessage;
var localized string[240] RatingMessage;
var localized string[240] CompletedMessage;
var localized string[240] VictoryMessage;
var localized string[32] Modifier[8];

function PostBeginPlay()
{
	local LadderMenu Ladder;
	Local ChallengeGameMenu C;
	local DeathMatchPlus RatedGame;
	local int ModifiedRating, i;
	local float BaseRating;
	local bool bDone;

	Super.PostBeginPlay();

	RatedGame = DeathMatchPlus(Level.Game);
	C = Spawn(class'ChallengeGameMenu');

	if ( RatedGame.SuccessfulGame() )
	{
		Ladder=Spawn(RatedGame.LadderMenuType);
		Ladder.Climb(RatedGame.IDnum);
		SuccessMessage = SuccessMessage
						$C.Ranking[RatedGame.IDnum]
						$" "$C.GetRungname(Ladder.rung[RatedGame.IDnum])$".";
		Ladder.Destroy();

		bDone = true;
		for ( i=0; i<C.numLadders; i++ )
			if ( C.Ladders[i].Default.rung[RatedGame.IDnum] != 15 )
				bDone = false;
	}
	else
		SuccessMessage = FailureMessage;

	BaseRating = 1000 + 400 * RatedGame.Difficulty;
	if ( RatedGame.bNoviceMode )
		BaseRating -= 500;

	ModifiedRating = Clamp(0,7,
						3 + int((RatedGame.PlayerRating - BaseRating)/100)); 

	if ( RatedGame.bNoviceMode )
		ModifiedRating = Min(ModifiedRating, 5);

	RatingMessage = RatingMessage$Modifier[ModifiedRating]$int(RatedGame.PlayerRating);


	if ( bDone )
	{
		C.Rank[RatedGame.IDnum]++;
		C.SaveConfig();
		if( C.Rank[RatedGame.IDnum] > 2 )
			CompletedMessage = VictoryMessage;
		//FIXME - print victory certificate, and end
	}
	else
		CompletedMessage="";

	C.Destroy();
}
	
function Menu ExitMenu()
{
	ProcessSelection();
}

function bool ProcessSelection()
{
	local Menu ChildMenu;
	
	ChildMenu = spawn(class'ChallengeGameMenu', owner);

	if ( ChildMenu != None )
	{
		HUD(Owner).MainMenu = ChildMenu;
		ChildMenu.ParentMenu = None;
		ChildMenu.PlayerOwner = PlayerOwner;
		Destroy();
	}
	return true;
}

function DrawMenu(canvas Canvas)
{
	local int i, StartX, StartY, Spacing;
	local vector DrawOffset;
	local rotator NewRot;

	// Draw title.
	MenuTitle=Default.MenuTitle$Level.Game.GameName;
	DrawFadeTitle(Canvas);

	Spacing = Clamp(0.1 * Canvas.ClipY, 20, 40);
	StartY = Max(40, 0.5 * (Canvas.ClipY - 128));

	Canvas.DrawColor.R = 0;
	Canvas.DrawColor.G = 0;
	Canvas.DrawColor.B = 255;
	Canvas.SetPos(32, StartY );
	Canvas.DrawText(SuccessMessage, false);
	Canvas.SetPos(32, StartY + Spacing );
	Canvas.DrawText(RatingMessage, false);
	Canvas.SetPos(32, StartY + 2 * Spacing );
	Canvas.DrawText(CompletedMessage, false);
}

defaultproperties
{
	Menutitle="Recap - Tournament "
	Modifier(0)="an abysmal "
	Modifier(1)="a poor "
	Modifier(2)="a mediocre "
	Modifier(3)="a respectable "
	Modifier(4)="an excellent "
	Modifier(5)="an outstanding "
	Modifier(6)="an amazing "
	Modifier(7)="an unbelievable "
	SuccessMessage="Your challenge was successful, and you achieve the rank of "
	FailureMessage="You fail to advance."
	RatingMessage="Your personal rating for this match is "
	CompletedMessage="You have now completed all the ladders for "
	VictoryMessage="You are now an Unreal Tournament Champion!"
}