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

void SCR_DrawWeaponDamage (int x, int y)
{
    char    string[16];
    int     damage =  cg.frame.playerState.stats[STAT_DAMAGE];
    int     value = cg.frame.playerState.stats[STAT_SELECTED_ICON];

    if (damage < 1)
    {
        cg.weapondamage = 0;
        return;
    }

    if ((damage > cg.weapondamage + 2) && cg.normalfps > 1)
        cg.weapondamage += 2*cg.normalfps;
    else if (damage > cg.weapondamage)
        cg.weapondamage ++;
    if ((damage < cg.weapondamage + 2) && cg.normalfps > 1)
        cg.weapondamage -= 2*cg.normalfps;
    else if (damage < cg.weapondamage)
        cg.weapondamage --;

    Com_sprintf (string, sizeof(string), "Damage:%3i",cg.weapondamage);
    CG_DrawString ( x+40, y, string, FONT_SMALL, colorWhite );

    if ( cgs.configStrings[CS_IMAGES+value] )
        trap_Draw_StretchPic (x-6, y-4, 18, 18, 0, 0, 1, 1, colorWhite, trap_R_RegisterPic(cgs.configStrings[CS_IMAGES+value]) );
}

void SCR_DrawWeaponAccuracy (int x, int y)
{
    char    string[8];
    int     accuracy = cg.frame.playerState.persistant[PERS_ACCURACY];

//  Com_Printf("DEBUG: accuracy %i\n",accuracy);
    CG_DrawString ( x+4, y, "Acc", FONT_SMALL, colorWhite );
    Com_sprintf (string, sizeof(string), "%3i",accuracy);
    CG_DrawString ( x, y+8, string, FONT_SMALL, colorWhite );
}


void SCR_DrawMiliSrCharge (int x, int y)
{
    int     damage =  cg.frame.playerState.stats[STAT_FLASHES];
    char    string[8];
    vec4_t  color = {1,1,0,.2};
    float   damage2;
    vec4_t  color2 = {1,1,1,.2};
    int     charlength;

    if (damage < 1)
        return;

    if (damage == 1)
        damage = 0;

    if (damage > cg.damage  && damage == 110)
        cg.damage = 110;

    if ((damage > cg.damage + 2) && cg.normalfps > 1)
        cg.damage += 2*cg.normalfps;
    else if (damage > cg.damage)
        cg.damage ++;
    if (damage < cg.damage)
        cg.damage = damage;

    if (damage > 0)
    {
        damage2 = cg.damage;
        color[0]    = damage2/160;
        color[1]    = 1-(damage2/160);
        color[3]    +=damage2/160;
        color2[3]   = color[3];
        trap_Draw_FillRect (608+x, (400+y)-cg.damage, 16, cg.damage, color);
    }

    Com_sprintf (string, sizeof(string), "%i",cg.damage);
    charlength = strlen(string) * 4;
    CG_DrawString ( x+618-charlength, y+410, string, FONT_SMALL, color2 );
    CG_DrawString ( x+592, y+400, "Damage", FONT_SMALL, color2 );

    trap_Draw_Border (608+x, 238+y, 16, 162, color2, 1);
}


void SCR_DrawMilliCompass(void)
{
    int pitch,roll,dist,mode;

    mode    = cg.frame.playerState.persistant[PERS_COMPASS] >> 1;
    pitch   = cg.frame.playerState.persistant[PERS_COMPASS] >> 2;
    roll    = cg.frame.playerState.persistant[PERS_COMPASS] >> 4;
    dist    = cg.frame.playerState.persistant[PERS_COMPASS] >> 8;

    Com_Printf("DEBUG: dist:%i\n",dist);
}

