
class BRUTHUD extends ChallengeHUD config;

#exec TEXTURE IMPORT NAME=HudElements1Extra 	FILE=TEXTURES\HudElements1Extra.bmp GROUP="Icons" MIPS=OFF FLAGS=2
#exec TEXTURE IMPORT NAME=HudElements2Extra 	FILE=TEXTURES\HudElements2Extra.bmp GROUP="Icons" MIPS=OFF FLAGS=2
#exec TEXTURE IMPORT NAME=HUDWeaponsBRUT 		FILE=TEXTURES\HUDWeaponsBRUT.bmp 	GROUP="Icons" MIPS=OFF FLAGS=2

#exec TEXTURE IMPORT NAME=BlackStuff  FILE=Textures\BlackStuff.bmp  MIPS=OFF LODSET=0
#exec TEXTURE IMPORT NAME=BlackStuff2  FILE=Textures\BlackStuff2.bmp  MIPS=OFF LODSET=0

#exec TEXTURE IMPORT NAME=KillCamTile FILE=Textures\KillCamTile.bmp Group=HUD MIPS=ON

var int PlayerAliveCount;
var color WhiteColor;
var BRUTGameReplicationInfo GRI;

simulated function SetGRI(GameReplicationInfo NewGRI)
{
	GRI = BRUTGameReplicationInfo(NewGRI);
}

simulated function PostBeginPlay()
{
	Super.PostBeginPlay();
	if (Level.Game != None)
		SetGRI(Level.Game.GameReplicationInfo);
}

