D:\cygwin\wf_fusion_src_r8\CVSROOT\WeaponsFactory\cg_hud_milli.c

/*
==============================================================================
The Weapons Factory - 
  
Modified code by Keith Pase

Copyright (C) 1997-2003 Weapons Factory Software

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


  cg_hud_milli.c -- MilliHud
  

==============================================================================
*/


#include "..\cgame\cg_local.h"

#define DISPLAY_ITEMS   17

char *typeofammo[6] = 
{
    "Bullets",
    "Shells",
    "Grenades",
    "Rockets",
    "Slugs",
    "Cells"
};

vec4_t ammocolor[6] =
{
    {1, 1, 0, .33},
    {1, .5, 0, .33},
    {.1, .6, .2, .33},
    {1, 0, 0, .33},
    {0, 1, 0, .33},
    {1, 0, .9, .33}
};


void SCR_DrawMiliInventory (int x, int y)
{
    int     i;
    char    string[16];
    int     count;
    float   width;
    float   count2;
    vec4_t  color, color2;

    for (i= 0; i<6; i++)
    {
        count = cg.frame.playerState.ammo[i];
        if (count <= 0) continue;
        count2= cg.frame.playerState.ammo[i+6];
        Vector4Copy (ammocolor[i], color2);
        if (count > 999) count = 999;
        if (count != cg.ammo[i]) color2[3] = .66;
        if (count < cg.ammo[i]) cg.ammo[i]--;
        if (count > cg.ammo[i]) cg.ammo[i]++;
        width = (cg.ammo[i]/count2) * 80;
        if (width < 8)
            Vector4Copy (colorRed,color);
        else if (width < 20)
            Vector4Copy (colorYellow,color);
        else
            Vector4Copy (colorWhite,color);
        trap_Draw_FillRect (x+48, y+1, width, 8, color2);
        Com_sprintf (string, sizeof(string), "%3i",cg.ammo[i]);
        CG_DrawString ( x+12, y, string, FONT_SMALL|FONT_SHADOWED, color );
        trap_Draw_StretchPic ( x, y, 10, 10, 0, 0, 1, 1, colorWhite, CG_MediaShader(cgs.media.AmNums[i])  );
        CG_DrawString ( x+48, y, typeofammo[i], FONT_SMALL|FONT_SHADOWED, color );
        y=y+8;
    }
}

void SCR_DrawHealthBar (int x, int y)
{
    int w, h;
    float value,value2,value3;
    float r;
    float g;
    vec4_t color;
    int nw, nx;
    int armortype;
    char block[3];
    float armor, health;

    w = 79;
    h = 14;

    value = cg.frame.playerState.stats[STAT_HEALTH];
    value2 = cg.frame.playerState.stats[STAT_CHASE];
    value3 = cg.frame.playerState.stats[STAT_ARMOR];
    armortype = cg.frame.playerState.stats[STAT_SPECTATOR];
    armor = cg.armor;
    health = cg.health;

    if (value > health)
        cg.health ++;
    else if (value < health)
        cg.health --;

    if (value3 > armor)
        cg.armor ++;
    else if (value3 < armor)
        cg.armor --;

    if (health < 0) health = 0;

    r = 1 - (health / 100);
    g = (health / 100);

    if (value < 66) r = r*2;
    if (health > 33) g = g*2;

    color[0] = r;
    color[1] = g;
    color[2] = 0;
    color[3] = .33;

    trap_Draw_FillRect (x, y, w, h, color);
    nw = (79*(health / 100));
    nx = x + (w - nw);
    color[3] = .75;
    trap_Draw_FillRect (nx, y+3, nw, h-6, color);
    sprintf ( block, "%.0f", health);

    CG_DrawString ( x+w-60, y-12, "Health", FONT_SMALL|FONT_SHADOWED, colorWhite );
    CG_DrawString ( x+w-24, y+2, block, FONT_SMALL|FONT_SHADOWED, colorWhite );

    nw = (armor/value2) * w;

    color[0] = color[1] = color[2] = 0;

    if (armortype == 1)
        color[0] = 1;
    else if (armortype == 2)
    {
        color[0] = 1;
        color[1] = 1;
    }
    else if (armortype == 3)
        color[1] = .7;
    else
    {
        color[0] = 0;
        color[1] = 0;
        color[2] = 0;
    }

    color[3] = .33;
    trap_Draw_FillRect (x+w, y, w, h, color);
    color[3] = .75;
    trap_Draw_FillRect (x+w, y+3, nw, h-6, color);

    sprintf ( block, "%.0f", armor);
    CG_DrawString ( x+w+20, y-12, "Armor", FONT_SMALL|FONT_SHADOWED, colorWhite );
    CG_DrawString ( x+w, y+2, block, FONT_SMALL|FONT_SHADOWED, colorWhite );

}

