aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/client/c_team.cpp
diff options
context:
space:
mode:
authorJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
committerJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
commit39ed87570bdb2f86969d4be821c94b722dc71179 (patch)
treeabc53757f75f40c80278e87650ea92808274aa59 /mp/src/game/client/c_team.cpp
downloadsource-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz
source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip
First version of the SOurce SDK 2013
Diffstat (limited to 'mp/src/game/client/c_team.cpp')
-rw-r--r--mp/src/game/client/c_team.cpp256
1 files changed, 256 insertions, 0 deletions
diff --git a/mp/src/game/client/c_team.cpp b/mp/src/game/client/c_team.cpp
new file mode 100644
index 00000000..94373b5f
--- /dev/null
+++ b/mp/src/game/client/c_team.cpp
@@ -0,0 +1,256 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose: Client side CTeam class
+//
+// $NoKeywords: $
+//=============================================================================//
+#include "cbase.h"
+#include "c_team.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+//-----------------------------------------------------------------------------
+// Purpose: RecvProxy that converts the Team's player UtlVector to entindexes
+//-----------------------------------------------------------------------------
+void RecvProxy_PlayerList( const CRecvProxyData *pData, void *pStruct, void *pOut )
+{
+ C_Team *pTeam = (C_Team*)pOut;
+ pTeam->m_aPlayers[pData->m_iElement] = pData->m_Value.m_Int;
+}
+
+
+void RecvProxyArrayLength_PlayerArray( void *pStruct, int objectID, int currentArrayLength )
+{
+ C_Team *pTeam = (C_Team*)pStruct;
+
+ if ( pTeam->m_aPlayers.Size() != currentArrayLength )
+ pTeam->m_aPlayers.SetSize( currentArrayLength );
+}
+
+
+IMPLEMENT_CLIENTCLASS_DT_NOBASE(C_Team, DT_Team, CTeam)
+ RecvPropInt( RECVINFO(m_iTeamNum)),
+ RecvPropInt( RECVINFO(m_iScore)),
+ RecvPropInt( RECVINFO(m_iRoundsWon) ),
+ RecvPropString( RECVINFO(m_szTeamname)),
+
+ RecvPropArray2(
+ RecvProxyArrayLength_PlayerArray,
+ RecvPropInt( "player_array_element", 0, SIZEOF_IGNORE, 0, RecvProxy_PlayerList ),
+ MAX_PLAYERS,
+ 0,
+ "player_array"
+ )
+END_RECV_TABLE()
+
+BEGIN_PREDICTION_DATA( C_Team )
+ DEFINE_PRED_ARRAY( m_szTeamname, FIELD_CHARACTER, MAX_TEAM_NAME_LENGTH, FTYPEDESC_PRIVATE ),
+ DEFINE_PRED_FIELD( m_iScore, FIELD_INTEGER, FTYPEDESC_PRIVATE ),
+ DEFINE_PRED_FIELD( m_iRoundsWon, FIELD_INTEGER, FTYPEDESC_PRIVATE ),
+ DEFINE_PRED_FIELD( m_iDeaths, FIELD_INTEGER, FTYPEDESC_PRIVATE ),
+ DEFINE_PRED_FIELD( m_iPing, FIELD_INTEGER, FTYPEDESC_PRIVATE ),
+ DEFINE_PRED_FIELD( m_iPacketloss, FIELD_INTEGER, FTYPEDESC_PRIVATE ),
+ DEFINE_PRED_FIELD( m_iTeamNum, FIELD_INTEGER, FTYPEDESC_PRIVATE ),
+END_PREDICTION_DATA();
+
+// Global list of client side team entities
+CUtlVector< C_Team * > g_Teams;
+
+//=================================================================================================
+// C_Team functionality
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+C_Team::C_Team()
+{
+ m_iScore = 0;
+ m_iRoundsWon = 0;
+ memset( m_szTeamname, 0, sizeof(m_szTeamname) );
+
+ m_iDeaths = 0;
+ m_iPing = 0;
+ m_iPacketloss = 0;
+
+ // Add myself to the global list of team entities
+ g_Teams.AddToTail( this );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+C_Team::~C_Team()
+{
+ g_Teams.FindAndRemove( this );
+}
+
+
+void C_Team::RemoveAllPlayers()
+{
+ m_aPlayers.RemoveAll();
+}
+
+void C_Team::PreDataUpdate( DataUpdateType_t updateType )
+{
+ BaseClass::PreDataUpdate( updateType );
+}
+
+
+//-----------------------------------------------------------------------------
+// Gets the ith player on the team (may return NULL)
+//-----------------------------------------------------------------------------
+C_BasePlayer* C_Team::GetPlayer( int idx )
+{
+ return (C_BasePlayer*)cl_entitylist->GetEnt(m_aPlayers[idx]);
+}
+
+
+int C_Team::GetTeamNumber() const
+{
+ return m_iTeamNum;
+}
+
+
+//=================================================================================================
+// TEAM HANDLING
+//=================================================================================================
+// Purpose:
+//-----------------------------------------------------------------------------
+char *C_Team::Get_Name( void )
+{
+ return m_szTeamname;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+int C_Team::Get_Score( void )
+{
+ return m_iScore;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+int C_Team::Get_Deaths( void )
+{
+ return m_iDeaths;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+int C_Team::Get_Ping( void )
+{
+ return m_iPing;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Return the number of players in this team
+//-----------------------------------------------------------------------------
+int C_Team::Get_Number_Players( void )
+{
+ return m_aPlayers.Size();
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Returns true if the specified player is on this team
+//-----------------------------------------------------------------------------
+bool C_Team::ContainsPlayer( int iPlayerIndex )
+{
+ for (int i = 0; i < m_aPlayers.Size(); i++ )
+ {
+ if ( m_aPlayers[i] == iPlayerIndex )
+ return true;
+ }
+
+ return false;
+}
+
+
+void C_Team::ClientThink()
+{
+}
+
+
+//=================================================================================================
+// GLOBAL CLIENT TEAM HANDLING
+//=================================================================================================
+// Purpose: Get the C_Team for the local player
+//-----------------------------------------------------------------------------
+C_Team *GetLocalTeam( void )
+{
+ C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
+
+ if ( !player )
+ return NULL;
+
+ return GetPlayersTeam( player->index );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Get the C_Team for the specified team number
+//-----------------------------------------------------------------------------
+C_Team *GetGlobalTeam( int iTeamNumber )
+{
+ for (int i = 0; i < g_Teams.Count(); i++ )
+ {
+ if ( g_Teams[i]->GetTeamNumber() == iTeamNumber )
+ return g_Teams[i];
+ }
+
+ return NULL;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Returns the number of teams you can access via GetGlobalTeam() (hence the +1)
+//-----------------------------------------------------------------------------
+int GetNumTeams()
+{
+ return g_Teams.Count() + 1;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Get the team of the specified player
+//-----------------------------------------------------------------------------
+C_Team *GetPlayersTeam( int iPlayerIndex )
+{
+ for (int i = 0; i < g_Teams.Count(); i++ )
+ {
+ if ( g_Teams[i]->ContainsPlayer( iPlayerIndex ) )
+ return g_Teams[i];
+ }
+
+ return NULL;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Get the team of the specified player
+//-----------------------------------------------------------------------------
+C_Team *GetPlayersTeam( C_BasePlayer *pPlayer )
+{
+ return GetPlayersTeam( pPlayer->entindex() );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Returns true if the two specified players are on the same team
+//-----------------------------------------------------------------------------
+bool ArePlayersOnSameTeam( int iPlayerIndex1, int iPlayerIndex2 )
+{
+ for (int i = 0; i < g_Teams.Count(); i++ )
+ {
+ if ( g_Teams[i]->ContainsPlayer( iPlayerIndex1 ) && g_Teams[i]->ContainsPlayer( iPlayerIndex2 ) )
+ return true;
+ }
+
+ return false;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Get the number of team managers
+//-----------------------------------------------------------------------------
+int GetNumberOfTeams( void )
+{
+ return g_Teams.Size();
+} \ No newline at end of file