diff options
Diffstat (limited to 'src/cgame')
-rw-r--r-- | src/cgame/cg_draw.c | 139 | ||||
-rw-r--r-- | src/cgame/cg_drawtools.c | 27 | ||||
-rw-r--r-- | src/cgame/cg_local.h | 16 | ||||
-rw-r--r-- | src/cgame/cg_main.c | 9 | ||||
-rw-r--r-- | src/cgame/cg_servercmds.c | 19 |
5 files changed, 183 insertions, 27 deletions
diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c index 18427b8a..2b74a3f9 100644 --- a/src/cgame/cg_draw.c +++ b/src/cgame/cg_draw.c @@ -30,11 +30,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA menuDef_t *menuScoreboard = NULL; -int drawTeamOverlayModificationCount = -1; - -int sortedTeamPlayers[ TEAM_MAXOVERLAY ]; -int numSortedTeamPlayers; - static void CG_AlignText( rectDef_t *rect, const char *text, float scale, float w, float h, int align, int valign, @@ -1622,6 +1617,123 @@ static void CG_DrawTimer( rectDef_t *rect, float text_x, float text_y, /* ================= +CG_DrawTeamOverlay +================= +*/ + +static void CG_DrawTeamOverlay( rectDef_t *rect, float scale, vec4_t color ) +{ + char *s; + int i; + float x = rect->x; + float y, dx; + clientInfo_t *ci, *pci; + vec4_t tcolor; + float iconSize = rect->h/8.0f; + float leftMargin = 4.0f; + float iconTopMargin = 2.0f; + float midSep = 2.0f; + float backgroundWidth = rect->w; + float fontScale = 0.30f; + int maxDisplayCount = 0; + int displayCount = 0; + weapon_t curWeapon = WP_NONE; + + if( cg.predictedPlayerState.pm_type == PM_SPECTATOR ) + return; + + if( !cg_drawTeamOverlay.integer || !cg_teamOverlayMaxPlayers.integer ) + return; + + if( !cgs.teaminfoReceievedTime ) return; + + pci = cgs.clientinfo + cg.snap->ps.clientNum; + + + for( i = 0; i < MAX_CLIENTS; i++ ) + { + ci = cgs.clientinfo + i; + if( ci->infoValid && pci != ci && ci->team == pci->team) + maxDisplayCount++; + } + + if( maxDisplayCount > cg_teamOverlayMaxPlayers.integer ) + maxDisplayCount = cg_teamOverlayMaxPlayers.integer; + + iconSize *= scale; + leftMargin *= scale; + iconTopMargin *= scale; + midSep *= scale; + backgroundWidth *= scale; + fontScale *= scale; + + y = rect->y - (float) maxDisplayCount * ( iconSize / 2.0f ); + + tcolor[ 0 ] = 1.0f; + tcolor[ 1 ] = 1.0f; + tcolor[ 2 ] = 1.0f; + tcolor[ 3 ] = color[ 3 ]; + + for( i = 0; i < MAX_CLIENTS && displayCount < maxDisplayCount; i++ ) + { + ci = cgs.clientinfo + i; + + if( !ci->infoValid || pci == ci || ci->team != pci->team ) + continue; + + dx = 0.f; + trap_R_SetColor( color ); + CG_DrawPic( x, y-iconSize+iconTopMargin, backgroundWidth, + iconSize, cgs.media.teamOverlayShader ); + trap_R_SetColor( tcolor ); + if( ci->health <= 0 || !ci->curWeaponClass ) + { + dx = -iconSize; + s = va( "%s^7", ci->name ); + } + else + { + if( ci->team == TEAM_HUMANS ) + curWeapon = ci->curWeaponClass; + else if( ci->team == TEAM_ALIENS ) + curWeapon = BG_Class( ci->curWeaponClass )->startWeapon; + + CG_DrawPic( x+leftMargin, y-iconSize+iconTopMargin, iconSize, iconSize, + cg_weapons[ curWeapon ].weaponIcon ); + if( cg.predictedPlayerState.stats[ STAT_TEAM ] == TEAM_HUMANS ) + { + if( ci->upgrade != UP_NONE ) + { + CG_DrawPic( x+iconSize+leftMargin, y-iconSize+iconTopMargin, + iconSize, iconSize, cg_upgrades[ ci->upgrade ].upgradeIcon ); + dx = iconSize; + } + } + else + { + if( curWeapon == WP_ABUILD2 || curWeapon == WP_ALEVEL1_UPG || + curWeapon == WP_ALEVEL2_UPG || curWeapon == WP_ALEVEL3_UPG ) + { + CG_DrawPic( x+iconSize+leftMargin, y-iconSize+iconTopMargin, + iconSize, iconSize, cgs.media.upgradeClassIconShader ); + dx = iconSize; + } + } + s = va( "%s^7 [^%c%d^7] ^7%s", ci->name, + CG_GetColorCharForHealth( i ), + ci->health, + CG_ConfigString( CS_LOCATIONS + ci->location ) ); + } + trap_R_SetColor( NULL ); + UI_Text_Paint( x+iconSize+leftMargin+midSep+dx, y, fontScale, tcolor, s, + 0, 0, ITEM_TEXTSTYLE_NORMAL ); + y += iconSize; + displayCount++; + } +} + +/* +================= CG_DrawClock ================= */ @@ -2244,10 +2356,20 @@ static void CG_DrawCrosshairNames( rectDef_t *rect, float scale, int textStyle ) return; } + // add health from overlay info to the crosshair client name name = cgs.clientinfo[ cg.crosshairClientNum ].name; + if( cg_teamOverlayUserinfo.integer && + cg.snap->ps.stats[ STAT_TEAM ] != TEAM_NONE && + cgs.teaminfoReceievedTime ) + { + name = va( "%s ^7[^%c%d^7]", name, + CG_GetColorCharForHealth( cg.crosshairClientNum ), + cgs.clientinfo[ cg.crosshairClientNum ].health ); + } + w = UI_Text_Width( name, scale, 0 ); - x = rect->x + rect->w / 2; - UI_Text_Paint( x - w / 2, rect->y + rect->h, scale, color, name, 0, 0, textStyle ); + x = rect->x + rect->w / 2.0f; + UI_Text_Paint( x - w / 2.0f, rect->y + rect->h, scale, color, name, 0, 0, textStyle ); trap_R_SetColor( NULL ); } @@ -2440,6 +2562,9 @@ void CG_OwnerDraw( float x, float y, float w, float h, float text_x, case CG_LAGOMETER: CG_DrawLagometer( &rect, text_x, text_y, scale, foreColor ); break; + case CG_TEAMOVERLAY: + CG_DrawTeamOverlay( &rect, scale, foreColor ); + break; case CG_DEMO_PLAYBACK: CG_DrawDemoPlayback( &rect, foreColor, shader ); diff --git a/src/cgame/cg_drawtools.c b/src/cgame/cg_drawtools.c index 7d32fa1d..17eb7ac6 100644 --- a/src/cgame/cg_drawtools.c +++ b/src/cgame/cg_drawtools.c @@ -403,3 +403,30 @@ char *CG_KeyBinding( const char *bind ) } return key; } + +/* +================= +CG_GetColorCharForHealth +================= +*/ +char CG_GetColorCharForHealth( int clientnum ) +{ + char health_char = '2'; + int healthPercent; + int maxHealth; + int curWeaponClass = cgs.clientinfo[ clientnum ].curWeaponClass; + + if( cgs.clientinfo[ clientnum ].team == TEAM_ALIENS ) + maxHealth = BG_Class( curWeaponClass )->health; + else + maxHealth = BG_Class( PCL_HUMAN )->health; + + healthPercent = (int) ( 100.0f * (float) cgs.clientinfo[ clientnum ].health + / (float) maxHealth ); + + if( healthPercent < 33 ) + health_char = '1'; + else if( healthPercent < 67 ) + health_char = '3'; + return health_char; +} diff --git a/src/cgame/cg_local.h b/src/cgame/cg_local.h index d14454a1..7302ac78 100644 --- a/src/cgame/cg_local.h +++ b/src/cgame/cg_local.h @@ -730,8 +730,8 @@ typedef struct int score; // updated by score servercmds int location; // location index for team mode int health; // you only get this info about your teammates - int armor; - int curWeapon; + int upgrade; + int curWeaponClass; // sends current weapon for H, current class for A int handicap; @@ -1188,6 +1188,7 @@ typedef struct qhandle_t scannerBlipShader; qhandle_t scannerLineShader; + qhandle_t teamOverlayShader; qhandle_t numberShaders[ 11 ]; @@ -1384,6 +1385,8 @@ typedef struct clientInfo_t clientinfo[ MAX_CLIENTS ]; + int teaminfoReceievedTime; + // corpse info clientInfo_t corpseinfo[ MAX_CLIENTS ]; @@ -1440,6 +1443,9 @@ extern vmCvar_t cg_drawChargeBar; extern vmCvar_t cg_drawCrosshair; extern vmCvar_t cg_drawCrosshairNames; extern vmCvar_t cg_crosshairSize; +extern vmCvar_t cg_drawTeamOverlay; +extern vmCvar_t cg_teamOverlayMaxPlayers; +extern vmCvar_t cg_teamOverlayUserinfo; extern vmCvar_t cg_draw2D; extern vmCvar_t cg_animSpeed; extern vmCvar_t cg_debugAnim; @@ -1596,20 +1602,16 @@ int CG_DrawStrlen( const char *str ); float *CG_FadeColor( int startMsec, int totalMsec ); void CG_TileClear( void ); void CG_ColorForHealth( vec4_t hcolor ); -void CG_GetColorForHealth( int health, int armor, vec4_t hcolor ); - void CG_DrawRect( float x, float y, float width, float height, float size, const float *color ); void CG_DrawSides(float x, float y, float w, float h, float size); void CG_DrawTopBottom(float x, float y, float w, float h, float size); qboolean CG_WorldToScreen( vec3_t point, float *x, float *y ); char *CG_KeyBinding( const char *bind ); - +char CG_GetColorCharForHealth( int clientnum ); // // cg_draw.c // -extern int sortedTeamPlayers[ TEAM_MAXOVERLAY ]; -extern int numSortedTeamPlayers; void CG_AddLagometerFrameInfo( void ); void CG_AddLagometerSnapshotInfo( snapshot_t *snap ); diff --git a/src/cgame/cg_main.c b/src/cgame/cg_main.c index 89082cee..bd3acec5 100644 --- a/src/cgame/cg_main.c +++ b/src/cgame/cg_main.c @@ -153,8 +153,10 @@ vmCvar_t cg_synchronousClients; vmCvar_t cg_stats; vmCvar_t cg_paused; vmCvar_t cg_blood; -vmCvar_t cg_teamOverlayUserinfo; vmCvar_t cg_teamChatsOnly; +vmCvar_t cg_drawTeamOverlay; +vmCvar_t cg_teamOverlayMaxPlayers; +vmCvar_t cg_teamOverlayUserinfo; vmCvar_t cg_noPrintDuplicate; vmCvar_t cg_noVoiceChats; vmCvar_t cg_noVoiceText; @@ -270,6 +272,8 @@ static cvarTable_t cvarTable[ ] = { &cg_thirdPersonPitchFollow, "cg_thirdPersonPitchFollow", "0", 0 }, { &cg_thirdPersonShoulderViewMode, "cg_thirdPersonShoulderViewMode", "1", CVAR_ARCHIVE }, { &cg_stats, "cg_stats", "0", 0 }, + { &cg_drawTeamOverlay, "cg_drawTeamOverlay", "1", CVAR_ARCHIVE }, + { &cg_teamOverlayMaxPlayers, "cg_teamOverlayMaxPlayers", "8", CVAR_ARCHIVE }, { &cg_teamOverlayUserinfo, "teamoverlay", "1", CVAR_ARCHIVE|CVAR_USERINFO }, { &cg_teamChatsOnly, "cg_teamChatsOnly", "0", CVAR_ARCHIVE }, { &cg_noPrintDuplicate, "cg_noPrintDuplicate", "0", CVAR_ARCHIVE }, @@ -428,6 +432,7 @@ void CG_UpdateCvars( void ) // check for modications here CG_SetUIVars( ); + } @@ -747,6 +752,8 @@ static void CG_RegisterGraphics( void ) cgs.media.scannerBlipShader = trap_R_RegisterShader( "gfx/2d/blip" ); cgs.media.scannerLineShader = trap_R_RegisterShader( "gfx/2d/stalk" ); + cgs.media.teamOverlayShader = trap_R_RegisterShader( "gfx/2d/teamoverlay" ); + cgs.media.tracerShader = trap_R_RegisterShader( "gfx/misc/tracer" ); cgs.media.backTileShader = trap_R_RegisterShader( "console" ); diff --git a/src/cgame/cg_servercmds.c b/src/cgame/cg_servercmds.c index 4c462fe6..cd590c40 100644 --- a/src/cgame/cg_servercmds.c +++ b/src/cgame/cg_servercmds.c @@ -79,17 +79,14 @@ CG_ParseTeamInfo static void CG_ParseTeamInfo( void ) { int i; + int count; int client; - numSortedTeamPlayers = atoi( CG_Argv( 1 ) ); - if( numSortedTeamPlayers < 0 || numSortedTeamPlayers > TEAM_MAXOVERLAY ) - { - CG_Error( "CG_ParseTeamInfo: numSortedTeamPlayers out of range (%d)", - numSortedTeamPlayers ); - return; - } + count = atoi( CG_Argv( 1 ) ); - for( i = 0; i < numSortedTeamPlayers; i++ ) + cgs.teaminfoReceievedTime = cg.time; + + for( i = 0; i < count; i++ ) { client = atoi( CG_Argv( i * 5 + 2 ) ); if( client < 0 || client >= MAX_CLIENTS ) @@ -98,12 +95,10 @@ static void CG_ParseTeamInfo( void ) return; } - sortedTeamPlayers[ i ] = client; - cgs.clientinfo[ client ].location = atoi( CG_Argv( i * 5 + 3 ) ); cgs.clientinfo[ client ].health = atoi( CG_Argv( i * 5 + 4 ) ); - cgs.clientinfo[ client ].armor = atoi( CG_Argv( i * 5 + 5 ) ); - cgs.clientinfo[ client ].curWeapon = atoi( CG_Argv( i * 5 + 6 ) ); + cgs.clientinfo[ client ].curWeaponClass = atoi( CG_Argv( i * 5 + 5 ) ); + cgs.clientinfo[ client ].upgrade = atoi( CG_Argv( i * 5 + 6 ) ); } } |