コード例 #1
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CPlayerResource::UpdatePlayerData( void )
{
	for ( int i = 1; i <= gpGlobals->maxClients; i++ )
	{
		CBasePlayer *pPlayer = (CBasePlayer*)UTIL_PlayerByIndex( i );
		
		if ( pPlayer && pPlayer->IsConnected() )
		{
			m_iScore.Set( i, pPlayer->FragCount() );
			m_iDeaths.Set( i, pPlayer->DeathCount() );
			m_bConnected.Set( i, 1 );
			m_iTeam.Set( i, pPlayer->GetTeamNumber() );
			m_bAlive.Set( i, pPlayer->IsAlive()?1:0 );
			m_iHealth.Set(i, max( 0, pPlayer->GetHealth() ) );

			// Don't update ping / packetloss everytime

			if ( !(m_nUpdateCounter%20) )
			{
				// update ping all 20 think ticks = (20*0.1=2seconds)
				int ping, packetloss;
				UTIL_GetPlayerConnectionInfo( i, ping, packetloss );
				
				// calc avg for scoreboard so it's not so jittery
				ping = 0.8f * m_iPing.Get(i) + 0.2f * ping;

				
				m_iPing.Set( i, ping );
				// m_iPacketloss.Set( i, packetloss );
			}
		}
		else
		{
			m_bConnected.Set( i, 0 );
		}
	}
}
コード例 #2
0
ファイル: player_resource.cpp プロジェクト: ziming/IOS
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CPlayerResource::UpdatePlayerData( void )
{
	int pingSum[2] = { 0 };
	int pingPlayers[2] = { 0 };

	for (int i = 1; i <= gpGlobals->maxClients; i++)
	{
		CSDKPlayer *pPl = ToSDKPlayer(UTIL_PlayerByIndex(i));
		if (!pPl || !pPl->IsConnected())
		{
			m_bConnected.Set(i, 0);
			continue;
		}
		
		m_bConnected.Set( i, 1 );
		m_iTeam.Set( i, pPl->GetTeamNumber() );

		m_nSpecTeam.Set( i, pPl->GetSpecTeam() );
		m_TeamPosIndex.Set(i, pPl->GetTeamPosIndex() );
		m_ShirtNumber.Set(i, pPl->GetShirtNumber() );
		m_SkinIndex.Set(i, pPl->GetSkinIndex() );
		m_TeamToJoin.Set(i, pPl->GetTeamToJoin() );
		m_TeamPosIndexToJoin.Set(i, pPl->GetTeamPosIndexToJoin() );
		m_NextCardJoin.Set(i, pPl->GetNextCardJoin() );
		m_IsAway.Set(i, pPl->IsAway() );
		m_szPlayerNames.Set(i, MAKE_STRING(pPl->GetPlayerName()));
		m_CountryIndices.Set(i, pPl->GetCountryIndex());
		m_NationalityIndices.Set(i, pPl->GetNationalityIndex());
		m_szClubNames.Set(i, MAKE_STRING(pPl->GetClubName()));
		m_szNationalTeamNames.Set(i, MAKE_STRING(pPl->GetNationalTeamName()));
		m_szShirtNames.Set(i, MAKE_STRING(pPl->GetShirtName()));

		// We're dealing with arrays of char pointers which point to the char array of the player object variable.
		// Keep track of variable changes with a boolean variable so we know when to send an update to the clients.

		if (pPl->m_bPlayerNameChanged)
		{
			m_szPlayerNames.GetForModify(i);
			pPl->m_bPlayerNameChanged = false;
		}

		if (pPl->m_bClubNameChanged)
		{
			m_szClubNames.GetForModify(i);
			pPl->m_bClubNameChanged = false;
		}

		if (pPl->m_bNationalTeamNameChanged)
		{
			m_szNationalTeamNames.GetForModify(i);
			pPl->m_bNationalTeamNameChanged = false;
		}

		if (pPl->m_bShirtNameChanged)
		{
			m_szShirtNames.GetForModify(i);
			pPl->m_bShirtNameChanged = false;
		}

		// Don't update statistics every time

		if (m_nUpdateCounter % 20 == 0)
		{
			// update ping all 20 think ticks = (20*0.1=2seconds)
			int ping, packetloss;
			UTIL_GetPlayerConnectionInfo( i, ping, packetloss );

			// calc avg for scoreboard so it's not so jittery
			ping = 0.8f * m_iPing.Get(i) + 0.2f * ping;

			m_iPing.Set( i, ping );
			// m_iPacketloss.Set( i, packetloss );

			m_RedCards.Set(i, max( 0, pPl->GetRedCards() ) );
			m_YellowCards.Set(i, max( 0, pPl->GetYellowCards() ) );
			m_Fouls.Set(i, max( 0, pPl->GetFouls() ) );
			m_FoulsSuffered.Set(i, max( 0, pPl->GetFoulsSuffered() ) );
			m_SlidingTackles.Set(i, max( 0, pPl->GetSlidingTackles() ) );
			m_SlidingTacklesCompleted.Set(i, max( 0, pPl->GetSlidingTacklesCompleted() ) );
			m_GoalsConceded.Set(i, max( 0, pPl->GetGoalsConceded() ) );
			m_Shots.Set(i, max( 0, pPl->GetShots() ) );
			m_ShotsOnGoal.Set(i, max( 0, pPl->GetShotsOnGoal() ) );
			m_PassesCompleted.Set(i, max( 0, pPl->GetPassesCompleted() ) );
			m_Interceptions.Set(i, max( 0, pPl->GetInterceptions() ) );
			m_Offsides.Set(i, max( 0, pPl->GetOffsides() ) );
			m_Goals.Set(i, max( 0, pPl->GetGoals() ) );
			m_OwnGoals.Set(i, max( 0, pPl->GetOwnGoals() ) );
			m_Assists.Set(i, max( 0, pPl->GetAssists() ) );
			m_Possession.Set(i, max( 0, pPl->GetPossession() ) );
			m_DistanceCovered.Set(i, max( 0, pPl->GetDistanceCovered() ) );
			m_Passes.Set(i, max( 0, pPl->GetPasses() ) );
			m_FreeKicks.Set(i, max( 0, pPl->GetFreeKicks() ) );
			m_Penalties.Set(i, max( 0, pPl->GetPenalties() ) );
			m_Corners.Set(i, max( 0, pPl->GetCorners() ) );
			m_ThrowIns.Set(i, max( 0, pPl->GetThrowIns() ) );
			m_KeeperSaves.Set(i, max( 0, pPl->GetKeeperSaves() ) );
			m_KeeperSavesCaught.Set(i, max( 0, pPl->GetKeeperSavesCaught() ) );
			m_GoalKicks.Set(i, max( 0, pPl->GetGoalKicks() ) );
			//m_Ratings.Set(i, max( 0, pPl->GetRating() ) );
			m_Ratings.Set(i, 100 );

			if (pPl->GetTeamNumber() == TEAM_HOME || pPl->GetTeamNumber() == TEAM_AWAY)
			{
				int ti = pPl->GetTeamNumber() - TEAM_HOME;

				if (ping > 0)
				{
					pingSum[ti] += ping;
					pingPlayers[ti] += 1;
				}
			}
		}
	}

	for (int team = TEAM_HOME; team <= TEAM_AWAY; team++)
	{
		int ti = team - TEAM_HOME;
		CTeam *pTeam = GetGlobalTeam(team);

		if (m_nUpdateCounter % 20 == 0)
		{
			pTeam->m_Ping = pingSum[ti] / max(1, pingPlayers[ti]);
			pTeam->m_Rating = 100;
		}
	}
}