Team Fortress 2 Source Code as on 22/4/2020
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.

167 lines
4.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Team management class. Contains all the details for a specific team
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "dod_team.h"
  9. #include "entitylist.h"
  10. #include "dod_shareddefs.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. // Datatable
  14. IMPLEMENT_SERVERCLASS_ST(CDODTeam, DT_DODTeam)
  15. END_SEND_TABLE()
  16. LINK_ENTITY_TO_CLASS( dod_team_manager, CDODTeam );
  17. //-----------------------------------------------------------------------------
  18. // Purpose: Get a pointer to the specified TF team manager
  19. //-----------------------------------------------------------------------------
  20. CDODTeam *GetGlobalDODTeam( int iIndex )
  21. {
  22. return (CDODTeam*)GetGlobalTeam( iIndex );
  23. }
  24. //-----------------------------------------------------------------------------
  25. // Purpose: Needed because this is an entity, but should never be used
  26. //-----------------------------------------------------------------------------
  27. void CDODTeam::Init( const char *pName, int iNumber )
  28. {
  29. BaseClass::Init( pName, iNumber );
  30. // Only detect changes every half-second.
  31. NetworkProp()->SetUpdateInterval( 0.75f );
  32. m_hPlayerClassInfoHandles.Purge();
  33. }
  34. void CDODTeam::AddPlayerClass( const char *szClassName )
  35. {
  36. PLAYERCLASS_FILE_INFO_HANDLE hPlayerClassInfo;
  37. if ( ReadPlayerClassDataFromFileForSlot( filesystem, szClassName, &hPlayerClassInfo, GetEncryptionKey() ) )
  38. {
  39. m_hPlayerClassInfoHandles.AddToTail( hPlayerClassInfo );
  40. }
  41. else
  42. {
  43. Assert( !"missing playerclass script file" );
  44. Msg( "Missing playerclass script file for class: %s\n", szClassName );
  45. }
  46. }
  47. const CDODPlayerClassInfo &CDODTeam::GetPlayerClassInfo( int iPlayerClass ) const
  48. {
  49. Assert( iPlayerClass >= 0 && iPlayerClass < m_hPlayerClassInfoHandles.Count() );
  50. const FilePlayerClassInfo_t *pPlayerClassInfo = GetFilePlayerClassInfoFromHandle( m_hPlayerClassInfoHandles[iPlayerClass] );
  51. const CDODPlayerClassInfo *pDODInfo;
  52. #ifdef _DEBUG
  53. pDODInfo = dynamic_cast< const CDODPlayerClassInfo* >( pPlayerClassInfo );
  54. Assert( pDODInfo );
  55. #else
  56. pDODInfo = static_cast< const CDODPlayerClassInfo* >( pPlayerClassInfo );
  57. #endif
  58. return *pDODInfo;
  59. }
  60. bool CDODTeam::IsClassOnTeam( const char *pszClassName, int &iClassNum ) const
  61. {
  62. iClassNum = PLAYERCLASS_UNDEFINED;
  63. // Random is always on every team
  64. if( FStrEq( pszClassName, "cls_random" ) )
  65. {
  66. iClassNum = PLAYERCLASS_RANDOM;
  67. return true;
  68. }
  69. for( int i=0;i<m_hPlayerClassInfoHandles.Count(); i++ )
  70. {
  71. FilePlayerClassInfo_t *pPlayerClassInfo = GetFilePlayerClassInfoFromHandle( m_hPlayerClassInfoHandles[i] );
  72. if( stricmp( pszClassName, pPlayerClassInfo->m_szSelectCmd ) == 0 )
  73. {
  74. iClassNum = i;
  75. return true;
  76. }
  77. }
  78. return false;
  79. }
  80. void CDODTeam::ResetScores( void )
  81. {
  82. SetRoundsWon(0);
  83. SetScore(0);
  84. }
  85. //==================================
  86. // TEAMS!
  87. //==================================
  88. // US REGULARS
  89. //==================
  90. class CDODTeam_Allies : public CDODTeam
  91. {
  92. DECLARE_CLASS( CDODTeam_Allies, CDODTeam );
  93. DECLARE_SERVERCLASS();
  94. virtual void Init( const char *pName, int iNumber )
  95. {
  96. BaseClass::Init( pName, iNumber );
  97. int i = 0;
  98. while( pszTeamAlliesClasses[i] != NULL )
  99. {
  100. AddPlayerClass( pszTeamAlliesClasses[i] );
  101. i++;
  102. }
  103. }
  104. virtual const char *GetTeamName( void ) { return "#Teamname_Allies"; }
  105. };
  106. IMPLEMENT_SERVERCLASS_ST(CDODTeam_Allies, DT_DODTeam_Allies)
  107. END_SEND_TABLE()
  108. LINK_ENTITY_TO_CLASS( dod_team_allies, CDODTeam_Allies );
  109. // AXIS REGULAR
  110. //==================
  111. class CDODTeam_Axis : public CDODTeam
  112. {
  113. DECLARE_CLASS( CDODTeam_Axis, CDODTeam );
  114. DECLARE_SERVERCLASS();
  115. virtual void Init( const char *pName, int iNumber )
  116. {
  117. BaseClass::Init( pName, iNumber );
  118. int i = 0;
  119. while( pszTeamAxisClasses[i] != NULL )
  120. {
  121. AddPlayerClass( pszTeamAxisClasses[i] );
  122. i++;
  123. }
  124. }
  125. virtual const char *GetTeamName( void ) { return "#Teamname_Allies"; }
  126. };
  127. IMPLEMENT_SERVERCLASS_ST(CDODTeam_Axis, DT_DODTeam_Axis)
  128. END_SEND_TABLE()
  129. LINK_ENTITY_TO_CLASS( dod_team_axis, CDODTeam_Axis );