//Brought in to replace the default HUD weapon tiles
simulated function DrawWeapons(Canvas Canvas)
{
    local Weapon W, WeaponSlot[11];
    local inventory Inv;
    local int i, j, BaseY, BaseX, Pending, WeapX, WeapY;
    local float AmmoScale, WeaponOffset, WeapScale, WeaponX, TexX, TexY;

    BaseX = 0.5 * (Canvas.ClipX - HudScale * WeaponScale * Canvas.ClipX);
    WeapScale = WeaponScale * Scale;
    Canvas.Style = Style;
    BaseY = Canvas.ClipY - 63.5 * WeapScale;
    WeaponOffset = 0.1 * HUDScale * WeaponScale * Canvas.ClipX;

    if (PawnOwner.Weapon != None)
    {
        W = PawnOwner.Weapon;
        if ((Opacity > 8) || !Level.bHighDetailMode)
            Canvas.Style = ERenderStyle.STY_Normal;
        WeaponX = BaseX + (W.InventoryGroup - 1) * WeaponOffset;
        Canvas.CurX = WeaponX;
        Canvas.CurY = BaseY;
        Canvas.DrawColor = SolidHUDColor;
        Canvas.DrawIcon(W.StatusIcon, WeapScale);
        Canvas.DrawColor = GoldColor;
        Canvas.CurX = WeaponX + 4 * WeapScale;
        Canvas.CurY = BaseY + 4 * WeapScale;
        Canvas.Style = Style;
        if (W.InventoryGroup == 10)
            Canvas.DrawTile(Texture'BotPack.HudElements1', 0.75 * WeapScale * 25, 0.75 * WeapScale * 64, 0, 0, 25.0, 64.0);
        else
            Canvas.DrawTile(Texture'BotPack.HudElements1', 0.75 * WeapScale * 25, 0.75 * WeapScale * 64, 25*W.InventoryGroup, 0, 25.0, 64.0);

        WeaponSlot[W.InventoryGroup] = W;  
        Canvas.CurX = WeaponX;
        Canvas.CurY = BaseY;
        Canvas.DrawTile(Texture'HUDWeaponsBRUT', 128 * WeapScale, 64 * WeapScale, 128, 64, 128, 64);
    }
    if (Level.bHighDetailMode && (PawnOwner.PendingWeapon != None))
    {
        Pending = PawnOwner.PendingWeapon.InventoryGroup;
        Canvas.CurX = BaseX + (Pending - 1) * WeaponOffset - 64 * WeapScale;
        Canvas.CurY = Canvas.ClipY - 96 * WeapScale; 
        Canvas.Style = ERenderStyle.STY_Translucent;
        Canvas.DrawColor = GoldColor;
        Canvas.DrawTile(Texture'HUDWeaponsBRUT', 256 * WeapScale, 128 * WeapScale, 0, 128, 256.0, 128.0);
    }
    else
        Pending = 100;

    Canvas.Style = Style;
    i = 0;
    for (Inv=PawnOwner.Inventory; Inv!=None; Inv=Inv.Inventory)
    {
        if (Inv.IsA('Weapon') && (Inv != PawnOwner.Weapon))
        {
            W = Weapon(Inv);
            if (WeaponSlot[W.InventoryGroup] == None)
                WeaponSlot[W.InventoryGroup] = W;
            else if ((WeaponSlot[W.InventoryGroup] != PawnOwner.Weapon)
                    && ((W == PawnOwner.PendingWeapon) || (WeaponSlot[W.InventoryGroup].AutoSwitchPriority < W.AutoSwitchPriority)))
                WeaponSlot[W.InventoryGroup] = W;
        }
        i++;
        if (i > 100)
            break; // can occasionally get temporary loops in netplay
    }
    W = PawnOwner.Weapon;

    // draw weapon list
    TexX = 128 * WeapScale;
    TexY = 64 * WeapScale;
    for (i=1; i<11; i++)
    {
        if (WeaponSlot[i] == None)
        {
            Canvas.Style = Style;
            Canvas.DrawColor =  0.5 * HUDColor;
            Canvas.CurX = BaseX + (i - 1) * WeaponOffset;
            Canvas.CurY = BaseY;
            
            WeapX = ((i-1)%4) * 64;
            WeapY = ((i-1)/4) * 32;
            Canvas.DrawTile(Texture'HUDWeaponsBRUT',TexX,TexY,WeapX,WeapY,64.0,32.0);
        }
        else if (WeaponSlot[i] != W)
        {
            if (Pending == i)
            {
                if ((Opacity > 8) || !Level.bHighDetailMode)
                    Canvas.Style = ERenderStyle.STY_Normal;
                Canvas.DrawColor = SolidHUDColor;
            }
            else
            {
                Canvas.Style = Style;
                Canvas.DrawColor = 0.5 * HUDColor;
            }
            Canvas.CurX = BaseX + (i - 1) * WeaponOffset;
            Canvas.CurY = BaseY;
            
            if (WeaponSlot[i].bSpecialIcon)
                Canvas.DrawIcon(WeaponSlot[i].StatusIcon, WeapScale);
            else
            {
                WeapX = ((i-1)%4) * 64;
                WeapY = ((i-1)/4) * 32;
                Canvas.DrawTile(Texture'HUDWeaponsBRUT',TexX,TexY,WeapX,WeapY,64.0,32.0);
            }
        }
    }

    //draw weapon numbers and ammo
    TexX = 0.75 * WeapScale * 25;
    TexY = 0.75 * WeapScale * 64;
    for (i=1; i<11; i++)
    {
        if (WeaponSlot[i] != None)
        {
            WeaponX = BaseX + (i - 1) * WeaponOffset + 4 * WeapScale;
            if (WeaponSlot[i] != W)
            {
                Canvas.CurX = WeaponX;
                Canvas.CurY = BaseY + 4 * WeapScale;
                Canvas.DrawColor = GoldColor;
                if ((Opacity > 8) || !Level.bHighDetailMode)
                    Canvas.Style = ERenderStyle.STY_Normal;
                else
                    Canvas.Style = Style;
                if (i == 10)
                    Canvas.DrawTile(Texture'BotPack.HudElements1', TexX, TexY, 0, 0, 25.0, 64.0);
                else
                    Canvas.DrawTile(Texture'BotPack.HudElements1', TexX, TexY, 25*i, 0, 25.0, 64.0);
            }
            if (WeaponSlot[i].AmmoType != None)
            {
                // Draw Ammo bar
                Canvas.CurX = WeaponX;
                Canvas.CurY = BaseY + 52 * WeapScale;
                Canvas.DrawColor = BaseColor;
                AmmoScale = FClamp(88.0 * WeapScale * WeaponSlot[i].AmmoType.AmmoAmount/WeaponSlot[i].AmmoType.MaxAmmo, 0, 88);
                Canvas.DrawTile(Texture'BotPack.HudElements1', AmmoScale, 8 * WeapScale,64,64,128.0,8.0);
            }
        }
    }
}

//The longer-lasting meds are drawn in preference over the shorter ones. No active meds gets the BRUT default tile
simulated function DrawFragCount(Canvas Canvas)
{
	local inventory Inv;

   if (PawnOwner.PlayerReplicationInfo == None)
      return;

	Inv = Pawn(Owner).FindInventoryType(class'Medkit');
	if (Inv != none)
	{
		DrawMedkitTile(Canvas);
		return;
	}
	Inv = Pawn(Owner).FindInventoryType(class'PainPills');
	if (Inv != none)
	{
		DrawPainpillTile(Canvas);
		return;
	}
	Inv = Pawn(Owner).FindInventoryType(class'BandagesSmallPack');
	if (Inv != none)
	{
		DrawBandageTile(Canvas);
		return;
	}
	DrawPUBGTile(Canvas);
	return;
}

