Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/game/client/swarm/c_asw_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ BEGIN_NETWORK_TABLE( C_ASW_Player, DT_ASW_Player )
RecvPropQAngles( RECVINFO( m_angEyeAngles ) ),
RecvPropEHandle( RECVINFO( m_hInhabiting ) ),
RecvPropEHandle( RECVINFO( m_hSpectating ) ),
RecvPropInt( RECVINFO( m_iSpectatorIndexes ) ),
RecvPropInt( RECVINFO( m_iHealth ) ),
RecvPropEHandle( RECVINFO( m_pCurrentInfoMessage ) ),
RecvPropFloat( RECVINFO( m_fMarineDeathTime ) ),
Expand Down
1 change: 1 addition & 0 deletions src/game/client/swarm/c_asw_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class C_ASW_Player : public C_BasePlayer, public IASWPlayerAnimStateHelpers
CInterpolatedVar< QAngle > m_iv_angEyeAngles;
CNetworkHandle( C_ASW_Inhabitable_NPC, m_hInhabiting ); // our currently controlled marine
CNetworkHandle( C_ASW_Inhabitable_NPC, m_hSpectating ); // the marine we're spectating when dead
CNetworkVar( unsigned int, m_iSpectatorIndexes );
const Vector& GetCrosshairTracePos() { return m_vecCrosshairTracePos; }
void SetCrosshairTracePos( const Vector &vecPos ) { m_vecCrosshairTracePos = vecPos; }
Vector m_vecCrosshairTracePos; // the world location directly beneath the player's crosshair
Expand Down
66 changes: 61 additions & 5 deletions src/game/client/vgui_fpspanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "../common/xbox/xboxstubs.h"
#ifdef INFESTED_DLL
#include "c_asw_player.h"
#include "c_playerresource.h"
#include "c_asw_inhabitable_npc.h"
#endif

Expand All @@ -27,6 +28,7 @@

static ConVar cl_showfps( "cl_showfps", "0", FCVAR_RELEASE, "Draw fps meter at top of screen (1 = fps, 2 = smooth fps, 3 = server MS, 4 = Show FPS and Log to file )" );
static ConVar cl_showpos( "cl_showpos", "0", FCVAR_RELEASE, "Draw current position at top of screen (1 = eyes, 2 = feet)" );
static ConVar cl_showspectators( "cl_showspectators", "0", FCVAR_RELEASE, "Draw a list of spectators" );
#ifdef INFESTED_DLL
static ConVar cl_showpos_npc( "cl_showpos_npc", "-1", FCVAR_NONE, "If the player is controlling or spectating an NPC, use the NPC's position, angles, and velocity instead; -1 = 1 if asw_allow_detach is 0, 0 otherwise" );
extern ConVar asw_allow_detach;
Expand Down Expand Up @@ -184,7 +186,8 @@ bool CFPSPanel::ShouldDraw( void )
if ( g_bDisplayParticlePerformance )
return true;
if ( ( !cl_showfps.GetInt() || ( gpGlobals->absoluteframetime <= 0 ) ) &&
( !cl_showpos.GetInt() ) )
( !cl_showpos.GetInt() ) &&
( !cl_showspectators.GetInt() ) )
{
m_bLastDraw = false;
return false;
Expand Down Expand Up @@ -278,12 +281,12 @@ void CFPSPanel::Paint()

float flTotalTime = 0.0f;
float flPeakTime = 0.0f;
for ( int i = 0; i < SERVER_TIME_HISTORY; ++i )
for ( int j = 0; j < SERVER_TIME_HISTORY; ++j )
{
flTotalTime += m_pServerTimes[i];
if ( flPeakTime < m_pServerTimes[i] )
flTotalTime += m_pServerTimes[j];
if ( flPeakTime < m_pServerTimes[j] )
{
flPeakTime = m_pServerTimes[i];
flPeakTime = m_pServerTimes[j];
}
}
flTotalTime /= SERVER_TIME_HISTORY;
Expand Down Expand Up @@ -517,6 +520,59 @@ void CFPSPanel::Paint()
}
}

if ( cl_showspectators.GetInt() )
{
FOR_EACH_VALID_SPLITSCREEN_PLAYER( hh )
{
C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer( hh );
if ( !pPlayer )
continue;

C_ASW_Inhabitable_NPC *pSpectating = pPlayer->m_hSpectating;
if ( pSpectating && pSpectating->GetCommander() )
{
pPlayer = pSpectating->GetCommander();
}

i += 3;

int nSpecCount = 0;
for ( int id = 1; id <= 32; id += 1 )
{
if ( !g_PR->IsConnected( id ) )
continue;

if ( g_PR->IsFakePlayer( id ) )
continue;

if ( !( pPlayer->m_iSpectatorIndexes.Get() & ( 1u << id ) ) )
continue;

nSpecCount++;
i++;

char szSpecName[k_cchPersonaNameMax] = { 0 };
Q_strncpy( szSpecName, g_PR->GetPlayerName( id ), sizeof( szSpecName ) );
g_pMatSystemSurface->DrawColoredText( m_hFont, x, 2 + i * lineHeight,
255, 255, 255, 255,
" %s", szSpecName );
}

if ( nSpecCount == 0 )
{
i -= 3;
break;
}

char szName[k_cchPersonaNameMax] = { 0 };
Q_strncpy( szName, pPlayer->GetPlayerName(), sizeof( szName ) );

g_pMatSystemSurface->DrawColoredText( m_hFont, x, 2 + ( i - nSpecCount ) * lineHeight,
255, 255, 255, 255,
"Spectating %s (%d):", szName, nSpecCount );
}
}

