2
0
mirror of https://github.com/FWGS/hlsdk-xash3d synced 2024-11-28 13:09:13 +01:00
hlsdk-xash3d/cl_dll/scoreboard.cpp

635 lines
17 KiB
C++
Raw Normal View History

2016-02-24 22:26:16 +01:00
/***
*
* Copyright (c) 1999, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
//
// Scoreboard.cpp
//
// implementation of CHudScoreboard class
//
#include "hud.h"
#include "cl_util.h"
#include "parsemsg.h"
#include "triangleapi.h"
#include <string.h>
#include <stdio.h>
2017-04-03 22:15:16 +02:00
cvar_t *cl_scoreboard_bg;
2016-02-24 22:26:16 +01:00
cvar_t *cl_showpacketloss;
#if USE_VGUI
#include "vgui_TeamFortressViewport.h"
#endif
2016-02-24 22:26:16 +01:00
2016-06-25 20:21:01 +02:00
DECLARE_COMMAND( m_Scoreboard, ShowScores )
DECLARE_COMMAND( m_Scoreboard, HideScores )
2016-02-24 22:26:16 +01:00
#if !USE_VGUI || USE_NOVGUI_SCOREBOARD
2016-06-25 20:21:01 +02:00
DECLARE_MESSAGE( m_Scoreboard, ScoreInfo )
DECLARE_MESSAGE( m_Scoreboard, TeamInfo )
DECLARE_MESSAGE( m_Scoreboard, TeamScore )
#endif
2016-02-24 22:26:16 +01:00
2016-07-03 15:39:55 +02:00
int CHudScoreboard::Init( void )
2016-02-24 22:26:16 +01:00
{
gHUD.AddHudElem( this );
// Hook messages & commands here
// HOOK_COMMAND( "+showscores", ShowScores );
// HOOK_COMMAND( "-showscores", HideScores );
2016-02-24 22:26:16 +01:00
#if !USE_VGUI || USE_NOVGUI_SCOREBOARD
2016-02-24 22:26:16 +01:00
HOOK_MESSAGE( ScoreInfo );
HOOK_MESSAGE( TeamScore );
HOOK_MESSAGE( TeamInfo );
#endif
2016-02-24 22:26:16 +01:00
InitHUDData();
2017-04-03 22:43:21 +02:00
cl_scoreboard_bg = CVAR_CREATE( "cl_scoreboard_bg", "1", FCVAR_ARCHIVE );
2016-02-24 22:26:16 +01:00
cl_showpacketloss = CVAR_CREATE( "cl_showpacketloss", "0", FCVAR_ARCHIVE );
return 1;
}
2016-07-03 15:39:55 +02:00
int CHudScoreboard::VidInit( void )
2016-02-24 22:26:16 +01:00
{
// Load sprites here
return 1;
}
2016-07-03 15:39:55 +02:00
void CHudScoreboard::InitHUDData( void )
2016-02-24 22:26:16 +01:00
{
memset( g_PlayerExtraInfo, 0, sizeof g_PlayerExtraInfo );
m_iLastKilledBy = 0;
m_fLastKillTime = 0;
m_iPlayerNum = 0;
m_iNumTeams = 0;
memset( g_TeamInfo, 0, sizeof g_TeamInfo );
m_iFlags &= ~HUD_ACTIVE; // starts out inactive
m_iFlags |= HUD_INTERMISSION; // is always drawn during an intermission
}
/* The scoreboard
We have a minimum width of 1-320 - we could have the field widths scale with it?
*/
// X positions
// relative to the side of the scoreboard
#define NAME_RANGE_MIN 20
#define NAME_RANGE_MAX 145
#define NAME_RANGE_MODIFIER 120
#define KILLS_RANGE_MIN 130
#define KILLS_RANGE_MAX 170
#define DIVIDER_POS 180
#define DEATHS_RANGE_MIN 185
#define DEATHS_RANGE_MAX 210
#define PING_RANGE_MIN 245
#define PING_RANGE_MAX 295
#define PL_RANGE_MIN 315
#define PL_RANGE_MAX 375
2016-02-24 22:26:16 +01:00
int SCOREBOARD_WIDTH = 320;
// Y positions
#define ROW_GAP (gHUD.m_scrinfo.iCharHeight)
2016-02-24 22:26:16 +01:00
#define ROW_RANGE_MIN 15
2016-08-01 19:11:01 +02:00
#define ROW_RANGE_MAX ( ScreenHeight - 50 )
2016-02-24 22:26:16 +01:00
2016-07-03 15:39:55 +02:00
int CHudScoreboard::Draw( float fTime )
2016-02-24 22:26:16 +01:00
{
2016-03-01 21:18:42 +01:00
int i, j, can_show_packetloss = 0;
2016-02-24 22:26:16 +01:00
int FAR_RIGHT;
gHUD.m_iNoConsolePrint &= ~( 1 << 0 );
2016-07-03 15:39:55 +02:00
if( !m_iShowscoresHeld && gHUD.m_Health.m_iHealth > 0 && !gHUD.m_iIntermission )
2016-02-24 22:26:16 +01:00
return 1;
gHUD.m_iNoConsolePrint |= 1 << 0;
GetAllPlayersInfo();
// Packetloss removed on Kelly 'shipping nazi' Bailey's orders
2016-07-03 15:39:55 +02:00
if( cl_showpacketloss && cl_showpacketloss->value && ( ScreenWidth >= 400 ) )
2016-02-24 22:26:16 +01:00
{
can_show_packetloss = 1;
SCOREBOARD_WIDTH = ( ScreenWidth >= 520 ) ? ( 400 - NAME_RANGE_MODIFIER ) : 400;
2016-02-24 22:26:16 +01:00
}
else
{
SCOREBOARD_WIDTH = ( ScreenWidth >= 440 ) ? ( 320 - NAME_RANGE_MODIFIER ) : 320;
2016-02-24 22:26:16 +01:00
}
// just sort the list on the fly
// list is sorted first by frags, then by deaths
float list_slot = 0;
2016-07-03 15:39:55 +02:00
int xpos_rel = ( ScreenWidth - SCOREBOARD_WIDTH ) / 2;
2016-02-24 22:26:16 +01:00
// print the heading line
2016-07-03 15:39:55 +02:00
int ypos = ROW_RANGE_MIN + ( list_slot * ROW_GAP );
int xpos = NAME_RANGE_MIN + xpos_rel;
2016-02-24 22:26:16 +01:00
FAR_RIGHT = can_show_packetloss ? PL_RANGE_MAX : PING_RANGE_MAX;
FAR_RIGHT += 5;
if( ( ScreenWidth >= 440 && !can_show_packetloss ) || ( ScreenWidth >= 520 && can_show_packetloss ) )
{
xpos -= NAME_RANGE_MODIFIER;
FAR_RIGHT += NAME_RANGE_MODIFIER;
}
2017-04-03 22:15:16 +02:00
if( cl_scoreboard_bg && cl_scoreboard_bg->value )
gHUD.DrawDarkRectangle( xpos - 5, ypos - 5, FAR_RIGHT, ROW_RANGE_MAX );
2016-07-03 15:39:55 +02:00
if( !gHUD.m_Teamplay )
2017-03-29 21:59:50 +02:00
DrawUtfString( xpos, ypos, NAME_RANGE_MAX + xpos_rel, "Player", 255, 140, 0 );
2016-02-24 22:26:16 +01:00
else
2017-03-29 21:59:50 +02:00
DrawUtfString( xpos, ypos, NAME_RANGE_MAX + xpos_rel, "Teams", 255, 140, 0 );
2016-02-24 22:26:16 +01:00
gHUD.DrawHudStringReverse( KILLS_RANGE_MAX + xpos_rel, ypos, 0, "kills", 255, 140, 0 );
2017-03-29 21:59:50 +02:00
DrawUtfString( DIVIDER_POS + xpos_rel, ypos, ScreenWidth, "/", 255, 140, 0 );
DrawUtfString( DEATHS_RANGE_MIN + xpos_rel + 5, ypos, ScreenWidth, "deaths", 255, 140, 0 );
DrawUtfString( PING_RANGE_MAX + xpos_rel - 35, ypos, ScreenWidth, "latency", 255, 140, 0 );
2016-02-24 22:26:16 +01:00
2016-07-03 15:39:55 +02:00
if( can_show_packetloss )
2016-02-24 22:26:16 +01:00
{
2017-03-29 21:59:50 +02:00
DrawUtfString( PL_RANGE_MAX + xpos_rel - 35, ypos, ScreenWidth, "pkt loss", 255, 140, 0 );
2016-02-24 22:26:16 +01:00
}
2019-10-13 14:12:41 +02:00
list_slot += 1.2f;
2016-07-03 15:39:55 +02:00
ypos = ROW_RANGE_MIN + ( list_slot * ROW_GAP );
// xpos = NAME_RANGE_MIN + xpos_rel;
2016-07-03 15:39:55 +02:00
FillRGBA( xpos - 4, ypos, FAR_RIGHT -2, 1, 255, 140, 0, 255 ); // draw the seperator line
2019-10-13 14:12:41 +02:00
list_slot += 0.8f;
2016-02-24 22:26:16 +01:00
2016-07-03 15:39:55 +02:00
if( !gHUD.m_Teamplay )
2016-02-24 22:26:16 +01:00
{
// it's not teamplay, so just draw a simple player list
DrawPlayers( xpos_rel, list_slot );
return 1;
}
// clear out team scores
2016-07-03 15:39:55 +02:00
for( i = 1; i <= m_iNumTeams; i++ )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
if( !g_TeamInfo[i].scores_overriden )
2016-02-24 22:26:16 +01:00
g_TeamInfo[i].frags = g_TeamInfo[i].deaths = 0;
g_TeamInfo[i].ping = g_TeamInfo[i].packetloss = 0;
}
// recalc the team scores, then draw them
2016-07-03 15:39:55 +02:00
for( i = 1; i < MAX_PLAYERS; i++ )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
//if( g_PlayerInfoList[i].name == NULL )
2016-02-24 22:26:16 +01:00
// continue; // empty player slot, skip
2016-07-03 15:39:55 +02:00
if( g_PlayerExtraInfo[i].teamname[0] == 0 )
2016-02-24 22:26:16 +01:00
continue; // skip over players who are not in a team
// find what team this player is in
2016-07-03 15:39:55 +02:00
for( j = 1; j <= m_iNumTeams; j++ )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
if( !stricmp( g_PlayerExtraInfo[i].teamname, g_TeamInfo[j].name ) )
2016-02-24 22:26:16 +01:00
break;
}
2016-07-03 15:39:55 +02:00
if( j > m_iNumTeams ) // player is not in a team, skip to the next guy
2016-02-24 22:26:16 +01:00
continue;
2016-07-03 15:39:55 +02:00
if( !g_TeamInfo[j].scores_overriden )
2016-02-24 22:26:16 +01:00
{
g_TeamInfo[j].frags += g_PlayerExtraInfo[i].frags;
g_TeamInfo[j].deaths += g_PlayerExtraInfo[i].deaths;
}
g_TeamInfo[j].ping += g_PlayerInfoList[i].ping;
g_TeamInfo[j].packetloss += g_PlayerInfoList[i].packetloss;
2016-07-03 15:39:55 +02:00
if( g_PlayerInfoList[i].thisplayer )
2016-02-24 22:26:16 +01:00
g_TeamInfo[j].ownteam = TRUE;
else
g_TeamInfo[j].ownteam = FALSE;
}
// find team ping/packetloss averages
2016-07-03 15:39:55 +02:00
for( i = 1; i <= m_iNumTeams; i++ )
2016-02-24 22:26:16 +01:00
{
g_TeamInfo[i].already_drawn = FALSE;
2016-07-03 15:39:55 +02:00
if( g_TeamInfo[i].players > 0 )
2016-02-24 22:26:16 +01:00
{
g_TeamInfo[i].ping /= g_TeamInfo[i].players; // use the average ping of all the players in the team as the teams ping
g_TeamInfo[i].packetloss /= g_TeamInfo[i].players; // use the average ping of all the players in the team as the teams ping
}
}
// Draw the teams
2016-07-03 15:39:55 +02:00
while( 1 )
2016-02-24 22:26:16 +01:00
{
int highest_frags = -99999; int lowest_deaths = 99999;
int best_team = 0;
2016-07-03 15:39:55 +02:00
for( i = 1; i <= m_iNumTeams; i++ )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
if( g_TeamInfo[i].players < 0 )
2016-02-24 22:26:16 +01:00
continue;
2016-07-03 15:39:55 +02:00
if( !g_TeamInfo[i].already_drawn && g_TeamInfo[i].frags >= highest_frags )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
if( g_TeamInfo[i].frags > highest_frags || g_TeamInfo[i].deaths < lowest_deaths )
2016-02-24 22:26:16 +01:00
{
best_team = i;
lowest_deaths = g_TeamInfo[i].deaths;
highest_frags = g_TeamInfo[i].frags;
}
}
}
// draw the best team on the scoreboard
2016-07-03 15:39:55 +02:00
if( !best_team )
2016-02-24 22:26:16 +01:00
break;
// draw out the best team
team_info_t *team_info = &g_TeamInfo[best_team];
2016-07-03 15:39:55 +02:00
ypos = ROW_RANGE_MIN + ( list_slot * ROW_GAP );
2016-02-24 22:26:16 +01:00
// check we haven't drawn too far down
2016-07-03 15:39:55 +02:00
if( ypos > ROW_RANGE_MAX ) // don't draw to close to the lower border
2016-02-24 22:26:16 +01:00
break;
xpos = NAME_RANGE_MIN + xpos_rel;
if( ( ScreenWidth >= 440 && !can_show_packetloss ) || ( ScreenWidth >= 520 && can_show_packetloss ) )
{
xpos -= NAME_RANGE_MODIFIER;
}
2016-02-24 22:26:16 +01:00
int r = 255, g = 225, b = 55; // draw the stuff kinda yellowish
2016-07-03 15:39:55 +02:00
if( team_info->ownteam ) // if it is their team, draw the background different color
2016-02-24 22:26:16 +01:00
{
// overlay the background in blue, then draw the score text over it
FillRGBA( xpos - 5, ypos, FAR_RIGHT, ROW_GAP, 0, 0, 255, 70 );
2016-02-24 22:26:16 +01:00
}
// draw their name (left to right)
2017-03-29 21:59:50 +02:00
DrawUtfString( xpos, ypos, NAME_RANGE_MAX + xpos_rel, team_info->name, r, g, b );
2016-02-24 22:26:16 +01:00
// draw kills (right to left)
xpos = KILLS_RANGE_MAX + xpos_rel;
gHUD.DrawHudNumberString( xpos, ypos, KILLS_RANGE_MIN + xpos_rel, team_info->frags, r, g, b );
// draw divider
xpos = DIVIDER_POS + xpos_rel;
2017-03-29 21:59:50 +02:00
DrawUtfString( xpos, ypos, xpos + 20, "/", r, g, b );
2016-02-24 22:26:16 +01:00
// draw deaths
xpos = DEATHS_RANGE_MAX + xpos_rel;
gHUD.DrawHudNumberString( xpos, ypos, DEATHS_RANGE_MIN + xpos_rel, team_info->deaths, r, g, b );
// draw ping
// draw ping & packetloss
static char buf[64];
sprintf( buf, "%d", team_info->ping );
2016-07-03 15:39:55 +02:00
xpos = ( ( PING_RANGE_MAX - PING_RANGE_MIN ) / 2) + PING_RANGE_MIN + xpos_rel + 25;
2016-02-24 22:26:16 +01:00
UnpackRGB( r, g, b, RGB_YELLOWISH );
gHUD.DrawHudStringReverse( xpos, ypos, xpos - 50, buf, r, g, b );
2016-07-03 15:39:55 +02:00
// Packetloss removed on Kelly 'shipping nazi' Bailey's orders
if( can_show_packetloss )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
xpos = ( ( PL_RANGE_MAX - PL_RANGE_MIN ) / 2) + PL_RANGE_MIN + xpos_rel + 25;
2016-02-24 22:26:16 +01:00
sprintf( buf, " %d", team_info->packetloss );
2017-03-29 21:59:50 +02:00
DrawUtfString( xpos, ypos, xpos+50, buf, r, g, b );
2016-02-24 22:26:16 +01:00
}
team_info->already_drawn = TRUE; // set the already_drawn to be TRUE, so this team won't get drawn again
list_slot++;
// draw all the players that belong to this team, indented slightly
list_slot = DrawPlayers( xpos_rel, list_slot, 10, team_info->name );
}
// draw all the players who are not in a team
2019-10-13 14:12:41 +02:00
list_slot += 0.5f;
2016-02-24 22:26:16 +01:00
DrawPlayers( xpos_rel, list_slot, 0, "" );
return 1;
}
2016-07-03 15:39:55 +02:00
2016-02-24 22:26:16 +01:00
extern float *GetClientColor( int client );
2016-07-03 15:39:55 +02:00
2016-02-24 22:26:16 +01:00
// returns the ypos where it finishes drawing
int CHudScoreboard::DrawPlayers( int xpos_rel, float list_slot, int nameoffset, const char *team )
2016-02-24 22:26:16 +01:00
{
int can_show_packetloss = 0;
int FAR_RIGHT;
// Packetloss removed on Kelly 'shipping nazi' Bailey's orders
2016-07-03 15:39:55 +02:00
if( cl_showpacketloss && cl_showpacketloss->value && ( ScreenWidth >= 400 ) )
2016-02-24 22:26:16 +01:00
{
can_show_packetloss = 1;
SCOREBOARD_WIDTH = 400;
}
else
{
SCOREBOARD_WIDTH = 320;
}
FAR_RIGHT = can_show_packetloss ? PL_RANGE_MAX : PING_RANGE_MAX;
FAR_RIGHT += 5;
if( ( ScreenWidth >= 440 && !can_show_packetloss ) || ( ScreenWidth >= 520 && can_show_packetloss ) )
{
FAR_RIGHT += NAME_RANGE_MODIFIER;
}
2016-02-24 22:26:16 +01:00
// draw the players, in order, and restricted to team if set
2016-07-03 15:39:55 +02:00
while( 1 )
2016-02-24 22:26:16 +01:00
{
// Find the top ranking player
2016-07-03 15:39:55 +02:00
int highest_frags = -99999;
int lowest_deaths = 99999;
2016-02-24 22:26:16 +01:00
int best_player = 0;
2016-07-03 15:39:55 +02:00
for( int i = 1; i < MAX_PLAYERS; i++ )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
if( g_PlayerInfoList[i].name && g_PlayerExtraInfo[i].frags >= highest_frags )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
if( !( team && stricmp( g_PlayerExtraInfo[i].teamname, team ) ) ) // make sure it is the specified team
2016-02-24 22:26:16 +01:00
{
extra_player_info_t *pl_info = &g_PlayerExtraInfo[i];
2016-07-03 15:39:55 +02:00
if( pl_info->frags > highest_frags || pl_info->deaths < lowest_deaths )
2016-02-24 22:26:16 +01:00
{
best_player = i;
lowest_deaths = pl_info->deaths;
highest_frags = pl_info->frags;
}
}
}
}
2016-07-03 15:39:55 +02:00
if( !best_player )
2016-02-24 22:26:16 +01:00
break;
// draw out the best player
hud_player_info_t *pl_info = &g_PlayerInfoList[best_player];
2016-07-03 15:39:55 +02:00
int ypos = ROW_RANGE_MIN + ( list_slot * ROW_GAP );
2016-02-24 22:26:16 +01:00
// check we haven't drawn too far down
2016-07-03 15:39:55 +02:00
if( ypos > ROW_RANGE_MAX ) // don't draw to close to the lower border
2016-02-24 22:26:16 +01:00
break;
int xpos = NAME_RANGE_MIN + xpos_rel;
if( ( ScreenWidth >= 440 && !can_show_packetloss ) || ( ScreenWidth >= 520 && can_show_packetloss ) )
{
xpos -= NAME_RANGE_MODIFIER;
}
2016-02-24 22:26:16 +01:00
int r = 255, g = 255, b = 255;
float *colors = GetClientColor( best_player );
r *= colors[0], g *= colors[1], b *= colors[2];
2016-07-03 15:39:55 +02:00
if( best_player == m_iLastKilledBy && m_fLastKillTime && m_fLastKillTime > gHUD.m_flTime )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
if( pl_info->thisplayer )
{
// green is the suicide color? i wish this could do grey...
FillRGBA( xpos - 5, ypos, FAR_RIGHT, ROW_GAP, 80, 155, 0, 70 );
2016-02-24 22:26:16 +01:00
}
else
2016-07-03 15:39:55 +02:00
{
// Highlight the killers name - overlay the background in red, then draw the score text over it
FillRGBA( xpos - 5, ypos, FAR_RIGHT, ROW_GAP, 255, 0, 0, ( (float)15 * (float)( m_fLastKillTime - gHUD.m_flTime ) ) );
2016-02-24 22:26:16 +01:00
}
}
2016-07-03 15:39:55 +02:00
else if( pl_info->thisplayer ) // if it is their name, draw it a different color
2016-02-24 22:26:16 +01:00
{
// overlay the background in blue, then draw the score text over it
FillRGBA( xpos - 5, ypos, FAR_RIGHT, ROW_GAP, 0, 0, 255, 70 );
2016-02-24 22:26:16 +01:00
}
// draw their name (left to right)
2017-03-29 21:59:50 +02:00
DrawUtfString( xpos + nameoffset, ypos, NAME_RANGE_MAX + xpos_rel, pl_info->name, r, g, b );
2016-02-24 22:26:16 +01:00
// draw kills (right to left)
xpos = KILLS_RANGE_MAX + xpos_rel;
gHUD.DrawHudNumberString( xpos, ypos, KILLS_RANGE_MIN + xpos_rel, g_PlayerExtraInfo[best_player].frags, r, g, b );
// draw divider
xpos = DIVIDER_POS + xpos_rel;
2017-03-29 21:59:50 +02:00
DrawUtfString( xpos, ypos, xpos + 20, "/", r, g, b );
2016-02-24 22:26:16 +01:00
// draw deaths
xpos = DEATHS_RANGE_MAX + xpos_rel;
gHUD.DrawHudNumberString( xpos, ypos, DEATHS_RANGE_MIN + xpos_rel, g_PlayerExtraInfo[best_player].deaths, r, g, b );
// draw ping & packetloss
static char buf[64];
sprintf( buf, "%d", g_PlayerInfoList[best_player].ping );
2016-07-03 15:39:55 +02:00
xpos = ( ( PING_RANGE_MAX - PING_RANGE_MIN ) / 2 ) + PING_RANGE_MIN + xpos_rel + 25;
2016-02-24 22:26:16 +01:00
gHUD.DrawHudStringReverse( xpos, ypos, xpos - 50, buf, r, g, b );
// Packetloss removed on Kelly 'shipping nazi' Bailey's orders
2016-07-03 15:39:55 +02:00
if( can_show_packetloss )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
if( g_PlayerInfoList[best_player].packetloss >= 63 )
2016-02-24 22:26:16 +01:00
{
UnpackRGB( r, g, b, RGB_REDISH );
2022-11-14 03:41:21 +01:00
strcpy( buf, " !!!!" );
2016-02-24 22:26:16 +01:00
}
else
{
sprintf( buf, " %d", g_PlayerInfoList[best_player].packetloss );
}
2016-07-03 15:39:55 +02:00
xpos = ( ( PL_RANGE_MAX - PL_RANGE_MIN ) / 2 ) + PL_RANGE_MIN + xpos_rel + 25;
2017-03-29 21:59:50 +02:00
DrawUtfString( xpos, ypos, xpos+50, buf, r, g, b );
2016-02-24 22:26:16 +01:00
}
2016-07-03 15:39:55 +02:00
2016-02-24 22:26:16 +01:00
pl_info->name = NULL; // set the name to be NULL, so this client won't get drawn again
list_slot++;
}
return list_slot;
}
2016-07-03 15:39:55 +02:00
void CHudScoreboard::GetAllPlayersInfo( void )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
for( int i = 1; i < MAX_PLAYERS; i++ )
2016-02-24 22:26:16 +01:00
{
GetPlayerInfo( i, &g_PlayerInfoList[i] );
2016-07-03 15:39:55 +02:00
if( g_PlayerInfoList[i].thisplayer )
2016-02-24 22:26:16 +01:00
m_iPlayerNum = i; // !!!HACK: this should be initialized elsewhere... maybe gotten from the engine
}
}
2016-07-03 15:39:55 +02:00
int CHudScoreboard::MsgFunc_ScoreInfo( const char *pszName, int iSize, void *pbuf )
2016-02-24 22:26:16 +01:00
{
m_iFlags |= HUD_ACTIVE;
BEGIN_READ( pbuf, iSize );
short cl = READ_BYTE();
short frags = READ_SHORT();
short deaths = READ_SHORT();
short playerclass = READ_SHORT();
short teamnumber = READ_SHORT();
2016-07-03 15:39:55 +02:00
if( cl > 0 && cl <= MAX_PLAYERS )
2016-02-24 22:26:16 +01:00
{
g_PlayerExtraInfo[cl].frags = frags;
g_PlayerExtraInfo[cl].deaths = deaths;
g_PlayerExtraInfo[cl].playerclass = playerclass;
g_PlayerExtraInfo[cl].teamnumber = teamnumber;
#if USE_VGUI
gViewPort->UpdateOnPlayerInfo();
#endif
2016-02-24 22:26:16 +01:00
}
return 1;
}
// Message handler for TeamInfo message
// accepts two values:
// byte: client number
// string: client team name
2016-07-03 15:39:55 +02:00
int CHudScoreboard::MsgFunc_TeamInfo( const char *pszName, int iSize, void *pbuf )
2016-02-24 22:26:16 +01:00
{
2016-03-01 21:18:42 +01:00
int i, j;
2016-02-24 22:26:16 +01:00
BEGIN_READ( pbuf, iSize );
short cl = READ_BYTE();
2016-07-03 15:39:55 +02:00
if( cl > 0 && cl <= MAX_PLAYERS )
{
// set the players team
2022-11-14 04:47:47 +01:00
strncpy( g_PlayerExtraInfo[cl].teamname, READ_STRING(), MAX_TEAM_NAME - 1 );
2016-02-24 22:26:16 +01:00
}
// rebuild the list of teams
// clear out player counts from teams
2016-07-03 15:39:55 +02:00
for( i = 1; i <= m_iNumTeams; i++ )
2016-02-24 22:26:16 +01:00
{
g_TeamInfo[i].players = 0;
}
// rebuild the team list
GetAllPlayersInfo();
m_iNumTeams = 0;
2016-07-03 15:39:55 +02:00
for( i = 1; i < MAX_PLAYERS; i++ )
2016-02-24 22:26:16 +01:00
{
//if ( g_PlayerInfoList[i].name == NULL )
// continue;
2016-07-03 15:39:55 +02:00
if( g_PlayerExtraInfo[i].teamname[0] == 0 )
2016-02-24 22:26:16 +01:00
continue; // skip over players who are not in a team
// is this player in an existing team?
2016-07-03 15:39:55 +02:00
for( j = 1; j <= m_iNumTeams; j++ )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
if( g_TeamInfo[j].name[0] == '\0' )
2016-02-24 22:26:16 +01:00
break;
2016-07-03 15:39:55 +02:00
if( !stricmp( g_PlayerExtraInfo[i].teamname, g_TeamInfo[j].name ) )
2016-02-24 22:26:16 +01:00
break;
}
2016-07-03 15:39:55 +02:00
if( j > m_iNumTeams )
{
// they aren't in a listed team, so make a new one
2016-02-24 22:26:16 +01:00
// search through for an empty team slot
2016-07-03 15:39:55 +02:00
for( j = 1; j <= m_iNumTeams; j++ )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
if( g_TeamInfo[j].name[0] == '\0' )
2016-02-24 22:26:16 +01:00
break;
}
2019-08-11 23:25:50 +02:00
m_iNumTeams = Q_max( j, m_iNumTeams );
2016-02-24 22:26:16 +01:00
2022-11-14 04:47:47 +01:00
strncpy( g_TeamInfo[j].name, g_PlayerExtraInfo[i].teamname, MAX_TEAM_NAME - 1 );
2016-02-24 22:26:16 +01:00
g_TeamInfo[j].players = 0;
}
g_TeamInfo[j].players++;
}
// clear out any empty teams
2016-07-03 15:39:55 +02:00
for( i = 1; i <= m_iNumTeams; i++ )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
if( g_TeamInfo[i].players < 1 )
2016-02-24 22:26:16 +01:00
memset( &g_TeamInfo[i], 0, sizeof(team_info_t) );
}
return 1;
}
// Message handler for TeamScore message
// accepts three values:
// string: team name
// short: teams kills
// short: teams deaths
// if this message is never received, then scores will simply be the combined totals of the players.
2016-07-03 15:39:55 +02:00
int CHudScoreboard::MsgFunc_TeamScore( const char *pszName, int iSize, void *pbuf )
2016-02-24 22:26:16 +01:00
{
BEGIN_READ( pbuf, iSize );
char *TeamName = READ_STRING();
2016-03-01 21:18:42 +01:00
int i;
2016-02-24 22:26:16 +01:00
// find the team matching the name
2016-07-03 15:39:55 +02:00
for( i = 1; i <= m_iNumTeams; i++ )
2016-02-24 22:26:16 +01:00
{
2016-07-03 15:39:55 +02:00
if( !stricmp( TeamName, g_TeamInfo[i].name ) )
2016-02-24 22:26:16 +01:00
break;
}
2016-07-03 15:39:55 +02:00
if( i > m_iNumTeams )
2016-02-24 22:26:16 +01:00
return 1;
// use this new score data instead of combined player scores
g_TeamInfo[i].scores_overriden = TRUE;
g_TeamInfo[i].frags = READ_SHORT();
g_TeamInfo[i].deaths = READ_SHORT();
2016-07-03 15:39:55 +02:00
2016-02-24 22:26:16 +01:00
return 1;
}
2016-07-03 15:39:55 +02:00
void CHudScoreboard::DeathMsg( int killer, int victim )
2016-02-24 22:26:16 +01:00
{
// if we were the one killed, or the world killed us, set the scoreboard to indicate suicide
2016-07-03 15:39:55 +02:00
if( victim == m_iPlayerNum || killer == 0 )
2016-02-24 22:26:16 +01:00
{
m_iLastKilledBy = killer ? killer : m_iPlayerNum;
m_fLastKillTime = gHUD.m_flTime + 10; // display who we were killed by for 10 seconds
2016-07-03 15:39:55 +02:00
if( killer == m_iPlayerNum )
2016-02-24 22:26:16 +01:00
m_iLastKilledBy = m_iPlayerNum;
}
}
2016-07-03 15:39:55 +02:00
void CHudScoreboard::UserCmd_ShowScores( void )
2016-02-24 22:26:16 +01:00
{
m_iShowscoresHeld = TRUE;
}
2016-07-03 15:39:55 +02:00
void CHudScoreboard::UserCmd_HideScores( void )
2016-02-24 22:26:16 +01:00
{
m_iShowscoresHeld = FALSE;
}