simulated function DrawMedkitTile(Canvas Canvas)
{
   local float Whiten;
   local int X,Y;
   local inventory Inv;

   Canvas.Style = Style;
   if (bHideAllWeapons || (HudScale * WeaponScale * Canvas.ClipX <= Canvas.ClipX - 256 * Scale))
      Y = Canvas.ClipY - 63.5 * Scale;
   else
      Y = Canvas.ClipY - 127.5 * Scale;
   if (bHideAllWeapons)
      X = 0.5 * Canvas.ClipX - 256 * Scale;
   Canvas.CurX = X;
   Canvas.CurY = Y;
   Canvas.DrawColor = HUDColor;
  	Canvas.DrawTile(Texture'HudElements2Extra', 128*Scale, 64*Scale, 0, 128, 128.0, 64.0);
   Canvas.DrawColor = WhiteColor;
   for(Inv=PawnOwner.Inventory; Inv!=None; Inv=Inv.Inventory)
		if (Inv.class == Class'BRUT.Medkit')
   		DrawBigNum(Canvas, Medkit(Inv).Charge, X * Scale, Y + 16 * Scale);
}

simulated function DrawPainpillTile(Canvas Canvas)
{
   local float Whiten;
   local int X,Y;
   local inventory Inv;

   Canvas.Style = Style;
   if (bHideAllWeapons || (HudScale * WeaponScale * Canvas.ClipX <= Canvas.ClipX - 256 * Scale))
      Y = Canvas.ClipY - 63.5 * Scale;
   else
      Y = Canvas.ClipY - 127.5 * Scale;
   if (bHideAllWeapons)
      X = 0.5 * Canvas.ClipX - 256 * Scale;
   Canvas.CurX = X;
   Canvas.CurY = Y;
   Canvas.DrawColor = HUDColor;
  	Canvas.DrawTile(Texture'HudElements2Extra', 128*Scale, 64*Scale, 0, 192, 128.0, 64.0);
   Canvas.DrawColor = WhiteColor;
   for(Inv=PawnOwner.Inventory; Inv!=None; Inv=Inv.Inventory)
		if (Inv.class == Class'BRUT.Painpills')
   		DrawBigNum(Canvas, Painpills(Inv).Charge, X * Scale, Y + 16 * Scale);
}

simulated function DrawBandageTile(Canvas Canvas)
{
   local float Whiten;
   local int X,Y;
   local inventory Inv;

   Canvas.Style = Style;
   if (bHideAllWeapons || (HudScale * WeaponScale * Canvas.ClipX <= Canvas.ClipX - 256 * Scale))
      Y = Canvas.ClipY - 63.5 * Scale;
   else
      Y = Canvas.ClipY - 127.5 * Scale;
   if (bHideAllWeapons)
      X = 0.5 * Canvas.ClipX - 256 * Scale;
   Canvas.CurX = X;
   Canvas.CurY = Y;
   Canvas.DrawColor = HUDColor;
  	Canvas.DrawTile(Texture'HudElements2Extra', 128*Scale, 64*Scale, 128, 128, 128.0, 64.0);
   Canvas.DrawColor = WhiteColor;
   for(Inv=PawnOwner.Inventory; Inv!=None; Inv=Inv.Inventory)
		if (Inv.class == Class'BRUT.BandagesSmallPack')
   		DrawBigNum(Canvas, BandagesSmallPack(Inv).Charge, X * Scale, Y + 16 * Scale);
}

simulated function DrawPUBGTile(Canvas Canvas)
{
   local float Whiten;
   local int X,Y;

   Canvas.Style = Style;
   if (bHideAllWeapons || (HudScale * WeaponScale * Canvas.ClipX <= Canvas.ClipX - 256 * Scale))
      Y = Canvas.ClipY - 63.5 * Scale;
   else
      Y = Canvas.ClipY - 127.5 * Scale;
   if (bHideAllWeapons)
      X = 0.5 * Canvas.ClipX - 256 * Scale;
   Canvas.CurX = X;
   Canvas.CurY = Y;
   Canvas.DrawColor = HUDColor;
 	Canvas.DrawTile(Texture'HudElements1Extra', 128*Scale, 64*Scale, 0, 128, 128.0, 64.0);
}