if ( m_nLinesNeeded != i )
{
m_nLinesNeeded = i;
Expand Down
23 changes: 22 additions & 1 deletion src/game/server/swarm/asw_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ IMPLEMENT_SERVERCLASS_ST( CASW_Player, DT_ASW_Player )
SendPropQAngles( SENDINFO( m_angEyeAngles ), 10, SPROP_CHANGES_OFTEN, SendProxy_QAngles, SENDPROP_PLAYER_EYE_ANGLES_PRIORITY ),
SendPropEHandle( SENDINFO( m_hInhabiting ) ),
SendPropEHandle( SENDINFO( m_hSpectating ) ),
SendPropInt( SENDINFO( m_iSpectatorIndexes ) ),
SendPropFloat( SENDINFO( m_fMarineDeathTime ) ),
SendPropEHandle( SENDINFO( m_hOrderingMarine ) ),
SendPropEHandle( SENDINFO( m_pCurrentInfoMessage ) ),
Expand Down Expand Up @@ -250,6 +251,7 @@ BEGIN_DATADESC( CASW_Player )
DEFINE_FIELD( m_vecLastMarineOrigin, FIELD_VECTOR ),
DEFINE_FIELD( m_hInhabiting, FIELD_EHANDLE ),
DEFINE_FIELD( m_hSpectating, FIELD_EHANDLE ),
DEFINE_FIELD( m_iSpectatorIndexes, FIELD_INTEGER ),
DEFINE_FIELD( m_vecStoredPosition, FIELD_VECTOR ),
DEFINE_FIELD( m_pCurrentInfoMessage, FIELD_EHANDLE ),
DEFINE_FIELD( m_iUseEntities, FIELD_INTEGER ),
Expand Down Expand Up @@ -441,6 +443,8 @@ CASW_Player::~CASW_Player()
m_PlayerAnimState->Release();
if ( ASWGameRules() )
ASWGameRules()->SetMaxMarines( this );

SetSpectatingNPC( NULL );
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -556,9 +560,9 @@ void CASW_Player::PostThink()
if (found_available_marine)
{
DevMsg(" Riflemod Drop-In. Switching player to marine 0\n");
SetSpectatingNPC( NULL );
pBotMarine->SetCommander( this );
pBotMarine->GetMarineResource()->SetCommander( this );
SetSpectatingNPC( NULL );
SwitchMarine( 0, false );
// reactivedrop: when player took marine under control
// delay his primary attack to prevent immediate shooting at
Expand Down Expand Up @@ -693,6 +697,7 @@ void CASW_Player::Spawn()
m_nChangingSlot = 0;
m_bHasAwardedXP = false;
m_bSentPromotedMessage = false;
m_iSpectatorIndexes = 0;

m_flLastActiveTime = gpGlobals->curtime;

Expand Down Expand Up @@ -2213,7 +2218,23 @@ void CASW_Player::SpectateNextMarine()

void CASW_Player::SetSpectatingNPC( CASW_Inhabitable_NPC *pSpectating )
{
unsigned int nOwnIndex = 1u << ( GetClientIndex() + 1 );
CASW_Inhabitable_NPC *pSpectatingPrevious = GetSpectatingNPC();
if ( pSpectatingPrevious && pSpectatingPrevious->GetCommander() )
{
pSpectatingPrevious->GetCommander()->m_iSpectatorIndexes &=~ nOwnIndex;
}

m_hSpectating = pSpectating;

if ( !pSpectating )
return;

CASW_Player *pPlayer = pSpectating->GetCommander();
if ( !pPlayer )
return;

pPlayer->m_iSpectatorIndexes |= nOwnIndex;
}

CASW_Inhabitable_NPC *CASW_Player::GetSpectatingNPC() const
Expand Down
1 change: 1 addition & 0 deletions src/game/server/swarm/asw_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class CASW_Player : public CBaseMultiplayerPlayer, public IASWPlayerAnimStateHel
CASW_Inhabitable_NPC *GetSpectatingNPC() const;
HSCRIPT ScriptGetSpectatingNPC() const;
CNetworkHandle( CASW_Inhabitable_NPC, m_hSpectating );
CNetworkVar( unsigned int, m_iSpectatorIndexes );
bool m_bLastAttackButton; // used to detect left clicks for cycling through marines
bool m_bLastAttack2Button; // used to detect right clicks for cycling through marines
bool m_bRequestedSpectator; // this player requested to be a spectator since the start of a match (won't be considered for leader, campaign votes, etc.)
Expand Down