//=============================================================================
// UnrealScoreBoard
//=============================================================================
class UnrealScoreBoard expands ScoreBoard;

var float 		Score0, Score1, Score2, Score3, Score4, Score5, Score6, Score7, Score8,
				Score9, Score10, Score11, Score12, Score13, Score14,
				Score15; //replication of arrays doesn't work

var string[32]  Name0, Name1, Name2, Name3, Name4, Name5, Name6, Name7, Name8,
				Name9, Name10, Name11, Name12, Name13, Name14, Name15;  
replication
{
	unreliable if( Role==ROLE_Authority )
		Score0, Score1, Score2, Score3, Score4, Score5, Score6, Score7, Score8,
		Score9, Score10, Score11, Score12, Score13, Score14, Score15,
		Name0, Name1, Name2, Name3, Name4, Name5, Name6, Name7, Name8,
		Name9, Name10, Name11, Name12, Name13, Name14, Name15;
}

function PostBeginPlay()
{
	CallParent.PostBeginPlay();
	if ( Level.NetMode != NM_Client )
		SetTimer(0.5, True);
}

// FIXME - update scores immediately on score change or player enter/exit
function Timer()
{
	local Pawn aPawn, Moving, Temp;
	local Pawn Scoring[16];
	local int i, num;

	aPawn = Level.PawnList;
	num = 0;

	// get a sorted list of the top 16 players
	while ( aPawn != None )
	{
		if ( aPawn.bIsPlayer )
		{
			if ( num < 16 )
				num++;
			Moving = aPawn;
			for (i=0; i<num; i++)
			{
				if ( Scoring[i] == None )
					Scoring[i] = Moving;
				else if ( Scoring[i].Score < Moving.Score )
				{
					Temp = Moving;
					Moving = Scoring[i];
					Scoring[i] = Temp;
				}
			}
		}		
		aPawn = aPawn.nextPawn;
	}

	if ( Scoring[0] == None )
		Name0 = "";
	else
	{
		Score0 = Scoring[0].Score;
		Name0 = Scoring[0].PlayerName;
	}
	if ( Scoring[1] == None )
		Name1 = "";
	else
	{
		Score1 = Scoring[1].Score;
		Name1 = Scoring[1].PlayerName;
	}
	if ( Scoring[2] == None )
		Name2 = "";
	else
	{
		Score2 = Scoring[2].Score;
		Name2 = Scoring[2].PlayerName;
	}
	if ( Scoring[3] == None )
		Name3 = "";
	else
	{
		Score3 = Scoring[3].Score;
		Name3 = Scoring[3].PlayerName;
	}
	if ( Scoring[4] == None )
		Name4 = "";
	else
	{
		Score4 = Scoring[4].Score;
		Name4 = Scoring[4].PlayerName;
	}
	if ( Scoring[5] == None )
		Name5 = "";
	else
	{
		Score5 = Scoring[5].Score;
		Name5 = Scoring[5].PlayerName;
	}
	if ( Scoring[6] == None )
		Name6 = "";
	else
	{
		Score6 = Scoring[6].Score;
		Name6 = Scoring[6].PlayerName;
	}
	if ( Scoring[7] == None )
		Name7 = "";
	else
	{
		Score7 = Scoring[7].Score;
		Name7 = Scoring[7].PlayerName;
	}
	if ( Scoring[8] == None )
		Name8 = "";
	else
	{
		Score8 = Scoring[8].Score;
		Name8 = Scoring[8].PlayerName;
	}
	if ( Scoring[9] == None )
		Name9 = "";
	else
	{
		Score9 = Scoring[9].Score;
		Name9 = Scoring[9].PlayerName;
	}
	if ( Scoring[10] == None )
		Name10 = "";
	else
	{
		Score10 = Scoring[10].Score;
		Name10 = Scoring[10].PlayerName;
	}
	if ( Scoring[11] == None )
		Name11 = "";
	else
	{
		Score11 = Scoring[11].Score;
		Name11 = Scoring[11].PlayerName;
	}
	if ( Scoring[12] == None )
		Name12 = "";
	else
	{
		Score12 = Scoring[12].Score;
		Name12 = Scoring[12].PlayerName;
	}
	if ( Scoring[13] == None )
		Name13 = "";
	else
	{
		Score13 = Scoring[13].Score;
		Name13 = Scoring[13].PlayerName;
	}
	if ( Scoring[14] == None )
		Name14 = "";
	else
	{
		Score14 = Scoring[14].Score;
		Name14 = Scoring[14].PlayerName;
	}
	if ( Scoring[15] == None )
		Name15 = "";
	else
	{
		Score15 = Scoring[15].Score;
		Name15 = Scoring[15].PlayerName;
	}
}

simulated function ShowScores( canvas Canvas )
{
	local int i, num, max;
	local string[32]  Names[16];
	local float Scores[16];

	max = Min(num, int(0.03725 * Canvas.ClipY));
	
	Names[0] = Name0;
	Scores[0] = Score0;
	Names[1] = Name1;
	Scores[1] = Score1;
	Names[2] = Name2;
	Scores[2] = Score2;
	Names[3] = Name3;
	Scores[3] = Score3;
	Names[4] = Name4;
	Scores[4] = Score4;
	Names[5] = Name5;
	Scores[5] = Score5;
	Names[6] = Name6;
	Scores[6] = Score6;
	Names[7] = Name7;
	Scores[7] = Score7;
	Names[8] = Name8;
	Scores[8] = Score8;
	Names[9] = Name9;
	Scores[9] = Score9;
	Names[10] = Name10;
	Scores[10] = Score10;
	Names[11] = Name11;
	Scores[11] = Score11;
	Names[12] = Name12;
	Scores[12] = Score12;
	Names[13] = Name13;
	Scores[13] = Score13;
	Names[14] = Name14;
	Scores[14] = Score14;
	Names[15] = Name15;
	Scores[15] = Score15;

	// Display it
	Canvas.Font = Font'MedFont';
	num = 0;

	for ( i=0; i<16; i++ )
	{
		if ( Names[i] != "" )
		{
			Canvas.SetPos(0.2 * Canvas.ClipX, 0.2 * Canvas.ClipY + 16 * num );
			Canvas.DrawText(Names[i], False);
			Canvas.SetPos(0.7 * Canvas.ClipX, 0.2 * Canvas.ClipY + 16 * num );
			Canvas.DrawText(int(Scores[i]), False);
			num++;
			if ( num >= max )
				break;
		}
	}	
}