simulated function DrawGameSynopsis(Canvas Canvas)
{
   local float XL, YL, XOffset, YOffset;
   local int MaxPlayers;
   local string Spread;

   if ((PawnOwner.PlayerReplicationInfo == None) || PawnOwner.PlayerReplicationInfo.bIsSpectator || (PlayerCount == 1))
      return;

   Canvas.Font = MyFonts.GetBigFont(Canvas.ClipX);
   Canvas.DrawColor = WhiteColor;
   // Rank String (unused)
   Canvas.StrLen(RankString, XL, YL);
   if (bHideAllWeapons)
      YOffset = Canvas.ClipY - YL*2;
   else if (HudScale * WeaponScale * Canvas.ClipX <= Canvas.ClipX - 256 * Scale)
      YOffset = Canvas.ClipY - 64*Scale - YL*2;
   else
      YOffset = Canvas.ClipY - 128*Scale - YL*2;
   Canvas.SetPos(0, YOffset);
 //  Canvas.DrawText(RankString, False);
   Canvas.SetPos(XL, YOffset);
//   Canvas.DrawText(" "$Rank@"/"@PlayerCount, False);
   Canvas.DrawColor = WhiteColor;
   // ALIVE: String
   Canvas.SetPos(0, YOffset + YL);
   Spread = SpreadString$" "$PlayerAliveCount;
   Canvas.DrawText(Spread, False); 
}

function UpdateRankAndSpread()
{
   local PlayerReplicationInfo PRI;
   local int HighScore;
   local int i, j;

   PlayerCount = 0;
   PlayerAliveCount = 0;
   HighScore = -100;
   bTiedScore = False;
   Rank = 1;
   for (i=0; i<32; i++)
   {
      PRI = PlayerOwner.GameReplicationInfo.PRIArray[i];
      if ((PRI != None) && (!PRI.bIsSpectator || PRI.bWaitingPlayer))
      {
         PlayerCount++;
			if (PRI.Deaths == 0)
				PlayerAliveCount++;

         if (PRI != PawnOwner.PlayerReplicationInfo)
         {
            if (PRI.Score > PawnOwner.PlayerReplicationInfo.Score)
               Rank += 1;
            else if (PRI.Score == PawnOwner.PlayerReplicationInfo.Score)
            {
               bTiedScore = True;
            	if (PRI.Deaths < PawnOwner.PlayerReplicationInfo.Deaths)
                  Rank += 1;
               else if (PRI.Deaths == PawnOwner.PlayerReplicationInfo.Deaths)
                  if (PRI.PlayerID < PawnOwner.PlayerReplicationInfo.PlayerID)
                     Rank += 1;
            }
            if (PRI.Score > HighScore)
               HighScore = PRI.Score;
         }
      }
   }
   Lead = int(PawnOwner.PlayerReplicationInfo.Score) - HighScore;
}