void SCR_DrawMiliTimer (int x, int y)
{
    int     seconds = cg.frame.playerState.stats[STAT_TIMER];
    int     minutes;
    char    string[8];
    vec4_t  color = {1,1,1,1};

    if (seconds < 0)
        return;

    minutes = seconds/60;
    if (minutes < 0)
        minutes = 0;
    if (minutes > 999)
        minutes = 999;

    if (minutes < 5)
        Vector4Copy(colorYellow,color);
    if (minutes < 1)
        Vector4Copy(colorRed,color);

    seconds = seconds%60;

    if (seconds < 10)
        Com_sprintf (string, sizeof(string), "%3i:0%i",minutes,seconds);
    else
        Com_sprintf (string, sizeof(string), "%3i:%i",minutes,seconds);

    color[3] = .6;

    CG_DrawString ( x+534, y+26, string, FONT_BIG, color );

}


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_DrawMiliId (void)
{
    vec4_t  color;
    cg_clientInfo_t *ci;
    int i = cg.frame.playerState.stats[STAT_CTF_ID_VIEW];
    char string1[32];
    int lastsighted; 
    int x;
    int y = (cgs.vidHeight / 2) + 24;

    Vector4Copy (colorWhite,color);

    if (!cg.lastsighted)
    {
        if (!i)
            return;
        else
        {
            cg.lastsighted = i;
            cg.lastsighttime = 1;
        }
    }

    if (!i)
    {
        cg.lastsighttime -= .05;
        color[3] = cg.lastsighttime;
        if (color[3] <=0)
        {
            cg.lastsighted = 0;
            return;
        }
    }


    lastsighted = cg.lastsighted;
//
    Com_sprintf (string1, sizeof(string1), "%s",cgs.configStrings[lastsighted]);
    x = (cgs.vidWidth - CG_PropStringLength (string1, FONT_SMALL|FONT_SHADOWED)) / 1.8;
    CG_DrawString ( x, y, string1, FONT_SMALL|FONT_SHADOWED, color );

    if (i)
    {
        ci = &cgs.clientInfo[i];
    }
}


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,i;
    float value,value2,value3,barvalue;
    float r;
    float g;
    vec4_t color;
    int nw,nx,nwh,nxh;
    int armortype;
    char block[3];
    float armor,health,alpha,barhealth;

    w = 79;
    h = 20;

    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)
        if (value-health > 8)
            cg.health += ((value-health)/2);
        else
        cg.health ++;
    else if (value < health)
        if (health-value > 8)
            cg.health -= ((health-value)/2);
        else
            cg.health --;

    if (value3 > armor)
        if (value3-armor > 8)
            cg.armor += ((value3-armor)/2);
        else
            cg.armor ++;
    else if (value3 < armor)
        if (armor-value3 > 8)
            cg.armor -= ((armor-value3)/2);
        else
            cg.armor --;

    if (health < 0) health = 0;

    barhealth = health;
    barvalue = value;

    if (barvalue > 100)
        barvalue = 100;

    if (barhealth >100)
        barhealth = 100;

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

    if (value < 66) r = r*2;
    if (barhealth > 33) g = g*2;
    alpha = abs(value-cg.health) * .01;

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

    if (alpha > 0)
        for (i=0; i<4; i++)
            color[i] += alpha;

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

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

    nw = (armor/value2) * w;
    nwh= (value3/value2) * w;
    alpha = abs(value3-cg.armor) * .02;

    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;
    }

    if (alpha > 0)
        for (i=0; i<4; i++)
            color[i] += alpha;

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

    sprintf ( block, "%.0f", armor);
    CG_DrawString ( x+w+20, y-12, "Armor", FONT_SMALL|FONT_SHADOWED, colorWhite );
    CG_DrawString ( x+w, y+5, 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

    // accuracy
    trap_Draw_FillRect (192+x, y2, 32, 20, shaded);
    trap_Draw_Border (192+x, y2, 32, 20, DEFAULT_HUD_BORDERCOLOR, borderwidth); 
    SCR_DrawWeaponAccuracy(192+x,y2+2);
    

    // weapon/damage indicator
    trap_Draw_Border (384+x, 440+y, 128, 20, DEFAULT_HUD_BORDERCOLOR, borderwidth);
    SCR_DrawWeaponDamage(390+x,446+y);

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

    // headshots
//  trap_Draw_FillRect (160+x, y2, 32, 20, shaded);
    trap_Draw_Border (160+x, y2, 32, 20, DEFAULT_HUD_BORDERCOLOR, borderwidth);
    

     // 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") );
        }
    }

    // flag indicator
    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);
    trap_Draw_Border (224+x, y2, 160, 20, DEFAULT_HUD_BORDERCOLOR, borderwidth);

    SCR_DrawMiliId();
    SCR_DrawMiliTimer(x,y);
    SCR_DrawMiliSrCharge(x,y);
    SCR_DrawMilliCompass();
}