//=============================================================================
// ChallengeHUD.
//=============================================================================
class X_DOM_HUD expands ChallengeDominationHUD;

var color DarkRedColor;

simulated function DrawStatus(Canvas Canvas)
{
    local float StatScale, ChestAmount, ThighAmount, HelmetAmount, H1, H2, X, Y, DamageTime;
    Local int ArmorAmount,CurAbs,i;
    Local inventory Inv,BestArmor;
    local bool bChestArmor, bShieldbelt, bThighArmor, bJumpBoots, bHasDoll, bHasHelmet;
    local Bot BotOwner;
    local TournamentPlayer TPOwner;
    local texture Doll, DollBelt, HelmTex;
    local bool bBattleSuit;
	local string Temp;
	local byte InvCount;
	local texture CounterSlot[4];
	local Inventory InvSlot[4];
	local Inventory JBootsX, DoubleSX;

    ArmorAmount = 0;
    CurAbs = 0;
    i = 0;
    BestArmor=None;
    for( Inv=PawnOwner.Inventory; Inv!=None; Inv=Inv.Inventory )
    { 
        if (Inv.bIsAnArmor) 
        {
		if (Inv.IsA('BattleSuit'))
            {
		bBattleSuit = True;
            }
            else if ( Inv.IsA('UT_Shieldbelt') )
                bShieldbelt = true;
            else if ( Inv.IsA('Thighpads') )
            {
                ThighAmount += Inv.Charge;
                bThighArmor = true;
	    }
	    else if ( Inv.IsA('Helmet') )
            {
                HelmetAmount += Inv.Charge;
                bHasHelmet = true;
            }
            else
            { 
                bChestArmor = true;
                ChestAmount += Inv.Charge;
            }
            ArmorAmount += Inv.Charge;
        }
        else if ( Inv.IsA('UT_JumpBoots') )
            bJumpBoots = true;
        else
        {
            i++;
            if ( i > 100 )
                break; // can occasionally get temporary loops in netplay
        }
    }

    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;
            }
        }
        if ( bHasDoll )
        {                           
            Canvas.Style = ERenderStyle.STY_Translucent;
            StatScale = Scale * StatusScale;
            X = Canvas.ClipX - 128 * StatScale;
            Canvas.SetPos(X, 0);

		//-----------------------------------
		//Red UBerseker addon part
		//-----------------------------------
		Inv = PawnOwner.FindInventoryType(Class'UBerseker');
	    if (Inv != None)
		Canvas.DrawColor = DarkRedColor;
            else if (PawnOwner.DamageScaling > 2.0)
                Canvas.DrawColor = PurpleColor;
            else
                Canvas.DrawColor = HUDColor;

            Canvas.DrawTile(Doll, 128*StatScale, 256*StatScale, 0, 0, 128.0, 256.0);
            Canvas.DrawColor = HUDColor;

			if (Doll == Texture'BotPack.Icons.BossDoll')
			HelmTex = Texture'XPickups.Icons.BossDollNew';
		else if (Doll == Texture'BotPack.Icons.Woman')
			HelmTex = Texture'XPickups.Icons.WomanNew';
		else
			HelmTex = Texture'XPickups.Icons.ManNew';

            if (bBattleSuit)
            {
                Canvas.DrawColor = WhiteColor;
                Canvas.SetPos(X, 0);
                Canvas.DrawIcon(DollBelt, StatScale);
	    }
            else if ( bShieldBelt )
            {
                Canvas.DrawColor = BaseColor;
                Canvas.DrawColor.B = 0;
                Canvas.SetPos(X, 0);
                Canvas.DrawIcon(DollBelt, StatScale);
            }
            if ( bChestArmor )
            {
                Canvas.DrawColor = HUDColor;
                Canvas.SetPos(X, 0);
                Canvas.DrawTile(Doll, 128*StatScale, 64*StatScale, 128, 0, 128, 64);
            }
            if ( bThighArmor )
            {
                Canvas.DrawColor = HUDColor;
                Canvas.SetPos(X, 64*StatScale);
                Canvas.DrawTile(HelmTex, 128*StatScale, 64*StatScale, 128, 64, 128, 64);
            }

		//-----------------------------------
		//Helmet part
		//-----------------------------------
	    if ( bHasHelmet )
            {
                Canvas.DrawColor = HUDColor;
                Canvas.SetPos(X, 0);
                Canvas.DrawTile(HelmTex, 128*StatScale, 64*StatScale, 128, 0, 128, 64);
            }


            if ( bJumpBoots )
            {
                Canvas.DrawColor = HUDColor;
                Canvas.SetPos(X, 128*StatScale);
                Canvas.DrawTile(Doll, 128*StatScale, 64*StatScale, 128, 128, 128, 64);
            }


            Canvas.Style = Style;
            if ( (PawnOwner == PlayerOwner) && Level.bHighDetailMode && !Level.bDropDetail )
            {
                for ( i=0; i<4; i++ )
                {
                    DamageTime = Level.TimeSeconds - HitTime[i];
                    if ( DamageTime < 1 )
                    {
                        Canvas.SetPos(X + HitPos[i].X * StatScale, HitPos[i].Y * StatScale);
                        if ( (HUDColor.G > 100) || (HUDColor.B > 100) )
                            Canvas.DrawColor = RedColor;
                        else
                            Canvas.DrawColor = (WhiteColor - HudColor) * FMin(1, 2 * DamageTime);
                        Canvas.DrawColor.R = 255 * FMin(1, 2 * DamageTime);
                        Canvas.DrawTile(Texture'BotPack.HudElements1', StatScale * HitDamage[i] * 25, StatScale * HitDamage[i] * 64, 0, 64, 25.0, 64.0);
                    }
                }
            }
        }
    }
    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);

    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'BotPack.HudElements1', 128*Scale, 64*Scale, 0, 192, 128.0, 64.0);
    if ( bHideStatus && bShieldBelt )
        Canvas.DrawColor = GoldColor;
    else
        Canvas.DrawColor = WhiteColor;
    DrawBigNum(Canvas, Min(300,ArmorAmount), X + 4 * Scale, Y + 16 * Scale, 1);