simulated function DrawStatus(Canvas Canvas)
{
   local float StatScale, ChestAmount, ThighAmount, H1, H2, X, Y, DamageTime;
   Local int ArmorAmount, HelmetAmount, CurAbs,i;
   Local inventory Inv,BestArmor;
   local bool bChestArmor, bShieldbelt, bThighArmor, bJumpBoots, bHasDoll;
   local Bot BotOwner;
   local TournamentPlayer TPOwner;
   local texture Doll, DollBelt;

    ArmorAmount = 0;
    CurAbs = 0;
    i = 0;
    BestArmor=None;
    for(Inv=PawnOwner.Inventory; Inv!=None; Inv=Inv.Inventory)
    { 
      if (Inv.bIsAnArmor)
      {
 			if (Inv.IsA('KevlarOne'))
         {
            bChestArmor = true;
            ChestAmount += Inv.Charge;
            ArmorAmount += Inv.Charge;
         }
         else if (Inv.IsA('Helmet'))
				HelmetAmount += Inv.Charge;
      }
      else if (Inv.IsA('UT_JumpBoots'))
         bJumpBoots = true;
      else
      {
         i++;
         if (i > 100)
            break;
      }
   }
   if (!bHideStatus)
   {
      TPOwner = TournamentPlayer(PawnOwner);
      if (Canvas.ClipX < 400)
      	bHasDoll = false;
      else if (TPOwner != None)
      {
         Doll = TPOwner.StatusDoll;
         DollBelt = TPOwner.StatusBelt;
         bHasDoll = true;
      }
      else
      {
         BotOwner = Bot(PawnOwner);
         if (BotOwner != None)
         {
            Doll = BotOwner.StatusDoll;
            DollBelt = BotOwner.StatusBelt;
            bHasDoll = true;
         }
      }
   }

	//Health tile
    Canvas.DrawColor = HUDColor;
    if (bHideStatus && bHideAllWeapons)
    {
        X = 0.5 * Canvas.ClipX;
        Y = Canvas.ClipY - 64 * Scale;
    }
    else
    {
        X = Canvas.ClipX - 128 * StatScale - 140 * Scale;
        Y = 64 * Scale;
    }
    Canvas.SetPos(X,Y);
    if (PawnOwner.Health < 50)
    {
        H1 = 1.5 * TutIconBlink;
        H2 = 1 - H1;
        Canvas.DrawColor = WhiteColor * H2 + (HUDColor - WhiteColor) * H1;
    }
    else
        Canvas.DrawColor = HUDColor;
    Canvas.DrawTile(Texture'BotPack.HudElements1', 128*Scale, 64*Scale, 128, 128, 128.0, 64.0);

    if (PawnOwner.Health < 50)
    {
        H1 = 1.5 * TutIconBlink;
        H2 = 1 - H1;
        Canvas.DrawColor = Canvas.DrawColor * H2 + (WhiteColor - Canvas.DrawColor) * H1;
    }
    else Canvas.DrawColor = WhiteColor;
    DrawBigNum(Canvas, Max(0, PawnOwner.Health), X + 4 * Scale, Y + 16 * Scale, 1);

	//Vest tile
    Canvas.DrawColor = HUDColor;
    if (bHideStatus && bHideAllWeapons)
    {
        X = 0.5 * Canvas.ClipX - 128 * Scale;
        Y = Canvas.ClipY - 64 * Scale;
    }
    else
    {
        X = Canvas.ClipX - 128 * StatScale - 140 * Scale;
        Y = 0;
    }
    Canvas.SetPos(X, Y);
    Canvas.DrawTile(Texture'HudElements2Extra', 128*Scale, 64*Scale, 128, 192, 128.0, 64.0);
    if (bHideStatus && bShieldBelt)
        Canvas.DrawColor = GoldColor;
    else Canvas.DrawColor = WhiteColor;
    DrawBigNum(Canvas, Min(150,ArmorAmount), X + 4 * Scale, Y + 16 * Scale, 1);

	//Helmet tile
   Canvas.DrawColor = HUDColor;
    if (bHideStatus && bHideAllWeapons)
    {
        X = 0.5 * Canvas.ClipX - 128 * Scale;
        Y = Canvas.ClipY - 64 * Scale;
    }
    else
    {
        X = Canvas.ClipX - 128 * StatScale - 140 * Scale;
        Y = 128 * Scale;
    }
    Canvas.SetPos(X, Y);
    Canvas.DrawTile(Texture'HudElements1Extra', 128*Scale, 64*Scale, 0, 192, 128.0, 64.0);
    if (bHideStatus && bShieldBelt)
        Canvas.DrawColor = GoldColor;
    else Canvas.DrawColor = WhiteColor;
    DrawBigNum(Canvas, Min(150,HelmetAmount), X + 4 * Scale, Y + 16 * Scale, 1);
}

