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.

206 lines
6.0 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef TEAM_CONTROL_POINT_MASTER_H
  7. #define TEAM_CONTROL_POINT_MASTER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "utlmap.h"
  12. #include "team.h"
  13. #include "teamplay_gamerules.h"
  14. #include "team_control_point.h"
  15. #include "trigger_area_capture.h"
  16. #include "team_objectiveresource.h"
  17. #include "team_control_point_round.h"
  18. #define CPM_THINK "CTeamControlPointMasterCPMThink"
  19. #define CPM_POSTINITTHINK "CTeamControlPointMasterCPMPostInitThink"
  20. //-----------------------------------------------------------------------------
  21. // Purpose: One ControlPointMaster is spawned per level. Shortly after spawning it detects all the Control
  22. // points in the map and puts them into the m_ControlPoints. From there it detects the state
  23. // where all points are captured and resets them if necessary It gives points every time interval to
  24. // the owners of the points
  25. //-----------------------------------------------------------------------------
  26. class CTeamControlPointMaster : public CBaseEntity
  27. {
  28. DECLARE_CLASS( CTeamControlPointMaster, CBaseEntity );
  29. // Derived, game-specific control point masters must override these functions
  30. public:
  31. CTeamControlPointMaster();
  32. // Used to find game specific entities
  33. virtual const char *GetTriggerAreaCaptureName( void ) { return "trigger_capture_area"; }
  34. virtual const char *GetControlPointName( void ) { return "team_control_point"; }
  35. virtual const char *GetControlPointRoundName( void ) { return "team_control_point_round"; }
  36. public:
  37. virtual void Spawn( void );
  38. virtual void UpdateOnRemove( void );
  39. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  40. virtual void Precache( void );
  41. virtual void Activate( void );
  42. void RoundRespawn( void );
  43. void Reset( void );
  44. int GetNumPoints( void ){ return m_ControlPoints.Count(); }
  45. int GetNumPointsOwnedByTeam( int iTeam );
  46. int CalcNumRoundsRemaining( int iTeam );
  47. bool IsActive( void ) { return ( m_bDisabled == false ); }
  48. void FireTeamWinOutput( int iWinningTeam );
  49. bool PointCanBeCapped( CTeamControlPoint *pPoint );
  50. void CheckWinConditions( void );
  51. bool WouldNewCPOwnerWinGame( CTeamControlPoint *pPoint, int iNewOwner );
  52. int GetBaseControlPoint( int iTeam );
  53. bool IsBaseControlPoint( int iPointIndex );
  54. bool PlayingMiniRounds( void ){ return ( m_ControlPointRounds.Count() > 0 ); }
  55. float PointLastContestedAt( int point );
  56. CTeamControlPoint *GetControlPoint( int point )
  57. {
  58. Assert( point >= 0 );
  59. Assert( point < MAX_CONTROL_POINTS );
  60. for ( unsigned int i = 0; i < m_ControlPoints.Count(); i++ )
  61. {
  62. CTeamControlPoint *pPoint = m_ControlPoints[i];
  63. if ( pPoint && pPoint->GetPointIndex() == point )
  64. return pPoint;
  65. }
  66. return NULL;
  67. }
  68. CTeamControlPointRound *GetCurrentRound( void )
  69. {
  70. if ( !PlayingMiniRounds() || m_iCurrentRoundIndex == -1 )
  71. {
  72. return NULL;
  73. }
  74. return m_ControlPointRounds[m_iCurrentRoundIndex];
  75. }
  76. string_t GetRoundToUseAfterRestart( void )
  77. {
  78. int nCurrentPriority = -1;
  79. int nHighestPriority = -1;
  80. string_t nRetVal = NULL_STRING;
  81. if ( PlayingMiniRounds() && GetCurrentRound() )
  82. {
  83. nCurrentPriority = GetCurrentRound()->GetPriorityValue();
  84. nHighestPriority = GetHighestRoundPriorityValue();
  85. // if the current round has the highest priority, then use it again
  86. if ( nCurrentPriority == nHighestPriority )
  87. {
  88. nRetVal = GetCurrentRound()->GetEntityName();
  89. }
  90. }
  91. return nRetVal;
  92. }
  93. void FireRoundStartOutput( void );
  94. void FireRoundEndOutput( void );
  95. bool ShouldScorePerCapture( void ){ return m_bScorePerCapture; }
  96. bool ShouldPlayAllControlPointRounds( void ){ return m_bPlayAllRounds; }
  97. bool FindControlPointRoundToPlay( void ); // checks to see if there are any more rounds to play (but doesn't actually "get" one to play)
  98. // void ListRounds( void );
  99. float GetPartialCapturePointRate( void );
  100. private:
  101. void EXPORT CPMThink( void );
  102. void SetBaseControlPoints( void );
  103. int TeamOwnsAllPoints( CTeamControlPoint *pOverridePoint = NULL, int iOverrideNewTeam = TEAM_UNASSIGNED );
  104. bool FindControlPoints( void ); // look in the map to find active control points
  105. bool FindControlPointRounds( void ); // look in the map to find active control point rounds
  106. bool GetControlPointRoundToPlay( void ); // gets the next round we should play
  107. bool SelectSpecificRound( void ); // selects a specific round to play
  108. int GetHighestRoundPriorityValue( void )
  109. {
  110. int nRetVal = -1;
  111. // rounds are sorted with the higher priority rounds first
  112. for ( int i = 0 ; i < m_ControlPointRounds.Count() ; ++i )
  113. {
  114. CTeamControlPointRound *pRound = m_ControlPointRounds[i];
  115. if ( pRound )
  116. {
  117. if ( pRound->GetPriorityValue() > nRetVal )
  118. {
  119. nRetVal = pRound->GetPriorityValue();
  120. }
  121. }
  122. }
  123. return nRetVal;
  124. }
  125. void RegisterRoundBeingPlayed( void );
  126. CUtlMap<int, CTeamControlPoint *> m_ControlPoints;
  127. bool m_bFoundPoints; // true when the control points have been found and the array is initialized
  128. CUtlVector<CTeamControlPointRound *> m_ControlPointRounds;
  129. int m_iCurrentRoundIndex;
  130. DECLARE_DATADESC();
  131. bool m_bDisabled;
  132. void InputEnable( inputdata_t &inputdata );
  133. void InputDisable( inputdata_t &inputdata );
  134. void InputRoundSpawn( inputdata_t &inputdata );
  135. void InputRoundActivate( inputdata_t &inputdata );
  136. void InputSetWinner( inputdata_t &inputdata );
  137. void InputSetWinnerAndForceCaps( inputdata_t &inputdata );
  138. void InputSetCapLayout( inputdata_t &inputdata );
  139. void InternalSetWinner( int iTeam );
  140. void HandleRandomOwnerControlPoints( void );
  141. string_t m_iszTeamBaseIcons[MAX_TEAMS];
  142. int m_iTeamBaseIcons[MAX_TEAMS];
  143. string_t m_iszCapLayoutInHUD;
  144. int m_iInvalidCapWinner;
  145. bool m_bSwitchTeamsOnWin;
  146. bool m_bScorePerCapture;
  147. bool m_bPlayAllRounds;
  148. bool m_bFirstRoundAfterRestart;
  149. COutputEvent m_OnWonByTeam1;
  150. COutputEvent m_OnWonByTeam2;
  151. float m_flPartialCapturePointsRate;
  152. };
  153. extern CUtlVector< CHandle<CTeamControlPointMaster> > g_hControlPointMasters;
  154. #endif // TEAM_CONTROL_POINT_MASTER_H