///////////////////////////////////////////////////////////////////////////////////
//Counters
///////////////////////////////////////////////////////////////////////////////////
for( Inv=PawnOwner.Inventory; Inv!=None; Inv=Inv.Inventory )
{
	if (Inv.IsA('BattleSuit') || Inv.IsA('UBerseker') || Inv.IsA('UBersInvisibility') || Inv.IsA('UBersUDamage'))
		InvCount++;
}

if (PawnOwner.FindInventoryType(Class'BattleSuit') != None)
{
	CounterSlot[InvCount-1] = Texture'UBersInvulnIcon';
	InvSlot[InvCount-1] = PawnOwner.FindInventoryType(Class'BattleSuit');
}

if (PawnOwner.FindInventoryType(Class'UBerseker') != None)
{
	if (PawnOwner.FindInventoryType(Class'BattleSuit') == None)
	{
		CounterSlot[InvCount-1] = Texture'UBersBerzIcon';
		InvSlot[InvCount-1] = PawnOwner.FindInventoryType(Class'UBerseker');
	}
	else
	{
		CounterSlot[Max(InvCount-2,0)] = Texture'UBersBerzIcon';
		InvSlot[Max(InvCount-2,0)] = PawnOwner.FindInventoryType(Class'UBerseker');
	}
}

if (PawnOwner.FindInventoryType(Class'UBersInvisibility') != None)
{
	if (PawnOwner.FindInventoryType(Class'UBersUDamage') != None)
	{
		CounterSlot[1] = Texture'UBersInvisIcon';
		InvSlot[1] = PawnOwner.FindInventoryType(Class'UBersInvisibility');
	}
	else
	{
		CounterSlot[0] = Texture'UBersInvisIcon';
		InvSlot[0] = PawnOwner.FindInventoryType(Class'UBersInvisibility');
	}
}

if (PawnOwner.FindInventoryType(Class'UBersUDamage') != None)
{
	CounterSlot[0] = Texture'UBersUdamIcon';
	InvSlot[0] = PawnOwner.FindInventoryType(Class'UBersUDamage');
}


X = 0.02 * Canvas.ClipX;
Canvas.Font = Font'BotPack.LEDFont2';

if (Class'UBersDefault'.default.bOpaqueCounters)
	Canvas.Style = ERenderStyle.STY_Masked;
else
	Canvas.Style = ERenderStyle.STY_Translucent;

if (Class'UBersDefault'.default.bCountersCustomColor)
	Canvas.DrawColor = Class'UBersDefault'.default.CustomCountersColor;
else
	Canvas.DrawColor = HUDColor;


For(i=0; i<4; i++)
{
	if (CounterSlot[i] != None)
	{
		Y = (0.065 * (4 - i) + 0.45) * Canvas.ClipY;
		Canvas.SetPos(X, Y);
		Canvas.DrawIcon(CounterSlot[i], Scale/4);
		Y += 0.01 * Canvas.ClipY;
		X = 0.02 * Canvas.ClipX + 66 * Scale;
		Canvas.SetPos(X, Y);

		if (InvSlot[i].IsA('BattleSuit'))
			Temp = String(BattleSuit(InvSlot[i]).TimeActive);
		else
			Temp = String(InvSlot[i].Charge);

		//While(Len(Temp) < 2) Temp = "0"$Temp;
		Canvas.DrawText(Temp);
		X = 0.02 * Canvas.ClipX;
	}
}

//Jump Boots jumps counter
JBootsX = PawnOwner.FindInventoryType(Class'UBersJumpBoots');
if (JBootsX != None)
{
	X = 0.02 * Canvas.ClipX;
	Y = 0.775 * Canvas.ClipY;
	Canvas.SetPos(X, Y);
	Canvas.DrawIcon(Texture'UBersBootsIcon', Scale/4);
	Y += 0.01 * Canvas.ClipY;
	X = 0.02 * Canvas.ClipX + 66 * Scale;
	Canvas.SetPos(X, Y);
	Temp = String(JBootsX.Charge);
	Canvas.DrawText(Temp);
}

//Double Speed counter
DoubleSX = PawnOwner.FindInventoryType(Class'DoubleSpeed');
if (DoubleSX != None)
{
	X = 0.02 * Canvas.ClipX;
	Y = (0.065 * (4 - InvCount) + 0.45) * Canvas.ClipY;
	Canvas.SetPos(X, Y);
	Canvas.DrawIcon(Texture'UBersSpeedIcon', Scale/4);
	Y += 0.01 * Canvas.ClipY;
	X = 0.02 * Canvas.ClipX + 66 * Scale;
	Canvas.SetPos(X, Y);
	Temp = String(DoubleSX.Charge);
	Canvas.DrawText(Temp);
}
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////

}


defaultproperties
{
	DarkRedColor=(R=64,G=0,B=0)
}