simulated function PostRender(canvas Canvas)
{
    local float XL, YL, XPos, YPos, FadeValue;
    local string Message;
    local int M, i, j, k, XOverflow;
    local float OldOriginX;  

    HUDSetup(canvas);
    if ((PawnOwner == None) || (PlayerOwner.PlayerReplicationInfo == None))
        return;

    if (bShowInfo)
    {
        ServerInfo.RenderInfo(Canvas);
        return;
    }

    Canvas.Font = MyFonts.GetSmallFont(Canvas.ClipX);
    OldOriginX = Canvas.OrgX;
    // Master message short queue control loop.
    Canvas.Font = MyFonts.GetSmallFont(Canvas.ClipX);
    Canvas.StrLen("TEST", XL, YL);
    Canvas.SetClip(768*Scale - 10, Canvas.ClipY);
    bDrawFaceArea = false;
    if (!bHideFaces && !PlayerOwner.bShowScores && !bForceScores && !bHideHUD 
            && !PawnOwner.PlayerReplicationInfo.bIsSpectator && (Scale >= 0.4))
    {
        DrawSpeechArea(Canvas, XL, YL);
        bDrawFaceArea = (FaceTexture != None) && (FaceTime > Level.TimeSeconds);
        if (bDrawFaceArea)
        {
            if (!bHideHUD && ((PawnOwner.PlayerReplicationInfo == None) || !PawnOwner.PlayerReplicationInfo.bIsSpectator))
                Canvas.SetOrigin(FMax(YL*4 + 8, 70*Scale) + 7*Scale + 6 + FaceAreaOffset, Canvas.OrgY);
        }
    }

    for (i=0; i<4; i++)
    {
        if (ShortMessageQueue[i].Message != None)
        {
            j++;

            if (bResChanged || (ShortMessageQueue[i].XL == 0))
            {
                if (ShortMessageQueue[i].Message.Default.bComplexString)
                    Canvas.StrLen(ShortMessageQueue[i].Message.Static.AssembleString(
                                            self,
                                            ShortMessageQueue[i].Switch,
                                            ShortMessageQueue[i].RelatedPRI,
                                            ShortMessageQueue[i].StringMessage), 
                                   ShortMessageQueue[i].XL, ShortMessageQueue[i].YL);
                else
                    Canvas.StrLen(ShortMessageQueue[i].StringMessage, ShortMessageQueue[i].XL, ShortMessageQueue[i].YL);
                Canvas.StrLen("TEST", XL, YL);
                ShortMessageQueue[i].numLines = 1;
                if (ShortMessageQueue[i].YL > YL)
                {
                    ShortMessageQueue[i].numLines++;
                    for (k=2; k<4-i; k++)
                    {
                        if (ShortMessageQueue[i].YL > YL*k)
                            ShortMessageQueue[i].numLines++;
                    }
                }
            }

            // Keep track of the amount of lines a message overflows, to offset the next message with.
            Canvas.SetPos(6, 2 + YL * YPos);
            YPos += ShortMessageQueue[i].numLines;
            if (YPos > 4)
                break; 

            if (ShortMessageQueue[i].Message.Default.bComplexString)
            {
                // Use this for string messages with multiple colors.
                ShortMessageQueue[i].Message.Static.RenderComplexMessage(
                    Canvas,
                    ShortMessageQueue[i].XL,  YL,
                    ShortMessageQueue[i].StringMessage,
                    ShortMessageQueue[i].Switch,
                    ShortMessageQueue[i].RelatedPRI,
                    None,
                    ShortMessageQueue[i].OptionalObject
                   );              
            } 
            else
            {
                Canvas.DrawColor = ShortMessageQueue[i].Message.Default.DrawColor;
                Canvas.DrawText(ShortMessageQueue[i].StringMessage, False);
            }
        }
    }

    Canvas.DrawColor = WhiteColor;
    Canvas.SetClip(OldClipX, Canvas.ClipY);
    Canvas.SetOrigin(OldOriginX, Canvas.OrgY);

    if (PlayerOwner.bShowScores || bForceScores)
    {
        if ((PlayerOwner.Scoring == None) && (PlayerOwner.ScoringType != None))
            PlayerOwner.Scoring = Spawn(PlayerOwner.ScoringType, PlayerOwner);
        if (PlayerOwner.Scoring != None)
        { 
            PlayerOwner.Scoring.OwnerHUD = self;
            PlayerOwner.Scoring.ShowScores(Canvas);
            if (PlayerOwner.Player.Console.bTyping)
                DrawTypingPrompt(Canvas, PlayerOwner.Player.Console);
            return;
        }
    }

    YPos = FMax(YL*4 + 8, 70*Scale);
    if (bDrawFaceArea)
        DrawTalkFace(Canvas,0, YPos);
    if (j > 0) 
    {
        bDrawMessageArea = True;
        MessageFadeCount = 2;
    } 
    else 
        bDrawMessageArea = False;

    if (!bHideCenterMessages)
    {
        // Master localized message control loop.
        for (i=0; i<10; i++)
        {
            if (LocalMessages[i].Message != None)
            {
                if (LocalMessages[i].Message.Default.bFadeMessage && Level.bHighDetailMode)
                {
                    Canvas.Style = ERenderStyle.STY_Translucent;
                    FadeValue = (LocalMessages[i].EndOfLife - Level.TimeSeconds);
                    if (FadeValue > 0.0)
                    {
                        if (bResChanged || (LocalMessages[i].XL == 0))
                        {
                            if (LocalMessages[i].Message.Static.GetFontSize(LocalMessages[i].Switch) == 1)
                                LocalMessages[i].StringFont = MyFonts.GetBigFont(Canvas.ClipX);
                            else // ==2
                                LocalMessages[i].StringFont = MyFonts.GetHugeFont(Canvas.ClipX);
                            Canvas.Font = LocalMessages[i].StringFont;
                            Canvas.StrLen(LocalMessages[i].StringMessage, LocalMessages[i].XL, LocalMessages[i].YL);
                            LocalMessages[i].YPos = LocalMessages[i].Message.Static.GetOffset(LocalMessages[i].Switch, LocalMessages[i].YL, Canvas.ClipY);
                        }
                        Canvas.Font = LocalMessages[i].StringFont;
                        Canvas.DrawColor = LocalMessages[i].DrawColor * (FadeValue/LocalMessages[i].LifeTime);
                        Canvas.SetPos(0.5 * (Canvas.ClipX - LocalMessages[i].XL), LocalMessages[i].YPos);
                        Canvas.DrawText(LocalMessages[i].StringMessage, False);
                    }
                } 
                else 
                {
                    if (bResChanged || (LocalMessages[i].XL == 0))
                    {
                        if (LocalMessages[i].Message.Static.GetFontSize(LocalMessages[i].Switch) == 1)
                            LocalMessages[i].StringFont = MyFonts.GetBigFont(Canvas.ClipX);
                        else // == 2
                            LocalMessages[i].StringFont = MyFonts.GetHugeFont(Canvas.ClipX);
                        Canvas.Font = LocalMessages[i].StringFont;
                        Canvas.StrLen(LocalMessages[i].StringMessage, LocalMessages[i].XL, LocalMessages[i].YL);
                        LocalMessages[i].YPos = LocalMessages[i].Message.Static.GetOffset(LocalMessages[i].Switch, LocalMessages[i].YL, Canvas.ClipY);
                    }
                    Canvas.Font = LocalMessages[i].StringFont;
                    Canvas.Style = ERenderStyle.STY_Normal;
                    Canvas.DrawColor = LocalMessages[i].DrawColor;
                    Canvas.SetPos(0.5 * (Canvas.ClipX - LocalMessages[i].XL), LocalMessages[i].YPos);
                    Canvas.DrawText(LocalMessages[i].StringMessage, False);
                }
            }
        }
    }
    Canvas.Style = ERenderStyle.STY_Normal;

    if (!PlayerOwner.bBehindView && (PawnOwner.Weapon != None) && (Level.LevelAction == LEVACT_None))
    {
        Canvas.DrawColor = WhiteColor;
        PawnOwner.Weapon.PostRender(Canvas);
        if (!PawnOwner.Weapon.bOwnsCrossHair)
            DrawCrossHair(Canvas, 0,0);
    }

    if ((PawnOwner != Owner) && PawnOwner.bIsPlayer)
    {
        Canvas.Font = MyFonts.GetSmallFont(Canvas.ClipX);
        Canvas.bCenter = true;
        Canvas.Style = ERenderStyle.STY_Normal;
        Canvas.DrawColor = CyanColor * TutIconBlink;
        Canvas.SetPos(4, Canvas.ClipY - 96 * Scale);
        Canvas.DrawText(LiveFeed$PawnOwner.PlayerReplicationInfo.PlayerName, true);
        Canvas.bCenter = false;
        Canvas.DrawColor = WhiteColor;
        Canvas.Style = Style;
    }

    if (bStartUpMessage && (Level.TimeSeconds < 5))
    {
        bStartUpMessage = false;
        PlayerOwner.SetProgressTime(7);
    }
    if ((PlayerOwner.ProgressTimeOut > Level.TimeSeconds) && !bHideCenterMessages)
        DisplayProgressMessage(Canvas);

    // Display MOTD
    if (MOTDFadeOutTime > 0.0)
        DrawMOTD(Canvas);
         
    if(!bHideHUD)
    {
        if (!PawnOwner.PlayerReplicationInfo.bIsSpectator)
        {
            Canvas.Style = Style;

            // Draw Ammo
            if (!bHideAmmo)
                DrawAmmo(Canvas);
            
            // Draw Health/Armor status
            DrawStatus(Canvas);

            // Display Weapons
            if (!bHideAllWeapons)
                DrawWeapons(Canvas);
            else if (Level.bHighDetailMode
                    && (PawnOwner == PlayerOwner) && (PlayerOwner.Handedness == 2))
            {
                // if weapon bar hidden and weapon hidden, draw weapon name when it changes
                if (PawnOwner.PendingWeapon != None)
                {
                    WeaponNameFade = 1.0;
                    Canvas.Font = MyFonts.GetBigFont(Canvas.ClipX);
                    Canvas.DrawColor = PawnOwner.PendingWeapon.NameColor;
                    Canvas.SetPos(Canvas.ClipX - 360 * Scale, Canvas.ClipY - 64 * Scale);
                    Canvas.DrawText(PawnOwner.PendingWeapon.ItemName, False);
                }
                else if ((Level.NetMode == NM_Client)  
                        && PawnOwner.IsA('TournamentPlayer') && (TournamentPlayer(PawnOwner).ClientPending != None))
                {
                    WeaponNameFade = 1.0;
                    Canvas.Font = MyFonts.GetBigFont(Canvas.ClipX);
                    Canvas.DrawColor = TournamentPlayer(PawnOwner).ClientPending.NameColor;
                    Canvas.SetPos(Canvas.ClipX - 360 * Scale, Canvas.ClipY - 64 * Scale);
                    Canvas.DrawText(TournamentPlayer(PawnOwner).ClientPending.ItemName, False);
                }
                else if ((WeaponNameFade > 0) && (PawnOwner.Weapon != None))
                {
                    Canvas.Font = MyFonts.GetBigFont(Canvas.ClipX);
                    Canvas.DrawColor = PawnOwner.Weapon.NameColor;
                    if (WeaponNameFade < 1)
                        Canvas.DrawColor = Canvas.DrawColor * WeaponNameFade;
                    Canvas.SetPos(Canvas.ClipX - 360 * Scale, Canvas.ClipY - 64 * Scale);
                    Canvas.DrawText(PawnOwner.Weapon.ItemName, False);
                }
            }
            // Display Frag count
            if (!bAlwaysHideFrags && !bHideFrags)
                DrawFragCount(Canvas);
        }
        // Team Game Synopsis
        if (!bHideTeamInfo)
            DrawGameSynopsis(Canvas);

        // Display Identification Info
        if (PawnOwner == PlayerOwner)
            DrawIdentifyInfo(Canvas);

        if (HUDMutator != None)
            HUDMutator.PostRender(Canvas);

        if ((PlayerOwner.GameReplicationInfo != None) && (PlayerPawn(Owner).GameReplicationInfo.RemainingTime > 0)) 
        {
            if (TimeMessageClass == None)
                TimeMessageClass = class<CriticalEventPlus>(DynamicLoadObject("Botpack.TimeMessage", class'Class'));

            if ((PlayerOwner.GameReplicationInfo.RemainingTime <= 300)
              && (PlayerOwner.GameReplicationInfo.RemainingTime != LastReportedTime))
            {
                LastReportedTime = PlayerOwner.GameReplicationInfo.RemainingTime;
                if (PlayerOwner.GameReplicationInfo.RemainingTime <= 30)
                {
                    bTimeValid = (bTimeValid || (PlayerOwner.GameReplicationInfo.RemainingTime > 0)); 
                    if (PlayerOwner.GameReplicationInfo.RemainingTime == 30)
                        TellTime(5);
                    else if (bTimeValid && PlayerOwner.GameReplicationInfo.RemainingTime <= 10)
                        TellTime(16 - PlayerOwner.GameReplicationInfo.RemainingTime);
                }
                else if (PlayerOwner.GameReplicationInfo.RemainingTime % 60 == 0)
                {
                    M = PlayerOwner.GameReplicationInfo.RemainingTime/60;
                    TellTime(5 - M);
                }
            }
        }
    }
    if (PlayerOwner.Player.Console.bTyping)
        DrawTypingPrompt(Canvas, PlayerOwner.Player.Console);

    if (PlayerOwner.bBadConnectionAlert && (PlayerOwner.Level.TimeSeconds > 5))
    {
        Canvas.Style = ERenderStyle.STY_Normal;
        Canvas.DrawColor = WhiteColor;
        Canvas.SetPos(Canvas.ClipX - (64*Scale), Canvas.ClipY / 2);
        Canvas.DrawIcon(texture'DisconnectWarn', Scale);
    }

	if (BRUTGameReplicationInfo(PlayerPawn(Owner).GameReplicationInfo).bSlowTime)
    {
    	DrawBlackStuff(Canvas);
    	DrawKillCamTile(Canvas);
   }
}