void SCR_DrawHudMilli (void)
{
    vec4_t DEFAULT_HUD_BORDERCOLOR = {1,1,1,.75};
    vec4_t bordercolor2 = {1, .5, .5, .75};
    vec4_t blueborder = {0, 0, 1, .75};
    vec4_t blueback = {0, 0, 1, .33};
    vec4_t redborder = {1, 0, 0, .75};
    vec4_t redback = {1, 0, 0, .33};
    vec4_t shaded = {0, 0, 0, .33};
    int borderwidth = 1;
    int y = cgs.vidHeight - 480;
    int x = (scr_vrect.x + ((scr_vrect.width)>>1)) - 320;
    int y2 = y + 460;
    int ctfflagpic = cg.frame.playerState.stats[STAT_CTF_FLAG_PIC];
    char block[3];
    int team1 = cg.frame.playerState.stats[STAT_CTF_JOINED_TEAM1_PIC];
    int team2 = cg.frame.playerState.stats[STAT_CTF_JOINED_TEAM2_PIC];

//  trap_Draw_FillRect (0, 432, 128, 48, DEFAULT_HUD_BORDERCOLOR);

//  trap_Draw_Border (0, 334, 172, 98, DEFAULT_HUD_BORDERCOLOR, borderwidth); // teaminfo

    // playerSelect
    trap_Draw_Border (192+x, y2, 32, 20, DEFAULT_HUD_BORDERCOLOR, borderwidth); 
    

    // drug + disguise
    trap_Draw_Border (384+x, 440+y, 128, 20, DEFAULT_HUD_BORDERCOLOR, borderwidth); 
//  trap_Draw_FillRect (384+x, 440+y, 128, 20, shaded);


    trap_Draw_Border (128+x, y2, 32, 20, DEFAULT_HUD_BORDERCOLOR, borderwidth); // health
    trap_Draw_Border (160+x, y2, 32, 20, DEFAULT_HUD_BORDERCOLOR, borderwidth); // armor

     // Flag Indicator

    if (ctfflagpic)
    {
        trap_Draw_StretchPic ( 512+x, 432+y, 128, 48, 0, 0, 1, 1, shaded, trap_R_RegisterPic("hudalert2") );
        trap_Draw_StretchPic ( x, 432+y, 128, 48, 0, 0, 1, 1, shaded, trap_R_RegisterPic("hudalert2") );
        if (ctfflagpic == 2)
        {
            trap_Draw_StretchPic ( 512+x, 432+y, 64, 48, 0, 0, 1, 1, colorBlue, trap_R_RegisterPic("flagcapture") );
        }
        else
        {
            trap_Draw_StretchPic ( 576+x, 432+y, 64, 48, 0, 0, 1, 1, colorRed, trap_R_RegisterPic("flagcapture") );
        }
    }

    trap_Draw_Border (512+x, 432+y, 128, 48, DEFAULT_HUD_BORDERCOLOR, borderwidth); 


    // ammo
    trap_Draw_Border (x, 432+y, 128, 48, DEFAULT_HUD_BORDERCOLOR, borderwidth); 
    SCR_DrawMiliInventory (x, 432+y);


     // miniscore
//  trap_Draw_FillRect (128, 440, 80, 20, shaded);
//  trap_Draw_FillRect (152, 440, 26, 9, redback);
//  trap_Draw_FillRect (152, 449, 26, 9, blueback);
//  trap_Draw_Border (128, 440, 80, 20, DEFAULT_HUD_BORDERCOLOR, borderwidth);

     // redteamscore
    trap_Draw_FillRect (480+x, y2, 32, 20, redback);
    if (team1)
        trap_Draw_StretchPic ( 480+x, y2, 32, 20, 0, 0, 1, 1, colorRed, trap_R_RegisterPic("flaginbase") );
    trap_Draw_Border (480+x, y2, 32, 20, redborder, borderwidth);
    sprintf ( block, "%i", cg.frame.playerState.stats[STAT_CTF_TEAM1_CAPS]);
    CG_DrawString ( 492+x, y2+8, block, FONT_SMALL|FONT_SHADOWED, colorWhite );
    
     // blueteamscore
    trap_Draw_FillRect (416+x, y2, 32, 20, blueback);
    if (team2)
        trap_Draw_StretchPic ( 416+x, y2, 32, 20, 0, 0, 1, 1, colorBlue, trap_R_RegisterPic("flaginbase") );
    trap_Draw_Border (416+x, y2, 32, 20, blueborder, borderwidth);
    sprintf ( block, "%i", cg.frame.playerState.stats[STAT_CTF_TEAM2_CAPS]);
    CG_DrawString ( 428+x, y2+8, block, FONT_SMALL|FONT_SHADOWED, colorWhite );

    // personalscore
    trap_Draw_FillRect (385+x, y2+1, 30, 18, shaded);
    trap_Draw_Border (384+x, y2, 32, 20, bordercolor2, borderwidth);
    sprintf ( block, "%i", cg.frame.playerState.stats[STAT_FRAGS]);
    CG_DrawString ( 386+x, y2+8, block, FONT_SMALL|FONT_SHADOWED, colorWhite );

     // healthbars
    trap_Draw_FillRect (225+x, y2+1, 158, 18, shaded);
    SCR_DrawHealthBar(225+x, y2+3);
    trap_Draw_Border (224+x, y2, 160, 20, DEFAULT_HUD_BORDERCOLOR, borderwidth);

}