Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
3.2 KiB

  1. //===== Copyright � 1996-2009, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #include "game.h"
  7. #include "gamemanager.h"
  8. #include "matchsystem.h"
  9. #include "playermanager.h"
  10. #include "matchmaking.h"
  11. // NOTE: This has to be the last file included!
  12. #include "tier0/memdbgon.h"
  13. CMatchGame::CMatchGame()
  14. {
  15. }
  16. CMatchGame::~CMatchGame()
  17. {
  18. }
  19. void CMatchGame::Reset()
  20. {
  21. RemoveAllPlayers();
  22. }
  23. XNKID CMatchGame::GetXNKID()
  24. {
  25. return (XNKID) g_pMatchmaking->GetSessionXNKID();
  26. }
  27. int CMatchGame::GetNumPlayers()
  28. {
  29. return m_PlayerList.Count();
  30. }
  31. IPlayer * CMatchGame::GetPlayer( int index )
  32. {
  33. if ( m_PlayerList.IsValidIndex( index ) )
  34. return m_PlayerList[index];
  35. else
  36. return NULL;
  37. }
  38. void CMatchGame::AddPlayer( XUID xuid, int pExperience[ MATCH_MAX_DIFFICULTIES ] /*= NULL*/, int pSkills[ MATCH_MAX_DIFFICULTIES ][ MATCH_MAX_SKILL_FIELDS ] /*= NULL*/ )
  39. {
  40. if ( MM_IsDebug() )
  41. {
  42. Msg( "[L4DMM] CMatchGame::AddPlayer( %llx )\n", xuid );
  43. }
  44. IPlayer * player = g_pPlayerManager->FindPlayer( xuid );
  45. if ( !player )
  46. {
  47. Warning( "[L4DMM] CMatchGame::AddPlayer - Cannot find player by %llx!\n", xuid );
  48. return;
  49. }
  50. // Find a player first
  51. for ( int k = 0; k < m_PlayerList.Count(); ++ k )
  52. {
  53. if( m_PlayerList[k]->GetXUID() == xuid )
  54. {
  55. Warning( "[L4DMM] CMatchGame::AddPlayer - player %llx already added!\n", xuid );
  56. return;
  57. }
  58. }
  59. m_PlayerList.AddToTail( player );
  60. }
  61. void CMatchGame::RemovePlayer( XUID xuid )
  62. {
  63. if ( MM_IsDebug() )
  64. {
  65. Msg( "[L4DMM] CMatchGame::RemovePlayer( %llx )\n", xuid );
  66. }
  67. int numRemoved = 0;
  68. for ( int k = 0; k < m_PlayerList.Count(); ++ k )
  69. {
  70. if( m_PlayerList[k]->GetXUID() == xuid )
  71. {
  72. m_PlayerList.Remove( k );
  73. ++ numRemoved;
  74. }
  75. }
  76. if ( !numRemoved )
  77. {
  78. Warning( "[L4DMM] CMatchGame::RemovePlayer - Cannot find player by %llx!\n", xuid );
  79. }
  80. }
  81. void CMatchGame::RemoveAllPlayers( )
  82. {
  83. if ( MM_IsDebug() )
  84. {
  85. Msg( "[L4DMM] CMatchGame::RemoveAllPlayers\n" );
  86. }
  87. m_PlayerList.RemoveAll();
  88. }
  89. int CMatchGame::GetAggregateExperience( )
  90. {
  91. int difficulty = 1; // CMatchSystem::GetMatchSystem()->GetManager()->GameGetDifficulty();
  92. double exp = 0;
  93. int numExp = 0;
  94. int numPlayers = m_PlayerList.Count();
  95. for( int index = 0; index < numPlayers; ++index )
  96. {
  97. IPlayer * player = GetPlayer( index );
  98. if( player )
  99. {
  100. // TODO: exp += player->GetExperience( difficulty );
  101. ++ numExp;
  102. }
  103. }
  104. if( numExp )
  105. exp /= numExp;
  106. if ( MM_IsDebug() >= 2 )
  107. {
  108. Msg( "[L4DMM] Game aggregate experience on difficulty%d = %f out of %d exp players.\n", difficulty, exp, numExp );
  109. }
  110. return exp;
  111. }
  112. int CMatchGame::GetAggregateSkill( int iSkillType )
  113. {
  114. int difficulty = 1; // CMatchSystem::GetMatchSystem()->GetManager()->GameGetDifficulty();
  115. double skill = 0;
  116. int numSkills = 0;
  117. int numPlayers = m_PlayerList.Count();
  118. for( int index = 0; index < numPlayers; ++index )
  119. {
  120. IPlayer * player = GetPlayer( index );
  121. if( player )
  122. {
  123. // TODO: skill += player->GetSkill( iSkillType, difficulty );
  124. ++ numSkills;
  125. }
  126. }
  127. if( numSkills )
  128. skill /= numSkills;
  129. if ( MM_IsDebug() >= 2 )
  130. {
  131. Msg( "[L4DMM] Game aggregate skill%d on difficulty%d = %f out of %d skill players.\n", iSkillType, difficulty, skill, numSkills );
  132. }
  133. return skill;
  134. }