simulated function DrawBlackStuff(canvas Canvas)
{
	Canvas.DrawColor = WhiteColor;
	Canvas.Style = ERenderStyle.STY_Modulated;

	Canvas.SetPos(0, 0);
	Canvas.DrawTile(Texture'BlackStuff', Canvas.ClipX, 160*Scale, 0, 0, 16, 64);
	Canvas.SetPos(0, Canvas.ClipY - (160*Scale));
	Canvas.DrawTile(Texture'BlackStuff2', Canvas.ClipX, 160*Scale, 0, 0, 16, 64);

	Canvas.Style = ERenderStyle.STY_Translucent;
}

simulated function DrawKillCamTile(Canvas Canvas)
{
   local float XL, YL, DrawScale;

	Canvas.Style = ERenderStyle.STY_Translucent;

	XL = Canvas.ClipX * 0.5;
	YL = Canvas.ClipY * 0.7;

	if (Canvas.ClipX < 1024)
		DrawScale = Canvas.ClipX / 1024;
	else
		DrawScale = 1;

	Canvas.SetPos(XL - (DrawScale * 256) , YL - (DrawScale * 64));
	Canvas.DrawTile(Texture'KillCamTile', DrawScale * 512, DrawScale * 128, 0, 0,512,128);

   XL = Canvas.ClipX * 0.5;
	YL = Canvas.ClipY * 0.8;
	if (Canvas.ClipX < 1024)
		DrawScale = Canvas.ClipX / 1024;
	else
		DrawScale = 0.6;

	Canvas.SetPos(XL - (DrawScale * 256) , YL - (DrawScale * 64));
}

defaultproperties
{
	SpreadString="Alive:"
	WhiteColor=(R=255,G=255,B=255)
}
